apply to all dialog / work in progress
This commit is contained in:
parent
54d0245f48
commit
971db3f666
19 changed files with 567 additions and 161 deletions
|
@ -71,6 +71,10 @@ public interface OsmAndCustomizationConstants {
|
|||
|
||||
//Map Context Menu 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_SEARCH_NEARBY = MAP_CONTEXT_MENU_ACTIONS + "search_nearby";
|
||||
String MAP_CONTEXT_MENU_CHANGE_MARKER_POSITION = MAP_CONTEXT_MENU_ACTIONS + "change_m_position";
|
||||
|
|
32
OsmAnd/res/layout/context_menu_action_item.xml
Normal file
32
OsmAnd/res/layout/context_menu_action_item.xml
Normal 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>
|
||||
|
|
@ -5,6 +5,22 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/image_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/activity_background_basic"
|
||||
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"
|
||||
|
@ -12,6 +28,8 @@
|
|||
android:adjustViewBounds="true"
|
||||
tools:src="@drawable/img_settings_customize_configure_map_night" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
android:letterSpacing="@dimen/description_letter_spacing"
|
||||
android:paddingTop="@dimen/list_header_settings_top_margin"
|
||||
android:singleLine="true"
|
||||
android:textColor="@color/preference_category_title"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="@string/plugin_settings" />
|
||||
|
@ -64,6 +64,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:letterSpacing="@dimen/description_letter_spacing"
|
||||
android:paddingBottom="@dimen/list_header_settings_top_margin"
|
||||
android:lineSpacingExtra="@dimen/line_spacing_extra_description"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_regular"
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="@dimen/content_padding_small"
|
||||
android:background="?attr/dashboard_divider"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
@ -79,6 +80,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:letterSpacing="@dimen/description_letter_spacing"
|
||||
android:lineSpacingExtra="@dimen/line_spacing_extra_description"
|
||||
android:maxLines="4"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
<string name="context_menu_actions">Context menu actions</string>
|
||||
<string name="shared_string_drawer">Drawer</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="shared_string_min">Min</string>
|
||||
<string name="shared_string_square">Square</string>
|
||||
|
|
|
@ -52,14 +52,13 @@
|
|||
android:title="@string/profile_appearance"
|
||||
tools:icon="@drawable/ic_action_offroad" />
|
||||
|
||||
<!-- TODO: change description-->
|
||||
<Preference
|
||||
android:key="ui_customization"
|
||||
android:layout="@layout/preference_with_descr"
|
||||
android:persistent="false"
|
||||
android:summary="TODO: change description"
|
||||
android:summary="@string/ui_customization_short_descr"
|
||||
android:title="@string/ui_customization"
|
||||
tools:icon="@drawable/ic_action_offroad" />
|
||||
tools:icon="@drawable/ic_action_ui_customization" />
|
||||
|
||||
<Preference
|
||||
android:layout="@layout/simple_divider_item"
|
||||
|
|
|
@ -641,4 +641,113 @@ public class ContextMenuAdapter {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -412,6 +412,11 @@ public class OsmandSettings {
|
|||
((BooleanPreference) preference).setModeValue(mode, (Boolean) value);
|
||||
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) {
|
||||
if (value instanceof String) {
|
||||
((StringPreference) preference).setModeValue(mode, (String) value);
|
||||
|
@ -1078,6 +1083,24 @@ public class OsmandSettings {
|
|||
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> {
|
||||
|
|
|
@ -753,7 +753,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
}
|
||||
ConfigureMenuItemsFragment configureMenuItemsFragment = getConfigureMenuItemsFragment();
|
||||
if (configureMenuItemsFragment != null) {
|
||||
configureMenuItemsFragment.showExitDialog();
|
||||
configureMenuItemsFragment.exitFragment();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ import net.osmand.plus.routepreparationmenu.WaypointsFragment;
|
|||
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.settings.BaseSettingsFragment;
|
||||
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
|
||||
import net.osmand.plus.views.BaseMapLayer;
|
||||
import net.osmand.plus.views.MapControlsLayer;
|
||||
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_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_ID;
|
||||
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_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_MORE_ID;
|
||||
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_CONTROL_BUTTON_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) {
|
||||
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();
|
||||
|
||||
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
|
||||
.setTitleId(R.string.context_menu_item_directions_from, mapActivity)
|
||||
.setId(MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID)
|
||||
|
@ -348,7 +446,9 @@ public class MapActivityActions implements DialogProvider {
|
|||
.setOrder(SEARCH_NEAR_ITEM_ORDER)
|
||||
.createItem());
|
||||
|
||||
OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj);
|
||||
// if (register){
|
||||
// OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj);
|
||||
// }
|
||||
|
||||
ItemClickListener listener = new ItemClickListener() {
|
||||
@Override
|
||||
|
@ -395,38 +495,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
.createItem());
|
||||
|
||||
adapter.sortItemsByOrder();
|
||||
|
||||
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);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
public void enterDirectionsFromPoint(final double latitude, final double longitude) {
|
||||
|
@ -1125,6 +1194,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
}
|
||||
menuItemsListView.setDivider(null);
|
||||
final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu();
|
||||
contextMenuAdapter.initItemsCustomOrder(getMyApplication(), ScreenType.DRAWER);
|
||||
contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item);
|
||||
final ArrayAdapter<ContextMenuItem> simpleListAdapter = contextMenuAdapter.createListAdapter(mapActivity,
|
||||
!nightMode);
|
||||
|
|
|
@ -77,6 +77,7 @@ import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
|||
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter;
|
||||
import net.osmand.plus.routing.IRouteInformationListener;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
|
||||
import net.osmand.plus.srtmplugin.ContourLinesMenu;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
import net.osmand.plus.srtmplugin.TerrainFragment;
|
||||
|
@ -697,6 +698,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
|
|||
cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity);
|
||||
} else if (visibleType == DashboardType.CONFIGURE_MAP) {
|
||||
cm = new ConfigureMapMenu().createListAdapter(mapActivity);
|
||||
cm.initItemsCustomOrder(getMyApplication(), ScreenType.CONFIGURE_MAP);
|
||||
} else if (visibleType == DashboardType.LIST_MENU) {
|
||||
cm = mapActivity.getMapActions().createMainOptionsMenu();
|
||||
} else if (visibleType == DashboardType.ROUTE_PREFERENCES) {
|
||||
|
|
|
@ -51,6 +51,7 @@ import net.osmand.plus.inapp.InAppPurchaseHelper;
|
|||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.corenative.NativeCoreContext;
|
||||
|
@ -151,7 +152,6 @@ public class ConfigureMapMenu {
|
|||
adapter.setNightMode(nightMode);
|
||||
createLayersItems(customRules, adapter, ma, themeRes, nightMode);
|
||||
createRenderingAttributeItems(customRules, adapter, ma, themeRes, nightMode);
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
|
|
|
@ -1064,14 +1064,22 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
public void buttonMorePressed() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
final ContextMenuAdapter menuAdapter = new ContextMenuAdapter();
|
||||
LatLon latLon = getLatLon();
|
||||
for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) {
|
||||
layer.populateObjectContextMenu(latLon, getObject(), menuAdapter, mapActivity);
|
||||
mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), getAdapter(), getObject());
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -19,9 +20,11 @@ import androidx.fragment.app.FragmentActivity;
|
|||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.PagerSnapHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
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.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
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.settings.RearrangeMenuItemsAdapter.AdapterItem;
|
||||
import net.osmand.plus.settings.RearrangeMenuItemsAdapter.MenuItemsAdapterListener;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
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.DESCRIPTION;
|
||||
import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DIVIDER;
|
||||
|
@ -63,6 +70,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
private ScreenType screenType;
|
||||
private boolean nightMode;
|
||||
private boolean wasReset = false;
|
||||
private boolean isChanged = false;
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
|
@ -100,6 +108,8 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
contextMenuAdapter = configureMapMenu.createListAdapter((MapActivity) activity);
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
MapContextMenu menu = ((MapActivity) activity).getContextMenu();
|
||||
contextMenuAdapter = menu.getAdapter();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -111,19 +121,20 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
hiddenMenuItems = savedInstanceState.getStringArrayList(HIDDEN_ITEMS_KEY);
|
||||
menuItemsOrder = (HashMap<String, Integer>) savedInstanceState.getSerializable(ITEMS_ORDER_KEY);
|
||||
} else {
|
||||
hiddenMenuItems = getHiddenItemsIds(screenType);
|
||||
menuItemsOrder = contextMenuAdapter.getMenuItemsOrder(getItemsIdsOrder(screenType));
|
||||
hiddenMenuItems = contextMenuAdapter.getHiddenItemsIds(app, screenType);
|
||||
menuItemsOrder = contextMenuAdapter.getMenuItemsOrder(contextMenuAdapter.getItemsIdsOrder(app, screenType));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@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);
|
||||
Toolbar toolbar = root.findViewById(R.id.toolbar);
|
||||
TextView toolbarTitle = root.findViewById(R.id.toolbar_title);
|
||||
ImageButton toolbarButton = root.findViewById(R.id.close_button);
|
||||
RecyclerView recyclerView = root.findViewById(R.id.profiles_list);
|
||||
recyclerView.setPadding(0, 0, 0, AndroidUtils.dpToPx(app, 72));
|
||||
toolbar.setBackgroundColor(nightMode
|
||||
? getResources().getColor(R.color.list_background_color_dark)
|
||||
: getResources().getColor(R.color.list_background_color_light));
|
||||
|
@ -135,7 +146,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
toolbarButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showExitDialog();
|
||||
exitFragment();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -174,6 +185,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
hiddenMenuItems.remove(menuItemBase.getId());
|
||||
}
|
||||
wasReset = false;
|
||||
isChanged = true;
|
||||
rearrangeAdapter.updateItems(getAdapterItems());
|
||||
}
|
||||
}
|
||||
|
@ -182,6 +194,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
public void onItemMoved(String id, int position) {
|
||||
menuItemsOrder.put(id, position);
|
||||
wasReset = false;
|
||||
isChanged = true;
|
||||
}
|
||||
};
|
||||
rearrangeAdapter.setListener(listener);
|
||||
|
@ -204,20 +217,46 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
applyButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (wasReset) {
|
||||
resetMenuItems(screenType);
|
||||
} else {
|
||||
saveHiddenItemsIds(screenType, hiddenMenuItems);
|
||||
// if (wasReset) {
|
||||
// contextMenuAdapter.resetMenuItems(app, screenType);
|
||||
// } else {
|
||||
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);
|
||||
contextMenuAdapter.reorderMenuItems(defItems, menuItemsOrder);
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (ContextMenuItem item : defItems) {
|
||||
ids.add(item.getId());
|
||||
}
|
||||
saveItemsIdsOrder(screenType, ids);
|
||||
}
|
||||
prefsMap.put(contextMenuAdapter.getPrefIdOrder(app, screenType), (Serializable) ids);
|
||||
|
||||
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) {
|
||||
AndroidUtils.addStatusBarPadding21v(app, root);
|
||||
|
@ -231,7 +270,29 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
|
||||
List<AdapterItem> visible = contextMenuAdapter.getItemsForRearrangeAdapter(screenType, hiddenMenuItems, wasReset ? null : menuItemsOrder, false);
|
||||
List<AdapterItem> hiddenItems = contextMenuAdapter.getItemsForRearrangeAdapter(screenType, hiddenMenuItems, wasReset ? null : menuItemsOrder, true);
|
||||
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()) {
|
||||
items.add(new AdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.shared_string_hidden, R.string.hidden_items_descr)));
|
||||
items.addAll(hiddenItems);
|
||||
|
@ -246,6 +307,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
hiddenMenuItems.clear();
|
||||
menuItemsOrder.clear();
|
||||
wasReset = true;
|
||||
isChanged = true;
|
||||
rearrangeAdapter.updateItems(getAdapterItems());
|
||||
}
|
||||
})));
|
||||
|
@ -261,6 +323,14 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
return items;
|
||||
}
|
||||
|
||||
public void exitFragment() {
|
||||
if (isChanged) {
|
||||
showExitDialog();
|
||||
} else {
|
||||
dismissFragment();
|
||||
}
|
||||
}
|
||||
|
||||
public void showExitDialog() {
|
||||
Context themedContext = UiUtilities.getThemedContext(getActivity(), nightMode);
|
||||
AlertDialog.Builder dismissDialog = new AlertDialog.Builder(themedContext);
|
||||
|
@ -286,71 +356,4 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
private void setScreenType(@NonNull 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -26,11 +27,15 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.MapActivityActions;
|
||||
import net.osmand.plus.activities.PluginsActivity;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
|
||||
|
||||
|
@ -41,6 +46,8 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType.CONFIGURE_MAP;
|
||||
|
||||
public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
|
||||
|
||||
public static final String TAG = ConfigureMenuRootFragment.class.getName();
|
||||
|
@ -202,23 +209,30 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
private String getSubTitleText(ScreenType type) {
|
||||
List<String> hiddenItems = null;
|
||||
ContextMenuAdapter contextMenuAdapter = null;
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof MapActivity) {
|
||||
switch (type) {
|
||||
case DRAWER:
|
||||
hiddenItems = app.getSettings().HIDDEN_DRAWER_ITEMS.getStringsList();
|
||||
MapActivityActions mapActivityActions = new MapActivityActions((MapActivity) activity);
|
||||
contextMenuAdapter = mapActivityActions.createMainOptionsMenu();
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
hiddenItems = app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getStringsList();
|
||||
ConfigureMapMenu configureMapMenu = new ConfigureMapMenu();
|
||||
contextMenuAdapter = configureMapMenu.createListAdapter((MapActivity) activity);
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
hiddenItems = app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.getStringsList();
|
||||
ConfigureMapMenu configureaMapMenu = new ConfigureMapMenu();
|
||||
contextMenuAdapter = configureaMapMenu.createListAdapter((MapActivity) activity);
|
||||
break;
|
||||
}
|
||||
int hiddenCount = hiddenItems != null ? hiddenItems.size() : 0;
|
||||
int allCount = 0;
|
||||
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);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
class DescriptionHolder extends RecyclerView.ViewHolder {
|
||||
ImageView image;
|
||||
|
|
|
@ -390,10 +390,11 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
|
|||
return;
|
||||
}
|
||||
Preference uiCustomization = findPreference(UI_CUSTOMIZATION);
|
||||
// TODO change icon
|
||||
uiCustomization.setIcon(getContentIcon(getSelectedAppMode().getIconRes()));
|
||||
if (uiCustomization != null) {
|
||||
uiCustomization.setIcon(getContentIcon(R.drawable.ic_action_ui_customization));
|
||||
uiCustomization.setFragment(ConfigureMenuRootFragment.TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -21,6 +22,7 @@ import net.osmand.plus.ContextMenuItem;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
|
||||
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
|
||||
|
||||
|
@ -29,6 +31,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
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.RENDERING_ITEMS_ID_SCHEME;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.SHOW_CATEGORY_ID;
|
||||
|
@ -96,14 +99,30 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
if (holder instanceof DescriptionHolder) {
|
||||
DescriptionHolder h = (DescriptionHolder) holder;
|
||||
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.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) {
|
||||
final ItemHolder h = (ItemHolder) holder;
|
||||
ContextMenuItem menuItem = (ContextMenuItem) item.value;
|
||||
String id = menuItem.getId();
|
||||
if (DRAWER_DIVIDER_ID.equals(menuItem.getId())) {
|
||||
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.icon.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)
|
||||
|| MAP_RENDERING_CATEGORY_ID.equals(id)) {
|
||||
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.icon.setVisibility(View.GONE);
|
||||
h.actionIcon.setVisibility(View.GONE);
|
||||
|
@ -147,13 +168,20 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
return false;
|
||||
}
|
||||
});
|
||||
if (menuItem.isHidden()) {
|
||||
h.moveIcon.setVisibility(View.GONE);
|
||||
h.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_undo, R.color.color_osm_edit_create));
|
||||
} else {
|
||||
if (!menuItem.isHidden()
|
||||
&& !id.equals(SHOW_CATEGORY_ID)
|
||||
&& !id.equals(MAP_RENDERING_CATEGORY_ID)) {
|
||||
h.moveIcon.setVisibility(View.VISIBLE);
|
||||
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));
|
||||
} 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) {
|
||||
HeaderHolder h = (HeaderHolder) holder;
|
||||
|
@ -216,12 +244,16 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
private static class DescriptionHolder extends RecyclerView.ViewHolder
|
||||
implements ReorderItemTouchHelperCallback.UnmovableItem {
|
||||
private ImageView image;
|
||||
private ImageView deviceImage;
|
||||
private TextView description;
|
||||
private FrameLayout imageContainer;
|
||||
|
||||
DescriptionHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
image = itemView.findViewById(R.id.image);
|
||||
deviceImage = itemView.findViewById(R.id.device_image);
|
||||
description = itemView.findViewById(R.id.description);
|
||||
imageContainer = itemView.findViewById(R.id.image_container);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,9 @@ import net.osmand.plus.settings.BaseSettingsFragment;
|
|||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
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 PREFS_MAP_KEY = "prefs_map_key";
|
||||
|
||||
@Nullable
|
||||
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
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
|
@ -39,11 +58,12 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
if (app == null || args == null) {
|
||||
return;
|
||||
}
|
||||
final String prefId = args.getString(PREFERENCE_ID);
|
||||
prefId = args.getString(PREFERENCE_ID);
|
||||
newValue = args.getSerializable(NEW_VALUE_KEY);
|
||||
if (newValue == null || prefId == null) {
|
||||
return;
|
||||
}
|
||||
prefsMap = (HashMap<String, Serializable>) args.getSerializable(PREFS_MAP_KEY);
|
||||
// if (newValue == null || prefId == null) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
items.add(new TitleItem(getString(R.string.change_default_settings)));
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (prefsMap != null) {
|
||||
savePrefs(app, prefsMap, true);
|
||||
} else if (newValue != null || prefId != null) {
|
||||
app.getSettings().setPreferenceForAllModes(prefId, newValue);
|
||||
}
|
||||
updateTargetSettings(false, true);
|
||||
if (listener != null) {
|
||||
listener.onApplied();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
|
@ -72,8 +99,15 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (prefsMap != null) {
|
||||
savePrefs(app, prefsMap, false);
|
||||
} else if (newValue != null || prefId != null) {
|
||||
app.getSettings().setPreference(prefId, newValue, getAppMode());
|
||||
}
|
||||
updateTargetSettings(false, false);
|
||||
if (listener != null) {
|
||||
listener.onApplied();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
|
@ -88,6 +122,9 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
updateTargetSettings(true, false);
|
||||
if (listener != null) {
|
||||
listener.onDiscard();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
|
@ -106,6 +143,18 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
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) {
|
||||
BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment();
|
||||
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,
|
||||
boolean usedOnMap, @Nullable ApplicationMode appMode) {
|
||||
public static void showInstance(@NonNull FragmentManager fm,
|
||||
@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 {
|
||||
if (fm.findFragmentByTag(ChangeGeneralProfilesPrefBottomSheet.TAG) == null) {
|
||||
Bundle args = new Bundle();
|
||||
if (prefId != null) {
|
||||
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();
|
||||
fragment.setArguments(args);
|
||||
fragment.setUsedOnMap(usedOnMap);
|
||||
fragment.setAppMode(appMode);
|
||||
fragment.setTargetFragment(target, 0);
|
||||
fragment.setListener(listener);
|
||||
fragment.show(fm, ChangeGeneralProfilesPrefBottomSheet.TAG);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("showInstance", e);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnChangeSettingListener {
|
||||
void onApplied();
|
||||
|
||||
void onDiscard();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue