Rewritten working ContextMenu. Need to be removed completely. Little fixes for AvailableGPXFragment.
This commit is contained in:
parent
f04df5b622
commit
bd3ca97411
2 changed files with 22 additions and 20 deletions
|
@ -57,6 +57,7 @@ public class ContextMenuItem {
|
|||
return title;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
@ -159,6 +160,7 @@ public class ContextMenuItem {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ItemBuilder setIcon(int icon) {
|
||||
mIcon = icon;
|
||||
return this;
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.net.Uri;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.view.ActionMode;
|
||||
|
@ -96,7 +97,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
private boolean showOnMapMode;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
public void onAttach(Context activity) {
|
||||
super.onAttach(activity);
|
||||
this.app = (OsmandApplication) getActivity().getApplication();
|
||||
final Collator collator = Collator.getInstance();
|
||||
|
@ -104,7 +105,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
currentRecording = new GpxInfo(getMyApplication().getSavingTrackHelper().getCurrentGpx(), getString(R.string.shared_string_currently_recording_track));
|
||||
currentRecording.currentlyRecordingTrack = true;
|
||||
asyncLoader = new LoadGpxTask();
|
||||
selectedGpxHelper = ((OsmandApplication) activity.getApplication()).getSelectedGpxHelper();
|
||||
selectedGpxHelper = ((OsmandApplication) activity.getApplicationContext()).getSelectedGpxHelper();
|
||||
allGpxAdapter = new GpxIndexesAdapter(getActivity());
|
||||
setAdapter(allGpxAdapter);
|
||||
}
|
||||
|
@ -197,20 +198,17 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
public void onClick(View v) {
|
||||
if (isRecording) {
|
||||
plugin.stopRecording();
|
||||
} else if(plugin != null){
|
||||
} else
|
||||
if (app.getLocationProvider().checkGPSEnabled(ctx)) {
|
||||
plugin.startGPXMonitoring(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
SavingTrackHelper sth = app.getSavingTrackHelper();
|
||||
ImageButton save = ((ImageButton) v.findViewById(R.id.show_on_map));
|
||||
save.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final OsmandMonitoringPlugin plugin = OsmandPlugin
|
||||
.getEnabledPlugin(OsmandMonitoringPlugin.class);
|
||||
plugin.saveCurrentTrack();
|
||||
}
|
||||
});
|
||||
|
@ -221,7 +219,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
save.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_action_gsave_dark));
|
||||
|
||||
((TextView) v.findViewById(R.id.points_count)).setText(sth.getPoints() + "");
|
||||
((TextView) v.findViewById(R.id.points_count)).setText(String.valueOf(sth.getPoints()));
|
||||
((TextView) v.findViewById(R.id.distance))
|
||||
.setText(OsmAndFormatter.getFormattedDistance(sth.getDistance(), app));
|
||||
v.findViewById(R.id.points_icon).setVisibility(View.VISIBLE);
|
||||
|
@ -327,6 +325,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
((FavoritesActivity) getActivity()).getClearToolbar(false);
|
||||
}
|
||||
|
||||
// TODO Rewrite without ContextMenuAdapter
|
||||
optionsMenuAdapter = new ContextMenuAdapter();
|
||||
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
|
@ -350,16 +349,17 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
};
|
||||
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show_on_map, getActivity())
|
||||
.setIcon(R.drawable.ic_show_on_map)
|
||||
.setColorIcon(R.drawable.ic_show_on_map)
|
||||
.setListener(listener).createItem());
|
||||
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_delete, getActivity())
|
||||
.setIcon(R.drawable.ic_action_delete_dark).setListener(listener).createItem());
|
||||
.setColorIcon(R.drawable.ic_action_delete_dark).setListener(listener).createItem());
|
||||
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_reload, getActivity())
|
||||
.setIcon(R.drawable.ic_action_refresh_dark).setListener(listener).createItem());
|
||||
.setColorIcon(R.drawable.ic_action_refresh_dark).setListener(listener).createItem());
|
||||
OsmandPlugin.onOptionsMenuActivity(getActivity(), this, optionsMenuAdapter);
|
||||
for (int j = 0; j < optionsMenuAdapter.length(); j++) {
|
||||
final MenuItem item;
|
||||
item = menu.add(0, optionsMenuAdapter.getElementId(j), j + 1, optionsMenuAdapter.getItemName(j));
|
||||
ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(j);
|
||||
item = menu.add(0, contextMenuItem.getTitleId(), j + 1, contextMenuItem.getTitle());
|
||||
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
|
@ -370,9 +370,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
});
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -394,8 +393,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
@ -548,7 +548,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
private void showGpxOnMap(GpxInfo info) {
|
||||
info.setGpx(GPXUtilities.loadGPXFile(app, info.file));
|
||||
boolean e = true;
|
||||
if (info != null && info.gpx != null) {
|
||||
if (info.gpx != null) {
|
||||
WptPt loc = info.gpx.findPointToShow();
|
||||
OsmandSettings settings = getMyApplication().getSettings();
|
||||
if (loc != null) {
|
||||
|
@ -676,9 +676,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
private SearchFilter filter;
|
||||
|
||||
public GpxIndexesAdapter(Context ctx) {
|
||||
warningColor = ctx.getResources().getColor(R.color.color_warning);
|
||||
warningColor = ContextCompat.getColor(ctx, R.color.color_warning);
|
||||
TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
|
||||
defaultColor = ta.getColor(0, ctx.getResources().getColor(R.color.color_unknown));
|
||||
defaultColor = ta.getColor(0, ContextCompat.getColor(ctx, R.color.color_unknown));
|
||||
ta.recycle();
|
||||
}
|
||||
|
||||
|
@ -1133,7 +1133,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
String cs = constraint.toString();
|
||||
List<GpxInfo> res = new ArrayList<>();
|
||||
for (GpxInfo r : raw) {
|
||||
if (r.getName().toLowerCase().indexOf(cs) != -1) {
|
||||
if (r.getName().toLowerCase().contains(cs)) {
|
||||
res.add(r);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue