Replace ColoredStatusBarFragment with BaseOsmAndFragment

This commit is contained in:
alex 2017-11-06 12:40:43 +02:00
parent 9bd832ceb9
commit ff86ebfb3e
8 changed files with 66 additions and 87 deletions

View file

@ -1,11 +1,13 @@
package net.osmand.plus.base;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
@ -17,6 +19,36 @@ import net.osmand.plus.activities.OsmandActionBarActivity;
public class BaseOsmAndFragment extends Fragment {
private IconsCache iconsCache;
private int statusBarColor = -1;
@Override
public void onResume() {
super.onResume();
if (Build.VERSION.SDK_INT >= 21) {
statusBarColor = getActivity().getWindow().getStatusBarColor();
}
setupStatusBarColor();
}
@Override
public void onPause() {
super.onPause();
if (Build.VERSION.SDK_INT >= 21 && statusBarColor != -1) {
getActivity().getWindow().setStatusBarColor(statusBarColor);
}
}
protected void setupStatusBarColor() {
if (Build.VERSION.SDK_INT >= 21 && getStatusBarColor() != -1) {
getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(getActivity(), getStatusBarColor()));
}
}
@ColorRes
protected int getStatusBarColor() {
return -1;
}
protected OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}

View file

@ -1,39 +0,0 @@
package net.osmand.plus.base;
import android.os.Build;
import android.support.annotation.ColorRes;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
public class ColoredStatusBarFragment extends Fragment {
private int statusBarColor = -1;
@Override
public void onResume() {
super.onResume();
if (Build.VERSION.SDK_INT >= 21) {
statusBarColor = getActivity().getWindow().getStatusBarColor();
}
setupStatusBarColor();
}
@Override
public void onPause() {
super.onPause();
if (Build.VERSION.SDK_INT >= 21 && statusBarColor != -1) {
getActivity().getWindow().setStatusBarColor(statusBarColor);
}
}
protected void setupStatusBarColor() {
if (Build.VERSION.SDK_INT >= 21 && getStatusBarColor() != -1) {
getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(getActivity(), getStatusBarColor()));
}
}
@ColorRes
protected int getStatusBarColor() {
return -1;
}
}

View file

@ -33,12 +33,11 @@ import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.ColoredStatusBarFragment;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
@ -55,7 +54,7 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
public class MapContextMenuFragment extends ColoredStatusBarFragment implements DownloadEvents {
public class MapContextMenuFragment extends BaseOsmAndFragment implements DownloadEvents {
public static final String TAG = "MapContextMenuFragment";
public static final float FAB_PADDING_TOP_DP = 4f;
@ -149,8 +148,6 @@ public class MapContextMenuFragment extends ColoredStatusBarFragment implements
mapZoom = map.getZoom();
}
IconsCache iconsCache = getMyApplication().getIconsCache();
// Left title button
final Button leftTitleButton = (Button) view.findViewById(R.id.title_button);
leftTitleButton.setOnClickListener(new View.OnClickListener() {
@ -225,7 +222,7 @@ public class MapContextMenuFragment extends ColoredStatusBarFragment implements
// Progress bar
final ImageView progressButton = (ImageView) view.findViewById(R.id.progressButton);
progressButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark,
progressButton.setImageDrawable(getIcon(R.drawable.ic_action_remove_dark,
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
progressButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -386,7 +383,7 @@ public class MapContextMenuFragment extends ColoredStatusBarFragment implements
// FAB
fabView = (ImageView) view.findViewById(R.id.context_menu_fab_view);
if (menu.fabVisible()) {
fabView.setImageDrawable(iconsCache.getIcon(menu.getFabIconId(), 0));
fabView.setImageDrawable(getIcon(menu.getFabIconId(), 0));
if (menu.isLandscapeLayout()) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) fabView.getLayoutParams();
params.setMargins(0, 0, dpToPx(28f), 0);
@ -446,7 +443,7 @@ public class MapContextMenuFragment extends ColoredStatusBarFragment implements
// Action buttons
final ImageButton buttonFavorite = (ImageButton) view.findViewById(R.id.context_menu_fav_button);
buttonFavorite.setImageDrawable(iconsCache.getIcon(menu.getFavActionIconId(),
buttonFavorite.setImageDrawable(getIcon(menu.getFavActionIconId(),
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
AndroidUtils.setDashButtonBackground(getMapActivity(), buttonFavorite, nightMode);
buttonFavorite.setContentDescription(getString(menu.getFavActionStringId()));
@ -459,11 +456,11 @@ public class MapContextMenuFragment extends ColoredStatusBarFragment implements
final ImageButton buttonWaypoint = (ImageButton) view.findViewById(R.id.context_menu_route_button);
if (getMyApplication().getSettings().USE_MAP_MARKERS.get()) {
buttonWaypoint.setImageDrawable(iconsCache.getIcon(R.drawable.map_action_flag_dark,
buttonWaypoint.setImageDrawable(getIcon(R.drawable.map_action_flag_dark,
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
buttonWaypoint.setContentDescription(getString(R.string.shared_string_add_to_map_markers));
} else {
buttonWaypoint.setImageDrawable(iconsCache.getIcon(R.drawable.map_action_waypoint,
buttonWaypoint.setImageDrawable(getIcon(R.drawable.map_action_waypoint,
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
buttonWaypoint.setContentDescription(getString(R.string.context_menu_item_destination_point));
}
@ -476,7 +473,7 @@ public class MapContextMenuFragment extends ColoredStatusBarFragment implements
});
final ImageButton buttonShare = (ImageButton) view.findViewById(R.id.context_menu_share_button);
buttonShare.setImageDrawable(iconsCache.getIcon(R.drawable.map_action_gshare_dark,
buttonShare.setImageDrawable(getIcon(R.drawable.map_action_gshare_dark,
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
AndroidUtils.setDashButtonBackground(getMapActivity(), buttonShare, nightMode);
buttonShare.setOnClickListener(new View.OnClickListener() {
@ -487,7 +484,7 @@ public class MapContextMenuFragment extends ColoredStatusBarFragment implements
});
final ImageButton buttonMore = (ImageButton) view.findViewById(R.id.context_menu_more_button);
buttonMore.setImageDrawable(iconsCache.getIcon(R.drawable.map_overflow_menu_white,
buttonMore.setImageDrawable(getIcon(R.drawable.map_overflow_menu_white,
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
AndroidUtils.setDashButtonBackground(getMapActivity(), buttonMore, nightMode);
buttonMore.setOnClickListener(new View.OnClickListener() {
@ -858,8 +855,6 @@ public class MapContextMenuFragment extends ColoredStatusBarFragment implements
private void buildHeader() {
OsmandApplication app = getMyApplication();
if (app != null && view != null) {
IconsCache iconsCache = app.getIconsCache();
final View iconLayout = view.findViewById(R.id.context_menu_icon_layout);
final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view);
Drawable icon = menu.getLeftIcon();
@ -868,7 +863,7 @@ public class MapContextMenuFragment extends ColoredStatusBarFragment implements
iconView.setImageDrawable(icon);
iconLayout.setVisibility(View.VISIBLE);
} else if (iconId != 0) {
iconView.setImageDrawable(iconsCache.getIcon(iconId,
iconView.setImageDrawable(getIcon(iconId,
!nightMode ? R.color.osmand_orange : R.color.osmand_orange_dark));
iconLayout.setVisibility(View.VISIBLE);
} else {
@ -955,9 +950,8 @@ public class MapContextMenuFragment extends ColoredStatusBarFragment implements
public void rebuildMenu(boolean centered) {
OsmandApplication app = getMyApplication();
if (app != null && view != null) {
IconsCache iconsCache = app.getIconsCache();
final ImageButton buttonFavorite = (ImageButton) view.findViewById(R.id.context_menu_fav_button);
buttonFavorite.setImageDrawable(iconsCache.getIcon(menu.getFavActionIconId(),
buttonFavorite.setImageDrawable(getIcon(menu.getFavActionIconId(),
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
buttonFavorite.setContentDescription(getString(menu.getFavActionStringId()));

View file

@ -17,12 +17,12 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.ColoredStatusBarFragment;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.mapillary.MapillaryPlugin;
import net.osmand.util.Algorithms;
public class ContextMenuCardDialogFragment extends ColoredStatusBarFragment {
public class ContextMenuCardDialogFragment extends BaseOsmAndFragment {
public static final String TAG = "ContextMenuCardDialogFragment";
private ContextMenuCardDialog dialog;

View file

@ -23,15 +23,14 @@ import android.widget.ScrollView;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.ColoredStatusBarFragment;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.widgets.AutoCompleteTextViewEx;
import net.osmand.util.Algorithms;
public abstract class PointEditorFragment extends ColoredStatusBarFragment {
public abstract class PointEditorFragment extends BaseOsmAndFragment {
private View view;
private EditText nameEdit;
@ -182,9 +181,7 @@ public abstract class PointEditorFragment extends ColoredStatusBarFragment {
}
public Drawable getRowIcon(int iconId) {
IconsCache iconsCache = getMyApplication().getIconsCache();
return iconsCache.getIcon(iconId,
getEditor().isLight() ? R.color.icon_color : R.color.icon_color_light);
return getIcon(iconId, getEditor().isLight() ? R.color.icon_color : R.color.icon_color_light);
}
@Override
@ -331,7 +328,6 @@ public abstract class PointEditorFragment extends ColoredStatusBarFragment {
}
protected Drawable getPaintedIcon(int iconId, int color) {
IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache();
return iconsCache.getPaintedIcon(iconId, color);
return getPaintedContentIcon(iconId, color);
}
}

View file

@ -15,10 +15,10 @@ import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.ColoredStatusBarFragment;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
public class TrackDetailsMenuFragment extends ColoredStatusBarFragment {
public class TrackDetailsMenuFragment extends BaseOsmAndFragment {
public static final String TAG = "TrackDetailsMenuFragment";
private TrackDetailsMenu menu;
@ -168,12 +168,12 @@ public class TrackDetailsMenuFragment extends ColoredStatusBarFragment {
ImageView yAxisArrow = (ImageView) mainView.findViewById(R.id.y_axis_arrow);
ImageView xAxisArrow = (ImageView) mainView.findViewById(R.id.x_axis_arrow);
yAxisArrow.setImageDrawable(ctx.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_arrow_drop_down));
xAxisArrow.setImageDrawable(ctx.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_arrow_drop_down));
yAxisArrow.setImageDrawable(getContentIcon(R.drawable.ic_action_arrow_drop_down));
xAxisArrow.setImageDrawable(getContentIcon(R.drawable.ic_action_arrow_drop_down));
ImageButton backButton = (ImageButton) mainView.findViewById(R.id.top_bar_back_button);
if (backButton != null) {
backButton.setImageDrawable(ctx.getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back, R.color.color_white));
backButton.setImageDrawable(getIcon(R.drawable.ic_arrow_back, R.color.color_white));
}
}

View file

@ -35,7 +35,6 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter;
@ -46,7 +45,7 @@ import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.ColoredStatusBarFragment;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener;
import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback;
@ -66,7 +65,7 @@ import java.util.List;
import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
import static net.osmand.plus.OsmandSettings.MIDDLE_TOP_CONSTANT;
public class PlanRouteFragment extends ColoredStatusBarFragment implements OsmAndLocationListener {
public class PlanRouteFragment extends BaseOsmAndFragment implements OsmAndLocationListener {
public static final String TAG = "PlanRouteFragment";
private static final int MIN_DISTANCE_FOR_RECALCULATE = 50; // in meters
@ -75,7 +74,6 @@ public class PlanRouteFragment extends ColoredStatusBarFragment implements OsmAn
private MarkersPlanRouteContext planRouteContext;
private MapMarkersListAdapter adapter;
private IconsCache iconsCache;
private PlanRouteToolbarController toolbarController;
private int previousMapPosition;
@ -159,7 +157,6 @@ public class PlanRouteFragment extends ColoredStatusBarFragment implements OsmAn
toolbarHeight = mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
iconsCache = mapActivity.getMyApplication().getIconsCache();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final int backgroundColor = ContextCompat.getColor(mapActivity,
@ -436,12 +433,13 @@ public class PlanRouteFragment extends ColoredStatusBarFragment implements OsmAn
return null;
}
private Drawable getContentIcon(@DrawableRes int id) {
return iconsCache.getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color);
@Override
protected Drawable getContentIcon(@DrawableRes int id) {
return getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color);
}
private Drawable getActiveIcon(@DrawableRes int id) {
return iconsCache.getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
return getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
}
private void moveMapToPosition(double lat, double lon) {

View file

@ -42,12 +42,11 @@ import net.osmand.plus.GPXUtilities.Track;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.ColoredStatusBarFragment;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.measurementtool.NewGpxData.ActionType;
@ -79,11 +78,10 @@ import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
import static net.osmand.plus.OsmandSettings.MIDDLE_TOP_CONSTANT;
import static net.osmand.plus.helpers.GpxImportHelper.GPX_SUFFIX;
public class MeasurementToolFragment extends ColoredStatusBarFragment {
public class MeasurementToolFragment extends BaseOsmAndFragment {
public static final String TAG = "MeasurementToolFragment";
private IconsCache iconsCache;
private RecyclerView pointsRv;
private String previousToolBarTitle = "";
private MeasurementToolBarController toolBarController;
@ -181,7 +179,6 @@ public class MeasurementToolFragment extends ColoredStatusBarFragment {
}
editingCtx.getCommandManager().resetMeasurementLayer(measurementLayer);
iconsCache = mapActivity.getMyApplication().getIconsCache();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final int backgroundColor = ContextCompat.getColor(getActivity(),
@ -499,12 +496,13 @@ public class MeasurementToolFragment extends ColoredStatusBarFragment {
return null;
}
private Drawable getContentIcon(@DrawableRes int id) {
return iconsCache.getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color);
@Override
protected Drawable getContentIcon(@DrawableRes int id) {
return getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color);
}
private Drawable getActiveIcon(@DrawableRes int id) {
return iconsCache.getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
return getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
}
private void showProgressBar() {