forked from upstream-mirrors/OpenTracks
Move select all in multiple select to an action bar item
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
@@ -40,4 +40,9 @@ limitations under the License.
|
|||||||
android:id="@+id/list_context_menu_delete"
|
android:id="@+id/list_context_menu_delete"
|
||||||
android:showAsAction="ifRoom"
|
android:showAsAction="ifRoom"
|
||||||
android:title="@string/menu_delete"/>
|
android:title="@string/menu_delete"/>
|
||||||
|
<item
|
||||||
|
android:icon="@drawable/menu_select_all"
|
||||||
|
android:id="@+id/list_context_menu_select_all"
|
||||||
|
android:showAsAction="ifRoom"
|
||||||
|
android:title="@string/menu_select_all"/>
|
||||||
</menu>
|
</menu>
|
||||||
@@ -953,19 +953,11 @@ limitations under the License.
|
|||||||
</string>
|
</string>
|
||||||
|
|
||||||
<!-- List item -->
|
<!-- List item -->
|
||||||
<string name="list_deselect_all"
|
|
||||||
translation_description="Option to deselect all the items in a list.">
|
|
||||||
Deselect all
|
|
||||||
</string>
|
|
||||||
<string name="list_item_selected"
|
<string name="list_item_selected"
|
||||||
translation_description="Title indicating the number of items selected in a list.
|
translation_description="Title indicating the number of items selected in a list.
|
||||||
%1$d: an integer value. E.g., '2'.">
|
%1$d: an integer value. E.g., '2'.">
|
||||||
%1$d selected
|
%1$d selected
|
||||||
</string>
|
</string>
|
||||||
<string name="list_select_all"
|
|
||||||
translation_description="Option to select all the items in a list.">
|
|
||||||
Select all
|
|
||||||
</string>
|
|
||||||
|
|
||||||
<!-- Marker -->
|
<!-- Marker -->
|
||||||
<string name="marker_add_error"
|
<string name="marker_add_error"
|
||||||
@@ -1155,6 +1147,12 @@ limitations under the License.
|
|||||||
Character limit: ~20 (1 line)">
|
Character limit: ~20 (1 line)">
|
||||||
Search
|
Search
|
||||||
</string>
|
</string>
|
||||||
|
<string name="menu_select_all"
|
||||||
|
translation_description="In the menu, to select all the items.
|
||||||
|
|
||||||
|
Character limit: ~20 (1 line)">
|
||||||
|
Select all
|
||||||
|
</string>
|
||||||
<string name="menu_sensor_state"
|
<string name="menu_sensor_state"
|
||||||
translation_description="In the menu, to go to the sensor state page.
|
translation_description="In the menu, to go to the sensor state page.
|
||||||
|
|
||||||
@@ -2015,7 +2013,7 @@ limitations under the License.
|
|||||||
translation_description="When sharing a track, error message indicating that no email addresses
|
translation_description="When sharing a track, error message indicating that no email addresses
|
||||||
is entered.">
|
is entered.">
|
||||||
No email addresses entered.
|
No email addresses entered.
|
||||||
</string>
|
</string>
|
||||||
<string name="share_track_no_selection"
|
<string name="share_track_no_selection"
|
||||||
translation_description="When sharing a track, error message indicating that no option is
|
translation_description="When sharing a track, error message indicating that no option is
|
||||||
selected.">
|
selected.">
|
||||||
|
|||||||
@@ -31,8 +31,9 @@ public interface ContextualActionModeCallback {
|
|||||||
* @param menu the menu
|
* @param menu the menu
|
||||||
* @param positions the selected items' positions
|
* @param positions the selected items' positions
|
||||||
* @param ids the selected items' ids, if available
|
* @param ids the selected items' ids, if available
|
||||||
|
* @param showSelectAll true to show select all
|
||||||
*/
|
*/
|
||||||
public void onPrepare(Menu menu, int[] positions, long[] ids);
|
public void onPrepare(Menu menu, int[] positions, long[] ids, boolean showSelectAll);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when items are selected.
|
* Invoked when items are selected.
|
||||||
|
|||||||
@@ -69,13 +69,19 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
|
|||||||
private ContextualActionModeCallback
|
private ContextualActionModeCallback
|
||||||
contextualActionModeCallback = new ContextualActionModeCallback() {
|
contextualActionModeCallback = new ContextualActionModeCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onPrepare(Menu menu, int[] positions, long[] ids) {
|
public void onPrepare(Menu menu, int[] positions, long[] ids, boolean showSelectAll) {
|
||||||
menu.findItem(R.id.list_context_menu_play).setVisible(false);
|
menu.findItem(R.id.list_context_menu_play).setVisible(false);
|
||||||
menu.findItem(R.id.list_context_menu_share).setVisible(false);
|
menu.findItem(R.id.list_context_menu_share).setVisible(false);
|
||||||
menu.findItem(R.id.list_context_menu_show_on_map).setVisible(ids.length == 1);
|
menu.findItem(R.id.list_context_menu_show_on_map).setVisible(ids.length == 1);
|
||||||
menu.findItem(R.id.list_context_menu_edit)
|
menu.findItem(R.id.list_context_menu_edit)
|
||||||
.setVisible(ids.length == 1 && !track.isSharedWithMe());
|
.setVisible(ids.length == 1 && !track.isSharedWithMe());
|
||||||
menu.findItem(R.id.list_context_menu_delete).setVisible(!track.isSharedWithMe());
|
menu.findItem(R.id.list_context_menu_delete).setVisible(!track.isSharedWithMe());
|
||||||
|
/*
|
||||||
|
* Set select all to the same visibility as delete since delete is the
|
||||||
|
* only action that can be applied to multiple markers.
|
||||||
|
*/
|
||||||
|
menu.findItem(R.id.list_context_menu_select_all)
|
||||||
|
.setVisible(showSelectAll && !track.isSharedWithMe());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -125,6 +131,7 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
|
|||||||
private ResourceCursorAdapter resourceCursorAdapter;
|
private ResourceCursorAdapter resourceCursorAdapter;
|
||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
|
private ListView listView;
|
||||||
private MenuItem insertMarkerMenuItem;
|
private MenuItem insertMarkerMenuItem;
|
||||||
private MenuItem searchMenuItem;
|
private MenuItem searchMenuItem;
|
||||||
|
|
||||||
@@ -144,7 +151,7 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
|
|||||||
|
|
||||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||||
|
|
||||||
ListView listView = (ListView) findViewById(R.id.marker_list);
|
listView = (ListView) findViewById(R.id.marker_list);
|
||||||
listView.setEmptyView(findViewById(R.id.marker_list_empty));
|
listView.setEmptyView(findViewById(R.id.marker_list_empty));
|
||||||
listView.setOnItemClickListener(new OnItemClickListener() {
|
listView.setOnItemClickListener(new OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -257,9 +264,10 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
|
|||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
||||||
|
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
||||||
contextualActionModeCallback.onPrepare(menu, new int[] {info.position}, new long[] {info.id});
|
contextualActionModeCallback.onPrepare(
|
||||||
|
menu, new int[] { info.position }, new long[] { info.id }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -299,6 +307,12 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
|
|||||||
DeleteMarkerDialogFragment.newInstance(markerIds)
|
DeleteMarkerDialogFragment.newInstance(markerIds)
|
||||||
.show(getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
|
.show(getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.list_context_menu_select_all:
|
||||||
|
int size = listView.getCount();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
listView.setItemChecked(i, true);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
|||||||
return handleContextItem(itemId, positions);
|
return handleContextItem(itemId, positions);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onPrepare(Menu menu, int[] positions, long[] ids) {
|
public void onPrepare(Menu menu, int[] positions, long[] ids, boolean showSelectAll) {
|
||||||
boolean shareWithMe = true;
|
boolean shareWithMe = true;
|
||||||
Long markerId = null;
|
Long markerId = null;
|
||||||
if (positions.length == 1) {
|
if (positions.length == 1) {
|
||||||
@@ -158,6 +158,8 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
|||||||
// Only one item. If marker, cannot be a shareWithMe item. If track, no restriction
|
// Only one item. If marker, cannot be a shareWithMe item. If track, no restriction
|
||||||
menu.findItem(R.id.list_context_menu_delete)
|
menu.findItem(R.id.list_context_menu_delete)
|
||||||
.setVisible(positions.length == 1 && (markerId == null || !shareWithMe));
|
.setVisible(positions.length == 1 && (markerId == null || !shareWithMe));
|
||||||
|
// Disable select all, no action is available for multiple selection
|
||||||
|
menu.findItem(R.id.list_context_menu_select_all).setVisible(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -296,7 +298,8 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
|||||||
getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
||||||
|
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
||||||
contextualActionModeCallback.onPrepare(menu, new int[] {info.position}, new long[] {info.id});
|
contextualActionModeCallback.onPrepare(
|
||||||
|
menu, new int[] { info.position }, new long[] { info.id }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -211,16 +211,18 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
contextualActionModeCallback = new ContextualActionModeCallback() {
|
contextualActionModeCallback = new ContextualActionModeCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrepare(Menu menu, int[] positions, long[] ids) {
|
public void onPrepare(Menu menu, int[] positions, long[] ids, boolean showSelectAll) {
|
||||||
boolean shareWithMe = true;
|
boolean shareWithMe = true;
|
||||||
if (ids.length == 1) {
|
if (ids.length == 1) {
|
||||||
Track track = myTracksProviderUtils.getTrack(ids[0]);
|
Track track = myTracksProviderUtils.getTrack(ids[0]);
|
||||||
shareWithMe = track.isSharedWithMe();
|
shareWithMe = track.isSharedWithMe();
|
||||||
}
|
}
|
||||||
|
// play is always enabled
|
||||||
menu.findItem(R.id.list_context_menu_share).setVisible(!shareWithMe);
|
menu.findItem(R.id.list_context_menu_share).setVisible(!shareWithMe);
|
||||||
menu.findItem(R.id.list_context_menu_show_on_map).setVisible(false);
|
menu.findItem(R.id.list_context_menu_show_on_map).setVisible(false);
|
||||||
menu.findItem(R.id.list_context_menu_edit).setVisible(!shareWithMe);
|
menu.findItem(R.id.list_context_menu_edit).setVisible(!shareWithMe);
|
||||||
menu.findItem(R.id.list_context_menu_delete).setVisible(true);
|
// delete is always enabled
|
||||||
|
menu.findItem(R.id.list_context_menu_select_all).setVisible(showSelectAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -565,7 +567,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
|
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
||||||
contextualActionModeCallback.onPrepare(
|
contextualActionModeCallback.onPrepare(
|
||||||
menu, new int[] { info.position }, new long[] { info.id });
|
menu, new int[] { info.position }, new long[] { info.id }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -770,6 +772,12 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
|||||||
DeleteTrackDialogFragment.newInstance(deleteAll, trackIds)
|
DeleteTrackDialogFragment.newInstance(deleteAll, trackIds)
|
||||||
.show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
|
.show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.list_context_menu_select_all:
|
||||||
|
int size = listView.getCount();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
listView.setItemChecked(i, true);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,16 +30,11 @@ import android.view.ActionMode;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.AbsListView.MultiChoiceModeListener;
|
import android.widget.AbsListView.MultiChoiceModeListener;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.AdapterView.OnItemSelectedListener;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TabWidget;
|
import android.widget.TabWidget;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -74,58 +69,6 @@ public class Api11Adapter extends Api10Adapter {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
mode.getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
mode.getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
||||||
final Spinner spinner = new Spinner(activity) {
|
|
||||||
@Override
|
|
||||||
public void setSelection(int position) {
|
|
||||||
super.setSelection(position);
|
|
||||||
// Fire event when selecting the same item
|
|
||||||
if (position == getSelectedItemPosition()) {
|
|
||||||
getOnItemSelectedListener()
|
|
||||||
.onItemSelected(this, getSelectedView(), position, getSelectedItemId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ArrayAdapter<StringBuilder> adapter = new ArrayAdapter<StringBuilder>(
|
|
||||||
activity, android.R.layout.simple_spinner_item,
|
|
||||||
new StringBuilder[] { new StringBuilder("") }) {
|
|
||||||
@Override
|
|
||||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
|
||||||
// Display select all/ deselect all
|
|
||||||
View view = super.getDropDownView(position, convertView, parent);
|
|
||||||
TextView textView = (TextView) view;
|
|
||||||
int messageId = listView.getCheckedItemCount() == listView.getCount()
|
|
||||||
? R.string.list_deselect_all
|
|
||||||
: R.string.list_select_all;
|
|
||||||
textView.setText(messageId);
|
|
||||||
return view;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
||||||
spinner.setAdapter(adapter);
|
|
||||||
|
|
||||||
// Use a post to prevent the spinner item from firing when first created
|
|
||||||
spinner.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
||||||
// Handle select all/ deselect all
|
|
||||||
int size = listView.getCount();
|
|
||||||
boolean allSelected = listView.getCheckedItemCount() == size;
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
listView.setItemChecked(i, !allSelected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mode.setCustomView(spinner);
|
|
||||||
setActionModeTitle(mode);
|
setActionModeTitle(mode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -133,7 +76,7 @@ public class Api11Adapter extends Api10Adapter {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||||
contextualActionModeCallback.onPrepare(
|
contextualActionModeCallback.onPrepare(
|
||||||
menu, getCheckedPositions(listView), listView.getCheckedItemIds());
|
menu, getCheckedPositions(listView), listView.getCheckedItemIds(), true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,18 +85,10 @@ public class Api11Adapter extends Api10Adapter {
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemCheckedStateChanged(
|
public void onItemCheckedStateChanged(
|
||||||
ActionMode mode, int position, long id, boolean checked) {
|
ActionMode mode, int position, long id, boolean checked) {
|
||||||
setActionModeTitle(mode);
|
setActionModeTitle(mode);
|
||||||
|
|
||||||
// Update action mode title
|
|
||||||
Spinner spinner = (Spinner) mode.getCustomView();
|
|
||||||
ArrayAdapter<StringBuilder> adapter = (ArrayAdapter<StringBuilder>) spinner.getAdapter();
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
|
|
||||||
// Update contextual action mode items
|
|
||||||
mode.invalidate();
|
mode.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,12 +107,8 @@ public class Api11Adapter extends Api10Adapter {
|
|||||||
* @param mode action mode
|
* @param mode action mode
|
||||||
*/
|
*/
|
||||||
private void setActionModeTitle(ActionMode mode) {
|
private void setActionModeTitle(ActionMode mode) {
|
||||||
Spinner spinner = (Spinner) mode.getCustomView();
|
|
||||||
StringBuilder stringBuilder = (StringBuilder) spinner.getSelectedItem();
|
|
||||||
stringBuilder.delete(0, stringBuilder.length());
|
|
||||||
|
|
||||||
int count = listView.getCheckedItemCount();
|
int count = listView.getCheckedItemCount();
|
||||||
stringBuilder.append(activity.getString(R.string.list_item_selected, count));
|
mode.setTitle(activity.getString(R.string.list_item_selected, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user