Rewritten working ContextMenu. Need to be removed completely. Little fixes for AvailableIndexesFragment.
This commit is contained in:
parent
bd3ca97411
commit
c124ddf21b
3 changed files with 32 additions and 52 deletions
|
@ -46,16 +46,6 @@ public class ContextMenuAdapter {
|
||||||
return items.size();
|
return items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public int getElementId(int position) {
|
|
||||||
return items.get(position).getTitleId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public ItemClickListener getClickAdapter(int position) {
|
|
||||||
return items.get(position).getItemClickListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public String getItemName(int position) {
|
public String getItemName(int position) {
|
||||||
return items.get(position).getTitle();
|
return items.get(position).getTitle();
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -301,8 +302,9 @@ public class MapActivityActions implements DialogProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
int standardId = adapter.getElementId(which);
|
ContextMenuItem item = adapter.getItem(which);
|
||||||
ItemClickListener click = adapter.getClickAdapter(which);
|
int standardId = item.getTitleId();
|
||||||
|
ItemClickListener click = item.getItemClickListener();
|
||||||
if (click != null) {
|
if (click != null) {
|
||||||
click.onContextMenuClick(listAdapter, standardId, which, false);
|
click.onContextMenuClick(listAdapter, standardId, which, false);
|
||||||
} else if (standardId == R.string.context_menu_item_last_intermediate_point) {
|
} else if (standardId == R.string.context_menu_item_last_intermediate_point) {
|
||||||
|
@ -357,7 +359,7 @@ public class MapActivityActions implements DialogProvider {
|
||||||
final boolean useIntermediatePointsByDefault = true;
|
final boolean useIntermediatePointsByDefault = true;
|
||||||
List<SelectedGpxFile> selectedGPXFiles = mapActivity.getMyApplication().getSelectedGpxHelper()
|
List<SelectedGpxFile> selectedGPXFiles = mapActivity.getMyApplication().getSelectedGpxHelper()
|
||||||
.getSelectedGPXFiles();
|
.getSelectedGPXFiles();
|
||||||
final List<GPXFile> gpxFiles = new ArrayList<GPXFile>();
|
final List<GPXFile> gpxFiles = new ArrayList<>();
|
||||||
for (SelectedGpxFile gs : selectedGPXFiles) {
|
for (SelectedGpxFile gs : selectedGPXFiles) {
|
||||||
if (!gs.isShowCurrentTrack() && !gs.notShowNavigationDialog) {
|
if (!gs.isShowCurrentTrack() && !gs.notShowNavigationDialog) {
|
||||||
if (gs.getGpxFile().hasRtePt() || gs.getGpxFile().hasTrkpt()) {
|
if (gs.getGpxFile().hasRtePt() || gs.getGpxFile().hasTrkpt()) {
|
||||||
|
@ -855,7 +857,7 @@ public class MapActivityActions implements DialogProvider {
|
||||||
|
|
||||||
|
|
||||||
public void whereAmIDialog() {
|
public void whereAmIDialog() {
|
||||||
final List<String> items = new ArrayList<String>();
|
final List<String> items = new ArrayList<>();
|
||||||
items.add(getString(R.string.show_location));
|
items.add(getString(R.string.show_location));
|
||||||
items.add(getString(R.string.shared_string_show_details));
|
items.add(getString(R.string.shared_string_show_details));
|
||||||
AlertDialog.Builder menu = new AlertDialog.Builder(mapActivity);
|
AlertDialog.Builder menu = new AlertDialog.Builder(mapActivity);
|
||||||
|
@ -883,9 +885,9 @@ public class MapActivityActions implements DialogProvider {
|
||||||
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||||
final ListView menuItemsListView = (ListView) mapActivity.findViewById(R.id.menuItems);
|
final ListView menuItemsListView = (ListView) mapActivity.findViewById(R.id.menuItems);
|
||||||
if (nightMode) {
|
if (nightMode) {
|
||||||
menuItemsListView.setBackgroundColor(mapActivity.getResources().getColor(R.color.bg_color_dark));
|
menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_dark));
|
||||||
} else {
|
} else {
|
||||||
menuItemsListView.setBackgroundColor(mapActivity.getResources().getColor(R.color.bg_color_light));
|
menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_light));
|
||||||
}
|
}
|
||||||
menuItemsListView.setDivider(null);
|
menuItemsListView.setDivider(null);
|
||||||
final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu();
|
final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu();
|
||||||
|
@ -896,10 +898,10 @@ public class MapActivityActions implements DialogProvider {
|
||||||
menuItemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
menuItemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
ContextMenuAdapter.ItemClickListener click =
|
ContextMenuItem item = contextMenuAdapter.getItem(position);
|
||||||
contextMenuAdapter.getClickAdapter(position);
|
ContextMenuAdapter.ItemClickListener click = item.getItemClickListener();
|
||||||
if (click.onContextMenuClick(simpleListAdapter,
|
if (click.onContextMenuClick(simpleListAdapter, item.getTitleId(),
|
||||||
contextMenuAdapter.getElementId(position), position, false)) {
|
position, false)) {
|
||||||
mapActivity.closeDrawer();
|
mapActivity.closeDrawer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import android.app.Activity;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
@ -87,16 +87,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
||||||
private boolean selectionMode = false;
|
private boolean selectionMode = false;
|
||||||
private Set<LocalIndexInfo> selectedItems = new LinkedHashSet<>();
|
private Set<LocalIndexInfo> selectedItems = new LinkedHashSet<>();
|
||||||
|
|
||||||
protected static final int DELETE_OPERATION = 1;
|
|
||||||
protected static final int BACKUP_OPERATION = 2;
|
|
||||||
protected static final int RESTORE_OPERATION = 3;
|
|
||||||
|
|
||||||
private ContextMenuAdapter optionsMenuAdapter;
|
private ContextMenuAdapter optionsMenuAdapter;
|
||||||
private ActionMode actionMode;
|
private ActionMode actionMode;
|
||||||
|
|
||||||
Drawable sdcard;
|
|
||||||
Drawable planet;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.local_index, container, false);
|
View view = inflater.inflate(R.layout.local_index, container, false);
|
||||||
|
@ -108,7 +101,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
||||||
listView.setAdapter(listAdapter);
|
listView.setAdapter(listAdapter);
|
||||||
expandAllGroups();
|
expandAllGroups();
|
||||||
setListView(listView);
|
setListView(listView);
|
||||||
colorDrawables();
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,13 +120,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void colorDrawables() {
|
|
||||||
boolean light = getMyApplication().getSettings().isLightContent();
|
|
||||||
sdcard = getActivity().getResources().getDrawable(R.drawable.ic_sdcard);
|
|
||||||
sdcard.mutate();
|
|
||||||
sdcard.setColorFilter(getActivity().getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -180,9 +165,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
||||||
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) {
|
||||||
ContextMenuAdapter.ItemClickListener clk = adapter.getClickAdapter(which);
|
ContextMenuItem item = adapter.getItem(which);
|
||||||
if (clk != null) {
|
if (item.getItemClickListener() != null) {
|
||||||
clk.onContextMenuClick(null, adapter.getElementId(which), which, false);
|
item.getItemClickListener().onContextMenuClick(null,
|
||||||
|
item.getTitleId(), which, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,19 +582,20 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
||||||
optionsMenuAdapter = new ContextMenuAdapter();
|
optionsMenuAdapter = new ContextMenuAdapter();
|
||||||
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
|
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
|
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter,
|
||||||
|
int itemId, int pos, boolean isChecked) {
|
||||||
localOptionsMenu(itemId);
|
localOptionsMenu(itemId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
.setTitleId(R.string.local_index_mi_reload, getContext())
|
.setTitleId(R.string.local_index_mi_reload, getContext())
|
||||||
.setIcon(R.drawable.ic_action_refresh_dark)
|
.setColorIcon(R.drawable.ic_action_refresh_dark)
|
||||||
.setListener(listener)
|
.setListener(listener)
|
||||||
.createItem());
|
.createItem());
|
||||||
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
.setTitleId(R.string.shared_string_delete, getContext())
|
.setTitleId(R.string.shared_string_delete, getContext())
|
||||||
.setIcon(R.drawable.ic_action_delete_dark)
|
.setColorIcon(R.drawable.ic_action_delete_dark)
|
||||||
.setListener(listener)
|
.setListener(listener)
|
||||||
.createItem());
|
.createItem());
|
||||||
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
|
@ -625,6 +612,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
||||||
SubMenu split = null;
|
SubMenu split = null;
|
||||||
for (int j = 0; j < optionsMenuAdapter.length(); j++) {
|
for (int j = 0; j < optionsMenuAdapter.length(); j++) {
|
||||||
MenuItem item;
|
MenuItem item;
|
||||||
|
ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(j);
|
||||||
if (j + 1 >= max && optionsMenuAdapter.length() > max) {
|
if (j + 1 >= max && optionsMenuAdapter.length() > max) {
|
||||||
if (split == null) {
|
if (split == null) {
|
||||||
split = menu.addSubMenu(0, 1, j + 1, R.string.shared_string_more_actions);
|
split = menu.addSubMenu(0, 1, j + 1, R.string.shared_string_more_actions);
|
||||||
|
@ -632,15 +620,14 @@ 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.getElementId(j), j + 1, optionsMenuAdapter.getItemName(j));
|
item = split.add(0, contextMenuItem.getTitleId(), j + 1, contextMenuItem.getTitle());
|
||||||
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||||
} else {
|
} else {
|
||||||
item = menu.add(0, optionsMenuAdapter.getElementId(j), j + 1, optionsMenuAdapter.getItemName(j));
|
item = menu.add(0, contextMenuItem.getTitleId(), j + 1, contextMenuItem.getTitle());
|
||||||
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||||
}
|
}
|
||||||
OsmandApplication app = getMyApplication();
|
if (contextMenuItem.getLightIcon() != -1) {
|
||||||
if (optionsMenuAdapter.getImage(app, j, isLightActionBar()) != null) {
|
item.setIcon(contextMenuItem.getLightIcon());
|
||||||
item.setIcon(optionsMenuAdapter.getImage(app, j, isLightActionBar()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -656,8 +643,9 @@ 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.getElementId(i)) {
|
ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(i);
|
||||||
optionsMenuAdapter.getClickAdapter(i).onContextMenuClick(null, itemId, i, false);
|
if (itemId == contextMenuItem.getTitleId()) {
|
||||||
|
contextMenuItem.getItemClickListener().onContextMenuClick(null, itemId, i, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -809,11 +797,11 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
||||||
|
|
||||||
public LocalIndexesAdapter(DownloadActivity ctx) {
|
public LocalIndexesAdapter(DownloadActivity ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
warningColor = ctx.getResources().getColor(R.color.color_warning);
|
warningColor = ContextCompat.getColor(ctx, R.color.color_warning);
|
||||||
okColor = ctx.getResources().getColor(R.color.color_ok);
|
okColor = ContextCompat.getColor(ctx, R.color.color_ok);
|
||||||
TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
|
TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
|
||||||
ta.recycle();
|
ta.recycle();
|
||||||
corruptedColor = ctx.getResources().getColor(R.color.color_invalid);
|
corruptedColor = ContextCompat.getColor(ctx, R.color.color_invalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
|
Loading…
Reference in a new issue