Add paddings from code for second splash

This commit is contained in:
PavelRatushny 2017-07-11 12:35:29 +03:00
parent 54feb6e00c
commit 8ee0a07792
2 changed files with 52 additions and 33 deletions

View file

@ -13,7 +13,9 @@ 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;
import net.osmand.plus.helpers.AndroidUiHelper;
@ -45,7 +47,6 @@ public class SecondSplashScreenFragment extends Fragment {
int orientation = getResources().getConfiguration().orientation;
//Only phone between 0-599 has navigationbar can move
boolean isSmartphone = getResources().getConfiguration().smallestScreenWidthDp < 600;
if (isSmartphone && Configuration.ORIENTATION_LANDSCAPE == orientation)
return 0;
@ -57,6 +58,10 @@ public class SecondSplashScreenFragment extends Fragment {
return 0;
}
public boolean isSmartphone() {
return getResources().getConfiguration().smallestScreenWidthDp < 600;
}
public int getNavigationBarWidth ()
{
if (!hasNavBar())
@ -64,11 +69,9 @@ public class SecondSplashScreenFragment extends Fragment {
int orientation = getResources().getConfiguration().orientation;
//Only phone between 0-599 has navigationbar can move
boolean isSmartphone = getResources().getConfiguration().smallestScreenWidthDp < 600;
if (orientation == Configuration.ORIENTATION_LANDSCAPE && isSmartphone)
{
if (orientation == Configuration.ORIENTATION_LANDSCAPE && isSmartphone) {
int id = getResources().getIdentifier("navigation_bar_width", "dimen", "android");
if (id > 0)
return getResources().getDimensionPixelSize(id);
@ -97,47 +100,59 @@ public class SecondSplashScreenFragment extends Fragment {
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 logoMarginLeft = getNavigationBarWidth();
logoLayoutParams.setMargins(logoMarginLeft, defaultLogoMarginTop - getStatusBarHeight(), 0, 0);
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 logoMarginRight = getNavigationBarWidth();
logoLayoutParams.setMargins(0, defaultLogoMarginTop - getStatusBarHeight(), logoMarginRight, 0);
int logoPaddingRight = getNavigationBarWidth();
logo.setPadding(0, 0, logoPaddingRight, 0);
logoLayoutParams.setMargins(0, defaultLogoMarginTop - getStatusBarHeight(), 0, 0);
}
} else {
int defaultLogoMarginTop = AndroidUtils.dpToPx(getActivity(), 24);
int logoMarginLeft = getNavigationBarWidth();
logoLayoutParams.setMargins(logoMarginLeft, defaultLogoMarginTop - getStatusBarHeight(), 0, 0);
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));
} else if ((Version.isPaidVersion(((MapActivity) getActivity()).getMyApplication())) ||
(Version.isDeveloperVersion(((MapActivity) getActivity()).getMyApplication()))) {
text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand_plus));
}
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 textMarginLeft = getNavigationBarWidth();
Log.d("LANDSCAPE", "width: " + getNavigationBarWidth());
textLayoutParams.setMargins(textMarginLeft, 0, 0, defaultTextMarginBottom);
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 textMarginRight = getNavigationBarWidth();
Log.d("REVERSE_LANDSCAPE", "width: " + getNavigationBarWidth());
textLayoutParams.setMargins(0, 0, textMarginRight, defaultTextMarginBottom);
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);
}
}
@ -148,6 +163,11 @@ public class SecondSplashScreenFragment extends Fragment {
@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().getSupportFragmentManager().beginTransaction().remove(SecondSplashScreenFragment.this).commitAllowingStateLoss();
}
}, SECOND_SPLASH_TIME_OUT);

View file

@ -10,6 +10,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.net.Uri;
@ -188,23 +189,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean mIsDestroyed = false;
private InAppHelper inAppHelper;
public void hideStatusBar() {
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
public void showStatusBar() {
// getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
@Override
public void onCreate(Bundle savedInstanceState) {
// setRequestedOrientation(AndroidUiHelper.getScreenOrientation(this));
overridePendingTransition(0, 0);
long tm = System.currentTimeMillis();
app = getMyApplication();
@ -235,6 +222,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
mapView = new OsmandMapTileView(this, w, h);
if (app.getAppInitializer().checkAppVersionChanged() && WhatsNewDialogFragment.SHOW) {
SecondSplashScreenFragment.SHOW = false;
WhatsNewDialogFragment.SHOW = false;
new WhatsNewDialogFragment().show(getSupportFragmentManager(), null);
}
@ -542,8 +530,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
dashboardOnMap.setDashboardVisibility(true, DashboardOnMap.staticVisibleType);
} else {
if (ErrorBottomSheetDialog.shouldShow(settings, this)) {
SecondSplashScreenFragment.SHOW = false;
new ErrorBottomSheetDialog().show(getSupportFragmentManager(), "dialog");
} else if (RateUsBottomSheetDialog.shouldShow(app)) {
SecondSplashScreenFragment.SHOW = false;
new RateUsBottomSheetDialog().show(getSupportFragmentManager(), "dialog");
}
}
@ -696,16 +686,25 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
enableDrawer();
if (showWelcomeScreen) {
SecondSplashScreenFragment.SHOW = false;
getSupportFragmentManager().beginTransaction()
.add(R.id.fragmentContainer, new FirstUsageWelcomeFragment(),
FirstUsageWelcomeFragment.TAG).commitAllowingStateLoss();
} else if (!isFirstScreenShowing() && XMasDialogFragment.shouldShowXmasDialog(app)) {
SecondSplashScreenFragment.SHOW = false;
new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG);
}
FirstUsageWelcomeFragment.SHOW = false;
if (!showWelcomeScreen && SecondSplashScreenFragment.SHOW) {
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
// }
// }
SecondSplashScreenFragment.SHOW = false;
}