Source code
package android.support.v7.internal.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.support.v7.appcompat.R;
import android.support.v7.internal.VersionUtils;
import android.support.v7.view.ActionMode;
import android.support.v7.view.ActionMode.Callback;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
public class ActionBarContainer extends FrameLayout {
private View mActionBarView;
Drawable mBackground;
private View mContextView;
private int mHeight;
boolean mIsSplit;
boolean mIsStacked;
private boolean mIsTransitioning;
Drawable mSplitBackground;
Drawable mStackedBackground;
private View mTabContainer;
public ActionBarContainer(Context context) {
this(context, null);
}
public ActionBarContainer(Context context, AttributeSet attrs) {
boolean z = true;
super(context, attrs);
setBackgroundDrawable(VersionUtils.isAtLeastL() ? new ActionBarBackgroundDrawableV21(this) : new ActionBarBackgroundDrawable(this));
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar);
this.mBackground = a.getDrawable(R.styleable.ActionBar_background);
this.mStackedBackground = a.getDrawable(R.styleable.ActionBar_backgroundStacked);
this.mHeight = a.getDimensionPixelSize(R.styleable.ActionBar_height, -1);
if (getId() == R.id.split_action_bar) {
this.mIsSplit = true;
this.mSplitBackground = a.getDrawable(R.styleable.ActionBar_backgroundSplit);
}
a.recycle();
if (this.mIsSplit) {
if (this.mSplitBackground != null) {
z = false;
}
} else if (!(this.mBackground == null && this.mStackedBackground == null)) {
z = false;
}
setWillNotDraw(z);
}
public void onFinishInflate() {
super.onFinishInflate();
this.mActionBarView = findViewById(R.id.action_bar);
this.mContextView = findViewById(R.id.action_context_bar);
}
public void setPrimaryBackground(Drawable bg) {
boolean z = true;
if (this.mBackground != null) {
this.mBackground.setCallback(null);
unscheduleDrawable(this.mBackground);
}
this.mBackground = bg;
if (bg != null) {
bg.setCallback(this);
if (this.mActionBarView != null) {
this.mBackground.setBounds(this.mActionBarView.getLeft(), this.mActionBarView.getTop(), this.mActionBarView.getRight(), this.mActionBarView.getBottom());
}
}
if (this.mIsSplit) {
if (this.mSplitBackground != null) {
z = false;
}
} else if (!(this.mBackground == null && this.mStackedBackground == null)) {
z = false;
}
setWillNotDraw(z);
invalidate();
}
public void setStackedBackground(Drawable bg) {
boolean z = true;
if (this.mStackedBackground != null) {
this.mStackedBackground.setCallback(null);
unscheduleDrawable(this.mStackedBackground);
}
this.mStackedBackground = bg;
if (bg != null) {
bg.setCallback(this);
if (this.mIsStacked && this.mStackedBackground != null) {
this.mStackedBackground.setBounds(this.mTabContainer.getLeft(), this.mTabContainer.getTop(), this.mTabContainer.getRight(), this.mTabContainer.getBottom());
}
}
if (this.mIsSplit) {
if (this.mSplitBackground != null) {
z = false;
}
} else if (!(this.mBackground == null && this.mStackedBackground == null)) {
z = false;
}
setWillNotDraw(z);
invalidate();
}
public void setSplitBackground(Drawable bg) {
boolean z = true;
if (this.mSplitBackground != null) {
this.mSplitBackground.setCallback(null);
unscheduleDrawable(this.mSplitBackground);
}
this.mSplitBackground = bg;
if (bg != null) {
bg.setCallback(this);
if (this.mIsSplit && this.mSplitBackground != null) {
this.mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
}
}
if (this.mIsSplit) {
if (this.mSplitBackground != null) {
z = false;
}
} else if (!(this.mBackground == null && this.mStackedBackground == null)) {
z = false;
}
setWillNotDraw(z);
invalidate();
}
public void setVisibility(int visibility) {
boolean isVisible;
super.setVisibility(visibility);
if (visibility == 0) {
isVisible = true;
} else {
isVisible = false;
}
if (this.mBackground != null) {
this.mBackground.setVisible(isVisible, false);
}
if (this.mStackedBackground != null) {
this.mStackedBackground.setVisible(isVisible, false);
}
if (this.mSplitBackground != null) {
this.mSplitBackground.setVisible(isVisible, false);
}
}
protected boolean verifyDrawable(Drawable who) {
return (who == this.mBackground && !this.mIsSplit) || ((who == this.mStackedBackground && this.mIsStacked) || ((who == this.mSplitBackground && this.mIsSplit) || super.verifyDrawable(who)));
}
protected void drawableStateChanged() {
super.drawableStateChanged();
if (this.mBackground != null && this.mBackground.isStateful()) {
this.mBackground.setState(getDrawableState());
}
if (this.mStackedBackground != null && this.mStackedBackground.isStateful()) {
this.mStackedBackground.setState(getDrawableState());
}
if (this.mSplitBackground != null && this.mSplitBackground.isStateful()) {
this.mSplitBackground.setState(getDrawableState());
}
}
public void jumpDrawablesToCurrentState() {
if (VERSION.SDK_INT >= 11) {
super.jumpDrawablesToCurrentState();
if (this.mBackground != null) {
this.mBackground.jumpToCurrentState();
}
if (this.mStackedBackground != null) {
this.mStackedBackground.jumpToCurrentState();
}
if (this.mSplitBackground != null) {
this.mSplitBackground.jumpToCurrentState();
}
}
}
public void setTransitioning(boolean isTransitioning) {
this.mIsTransitioning = isTransitioning;
setDescendantFocusability(isTransitioning ? 393216 : 262144);
}
public boolean onInterceptTouchEvent(MotionEvent ev) {
return this.mIsTransitioning || super.onInterceptTouchEvent(ev);
}
public boolean onTouchEvent(MotionEvent ev) {
super.onTouchEvent(ev);
return true;
}
public void setTabContainer(ScrollingTabContainerView tabView) {
if (this.mTabContainer != null) {
removeView(this.mTabContainer);
}
this.mTabContainer = tabView;
if (tabView != null) {
addView(tabView);
LayoutParams lp = tabView.getLayoutParams();
lp.width = -1;
lp.height = -2;
tabView.setAllowCollapse(false);
}
}
public View getTabContainer() {
return this.mTabContainer;
}
public ActionMode startActionModeForChild(View child, Callback callback) {
return null;
}
public android.view.ActionMode startActionModeForChild(View originalView, android.view.ActionMode.Callback callback) {
return null;
}
private boolean isCollapsed(View view) {
return view == null || view.getVisibility() == 8 || view.getMeasuredHeight() == 0;
}
private int getMeasuredHeightWithMargins(View view) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) view.getLayoutParams();
return (view.getMeasuredHeight() + lp.topMargin) + lp.bottomMargin;
}
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (this.mActionBarView == null && MeasureSpec.getMode(heightMeasureSpec) == Integer.MIN_VALUE && this.mHeight >= 0) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(Math.min(this.mHeight, MeasureSpec.getSize(heightMeasureSpec)), Integer.MIN_VALUE);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (this.mActionBarView != null) {
int mode = MeasureSpec.getMode(heightMeasureSpec);
if (this.mTabContainer != null && this.mTabContainer.getVisibility() != 8 && mode != 1073741824) {
int topMarginForTabs;
if (!isCollapsed(this.mActionBarView)) {
topMarginForTabs = getMeasuredHeightWithMargins(this.mActionBarView);
} else if (isCollapsed(this.mContextView)) {
topMarginForTabs = 0;
} else {
topMarginForTabs = getMeasuredHeightWithMargins(this.mContextView);
}
setMeasuredDimension(getMeasuredWidth(), Math.min(getMeasuredHeightWithMargins(this.mTabContainer) + topMarginForTabs, mode == Integer.MIN_VALUE ? MeasureSpec.getSize(heightMeasureSpec) : ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED));
}
}
}
public void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
View tabContainer = this.mTabContainer;
boolean hasTabs = (tabContainer == null || tabContainer.getVisibility() == 8) ? false : true;
if (!(tabContainer == null || tabContainer.getVisibility() == 8)) {
int containerHeight = getMeasuredHeight();
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) tabContainer.getLayoutParams();
tabContainer.layout(l, (containerHeight - tabContainer.getMeasuredHeight()) - lp.bottomMargin, r, containerHeight - lp.bottomMargin);
}
boolean needsInvalidate = false;
if (!this.mIsSplit) {
if (this.mBackground != null) {
if (this.mActionBarView.getVisibility() == 0) {
this.mBackground.setBounds(this.mActionBarView.getLeft(), this.mActionBarView.getTop(), this.mActionBarView.getRight(), this.mActionBarView.getBottom());
} else if (this.mContextView == null || this.mContextView.getVisibility() != 0) {
this.mBackground.setBounds(0, 0, 0, 0);
} else {
this.mBackground.setBounds(this.mContextView.getLeft(), this.mContextView.getTop(), this.mContextView.getRight(), this.mContextView.getBottom());
}
needsInvalidate = true;
}
this.mIsStacked = hasTabs;
if (hasTabs && this.mStackedBackground != null) {
this.mStackedBackground.setBounds(tabContainer.getLeft(), tabContainer.getTop(), tabContainer.getRight(), tabContainer.getBottom());
needsInvalidate = true;
}
} else if (this.mSplitBackground != null) {
this.mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
needsInvalidate = true;
}
if (needsInvalidate) {
invalidate();
}
}
}