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:com.miz.mizuu.fragments.TvShowEpisodesFragment.java

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

    if (MizLib.isTablet(mContext) && !MizLib.isPortrait(mContext)) {
        v.findViewById(R.id.container).setBackgroundColor(Color.parseColor("#05FFFFFF"));
    }/*from w  ww  .j  av a 2 s  .c  om*/

    mAdapter = new ImageAdapter(mContext);

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

    mGridView = (GridView) v.findViewById(R.id.gridView);
    mGridView.setColumnWidth(mImageThumbSize);
    mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
    mGridView.setEmptyView(v.findViewById(R.id.progress));
    mGridView.setAdapter(mAdapter);

    if (mUseGridView) {
        // 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);
                                mResizedWidth = (int) (((mGridView.getWidth()
                                        - (numColumns * mImageThumbSpacing)) / numColumns) * 1.1); // * 1.1 is a hack to make images look slightly less blurry
                                mResizedHeight = (int) (mResizedWidth / 1.778);
                            }
                        }
                    }
                });
    } else {
        mGridView.setNumColumns(1);
        mAdapter.setNumColumns(1);
    }
    mGridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            Intent i = new Intent(mContext, TvShowEpisodeDetails.class);
            i.putExtra(SHOW_ID, mShowId);
            i.putExtra("episode", mEpisodeLoader.getResults().get(arg2).getEpisode());
            i.putExtra("season", mSeason);
            getActivity().startActivityForResult(i, 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.episodes_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>(mCheckedEpisodes));
                break;
            case R.id.unwatched:
                changeWatchedStatus(false, new HashSet<Integer>(mCheckedEpisodes));
                break;
            case R.id.remove:
                removeSelectedEpisodes(new HashSet<Integer>(mCheckedEpisodes));
                break;
            case R.id.identify:
                identify(new HashSet<Integer>(mCheckedEpisodes));
                break;
            }

            mode.finish();

            // Make the seasons grid refresh
            mBus.post(new com.miz.mizuu.TvShowEpisode());

            return true;
        }

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

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            if (checked)
                mCheckedEpisodes.add(mEpisodeLoader.getResults().get(position).getEpisode());
            else
                mCheckedEpisodes.remove(mEpisodeLoader.getResults().get(position).getEpisode());

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

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

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

From source file:com.btmura.android.reddit.app.NavigationFragment.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    if (subredditAdapter.getCursor() == null) {
        getListView().clearChoices();// w w w  .  j ava 2 s.  c  om
        return false;
    }

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

From source file:com.miz.mizuu.UnidentifiedTvShows.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mList = (ListView) findViewById(R.id.listView1);
    mList.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        // Called when the user selects a contextual menu item
        @Override/*from   w  ww  .j  av  a  2 s. c o  m*/
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
            case R.id.identify:
                identifySelectedFiles();
                break;
            }

            mode.finish();

            return true;
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // Inflate a menu resource providing context menu items
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.unidentified, menu);

            return true;
        }

        // Called when the user exits the action mode
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            mode = null;

            // Unselected the item
            mList.clearFocus();
            mList.clearChoices();
            mList.invalidate();
        }

        // Called each time the action mode is shown. Always called after onCreateActionMode, but
        // may be called multiple times if the mode is invalidated.
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return true; // Return false if nothing is done
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            mode.setTitle(mList.getCheckedItemCount() + " selected");
        }
    });
    mList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            mList.setItemChecked(arg2, !mList.isItemChecked(arg2));
        }
    });

    loadData();

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
            new IntentFilter(LocalBroadcastUtils.UPDATE_TV_SHOW_LIBRARY));
}

From source file:com.miz.mizuu.UnidentifiedFiles.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.unidentified_files_layout);

    mList = (ListView) findViewById(R.id.listView1);
    mList.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        // Called when the user selects a contextual menu item
        @Override/*from   w  w  w  . j av a  2  s.com*/
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
            case R.id.identify:
                identifySelectedFiles();
                break;
            }

            mode.finish();

            return true;
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // Inflate a menu resource providing context menu items
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.unidentified, menu);

            return true;
        }

        // Called when the user exits the action mode
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            mode = null;

            // Unselected the item
            mList.clearFocus();
            mList.clearChoices();
            mList.invalidate();
        }

        // Called each time the action mode is shown. Always called after onCreateActionMode, but
        // may be called multiple times if the mode is invalidated.
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return true; // Return false if nothing is done
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            mode.setTitle(mList.getCheckedItemCount() + " selected");
        }
    });
    mList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            mList.setItemChecked(arg2, !mList.isItemChecked(arg2));
        }
    });

    loadData();

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
            new IntentFilter("tvshow-episode-changed"));
}

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  w  w  .  j  av a 2  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_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());
        }
    });
}

From source file:com.acbelter.scheduleview.ScheduleView.java

public ScheduleView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    mClipRect = new Rect();
    mClickedViewBounds = new Rect();
    mSelectedIds = new HashSet<Long>();
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mTopEdgeEffect = new EdgeEffectCompat(context);
    mBottomEdgeEffect = new EdgeEffectCompat(context);

    mDataSetObserver = new DataSetObserver() {
        @Override/*www  .  j  a va2  s  . co  m*/
        public void onChanged() {
            super.onChanged();
            removeAllViewsInLayout();
            requestLayout();
        }

        @Override
        public void onInvalidated() {
            super.onInvalidated();
            removeAllViewsInLayout();
            requestLayout();
        }
    };

    init(context);

    setVerticalScrollBarEnabled(true);
    setHorizontalScrollBarEnabled(false);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScheduleView, defStyle, 0);
    try {
        if (a != null) {
            DisplayMetrics dm = context.getResources().getDisplayMetrics();
            mInternalPaddingTop = (int) a.getDimension(R.styleable.ScheduleView_internalPaddingTop,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            mInternalPaddingBottom = (int) a.getDimension(R.styleable.ScheduleView_internalPaddingBottom,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            mTimeMarksDistance = (int) a.getDimension(R.styleable.ScheduleView_timeMarksDistance,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, dm));
            mItemPaddingLeft = (int) a.getDimension(R.styleable.ScheduleView_itemPaddingLeft,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            mItemPaddingRight = (int) a.getDimension(R.styleable.ScheduleView_itemPaddingRight,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            initializeScrollbars(a);
        }
    } finally {
        if (a != null) {
            a.recycle();
        }
    }

    // Draw the background even if no items to display
    setWillNotDraw(false);

    mActionModeCallback = new ActionMode.Callback() {
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.getMenuInflater().inflate(R.menu.menu_context, menu);
            mIsActionMode = true;
            return true;
        }

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

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            if (item.getItemId() == R.id.delete_items) {
                deleteSelectedItems();
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            clearSelection();
            mIsActionMode = false;
            mActionMode = null;
            invalidate();
        }
    };
}

From source file:net.sourceforge.lifeograph.ActivityDiary.java

public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    // Inflate a menu resource providing context menu items
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.menu_calendar_contextual, menu);

    menu.findItem(R.id.open_entry)/*from   w w  w  . j  a  v a2 s .  c  om*/
            .setVisible(Diary.diary.m_entries.containsKey(mCalPagerAdapter.getSelectedDate().m_date + 1));

    menu.findItem(R.id.create_chapter).setVisible(
            !Diary.diary.m_ptr2chapter_ctg_cur.mMap.containsKey(mCalPagerAdapter.getSelectedDate().m_date));

    return true;
}

From source file:org.ambient.control.home.roomitems.LightObjectStrategy.java

/**
 * edit the renderingconfiguration of the light object. preview, and save actions are handled in the editActivity.
 *//*from  w ww. j a va2 s. c  o m*/
@Override
public void onLongClick(View view, final Room room, final RoomFragment roomFragment, final Entity entity) {

    final RenderingProgramConfiguration itemConfig = ((Renderable) entity).getRenderingProgrammConfiguration();

    roomFragment.getActivity().startActionMode(new ActionMode.Callback() {

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {

            switch (item.getItemId()) {

            case R.id.menuEntryEditActorConduct:

                EditRenderingConfigActivity.createInstanceForEditObject(roomFragment.getActivity(), itemConfig,
                        entity.getId(), room.roomName, room);
                break;

            case R.id.menuEntryAddActorConduct:

                EditRenderingConfigActivity.createInstanceForNewObject(roomFragment.getActivity(), itemConfig,
                        entity.getId(), room.roomName, room);
                break;

            }
            mode.finish();
            return true;
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.getMenuInflater().inflate(R.menu.fragment_room_cab, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

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

From source file:com.cummins.mowo.activity.swipelistview.SwipeListViewExampleActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from  w  w w. j  a  va  2 s. co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.swipe_list_view_activity);

    data = new ArrayList<PackageItem>();

    adapter = new PackageAdapter(this, data);

    swipeListView = (SwipeListView) findViewById(R.id.example_lv_list);

    if (Build.VERSION.SDK_INT >= 11) {
        swipeListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        swipeListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

            @Override
            public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
                mode.setTitle("Selected (" + swipeListView.getCountSelected() + ")");
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                int id = item.getItemId();
                if (id == R.id.menu_delete) {
                    swipeListView.dismissSelected();
                    return true;
                }
                return false;
            }

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                MenuInflater inflater = mode.getMenuInflater();
                inflater.inflate(R.menu.menu_choice_items, menu);
                return true;
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {
                swipeListView.unselectedChoiceStates();
            }

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

    swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() {
        @Override
        public void onOpened(int position, boolean toRight) {
        }

        @Override
        public void onClosed(int position, boolean fromRight) {
        }

        @Override
        public void onListChanged() {
        }

        @Override
        public void onMove(int position, float x) {
        }

        @Override
        public void onStartOpen(int position, int action, boolean right) {
            Log.d("swipe", String.format("onStartOpen %d - action %d", position, action));
        }

        @Override
        public void onStartClose(int position, boolean right) {
            Log.d("swipe", String.format("onStartClose %d", position));
        }

        @Override
        public void onClickFrontView(int position) {
            Log.d("swipe", String.format("onClickFrontView %d", position));
        }

        @Override
        public void onClickBackView(int position) {
            Log.d("swipe", String.format("onClickBackView %d", position));
        }

        @Override
        public void onDismiss(int[] reverseSortedPositions) {
            for (int position : reverseSortedPositions) {
                data.remove(position);
            }
            adapter.notifyDataSetChanged();
        }

    });

    swipeListView.setAdapter(adapter);

    reload();

    new ListAppTask().execute();

    progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(getString(R.string.loading));
    progressDialog.setCancelable(false);
    progressDialog.show();

}

From source file:net.named_data.nfd.FaceListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    @SuppressLint("InflateParams")
    View v = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_face_list_list_header, null);
    getListView().addHeaderView(v, null, false);
    getListView().setDivider(getResources().getDrawable(R.drawable.list_item_divider));

    // Get info unavailable view
    m_faceListInfoUnavailableView = v.findViewById(R.id.face_list_info_unavailable);

    // Get progress bar spinner view
    m_reloadingListProgressBar = (ProgressBar) v.findViewById(R.id.face_list_reloading_list_progress_bar);

    // Setup list view for deletion
    ListView listView = getListView();
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        @Override//from w ww . j a va 2  s .c  om
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            if (checked && id < 256) {
                getListView().setItemChecked(position, false);
                return;
            }
            if (checked)
                m_facesToDelete.add((int) id);
            else
                m_facesToDelete.remove((int) id);
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater menuInflater = mode.getMenuInflater();
            menuInflater.inflate(R.menu.menu_face_list_multiple_modal_menu, menu);
            return true;
        }

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

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_item_delete_face_item:
                G.Log("Requesting to delete " + String.valueOf(m_facesToDelete));

                // Delete selected faceIds
                m_faceDestroyAsyncTask = new FaceDestroyAsyncTask();
                m_faceDestroyAsyncTask.execute(m_facesToDelete);

                m_facesToDelete = new HashSet<>();
                mode.finish();
                return true;
            default:
                return false;
            }
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

        private HashSet<Integer> m_facesToDelete = new HashSet<>();
    });
}