Fix splash

(cherry picked from commit 77d3b14)
This commit is contained in:
PavelRatushnyi 2017-07-22 18:47:47 +03:00
parent df4d926b38
commit 058b5ade68
2 changed files with 21 additions and 19 deletions

View file

@ -25,11 +25,10 @@ public class SecondSplashScreenFragment extends Fragment {
public static boolean SHOW = true; public static boolean SHOW = true;
private static final int SECOND_SPLASH_TIME_OUT = 8000; private static final int SECOND_SPLASH_TIME_OUT = 8000;
private boolean started = false; private boolean started = false;
private FragmentActivity activity;
private OsmandApplication app; private OsmandApplication app;
public OsmandApplication getMyApplication() { public OsmandApplication getMyApplication() {
return ((OsmandApplication) activity.getApplication()); return ((OsmandApplication) getActivity().getApplication());
} }
private boolean hasNavBar() { private boolean hasNavBar() {
@ -78,10 +77,9 @@ public class SecondSplashScreenFragment extends Fragment {
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
activity = getActivity();
app = getMyApplication(); app = getMyApplication();
RelativeLayout view = new RelativeLayout(activity); RelativeLayout view = new RelativeLayout(getActivity());
view.setOnClickListener(null); view.setOnClickListener(null);
view.setBackgroundColor(getResources().getColor(R.color.map_background_color_light)); view.setBackgroundColor(getResources().getColor(R.color.map_background_color_light));
@ -94,7 +92,7 @@ public class SecondSplashScreenFragment extends Fragment {
RelativeLayout.LayoutParams logoLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams logoLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
logoLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); logoLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
logoLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL); logoLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
ImageView text = new ImageView(activity); ImageView text = new ImageView(getActivity());
if (Version.isFreeVersion(app)) { if (Version.isFreeVersion(app)) {
if ((InAppHelper.isSubscribedToLiveUpdates() && InAppHelper.isFullVersionPurchased()) || InAppHelper.isSubscribedToLiveUpdates()) { if ((InAppHelper.isSubscribedToLiveUpdates() && InAppHelper.isFullVersionPurchased()) || InAppHelper.isSubscribedToLiveUpdates()) {
text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand_osmlive)); text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand_osmlive));
@ -122,10 +120,10 @@ public class SecondSplashScreenFragment extends Fragment {
int textPaddingLeft = 0; int textPaddingLeft = 0;
int textPaddingRight = 0; int textPaddingRight = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
if (AndroidUiHelper.getScreenOrientation(activity) == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
logoPaddingLeft = getNavigationBarWidth(); logoPaddingLeft = getNavigationBarWidth();
textPaddingLeft = getNavigationBarWidth(); textPaddingLeft = getNavigationBarWidth();
} else if (AndroidUiHelper.getScreenOrientation(activity) == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) { } else if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
logoPaddingRight = getNavigationBarWidth(); logoPaddingRight = getNavigationBarWidth();
textPaddingRight = getNavigationBarWidth(); textPaddingRight = getNavigationBarWidth();
} }
@ -148,18 +146,18 @@ public class SecondSplashScreenFragment extends Fragment {
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (activity instanceof MapActivity) { if (getActivity() instanceof MapActivity) {
((MapActivity) activity).disableDrawer(); ((MapActivity) getActivity()).disableDrawer();
} }
if (!started) { if (!started) {
started = true; started = true;
SecondSplashScreenFragment.SHOW = false;
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (activity instanceof MapActivity && !((MapActivity) activity).isActivityDestroyed()) { if (getActivity() instanceof MapActivity
((MapActivity)activity).dismissSecondSplashScreen(); && (getActivity().getSupportFragmentManager().findFragmentByTag(SecondSplashScreenFragment.TAG) != null)) {
((MapActivity)getActivity()).dismissSecondSplashScreen();
} }
} }
}, SECOND_SPLASH_TIME_OUT); }, SECOND_SPLASH_TIME_OUT);
@ -169,8 +167,8 @@ public class SecondSplashScreenFragment extends Fragment {
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
if (activity instanceof MapActivity) { if (getActivity() instanceof MapActivity) {
((MapActivity) activity).enableDrawer(); ((MapActivity) getActivity()).enableDrawer();
} }
} }
} }

View file

@ -189,8 +189,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean mIsDestroyed = false; private boolean mIsDestroyed = false;
private InAppHelper inAppHelper; private InAppHelper inAppHelper;
private SecondSplashScreenFragment secondSplashScreenFragment;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(AndroidUiHelper.getScreenOrientation(this)); setRequestedOrientation(AndroidUiHelper.getScreenOrientation(this));
@ -694,8 +692,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
FirstUsageWelcomeFragment.SHOW = false; FirstUsageWelcomeFragment.SHOW = false;
if (SecondSplashScreenFragment.SHOW) { if (SecondSplashScreenFragment.SHOW) {
secondSplashScreenFragment = new SecondSplashScreenFragment(); SecondSplashScreenFragment.SHOW = false;
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, secondSplashScreenFragment, SecondSplashScreenFragment.TAG).commitAllowingStateLoss(); getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragmentContainer, new SecondSplashScreenFragment(), SecondSplashScreenFragment.TAG)
.commitAllowingStateLoss();
} else { } else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) { if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
@ -707,7 +708,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
public void dismissSecondSplashScreen() { public void dismissSecondSplashScreen() {
SecondSplashScreenFragment.SHOW = false; SecondSplashScreenFragment.SHOW = false;
getSupportFragmentManager().beginTransaction().remove(secondSplashScreenFragment).commitAllowingStateLoss(); getSupportFragmentManager()
.beginTransaction()
.remove(getSupportFragmentManager().findFragmentByTag(SecondSplashScreenFragment.TAG))
.commitAllowingStateLoss();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
if (app.getSettings().MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) { if (app.getSettings().MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
setRequestedOrientation(app.getSettings().MAP_SCREEN_ORIENTATION.get()); setRequestedOrientation(app.getSettings().MAP_SCREEN_ORIENTATION.get());