public class

SupportActionModeWrapper

extends ActionMode

 java.lang.Object

androidx.appcompat.view.ActionMode

↳androidx.appcompat.view.SupportActionModeWrapper

Gradle dependencies

compile group: 'androidx.appcompat', name: 'appcompat', version: '1.6.0-alpha04'

  • groupId: androidx.appcompat
  • artifactId: appcompat
  • version: 1.6.0-alpha04

Artifact androidx.appcompat:appcompat:1.6.0-alpha04 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.appcompat:appcompat com.android.support:appcompat-v7

Androidx class mapping:

androidx.appcompat.view.SupportActionModeWrapper android.support.v7.view.SupportActionModeWrapper

Overview

Wraps a support ActionMode as a framework android.view.ActionMode.

Summary

Constructors
publicSupportActionModeWrapper(Context context, ActionMode supportActionMode)

Methods
public abstract voidfinish()

Finish and close this action mode.

public abstract ViewgetCustomView()

Returns the current custom view for this action mode.

public abstract MenugetMenu()

Returns the menu of actions that this action mode presents.

public abstract MenuInflatergetMenuInflater()

Returns a with the ActionMode's context.

public abstract java.lang.CharSequencegetSubtitle()

Returns the current subtitle of this action mode.

public java.lang.ObjectgetTag()

Retrieve the tag object associated with this ActionMode.

public abstract java.lang.CharSequencegetTitle()

Returns the current title of this action mode.

public booleangetTitleOptionalHint()

public abstract voidinvalidate()

Invalidate the action mode and refresh menu content.

public booleanisTitleOptional()

public abstract voidsetCustomView(View view)

Set a custom view for this action mode.

public abstract voidsetSubtitle(java.lang.CharSequence subtitle)

Set the subtitle of the action mode.

public abstract voidsetSubtitle(int resId)

Set the subtitle of the action mode.

public voidsetTag(java.lang.Object tag)

Set a tag object associated with this ActionMode.

public abstract voidsetTitle(java.lang.CharSequence title)

Set the title of the action mode.

public abstract voidsetTitle(int resId)

Set the title of the action mode.

public voidsetTitleOptionalHint(boolean titleOptional)

Set whether or not the title/subtitle display for this action mode is optional.

from ActionModeisUiFocusable
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public SupportActionModeWrapper(Context context, ActionMode supportActionMode)

Methods

public java.lang.Object getTag()

Retrieve the tag object associated with this ActionMode.

Like the tag available to views, this allows applications to associate arbitrary data with an ActionMode for later reference.

Returns:

Tag associated with this ActionMode

See also: ActionMode.setTag(Object)

public void setTag(java.lang.Object tag)

Set a tag object associated with this ActionMode.

Like the tag available to views, this allows applications to associate arbitrary data with an ActionMode for later reference.

Parameters:

tag: Tag to associate with this ActionMode

See also: ActionMode.getTag()

public abstract void setTitle(java.lang.CharSequence title)

Set the title of the action mode. This method will have no visible effect if a custom view has been set.

Parameters:

title: Title string to set

See also: ActionMode.setTitle(int), ActionMode.setCustomView(View)

public abstract void setSubtitle(java.lang.CharSequence subtitle)

Set the subtitle of the action mode. This method will have no visible effect if a custom view has been set.

Parameters:

subtitle: Subtitle string to set

See also: ActionMode.setSubtitle(int), ActionMode.setCustomView(View)

public abstract void invalidate()

Invalidate the action mode and refresh menu content. The mode's ActionMode.Callback will have its ActionMode.Callback.onPrepareActionMode(ActionMode, Menu) method called. If it returns true the menu will be scanned for updated content and any relevant changes will be reflected to the user.

public abstract void finish()

Finish and close this action mode. The action mode's ActionMode.Callback will have its ActionMode.Callback.onDestroyActionMode(ActionMode) method called.

public abstract Menu getMenu()

Returns the menu of actions that this action mode presents.

Returns:

The action mode's menu.

public abstract java.lang.CharSequence getTitle()

Returns the current title of this action mode.

Returns:

Title text

public abstract void setTitle(int resId)

Set the title of the action mode. This method will have no visible effect if a custom view has been set.

Parameters:

resId: Resource ID of a string to set as the title

See also: ActionMode.setTitle(CharSequence), ActionMode.setCustomView(View)

public abstract java.lang.CharSequence getSubtitle()

Returns the current subtitle of this action mode.

Returns:

Subtitle text

public abstract void setSubtitle(int resId)

Set the subtitle of the action mode. This method will have no visible effect if a custom view has been set.

Parameters:

resId: Resource ID of a string to set as the subtitle

See also: ActionMode.setSubtitle(CharSequence), ActionMode.setCustomView(View)

public abstract View getCustomView()

Returns the current custom view for this action mode.

Returns:

The current custom view

public abstract void setCustomView(View view)

Set a custom view for this action mode. The custom view will take the place of the title and subtitle. Useful for things like search boxes.

Parameters:

view: Custom view to use in place of the title/subtitle.

See also: ActionMode.setTitle(CharSequence), ActionMode.setSubtitle(CharSequence)

public abstract MenuInflater getMenuInflater()

Returns a with the ActionMode's context.

public boolean getTitleOptionalHint()

Returns:

true if this action mode has been given a hint to consider the title/subtitle display to be optional.

See also: ActionMode.setTitleOptionalHint(boolean), ActionMode.isTitleOptional()

public void setTitleOptionalHint(boolean titleOptional)

Set whether or not the title/subtitle display for this action mode is optional.

In many cases the supplied title for an action mode is merely meant to add context and is not strictly required for the action mode to be useful. If the title is optional, the system may choose to hide the title entirely rather than truncate it due to a lack of available space.

Note that this is merely a hint; the underlying implementation may choose to ignore this setting under some circumstances.

Parameters:

titleOptional: true if the title only presents optional information.

public boolean isTitleOptional()

Returns:

true if this action mode considers the title and subtitle fields as optional. Optional titles may not be displayed to the user.

Source

/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.appcompat.view;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX;

import android.content.Context;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;

import androidx.annotation.RestrictTo;
import androidx.appcompat.view.menu.MenuItemWrapperICS;
import androidx.appcompat.view.menu.MenuWrapperICS;
import androidx.collection.SimpleArrayMap;
import androidx.core.internal.view.SupportMenu;
import androidx.core.internal.view.SupportMenuItem;

import java.util.ArrayList;

/**
 * Wraps a support {@link androidx.appcompat.view.ActionMode} as a framework
 * {@link android.view.ActionMode}.
 *
 * @hide
 */
@RestrictTo(LIBRARY_GROUP_PREFIX)
public class SupportActionModeWrapper extends ActionMode {

    final Context mContext;
    final androidx.appcompat.view.ActionMode mWrappedObject;

    public SupportActionModeWrapper(Context context,
            androidx.appcompat.view.ActionMode supportActionMode) {
        mContext = context;
        mWrappedObject = supportActionMode;
    }

    @Override
    public Object getTag() {
        return mWrappedObject.getTag();
    }

    @Override
    public void setTag(Object tag) {
        mWrappedObject.setTag(tag);
    }

    @Override
    public void setTitle(CharSequence title) {
        mWrappedObject.setTitle(title);
    }

    @Override
    public void setSubtitle(CharSequence subtitle) {
        mWrappedObject.setSubtitle(subtitle);
    }

    @Override
    public void invalidate() {
        mWrappedObject.invalidate();
    }

    @Override
    public void finish() {
        mWrappedObject.finish();
    }

    @Override
    public Menu getMenu() {
        return new MenuWrapperICS(mContext, (SupportMenu) mWrappedObject.getMenu());
    }

    @Override
    public CharSequence getTitle() {
        return mWrappedObject.getTitle();
    }

    @Override
    public void setTitle(int resId) {
        mWrappedObject.setTitle(resId);
    }

    @Override
    public CharSequence getSubtitle() {
        return mWrappedObject.getSubtitle();
    }

    @Override
    public void setSubtitle(int resId) {
        mWrappedObject.setSubtitle(resId);
    }

    @Override
    public View getCustomView() {
        return mWrappedObject.getCustomView();
    }

    @Override
    public void setCustomView(View view) {
        mWrappedObject.setCustomView(view);
    }

    @Override
    public MenuInflater getMenuInflater() {
        return mWrappedObject.getMenuInflater();
    }

    @Override
    public boolean getTitleOptionalHint() {
        return mWrappedObject.getTitleOptionalHint();
    }

    @Override
    public void setTitleOptionalHint(boolean titleOptional) {
        mWrappedObject.setTitleOptionalHint(titleOptional);
    }

    @Override
    public boolean isTitleOptional() {
        return mWrappedObject.isTitleOptional();
    }

    /**
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP_PREFIX)
    public static class CallbackWrapper implements androidx.appcompat.view.ActionMode.Callback {
        final Callback mWrappedCallback;
        final Context mContext;

        final ArrayList<SupportActionModeWrapper> mActionModes;
        final SimpleArrayMap<Menu, Menu> mMenus;

        public CallbackWrapper(Context context, Callback supportCallback) {
            mContext = context;
            mWrappedCallback = supportCallback;
            mActionModes = new ArrayList<>();
            mMenus = new SimpleArrayMap<>();
        }

        @Override
        public boolean onCreateActionMode(androidx.appcompat.view.ActionMode mode, Menu menu) {
            return mWrappedCallback.onCreateActionMode(getActionModeWrapper(mode),
                    getMenuWrapper(menu));
        }

        @Override
        public boolean onPrepareActionMode(androidx.appcompat.view.ActionMode mode, Menu menu) {
            return mWrappedCallback.onPrepareActionMode(getActionModeWrapper(mode),
                    getMenuWrapper(menu));
        }

        @Override
        public boolean onActionItemClicked(androidx.appcompat.view.ActionMode mode,
                android.view.MenuItem item) {
            return mWrappedCallback.onActionItemClicked(getActionModeWrapper(mode),
                    new MenuItemWrapperICS(mContext, (SupportMenuItem) item));
        }

        @Override
        public void onDestroyActionMode(androidx.appcompat.view.ActionMode mode) {
            mWrappedCallback.onDestroyActionMode(getActionModeWrapper(mode));
        }

        private Menu getMenuWrapper(Menu menu) {
            Menu wrapper = mMenus.get(menu);
            if (wrapper == null) {
                wrapper = new MenuWrapperICS(mContext, (SupportMenu) menu);
                mMenus.put(menu, wrapper);
            }
            return wrapper;
        }

        public ActionMode getActionModeWrapper(androidx.appcompat.view.ActionMode mode) {
            // First see if we already have a wrapper for this mode
            for (int i = 0, count = mActionModes.size(); i < count; i++) {
                SupportActionModeWrapper wrapper = mActionModes.get(i);
                if (wrapper != null && wrapper.mWrappedObject == mode) {
                    // We've found a wrapper, return it
                    return wrapper;
                }
            }

            // If we reach here then we haven't seen this mode before. Create a new wrapper and
            // add it to our collection
            SupportActionModeWrapper wrapper = new SupportActionModeWrapper(mContext, mode);
            mActionModes.add(wrapper);
            return wrapper;
        }
    }
}