List of usage examples for android.view ActionMode finish
public abstract void finish();
From source file:com.github.jvanhie.discogsscrobbler.NowPlayingFragment.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setSelection(final ListView list) { list.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); list.setSelector(R.drawable.track_selector); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from ww w. j a v a2 s . c o m public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (mBound) { //fully stop previous playlist since we start again from the beginning of the selected track ArrayList<Track> trackList = new ArrayList<Track>(mService.trackList); mService.stop(); mService.trackList = trackList; mService.currentTrack = i; mService.resume(); } } }); list.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) { } @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.now_playing_cab, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { SparseBooleanArray checkedItems = list.getCheckedItemPositions(); final List<Integer> positions = new ArrayList<Integer>(); if (checkedItems != null) { for (int i = 0; i < checkedItems.size(); i++) { if (checkedItems.valueAt(i)) { positions.add(checkedItems.keyAt(i)); } } } switch (menuItem.getItemId()) { case R.id.play_selection: if (mBound) { //change tracklist and start over again ArrayList<Track> newTrackList = new ArrayList<Track>(); for (Integer i : positions) { newTrackList.add(mService.trackList.get(i)); } //fully stop previous playlist since we start again from the beginning mService.stop(); mService.trackList = newTrackList; mService.currentTrack = 0; mService.resume(); } actionMode.finish(); break; case R.id.remove_selection: int currPlaying = mService.currentTrack; int newPlaying = -1; //change tracklist and start over again ArrayList<Track> newTrackList = new ArrayList<Track>(); for (int i = 0; i < mService.trackList.size(); i++) { if (!positions.contains(i)) { newTrackList.add(mService.trackList.get(i)); } //calculate new currently playing counter if (i == currPlaying) { if (positions.contains(i)) { currPlaying++; } else { newPlaying = newTrackList.size() - 1; } } } //the currently playing track was removed, start fresh from the next available if (currPlaying != mService.currentTrack) { mService.stop(); if (newPlaying != -1) { mService.trackList = newTrackList; mService.currentTrack = newPlaying; mService.resume(); } } else { //pause the playlist and resume with the new tracklist mService.pause(); mService.trackList = newTrackList; mService.currentTrack = newPlaying; mService.resume(); } actionMode.finish(); break; } return false; } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); }
From source file:com.audiokernel.euphonyrmt.fragments.QueueFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); mRootView = container;/*w w w.ja v a 2s . c om*/ final View view = inflater.inflate(R.layout.playlist_activity, container, false); mSearchView = (SearchView) view.findViewById(R.id.search); mSearchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextChange(final String newText) { mFilter = newText; if (newText != null && newText.isEmpty()) { mFilter = null; } if (mFilter != null) { mFilter = mFilter.toLowerCase(); } mList.setDragEnabled(mFilter == null); update(false); return false; } @Override public boolean onQueryTextSubmit(final String query) { // Hide the keyboard and give focus to the list final InputMethodManager imm = (InputMethodManager) mActivity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0); mList.requestFocus(); return true; } }); mList = (DragSortListView) view.findViewById(android.R.id.list); mList.requestFocus(); mList.setDropListener(mDropListener); mController = new DragSortController(mList); mController.setDragHandleId(R.id.cover); mController.setRemoveEnabled(false); mController.setSortEnabled(true); mController.setDragInitMode(1); mList.setFloatViewManager(mController); mList.setOnTouchListener(mController); mList.setDragEnabled(true); refreshListColorCacheHint(); mList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); mList.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { final SparseBooleanArray checkedItems = mList.getCheckedItemPositions(); final int count = mList.getCount(); final ListAdapter adapter = mList.getAdapter(); final int itemId = item.getItemId(); int j = 0; int[] positions = null; boolean result = true; if (itemId == R.id.menu_delete) { positions = new int[mList.getCheckedItemCount()]; for (int i = 0; i < count && j < positions.length; i++) { if (checkedItems.get(i)) { positions[j] = ((Music) adapter.getItem(i)).getSongId(); j++; } } } else if (itemId == R.id.menu_crop) { positions = new int[mList.getCount() - mList.getCheckedItemCount()]; for (int i = 0; i < count && j < positions.length; i++) { if (!checkedItems.get(i)) { positions[j] = ((Music) adapter.getItem(i)).getSongId(); j++; } } } else { result = false; } if (j > 0) { QueueControl.run(QueueControl.REMOVE_BY_ID, positions); mode.finish(); } return result; } @Override public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.mpd_queuemenu, menu); return true; } @Override public void onDestroyActionMode(final ActionMode mode) { mActionMode = null; mController.setSortEnabled(true); } @Override public void onItemCheckedStateChanged(final ActionMode mode, final int position, final long id, final boolean checked) { final int selectCount = mList.getCheckedItemCount(); if (selectCount == 0) { mode.finish(); } if (selectCount == 1) { mode.setTitle(R.string.actionSongSelected); } else { mode.setTitle(getString(R.string.actionSongsSelected, selectCount)); } } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { mActionMode = mode; mController.setSortEnabled(false); return false; } }); return view; }
From source file:pl.bcichecki.rms.client.android.fragments.DevicesListFragment.java
private void performActionDelete(final ActionMode mode, MenuItem item, final Device selectedDevice) { devicesRestClient.deleteDevice(selectedDevice, new AsyncHttpResponseHandler() { @Override/*from ww w.j a va 2s. co m*/ public void onFailure(Throwable error, String content) { Log.d(TAG, "Removing event " + selectedDevice + " failed. [error=" + error + ", content=" + content + "]"); if (error instanceof HttpResponseException) { if (((HttpResponseException) error).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { AppUtils.showCenteredToast(getActivity(), R.string.general_unathorized_error_message_title, Toast.LENGTH_LONG); } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } @Override public void onFinish() { Log.d(TAG, "Attempt to delete device finished. " + selectedDevice); } @Override public void onStart() { Log.d(TAG, "Attempting to delete device. " + selectedDevice); AppUtils.showCenteredToast(getActivity(), R.string.fragment_devices_list_delete_successful, Toast.LENGTH_LONG); } @Override public void onSuccess(int statusCode, String content) { Log.d(TAG, "Attempt to delete event " + selectedDevice + " succesful. Removing object locally and refreshing view..."); devicesListAdapter.remove(selectedDevice); devicesListAdapter.refresh(); mode.finish(); } }); }
From source file:pl.bcichecki.rms.client.android.fragments.InboxMessagesListFragment.java
private void performActionArchive(final ActionMode mode, MenuItem item, final Message selectedMessage) { messagesRestClient.archiveMessage(selectedMessage, new AsyncHttpResponseHandler() { @Override//from w ww . ja va 2 s . co m public void onFailure(Throwable error, String content) { Log.d(TAG, "Archive inbox messages failed. [error=" + error + ", content=" + content + "]"); if (error instanceof HttpResponseException) { if (((HttpResponseException) error).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { AppUtils.showCenteredToast(getActivity(), R.string.general_unathorized_error_message_title, Toast.LENGTH_LONG); } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } @Override public void onFinish() { hideLoadingMessage(); Log.d(TAG, "Attempt archive inbox message " + selectedMessage + " finished."); } @Override public void onStart() { Log.d(TAG, "Attempting archive inbox message " + selectedMessage + " started."); showLoadingMessage(); } @Override public void onSuccess(int statusCode, String content) { Log.d(TAG, "Inbox message archive succesfull. Refreshing view."); AppUtils.showCenteredToast(getActivity(), R.string.fragment_inbox_messages_list_archive_successful, Toast.LENGTH_LONG); downloadData(); downloadArchivedData(); mode.finish(); } }); }
From source file:pl.bcichecki.rms.client.android.fragments.OutboxMessagesListFragment.java
private void performActionArchive(final ActionMode mode, MenuItem item, final Message selectedMessage) { messagesRestClient.archiveMessage(selectedMessage, new AsyncHttpResponseHandler() { @Override/* w w w .j a va 2 s . c o m*/ public void onFailure(Throwable error, String content) { Log.d(TAG, "Archive outbox messages failed. [error=" + error + ", content=" + content + "]"); if (error instanceof HttpResponseException) { if (((HttpResponseException) error).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { AppUtils.showCenteredToast(getActivity(), R.string.general_unathorized_error_message_title, Toast.LENGTH_LONG); } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } @Override public void onFinish() { hideLoadingMessage(); Log.d(TAG, "Attempt archive outbox message " + selectedMessage + " finished."); } @Override public void onStart() { Log.d(TAG, "Attempting archive outbox message " + selectedMessage + " started."); showLoadingMessage(); } @Override public void onSuccess(int statusCode, String content) { Log.d(TAG, "Outbox message archive succesfull. Refreshing view."); AppUtils.showCenteredToast(getActivity(), R.string.fragment_outbox_messages_list_archive_successful, Toast.LENGTH_LONG); downloadData(); downloadArchivedData(); mode.finish(); } }); }
From source file:pl.bcichecki.rms.client.android.fragments.InboxMessagesListFragment.java
private void performActionDelete(final ActionMode mode, MenuItem item, final Message selectedMessage) { AsyncHttpResponseHandler handler = new AsyncHttpResponseHandler() { @Override// ww w . j a v a 2 s . c o m public void onFailure(Throwable error, String content) { Log.d(TAG, "Removing inbox message " + selectedMessage + " failed. [error=" + error + ", content=" + content + "]"); if (error instanceof HttpResponseException) { if (((HttpResponseException) error).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { AppUtils.showCenteredToast(getActivity(), R.string.general_unathorized_error_message_title, Toast.LENGTH_LONG); } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } @Override public void onFinish() { Log.d(TAG, "Attempt to delete inbox message finished. " + selectedMessage); } @Override public void onStart() { Log.d(TAG, "Attempting to delete inbox message. " + selectedMessage); } @Override public void onSuccess(int statusCode, String content) { Log.d(TAG, "Attempt to delete inbox message " + selectedMessage + " succesful. Removing object locally and refreshing view..."); AppUtils.showCenteredToast(getActivity(), R.string.fragment_inbox_messages_list_delete_successful, Toast.LENGTH_LONG); downloadData(); downloadArchivedData(); mode.finish(); } }; if (!selectedMessage.isArchivedBySender()) { messagesRestClient.deleteInboxMessage(selectedMessage, handler); } else { messagesRestClient.deleteArchivedInboxMessage(selectedMessage, handler); } }
From source file:pl.bcichecki.rms.client.android.fragments.OutboxMessagesListFragment.java
private void performActionDelete(final ActionMode mode, MenuItem item, final Message selectedMessage) { AsyncHttpResponseHandler handler = new AsyncHttpResponseHandler() { @Override//from ww w. ja v a2 s . c o m public void onFailure(Throwable error, String content) { Log.d(TAG, "Removing outbox message " + selectedMessage + " failed. [error=" + error + ", content=" + content + "]"); if (error instanceof HttpResponseException) { if (((HttpResponseException) error).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { AppUtils.showCenteredToast(getActivity(), R.string.general_unathorized_error_message_title, Toast.LENGTH_LONG); } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } @Override public void onFinish() { Log.d(TAG, "Attempt to delete outbox message finished. " + selectedMessage); } @Override public void onStart() { Log.d(TAG, "Attempting to delete outbox message. " + selectedMessage); } @Override public void onSuccess(int statusCode, String content) { Log.d(TAG, "Attempt to delete outbox message " + selectedMessage + " succesful. Removing object locally and refreshing view..."); AppUtils.showCenteredToast(getActivity(), R.string.fragment_outbox_messages_list_delete_successful, Toast.LENGTH_LONG); downloadData(); downloadArchivedData(); mode.finish(); } }; if (!selectedMessage.isArchivedBySender()) { messagesRestClient.deleteOutboxMessage(selectedMessage, handler); } else { messagesRestClient.deleteArchivedOutboxMessage(selectedMessage, handler); } }
From source file:pl.bcichecki.rms.client.android.fragments.EventsListFragment.java
private void performActionLock(final ActionMode mode, MenuItem item, final Event selectedEvent) { eventsRestClient.lockEvent(selectedEvent, true, new AsyncHttpResponseHandler() { @Override// w ww .j av a 2s . c om public void onFailure(Throwable error, String content) { Log.d(TAG, "Locking event " + selectedEvent + " failed. [error=" + error + ", content=" + content + "]"); if (error instanceof HttpResponseException) { if (((HttpResponseException) error).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { AppUtils.showCenteredToast(getActivity(), R.string.general_unathorized_error_message_title, Toast.LENGTH_LONG); } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } @Override public void onFinish() { Log.d(TAG, "Attempt to lock event finished. " + selectedEvent); } @Override public void onStart() { Log.d(TAG, "Attempting to lock event. " + selectedEvent); } @Override public void onSuccess(int statusCode, String content) { Log.d(TAG, "Attempt to lock event " + selectedEvent + " succesful. Refreshing view..."); AppUtils.showCenteredToast(getActivity(), R.string.fragment_events_list_lock_successful, Toast.LENGTH_LONG); refreshEvent(selectedEvent); mode.finish(); } }); }
From source file:pl.bcichecki.rms.client.android.fragments.EventsListFragment.java
private void performActionUnlock(final ActionMode mode, MenuItem item, final Event selectedEvent) { eventsRestClient.lockEvent(selectedEvent, false, new AsyncHttpResponseHandler() { @Override/*from ww w . j av a2 s . c o m*/ public void onFailure(Throwable error, String content) { Log.d(TAG, "Unlocking event " + selectedEvent + " failed. [error=" + error + ", content=" + content + "]"); if (error instanceof HttpResponseException) { if (((HttpResponseException) error).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { AppUtils.showCenteredToast(getActivity(), R.string.general_unathorized_error_message_title, Toast.LENGTH_LONG); } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } @Override public void onFinish() { Log.d(TAG, "Attempt to unlock event finished. " + selectedEvent); } @Override public void onStart() { Log.d(TAG, "Attempting to unlock event. " + selectedEvent); } @Override public void onSuccess(int statusCode, String content) { Log.d(TAG, "Attempt to unlock event " + selectedEvent + " succesful. Refreshing view..."); AppUtils.showCenteredToast(getActivity(), R.string.fragment_events_list_unlock_successful, Toast.LENGTH_LONG); refreshEvent(selectedEvent); mode.finish(); } }); }
From source file:pl.bcichecki.rms.client.android.fragments.EventsListFragment.java
private void performActionArchive(final ActionMode mode, MenuItem item, final Event selectedEvent) { eventsRestClient.archiveEvent(selectedEvent, new AsyncHttpResponseHandler() { @Override/*from w ww. ja v a 2 s. c om*/ public void onFailure(Throwable error, String content) { Log.d(TAG, "Archive event failed. [error=" + error + ", content=" + content + "]"); if (error instanceof HttpResponseException) { if (((HttpResponseException) error).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { AppUtils.showCenteredToast(getActivity(), R.string.general_unathorized_error_message_title, Toast.LENGTH_LONG); } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } else { AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title, Toast.LENGTH_LONG); } } @Override public void onFinish() { hideLoadingMessage(); Log.d(TAG, "Attempt archive Event " + selectedEvent + " finished."); } @Override public void onStart() { Log.d(TAG, "Attempting archive Event " + selectedEvent + " started."); showLoadingMessage(); } @Override public void onSuccess(int statusCode, String content) { Log.d(TAG, "Event archive succesfull. Refreshing view."); AppUtils.showCenteredToast(getActivity(), R.string.fragment_events_list_archive_successful, Toast.LENGTH_LONG); refreshEvent(selectedEvent); mode.finish(); } }); }