apply to all dialog / work in progress

This commit is contained in:
veliymolfar 2020-04-07 14:47:51 +03:00
parent 54d0245f48
commit 971db3f666
19 changed files with 567 additions and 161 deletions

View file

@ -71,6 +71,10 @@ public interface OsmAndCustomizationConstants {
//Map Context Menu Actions: //Map Context Menu Actions:
String MAP_CONTEXT_MENU_ACTIONS = "point.actions."; String MAP_CONTEXT_MENU_ACTIONS = "point.actions.";
String MAP_CONTEXT_MENU_ADD_ID = MAP_CONTEXT_MENU_ACTIONS + "add";
String MAP_CONTEXT_MENU_MARKER_ID = MAP_CONTEXT_MENU_ACTIONS + "marker";
String MAP_CONTEXT_MENU_SHARE_ID = MAP_CONTEXT_MENU_ACTIONS + "share";
String MAP_CONTEXT_MENU_MORE_ID = MAP_CONTEXT_MENU_ACTIONS + "more";
String MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID = MAP_CONTEXT_MENU_ACTIONS + "directions_from"; String MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID = MAP_CONTEXT_MENU_ACTIONS + "directions_from";
String MAP_CONTEXT_MENU_SEARCH_NEARBY = MAP_CONTEXT_MENU_ACTIONS + "search_nearby"; String MAP_CONTEXT_MENU_SEARCH_NEARBY = MAP_CONTEXT_MENU_ACTIONS + "search_nearby";
String MAP_CONTEXT_MENU_CHANGE_MARKER_POSITION = MAP_CONTEXT_MENU_ACTIONS + "change_m_position"; String MAP_CONTEXT_MENU_CHANGE_MARKER_POSITION = MAP_CONTEXT_MENU_ACTIONS + "change_m_position";

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:id="@+id/menu_item"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?selectableItemBackground"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="@dimen/context_menu_main_actions_padding_top"
android:paddingBottom="@dimen/context_menu_main_actions_padding_bottom">
<ImageView
android:id="@+id/item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/context_menu_main_actions_icon_margin"
android:scaleType="center" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/ctx_menu_buttons_text_color"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>

View file

@ -5,12 +5,30 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<ImageView <FrameLayout
android:id="@+id/image" android:id="@+id/image_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:adjustViewBounds="true" android:background="?attr/activity_background_basic"
tools:src="@drawable/img_settings_customize_configure_map_night" /> tools:paddingEnd="56dp"
tools:paddingStart="56dp"
tools:paddingTop="16dp">
<ImageView
android:id="@+id/device_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
tools:src="@drawable/img_settings_device_top_dark" />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
tools:src="@drawable/img_settings_customize_configure_map_night" />
</FrameLayout>
<TextView <TextView
android:id="@+id/description" android:id="@+id/description"

View file

@ -53,7 +53,7 @@
android:letterSpacing="@dimen/description_letter_spacing" android:letterSpacing="@dimen/description_letter_spacing"
android:paddingTop="@dimen/list_header_settings_top_margin" android:paddingTop="@dimen/list_header_settings_top_margin"
android:singleLine="true" android:singleLine="true"
android:textColor="@color/preference_category_title" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium" osmand:typeface="@string/font_roboto_medium"
tools:text="@string/plugin_settings" /> tools:text="@string/plugin_settings" />
@ -64,6 +64,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:letterSpacing="@dimen/description_letter_spacing" android:letterSpacing="@dimen/description_letter_spacing"
android:paddingBottom="@dimen/list_header_settings_top_margin" android:paddingBottom="@dimen/list_header_settings_top_margin"
android:lineSpacingExtra="@dimen/line_spacing_extra_description"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" osmand:typeface="@string/font_roboto_regular"

View file

@ -12,6 +12,7 @@
android:id="@+id/divider" android:id="@+id/divider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_marginBottom="@dimen/content_padding_small"
android:background="?attr/dashboard_divider" android:background="?attr/dashboard_divider"
android:visibility="gone" android:visibility="gone"
tools:visibility="visible" /> tools:visibility="visible" />
@ -79,6 +80,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:letterSpacing="@dimen/description_letter_spacing" android:letterSpacing="@dimen/description_letter_spacing"
android:lineSpacingExtra="@dimen/line_spacing_extra_description"
android:maxLines="4" android:maxLines="4"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"

View file

@ -34,6 +34,7 @@
<string name="context_menu_actions">Context menu actions</string> <string name="context_menu_actions">Context menu actions</string>
<string name="shared_string_drawer">Drawer</string> <string name="shared_string_drawer">Drawer</string>
<string name="ui_customization">UI Customization</string> <string name="ui_customization">UI Customization</string>
<string name="ui_customization_short_descr">Drawer items, context menu</string>
<string name="ui_customization_description">Customize the quantity of items in Drawer, Configure map and context menu.\n\nYou can disable unused plugins, to hide all its controls from the application.</string> <string name="ui_customization_description">Customize the quantity of items in Drawer, Configure map and context menu.\n\nYou can disable unused plugins, to hide all its controls from the application.</string>
<string name="shared_string_min">Min</string> <string name="shared_string_min">Min</string>
<string name="shared_string_square">Square</string> <string name="shared_string_square">Square</string>

View file

@ -52,14 +52,13 @@
android:title="@string/profile_appearance" android:title="@string/profile_appearance"
tools:icon="@drawable/ic_action_offroad" /> tools:icon="@drawable/ic_action_offroad" />
<!-- TODO: change description-->
<Preference <Preference
android:key="ui_customization" android:key="ui_customization"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:persistent="false" android:persistent="false"
android:summary="TODO: change description" android:summary="@string/ui_customization_short_descr"
android:title="@string/ui_customization" android:title="@string/ui_customization"
tools:icon="@drawable/ic_action_offroad" /> tools:icon="@drawable/ic_action_ui_customization" />
<Preference <Preference
android:layout="@layout/simple_divider_item" android:layout="@layout/simple_divider_item"

View file

@ -641,4 +641,113 @@ public class ContextMenuAdapter {
return result; return result;
} }
public void resetMenuItems(@NonNull OsmandApplication app, @NonNull ScreenType screenType) {
saveHiddenItemsIds(app, screenType, null);
saveItemsIdsOrder(app, screenType, null);
}
@NonNull
public List<String> getHiddenItemsIds(@NonNull OsmandApplication app, @NonNull ScreenType type) {
List<String> hiddenItemsIds = null;
switch (type) {
case DRAWER:
hiddenItemsIds = app.getSettings().HIDDEN_DRAWER_ITEMS.getStringsList();
break;
case CONFIGURE_MAP:
hiddenItemsIds = app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getStringsList();
break;
case CONTEXT_MENU_ACTIONS:
hiddenItemsIds = app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.getStringsList();
break;
}
return hiddenItemsIds != null ? new ArrayList<>(hiddenItemsIds) : new ArrayList<String>();
}
@NonNull
public List<String> getItemsIdsOrder(@NonNull OsmandApplication app, @NonNull ScreenType type) {
List<String> hiddenItemsIds = null;
switch (type) {
case DRAWER:
hiddenItemsIds = app.getSettings().DRAWER_ITEMS_ORDER.getStringsList();
break;
case CONFIGURE_MAP:
hiddenItemsIds = app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.getStringsList();
break;
case CONTEXT_MENU_ACTIONS:
hiddenItemsIds = app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.getStringsList();
break;
}
return hiddenItemsIds != null ? new ArrayList<>(hiddenItemsIds) : new ArrayList<String>();
}
public void saveHiddenItemsIds(@NonNull OsmandApplication app, @NonNull ScreenType type, @Nullable List<String> hiddenItemsIds) {
switch (type) {
case DRAWER:
app.getSettings().HIDDEN_DRAWER_ITEMS.setStringsList(hiddenItemsIds);
break;
case CONFIGURE_MAP:
app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.setStringsList(hiddenItemsIds);
break;
case CONTEXT_MENU_ACTIONS:
app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.setStringsList(hiddenItemsIds);
break;
}
}
public void saveItemsIdsOrder(@NonNull OsmandApplication app, @NonNull ScreenType type, @Nullable List<String> itemsIdsOrder) {
switch (type) {
case DRAWER:
app.getSettings().DRAWER_ITEMS_ORDER.setStringsList(itemsIdsOrder);
break;
case CONFIGURE_MAP:
app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.setStringsList(itemsIdsOrder);
break;
case CONTEXT_MENU_ACTIONS:
app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.setStringsList(itemsIdsOrder);
break;
}
}
public String getPrefIdOrder(@NonNull OsmandApplication app, @NonNull ScreenType type) {
switch (type) {
case DRAWER:
return app.getSettings().DRAWER_ITEMS_ORDER.getId();
case CONFIGURE_MAP:
return app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.getId();
case CONTEXT_MENU_ACTIONS:
return app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.get();
}
return "";
}
public String getPrefIdHidden(@NonNull OsmandApplication app, @NonNull ScreenType type) {
switch (type) {
case DRAWER:
return app.getSettings().HIDDEN_DRAWER_ITEMS.getId();
case CONFIGURE_MAP:
return app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getId();
case CONTEXT_MENU_ACTIONS:
return app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.get();
}
return "";
}
public void initItemsCustomOrder(@NonNull OsmandApplication app, @NonNull ScreenType type) {
List<String> savedOrder = getItemsIdsOrder(app, type);
List<String> hiddenItems = getHiddenItemsIds(app, type);
if (!savedOrder.isEmpty()) {
reorderMenuItems(items, getMenuItemsOrder(savedOrder));
}
if (!hiddenItems.isEmpty()) {
List<ContextMenuItem> filtered = new ArrayList<>();
for (ContextMenuItem item : items) {
if (!hiddenItems.contains(item.getId())) {
filtered.add(item);
}
}
items = filtered;
}
}
} }

View file

@ -412,6 +412,11 @@ public class OsmandSettings {
((BooleanPreference) preference).setModeValue(mode, (Boolean) value); ((BooleanPreference) preference).setModeValue(mode, (Boolean) value);
return true; return true;
} }
} else if (preference instanceof ListStringPreference) {
if (value instanceof List) {
((ListStringPreference) preference).setModeValue(mode, (List<String>) value);
return true;
}
} else if (preference instanceof StringPreference) { } else if (preference instanceof StringPreference) {
if (value instanceof String) { if (value instanceof String) {
((StringPreference) preference).setModeValue(mode, (String) value); ((StringPreference) preference).setModeValue(mode, (String) value);
@ -1078,6 +1083,24 @@ public class OsmandSettings {
addValue(value); addValue(value);
} }
} }
public boolean setModeValue(ApplicationMode mode, List<String> values) {
if (values == null || values.size() == 0) {
set(null);
return false;
}
clearAll();
String vl = get();
for (String value : values) {
addValue(value);
if (vl == null || vl.isEmpty()) {
vl = value + delimiter;
} else {
vl = vl + value + delimiter;
}
}
return setModeValue(mode, vl);
}
} }
public class EnumIntPreference<E extends Enum<E>> extends CommonPreference<E> { public class EnumIntPreference<E extends Enum<E>> extends CommonPreference<E> {

View file

@ -753,7 +753,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
ConfigureMenuItemsFragment configureMenuItemsFragment = getConfigureMenuItemsFragment(); ConfigureMenuItemsFragment configureMenuItemsFragment = getConfigureMenuItemsFragment();
if (configureMenuItemsFragment != null) { if (configureMenuItemsFragment != null) {
configureMenuItemsFragment.showExitDialog(); configureMenuItemsFragment.exitFragment();
return; return;
} }

View file

@ -64,6 +64,7 @@ import net.osmand.plus.routepreparationmenu.WaypointsFragment;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
import net.osmand.plus.views.BaseMapLayer; import net.osmand.plus.views.BaseMapLayer;
import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapControlsLayer;
import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.MapTileLayer;
@ -98,11 +99,15 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SEARCH_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_TRAVEL_GUIDES_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_TRAVEL_GUIDES_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_GPX_WAYPOINT; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_GPX_WAYPOINT;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_AVOID_ROAD; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_AVOID_ROAD;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_EDIT_GPX_WP; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_EDIT_GPX_WP;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MARKER_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MEASURE_DISTANCE; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MEASURE_DISTANCE;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_SEARCH_NEARBY; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_SEARCH_NEARBY;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_SHARE_ID;
import static net.osmand.plus.ContextMenuAdapter.PROFILES_CHOSEN_PROFILE_TAG; import static net.osmand.plus.ContextMenuAdapter.PROFILES_CHOSEN_PROFILE_TAG;
import static net.osmand.plus.ContextMenuAdapter.PROFILES_CONTROL_BUTTON_TAG; import static net.osmand.plus.ContextMenuAdapter.PROFILES_CONTROL_BUTTON_TAG;
import static net.osmand.plus.ContextMenuAdapter.PROFILES_NORMAL_PROFILE_TAG; import static net.osmand.plus.ContextMenuAdapter.PROFILES_NORMAL_PROFILE_TAG;
@ -332,9 +337,102 @@ public class MapActivityActions implements DialogProvider {
} }
public void contextMenuPoint(final double latitude, final double longitude, final ContextMenuAdapter iadapter, Object selectedObj) { public void contextMenuPoint(final double latitude, final double longitude, final ContextMenuAdapter iadapter, Object selectedObj) {
final ContextMenuAdapter adapter = iadapter == null ? new ContextMenuAdapter() : iadapter; final ContextMenuAdapter adapter = getContextMenuAdapter(iadapter, selectedObj);
final ArrayAdapter<ContextMenuItem> listAdapter =
adapter.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent());
AdditionalActionsBottomSheetDialogFragment actionsBottomSheetDialogFragment = new AdditionalActionsBottomSheetDialogFragment();
actionsBottomSheetDialogFragment.setAdapter(adapter, new AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener() {
@Override
public void onItemClick(int position) {
ContextMenuItem item = adapter.getItem(position);
int standardId = item.getTitleId();
ItemClickListener click = item.getItemClickListener();
if (click != null) {
click.onContextMenuClick(listAdapter, standardId, position, false, null);
} else if (standardId == R.string.context_menu_item_search) {
mapActivity.showQuickSearch(latitude, longitude);
} else if (standardId == R.string.context_menu_item_directions_from) {
if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
enterDirectionsFromPoint(latitude, longitude);
} else if (!ActivityCompat.shouldShowRequestPermissionRationale(mapActivity, Manifest.permission.ACCESS_FINE_LOCATION)) {
mapActivity.getMyApplication().showToastMessage(R.string.ask_for_location_permission);
} else {
ActivityCompat.requestPermissions(mapActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION);
}
} else if (standardId == R.string.measurement_tool) {
mapActivity.getContextMenu().close();
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), new LatLon(latitude, longitude));
} else if (standardId == R.string.avoid_road) {
getMyApplication().getAvoidSpecificRoads().addImpassableRoad(mapActivity, new LatLon(latitude, longitude), true, false, null);
}
}
});
actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG);
}
public void showActionsBottomSheet(final double latitude, final double longitude, final ContextMenuAdapter adapter) {
final ArrayAdapter<ContextMenuItem> listAdapter =
adapter.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent());
AdditionalActionsBottomSheetDialogFragment actionsBottomSheetDialogFragment = new AdditionalActionsBottomSheetDialogFragment();
actionsBottomSheetDialogFragment.setAdapter(adapter, new AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener() {
@Override
public void onItemClick(int position) {
ContextMenuItem item = adapter.getItem(position);
int standardId = item.getTitleId();
ItemClickListener click = item.getItemClickListener();
if (click != null) {
click.onContextMenuClick(listAdapter, standardId, position, false, null);
} else if (standardId == R.string.context_menu_item_search) {
mapActivity.showQuickSearch(latitude, longitude);
} else if (standardId == R.string.context_menu_item_directions_from) {
if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
enterDirectionsFromPoint(latitude, longitude);
} else if (!ActivityCompat.shouldShowRequestPermissionRationale(mapActivity, Manifest.permission.ACCESS_FINE_LOCATION)) {
mapActivity.getMyApplication().showToastMessage(R.string.ask_for_location_permission);
} else {
ActivityCompat.requestPermissions(mapActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION);
}
} else if (standardId == R.string.measurement_tool) {
mapActivity.getContextMenu().close();
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), new LatLon(latitude, longitude));
} else if (standardId == R.string.avoid_road) {
getMyApplication().getAvoidSpecificRoads().addImpassableRoad(mapActivity, new LatLon(latitude, longitude), true, false, null);
}
}
});
actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG);
}
public ContextMenuAdapter getContextMenuAdapter(final ContextMenuAdapter iadapter, Object selectedObj) {
ContextMenuAdapter adapter = iadapter == null ? new ContextMenuAdapter() : iadapter;
ItemBuilder itemBuilder = new ItemBuilder(); ItemBuilder itemBuilder = new ItemBuilder();
adapter.addItem(itemBuilder
.setTitleId(R.string.shared_string_add, mapActivity)
.setId(MAP_CONTEXT_MENU_ADD_ID)
.setIcon(R.drawable.map_action_fav_dark)
.setOrder(0)
.createItem());
adapter.addItem(itemBuilder
.setTitleId(R.string.shared_string_marker, mapActivity)
.setId(MAP_CONTEXT_MENU_MARKER_ID)
.setIcon(R.drawable.map_action_flag_dark)
.setOrder(1)
.createItem());
adapter.addItem(itemBuilder
.setTitleId(R.string.shared_string_share, mapActivity)
.setId(MAP_CONTEXT_MENU_SHARE_ID)
.setIcon(R.drawable.map_action_gshare_dark)
.setOrder(2)
.createItem());
adapter.addItem(itemBuilder
.setTitleId(R.string.shared_string_actions, mapActivity)
.setId(MAP_CONTEXT_MENU_MORE_ID)
.setIcon(R.drawable.map_overflow_menu_white)
.setOrder(3)
.createItem());
adapter.addItem(itemBuilder adapter.addItem(itemBuilder
.setTitleId(R.string.context_menu_item_directions_from, mapActivity) .setTitleId(R.string.context_menu_item_directions_from, mapActivity)
.setId(MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID) .setId(MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID)
@ -348,7 +446,9 @@ public class MapActivityActions implements DialogProvider {
.setOrder(SEARCH_NEAR_ITEM_ORDER) .setOrder(SEARCH_NEAR_ITEM_ORDER)
.createItem()); .createItem());
OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj); // if (register){
// OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj);
// }
ItemClickListener listener = new ItemClickListener() { ItemClickListener listener = new ItemClickListener() {
@Override @Override
@ -395,38 +495,7 @@ public class MapActivityActions implements DialogProvider {
.createItem()); .createItem());
adapter.sortItemsByOrder(); adapter.sortItemsByOrder();
return adapter;
final ArrayAdapter<ContextMenuItem> listAdapter =
adapter.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent());
AdditionalActionsBottomSheetDialogFragment actionsBottomSheetDialogFragment = new AdditionalActionsBottomSheetDialogFragment();
actionsBottomSheetDialogFragment.setAdapter(adapter, new AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener() {
@Override
public void onItemClick(int position) {
ContextMenuItem item = adapter.getItem(position);
int standardId = item.getTitleId();
ItemClickListener click = item.getItemClickListener();
if (click != null) {
click.onContextMenuClick(listAdapter, standardId, position, false, null);
} else if (standardId == R.string.context_menu_item_search) {
mapActivity.showQuickSearch(latitude, longitude);
} else if (standardId == R.string.context_menu_item_directions_from) {
if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
enterDirectionsFromPoint(latitude, longitude);
} else if (!ActivityCompat.shouldShowRequestPermissionRationale(mapActivity, Manifest.permission.ACCESS_FINE_LOCATION)) {
mapActivity.getMyApplication().showToastMessage(R.string.ask_for_location_permission);
} else {
ActivityCompat.requestPermissions(mapActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION);
}
} else if (standardId == R.string.measurement_tool) {
mapActivity.getContextMenu().close();
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), new LatLon(latitude, longitude));
} else if (standardId == R.string.avoid_road) {
getMyApplication().getAvoidSpecificRoads().addImpassableRoad(mapActivity, new LatLon(latitude, longitude), true, false, null);
}
}
});
actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG);
} }
public void enterDirectionsFromPoint(final double latitude, final double longitude) { public void enterDirectionsFromPoint(final double latitude, final double longitude) {
@ -1125,6 +1194,7 @@ public class MapActivityActions implements DialogProvider {
} }
menuItemsListView.setDivider(null); menuItemsListView.setDivider(null);
final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu(); final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu();
contextMenuAdapter.initItemsCustomOrder(getMyApplication(), ScreenType.DRAWER);
contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item); contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item);
final ArrayAdapter<ContextMenuItem> simpleListAdapter = contextMenuAdapter.createListAdapter(mapActivity, final ArrayAdapter<ContextMenuItem> simpleListAdapter = contextMenuAdapter.createListAdapter(mapActivity,
!nightMode); !nightMode);

View file

@ -77,6 +77,7 @@ import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter;
import net.osmand.plus.routing.IRouteInformationListener; import net.osmand.plus.routing.IRouteInformationListener;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
import net.osmand.plus.srtmplugin.ContourLinesMenu; import net.osmand.plus.srtmplugin.ContourLinesMenu;
import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.srtmplugin.TerrainFragment; import net.osmand.plus.srtmplugin.TerrainFragment;
@ -697,6 +698,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity); cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity);
} else if (visibleType == DashboardType.CONFIGURE_MAP) { } else if (visibleType == DashboardType.CONFIGURE_MAP) {
cm = new ConfigureMapMenu().createListAdapter(mapActivity); cm = new ConfigureMapMenu().createListAdapter(mapActivity);
cm.initItemsCustomOrder(getMyApplication(), ScreenType.CONFIGURE_MAP);
} else if (visibleType == DashboardType.LIST_MENU) { } else if (visibleType == DashboardType.LIST_MENU) {
cm = mapActivity.getMapActions().createMainOptionsMenu(); cm = mapActivity.getMapActions().createMainOptionsMenu();
} else if (visibleType == DashboardType.ROUTE_PREFERENCES) { } else if (visibleType == DashboardType.ROUTE_PREFERENCES) {

View file

@ -51,6 +51,7 @@ import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.corenative.NativeCoreContext; import net.osmand.plus.views.corenative.NativeCoreContext;
@ -151,7 +152,6 @@ public class ConfigureMapMenu {
adapter.setNightMode(nightMode); adapter.setNightMode(nightMode);
createLayersItems(customRules, adapter, ma, themeRes, nightMode); createLayersItems(customRules, adapter, ma, themeRes, nightMode);
createRenderingAttributeItems(customRules, adapter, ma, themeRes, nightMode); createRenderingAttributeItems(customRules, adapter, ma, themeRes, nightMode);
return adapter; return adapter;
} }

View file

@ -1064,16 +1064,24 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
public void buttonMorePressed() { public void buttonMorePressed() {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
final ContextMenuAdapter menuAdapter = new ContextMenuAdapter();
LatLon latLon = getLatLon(); LatLon latLon = getLatLon();
for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) { mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), getAdapter(), getObject());
layer.populateObjectContextMenu(latLon, getObject(), menuAdapter, mapActivity);
}
mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), menuAdapter, getObject());
} }
} }
public ContextMenuAdapter getAdapter() {
final ContextMenuAdapter menuAdapter = new ContextMenuAdapter();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
// LatLon latLon = getLatLon();
// for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) {
// layer.populateObjectContextMenu(latLon, getObject(), menuAdapter, mapActivity);
// }
mapActivity.getMapActions().getContextMenuAdapter(menuAdapter, getObject());
}
return menuAdapter;
}
private void callMenuAction(boolean waitForAddressLookup, MenuAction menuAction) { private void callMenuAction(boolean waitForAddressLookup, MenuAction menuAction) {
if (searchingAddress() && waitForAddressLookup) { if (searchingAddress() && waitForAddressLookup) {
ProgressDialog dlg = buildSearchActionDialog(); ProgressDialog dlg = buildSearchActionDialog();

View file

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -19,9 +20,11 @@ import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -31,17 +34,21 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions; import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType; import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItem; import net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItem;
import net.osmand.plus.settings.RearrangeMenuItemsAdapter.MenuItemsAdapterListener; import net.osmand.plus.settings.RearrangeMenuItemsAdapter.MenuItemsAdapterListener;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID;
import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.BUTTON; import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.BUTTON;
import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DESCRIPTION; import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DESCRIPTION;
import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DIVIDER; import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DIVIDER;
@ -63,6 +70,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
private ScreenType screenType; private ScreenType screenType;
private boolean nightMode; private boolean nightMode;
private boolean wasReset = false; private boolean wasReset = false;
private boolean isChanged = false;
@Override @Override
public void onSaveInstanceState(@NonNull Bundle outState) { public void onSaveInstanceState(@NonNull Bundle outState) {
@ -100,6 +108,8 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
contextMenuAdapter = configureMapMenu.createListAdapter((MapActivity) activity); contextMenuAdapter = configureMapMenu.createListAdapter((MapActivity) activity);
break; break;
case CONTEXT_MENU_ACTIONS: case CONTEXT_MENU_ACTIONS:
MapContextMenu menu = ((MapActivity) activity).getContextMenu();
contextMenuAdapter = menu.getAdapter();
break; break;
} }
} }
@ -111,19 +121,20 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
hiddenMenuItems = savedInstanceState.getStringArrayList(HIDDEN_ITEMS_KEY); hiddenMenuItems = savedInstanceState.getStringArrayList(HIDDEN_ITEMS_KEY);
menuItemsOrder = (HashMap<String, Integer>) savedInstanceState.getSerializable(ITEMS_ORDER_KEY); menuItemsOrder = (HashMap<String, Integer>) savedInstanceState.getSerializable(ITEMS_ORDER_KEY);
} else { } else {
hiddenMenuItems = getHiddenItemsIds(screenType); hiddenMenuItems = contextMenuAdapter.getHiddenItemsIds(app, screenType);
menuItemsOrder = contextMenuAdapter.getMenuItemsOrder(getItemsIdsOrder(screenType)); menuItemsOrder = contextMenuAdapter.getMenuItemsOrder(contextMenuAdapter.getItemsIdsOrder(app, screenType));
} }
} }
@Nullable @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
View root = mInflater.inflate(R.layout.edit_arrangement_list_fragment, container, false); View root = mInflater.inflate(R.layout.edit_arrangement_list_fragment, container, false);
Toolbar toolbar = root.findViewById(R.id.toolbar); Toolbar toolbar = root.findViewById(R.id.toolbar);
TextView toolbarTitle = root.findViewById(R.id.toolbar_title); TextView toolbarTitle = root.findViewById(R.id.toolbar_title);
ImageButton toolbarButton = root.findViewById(R.id.close_button); ImageButton toolbarButton = root.findViewById(R.id.close_button);
RecyclerView recyclerView = root.findViewById(R.id.profiles_list); RecyclerView recyclerView = root.findViewById(R.id.profiles_list);
recyclerView.setPadding(0, 0, 0, AndroidUtils.dpToPx(app, 72));
toolbar.setBackgroundColor(nightMode toolbar.setBackgroundColor(nightMode
? getResources().getColor(R.color.list_background_color_dark) ? getResources().getColor(R.color.list_background_color_dark)
: getResources().getColor(R.color.list_background_color_light)); : getResources().getColor(R.color.list_background_color_light));
@ -135,7 +146,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
toolbarButton.setOnClickListener(new View.OnClickListener() { toolbarButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
showExitDialog(); exitFragment();
} }
}); });
@ -174,6 +185,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
hiddenMenuItems.remove(menuItemBase.getId()); hiddenMenuItems.remove(menuItemBase.getId());
} }
wasReset = false; wasReset = false;
isChanged = true;
rearrangeAdapter.updateItems(getAdapterItems()); rearrangeAdapter.updateItems(getAdapterItems());
} }
} }
@ -182,6 +194,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
public void onItemMoved(String id, int position) { public void onItemMoved(String id, int position) {
menuItemsOrder.put(id, position); menuItemsOrder.put(id, position);
wasReset = false; wasReset = false;
isChanged = true;
} }
}; };
rearrangeAdapter.setListener(listener); rearrangeAdapter.setListener(listener);
@ -204,19 +217,45 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
applyButton.setOnClickListener(new View.OnClickListener() { applyButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (wasReset) { // if (wasReset) {
resetMenuItems(screenType); // contextMenuAdapter.resetMenuItems(app, screenType);
} else { // } else {
saveHiddenItemsIds(screenType, hiddenMenuItems); HashMap<String, Serializable> prefsMap = new HashMap<>();
prefsMap.put(contextMenuAdapter.getPrefIdHidden(app, screenType), (Serializable) hiddenMenuItems);
// contextMenuAdapter.saveHiddenItemsIds(app, screenType, hiddenMenuItems);
List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems(screenType); List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems(screenType);
contextMenuAdapter.reorderMenuItems(defItems, menuItemsOrder); contextMenuAdapter.reorderMenuItems(defItems, menuItemsOrder);
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
for (ContextMenuItem item : defItems) { for (ContextMenuItem item : defItems) {
ids.add(item.getId()); ids.add(item.getId());
} }
saveItemsIdsOrder(screenType, ids); prefsMap.put(contextMenuAdapter.getPrefIdOrder(app, screenType), (Serializable) ids);
}
dismissFragment(); FragmentManager fm = getFragmentManager();
ApplicationMode appMode = app.getSettings().getApplicationMode();
if (fm != null) {
ChangeGeneralProfilesPrefBottomSheet.showInstance(
fm,
prefsMap,
getTargetFragment(),
false,
appMode,
new ChangeGeneralProfilesPrefBottomSheet.OnChangeSettingListener() {
@Override
public void onApplied() {
dismissFragment();
}
@Override
public void onDiscard() {
}
});
}
// contextMenuAdapter.saveItemsIdsOrder(app, screenType, ids);
// }
// dismissFragment();
} }
}); });
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21) {
@ -231,7 +270,29 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
List<AdapterItem> visible = contextMenuAdapter.getItemsForRearrangeAdapter(screenType, hiddenMenuItems, wasReset ? null : menuItemsOrder, false); List<AdapterItem> visible = contextMenuAdapter.getItemsForRearrangeAdapter(screenType, hiddenMenuItems, wasReset ? null : menuItemsOrder, false);
List<AdapterItem> hiddenItems = contextMenuAdapter.getItemsForRearrangeAdapter(screenType, hiddenMenuItems, wasReset ? null : menuItemsOrder, true); List<AdapterItem> hiddenItems = contextMenuAdapter.getItemsForRearrangeAdapter(screenType, hiddenMenuItems, wasReset ? null : menuItemsOrder, true);
items.addAll(visible); if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
List<AdapterItem> main = new ArrayList<>();
int actionsIndex = 3;
for (int i = 0; i < visible.size(); i++) {
if (((ContextMenuItem) visible.get(i).getValue()).getId().equals(MAP_CONTEXT_MENU_MORE_ID)) {
actionsIndex = i;
break;
}
}
for (int i = 0; i < actionsIndex + 1; i++) {
main.add(visible.get(i));
}
items.add(new AdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.main_actions, R.string.main_actions_descr)));
items.addAll(main);
items.add(new AdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.additional_actions, R.string.additional_actions_descr)));
List<AdapterItem> additional = new ArrayList<>();
for (int i = 4; i < visible.size(); i++) {
additional.add(visible.get(i));
}
items.addAll(additional);
} else {
items.addAll(visible);
}
if (!hiddenItems.isEmpty()) { if (!hiddenItems.isEmpty()) {
items.add(new AdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.shared_string_hidden, R.string.hidden_items_descr))); items.add(new AdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.shared_string_hidden, R.string.hidden_items_descr)));
items.addAll(hiddenItems); items.addAll(hiddenItems);
@ -246,6 +307,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
hiddenMenuItems.clear(); hiddenMenuItems.clear();
menuItemsOrder.clear(); menuItemsOrder.clear();
wasReset = true; wasReset = true;
isChanged = true;
rearrangeAdapter.updateItems(getAdapterItems()); rearrangeAdapter.updateItems(getAdapterItems());
} }
}))); })));
@ -261,6 +323,14 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
return items; return items;
} }
public void exitFragment() {
if (isChanged) {
showExitDialog();
} else {
dismissFragment();
}
}
public void showExitDialog() { public void showExitDialog() {
Context themedContext = UiUtilities.getThemedContext(getActivity(), nightMode); Context themedContext = UiUtilities.getThemedContext(getActivity(), nightMode);
AlertDialog.Builder dismissDialog = new AlertDialog.Builder(themedContext); AlertDialog.Builder dismissDialog = new AlertDialog.Builder(themedContext);
@ -286,71 +356,4 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
private void setScreenType(@NonNull ScreenType screenType) { private void setScreenType(@NonNull ScreenType screenType) {
this.screenType = screenType; this.screenType = screenType;
} }
private void resetMenuItems(@NonNull ScreenType screenType) {
saveHiddenItemsIds(screenType, null);
saveItemsIdsOrder(screenType, null);
}
@NonNull
private List<String> getHiddenItemsIds(@NonNull ScreenType type) {
List<String> hiddenItemsIds = null;
switch (type) {
case DRAWER:
hiddenItemsIds = app.getSettings().HIDDEN_DRAWER_ITEMS.getStringsList();
break;
case CONFIGURE_MAP:
hiddenItemsIds = app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getStringsList();
break;
case CONTEXT_MENU_ACTIONS:
hiddenItemsIds = app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.getStringsList();
break;
}
return hiddenItemsIds != null ? new ArrayList<>(hiddenItemsIds) : new ArrayList<String>();
}
@NonNull
private List<String> getItemsIdsOrder(@NonNull ScreenType type) {
List<String> hiddenItemsIds = null;
switch (type) {
case DRAWER:
hiddenItemsIds = app.getSettings().DRAWER_ITEMS_ORDER.getStringsList();
break;
case CONFIGURE_MAP:
hiddenItemsIds = app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.getStringsList();
break;
case CONTEXT_MENU_ACTIONS:
hiddenItemsIds = app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.getStringsList();
break;
}
return hiddenItemsIds != null ? new ArrayList<>(hiddenItemsIds) : new ArrayList<String>();
}
private void saveHiddenItemsIds(@NonNull ScreenType type, @Nullable List<String> hiddenItemsIds) {
switch (type) {
case DRAWER:
app.getSettings().HIDDEN_DRAWER_ITEMS.setStringsList(hiddenItemsIds);
break;
case CONFIGURE_MAP:
app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.setStringsList(hiddenItemsIds);
break;
case CONTEXT_MENU_ACTIONS:
app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.setStringsList(hiddenItemsIds);
break;
}
}
private void saveItemsIdsOrder(@NonNull ScreenType type, @Nullable List<String> itemsIdsOrder) {
switch (type) {
case DRAWER:
app.getSettings().DRAWER_ITEMS_ORDER.setStringsList(itemsIdsOrder);
break;
case CONFIGURE_MAP:
app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.setStringsList(itemsIdsOrder);
break;
case CONTEXT_MENU_ACTIONS:
app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.setStringsList(itemsIdsOrder);
break;
}
}
} }

View file

@ -1,5 +1,6 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -26,11 +27,15 @@ import androidx.recyclerview.widget.RecyclerView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.activities.PluginsActivity; import net.osmand.plus.activities.PluginsActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.widgets.style.CustomTypefaceSpan; import net.osmand.plus.widgets.style.CustomTypefaceSpan;
@ -41,6 +46,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType.CONFIGURE_MAP;
public class ConfigureMenuRootFragment extends BaseOsmAndFragment { public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
public static final String TAG = ConfigureMenuRootFragment.class.getName(); public static final String TAG = ConfigureMenuRootFragment.class.getName();
@ -202,22 +209,29 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
} }
private String getSubTitleText(ScreenType type) { private String getSubTitleText(ScreenType type) {
List<String> hiddenItems = null; ContextMenuAdapter contextMenuAdapter = null;
switch (type) { Activity activity = getActivity();
case DRAWER: if (activity instanceof MapActivity) {
hiddenItems = app.getSettings().HIDDEN_DRAWER_ITEMS.getStringsList(); switch (type) {
break; case DRAWER:
case CONFIGURE_MAP: MapActivityActions mapActivityActions = new MapActivityActions((MapActivity) activity);
hiddenItems = app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getStringsList(); contextMenuAdapter = mapActivityActions.createMainOptionsMenu();
break; break;
case CONTEXT_MENU_ACTIONS: case CONFIGURE_MAP:
hiddenItems = app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.getStringsList(); ConfigureMapMenu configureMapMenu = new ConfigureMapMenu();
break; contextMenuAdapter = configureMapMenu.createListAdapter((MapActivity) activity);
break;
case CONTEXT_MENU_ACTIONS:
ConfigureMapMenu configureaMapMenu = new ConfigureMapMenu();
contextMenuAdapter = configureaMapMenu.createListAdapter((MapActivity) activity);
break;
}
int hiddenCount = contextMenuAdapter.getHiddenItemsIds(app, type).size();
int allCount = contextMenuAdapter.getDefaultItems(type).size();
String amount = getString(R.string.n_items_of_z, String.valueOf(allCount - hiddenCount), String.valueOf(allCount));
return getString(R.string.ltr_or_rtl_combine_via_colon, getString(R.string.shared_string_items), amount);
} }
int hiddenCount = hiddenItems != null ? hiddenItems.size() : 0; return "";
int allCount = 0;
String amount = getString(R.string.n_items_of_z, String.valueOf(allCount - hiddenCount), String.valueOf(allCount));
return getString(R.string.ltr_or_rtl_combine_via_colon, getString(R.string.shared_string_items), amount);
} }
class DescriptionHolder extends RecyclerView.ViewHolder { class DescriptionHolder extends RecyclerView.ViewHolder {

View file

@ -390,9 +390,10 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
return; return;
} }
Preference uiCustomization = findPreference(UI_CUSTOMIZATION); Preference uiCustomization = findPreference(UI_CUSTOMIZATION);
// TODO change icon if (uiCustomization != null) {
uiCustomization.setIcon(getContentIcon(getSelectedAppMode().getIconRes())); uiCustomization.setIcon(getContentIcon(R.drawable.ic_action_ui_customization));
uiCustomization.setFragment(ConfigureMenuRootFragment.TAG); uiCustomization.setFragment(ConfigureMenuRootFragment.TAG);
}
} }
@Override @Override

View file

@ -6,6 +6,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -21,6 +22,7 @@ import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType; import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
@ -29,6 +31,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DIVIDER_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DIVIDER_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_RENDERING_CATEGORY_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_RENDERING_CATEGORY_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.RENDERING_ITEMS_ID_SCHEME; import static net.osmand.aidlapi.OsmAndCustomizationConstants.RENDERING_ITEMS_ID_SCHEME;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.SHOW_CATEGORY_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.SHOW_CATEGORY_ID;
@ -96,14 +99,30 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
if (holder instanceof DescriptionHolder) { if (holder instanceof DescriptionHolder) {
DescriptionHolder h = (DescriptionHolder) holder; DescriptionHolder h = (DescriptionHolder) holder;
ScreenType screenType = (ScreenType) item.value; ScreenType screenType = (ScreenType) item.value;
int paddingStart = AndroidUtils.dpToPx(app, 56);
int paddingTop = AndroidUtils.dpToPx(app, 16);
h.description.setText(String.format(app.getString(R.string.reorder_or_hide_from), app.getString(screenType.titleRes))); h.description.setText(String.format(app.getString(R.string.reorder_or_hide_from), app.getString(screenType.titleRes)));
h.image.setImageResource(nightMode ? screenType.imageNightRes : screenType.imageDayRes); h.image.setImageResource(nightMode ? screenType.imageNightRes : screenType.imageDayRes);
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
h.deviceImage.setImageResource(nightMode
? R.drawable.img_settings_device_bottom_dark
: R.drawable.img_settings_device_bottom_light);
h.imageContainer.setPadding(paddingStart, 0, paddingStart, paddingTop);
} else {
h.deviceImage.setImageResource(nightMode
? R.drawable.img_settings_device_top_dark
: R.drawable.img_settings_device_top_light);
h.imageContainer.setPadding(paddingStart, paddingTop, paddingStart, 0);
}
} else if (holder instanceof ItemHolder) { } else if (holder instanceof ItemHolder) {
final ItemHolder h = (ItemHolder) holder; final ItemHolder h = (ItemHolder) holder;
ContextMenuItem menuItem = (ContextMenuItem) item.value; ContextMenuItem menuItem = (ContextMenuItem) item.value;
String id = menuItem.getId(); String id = menuItem.getId();
if (DRAWER_DIVIDER_ID.equals(menuItem.getId())) { if (DRAWER_DIVIDER_ID.equals(menuItem.getId())) {
h.title.setText(R.string.shared_string_divider); h.title.setText(R.string.shared_string_divider);
h.title.setTypeface(FontCache.getFont(app, app.getString(R.string.font_roboto_medium)));
h.title.setTextColor(app.getResources().getColor(activeColorRes));
h.title.setTextSize(15);
h.description.setText(R.string.divider_descr); h.description.setText(R.string.divider_descr);
h.icon.setVisibility(View.GONE); h.icon.setVisibility(View.GONE);
h.actionIcon.setVisibility(View.GONE); h.actionIcon.setVisibility(View.GONE);
@ -112,6 +131,8 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
} else if (SHOW_CATEGORY_ID.equals(id) } else if (SHOW_CATEGORY_ID.equals(id)
|| MAP_RENDERING_CATEGORY_ID.equals(id)) { || MAP_RENDERING_CATEGORY_ID.equals(id)) {
h.title.setText(menuItem.getTitle()); h.title.setText(menuItem.getTitle());
h.title.setTypeface(FontCache.getFont(app, app.getString(R.string.font_roboto_medium)));
h.title.setTextSize(15);
h.description.setText(R.string.move_inside_category); h.description.setText(R.string.move_inside_category);
h.icon.setVisibility(View.GONE); h.icon.setVisibility(View.GONE);
h.actionIcon.setVisibility(View.GONE); h.actionIcon.setVisibility(View.GONE);
@ -147,13 +168,20 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
return false; return false;
} }
}); });
if (menuItem.isHidden()) { if (!menuItem.isHidden()
h.moveIcon.setVisibility(View.GONE); && !id.equals(SHOW_CATEGORY_ID)
h.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_undo, R.color.color_osm_edit_create)); && !id.equals(MAP_RENDERING_CATEGORY_ID)) {
} else {
h.moveIcon.setVisibility(View.VISIBLE); h.moveIcon.setVisibility(View.VISIBLE);
h.moveIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_item_move, nightMode)); h.moveIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_item_move, nightMode));
h.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_remove, R.color.color_osm_edit_delete)); h.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_remove, R.color.color_osm_edit_delete));
} else {
h.moveIcon.setVisibility(View.GONE);
h.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_undo, R.color.color_osm_edit_create));
}
if (id.equals(MAP_CONTEXT_MENU_MORE_ID)) {
h.moveIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_item_move, nightMode));
h.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_remove, nightMode));
h.actionIcon.setOnClickListener(null);
} }
} else if (holder instanceof HeaderHolder) { } else if (holder instanceof HeaderHolder) {
HeaderHolder h = (HeaderHolder) holder; HeaderHolder h = (HeaderHolder) holder;
@ -216,12 +244,16 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
private static class DescriptionHolder extends RecyclerView.ViewHolder private static class DescriptionHolder extends RecyclerView.ViewHolder
implements ReorderItemTouchHelperCallback.UnmovableItem { implements ReorderItemTouchHelperCallback.UnmovableItem {
private ImageView image; private ImageView image;
private ImageView deviceImage;
private TextView description; private TextView description;
private FrameLayout imageContainer;
DescriptionHolder(@NonNull View itemView) { DescriptionHolder(@NonNull View itemView) {
super(itemView); super(itemView);
image = itemView.findViewById(R.id.image); image = itemView.findViewById(R.id.image);
deviceImage = itemView.findViewById(R.id.device_image);
description = itemView.findViewById(R.id.description); description = itemView.findViewById(R.id.description);
imageContainer = itemView.findViewById(R.id.image_container);
} }
@Override @Override

View file

@ -21,6 +21,9 @@ import net.osmand.plus.settings.BaseSettingsFragment;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSheet { public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSheet {
@ -30,8 +33,24 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
private static final String NEW_VALUE_KEY = "new_value_key"; private static final String NEW_VALUE_KEY = "new_value_key";
private static final String PREFS_MAP_KEY = "prefs_map_key";
@Nullable
private Serializable newValue; private Serializable newValue;
@Nullable
private String prefId;
@Nullable
private HashMap<String, Serializable> prefsMap;
@Nullable
private OnChangeSettingListener listener;
public void setListener(@Nullable OnChangeSettingListener listener) {
this.listener = listener;
}
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication(); final OsmandApplication app = getMyApplication();
@ -39,11 +58,12 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
if (app == null || args == null) { if (app == null || args == null) {
return; return;
} }
final String prefId = args.getString(PREFERENCE_ID); prefId = args.getString(PREFERENCE_ID);
newValue = args.getSerializable(NEW_VALUE_KEY); newValue = args.getSerializable(NEW_VALUE_KEY);
if (newValue == null || prefId == null) { prefsMap = (HashMap<String, Serializable>) args.getSerializable(PREFS_MAP_KEY);
return; // if (newValue == null || prefId == null) {
} // return;
// }
items.add(new TitleItem(getString(R.string.change_default_settings))); items.add(new TitleItem(getString(R.string.change_default_settings)));
items.add(new LongDescriptionItem(getString(R.string.apply_preference_to_all_profiles))); items.add(new LongDescriptionItem(getString(R.string.apply_preference_to_all_profiles)));
@ -55,8 +75,15 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
app.getSettings().setPreferenceForAllModes(prefId, newValue); if (prefsMap != null) {
savePrefs(app, prefsMap, true);
} else if (newValue != null || prefId != null) {
app.getSettings().setPreferenceForAllModes(prefId, newValue);
}
updateTargetSettings(false, true); updateTargetSettings(false, true);
if (listener != null) {
listener.onApplied();
}
dismiss(); dismiss();
} }
}) })
@ -72,8 +99,15 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
app.getSettings().setPreference(prefId, newValue, getAppMode()); if (prefsMap != null) {
savePrefs(app, prefsMap, false);
} else if (newValue != null || prefId != null) {
app.getSettings().setPreference(prefId, newValue, getAppMode());
}
updateTargetSettings(false, false); updateTargetSettings(false, false);
if (listener != null) {
listener.onApplied();
}
dismiss(); dismiss();
} }
}) })
@ -88,6 +122,9 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
@Override @Override
public void onClick(View v) { public void onClick(View v) {
updateTargetSettings(true, false); updateTargetSettings(true, false);
if (listener != null) {
listener.onDiscard();
}
dismiss(); dismiss();
} }
}) })
@ -106,6 +143,18 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
outState.putSerializable(NEW_VALUE_KEY, newValue); outState.putSerializable(NEW_VALUE_KEY, newValue);
} }
private void savePrefs(@NonNull OsmandApplication app,
@NonNull HashMap<String, Serializable> prefsMap, boolean toAllProfiles) {
List<String> ids = new ArrayList<>(prefsMap.keySet());
for (String id : ids) {
if (toAllProfiles) {
app.getSettings().setPreferenceForAllModes(id, prefsMap.get(id));
} else {
app.getSettings().setPreference(id, prefsMap.get(id), getAppMode());
}
}
}
private void updateTargetSettings(boolean discard, boolean appliedToAllProfiles) { private void updateTargetSettings(boolean discard, boolean appliedToAllProfiles) {
BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment(); BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment();
if (target != null) { if (target != null) {
@ -129,23 +178,61 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
} }
} }
public static void showInstance(@NonNull FragmentManager fm, String prefId, Serializable newValue, Fragment target, public static void showInstance(@NonNull FragmentManager fm,
boolean usedOnMap, @Nullable ApplicationMode appMode) { @Nullable String prefId,
@Nullable Serializable newValue,
Fragment target,
boolean usedOnMap,
@Nullable ApplicationMode appMode) {
showFragmentInstance(fm, prefId, newValue, null, target, usedOnMap, appMode, null);
}
public static void showInstance(@NonNull FragmentManager fm,
@Nullable HashMap<String, Serializable> prefs,
Fragment target,
boolean usedOnMap,
@Nullable ApplicationMode appMode,
@Nullable OnChangeSettingListener listener) {
showFragmentInstance(fm, null, null, prefs, target, usedOnMap, appMode, listener);
}
private static void showFragmentInstance(@NonNull FragmentManager fm,
@Nullable String prefId,
@Nullable Serializable newValue,
@Nullable HashMap<String, Serializable> prefs,
Fragment target,
boolean usedOnMap,
@Nullable ApplicationMode appMode,
@Nullable OnChangeSettingListener listener) {
try { try {
if (fm.findFragmentByTag(ChangeGeneralProfilesPrefBottomSheet.TAG) == null) { if (fm.findFragmentByTag(ChangeGeneralProfilesPrefBottomSheet.TAG) == null) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(PREFERENCE_ID, prefId); if (prefId != null) {
args.putSerializable(NEW_VALUE_KEY, newValue); args.putString(PREFERENCE_ID, prefId);
}
if (newValue != null) {
args.putSerializable(NEW_VALUE_KEY, newValue);
}
if (prefs != null) {
args.putSerializable(PREFS_MAP_KEY, prefs);
}
ChangeGeneralProfilesPrefBottomSheet fragment = new ChangeGeneralProfilesPrefBottomSheet(); ChangeGeneralProfilesPrefBottomSheet fragment = new ChangeGeneralProfilesPrefBottomSheet();
fragment.setArguments(args); fragment.setArguments(args);
fragment.setUsedOnMap(usedOnMap); fragment.setUsedOnMap(usedOnMap);
fragment.setAppMode(appMode); fragment.setAppMode(appMode);
fragment.setTargetFragment(target, 0); fragment.setTargetFragment(target, 0);
fragment.setListener(listener);
fragment.show(fm, ChangeGeneralProfilesPrefBottomSheet.TAG); fragment.show(fm, ChangeGeneralProfilesPrefBottomSheet.TAG);
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
LOG.error("showInstance", e); LOG.error("showInstance", e);
} }
} }
public interface OnChangeSettingListener {
void onApplied();
void onDiscard();
}
} }