List of usage examples for android.widget AbsListView CHOICE_MODE_MULTIPLE_MODAL
int CHOICE_MODE_MULTIPLE_MODAL
To view the source code for android.widget AbsListView CHOICE_MODE_MULTIPLE_MODAL.
Click Source Link
From source file:com.docd.purefm.ui.fragments.BrowserFragment.java
private void initList(@NonNull final LayoutInflater inflater, @NonNull final View parent) { final AbstractBrowserActivity context = getBrowserActivity(); if (mListView != null) { final View emptyView = mListView.getEmptyView(); if (emptyView != null) { emptyView.setVisibility(View.GONE); }/*from w ww . ja va2 s . c om*/ mListView.setVisibility(View.GONE); } final Settings settings = Settings.getInstance(context); final ViewGroup listContainer = (ViewGroup) parent.findViewById(R.id.list_container); if (listContainer == null) { throw new RuntimeException("parent should contain ViewGroup with id R.id.list_container"); } final View swipeRefreshList; switch (settings.getListAppearance()) { case LIST: swipeRefreshList = inflater.inflate(R.layout.browser_listview, listContainer); break; case GRID: swipeRefreshList = inflater.inflate(R.layout.browser_gridview, listContainer); break; default: throw new IllegalArgumentException("Unexpected ListAppearance: " + settings.getListAppearance()); } if (swipeRefreshList == null) { throw new RuntimeException("Inflated View is null"); } mMainProgress = parent.findViewById(android.R.id.progress); mSwipeRefreshLayoutList = (SwipeRefreshLayout) swipeRefreshList .findViewById(R.id.browser_list_swipe_refresh); mSwipeRefreshLayoutEmpty = (SwipeRefreshLayout) parent.findViewById(android.R.id.empty); mListView = (AbsListView) mSwipeRefreshLayoutList.getChildAt(0); if (mListView instanceof ListView) { mAdapter = new BrowserListAdapter(context); } else { mAdapter = new BrowserGridAdapter(context); } menuController.setBrowserAdapter(this.mAdapter); mListView.setEmptyView(parent.findViewById(android.R.id.empty)); mListView.setAdapter(this.mAdapter); final View emptyView = mListView.getEmptyView(); if (emptyView != null) { emptyView.setVisibility(View.GONE); } mListView.setVisibility(View.GONE); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> av, View v, int pos, long id) { final GenericFile target = (GenericFile) (av.getItemAtPosition(pos)); if (target == null) { throw new RuntimeException("onItemClick(): item at position is null"); } if (target.isDirectory()) { mBrowser.navigate(target, true); } else { final AbstractBrowserActivity activity = getBrowserActivity(); if (activity.getGetContentMimeType() == null) { PFMFileUtils.openFileInExternalApp(activity, target.toFile()); } else { final Intent intent = new Intent(); intent.setData(getResultUriForFileFromIntent(activity.getContentResolver(), target.toFile(), activity.getIntent())); activity.setResult(Activity.RESULT_OK, intent); activity.finish(); } } } /* * Copyright (C) 2013 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ private Uri getResultUriForFileFromIntent(ContentResolver cr, File src, Intent intent) { // Try to find the preferred uri scheme Uri result = MediaHelper.fileToContentUri(cr, src); if (result == null) { result = Uri.fromFile(src); } if (Intent.ACTION_PICK.equals(intent.getAction()) && intent.getData() != null) { final String scheme = intent.getData().getScheme(); if (scheme != null) { result = result.buildUpon().scheme(scheme).build(); } } return result; } }); mListView.setChoiceMode(context.getGetContentMimeType() == null ? AbsListView.CHOICE_MODE_MULTIPLE_MODAL : AbsListView.CHOICE_MODE_NONE); mSwipeRefreshLayoutList.setOnRefreshListener(this); mSwipeRefreshLayoutEmpty.setOnRefreshListener(this); final int color2resId = settings.getTheme() == Settings.Theme.LIGHT ? R.color.holo_light_window_background : R.color.holo_dark_window_background; mSwipeRefreshLayoutList.setColorScheme(R.color.holo_light_selected, color2resId, R.color.holo_light_selected, color2resId); mSwipeRefreshLayoutEmpty.setColorScheme(R.color.holo_light_selected, color2resId, R.color.holo_light_selected, color2resId); }
From source file:pl.bcichecki.rms.client.android.fragments.OutboxMessagesListFragment.java
private void setUpActionModeOnListItems() { getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override//from w w w.j a v a 2s. c o m public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return performAction(mode, item); } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.fragment_outbox_messages_list_context, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { verifyMenuItems(mode.getMenu()); for (int i = 0; i < getListView().getCheckedItemPositions().size(); i++) { if (i != position) { getListView().setItemChecked(i, false); } } } } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } private void verifyMenuItems(Menu menu) { Message checkedMessage = getFirstCheckedItem(); menu.findItem(R.id.fragment_outbox_messages_list_context_menu_archive) .setVisible(!checkedMessage.isArchivedBySender()); } }); }
From source file:pl.bcichecki.rms.client.android.fragments.InboxMessagesListFragment.java
private void setUpActionModeOnListItems() { getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override/*from w w w. j a va2 s . c o m*/ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return performAction(mode, item); } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.fragment_inbox_messages_list_context, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { verifyMenuItems(mode.getMenu()); for (int i = 0; i < getListView().getCheckedItemPositions().size(); i++) { if (i != position) { getListView().setItemChecked(i, false); } } } } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } private void verifyMenuItems(Menu menu) { Message checkedMessage = getFirstCheckedItem(); menu.findItem(R.id.fragment_inbox_messages_list_context_menu_archive) .setVisible(!checkedMessage.isArchivedBySender()); } }); }
From source file:de.azapps.mirakel.main_activity.tasks_fragment.TasksFragment.java
@SuppressLint("NewApi") protected void update(final boolean reset) { if (!this.created) { return;/* w w w . j av a 2s . c om*/ } this.listView = (ListView) this.view.findViewById(R.id.tasks_list); this.adapter = new TaskAdapter(getActivity(), new OnTaskChangedListner() { @Override public void onTaskChanged(final Task newTask) { getLoaderManager().restartLoader(0, null, TasksFragment.this); if (MirakelCommonPreferences.isTablet() && TasksFragment.this.main.getTaskFragment() != null && TasksFragment.this.main.getTaskFragment().getTask().getId() == newTask.getId()) { TasksFragment.this.main.getTaskFragment().update(newTask); } } }); adapter.setFilterQueryProvider(this); this.listView.setAdapter(this.adapter); getLoaderManager().initLoader(0, null, this); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { this.listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(final AdapterView<?> parent, final View item, final int position, final long id) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final Task task = Task.get((Long) item.getTag()).orNull(); if (task == null) { return false; } builder.setTitle(task.getName()); final List<CharSequence> items = new ArrayList<CharSequence>( Arrays.asList(getActivity().getResources().getStringArray(R.array.task_actions_items))); builder.setItems(items.toArray(new CharSequence[items.size()]), new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int item) { switch (item) { case TASK_RENAME: TasksFragment.this.main.setCurrentTask(task); break; case TASK_MOVE: TasksFragment.this.main.handleMoveTask(task); break; case TASK_DESTROY: TasksFragment.this.main.handleDestroyTask(task); break; default: break; } } }); final AlertDialog dialog = builder.create(); dialog.show(); return true; } }); } else { this.listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); this.listView.setHapticFeedbackEnabled(true); this.listView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.menu_delete: TasksFragment.this.main.handleDestroyTask(TasksFragment.this.selectedTasks); break; case R.id.menu_move: TasksFragment.this.main.handleMoveTask(TasksFragment.this.selectedTasks); break; case R.id.menu_set_due: TasksFragment.this.main.handleSetDue(TasksFragment.this.selectedTasks); break; case R.id.edit_task: TasksFragment.this.main.setCurrentTask(TasksFragment.this.selectedTasks.get(0), true); break; case R.id.done_task: for (final Task t : TasksFragment.this.selectedTasks) { t.setDone(true); t.save(); } getLoaderManager().restartLoader(0, null, TasksFragment.this); break; default: break; } mode.finish(); return false; } @Override public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.context_tasks, menu); TasksFragment.this.mActionMode = mode; clearFocus(); TasksFragment.this.selectedTasks = new ArrayList<>(); return true; } @Override public void onDestroyActionMode(final ActionMode mode) { TasksFragment.this.selectedTasks = new ArrayList<>(); } @Override public void onItemCheckedStateChanged(final ActionMode mode, final int position, final long id, final boolean checked) { final Cursor cursor = (Cursor) TasksFragment.this.listView.getItemAtPosition(position); if (cursor.getCount() > 0) { final Task t = new Task(cursor); if (!TasksFragment.this.selectedTasks.contains(t) && checked) { TasksFragment.this.selectedTasks.add(t); } else if (checked) { TasksFragment.this.selectedTasks.remove(t); } } } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { menu.findItem(R.id.edit_task).setVisible(TasksFragment.this.selectedTasks.size() <= 1); return false; } }); } this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View item, final int position, final long id) { long taskId = (Long) item.getTag(); Optional<Task> taskOptional = Task.get(taskId); if (taskOptional.isPresent()) { TasksFragment.this.main.setCurrentTask(taskOptional.get(), true); } else { throw new TaskVanishedException(taskId); } } }); }
From source file:pl.bcichecki.rms.client.android.fragments.EventsListFragment.java
private void setUpActionModeOnListItems() { getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override// w ww. j a v a2 s .co m public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return performAction(mode, item); } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.fragment_events_list_context, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { verifyMenuItems(mode.getMenu()); for (int i = 0; i < getListView().getCheckedItemPositions().size(); i++) { if (i != position) { getListView().setItemChecked(i, false); } } } } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } private void verifyMenuItems(Menu menu) { Event checkedEvent = getFirstCheckedItem(); menu.findItem(R.id.fragment_events_list_context_menu_archive) .setVisible(!checkedEvent.isArchived()); menu.findItem(R.id.fragment_events_list_context_menu_edit) .setVisible(!checkedEvent.isArchived() || !checkedEvent.isLocked()); menu.findItem(R.id.fragment_events_list_context_menu_lock).setVisible(!checkedEvent.isLocked()); menu.findItem(R.id.fragment_events_list_context_menu_share).setVisible(!checkedEvent.isArchived()); menu.findItem(R.id.fragment_events_list_context_menu_unlock).setVisible(checkedEvent.isLocked()); } }); }