Rewritten working ContextMenu. Need to be removed completely. Little fixes for AvailableIndexesFragment.

This commit is contained in:
GaidamakUA 2016-03-29 16:29:45 +03:00
parent bd3ca97411
commit c124ddf21b
3 changed files with 32 additions and 52 deletions

View file

@ -46,16 +46,6 @@ public class ContextMenuAdapter {
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
public String getItemName(int position) {
return items.get(position).getTitle();

View file

@ -6,6 +6,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.view.ViewGroup;
@ -301,8 +302,9 @@ public class MapActivityActions implements DialogProvider {
@Override
public void onClick(DialogInterface dialog, int which) {
int standardId = adapter.getElementId(which);
ItemClickListener click = adapter.getClickAdapter(which);
ContextMenuItem item = adapter.getItem(which);
int standardId = item.getTitleId();
ItemClickListener click = item.getItemClickListener();
if (click != null) {
click.onContextMenuClick(listAdapter, standardId, which, false);
} else if (standardId == R.string.context_menu_item_last_intermediate_point) {
@ -357,7 +359,7 @@ public class MapActivityActions implements DialogProvider {
final boolean useIntermediatePointsByDefault = true;
List<SelectedGpxFile> selectedGPXFiles = mapActivity.getMyApplication().getSelectedGpxHelper()
.getSelectedGPXFiles();
final List<GPXFile> gpxFiles = new ArrayList<GPXFile>();
final List<GPXFile> gpxFiles = new ArrayList<>();
for (SelectedGpxFile gs : selectedGPXFiles) {
if (!gs.isShowCurrentTrack() && !gs.notShowNavigationDialog) {
if (gs.getGpxFile().hasRtePt() || gs.getGpxFile().hasTrkpt()) {
@ -855,7 +857,7 @@ public class MapActivityActions implements DialogProvider {
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.shared_string_show_details));
AlertDialog.Builder menu = new AlertDialog.Builder(mapActivity);
@ -883,9 +885,9 @@ public class MapActivityActions implements DialogProvider {
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final ListView menuItemsListView = (ListView) mapActivity.findViewById(R.id.menuItems);
if (nightMode) {
menuItemsListView.setBackgroundColor(mapActivity.getResources().getColor(R.color.bg_color_dark));
menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_dark));
} else {
menuItemsListView.setBackgroundColor(mapActivity.getResources().getColor(R.color.bg_color_light));
menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_light));
}
menuItemsListView.setDivider(null);
final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu();
@ -896,10 +898,10 @@ public class MapActivityActions implements DialogProvider {
menuItemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ContextMenuAdapter.ItemClickListener click =
contextMenuAdapter.getClickAdapter(position);
if (click.onContextMenuClick(simpleListAdapter,
contextMenuAdapter.getElementId(position), position, false)) {
ContextMenuItem item = contextMenuAdapter.getItem(position);
ContextMenuAdapter.ItemClickListener click = item.getItemClickListener();
if (click.onContextMenuClick(simpleListAdapter, item.getTitleId(),
position, false)) {
mapActivity.closeDrawer();
}
}

View file

@ -4,11 +4,11 @@ import android.app.Activity;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
@ -87,16 +87,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
private boolean selectionMode = false;
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 ActionMode actionMode;
Drawable sdcard;
Drawable planet;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.local_index, container, false);
@ -108,7 +101,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
listView.setAdapter(listAdapter);
expandAllGroups();
setListView(listView);
colorDrawables();
return view;
}
@ -128,13 +120,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
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
public void onResume() {
super.onResume();
@ -180,9 +165,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
builder.setItems(values, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ContextMenuAdapter.ItemClickListener clk = adapter.getClickAdapter(which);
if (clk != null) {
clk.onContextMenuClick(null, adapter.getElementId(which), which, false);
ContextMenuItem item = adapter.getItem(which);
if (item.getItemClickListener() != null) {
item.getItemClickListener().onContextMenuClick(null,
item.getTitleId(), which, false);
}
}
@ -596,19 +582,20 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
optionsMenuAdapter = new ContextMenuAdapter();
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@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);
return true;
}
};
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.local_index_mi_reload, getContext())
.setIcon(R.drawable.ic_action_refresh_dark)
.setColorIcon(R.drawable.ic_action_refresh_dark)
.setListener(listener)
.createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.shared_string_delete, getContext())
.setIcon(R.drawable.ic_action_delete_dark)
.setColorIcon(R.drawable.ic_action_delete_dark)
.setListener(listener)
.createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
@ -625,6 +612,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
SubMenu split = null;
for (int j = 0; j < optionsMenuAdapter.length(); j++) {
MenuItem item;
ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(j);
if (j + 1 >= max && optionsMenuAdapter.length() > max) {
if (split == null) {
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();
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);
} 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);
}
OsmandApplication app = getMyApplication();
if (optionsMenuAdapter.getImage(app, j, isLightActionBar()) != null) {
item.setIcon(optionsMenuAdapter.getImage(app, j, isLightActionBar()));
if (contextMenuItem.getLightIcon() != -1) {
item.setIcon(contextMenuItem.getLightIcon());
}
}
@ -656,8 +643,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
for (int i = 0; i < optionsMenuAdapter.length(); i++) {
if (itemId == optionsMenuAdapter.getElementId(i)) {
optionsMenuAdapter.getClickAdapter(i).onContextMenuClick(null, itemId, i, false);
ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(i);
if (itemId == contextMenuItem.getTitleId()) {
contextMenuItem.getItemClickListener().onContextMenuClick(null, itemId, i, false);
return true;
}
}
@ -809,11 +797,11 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
public LocalIndexesAdapter(DownloadActivity ctx) {
this.ctx = ctx;
warningColor = ctx.getResources().getColor(R.color.color_warning);
okColor = ctx.getResources().getColor(R.color.color_ok);
warningColor = ContextCompat.getColor(ctx, R.color.color_warning);
okColor = ContextCompat.getColor(ctx, R.color.color_ok);
TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
ta.recycle();
corruptedColor = ctx.getResources().getColor(R.color.color_invalid);
corruptedColor = ContextCompat.getColor(ctx, R.color.color_invalid);
}
public void clear() {