Example usage for android.view ActionMode getMenuInflater

List of usage examples for android.view ActionMode getMenuInflater

Introduction

In this page you can find the example usage for android.view ActionMode getMenuInflater.

Prototype

public abstract MenuInflater getMenuInflater();

Source Link

Document

Returns a MenuInflater with the ActionMode's context.

Usage

From source file:biz.wiz.android.wallet.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override/* w  ww .  j  ava  2 s .c o  m*/
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today)
                        : dateFormat.format(time)) + ", " + timeFormat.format(time) : null);

                final Coin value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getWalletAddressOfReceived(tx, wallet)
                        : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null);

                serializedTx = tx.unsafeBitcoinSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString())));

                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = getResources().getDimensionPixelSize(R.dimen.bitmap_dialog_qr_size);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}

From source file:com.miz.mizuu.fragments.TvShowSeasonsFragment.java

public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    mAdapter = new ImageAdapter(mContext);

    mProgressBar = (ProgressBar) v.findViewById(R.id.progress);

    mGridView = (GridView) v.findViewById(R.id.gridView);
    mGridView.setEmptyView(v.findViewById(R.id.progress));
    mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
    mGridView.setAdapter(mAdapter);/*from   w w  w. j  a v  a 2 s  . c om*/
    mGridView.setColumnWidth(mImageThumbSize);

    // Calculate the total column width to set item heights by factor 1.5
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (mAdapter.getNumColumns() == 0) {
                final int numColumns = (int) Math
                        .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
                if (numColumns > 0) {
                    mAdapter.setNumColumns(numColumns);
                }
            }
        }
    });
    mGridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // Update the selected index variable
            mSelectedIndex = arg2;

            // Show the episode browser Activity for the given season
            getActivity().startActivityForResult(IntentUtils.getTvShowSeasonIntent(getActivity(), mShowId,
                    mItems.get(arg2).getSeason(), mItems.get(arg2).getEpisodeCount(), mToolbarColor), 0);
        }
    });
    mGridView.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            mGridView.setItemChecked(position, true);
            return true;
        }
    });
    mGridView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.seasons_contextual, menu);

            mContextualActionBarEnabled = true;
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return true;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
            case R.id.watched:
                changeWatchedStatus(true, new HashSet<Integer>(mCheckedSeasons));
                break;
            case R.id.unwatched:
                changeWatchedStatus(false, new HashSet<Integer>(mCheckedSeasons));
                break;
            case R.id.remove:
                removeSelectedSeasons(new HashSet<Integer>(mCheckedSeasons));
                break;
            }

            mode.finish();

            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            mContextualActionBarEnabled = false;
            mCheckedSeasons.clear();
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            if (checked) {
                mCheckedSeasons.add(mItems.get(position).getSeason());
            } else {
                mCheckedSeasons.remove(mItems.get(position).getSeason());
            }

            int count = mCheckedSeasons.size();
            mode.setTitle(
                    count + " " + getResources().getQuantityString(R.plurals.seasons_selected, count, count));

            // Nasty hack to update the selected items highlight...
            mAdapter.notifyDataSetChanged();
        }
    });

    // The layout has been created - let's load the data
    loadSeasons();
}

From source file:pl.bcichecki.rms.client.android.fragments.DevicesListFragment.java

private void setUpActionModeOnListItems() {
    getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

        @Override//from   www  .ja  va  2 s . c  om
        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_devices_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) {
                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;
        }
    });
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.TransactionsListFragment.java

private void handleTransactionClick(@Nonnull final Transaction tx) {
    activity.startActionMode(new ActionMode.Callback() {
        private Address address;
        private byte[] serializedTx;

        private static final int SHOW_QR_THRESHOLD_BYTES = 2500;

        @Override/*from  w w  w. j a v  a 2  s  .  c  om*/
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.wallet_transactions_context, menu);

            return true;
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            try {
                final Date time = tx.getUpdateTime();
                final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
                final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);

                mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today)
                        : dateFormat.format(time)) + ", " + timeFormat.format(time) : null);

                final Coin value = tx.getValue(wallet);
                final boolean sent = value.signum() < 0;

                address = sent ? WalletUtils.getWalletAddressOfReceived(tx, wallet)
                        : WalletUtils.getFirstFromAddress(tx);

                final String label;
                if (tx.isCoinBase())
                    label = getString(R.string.wallet_transactions_fragment_coinbase);
                else if (address != null)
                    label = AddressBookProvider.resolveLabel(activity, address.toString());
                else
                    label = "?";

                final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " ";

                if (tx.getPurpose() != Purpose.KEY_ROTATION)
                    mode.setSubtitle(label != null ? prefix + label
                            : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE,
                                    Constants.ADDRESS_FORMAT_LINE_SIZE));
                else
                    mode.setSubtitle(null);

                menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null);

                serializedTx = tx.unsafePeercoinSerialize();

                menu.findItem(R.id.wallet_transactions_context_show_qr)
                        .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES);

                return true;
            } catch (final ScriptException x) {
                return false;
            }
        }

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();

                mode.finish();
                return true;

            case R.id.wallet_transactions_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString())));

                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
        }

        private void handleEditAddress(@Nonnull final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
        }

        private void handleShowQr() {
            final int size = getResources().getDimensionPixelSize(R.dimen.bitmap_dialog_qr_size);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
}

From source file:me.acristoffers.tracker.activities.PackageListActivity.java

@Override
public boolean onCreateActionMode(final ActionMode actionMode, final Menu menu) {
    final MenuInflater inflater = actionMode.getMenuInflater();
    inflater.inflate(R.menu.menu_package_long_click, menu);

    this.actionMode = actionMode;

    final ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.hide();/*  ww  w  . j a  v  a 2  s.c o  m*/
    }

    final View addButton = findViewById(R.id.addButton);
    if (addButton != null) {
        addButton.setVisibility(View.INVISIBLE);
    }

    return true;
}

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// ww  w  .  j a va2 s .  com
        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:email.schaal.ocreader.ListActivity.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    mode.getMenuInflater().inflate(R.menu.menu_item_list_action, menu);
    mode.setTitle(String.valueOf(adapter.getSelectedItemsCount()));
    startDrawer.getDrawerLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    swipeRefreshLayout.setEnabled(false);
    fab_mark_all_read.setVisibility(View.GONE);
    ((CoordinatorLayout.LayoutParams) fab_mark_all_read.getLayoutParams()).setBehavior(null);
    return true;//from   www .j  a  v a  2s  .c o  m
}

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//  w w w. j a v a2 s.c om
        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:com.lithidsw.wallbox.app.randomizer.RandomizerFrag.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    fa = super.getActivity();
    mUtils = new Utils(fa);
    menuHelper = new MenuHelper(fa);
    ll = (LinearLayout) inflater.inflate(R.layout.randomizer_frag, container, false);
    prefs = fa.getSharedPreferences(C.PREF, Context.MODE_PRIVATE);

    adapter = new RandomizerGridAdapter(fa, mGalItems);
    mGridView = (GridView) ll.findViewById(R.id.grid_view);
    mTextView = (TextView) ll.findViewById(R.id.no_content);
    mProgressBar = (ProgressBar) ll.findViewById(R.id.progress);
    mGridView.setAdapter(adapter);/*from  w w  w .  ja  v a  2  s  .c o  m*/

    mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
    mGridView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        @Override
        public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) {

        }

        @Override
        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
            actionMode.setTitle("Choose threads");
            mRemoveList.clear();
            MenuInflater inflater = actionMode.getMenuInflater();
            inflater.inflate(R.menu.randomizer_selection_menu, menu);
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
            final SparseBooleanArray checked = mGridView.getCheckedItemPositions();
            switch (menuItem.getItemId()) {
            case R.id.action_delete:
                int size = checked.size();
                for (int i = 0; i < size; i++) {
                    int key = checked.keyAt(i);
                    boolean value = checked.get(key);
                    if (value) {
                        new TableHelper(fa).deleteSinglePaper(mGalItems.get(key)[1]);
                    }
                }
                actionMode.finish();
                new GalLoader().execute();
                break;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode actionMode) {

        }
    });
    setHasOptionsMenu(true);

    if (!prefs.getBoolean(C.PREF_RANDOMIZER_FIRST_RUN_MAIN, false)) {
        prefs.edit().putBoolean(C.PREF_RANDOMIZER_FIRST_RUN_MAIN, true).commit();
        String title = getResources().getString(R.string.main_title_randomize);
        String message = getResources().getString(R.string.randomizer_description);
        new CustomDialogs().openFirstDialog(fa, title, message);
    }
    return ll;
}

From source file:org.amahi.anywhere.fragment.ServerFilesFragment.java

@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
    this.filesActions = actionMode;

    actionMode.getMenuInflater().inflate(R.menu.action_mode_server_files, menu);

    return true;/*from ww  w  . j  a v a 2s .c o m*/
}