Change status bar color update logic

This commit is contained in:
alex 2017-11-06 16:08:37 +02:00
parent ff86ebfb3e
commit 7eb05bbf8b
9 changed files with 54 additions and 24 deletions

View file

@ -72,6 +72,7 @@ import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.base.FailSafeFuntions; import net.osmand.plus.base.FailSafeFuntions;
import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.DashboardOnMap;
@ -802,6 +803,18 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
public void updateStatusBarColor() { public void updateStatusBarColor() {
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21) {
Fragment fragment = getVisibleFragment(getSupportFragmentManager());
if (fragment != null && fragment instanceof BaseOsmAndFragment) {
BaseOsmAndFragment f = (BaseOsmAndFragment) fragment;
if (f.getStatusBarColorId() != -1) {
getWindow().setStatusBarColor(ContextCompat.getColor(this, f.getStatusBarColorId()));
return;
}
}
if (dashboardOnMap.isVisible()) {
getWindow().setStatusBarColor(ContextCompat.getColor(this, dashboardOnMap.getStatusBarColor()));
return;
}
boolean night = app.getDaynightHelper().isNightModeForMapControls(); boolean night = app.getDaynightHelper().isNightModeForMapControls();
boolean markerTopBar = mapLayers.getMapMarkersLayer().getWidgetsFactory().isTopBarVisible(); boolean markerTopBar = mapLayers.getMapMarkersLayer().getWidgetsFactory().isTopBarVisible();
int colorId; int colorId;
@ -814,6 +827,20 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
} }
private Fragment getVisibleFragment(FragmentManager fm) {
int[] ids = new int[]{R.id.topFragmentContainer,
R.id.routeMenuContainer,
R.id.fragmentContainer,
R.id.bottomFragmentContainer};
for (int id : ids) {
Fragment fragment = fm.findFragmentById(id);
if (fragment != null) {
return fragment;
}
}
return null;
}
private void dismissSecondSplashScreen() { private void dismissSecondSplashScreen() {
if (SecondSplashScreenFragment.VISIBLE) { if (SecondSplashScreenFragment.VISIBLE) {
SecondSplashScreenFragment.VISIBLE = false; SecondSplashScreenFragment.VISIBLE = false;

View file

@ -1,5 +1,6 @@
package net.osmand.plus.base; package net.osmand.plus.base;
import android.app.Activity;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
@ -14,6 +15,7 @@ import android.widget.ImageView;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.activities.OsmandActionBarActivity;
public class BaseOsmAndFragment extends Fragment { public class BaseOsmAndFragment extends Fragment {
@ -24,10 +26,15 @@ public class BaseOsmAndFragment extends Fragment {
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21 && getStatusBarColorId() != -1) {
statusBarColor = getActivity().getWindow().getStatusBarColor(); statusBarColor = getActivity().getWindow().getStatusBarColor();
Activity activity = getActivity();
if (activity instanceof MapActivity) {
((MapActivity) activity).updateStatusBarColor();
} else if (getStatusBarColorId() != -1) {
getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(getActivity(), getStatusBarColorId()));
}
} }
setupStatusBarColor();
} }
@Override @Override
@ -38,14 +45,8 @@ public class BaseOsmAndFragment extends Fragment {
} }
} }
protected void setupStatusBarColor() {
if (Build.VERSION.SDK_INT >= 21 && getStatusBarColor() != -1) {
getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(getActivity(), getStatusBarColor()));
}
}
@ColorRes @ColorRes
protected int getStatusBarColor() { public int getStatusBarColorId() {
return -1; return -1;
} }

View file

@ -7,6 +7,7 @@ import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.support.annotation.ColorRes;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
@ -770,6 +771,11 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
addOrUpdateDashboardFragments(); addOrUpdateDashboardFragments();
} }
@ColorRes
public int getStatusBarColor() {
return R.color.status_bar_transparent_gradient;
}
public void setDashboardVisibility(boolean visible, DashboardType type, DashboardType prevItem, boolean animation) { public void setDashboardVisibility(boolean visible, DashboardType type, DashboardType prevItem, boolean animation) {
if (visible == this.visible && type == visibleType) { if (visible == this.visible && type == visibleType) {
return; return;
@ -797,6 +803,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
} }
removeMapillaryFiltersFragment(); removeMapillaryFiltersFragment();
mapActivity.updateStatusBarColor();
if (visible) { if (visible) {
mapActivity.dismissCardDialog(); mapActivity.dismissCardDialog();
mapActivity.getContextMenu().hideMenues(); mapActivity.getContextMenu().hideMenues();
@ -866,9 +874,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
updateLocation(true, true, false); updateLocation(true, true, false);
// addOrUpdateDashboardFragments(); // addOrUpdateDashboardFragments();
mapActivity.getRoutingHelper().addListener(this); mapActivity.getRoutingHelper().addListener(this);
if (Build.VERSION.SDK_INT >= 21) {
mapActivity.getWindow().setStatusBarColor(ContextCompat.getColor(mapActivity, R.color.status_bar_transparent_gradient));
}
} else { } else {
mapActivity.getMapViewTrackingUtilities().setDashboard(null); mapActivity.getMapViewTrackingUtilities().setDashboard(null);
hide(dashboardView.findViewById(R.id.animateContent), animation); hide(dashboardView.findViewById(R.id.animateContent), animation);
@ -893,9 +898,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
fragment.show(mapActivity.getSupportFragmentManager(), MapillaryFirstDialogFragment.TAG); fragment.show(mapActivity.getSupportFragmentManager(), MapillaryFirstDialogFragment.TAG);
settings.MAPILLARY_FIRST_DIALOG_SHOWN.set(true); settings.MAPILLARY_FIRST_DIALOG_SHOWN.set(true);
} }
if (Build.VERSION.SDK_INT >= 21) {
mapActivity.updateStatusBarColor();
}
} }
} }

View file

@ -521,8 +521,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
} }
@Override @Override
protected int getStatusBarColor() { public int getStatusBarColorId() {
if (menu.getCurrentMenuState() == MenuState.FULL_SCREEN || menu.isLandscapeLayout()) { if (menu != null && (menu.getCurrentMenuState() == MenuState.FULL_SCREEN || menu.isLandscapeLayout())) {
return nightMode ? R.color.status_bar_dark : R.color.status_bar_route_light; return nightMode ? R.color.status_bar_dark : R.color.status_bar_route_light;
} }
return nightMode ? R.color.status_bar_transparent_dark : R.color.status_bar_transparent_light; return nightMode ? R.color.status_bar_transparent_dark : R.color.status_bar_transparent_light;
@ -1232,7 +1232,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
break; break;
} }
if (!menu.isLandscapeLayout()) { if (!menu.isLandscapeLayout()) {
setupStatusBarColor(); getMapActivity().updateStatusBarColor();
} }
return posY; return posY;
} }

View file

@ -114,7 +114,7 @@ public class ContextMenuCardDialogFragment extends BaseOsmAndFragment {
} }
@Override @Override
protected int getStatusBarColor() { public int getStatusBarColorId() {
if (dialog != null && dialog.getType() == ContextMenuCardDialog.CardDialogType.MAPILLARY) { if (dialog != null && dialog.getType() == ContextMenuCardDialog.CardDialogType.MAPILLARY) {
return R.color.status_bar_mapillary; return R.color.status_bar_mapillary;
} }

View file

@ -216,8 +216,8 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
} }
@Override @Override
protected int getStatusBarColor() { public int getStatusBarColorId() {
return getEditor().isLight() ? R.color.status_bar_light : R.color.status_bar_dark; return R.color.status_bar_light;
} }
private void hideKeyboard() { private void hideKeyboard() {

View file

@ -109,7 +109,7 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment {
} }
@Override @Override
protected int getStatusBarColor() { public int getStatusBarColorId() {
return R.color.status_bar_transparent_gradient; return R.color.status_bar_transparent_gradient;
} }

View file

@ -385,7 +385,7 @@ public class PlanRouteFragment extends BaseOsmAndFragment implements OsmAndLocat
} }
@Override @Override
protected int getStatusBarColor() { public int getStatusBarColorId() {
if (fullScreen) { if (fullScreen) {
return nightMode ? R.color.status_bar_dark : R.color.status_bar_route_light; return nightMode ? R.color.status_bar_dark : R.color.status_bar_route_light;
} }

View file

@ -480,7 +480,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
} }
@Override @Override
protected int getStatusBarColor() { public int getStatusBarColorId() {
return R.color.status_bar_transparent_gradient; return R.color.status_bar_transparent_gradient;
} }