Java Code Examples for android.view.ActionMode#Callback2

The following examples show how to use android.view.ActionMode#Callback2 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FloatingActionMode.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public FloatingActionMode(Context context, ActionMode.Callback2 callback, View originatingView, FloatingToolbar floatingToolbar) {
    mContext = context;
    mCallback = callback;

    PopupMenu p = new PopupMenu(context, null);
    mMenu = p.getMenu();
    setType(ActionMode.TYPE_FLOATING);
    p.setOnMenuItemClickListener(menuItem -> mCallback.onActionItemClicked(FloatingActionMode.this, menuItem));
    mContentRect = new Rect();
    mContentRectOnScreen = new Rect();
    mPreviousContentRectOnScreen = new Rect();
    mViewPositionOnScreen = new int[2];
    mPreviousViewPositionOnScreen = new int[2];
    mRootViewPositionOnScreen = new int[2];
    mViewRectOnScreen = new Rect();
    mPreviousViewRectOnScreen = new Rect();
    mScreenRect = new Rect();
    mOriginatingView = originatingView;
    mOriginatingView.getLocationOnScreen(mViewPositionOnScreen);
    mBottomAllowance = AndroidUtilities.dp(20);
    mDisplaySize = new Point();
    setFloatingToolbar(floatingToolbar);
}
 
Example 2
Source File: FloatingActionMode.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public FloatingActionMode(Context context, ActionMode.Callback2 callback, View originatingView, FloatingToolbar floatingToolbar) {
    mContext = context;
    mCallback = callback;

    PopupMenu p = new PopupMenu(context, null);
    mMenu = p.getMenu();
    setType(ActionMode.TYPE_FLOATING);
    p.setOnMenuItemClickListener(menuItem -> mCallback.onActionItemClicked(FloatingActionMode.this, menuItem));
    mContentRect = new Rect();
    mContentRectOnScreen = new Rect();
    mPreviousContentRectOnScreen = new Rect();
    mViewPositionOnScreen = new int[2];
    mPreviousViewPositionOnScreen = new int[2];
    mRootViewPositionOnScreen = new int[2];
    mViewRectOnScreen = new Rect();
    mPreviousViewRectOnScreen = new Rect();
    mScreenRect = new Rect();
    mOriginatingView = originatingView;
    mOriginatingView.getLocationOnScreen(mViewPositionOnScreen);
    mBottomAllowance = AndroidUtilities.dp(20);
    mDisplaySize = new Point();
    setFloatingToolbar(floatingToolbar);
}
 
Example 3
Source File: TextSelectionActivity.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(23)
private void initData() {
    mCallback2 = new ActionMode.Callback2() {
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            if (inflater == null) {
                return false;
            }
            inflater.inflate(R.menu.actionmode_menu, menu);
            return true;
        }

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

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            Toast.makeText(TextSelectionActivity.this, item.getTitle(), Toast.LENGTH_LONG).show();
            mode.finish();
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {

        }

        // 控制这个浮动菜单的位置
        @Override
        public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
            super.onGetContentRect(mode, view, outRect);
        }

    };
    this.mTestTV.setCustomSelectionActionModeCallback(mCallback2);
}
 
Example 4
Source File: EditTextBoldCursor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
    if (mWrapped instanceof ActionMode.Callback2) {
        ((ActionMode.Callback2) mWrapped).onGetContentRect(mode, view, outRect);
    } else {
        super.onGetContentRect(mode, view, outRect);
    }
}
 
Example 5
Source File: EditTextBoldCursor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
    if (mWrapped instanceof ActionMode.Callback2) {
        ((ActionMode.Callback2) mWrapped).onGetContentRect(mode, view, outRect);
    } else {
        super.onGetContentRect(mode, view, outRect);
    }
}