Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b98a81f8 authored by Adam Powell's avatar Adam Powell
Browse files

Add support for optional titles in action modes

Optional titles will only be displayed in the CAB if they entirely fit
instead of ellipsizing.

Fixes bug 5821883

Change-Id: I0cfd6d4fd34a4fa9f520499d577706da30606811
parent 86574777
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -21935,12 +21935,14 @@ package android.view {
    method public java.lang.Object getTag();
    method public abstract java.lang.CharSequence getTitle();
    method public abstract void invalidate();
    method public boolean isTitleOptional();
    method public abstract void setCustomView(android.view.View);
    method public abstract void setSubtitle(java.lang.CharSequence);
    method public abstract void setSubtitle(int);
    method public void setTag(java.lang.Object);
    method public abstract void setTitle(java.lang.CharSequence);
    method public abstract void setTitle(int);
    method public void setTitleOptionalHint(boolean);
  }
  public static abstract interface ActionMode.Callback {
+6 −0
Original line number Diff line number Diff line
@@ -123,6 +123,12 @@ public class ExtractEditLayout extends LinearLayout {
            // Subtitle will not be shown.
        }

        @Override
        public boolean isTitleOptional() {
            // Not only is it optional, it will *never* be shown.
            return true;
        }

        @Override
        public void setCustomView(View view) {
            // Custom view is not supported here.
+26 −0
Original line number Diff line number Diff line
@@ -103,6 +103,32 @@ public abstract class ActionMode {
     */
    public abstract void setSubtitle(int resId);

    /**
     * Set whether or not the title/subtitle display for this action mode
     * is optional.
     *
     * <p>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.</p>
     *
     * <p>Note that this is merely a hint; the underlying implementation
     * may choose to ignore this setting under some circumstances.</p>
     *
     * @param titleOptional true if the title only presents optional information.
     */
    public void setTitleOptionalHint(boolean titleOptional) {
    }

    /**
     * @return true if this action mode considers the title and subtitle fields
     *         as optional. Optional titles may not be displayed to the user.
     */
    public boolean isTitleOptional() {
        return false;
    }

    /**
     * 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.
+2 −4
Original line number Diff line number Diff line
@@ -53,10 +53,8 @@ class SelectActionModeCallback implements ActionMode.Callback {
        mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_copy, menu);

        final Context context = mWebView.getContext();
        boolean allowText = context.getResources().getBoolean(
                com.android.internal.R.bool.config_allowActionMenuItemTextWithIcon);
        mode.setTitle(allowText ?
                context.getString(com.android.internal.R.string.textSelectionCABTitle) : null);
        mode.setTitle(context.getString(com.android.internal.R.string.textSelectionCABTitle));
        mode.setTitleOptionalHint(true);

        // If the action mode UI we're running in isn't capable of taking window focus
        // the user won't be able to type into the find on page UI. Disable this functionality.
+2 −2
Original line number Diff line number Diff line
@@ -10363,9 +10363,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            boolean allowText = getContext().getResources().getBoolean(
                    com.android.internal.R.bool.config_allowActionMenuItemTextWithIcon);

            mode.setTitle(allowText ?
                    mContext.getString(com.android.internal.R.string.textSelectionCABTitle) : null);
            mode.setTitle(mContext.getString(com.android.internal.R.string.textSelectionCABTitle));
            mode.setSubtitle(null);
            mode.setTitleOptionalHint(true);

            int selectAllIconId = 0; // No icon by default
            if (!allowText) {
Loading