Merge "Add support for optional titles in action modes"

This commit is contained in:
Adam Powell
2012-02-24 17:00:37 -08:00
committed by Android (Google) Code Review
8 changed files with 83 additions and 8 deletions

View File

@@ -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 {

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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) {

View File

@@ -747,6 +747,16 @@ public class ActionBarImpl extends ActionBar {
return mContextView.getSubtitle();
}
@Override
public void setTitleOptionalHint(boolean titleOptional) {
mContextView.setTitleOptional(titleOptional);
}
@Override
public boolean isTitleOptional() {
return mContextView.isTitleOptional();
}
@Override
public View getCustomView() {
return mCustomView != null ? mCustomView.get() : null;

View File

@@ -71,6 +71,16 @@ public class StandaloneActionMode extends ActionMode implements MenuBuilder.Call
setSubtitle(mContext.getString(resId));
}
@Override
public void setTitleOptionalHint(boolean titleOptional) {
mContextView.setTitleOptional(titleOptional);
}
@Override
public boolean isTitleOptional() {
return mContextView.isTitleOptional();
}
@Override
public void setCustomView(View view) {
mContextView.setCustomView(view);

View File

@@ -56,6 +56,7 @@ public class ActionBarContextView extends AbsActionBarView implements AnimatorLi
private int mTitleStyleRes;
private int mSubtitleStyleRes;
private Drawable mSplitBackground;
private boolean mTitleOptional;
private Animator mCurrentAnimation;
private boolean mAnimateInOnLayout;
@@ -354,7 +355,18 @@ public class ActionBarContextView extends AbsActionBarView implements AnimatorLi
}
if (mTitleLayout != null && mCustomView == null) {
availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0);
if (mTitleOptional) {
final int titleWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
mTitleLayout.measure(titleWidthSpec, childSpecHeight);
final int titleWidth = mTitleLayout.getMeasuredWidth();
final boolean titleFits = titleWidth <= availableWidth;
if (titleFits) {
availableWidth -= titleWidth;
}
mTitleLayout.setVisibility(titleFits ? VISIBLE : GONE);
} else {
availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0);
}
}
if (mCustomView != null) {
@@ -460,7 +472,7 @@ public class ActionBarContextView extends AbsActionBarView implements AnimatorLi
}
}
if (mTitleLayout != null && mCustomView == null) {
if (mTitleLayout != null && mCustomView == null && mTitleLayout.getVisibility() != GONE) {
x += positionChild(mTitleLayout, x, y, contentHeight);
}
@@ -512,4 +524,15 @@ public class ActionBarContextView extends AbsActionBarView implements AnimatorLi
super.onInitializeAccessibilityEvent(event);
}
}
public void setTitleOptional(boolean titleOptional) {
if (titleOptional != mTitleOptional) {
requestLayout();
}
mTitleOptional = titleOptional;
}
public boolean isTitleOptional() {
return mTitleOptional;
}
}