Add splash screen for phone and tablet from code
This commit is contained in:
parent
65d13cc991
commit
0741d3a042
12 changed files with 65 additions and 144 deletions
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:opacity="opaque">
|
||||
<item android:drawable="@color/map_background_color_light"/>
|
||||
<item android:top="24dp">
|
||||
<bitmap
|
||||
android:gravity="center_horizontal|top"
|
||||
android:src="@drawable/ic_logo_splash_osmand"/>
|
||||
</item>
|
||||
<item android:bottom="48dp">
|
||||
<bitmap
|
||||
android:gravity="center_horizontal|bottom"
|
||||
android:src="@drawable/image_text_osmand"/>
|
||||
</item>
|
||||
</layer-list>
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:opacity="opaque">
|
||||
<item android:drawable="@color/map_background_color_light"/>
|
||||
<item android:top="24dp">
|
||||
<bitmap
|
||||
android:gravity="center_horizontal|top"
|
||||
android:src="@drawable/ic_logo_splash_osmand"/>
|
||||
</item>
|
||||
<item android:bottom="48dp">
|
||||
<bitmap
|
||||
android:gravity="center_horizontal|bottom"
|
||||
android:src="@drawable/image_text_osmand"/>
|
||||
</item>
|
||||
</layer-list>
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:opacity="opaque">
|
||||
<item android:drawable="@color/map_background_color_light"/>
|
||||
<item android:top="24dp">
|
||||
<bitmap
|
||||
android:gravity="center_horizontal|top"
|
||||
android:src="@drawable/ic_logo_splash_osmand_plus"/>
|
||||
</item>
|
||||
</layer-list>
|
|
@ -2,14 +2,9 @@
|
|||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:opacity="opaque">
|
||||
<item android:drawable="@color/map_background_color_light"/>
|
||||
<item android:top="150dp">
|
||||
<item android:top="@dimen/splash_screen_logo_top">
|
||||
<bitmap
|
||||
android:gravity="center_horizontal|top"
|
||||
android:src="@drawable/ic_logo_splash_osmand"/>
|
||||
</item>
|
||||
<item android:bottom="128dp">
|
||||
<bitmap
|
||||
android:gravity="center_horizontal|bottom"
|
||||
android:src="@drawable/image_text_osmand"/>
|
||||
</item>
|
||||
</layer-list>
|
|
@ -2,14 +2,9 @@
|
|||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:opacity="opaque">
|
||||
<item android:drawable="@color/map_background_color_light"/>
|
||||
<item android:top="150dp">
|
||||
<item android:top="@dimen/splash_screen_logo_top">
|
||||
<bitmap
|
||||
android:gravity="center_horizontal|top"
|
||||
android:src="@drawable/ic_logo_splash_osmand"/>
|
||||
</item>
|
||||
<item android:bottom="128dp">
|
||||
<bitmap
|
||||
android:gravity="center_horizontal|bottom"
|
||||
android:src="@drawable/image_text_osmand"/>
|
||||
</item>
|
||||
</layer-list>
|
|
@ -2,7 +2,7 @@
|
|||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:opacity="opaque">
|
||||
<item android:drawable="@color/map_background_color_light"/>
|
||||
<item android:top="150dp">
|
||||
<item android:top="@dimen/splash_screen_logo_top">
|
||||
<bitmap
|
||||
android:gravity="center_horizontal|top"
|
||||
android:src="@drawable/ic_logo_splash_osmand_plus"/>
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="map_go_button_width">200dp</dimen>
|
||||
|
||||
<dimen name="splash_screen_logo_top">24dp</dimen>
|
||||
<dimen name="splash_screen_text_bottom">48dp</dimen>
|
||||
</resources>
|
5
OsmAnd/res/values-sw600dp-land/sizes.xml
Normal file
5
OsmAnd/res/values-sw600dp-land/sizes.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="splash_screen_logo_top">200dp</dimen>
|
||||
<dimen name="splash_screen_text_bottom">150dp</dimen>
|
||||
</resources>
|
5
OsmAnd/res/values-sw600dp-port/sizes.xml
Normal file
5
OsmAnd/res/values-sw600dp-port/sizes.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="splash_screen_logo_top">300dp</dimen>
|
||||
<dimen name="splash_screen_text_bottom">200dp</dimen>
|
||||
</resources>
|
|
@ -138,4 +138,7 @@
|
|||
<dimen name="default_split_segments_sub">10sp</dimen>
|
||||
|
||||
<dimen name="dialog_header_text_size">20sp</dimen>
|
||||
|
||||
<dimen name="splash_screen_logo_top">150dp</dimen>
|
||||
<dimen name="splash_screen_text_bottom">128dp</dimen>
|
||||
</resources>
|
|
@ -6,14 +6,12 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -24,7 +22,7 @@ public class SecondSplashScreenFragment extends Fragment {
|
|||
public static boolean SHOW = true;
|
||||
private static final int SECOND_SPLASH_TIME_OUT = 2000;
|
||||
|
||||
public boolean hasNavBar () {
|
||||
private boolean hasNavBar() {
|
||||
int id = getResources().getIdentifier("config_showNavigationBar", "bool", "android");
|
||||
if (id > 0)
|
||||
return getResources().getBoolean(id);
|
||||
|
@ -32,7 +30,7 @@ public class SecondSplashScreenFragment extends Fragment {
|
|||
return false;
|
||||
}
|
||||
|
||||
public int getStatusBarHeight() {
|
||||
private int getStatusBarHeight() {
|
||||
int statusBarHeight = 0;
|
||||
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
|
@ -41,42 +39,29 @@ public class SecondSplashScreenFragment extends Fragment {
|
|||
return statusBarHeight;
|
||||
}
|
||||
|
||||
public int getNavigationBarHeight () {
|
||||
private int getNavigationBarHeight() {
|
||||
if (!hasNavBar())
|
||||
return 0;
|
||||
|
||||
int orientation = getResources().getConfiguration().orientation;
|
||||
|
||||
boolean isSmartphone = getResources().getConfiguration().smallestScreenWidthDp < 600;
|
||||
if (isSmartphone && Configuration.ORIENTATION_LANDSCAPE == orientation)
|
||||
return 0;
|
||||
|
||||
int id = getResources().getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android");
|
||||
if (id > 0)
|
||||
return getResources().getDimensionPixelSize(id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isSmartphone() {
|
||||
return getResources().getConfiguration().smallestScreenWidthDp < 600;
|
||||
}
|
||||
|
||||
public int getNavigationBarWidth ()
|
||||
{
|
||||
private int getNavigationBarWidth() {
|
||||
if (!hasNavBar())
|
||||
return 0;
|
||||
|
||||
int orientation = getResources().getConfiguration().orientation;
|
||||
|
||||
boolean isSmartphone = getResources().getConfiguration().smallestScreenWidthDp < 600;
|
||||
|
||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE && isSmartphone) {
|
||||
int id = getResources().getIdentifier("navigation_bar_width", "dimen", "android");
|
||||
if (id > 0)
|
||||
return getResources().getDimensionPixelSize(id);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -91,34 +76,6 @@ public class SecondSplashScreenFragment extends Fragment {
|
|||
RelativeLayout.LayoutParams logoLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
|
||||
logoLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
|
||||
logoLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
|
||||
if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
|
||||
AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
|
||||
int defaultLogoMarginTop = AndroidUtils.dpToPx(getActivity(), 150);
|
||||
logoLayoutParams.setMargins(0, defaultLogoMarginTop - getStatusBarHeight(), 0, 0);
|
||||
} else if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
|
||||
AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
|
||||
if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
|
||||
int defaultLogoMarginTop = AndroidUtils.dpToPx(getActivity(), 24);
|
||||
int logoPaddingLeft = getNavigationBarWidth();
|
||||
logo.setPadding(logoPaddingLeft, 0, 0, 0);
|
||||
logoLayoutParams.setMargins(0, defaultLogoMarginTop - getStatusBarHeight(), 0, 0);
|
||||
} else if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
|
||||
int defaultLogoMarginTop = AndroidUtils.dpToPx(getActivity(), 24);
|
||||
int logoPaddingRight = getNavigationBarWidth();
|
||||
logo.setPadding(0, 0, logoPaddingRight, 0);
|
||||
logoLayoutParams.setMargins(0, defaultLogoMarginTop - getStatusBarHeight(), 0, 0);
|
||||
}
|
||||
} else {
|
||||
int defaultLogoMarginTop = AndroidUtils.dpToPx(getActivity(), 24);
|
||||
int logoPaddingLeft = getNavigationBarWidth();
|
||||
logo.setPadding(logoPaddingLeft, 0, 0, 0);
|
||||
logoLayoutParams.setMargins(0, defaultLogoMarginTop - getStatusBarHeight(), 0, 0);
|
||||
}
|
||||
}
|
||||
logo.setLayoutParams(logoLayoutParams);
|
||||
view.addView(logo);
|
||||
|
||||
ImageView text = new ImageView(getActivity());
|
||||
if (Version.isFreeVersion(((MapActivity) getActivity()).getMyApplication())) {
|
||||
text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand));
|
||||
|
@ -129,50 +86,53 @@ public class SecondSplashScreenFragment extends Fragment {
|
|||
RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
|
||||
textLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
textLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
|
||||
if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
|
||||
AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
|
||||
int defaultTextMarginBottom = AndroidUtils.dpToPx(getActivity(), 128);
|
||||
Log.d("PORTRAIT", "defaultTextMarginBottom: " + defaultTextMarginBottom);
|
||||
Log.d("PORTRAIT", "getNavigationBarHeight: " + getNavigationBarHeight());
|
||||
textLayoutParams.setMargins(0, 0, 0, defaultTextMarginBottom - getNavigationBarHeight());
|
||||
} else if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
|
||||
AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
|
||||
if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
|
||||
int defaultTextMarginBottom = AndroidUtils.dpToPx(getActivity(), 48);
|
||||
int textPaddingLeft = getNavigationBarWidth();
|
||||
text.setPadding(textPaddingLeft, 0, 0, 0);
|
||||
textLayoutParams.setMargins(0, 0, 0, defaultTextMarginBottom);
|
||||
} else if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
|
||||
int defaultTextMarginBottom = AndroidUtils.dpToPx(getActivity(), 48);
|
||||
int textPaddingRight = getNavigationBarWidth();
|
||||
text.setPadding(0, 0, textPaddingRight, 0);
|
||||
textLayoutParams.setMargins(0, 0, 0, defaultTextMarginBottom);
|
||||
}
|
||||
} else {
|
||||
int defaultTextMarginBottom = AndroidUtils.dpToPx(getActivity(), 48);
|
||||
int textPaddingLeft = getNavigationBarWidth();
|
||||
text.setPadding(textPaddingLeft, 0, 0, 0);
|
||||
textLayoutParams.setMargins(0, 0, 0, defaultTextMarginBottom);
|
||||
int defaultLogoMarginTop = (int) getResources().getDimension(R.dimen.splash_screen_logo_top);
|
||||
int logoMarginTop = defaultLogoMarginTop - getStatusBarHeight();
|
||||
int logoPaddingLeft = 0;
|
||||
int logoPaddingRight = 0;
|
||||
int defaultTextMarginBottom = (int) getResources().getDimension(R.dimen.splash_screen_text_bottom);
|
||||
int textMarginBottom = defaultTextMarginBottom - getNavigationBarHeight();
|
||||
int textPaddingLeft = 0;
|
||||
int textPaddingRight = 0;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
|
||||
if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
|
||||
logoPaddingLeft = getNavigationBarWidth();
|
||||
textPaddingLeft = getNavigationBarWidth();
|
||||
} else if (AndroidUiHelper.getScreenOrientation(getActivity()) == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
|
||||
logoPaddingRight = getNavigationBarWidth();
|
||||
textPaddingRight = getNavigationBarWidth();
|
||||
}
|
||||
} else {
|
||||
logoPaddingLeft = getNavigationBarWidth();
|
||||
textPaddingLeft = getNavigationBarWidth();
|
||||
}
|
||||
logoLayoutParams.setMargins(0, logoMarginTop, 0, 0);
|
||||
logo.setPadding(logoPaddingLeft, 0, logoPaddingRight, 0);
|
||||
logo.setLayoutParams(logoLayoutParams);
|
||||
view.addView(logo);
|
||||
textLayoutParams.setMargins(0, 0, 0, textMarginBottom);
|
||||
text.setPadding(textPaddingLeft, 0, textPaddingRight, 0);
|
||||
text.setLayoutParams(textLayoutParams);
|
||||
view.addView(text);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
// if (((MapActivity)getActivity()).getMyApplication().getSettings().MAP_SCREEN_ORIENTATION.get() != getActivity().getRequestedOrientation()) {
|
||||
// getActivity().setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get());
|
||||
// // can't return from this method we are not sure if activity will be recreated or not
|
||||
// }
|
||||
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
if (((MapActivity)getActivity()).getMyApplication().getSettings().MAP_SCREEN_ORIENTATION.get() != getActivity().getRequestedOrientation()) {
|
||||
getActivity().setRequestedOrientation(((MapActivity)getActivity()).getMyApplication().getSettings().MAP_SCREEN_ORIENTATION.get());
|
||||
// can't return from this method we are not sure if activity will be recreated or not
|
||||
}
|
||||
getActivity().getSupportFragmentManager().beginTransaction().remove(SecondSplashScreenFragment.this).commitAllowingStateLoss();
|
||||
}
|
||||
}, SECOND_SPLASH_TIME_OUT);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -191,7 +191,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
// setRequestedOrientation(AndroidUiHelper.getScreenOrientation(this));
|
||||
setRequestedOrientation(AndroidUiHelper.getScreenOrientation(this));
|
||||
overridePendingTransition(0, 0);
|
||||
long tm = System.currentTimeMillis();
|
||||
app = getMyApplication();
|
||||
|
@ -548,10 +548,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().hide();
|
||||
}
|
||||
if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
|
||||
setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get());
|
||||
// can't return from this method we are not sure if activity will be recreated or not
|
||||
}
|
||||
|
||||
app.getLocationProvider().checkIfLastKnownLocationIsValid();
|
||||
// for voice navigation
|
||||
|
@ -697,14 +693,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
FirstUsageWelcomeFragment.SHOW = false;
|
||||
if (SecondSplashScreenFragment.SHOW) {
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, new SecondSplashScreenFragment(), SecondSplashScreenFragment.TAG).commitAllowingStateLoss();
|
||||
} else {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
|
||||
setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get());
|
||||
// can't return from this method we are not sure if activity will be recreated or not
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
// if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
|
||||
// setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get());
|
||||
// // can't return from this method we are not sure if activity will be recreated or not
|
||||
// }
|
||||
// }
|
||||
SecondSplashScreenFragment.SHOW = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue