Rewritten working ContextMenu. GpxUiHelper, ConfigureMapMenu.
This commit is contained in:
parent
c124ddf21b
commit
60073c4ff3
4 changed files with 42 additions and 63 deletions
|
@ -40,26 +40,15 @@ public class ContextMenuAdapter {
|
||||||
R.layout.list_menu_item : R.layout.list_menu_item_native;
|
R.layout.list_menu_item : R.layout.list_menu_item_native;
|
||||||
List<ContextMenuItem> items = new ArrayList<>();
|
List<ContextMenuItem> items = new ArrayList<>();
|
||||||
private ConfigureMapMenu.OnClickListener changeAppModeListener = null;
|
private ConfigureMapMenu.OnClickListener changeAppModeListener = null;
|
||||||
//neded to detect whether user opened all modes or not
|
|
||||||
|
|
||||||
public int length() {
|
public int length() {
|
||||||
return items.size();
|
return items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public String getItemName(int position) {
|
|
||||||
return items.get(position).getTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public Boolean getSelection(int position) {
|
|
||||||
return items.get(position).getSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Drawable getImage(OsmandApplication ctx, int position, boolean light) {
|
public Drawable getImage(OsmandApplication ctx, int position, boolean light) {
|
||||||
@DrawableRes
|
@DrawableRes
|
||||||
int lst = items.get(position).getIcon();
|
int lst = items.get(position).getLightIcon();
|
||||||
if (lst != -1) {
|
if (lst != -1) {
|
||||||
return ContextCompat.getDrawable(ctx, lst);
|
return ContextCompat.getDrawable(ctx, lst);
|
||||||
}
|
}
|
||||||
|
@ -71,21 +60,6 @@ public class ContextMenuAdapter {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setItemName(int position, String str) {
|
|
||||||
items.get(position).setTitle(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setItemDescription(int position, String str) {
|
|
||||||
items.get(position).setDescription(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setSelection(int position, boolean s) {
|
|
||||||
items.get(position).setSelected(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adapter related
|
// Adapter related
|
||||||
public String[] getItemNames() {
|
public String[] getItemNames() {
|
||||||
String[] itemNames = new String[items.size()];
|
String[] itemNames = new String[items.size()];
|
||||||
|
@ -99,12 +73,12 @@ public class ContextMenuAdapter {
|
||||||
items.add(item);
|
items.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContextMenuItem getItem(int pos) {
|
public ContextMenuItem getItem(int position) {
|
||||||
return items.get(pos);
|
return items.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeItem(int pos) {
|
public void removeItem(int position) {
|
||||||
items.remove(pos);
|
items.remove(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultLayoutId(int defaultLayoutId) {
|
public void setDefaultLayoutId(int defaultLayoutId) {
|
||||||
|
@ -298,7 +272,7 @@ public class ContextMenuAdapter {
|
||||||
|
|
||||||
public interface ItemClickListener {
|
public interface ItemClickListener {
|
||||||
//boolean return type needed to desribe if drawer needed to be close or not
|
//boolean return type needed to desribe if drawer needed to be close or not
|
||||||
boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked);
|
boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnIntegerValueChangedListener {
|
public interface OnIntegerValueChangedListener {
|
||||||
|
@ -308,13 +282,13 @@ public class ContextMenuAdapter {
|
||||||
public static abstract class OnRowItemClick implements ItemClickListener {
|
public static abstract class OnRowItemClick implements ItemClickListener {
|
||||||
|
|
||||||
//boolean return type needed to describe if drawer needed to be close or not
|
//boolean return type needed to describe if drawer needed to be close or not
|
||||||
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
|
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
|
||||||
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
|
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
|
||||||
if (btn != null && btn.getVisibility() == View.VISIBLE) {
|
if (btn != null && btn.getVisibility() == View.VISIBLE) {
|
||||||
btn.setChecked(!btn.isChecked());
|
btn.setChecked(!btn.isChecked());
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return onContextMenuClick(adapter, itemId, pos, false);
|
return onContextMenuClick(adapter, itemId, position, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class ConfigureMapMenu {
|
||||||
if (itemId == R.string.layer_poi) {
|
if (itemId == R.string.layer_poi) {
|
||||||
selectPOILayer(ma.getMyApplication().getSettings());
|
selectPOILayer(ma.getMyApplication().getSettings());
|
||||||
return false;
|
return false;
|
||||||
} else if (itemId == R.string.layer_gpx_layer && cm.getSelection(pos)) {
|
} else if (itemId == R.string.layer_gpx_layer && cm.getItem(pos).getSelected()) {
|
||||||
ma.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(), ma.getMapView());
|
ma.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(), ma.getMapView());
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -134,7 +134,7 @@ public class ConfigureMapMenu {
|
||||||
public void onDismiss(DialogInterface dialog) {
|
public void onDismiss(DialogInterface dialog) {
|
||||||
boolean areAnyGpxTracksVisible =
|
boolean areAnyGpxTracksVisible =
|
||||||
ma.getMyApplication().getSelectedGpxHelper().isShowingAnyGpxFiles();
|
ma.getMyApplication().getSelectedGpxHelper().isShowingAnyGpxFiles();
|
||||||
cm.setSelection(pos, areAnyGpxTracksVisible);
|
cm.getItem(pos).setSelected(areAnyGpxTracksVisible);
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -266,7 +266,7 @@ public class ConfigureMapMenu {
|
||||||
} else {
|
} else {
|
||||||
AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
|
AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
adapter.setItemDescription(pos, getRenderDescr(activity));
|
adapter.getItem(pos).setDescription(getRenderDescr(activity));
|
||||||
activity.getDashboard().refreshContent(true);
|
activity.getDashboard().refreshContent(true);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ public class ConfigureMapMenu {
|
||||||
refreshMapComplete(activity);
|
refreshMapComplete(activity);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
activity.getDashboard().refreshContent(true);
|
activity.getDashboard().refreshContent(true);
|
||||||
//adapter.setItemDescription(pos, getDayNightDescr(activity));
|
//adapter.getItem(pos).setDescription(s, getDayNightDescr(activity));
|
||||||
//ad.notifyDataSetInvalidated();
|
//ad.notifyDataSetInvalidated();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -350,7 +350,7 @@ public class ConfigureMapMenu {
|
||||||
if (mapContext != null) {
|
if (mapContext != null) {
|
||||||
mapContext.updateMapSettings();
|
mapContext.updateMapSettings();
|
||||||
}
|
}
|
||||||
adapter.setItemDescription(pos, String.format("%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %");
|
adapter.getItem(pos).setDescription(String.format("%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %");
|
||||||
ad.notifyDataSetInvalidated();
|
ad.notifyDataSetInvalidated();
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ public class ConfigureMapMenu {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
view.getSettings().TEXT_SCALE.set(txtValues[which]);
|
view.getSettings().TEXT_SCALE.set(txtValues[which]);
|
||||||
refreshMapComplete(activity);
|
refreshMapComplete(activity);
|
||||||
adapter.setItemDescription(pos, getScale(activity));
|
adapter.getItem(pos).setDescription(getScale(activity));
|
||||||
ad.notifyDataSetInvalidated();
|
ad.notifyDataSetInvalidated();
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ public class ConfigureMapMenu {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[which]);
|
view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[which]);
|
||||||
refreshMapComplete(activity);
|
refreshMapComplete(activity);
|
||||||
adapter.setItemDescription(pos, txtIds[which]);
|
adapter.getItem(pos).setDescription(txtIds[which]);
|
||||||
ad.notifyDataSetInvalidated();
|
ad.notifyDataSetInvalidated();
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -579,7 +579,7 @@ public class ConfigureMapMenu {
|
||||||
for (int i = 0; i < prefs.size(); i++) {
|
for (int i = 0; i < prefs.size(); i++) {
|
||||||
prefs.get(i).set(tempPrefs[i]);
|
prefs.get(i).set(tempPrefs[i]);
|
||||||
}
|
}
|
||||||
adapter.setItemDescription(pos, getDescription(prefs));
|
adapter.getItem(pos).setDescription(getDescription(prefs));
|
||||||
a.notifyDataSetInvalidated();
|
a.notifyDataSetInvalidated();
|
||||||
refreshMapComplete(activity);
|
refreshMapComplete(activity);
|
||||||
activity.getMapLayers().updateLayers(activity.getMapView());
|
activity.getMapLayers().updateLayers(activity.getMapView());
|
||||||
|
@ -680,7 +680,7 @@ public class ConfigureMapMenu {
|
||||||
pref.set(p.getPossibleValues()[which - 1]);
|
pref.set(p.getPossibleValues()[which - 1]);
|
||||||
}
|
}
|
||||||
refreshMapComplete(activity);
|
refreshMapComplete(activity);
|
||||||
adapter.setItemDescription(pos, SettingsActivity.getStringPropertyValue(activity, pref.get()));
|
adapter.getItem(pos).setDescription(SettingsActivity.getStringPropertyValue(activity, pref.get()));
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
ad.notifyDataSetInvalidated();
|
ad.notifyDataSetInvalidated();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.app.Application;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -68,11 +69,11 @@ public class GpxUiHelper {
|
||||||
public static String getDescription(OsmandApplication app, GPXTrackAnalysis analysis, boolean html) {
|
public static String getDescription(OsmandApplication app, GPXTrackAnalysis analysis, boolean html) {
|
||||||
StringBuilder description = new StringBuilder();
|
StringBuilder description = new StringBuilder();
|
||||||
String nl = html ? "<br/>" : "\n";
|
String nl = html ? "<br/>" : "\n";
|
||||||
String timeSpanClr = Algorithms.colorToString(app.getResources().getColor(R.color.gpx_time_span_color));
|
String timeSpanClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_time_span_color));
|
||||||
String distanceClr = Algorithms.colorToString(app.getResources().getColor(R.color.gpx_distance_color));
|
String distanceClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_distance_color));
|
||||||
String speedClr = Algorithms.colorToString(app.getResources().getColor(R.color.gpx_speed));
|
String speedClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_speed));
|
||||||
String ascClr = Algorithms.colorToString(app.getResources().getColor(R.color.gpx_altitude_asc));
|
String ascClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_altitude_asc));
|
||||||
String descClr = Algorithms.colorToString(app.getResources().getColor(R.color.gpx_altitude_desc));
|
String descClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_altitude_desc));
|
||||||
// OUTPUT:
|
// OUTPUT:
|
||||||
// 1. Total distance, Start time, End time
|
// 1. Total distance, Start time, End time
|
||||||
description.append(app.getString(R.string.gpx_info_distance, getColorValue(distanceClr,
|
description.append(app.getString(R.string.gpx_info_distance, getColorValue(distanceClr,
|
||||||
|
@ -221,15 +222,16 @@ public class GpxUiHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void updateSelection(List<String> selectedGpxList, boolean showCurrentTrack,
|
protected static void updateSelection(List<String> selectedGpxList, boolean showCurrentTrack,
|
||||||
final ContextMenuAdapter adapter, int i, String fileName) {
|
final ContextMenuAdapter adapter, int position, String fileName) {
|
||||||
if (i == 0 && showCurrentTrack) {
|
ContextMenuItem item = adapter.getItem(position);
|
||||||
|
if (position == 0 && showCurrentTrack) {
|
||||||
if (selectedGpxList.contains("")) {
|
if (selectedGpxList.contains("")) {
|
||||||
adapter.setSelection(i, true);
|
item.setSelected(true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (String file : selectedGpxList) {
|
for (String file : selectedGpxList) {
|
||||||
if (file.endsWith(fileName)) {
|
if (file.endsWith(fileName)) {
|
||||||
adapter.setSelection(i, true);
|
item.setSelected(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,7 +246,8 @@ public class GpxUiHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean processResult(GPXFile[] result) {
|
public boolean processResult(GPXFile[] result) {
|
||||||
cmAdapter.setItemName(position, cmAdapter.getItemName(position) + "\n" + getDescription((OsmandApplication) app, result[0], f, false));
|
ContextMenuItem item = cmAdapter.getItem(position);
|
||||||
|
item.setTitle(item.getTitle() + "\n" + getDescription((OsmandApplication) app, result[0], f, false));
|
||||||
adapter.notifyDataSetInvalidated();
|
adapter.notifyDataSetInvalidated();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -270,6 +273,7 @@ public class GpxUiHelper {
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
v = activity.getLayoutInflater().inflate(layout, null);
|
v = activity.getLayoutInflater().inflate(layout, null);
|
||||||
}
|
}
|
||||||
|
final ContextMenuItem item = adapter.getItem(position);
|
||||||
ImageView icon = (ImageView) v.findViewById(R.id.icon);
|
ImageView icon = (ImageView) v.findViewById(R.id.icon);
|
||||||
icon.setImageDrawable(adapter.getImage(app, position, light));
|
icon.setImageDrawable(adapter.getImage(app, position, light));
|
||||||
final ArrayAdapter<String> arrayAdapter = this;
|
final ArrayAdapter<String> arrayAdapter = this;
|
||||||
|
@ -279,11 +283,11 @@ public class GpxUiHelper {
|
||||||
if (showCurrentGpx && position == 0) {
|
if (showCurrentGpx && position == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int nline = adapter.getItemName(position).indexOf('\n');
|
int nline = item.getTitle().indexOf('\n');
|
||||||
if (nline == -1) {
|
if (nline == -1) {
|
||||||
setDescripionInDialog(arrayAdapter, adapter, activity, dir, list.get(position), position);
|
setDescripionInDialog(arrayAdapter, adapter, activity, dir, list.get(position), position);
|
||||||
} else {
|
} else {
|
||||||
adapter.setItemName(position, adapter.getItemName(position).substring(0, nline));
|
item.setTitle(item.getTitle().substring(0, nline));
|
||||||
arrayAdapter.notifyDataSetInvalidated();
|
arrayAdapter.notifyDataSetInvalidated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,7 +299,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.getItemName(position));
|
tv.setText(item.getTitle());
|
||||||
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
|
||||||
|
@ -304,15 +308,15 @@ public class GpxUiHelper {
|
||||||
// }
|
// }
|
||||||
// tv.setCompoundDrawablePadding(padding);
|
// tv.setCompoundDrawablePadding(padding);
|
||||||
final CheckBox ch = ((CheckBox) v.findViewById(R.id.toggle_item));
|
final CheckBox ch = ((CheckBox) v.findViewById(R.id.toggle_item));
|
||||||
if (adapter.getSelection(position) == null) {
|
if (item.getSelected() == null) {
|
||||||
ch.setVisibility(View.INVISIBLE);
|
ch.setVisibility(View.INVISIBLE);
|
||||||
} else {
|
} else {
|
||||||
ch.setOnCheckedChangeListener(null);
|
ch.setOnCheckedChangeListener(null);
|
||||||
ch.setChecked(adapter.getSelection(position));
|
ch.setChecked(item.getSelected());
|
||||||
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
adapter.setSelection(position, isChecked);
|
item.setSelected(isChecked);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -338,12 +342,12 @@ public class GpxUiHelper {
|
||||||
if (app != null && app.getSelectedGpxHelper() != null) {
|
if (app != null && app.getSelectedGpxHelper() != null) {
|
||||||
app.getSelectedGpxHelper().clearAllGpxFileToShow();
|
app.getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||||
}
|
}
|
||||||
if (showCurrentGpx && adapter.getSelection(0)) {
|
if (showCurrentGpx && adapter.getItem(0).getSelected()) {
|
||||||
currentGPX = app.getSavingTrackHelper().getCurrentGpx();
|
currentGPX = app.getSavingTrackHelper().getCurrentGpx();
|
||||||
}
|
}
|
||||||
List<String> s = new ArrayList<>();
|
List<String> s = new ArrayList<>();
|
||||||
for (int i = (showCurrentGpx ? 1 : 0); i < adapter.length(); i++) {
|
for (int i = (showCurrentGpx ? 1 : 0); i < adapter.length(); i++) {
|
||||||
if (adapter.getSelection(i)) {
|
if (adapter.getItem(i).getSelected()) {
|
||||||
s.add(list.get(i));
|
s.add(list.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,7 +365,8 @@ public class GpxUiHelper {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
if (multipleChoice) {
|
if (multipleChoice) {
|
||||||
adapter.setSelection(position, !adapter.getSelection(position));
|
ContextMenuItem item = adapter.getItem(position);
|
||||||
|
item.setSelected(!item.getSelected());
|
||||||
listAdapter.notifyDataSetInvalidated();
|
listAdapter.notifyDataSetInvalidated();
|
||||||
} else {
|
} else {
|
||||||
dlg.dismiss();
|
dlg.dismiss();
|
||||||
|
|
|
@ -302,7 +302,7 @@ public class MapWidgetRegistry {
|
||||||
}
|
}
|
||||||
map.refreshMap();
|
map.refreshMap();
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
cm.setItemDescription(pos, settings.MAP_MARKERS_MODE.get().toHumanString(map));
|
cm.getItem(pos).setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map));
|
||||||
ad.notifyDataSetChanged();
|
ad.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue