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.Version;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.base.FailSafeFuntions;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.dashboard.DashboardOnMap;
@ -802,6 +803,18 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
public void updateStatusBarColor() {
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 markerTopBar = mapLayers.getMapMarkersLayer().getWidgetsFactory().isTopBarVisible();
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() {
if (SecondSplashScreenFragment.VISIBLE) {
SecondSplashScreenFragment.VISIBLE = false;

View file

@ -1,5 +1,6 @@
package net.osmand.plus.base;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.ColorInt;
@ -14,6 +15,7 @@ import android.widget.ImageView;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity;
public class BaseOsmAndFragment extends Fragment {
@ -24,10 +26,15 @@ public class BaseOsmAndFragment extends Fragment {
@Override
public void onResume() {
super.onResume();
if (Build.VERSION.SDK_INT >= 21) {
if (Build.VERSION.SDK_INT >= 21 && getStatusBarColorId() != -1) {
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
@ -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
protected int getStatusBarColor() {
public int getStatusBarColorId() {
return -1;
}

View file

@ -7,6 +7,7 @@ import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.ColorRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
@ -770,6 +771,11 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
addOrUpdateDashboardFragments();
}
@ColorRes
public int getStatusBarColor() {
return R.color.status_bar_transparent_gradient;
}
public void setDashboardVisibility(boolean visible, DashboardType type, DashboardType prevItem, boolean animation) {
if (visible == this.visible && type == visibleType) {
return;
@ -797,6 +803,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
}
removeMapillaryFiltersFragment();
mapActivity.updateStatusBarColor();
if (visible) {
mapActivity.dismissCardDialog();
mapActivity.getContextMenu().hideMenues();
@ -866,9 +874,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
updateLocation(true, true, false);
// addOrUpdateDashboardFragments();
mapActivity.getRoutingHelper().addListener(this);
if (Build.VERSION.SDK_INT >= 21) {
mapActivity.getWindow().setStatusBarColor(ContextCompat.getColor(mapActivity, R.color.status_bar_transparent_gradient));
}
} else {
mapActivity.getMapViewTrackingUtilities().setDashboard(null);
hide(dashboardView.findViewById(R.id.animateContent), animation);
@ -893,9 +898,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
fragment.show(mapActivity.getSupportFragmentManager(), MapillaryFirstDialogFragment.TAG);
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
protected int getStatusBarColor() {
if (menu.getCurrentMenuState() == MenuState.FULL_SCREEN || menu.isLandscapeLayout()) {
public int getStatusBarColorId() {
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_transparent_dark : R.color.status_bar_transparent_light;
@ -1232,7 +1232,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
break;
}
if (!menu.isLandscapeLayout()) {
setupStatusBarColor();
getMapActivity().updateStatusBarColor();
}
return posY;
}

View file

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

View file

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

View file

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

View file

@ -385,7 +385,7 @@ public class PlanRouteFragment extends BaseOsmAndFragment implements OsmAndLocat
}
@Override
protected int getStatusBarColor() {
public int getStatusBarColorId() {
if (fullScreen) {
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
protected int getStatusBarColor() {
public int getStatusBarColorId() {
return R.color.status_bar_transparent_gradient;
}