Hide splash screen when map is shown

This commit is contained in:
PavelRatushny 2017-07-20 13:31:15 +03:00
parent 9b54fb7725
commit e144f0858a
3 changed files with 22 additions and 9 deletions

View file

@ -22,7 +22,7 @@ import net.osmand.plus.helpers.AndroidUiHelper;
public class SecondSplashScreenFragment extends Fragment {
public static final String TAG = "SecondSplashScreenFragment";
public static boolean SHOW = true;
private static final int SECOND_SPLASH_TIME_OUT = 5000;
private static final int SECOND_SPLASH_TIME_OUT = 8000;
private boolean started = false;
private FragmentActivity activity;
private OsmandApplication app;
@ -142,18 +142,15 @@ public class SecondSplashScreenFragment extends Fragment {
}
if (!started) {
started = true;
SecondSplashScreenFragment.SHOW = false;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (activity instanceof MapActivity) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
if (app.getSettings().MAP_SCREEN_ORIENTATION.get() != activity.getRequestedOrientation()) {
activity.setRequestedOrientation(app.getSettings().MAP_SCREEN_ORIENTATION.get());
// can't return from this method we are not sure if activity will be recreated or not
}
android.util.Log.d("Splash", "dismisssplashinsplash");
if (activity instanceof MapActivity && !((MapActivity) activity).isActivityDestroyed()) {
((MapActivity)activity).dismissSecondSplashScreen();
}
activity.getSupportFragmentManager().beginTransaction().remove(SecondSplashScreenFragment.this).commitAllowingStateLoss();
}
}, SECOND_SPLASH_TIME_OUT);
}

View file

@ -189,6 +189,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean mIsDestroyed = false;
private InAppHelper inAppHelper;
private SecondSplashScreenFragment secondSplashScreenFragment;
@Override
public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(AndroidUiHelper.getScreenOrientation(this));
@ -692,7 +694,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
FirstUsageWelcomeFragment.SHOW = false;
if (SecondSplashScreenFragment.SHOW) {
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, new SecondSplashScreenFragment(), SecondSplashScreenFragment.TAG).commitAllowingStateLoss();
secondSplashScreenFragment = new SecondSplashScreenFragment();
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, secondSplashScreenFragment, SecondSplashScreenFragment.TAG).commitAllowingStateLoss();
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
@ -700,7 +703,16 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
// can't return from this method we are not sure if activity will be recreated or not
}
}
}
public void dismissSecondSplashScreen() {
SecondSplashScreenFragment.SHOW = false;
getSupportFragmentManager().beginTransaction().remove(secondSplashScreenFragment).commitAllowingStateLoss();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
if (app.getSettings().MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
setRequestedOrientation(app.getSettings().MAP_SCREEN_ORIENTATION.get());
// can't return from this method we are not sure if activity will be recreated or not
}
}
@Override

View file

@ -29,6 +29,7 @@ import android.view.WindowManager;
import android.widget.Toast;
import net.osmand.PlatformUtil;
import net.osmand.SecondSplashScreenFragment;
import net.osmand.access.AccessibilityActionsProvider;
import net.osmand.core.android.MapRendererView;
import net.osmand.data.LatLon;
@ -655,6 +656,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
} else if (doubleTapScaleDetector.isInZoomMode()) {
drawMapPosition(canvas, doubleTapScaleDetector.getCenterX(), doubleTapScaleDetector.getCenterY());
}
if (activity instanceof MapActivity && !((MapActivity) activity).isActivityDestroyed() && ((MapActivity) activity).getSupportFragmentManager().findFragmentByTag(SecondSplashScreenFragment.TAG) != null) {
((MapActivity) activity).dismissSecondSplashScreen();
}
}