Fix additional actions menu
This commit is contained in:
parent
dbd348cec8
commit
a660b16bbb
4 changed files with 190 additions and 49 deletions
|
@ -1,36 +1,47 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/bg_color"
|
||||
android:orientation="vertical">
|
||||
android:background="?attr/bg_color">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list_view"
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
<include layout="@layout/bottom_sheet_dialog_fragment_title"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/cancel_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/context_menu_items_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/shared_string_close"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
android:textStyle="bold"/>
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/cancel_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/shared_string_close"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
android:textStyle="bold"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
|
|
@ -444,7 +444,7 @@ public abstract class OsmandPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
public static void registerMapContextMenu(MapActivity map, double latitude, double longitude, ContextMenuAdapter adapter, Object selectedObj, int dividerLayoutResId) {
|
||||
public static void registerMapContextMenu(MapActivity map, double latitude, double longitude, ContextMenuAdapter adapter, Object selectedObj) {
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
if (plugin instanceof ParkingPositionPlugin) {
|
||||
plugin.registerMapContextMenuActions(map, latitude, longitude, adapter, selectedObj);
|
||||
|
@ -459,17 +459,13 @@ public abstract class OsmandPlugin {
|
|||
if (adapter.length() > itemsCount) {
|
||||
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||
.setPosition(itemsCount)
|
||||
.setLayout(dividerLayoutResId)
|
||||
.setLayout(R.layout.bottom_sheet_dialog_fragment_divider)
|
||||
.createItem());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerMapContextMenu(MapActivity map, double latitude, double longitude, ContextMenuAdapter adapter, Object selectedObj) {
|
||||
registerMapContextMenu(map, latitude, longitude, adapter, selectedObj, R.layout.context_menu_list_divider);
|
||||
}
|
||||
|
||||
public static void registerLayerContextMenu(OsmandMapTileView mapView, ContextMenuAdapter adapter, MapActivity mapActivity) {
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
plugin.registerLayerContextMenuActions(mapView, adapter, mapActivity);
|
||||
|
|
|
@ -49,7 +49,7 @@ import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
|
|||
import net.osmand.plus.dialogs.FavoriteDialogs;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.liveupdates.OsmLiveActivity;
|
||||
import net.osmand.plus.mapcontextmenu.ActionsBottomSheetDialogFragment;
|
||||
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
|
||||
import net.osmand.plus.mapmarkers.MarkersPlanRouteContext;
|
||||
import net.osmand.plus.measurementtool.MeasurementToolFragment;
|
||||
|
@ -271,14 +271,6 @@ 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;
|
||||
ItemBuilder itemBuilder = new ItemBuilder();
|
||||
adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_search, mapActivity)
|
||||
.setIcon(R.drawable.ic_action_search_dark).createItem());
|
||||
adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_directions_from, mapActivity)
|
||||
.setIcon(R.drawable.ic_action_gdirections_dark).createItem());
|
||||
adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_search, mapActivity)
|
||||
.setIcon(R.drawable.ic_action_search_dark).createItem());
|
||||
adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_directions_from, mapActivity)
|
||||
.setIcon(R.drawable.ic_action_gdirections_dark).createItem());
|
||||
adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_search, mapActivity)
|
||||
.setIcon(R.drawable.ic_action_search_dark).createItem());
|
||||
adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_directions_from, mapActivity)
|
||||
|
@ -288,7 +280,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_last_intermediate_point, mapActivity)
|
||||
.setIcon(R.drawable.ic_action_intermediate).createItem());
|
||||
}
|
||||
OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj, R.layout.bottom_sheet_dialog_fragment_divider);
|
||||
OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj);
|
||||
|
||||
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
|
@ -324,16 +316,15 @@ public class MapActivityActions implements DialogProvider {
|
|||
final ArrayAdapter<ContextMenuItem> listAdapter =
|
||||
adapter.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent());
|
||||
|
||||
ActionsBottomSheetDialogFragment actionsBottomSheetDialogFragment = new ActionsBottomSheetDialogFragment();
|
||||
actionsBottomSheetDialogFragment.setUsedOnMap(true);
|
||||
actionsBottomSheetDialogFragment.setAdapter(listAdapter, new AdapterView.OnItemClickListener() {
|
||||
AdditionalActionsBottomSheetDialogFragment actionsBottomSheetDialogFragment = new AdditionalActionsBottomSheetDialogFragment();
|
||||
actionsBottomSheetDialogFragment.setAdapter(adapter, new AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
ContextMenuItem item = adapter.getItem(i);
|
||||
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, i, false, null);
|
||||
click.onContextMenuClick(listAdapter, standardId, position, false, null);
|
||||
} else if (standardId == R.string.context_menu_item_last_intermediate_point) {
|
||||
mapActivity.getContextMenu().addAsLastIntermediate();
|
||||
} else if (standardId == R.string.context_menu_item_search) {
|
||||
|
@ -354,7 +345,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
}
|
||||
}
|
||||
});
|
||||
actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), ActionsBottomSheetDialogFragment.TAG);
|
||||
actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
|
||||
public void setGPXRouteParams(GPXFile result) {
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
package net.osmand.plus.mapcontextmenu;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.design.widget.BottomSheetBehavior;
|
||||
import android.support.design.widget.BottomSheetDialog;
|
||||
import android.support.design.widget.BottomSheetDialogFragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
|
||||
public class AdditionalActionsBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = "SnapToRoadBottomSheetDialogFragment";
|
||||
|
||||
private boolean nightMode;
|
||||
private boolean portrait;
|
||||
private ContextMenuAdapter adapter;
|
||||
private ContextMenuItemClickListener listener;
|
||||
|
||||
public void setAdapter(ContextMenuAdapter adapter, ContextMenuItemClickListener listener) {
|
||||
this.adapter = adapter;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupDialog(Dialog dialog, int style) {
|
||||
super.setupDialog(dialog, style);
|
||||
|
||||
if (getMyApplication().getSettings().DO_NOT_USE_ANIMATIONS.get()) {
|
||||
dialog.getWindow().setWindowAnimations(R.style.Animations_NoAnimation);
|
||||
}
|
||||
|
||||
nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
|
||||
final OsmandSettings settings = getMyApplication().getSettings();
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
|
||||
View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_context_menu_actions_bottom_sheet_dialog, null);
|
||||
|
||||
AndroidUtils.setBackground(getActivity(), mainView, nightMode,
|
||||
portrait ? R.drawable.bg_bottom_menu_light : R.drawable.bg_bottom_sheet_topsides_landscape_light,
|
||||
portrait ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_sheet_topsides_landscape_dark);
|
||||
|
||||
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
TextView headerTitle = (TextView) mainView.findViewById(R.id.header_title);
|
||||
if (nightMode) {
|
||||
headerTitle.setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark));
|
||||
}
|
||||
headerTitle.setText(getString(R.string.additional_actions));
|
||||
|
||||
if (!portrait) {
|
||||
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
@Override
|
||||
public void onShow(DialogInterface dialogInterface) {
|
||||
BottomSheetDialog dialog = (BottomSheetDialog) dialogInterface;
|
||||
FrameLayout bottomSheet = (FrameLayout) dialog.findViewById(android.support.design.R.id.design_bottom_sheet);
|
||||
BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
View.OnClickListener onClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (listener != null) {
|
||||
listener.onItemClick((int) view.getTag());
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
|
||||
LinearLayout itemsLinearLayout = (LinearLayout) mainView.findViewById(R.id.context_menu_items_container);
|
||||
for (int i = 0; i < adapter.length(); i++) {
|
||||
ContextMenuItem item = adapter.getItem(i);
|
||||
int layoutResId = item.getLayout();
|
||||
layoutResId = layoutResId != ContextMenuItem.INVALID_ID ? layoutResId : R.layout.bottom_sheet_dialog_fragment_item;
|
||||
View row = View.inflate(new ContextThemeWrapper(getContext(), themeRes), layoutResId, null);
|
||||
if (layoutResId != R.layout.bottom_sheet_dialog_fragment_divider) {
|
||||
if (item.getIcon() != ContextMenuItem.INVALID_ID) {
|
||||
((ImageView) row.findViewById(R.id.icon)).setImageDrawable(getContentIcon(item.getIcon()));
|
||||
}
|
||||
((TextView) row.findViewById(R.id.title)).setText(item.getTitle());
|
||||
}
|
||||
row.setTag(i);
|
||||
row.setOnClickListener(onClickListener);
|
||||
itemsLinearLayout.addView(row);
|
||||
}
|
||||
|
||||
dialog.setContentView(mainView);
|
||||
((View) mainView.getParent()).setBackgroundResource(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (!portrait) {
|
||||
final Window window = getDialog().getWindow();
|
||||
WindowManager.LayoutParams params = window.getAttributes();
|
||||
params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width);
|
||||
window.setAttributes(params);
|
||||
}
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return ((MapActivity) getActivity()).getMyApplication();
|
||||
}
|
||||
|
||||
private Drawable getContentIcon(@DrawableRes int id) {
|
||||
return getMyApplication().getIconsCache().getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
|
||||
}
|
||||
|
||||
public interface ContextMenuItemClickListener {
|
||||
void onItemClick(int position);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue