Refactor the updating of the status bar color

This commit is contained in:
Alex Sytnyk 2018-10-24 19:25:55 +03:00
parent 4a2b9abda1
commit 180a26077f
7 changed files with 47 additions and 20 deletions

View file

@ -862,23 +862,20 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
int color = -1;
boolean mapControlsVisible = findViewById(R.id.MapHudButtonsOverlay).getVisibility() == View.VISIBLE;
boolean night = app.getDaynightHelper().isNightModeForMapControls();
TopToolbarController discountController = getTopToolbarController(TopToolbarControllerType.DISCOUNT);
boolean quickSearchTopBar = getTopToolbarController(TopToolbarControllerType.QUICK_SEARCH) != null;
boolean contextMenuTopBar = getTopToolbarController(TopToolbarControllerType.CONTEXT_MENU) != null;
boolean poiFilterTopBar = getTopToolbarController(TopToolbarControllerType.POI_FILTER) != null;
TopToolbarController toolbarController = getMapLayers().getMapInfoLayer().getTopToolbarController();
if (toolbarController != null && mapControlsVisible) {
color = toolbarController.getStatusBarColor(this, night);
}
if (color == -1) {
boolean mapTopBar = findViewById(R.id.map_top_bar).getVisibility() == View.VISIBLE;
boolean markerTopBar = findViewById(R.id.map_markers_top_bar).getVisibility() == View.VISIBLE;
if (discountController != null) {
color = ((DiscountBarController) discountController).getStatusBarColor();
}
if (((quickSearchTopBar || poiFilterTopBar || mapTopBar) && mapControlsVisible) || contextMenuTopBar) {
if (mapTopBar && mapControlsVisible) {
colorId = night ? R.color.status_bar_route_dark : R.color.status_bar_route_light;
} else if (markerTopBar && mapControlsVisible) {
colorId = R.color.status_bar_dark;
} else {
colorId = night ? R.color.status_bar_transparent_dark : R.color.status_bar_transparent_light;
}
if (color == -1) {
color = ContextCompat.getColor(this, colorId);
}
getWindow().setStatusBarColor(color);

View file

@ -1,6 +1,7 @@
package net.osmand.plus.helpers;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
@ -332,7 +333,7 @@ public class DiscountHelper {
public static class DiscountBarController extends TopToolbarController {
private int statusBarColor;
private int statusBarColor = -1;
DiscountBarController() {
super(TopToolbarControllerType.DISCOUNT);
@ -345,11 +346,12 @@ public class DiscountHelper {
R.drawable.discount_bar_bg_land, R.drawable.discount_bar_bg_land);
}
public int getStatusBarColor() {
@Override
public int getStatusBarColor(Context context, boolean night) {
return statusBarColor;
}
public void setStatusBarColor(int statusBarColor) {
void setStatusBarColor(int statusBarColor) {
this.statusBarColor = statusBarColor;
}
}

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapcontextmenu.other;
import android.content.Context;
import android.graphics.Matrix;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
@ -24,14 +25,14 @@ import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.AndroidUiHelper;
@ -630,6 +631,11 @@ public class TrackDetailsMenu {
super.updateToolbar(view);
view.getShadowView().setVisibility(View.GONE);
}
@Override
public int getStatusBarColor(Context context, boolean night) {
return -1;
}
}
public class TrackChartPoints {

View file

@ -1,6 +1,7 @@
package net.osmand.plus.mapmarkers;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
@ -965,5 +966,10 @@ public class PlanRouteFragment extends BaseOsmAndFragment implements OsmAndLocat
shadow.setVisibility(View.GONE);
}
}
@Override
public int getStatusBarColor(Context context, boolean night) {
return -1;
}
}
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.measurementtool;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
@ -1579,5 +1580,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
shadow.setVisibility(View.GONE);
}
}
@Override
public int getStatusBarColor(Context context, boolean night) {
return -1;
}
}
}

View file

@ -126,6 +126,10 @@ public class MapInfoLayer extends OsmandMapLayer {
return topToolbarView.getTopController() != null;
}
public TopToolbarController getTopToolbarController() {
return topToolbarView == null ? null : topToolbarView.getTopController();
}
public TopToolbarController getTopToolbarController(TopToolbarControllerType type) {
return topToolbarView == null ? null : topToolbarView.getController(type);
}

View file

@ -1,5 +1,6 @@
package net.osmand.plus.views.mapwidgets;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
@ -318,6 +319,11 @@ public class MapInfoWidgetsFactory {
return type;
}
@ColorInt
public int getStatusBarColor(Context context, boolean night) {
return ContextCompat.getColor(context, night ? R.color.status_bar_route_dark : R.color.status_bar_route_light);
}
public void setTitle(String title) {
this.title = title;
}