FrameworkActionBarpublic class FrameworkActionBar extends BridgeActionBar Creates the ActionBar as done by the framework. |
Fields Summary |
---|
private static final String | LAYOUT_ATTR_NAME | private FrameworkActionBarWrapper | mActionBar | private android.view.ViewGroup | mMeasureParent |
Constructors Summary |
---|
public FrameworkActionBar(com.android.layoutlib.bridge.android.BridgeContext context, com.android.ide.common.rendering.api.SessionParams params, android.view.ViewGroup parentView)Inflate the action bar and attach it to {@code parentView}
super(context, params, parentView);
View decorContent = getDecorContent();
mActionBar = FrameworkActionBarWrapper.getActionBarWrapper(context, getCallBack(),
decorContent);
FrameLayout contentRoot = (FrameLayout) mEnclosingLayout.findViewById(android.R.id.content);
// If something went wrong and we were not able to initialize the content root,
// just add a frame layout inside this and return.
if (contentRoot == null) {
contentRoot = new FrameLayout(context);
setMatchParent(contentRoot);
mEnclosingLayout.addView(contentRoot);
setContentRoot(contentRoot);
} else {
setContentRoot(contentRoot);
setupActionBar();
mActionBar.inflateMenus();
}
|
Methods Summary |
---|
public void | createMenuPopup()Creates a Popup and adds it to the content frame. It also adds another {@link FrameLayout} to
the content frame which shall serve as the new content root.
if (!isOverflowPopupNeeded()) {
return;
}
DisplayMetrics metrics = mBridgeContext.getMetrics();
MenuBuilder menu = mActionBar.getMenuBuilder();
OverflowMenuAdapter adapter = new OverflowMenuAdapter(menu, mActionBar.getPopupContext());
ListView listView = new ListView(mActionBar.getPopupContext(), null,
R.attr.dropDownListViewStyle);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
measureContentWidth(adapter), LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
if (mActionBar.isSplit()) {
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.bottomMargin = getActionBarHeight() + mActionBar.getMenuPopupMargin();
} else {
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.topMargin = getActionBarHeight() + mActionBar.getMenuPopupMargin();
}
layoutParams.setMarginEnd(getPixelValue("5dp", metrics));
listView.setLayoutParams(layoutParams);
listView.setAdapter(adapter);
final TypedArray a = mActionBar.getPopupContext().obtainStyledAttributes(null,
R.styleable.PopupWindow, R.attr.popupMenuStyle, 0);
listView.setBackground(a.getDrawable(R.styleable.PopupWindow_popupBackground));
listView.setDivider(a.getDrawable(R.attr.actionBarDivider));
a.recycle();
listView.setElevation(mActionBar.getMenuPopupElevation());
mEnclosingLayout.addView(listView);
| private int | getActionBarHeight()
RenderResources resources = mBridgeContext.getRenderResources();
DisplayMetrics metrics = mBridgeContext.getMetrics();
ResourceValue value = resources.findItemInTheme("actionBarSize", true);
// resolve it
value = resources.resolveResValue(value);
if (value != null) {
// get the numerical value, if available
TypedValue typedValue = ResourceHelper.getValue("actionBarSize", value.getValue(),
true);
if (typedValue != null) {
// compute the pixel value based on the display metrics
return (int) typedValue.getDimension(metrics);
}
}
return 0;
| protected com.android.ide.common.rendering.api.ResourceValue | getLayoutResource(com.android.layoutlib.bridge.android.BridgeContext context)
ResourceValue layoutName =
context.getRenderResources().findItemInTheme(LAYOUT_ATTR_NAME, true);
if (layoutName != null) {
// We may need to resolve the reference obtained.
layoutName = context.getRenderResources().findResValue(layoutName.getValue(),
layoutName.isFramework());
}
if (layoutName == null) {
throw new InflateException("Unable to find action bar layout (" + LAYOUT_ATTR_NAME
+ ") in the current theme.");
}
return layoutName;
| static int | getPixelValue(java.lang.String value, android.util.DisplayMetrics metrics)
TypedValue typedValue = ResourceHelper.getValue(null, value, false /*requireUnit*/);
return (int) typedValue.getDimension(metrics);
| private boolean | isOverflowPopupNeeded()
boolean needed = mActionBar.isOverflowPopupNeeded();
if (!needed) {
return false;
}
// Copied from android.widget.ActionMenuPresenter.updateMenuView()
ArrayList<MenuItemImpl> menus = mActionBar.getMenuBuilder().getNonActionItems();
ActionMenuPresenter presenter = mActionBar.getActionMenuPresenter();
if (presenter == null) {
throw new RuntimeException("Failed to create a Presenter for Action Bar Menus.");
}
if (presenter.isOverflowReserved() &&
menus != null) {
final int count = menus.size();
if (count == 1) {
needed = !menus.get(0).isActionViewExpanded();
} else {
needed = count > 0;
}
}
return needed;
| private int | measureContentWidth(android.widget.ListAdapter adapter)
// Menus don't tend to be long, so this is more sane than it looks.
int maxWidth = 0;
View itemView = null;
int itemType = 0;
Context context = mActionBar.getPopupContext();
final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final int count = adapter.getCount();
for (int i = 0; i < count; i++) {
final int positionType = adapter.getItemViewType(i);
if (positionType != itemType) {
itemType = positionType;
itemView = null;
}
if (mMeasureParent == null) {
mMeasureParent = new FrameLayout(context);
}
itemView = adapter.getView(i, itemView, mMeasureParent);
itemView.measure(widthMeasureSpec, heightMeasureSpec);
final int itemWidth = itemView.getMeasuredWidth();
int popupMaxWidth = Math.max(mBridgeContext.getMetrics().widthPixels / 2,
context.getResources().getDimensionPixelSize(R.dimen.config_prefDialogWidth));
if (itemWidth >= popupMaxWidth) {
return popupMaxWidth;
} else if (itemWidth > maxWidth) {
maxWidth = itemWidth;
}
}
return maxWidth;
| protected void | setHomeAsUp(boolean homeAsUp)
mActionBar.setHomeAsUp(homeAsUp);
| protected void | setIcon(java.lang.String icon)
mActionBar.setIcon(icon);
| protected void | setSubtitle(java.lang.CharSequence subtitle)
mActionBar.setSubTitle(subtitle);
| protected void | setTitle(java.lang.CharSequence title)
mActionBar.setTitle(title);
| protected void | setupActionBar()
super.setupActionBar();
mActionBar.setupActionBar();
|
|