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:com.piusvelte.sonet.core.SonetNotifications.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_notifications, menu);
    return super.onCreateOptionsMenu(menu);
}

From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (!mContactsAvailable || mActivity.isInSecondLevel()) {
        // If contacts aren't available or this fragment is not visible, hide all menu items.
        return;//from  w ww . ja va2s.com
    }
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.people_options, menu);
}

From source file:com.piusvelte.sonet.core.SonetComments.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_comments, menu);
    return super.onCreateOptionsMenu(menu);
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.subreddit_select_menu, menu);
    // set options menu view
    int iconColor = Color.parseColor("#DBDBDB");
    (menu.findItem(R.id.menu_submit))/*from  w  w w .ja  v a  2  s  .  co  m*/
            .setIcon(new IconDrawable(this, Iconify.IconValue.fa_pencil).color(iconColor).actionBarSize());
    (menu.findItem(R.id.menu_feedprefs))
            .setIcon(new IconDrawable(this, Iconify.IconValue.fa_list_alt).color(iconColor).actionBarSize());
    if (mAppWidgetId == 0) {
        (menu.findItem(R.id.menu_widgettheme)).setEnabled(false);
    }
    (menu.findItem(R.id.menu_widgettheme))
            .setIcon(new IconDrawable(this, Iconify.IconValue.fa_paint_brush).color(iconColor).actionBarSize());
    (menu.findItem(R.id.menu_thememanager))
            .setIcon(new IconDrawable(this, Iconify.IconValue.fa_cogs).color(iconColor).actionBarSize());
    (menu.findItem(R.id.menu_account)).setIcon(
            new IconDrawable(this, Iconify.IconValue.fa_reddit_square).color(iconColor).actionBarSize());
    (menu.findItem(R.id.menu_prefs))
            .setIcon(new IconDrawable(this, Iconify.IconValue.fa_wrench).color(iconColor).actionBarSize());
    (menu.findItem(R.id.menu_about))
            .setIcon(new IconDrawable(this, Iconify.IconValue.fa_info_circle).color(iconColor).actionBarSize());

    return super.onCreateOptionsMenu(menu);
}

From source file:com.openerp.addons.messages.Message.java

public void setupListView(List<OEListViewRows> message_list) {
    // Destroying pre-loaded instance and going to create new one
    lstview = null;//ww w  .  j a  va2  s . co  m

    // Fetching required messages for listview by filtering of requrement
    if (list != null && list.size() <= 0) {
        list = message_list;// getMessages(message_list);
    } else {
        rootView.findViewById(R.id.messageSyncWaiter).setVisibility(View.GONE);
        rootView.findViewById(R.id.txvMessageAllReadMessage).setVisibility(View.GONE);
    }

    // Handling List View controls and keys
    String[] from = new String[] { "subject|type", "body", "starred", "author_id|email_from", "date",
            "model|type" };
    int[] to = new int[] { R.id.txvMessageSubject, R.id.txvMessageBody, R.id.imgMessageStarred,
            R.id.txvMessageFrom, R.id.txvMessageDate, R.id.txvMessageTag };

    // Creating instance for listAdapter
    listAdapter = new OEListViewAdapter(scope.context(), R.layout.message_listview_items, list, from, to, db,
            true, new int[] { R.drawable.message_listview_bg_toread_selector,
                    R.drawable.message_listview_bg_tonotread_selector },
            "to_read");
    // Telling adapter to clean HTML text for key value
    listAdapter.cleanHtmlToTextOn("body");
    listAdapter.cleanDate("date", scope.User().getTimezone());
    // Setting callback handler for boolean field value change.
    listAdapter.setBooleanEventOperation("starred", R.drawable.ic_action_starred,
            R.drawable.ic_action_unstarred, updateStarred);
    listAdapter.addViewListener(new OEListViewOnCreateListener() {

        @Override
        public View listViewOnCreateListener(int position, View row_view, OEListViewRows row_data) {
            String model_name = row_data.getRow_data().get("model").toString();
            String model = model_name;
            String res_id = row_data.getRow_data().get("res_id").toString();
            if (model_name.equals("false")) {
                model_name = capitalizeString(row_data.getRow_data().get("type").toString());
            } else {
                String[] model_parts = TextUtils.split(model_name, "\\.");
                HashSet unique_parts = new HashSet(Arrays.asList(model_parts));
                model_name = capitalizeString(TextUtils.join(" ", unique_parts.toArray()));

            }
            TextView msgTag = (TextView) row_view.findViewById(R.id.txvMessageTag);
            int tag_color = 0;
            if (message_model_colors.containsKey(model_name)) {
                tag_color = message_model_colors.get(model_name);
            } else {
                tag_color = Color.parseColor(tag_colors[tag_color_count]);
                message_model_colors.put(model_name, tag_color);
                tag_color_count++;
                if (tag_color_count > tag_colors.length) {
                    tag_color_count = 0;
                }
            }
            if (model.equals("mail.group")) {
                if (UserGroups.group_names.containsKey("group_" + res_id)) {
                    model_name = UserGroups.group_names.get("group_" + res_id);
                    tag_color = UserGroups.menu_color.get("group_" + res_id);
                }
            }
            msgTag.setBackgroundColor(tag_color);
            msgTag.setText(model_name);
            TextView txvSubject = (TextView) row_view.findViewById(R.id.txvMessageSubject);
            TextView txvAuthor = (TextView) row_view.findViewById(R.id.txvMessageFrom);
            if (row_data.getRow_data().get("to_read").toString().equals("false")) {
                txvSubject.setTypeface(null, Typeface.NORMAL);
                txvSubject.setTextColor(Color.BLACK);

                txvAuthor.setTypeface(null, Typeface.NORMAL);
                txvAuthor.setTextColor(Color.BLACK);
            } else {
                txvSubject.setTypeface(null, Typeface.BOLD);
                txvSubject.setTextColor(Color.parseColor("#414141"));
                txvAuthor.setTypeface(null, Typeface.BOLD);
                txvAuthor.setTextColor(Color.parseColor("#414141"));
            }

            return row_view;
        }
    });

    // Creating instance for listview control
    lstview = (ListView) rootView.findViewById(R.id.lstMessages);
    // Providing adapter to listview
    scope.context().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            lstview.setAdapter(listAdapter);

        }
    });

    // Setting listview choice mode to multiple model
    lstview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

    // Seeting item long click listern to activate action mode.
    lstview.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View view, int index, long arg3) {
            // TODO Auto-generated method stub

            OEListViewRows data = (OEListViewRows) lstview.getAdapter().getItem(index);

            Toast.makeText(scope.context(), data.getRow_id() + " id clicked", Toast.LENGTH_LONG).show();
            view.setSelected(true);
            if (mActionMode != null) {
                return false;
            }
            // Start the CAB using the ActionMode.Callback defined above
            mActionMode = scope.context().startActionMode(mActionModeCallback);
            selectedCounter++;
            view.setBackgroundResource(R.drawable.listitem_pressed);
            // lstview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
            return true;

        }
    });

    // Setting multi choice selection listener
    lstview.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        HashMap<Integer, Boolean> selectedList = new HashMap<Integer, Boolean>();

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            // Here you can do something when items are
            // selected/de-selected,
            // such as update the title in the CAB
            selectedList.put(position, checked);
            if (checked) {
                selectedCounter++;
            } else {
                selectedCounter--;
            }
            if (selectedCounter != 0) {
                mode.setTitle(selectedCounter + "");
            }

        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            // Respond to clicks on the actions in the CAB
            HashMap<Integer, Integer> msg_pos = new HashMap<Integer, Integer>();
            OEDialog dialog = null;
            switch (item.getItemId()) {
            case R.id.menu_message_mark_unread_selected:
                Log.e("menu_message_context", "Mark as Unread");
                for (int pos : selectedList.keySet()) {
                    msg_pos.put(list.get(pos).getRow_id(), pos);
                }
                readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, false);
                readunreadoperation.execute((Void) null);
                mode.finish();
                return true;
            case R.id.menu_message_mark_read_selected:
                Log.e("menu_message_context", "Mark as Read");
                for (int pos : selectedList.keySet()) {
                    msg_pos.put(list.get(pos).getRow_id(), pos);
                }
                readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, true);
                readunreadoperation.execute((Void) null);
                mode.finish();
                return true;
            case R.id.menu_message_more_move_to_archive_selected:
                Log.e("menu_message_context", "Archive");
                for (int pos : selectedList.keySet()) {
                    msg_pos.put(list.get(pos).getRow_id(), pos);
                }
                readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, false);
                readunreadoperation.execute((Void) null);
                mode.finish();
                return true;
            case R.id.menu_message_more_add_star_selected:
                for (int pos : selectedList.keySet()) {
                    msg_pos.put(list.get(pos).getRow_id(), pos);
                }

                markasTodoTask = new PerformOperation(msg_pos, true);
                markasTodoTask.execute((Void) null);

                mode.finish();

                return true;
            case R.id.menu_message_more_remove_star_selected:
                for (int pos : selectedList.keySet()) {
                    msg_pos.put(list.get(pos).getRow_id(), pos);
                }

                markasTodoTask = new PerformOperation(msg_pos, false);
                markasTodoTask.execute((Void) null);
                mode.finish();
                return true;
            default:
                return false;
            }
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // Inflate the menu for the CAB
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.menu_fragment_message_context, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            // Here you can make any necessary updates to the activity when
            // the CAB is removed. By default, selected items are
            // deselected/unchecked.

            /*
             * Perform Operation on Selected Ids.
             * 
             * row_ids are list of selected message Ids.
             */

            selectedList.clear();
            selectedCounter = 0;
            lstview.clearChoices();

        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            // Here you can perform updates to the CAB due to
            // an invalidate() request
            return false;
        }
    });
    lstview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int index, long id) {
            // TODO Auto-generated method stub
            MessageDetail messageDetail = new MessageDetail();
            Bundle bundle = new Bundle();
            bundle.putInt("message_id", list.get(index).getRow_id());
            bundle.putInt("position", index);
            messageDetail.setArguments(bundle);
            scope.context().fragmentHandler.setBackStack(true, null);
            scope.context().fragmentHandler.replaceFragmnet(messageDetail);
            if (!type.equals("archive")) {
                list.remove(index);
            }
            listAdapter.refresh(list);
        }
    });

    // Getting Pull To Refresh Attacher from Main Activity
    mPullToRefreshAttacher = scope.context().getPullToRefreshAttacher();

    // Set the Refreshable View to be the ListView and the refresh listener
    // to be this.
    if (mPullToRefreshAttacher != null & lstview != null) {
        mPullToRefreshAttacher.setRefreshableView(lstview, this);
    }
}

From source file:org.planetmono.dcuploader.ActivityUploader.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater mi = getMenuInflater();
    mi.inflate(R.menu.uploader, menu);

    Application app = (Application) getApplication();
    if (!app.isSignedOn())
        menu.findItem(R.id.menu_uploader_sign_off).setEnabled(false);

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

From source file:com.tsp.clipsy.audio.RingdroidEditActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.edit_options, menu);

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

From source file:com.trailbehind.android.iburn.map.MapActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (mMenu == null) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.map_menu, menu);
        mMenu = menu;//from  ww  w  .  j a  v  a  2 s  .c  om
    }

    return true;
}

From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java

/**
 * Populates the menu.//from ww  w . j  av  a2  s.  c om
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.subreddit, menu);
    return true;
}

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.info, menu);
    return true;/*  w  w w.ja  v  a  2 s  . com*/
}