icons fixed and refactored

This commit is contained in:
simon 2020-08-20 12:55:29 +03:00
parent 67f19eb9ce
commit 2f36b59ae7
4 changed files with 50 additions and 59 deletions

View file

@ -3,7 +3,6 @@ package net.osmand.plus;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -104,7 +103,7 @@ public class FavouritesDbHelper {
} }
public int getColor() { public int getColor() {
return color; return color;
} }
public boolean isVisible() { public boolean isVisible() {
@ -138,7 +137,7 @@ public class FavouritesDbHelper {
if (favoriteGroup != null) { if (favoriteGroup != null) {
int color = favoriteGroup.getColor() == 0 ? int color = favoriteGroup.getColor() == 0 ?
context.getResources().getColor(R.color.color_favorite) : favoriteGroup.getColor(); context.getResources().getColor(R.color.color_favorite) : favoriteGroup.getColor();
return context.getUIUtilities().getPaintedIcon(R.drawable.ic_action_folder, color); return context.getUIUtilities().getPaintedIcon(R.drawable.ic_action_group_name_16, color);
} }
return null; return null;
} }
@ -198,10 +197,10 @@ public class FavouritesDbHelper {
if (fp.getColor() == 0xFF000000 || fp.getColor() == ContextCompat.getColor(context, R.color.color_favorite)) { if (fp.getColor() == 0xFF000000 || fp.getColor() == ContextCompat.getColor(context, R.color.color_favorite)) {
fp.setColor(0); fp.setColor(0);
} }
if (fp.getBackgroundType() == FavouritePoint.DEFAULT_BACKGROUND_TYPE){ if (fp.getBackgroundType() == FavouritePoint.DEFAULT_BACKGROUND_TYPE) {
fp.setBackgroundType(null); fp.setBackgroundType(null);
} }
if(fp.getIconId()== FavouritePoint.DEFAULT_UI_ICON_ID){ if (fp.getIconId() == FavouritePoint.DEFAULT_UI_ICON_ID) {
fp.setIconId(0); fp.setIconId(0);
} }
FavoriteGroup group = getOrCreateGroup(fp, 0); FavoriteGroup group = getOrCreateGroup(fp, 0);

View file

@ -46,7 +46,6 @@ import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint; import net.osmand.data.QuadPoint;
@ -55,11 +54,9 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportRoute; import net.osmand.data.TransportRoute;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.LockableScrollView; import net.osmand.plus.LockableScrollView;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.UiUtilities.DialogButtonType;
@ -69,19 +66,20 @@ import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.base.ContextMenuFragment; import net.osmand.plus.base.ContextMenuFragment;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener;
import net.osmand.plus.mapcontextmenu.MenuController.MenuState; import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener;
import net.osmand.plus.routepreparationmenu.ChooseRouteFragment; import net.osmand.plus.routepreparationmenu.ChooseRouteFragment;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.layers.TransportStopsLayer;
import net.osmand.plus.views.controls.HorizontalSwipeConfirm; import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.views.controls.SingleTapConfirm; import net.osmand.plus.views.controls.SingleTapConfirm;
import net.osmand.plus.views.layers.TransportStopsLayer;
import net.osmand.plus.widgets.style.CustomTypefaceSpan; import net.osmand.plus.widgets.style.CustomTypefaceSpan;
import net.osmand.router.TransportRouteResult; import net.osmand.router.TransportRouteResult;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -91,7 +89,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID;
import static net.osmand.plus.FavouritesDbHelper.FavoriteGroup.convertDisplayNameToGroupIdName;
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP; import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
import static net.osmand.plus.settings.fragments.ConfigureMenuItemsFragment.MAIN_BUTTONS_QUANTITY; import static net.osmand.plus.settings.fragments.ConfigureMenuItemsFragment.MAIN_BUTTONS_QUANTITY;
@ -177,7 +174,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity == null) { if (mapActivity == null) {
@ -609,7 +606,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
containerLayoutListener = new OnLayoutChangeListener() { containerLayoutListener = new OnLayoutChangeListener() {
@Override @Override
public void onLayoutChange(View view, int left, int top, int right, int bottom, public void onLayoutChange(View view, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) { int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (!transportBadgesCreated) { if (!transportBadgesCreated) {
createTransportBadges(); createTransportBadges();
} }
@ -678,11 +675,11 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
} }
private View getActionView(ContextMenuItem contextMenuItem, private View getActionView(ContextMenuItem contextMenuItem,
final int position, final int position,
final ContextMenuAdapter mainAdapter, final ContextMenuAdapter mainAdapter,
final ContextMenuAdapter additionalAdapter, final ContextMenuAdapter additionalAdapter,
final ContextMenuItemClickListener mainListener, final ContextMenuItemClickListener mainListener,
final ContextMenuItemClickListener additionalListener) { final ContextMenuItemClickListener additionalListener) {
UiUtilities uiUtilities = requireMyApplication().getUIUtilities(); UiUtilities uiUtilities = requireMyApplication().getUIUtilities();
LayoutInflater inflater = UiUtilities.getInflater(getMyApplication(), nightMode); LayoutInflater inflater = UiUtilities.getInflater(getMyApplication(), nightMode);
View view = inflater.inflate(R.layout.context_menu_action_item, null); View view = inflater.inflate(R.layout.context_menu_action_item, null);
@ -831,7 +828,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
v.setAlpha(alpha); v.setAlpha(alpha);
if (visible && v.getVisibility() != View.VISIBLE) { if (visible && v.getVisibility() != View.VISIBLE) {
v.setVisibility(View.VISIBLE); v.setVisibility(View.VISIBLE);
} else if (!visible && v.getVisibility() == View.VISIBLE) { } else if (!visible && v.getVisibility() == View.VISIBLE) {
v.setVisibility(View.INVISIBLE); v.setVisibility(View.INVISIBLE);
} }
} }
@ -839,7 +836,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
private void updateVisibility(View v, boolean visible) { private void updateVisibility(View v, boolean visible) {
if (visible && v.getVisibility() != View.VISIBLE) { if (visible && v.getVisibility() != View.VISIBLE) {
v.setVisibility(View.VISIBLE); v.setVisibility(View.VISIBLE);
} else if (!visible && v.getVisibility() == View.VISIBLE) { } else if (!visible && v.getVisibility() == View.VISIBLE) {
v.setVisibility(View.INVISIBLE); v.setVisibility(View.INVISIBLE);
} }
} }
@ -1025,7 +1022,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
} }
private void applyPosY(final int currentY, final boolean needCloseMenu, boolean needMapAdjust, private void applyPosY(final int currentY, final boolean needCloseMenu, boolean needMapAdjust,
final int previousMenuState, final int newMenuState, int dZoom) { final int previousMenuState, final int newMenuState, int dZoom) {
final int posY = getPosY(currentY, needCloseMenu, previousMenuState); final int posY = getPosY(currentY, needCloseMenu, previousMenuState);
if (getViewY() != posY || dZoom != 0) { if (getViewY() != posY || dZoom != 0) {
if (posY < getViewY()) { if (posY < getViewY()) {
@ -1713,7 +1710,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
- (newMenuTopShadowAllHeight - menuTopShadowAllHeight)); - (newMenuTopShadowAllHeight - menuTopShadowAllHeight));
} else { } else {
menuTopViewHeightExcludingTitle = newMenuTopViewHeight - line1.getMeasuredHeight() - line2MeasuredHeight menuTopViewHeightExcludingTitle = newMenuTopViewHeight - line1.getMeasuredHeight() - line2MeasuredHeight
- titleButtonHeight - downloadButtonsHeight - titleBottomButtonHeight - additionalButtonsHeight - titleProgressHeight-line3Height; - titleButtonHeight - downloadButtonsHeight - titleBottomButtonHeight - additionalButtonsHeight - titleProgressHeight - line3Height;
menuTitleTopBottomPadding = (line1.getMeasuredHeight() - line1.getLineCount() * line1.getLineHeight()) menuTitleTopBottomPadding = (line1.getMeasuredHeight() - line1.getLineCount() * line1.getLineHeight())
+ (line2MeasuredHeight - line2LineCount * line2LineHeight); + (line2MeasuredHeight - line2LineCount * line2LineHeight);
menuButtonsHeight = view.findViewById(R.id.context_menu_bottom_buttons).getHeight() menuButtonsHeight = view.findViewById(R.id.context_menu_bottom_buttons).getHeight()
@ -1820,15 +1817,15 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
if (!Algorithms.isEmpty(typeStr)) { if (!Algorithms.isEmpty(typeStr)) {
line2Str.append(typeStr); line2Str.append(typeStr);
Drawable icon = menu.getTypeIcon(); Drawable icon = menu.getTypeIcon();
if (icon != null){ if (icon != null) {
GravityDrawable gravityIcon = new GravityDrawable(icon); if (menu.getTypeIcon() instanceof GravityDrawable) {
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds( GravityDrawable line2Icon = (GravityDrawable) menu.getTypeIcon();
line2, gravityIcon, null, null, null); line2Icon.setBoundsFrom(icon);
} line2.setCompoundDrawablesWithIntrinsicBounds(line2Icon, null, null, null);
String groupName = convertDisplayNameToGroupIdName(requireContext(), } else {
menu.getTypeStr()); line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
if (menu.getMyApplication() != null){ }
line2.setCompoundDrawablePadding(AndroidUtils.dpToPx(requireContext(), 5f));
} }
line2.setCompoundDrawablePadding(dpToPx(5f)); line2.setCompoundDrawablePadding(dpToPx(5f));
} }
@ -2211,7 +2208,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
} }
public static boolean showInstance(final MapContextMenu menu, final MapActivity mapActivity, public static boolean showInstance(final MapContextMenu menu, final MapActivity mapActivity,
final boolean centered) { final boolean centered) {
try { try {
if (menu.getLatLon() == null || mapActivity == null || mapActivity.isActivityDestroyed()) { if (menu.getLatLon() == null || mapActivity == null || mapActivity.isActivityDestroyed()) {

View file

@ -14,6 +14,7 @@ import net.osmand.data.TransportStop;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.base.PointImageDrawable;
@ -160,14 +161,19 @@ public class FavouritePointMenuController extends MenuController {
@Override @Override
public Drawable getSecondLineTypeIcon() { public Drawable getSecondLineTypeIcon() {
if (this.getMapActivity() != null) {
FavouritesDbHelper helper = menu.getMyApplication().getFavorites(); OsmandApplication app = this.getMapActivity().getMyApplication();
if (helper != null && helper.getGroup(groupName) != null) { if (app != null) {
Drawable line2icon = helper.getColoredIconForGroup(groupName); FavouritesDbHelper helper = app.getFavorites();
GravityDrawable line2GravityDrawable = String group = fav.getCategory();
new GravityDrawable(line2icon); if (helper != null && helper.getGroup(group) != null) {
Drawable line2icon = helper.getColoredIconForGroup(group);
GravityDrawable gravityIcon = new GravityDrawable(line2icon);
gravityIcon.setBoundsFrom(line2icon);
return gravityIcon;
}
}
} }
return getIcon(R.drawable.ic_action_group_name_16, isLight() ? R.color.icon_color_default_light : R.color.ctx_menu_bottom_view_icon_dark); return getIcon(R.drawable.ic_action_group_name_16, isLight() ? R.color.icon_color_default_light : R.color.ctx_menu_bottom_view_icon_dark);
} }

View file

@ -12,8 +12,6 @@ import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.data.FavouritePoint;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -21,8 +19,6 @@ import net.osmand.view.GravityDrawable;
import java.util.List; import java.util.List;
import static net.osmand.plus.FavouritesDbHelper.FavoriteGroup.convertDisplayNameToGroupIdName;
public class MultiSelectionArrayAdapter extends ArrayAdapter<MapMultiSelectionMenu.MenuObject> { public class MultiSelectionArrayAdapter extends ArrayAdapter<MapMultiSelectionMenu.MenuObject> {
private MapMultiSelectionMenu menu; private MapMultiSelectionMenu menu;
@ -98,22 +94,15 @@ public class MultiSelectionArrayAdapter extends ArrayAdapter<MapMultiSelectionMe
} }
line2.setText(line2Str); line2.setText(line2Str);
Drawable slIcon = item.getTypeIcon(); Drawable slIcon = item.getTypeIcon();
GravityDrawable line2Icon = new GravityDrawable(slIcon); if (slIcon != null) {
if (slIcon != null){ if (item.getTypeIcon() instanceof GravityDrawable) {
line2Icon.setBoundsFrom(slIcon); GravityDrawable line2Icon = (GravityDrawable) item.getTypeIcon();
line2.setCompoundDrawablesWithIntrinsicBounds(line2Icon, null, null, null); line2Icon.setBoundsFrom(slIcon);
line2.setCompoundDrawablePadding(AndroidUtils.dpToPx(menu.getMapActivity(), 5f)); line2.setCompoundDrawablesWithIntrinsicBounds(line2Icon, null, null, null);
} } else {
String groupName = convertDisplayNameToGroupIdName(getContext(), line2.setCompoundDrawablesWithIntrinsicBounds(slIcon, null, null, null);
item.getTypeStr());
if (item.getMyApplication() != null){
FavouritesDbHelper helper = item.getMyApplication().getFavorites();
if (helper != null && helper.getGroup(groupName) != null){
Drawable line2icon = helper.getColoredIconForGroup(groupName);
GravityDrawable line2GravityIcon = new GravityDrawable(line2icon);
line2GravityIcon.setBoundsFrom(line2icon);
line2.setCompoundDrawablesWithIntrinsicBounds(line2GravityIcon, null, null, null);
} }
line2.setCompoundDrawablePadding(AndroidUtils.dpToPx(menu.getMapActivity(), 5f));
} }
// Divider // Divider
View divider = convertView.findViewById(R.id.divider); View divider = convertView.findViewById(R.id.divider);