Example usage for android.view MenuInflater inflate

List of usage examples for android.view MenuInflater inflate

Introduction

In this page you can find the example usage for android.view MenuInflater inflate.

Prototype

public void inflate(@MenuRes int menuRes, Menu menu) 

Source Link

Document

Inflate a menu hierarchy from the specified XML resource.

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//from  w w w.j av a2s  .  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.activiti.android.app.fragments.settings.AccountSettingsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    if (!DisplayUtils.hasCentralPane(getActivity())) {
        menu.clear();/*from   www  .  j a  va 2  s  . com*/
        inflater.inflate(R.menu.account, menu);
    } else {
        getToolbar().getMenu().clear();
        getToolbar().inflateMenu(R.menu.account);
        getToolbar().setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                return onOptionsItemSelected(item);
            }
        });

    }
}

From source file:net.reichholf.dreamdroid.fragment.NavigationFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.preferences, menu);
}

From source file:com.odkclinic.client.PatientList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the patientlist menu XML resource.
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.patientlist, menu);

    return true;/* ww w  . j  a v a  2s  .c om*/
}

From source file:com.danielme.muspyforandroid.activities.base.AbstractActivity.java

/**
 * Unfortunately font-style must be set programmatically //
 * http://stackoverflow//  ww w  .  ja  v a2s . c o m
 * .com/questions/10521416/option-menu-default-gray-border-removal <item
 * name="android:panelFullBackground">@color/barbackground</item>
 * 
 */
public boolean onCreateOptionsMenu(android.view.Menu menu) {
    if (this instanceof AboutActivity) {
        return false;
    }

    MenuInflater inflater = getMenuInflater();
    if (this instanceof SignInActivity || this instanceof SignUpActivity
            || this instanceof ResetPasswordActivity) {
        inflater.inflate(R.menu.menusimple, menu);
    } else {
        inflater.inflate(R.menu.menu, menu);
    }

    getLayoutInflater().setFactory(new Factory() {
        public View onCreateView(String name, Context context, AttributeSet attrs) {
            if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
                try {
                    LayoutInflater layoutInflater = LayoutInflater.from(context);
                    final View view = layoutInflater.createView(name, null, attrs);

                    new Handler().post(new Runnable() {
                        public void run() {
                            ((TextView) view).setTextColor(Color.WHITE);
                            view.setBackgroundResource(R.drawable.menu_selector);
                        }
                    });
                    return view;
                } catch (Exception e) {
                    Log.w("onCreateOptionsMenu", e.getMessage(), e);
                }
            }
            return null;
        }
    });
    return super.onCreateOptionsMenu(menu);
}

From source file:co.carlosjimenez.android.currencyalerts.app.DetailActivityFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (getActivity() instanceof DetailActivity) {
        // Inflate the menu; this adds items to the action bar if it is present.
        inflater.inflate(R.menu.detailfragment, menu);
        finishCreatingMenu(menu);// ww  w  .jav a 2s .  c  om
    }
}

From source file:com.anjalimacwan.fragment.NoteViewFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.note_view, menu);
}

From source file:fr.cph.chicago.activity.StationActivity.java

@Override
public final boolean onCreateOptionsMenu(final Menu menu) {
    super.onCreateOptionsMenu(menu);
    this.mMenu = menu;
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_no_search, menu);

    MenuItem refreshMenuItem = menu.findItem(R.id.action_refresh);
    refreshMenuItem.setActionView(R.layout.progressbar);
    refreshMenuItem.expandActionView();//from   w w  w .ja  v a  2  s . c om

    return true;
}

From source file:com.amrutpatil.makeanote.NotesActivity.java

private void setUpForRecyclerView() {
    mContentResolver = getContentResolver();
    mNotesAdapter = new NotesAdapter(NotesActivity.this, new ArrayList<Note>());
    int LOADER_ID = 1;
    getSupportLoaderManager().initLoader(LOADER_ID, null, NotesActivity.this);
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_home);
    GridLayoutManager linearlayoutManager = new GridLayoutManager(getApplicationContext(), 1);
    linearlayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(linearlayoutManager);
    mRecyclerView.setAdapter(mNotesAdapter);
    mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, mRecyclerView,
            new RecyclerItemClickListener.OnItemClickListener() {
                @Override/*ww w .  j av a2s .com*/
                public void OnItemClick(View view, int position) {
                    edit(view);
                }

                @Override
                public void OnItemLongClick(View view, int position) {
                    PopupMenu popupMenu = new PopupMenu(NotesActivity.this, view);
                    MenuInflater menuInflater = popupMenu.getMenuInflater();
                    menuInflater.inflate(R.menu.action_notes, popupMenu.getMenu());
                    popupMenu.show();
                    final View v = view;
                    final int pos = position;
                    popupMenu.setOnMenuItemClickListener(
                            new android.support.v7.widget.PopupMenu.OnMenuItemClickListener() {
                                @Override
                                public boolean onMenuItemClick(MenuItem item) {
                                    if (item.getItemId() == R.id.action_delete) {
                                        moveToTrash();
                                        delete(v, pos);
                                    } else if (item.getItemId() == R.id.action_archive) {
                                        moveToArchive(v, pos);
                                    } else if (item.getItemId() == R.id.action_edit) {
                                        edit(v);
                                    }
                                    return false;
                                }
                            });
                }
            }));
}

From source file:com.orange.ocara.ui.activity.SetupAuditPathActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    final AuditObject auditObject = auditObjectsAdapter.getItem(info.position);

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(com.orange.ocara.R.menu.audit_objects_context_menu, menu);

    if (auditObject.getObjectDescription().getChildren().isEmpty()) {
        menu.findItem(com.orange.ocara.R.id.action_object_characteristics).setVisible(false);
    } else {//from  w  ww.ja  v a  2  s . c  om
        menu.findItem(com.orange.ocara.R.id.action_object_characteristics).setVisible(true);
    }

}