Revert "ContextMenuAdapter refactoring. Need to review GpxUiHelper."

This reverts commit f010b21fda.
This commit is contained in:
GaidamakUA 2016-03-25 15:29:25 +02:00
parent 61cc83da27
commit 1ae6683dbc
8 changed files with 167 additions and 135 deletions

View file

@ -6,6 +6,7 @@ import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
@ -37,12 +38,53 @@ import gnu.trove.list.array.TIntArrayList;
public class ContextMenuAdapter { public class ContextMenuAdapter {
private static final Log LOG = PlatformUtil.getLog(ContextMenuAdapter.class); private static final Log LOG = PlatformUtil.getLog(ContextMenuAdapter.class);
public interface OnContextMenuClick {
//boolean return type needed to desribe if drawer needed to be close or not
boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked);
}
public interface OnIntegerValueChangedListener {
boolean onIntegerValueChangedListener(int newValue);
}
public static abstract class OnRowItemClick implements OnContextMenuClick {
public OnRowItemClick() {
}
//boolean return type needed to desribe if drawer needed to be close or not
public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked());
return false;
} else {
return onContextMenuClick(adapter, itemId, pos, false);
}
}
}
public class BooleanResult {
private boolean result = false;
public void setResult(boolean value) {
result = value;
}
public boolean getResult() {
return result;
}
}
private final Context ctx; private final Context ctx;
private View anchor;
@LayoutRes @LayoutRes
private int defaultLayoutId = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? private int defaultLayoutId = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ?
R.layout.list_menu_item : R.layout.list_menu_item_native; R.layout.list_menu_item : R.layout.list_menu_item_native;
final TIntArrayList titleResList = new TIntArrayList(); final TIntArrayList items = new TIntArrayList();
final TIntArrayList isCategory = new TIntArrayList(); final TIntArrayList isCategory = new TIntArrayList();
final ArrayList<String> itemNames = new ArrayList<String>();
final ArrayList<OnContextMenuClick> checkListeners = new ArrayList<>(); final ArrayList<OnContextMenuClick> checkListeners = new ArrayList<>();
final ArrayList<OnIntegerValueChangedListener> integerListeners = new ArrayList<>(); final ArrayList<OnIntegerValueChangedListener> integerListeners = new ArrayList<>();
final TIntArrayList selectedList = new TIntArrayList(); final TIntArrayList selectedList = new TIntArrayList();
@ -52,8 +94,8 @@ public class ContextMenuAdapter {
final TIntArrayList iconList = new TIntArrayList(); final TIntArrayList iconList = new TIntArrayList();
final TIntArrayList lightIconList = new TIntArrayList(); final TIntArrayList lightIconList = new TIntArrayList();
final TIntArrayList secondaryLightIconList = new TIntArrayList(); final TIntArrayList secondaryLightIconList = new TIntArrayList();
final ArrayList<String> itemDescription = new ArrayList<>(); final ArrayList<String> itemDescription = new ArrayList<String>();
private List<ApplicationMode> visibleModes = new ArrayList<>(); private List<ApplicationMode> visibleModes = new ArrayList<ApplicationMode>();
private ConfigureMapMenu.OnClickListener changeAppModeListener = null; private ConfigureMapMenu.OnClickListener changeAppModeListener = null;
//neded to detect whether user opened all modes or not //neded to detect whether user opened all modes or not
private BooleanResult allModes = new BooleanResult(); private BooleanResult allModes = new BooleanResult();
@ -67,37 +109,20 @@ public class ContextMenuAdapter {
this.ctx = ctx; this.ctx = ctx;
} }
// Related to whole adapter public void setAnchor(View anchor) {
this.anchor = anchor;
}
public View getAnchor() {
return anchor;
}
public int length() { public int length() {
return titleResList.size(); return items.size();
} }
public void setDefaultLayoutId(int defaultLayoutId) { public int getElementId(int pos) {
this.defaultLayoutId = defaultLayoutId; return items.get(pos);
}
public void setChangeAppModeListener(ConfigureMapMenu.OnClickListener changeAppModeListener) {
this.changeAppModeListener = changeAppModeListener;
}
public ArrayAdapter<?> createListAdapter(final Activity activity, final boolean holoLight) {
final int layoutId = defaultLayoutId;
final OsmandApplication app = ((OsmandApplication) activity.getApplication());
String[] names = new String[titleResList.size()];
for (int i = 0; i < titleResList.size(); i++) {
names[i] = activity.getString(titleResList.get(i));
}
return new ContextMenuArrayAdapter(activity, layoutId, R.id.title, names, app, holoLight);
}
public int[] getTitleResources() {
return titleResList.toArray();
}
// Item related
@StringRes
public int getTitleRes(int pos) {
return titleResList.get(pos);
} }
public OnContextMenuClick getClickAdapter(int i) { public OnContextMenuClick getClickAdapter(int i) {
@ -108,10 +133,18 @@ public class ContextMenuAdapter {
return integerListeners.get(i); return integerListeners.get(i);
} }
public String getItemName(int pos) {
return itemNames.get(pos);
}
public String getItemDescr(int pos) { public String getItemDescr(int pos) {
return itemDescription.get(pos); return itemDescription.get(pos);
} }
public void setItemName(int pos, String str) {
itemNames.set(pos, str);
}
public void setItemDescription(int pos, String str) { public void setItemDescription(int pos, String str) {
itemDescription.set(pos, str); itemDescription.set(pos, str);
} }
@ -136,6 +169,7 @@ public class ContextMenuAdapter {
progressList.set(pos, s); progressList.set(pos, s);
} }
public Drawable getImage(OsmandApplication ctx, int pos, boolean light) { public Drawable getImage(OsmandApplication ctx, int pos, boolean light) {
int lst = iconList.get(pos); int lst = iconList.get(pos);
if (lst != 0) { if (lst != 0) {
@ -157,35 +191,22 @@ public class ContextMenuAdapter {
return null; return null;
} }
public int getBackgroundColor(Context ctx, boolean holoLight) {
if (holoLight) {
return ctx.getResources().getColor(R.color.bg_color_light);
} else {
return ctx.getResources().getColor(R.color.bg_color_dark);
}
}
public boolean isCategory(int pos) { public boolean isCategory(int pos) {
return isCategory.get(pos) > 0; return isCategory.get(pos) > 0;
} }
public void removeItem(int pos) {
titleResList.removeAt(pos);
selectedList.removeAt(pos);
progressList.removeAt(pos);
iconList.removeAt(pos);
lightIconList.removeAt(pos);
secondaryLightIconList.removeAt(pos);
checkListeners.remove(pos);
integerListeners.remove(pos);
isCategory.removeAt(pos);
layoutIds.removeAt(pos);
loadingList.removeAt(pos);
}
public int getLayoutId(int position) {
int l = layoutIds.get(position);
if (l != -1) {
return l;
}
return defaultLayoutId;
}
public Item item(String name) { public Item item(String name) {
Item i = new Item(); Item i = new Item();
i.title = (name.hashCode() << 4) | titleResList.size(); i.id = (name.hashCode() << 4) | items.size();
i.name = name; i.name = name;
return i; return i;
} }
@ -193,7 +214,7 @@ public class ContextMenuAdapter {
public Item item(@StringRes int resId) { public Item item(@StringRes int resId) {
Item i = new Item(); Item i = new Item();
i.title = resId; i.id = resId;
i.name = ctx.getString(resId); i.name = ctx.getString(resId);
return i; return i;
} }
@ -202,11 +223,11 @@ public class ContextMenuAdapter {
@DrawableRes @DrawableRes
int icon = 0; int icon = 0;
@DrawableRes @DrawableRes
int secondaryIcon = 0;
@DrawableRes
int lightIcon = 0; int lightIcon = 0;
@StringRes @DrawableRes
int title; int secondaryLightIcon = 0;
@IdRes
int id;
String name; String name;
int selected = -1; int selected = -1;
int progress = -1; int progress = -1;
@ -227,14 +248,13 @@ public class ContextMenuAdapter {
return this; return this;
} }
public Item colorIcon(@DrawableRes int icon) { public Item colorIcon(@DrawableRes int icon) {
this.lightIcon = icon; this.lightIcon = icon;
return this; return this;
} }
public Item secondaryIconColor(@DrawableRes int icon) { public Item secondaryIconColor(@DrawableRes int icon) {
this.secondaryIcon = icon; this.secondaryLightIcon = icon;
return this; return this;
} }
@ -279,10 +299,11 @@ public class ContextMenuAdapter {
} }
public void reg() { public void reg() {
if (pos >= titleResList.size() || pos < 0) { if (pos >= items.size() || pos < 0) {
pos = titleResList.size(); pos = items.size();
} }
titleResList.insert(pos, title); items.insert(pos, id);
itemNames.add(pos, name);
itemDescription.add(pos, description); itemDescription.add(pos, description);
selectedList.insert(pos, selected); selectedList.insert(pos, selected);
progressList.insert(pos, progress); progressList.insert(pos, progress);
@ -290,7 +311,7 @@ public class ContextMenuAdapter {
layoutIds.insert(pos, layout); layoutIds.insert(pos, layout);
iconList.insert(pos, icon); iconList.insert(pos, icon);
lightIconList.insert(pos, lightIcon); lightIconList.insert(pos, lightIcon);
secondaryLightIconList.insert(pos, secondaryIcon); secondaryLightIconList.insert(pos, secondaryLightIcon);
checkListeners.add(pos, checkBoxListener); checkListeners.add(pos, checkBoxListener);
integerListeners.add(pos, integerListener); integerListeners.add(pos, integerListener);
isCategory.insert(pos, cat ? 1 : 0); isCategory.insert(pos, cat ? 1 : 0);
@ -308,6 +329,51 @@ public class ContextMenuAdapter {
} }
public String[] getItemNames() {
return itemNames.toArray(new String[itemNames.size()]);
}
public void removeItem(int pos) {
items.removeAt(pos);
itemNames.remove(pos);
selectedList.removeAt(pos);
progressList.removeAt(pos);
iconList.removeAt(pos);
lightIconList.removeAt(pos);
secondaryLightIconList.removeAt(pos);
checkListeners.remove(pos);
integerListeners.remove(pos);
isCategory.removeAt(pos);
layoutIds.removeAt(pos);
loadingList.removeAt(pos);
}
public int getLayoutId(int position) {
int l = layoutIds.get(position);
if (l != -1) {
return l;
}
return defaultLayoutId;
}
public void setDefaultLayoutId(int defaultLayoutId) {
this.defaultLayoutId = defaultLayoutId;
}
public void setChangeAppModeListener(ConfigureMapMenu.OnClickListener changeAppModeListener) {
this.changeAppModeListener = changeAppModeListener;
}
public ArrayAdapter<?> createListAdapter(final Activity activity, final boolean holoLight) {
final int layoutId = defaultLayoutId;
final OsmandApplication app = ((OsmandApplication) activity.getApplication());
return new ContextMenuArrayAdapter(activity, layoutId, R.id.title,
getItemNames(), app, holoLight);
}
public class ContextMenuArrayAdapter extends ArrayAdapter<String> { public class ContextMenuArrayAdapter extends ArrayAdapter<String> {
private Activity activity; private Activity activity;
private OsmandApplication app; private OsmandApplication app;
@ -315,8 +381,8 @@ public class ContextMenuAdapter {
private int layoutId; private int layoutId;
public ContextMenuArrayAdapter(Activity context, int resource, int textViewResourceId, public ContextMenuArrayAdapter(Activity context, int resource, int textViewResourceId,
String[] names, OsmandApplication app, boolean holoLight) { String[] objects, OsmandApplication app, boolean holoLight) {
super(context, resource, textViewResourceId, names); super(context, resource, textViewResourceId, objects);
activity = context; activity = context;
this.app = app; this.app = app;
this.holoLight = holoLight; this.holoLight = holoLight;
@ -328,7 +394,7 @@ public class ContextMenuAdapter {
// User super class to create the View // User super class to create the View
Integer lid = getLayoutId(position); Integer lid = getLayoutId(position);
if (lid == R.layout.mode_toggles) { if (lid == R.layout.mode_toggles) {
final Set<ApplicationMode> selected = new LinkedHashSet<>(); final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>();
return AppModeDialog.prepareAppModeDrawerView(activity, visibleModes, selected, allModes, true, new View.OnClickListener() { return AppModeDialog.prepareAppModeDrawerView(activity, visibleModes, selected, allModes, true, new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -351,7 +417,7 @@ public class ContextMenuAdapter {
if (!isCategory(position)) { if (!isCategory(position)) {
AndroidUtils.setTextPrimaryColor(ctx, tv, !holoLight); AndroidUtils.setTextPrimaryColor(ctx, tv, !holoLight);
} }
tv.setText(isCategory(position) ? getItem(position).toUpperCase() : getItem(position)); tv.setText(isCategory(position) ? getItemName(position).toUpperCase() : getItemName(position));
if (layoutId == R.layout.simple_list_menu_item) { if (layoutId == R.layout.simple_list_menu_item) {
int color = activity.getResources() int color = activity.getResources()
@ -411,7 +477,7 @@ public class ContextMenuAdapter {
OnContextMenuClick ca = getClickAdapter(position); OnContextMenuClick ca = getClickAdapter(position);
selectedList.set(position, isChecked ? 1 : 0); selectedList.set(position, isChecked ? 1 : 0);
if (ca != null) { if (ca != null) {
ca.onContextMenuClick(la, getTitleRes(position), position, isChecked); ca.onContextMenuClick(la, getElementId(position), position, isChecked);
} }
} }
}; };
@ -466,42 +532,4 @@ public class ContextMenuAdapter {
return convertView; return convertView;
} }
} }
public interface OnContextMenuClick {
//boolean return type needed to desribe if drawer needed to be close or not
boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked);
}
public interface OnIntegerValueChangedListener {
boolean onIntegerValueChangedListener(int newValue);
}
public static abstract class OnRowItemClick implements OnContextMenuClick {
public OnRowItemClick() {
}
//boolean return type needed to desribe if drawer needed to be close or not
public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked());
return false;
} else {
return onContextMenuClick(adapter, itemId, pos, false);
}
}
}
public class BooleanResult {
private boolean result = false;
public void setResult(boolean value) {
result = value;
}
public boolean getResult() {
return result;
}
}
} }

View file

@ -271,6 +271,10 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
// if (item.getElementId() == EXPORT_ID) {
// export();
// return true;
// } else
if (item.getItemId() == SELECT_MAP_MARKERS_ID) { if (item.getItemId() == SELECT_MAP_MARKERS_ID) {
selectMapMarkers(); selectMapMarkers();
return true; return true;

View file

@ -298,7 +298,7 @@ public class MapActivityActions implements DialogProvider {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
int standardId = adapter.getTitleRes(which); int standardId = adapter.getElementId(which);
OnContextMenuClick click = adapter.getClickAdapter(which); OnContextMenuClick click = adapter.getClickAdapter(which);
if (click != null) { if (click != null) {
click.onContextMenuClick(listAdapter, standardId, which, false); click.onContextMenuClick(listAdapter, standardId, which, false);
@ -883,7 +883,7 @@ public class MapActivityActions implements DialogProvider {
ContextMenuAdapter.OnContextMenuClick click = ContextMenuAdapter.OnContextMenuClick click =
contextMenuAdapter.getClickAdapter(position); contextMenuAdapter.getClickAdapter(position);
if (click.onContextMenuClick(simpleListAdapter, if (click.onContextMenuClick(simpleListAdapter,
contextMenuAdapter.getTitleRes(position), position, false)) { contextMenuAdapter.getElementId(position), position, false)) {
mapActivity.closeDrawer(); mapActivity.closeDrawer();
} }
} }

View file

@ -1011,7 +1011,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
public void onItemClick(AdapterView<?> parent, View view, int which, long id) { public void onItemClick(AdapterView<?> parent, View view, int which, long id) {
OnContextMenuClick click = cm.getClickAdapter(which); OnContextMenuClick click = cm.getClickAdapter(which);
if (click instanceof OnRowItemClick) { if (click instanceof OnRowItemClick) {
boolean cl = ((OnRowItemClick) click).onRowItemClick(listAdapter, view, cm.getTitleRes(which), which); boolean cl = ((OnRowItemClick) click).onRowItemClick(listAdapter, view, cm.getElementId(which), which);
if (cl) { if (cl) {
hideDashboard(); hideDashboard();
} }
@ -1020,7 +1020,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
if (btn != null && btn.getVisibility() == View.VISIBLE) { if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked()); btn.setChecked(!btn.isChecked());
} else { } else {
if (click.onContextMenuClick(listAdapter, cm.getTitleRes(which), which, false)) { if (click.onContextMenuClick(listAdapter, cm.getElementId(which), which, false)) {
hideDashboard(); hideDashboard();
} }
} }

View file

@ -175,17 +175,13 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
basicFileOperation(info, adapter); basicFileOperation(info, adapter);
OsmandPlugin.onContextMenuActivity(getActivity(), null, info, adapter); OsmandPlugin.onContextMenuActivity(getActivity(), null, info, adapter);
int[] titleResources = adapter.getTitleResources(); String[] values = adapter.getItemNames();
String[] values = new String[titleResources.length];
for (int i = 0; i < titleResources.length; i++) {
values[i] = getString(titleResources[i]);
}
builder.setItems(values, new DialogInterface.OnClickListener() { builder.setItems(values, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
OnContextMenuClick clk = adapter.getClickAdapter(which); OnContextMenuClick clk = adapter.getClickAdapter(which);
if (clk != null) { if (clk != null) {
clk.onContextMenuClick(null, adapter.getTitleRes(which), which, false); clk.onContextMenuClick(null, adapter.getElementId(which), which, false);
} }
} }
@ -615,10 +611,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
split.getItem(); split.getItem();
MenuItemCompat.setShowAsAction(split.getItem(), MenuItemCompat.SHOW_AS_ACTION_ALWAYS); MenuItemCompat.setShowAsAction(split.getItem(), MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
} }
item = split.add(0, optionsMenuAdapter.getTitleRes(j), j + 1, optionsMenuAdapter.getTitleRes(j)); item = split.add(0, optionsMenuAdapter.getElementId(j), j + 1, optionsMenuAdapter.getItemName(j));
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
} else { } else {
item = menu.add(0, optionsMenuAdapter.getTitleRes(j), j + 1, optionsMenuAdapter.getTitleRes(j)); item = menu.add(0, optionsMenuAdapter.getElementId(j), j + 1, optionsMenuAdapter.getItemName(j));
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
} }
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
@ -639,7 +635,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId(); int itemId = item.getItemId();
for (int i = 0; i < optionsMenuAdapter.length(); i++) { for (int i = 0; i < optionsMenuAdapter.length(); i++) {
if (itemId == optionsMenuAdapter.getTitleRes(i)) { if (itemId == optionsMenuAdapter.getElementId(i)) {
optionsMenuAdapter.getClickAdapter(i).onContextMenuClick(null, itemId, i, false); optionsMenuAdapter.getClickAdapter(i).onContextMenuClick(null, itemId, i, false);
return true; return true;
} }

View file

@ -243,8 +243,7 @@ public class GpxUiHelper {
@Override @Override
public boolean processResult(GPXFile[] result) { public boolean processResult(GPXFile[] result) {
cmAdapter.setItemDescription(position, cmAdapter.setItemName(position, cmAdapter.getItemName(position) + "\n" + getDescription((OsmandApplication) app, result[0], f, false));
getDescription((OsmandApplication) app, result[0], f, false));
adapter.notifyDataSetInvalidated(); adapter.notifyDataSetInvalidated();
return true; return true;
} }
@ -261,13 +260,8 @@ public class GpxUiHelper {
final boolean light = app.getSettings().isLightContent(); final boolean light = app.getSettings().isLightContent();
final int layout = R.layout.list_menu_item_native; final int layout = R.layout.list_menu_item_native;
int[] tileIds = adapter.getTitleResources(); final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout, R.id.title,
String[] titles = new String[tileIds.length]; adapter.getItemNames()) {
for (int i = 0; i < tileIds.length; i++) {
titles[i] = activity.getString(tileIds[i]);
}
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout,
R.id.title, titles) {
@Override @Override
public View getView(final int position, View convertView, ViewGroup parent) { public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View // User super class to create the View
@ -284,10 +278,11 @@ public class GpxUiHelper {
if (showCurrentGpx && position == 0) { if (showCurrentGpx && position == 0) {
return; return;
} }
if (adapter.getItemDescr(position) == null) { int nline = adapter.getItemName(position).indexOf('\n');
if (nline == -1) {
setDescripionInDialog(arrayAdapter, adapter, activity, dir, list.get(position), position); setDescripionInDialog(arrayAdapter, adapter, activity, dir, list.get(position), position);
} else { } else {
adapter.setItemDescription(position, null); adapter.setItemName(position, adapter.getItemName(position).substring(0, nline));
arrayAdapter.notifyDataSetInvalidated(); arrayAdapter.notifyDataSetInvalidated();
} }
} }
@ -299,7 +294,7 @@ public class GpxUiHelper {
icon.setVisibility(View.VISIBLE); icon.setVisibility(View.VISIBLE);
} }
TextView tv = (TextView) v.findViewById(R.id.title); TextView tv = (TextView) v.findViewById(R.id.title);
tv.setText(adapter.getTitleRes(position)); tv.setText(adapter.getItemName(position));
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
// Put the image on the TextView // Put the image on the TextView

View file

@ -78,6 +78,8 @@ import java.util.Set;
public class AvailableGPXFragment extends OsmandExpandableListFragment { public class AvailableGPXFragment extends OsmandExpandableListFragment {
public static final int SEARCH_ID = -1; public static final int SEARCH_ID = -1;
// public static final int ACTION_ID = 0;
// protected static final int DELETE_ACTION_ID = 1;
private boolean selectionMode = false; private boolean selectionMode = false;
private List<GpxInfo> selectedItems = new ArrayList<>(); private List<GpxInfo> selectedItems = new ArrayList<>();
private ActionMode actionMode; private ActionMode actionMode;
@ -355,7 +357,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
OsmandPlugin.onOptionsMenuActivity(getActivity(), this, optionsMenuAdapter); OsmandPlugin.onOptionsMenuActivity(getActivity(), this, optionsMenuAdapter);
for (int j = 0; j < optionsMenuAdapter.length(); j++) { for (int j = 0; j < optionsMenuAdapter.length(); j++) {
final MenuItem item; final MenuItem item;
item = menu.add(0, optionsMenuAdapter.getTitleRes(j), j + 1, optionsMenuAdapter.getTitleRes(j)); item = menu.add(0, optionsMenuAdapter.getElementId(j), j + 1, optionsMenuAdapter.getItemName(j));
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
if (AndroidUiHelper.isOrientationPortrait(getActivity())) { if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@ -390,7 +392,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId(); int itemId = item.getItemId();
for (int i = 0; i < optionsMenuAdapter.length(); i++) { for (int i = 0; i < optionsMenuAdapter.length(); i++) {
if (itemId == optionsMenuAdapter.getTitleRes(i)) { if (itemId == optionsMenuAdapter.getElementId(i)) {
optionsMenuAdapter.getClickAdapter(i).onContextMenuClick(null, itemId, i, false); optionsMenuAdapter.getClickAdapter(i).onContextMenuClick(null, itemId, i, false);
return true; return true;
} }

View file

@ -1,5 +1,6 @@
package net.osmand.plus.views.mapwidgets; package net.osmand.plus.views.mapwidgets;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
@ -369,6 +370,10 @@ public class MapWidgetRegistry {
addControlsAppearance(map, cm, mode); addControlsAppearance(map, cm, mode);
} }
public String getText(Context ctx, final ApplicationMode mode, final MapWidgetRegInfo r) {
return (r.visibleCollapsed(mode) ? " + " : " ") + ctx.getString(r.messageId);
}
public Set<MapWidgetRegInfo> getRight() { public Set<MapWidgetRegInfo> getRight() {
return right; return right;
} }
@ -400,12 +405,14 @@ public class MapWidgetRegistry {
if (mil != null) { if (mil != null) {
mil.recreateControls(); mil.recreateControls();
} }
adapter.setItemName(pos, getText(mil.getMapActivity(), mode, r));
adapter.setSelection(pos, r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0); adapter.setSelection(pos, r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0);
a.notifyDataSetChanged(); a.notifyDataSetChanged();
return false; return false;
} }
}) })
.reg(); .reg();
adapter.setItemName(adapter.length() - 1, getText(map, mode, r));
} }
} }