ActionBarSherlock 4.0.2

This commit is contained in:
Dominik
2012-04-20 12:14:21 +02:00
parent 784c3156df
commit da96aacf55
69 changed files with 2922 additions and 180 deletions

View File

@@ -71,6 +71,8 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu
private MenuBuilder mMenu;
/** Map between native options items and sherlock items. */
protected HashMap<android.view.MenuItem, MenuItemImpl> mNativeItemMap;
/** Indication of a long-press on the hardware menu key. */
private boolean mMenuKeyIsLongPress = false;
/** Parent view of the window decoration (action bar, mode, etc.). */
private ViewGroup mDecor;
@@ -318,6 +320,10 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu
public boolean dispatchPrepareOptionsMenu(android.view.Menu menu) {
if (DEBUG) Log.d(TAG, "[dispatchPrepareOptionsMenu] android.view.Menu: " + menu);
if (mActionMode != null) {
return false;
}
mMenuIsPrepared = false;
if (!preparePanel()) {
return false;
@@ -416,20 +422,27 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu
}
}
if (keyCode == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP && isReservingOverflow()) {
if (mActionMode == null) {
if (wActionBar.isOverflowMenuShowing()) {
wActionBar.hideOverflowMenu();
} else {
wActionBar.showOverflowMenu();
boolean result = false;
if (keyCode == KeyEvent.KEYCODE_MENU && isReservingOverflow()) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.isLongPress()) {
mMenuKeyIsLongPress = true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
if (!mMenuKeyIsLongPress) {
if (mActionMode == null) {
if (wActionBar.isOverflowMenuShowing()) {
wActionBar.hideOverflowMenu();
} else {
wActionBar.showOverflowMenu();
}
}
result = true;
}
mMenuKeyIsLongPress = false;
}
if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning true");
return true;
}
if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning false");
return false;
if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning " + result);
return result;
}
@@ -964,7 +977,7 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu
@Override
public void run() {
//Invalidate if the panel menu hasn't been created before this.
if (mMenu == null) {
if (!mActivity.isFinishing() && mMenu == null) {
dispatchInvalidateOptionsMenu();
}
}

View File

@@ -314,5 +314,15 @@ public class ActionBarSherlockNative extends ActionBarSherlock {
public MenuInflater getMenuInflater() {
return ActionBarSherlockNative.this.getMenuInflater();
}
@Override
public void setTag(Object tag) {
mActionMode.setTag(tag);
}
@Override
public Object getTag() {
return mActionMode.getTag();
}
}
}

View File

@@ -335,6 +335,12 @@ public class ActionBarWrapper extends ActionBar implements android.app.ActionBar
@Override
public void onTabSelected(android.app.ActionBar.Tab tab, android.app.FragmentTransaction ft) {
if (mListener != null) {
if (mFragmentTransaction == null && mActivity instanceof SherlockFragmentActivity) {
mFragmentTransaction = ((SherlockFragmentActivity)mActivity).getSupportFragmentManager().beginTransaction()
.disallowAddToBackStack();
}
mListener.onTabSelected(this, mFragmentTransaction);
if (mFragmentTransaction != null) {

View File

@@ -947,7 +947,7 @@ public final class AnimatorSet extends Animator {
public Node clone() {
try {
Node node = (Node) super.clone();
node.animation = (Animator) animation.clone();
node.animation = animation.clone();
return node;
} catch (CloneNotSupportedException e) {
throw new AssertionError();

View File

@@ -256,7 +256,7 @@ public class PropertyValuesHolder implements Cloneable {
else {
PropertyValuesHolder pvh = new PropertyValuesHolder(propertyName);
pvh.mKeyframeSet = keyframeSet;
pvh.mValueType = ((Keyframe)values[0]).getType();
pvh.mValueType = values[0].getType();
return pvh;
}
}
@@ -336,9 +336,9 @@ public class PropertyValuesHolder implements Cloneable {
public void setKeyframes(Keyframe... values) {
int numKeyframes = values.length;
Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)];
mValueType = ((Keyframe)values[0]).getType();
mValueType = values[0].getType();
for (int i = 0; i < numKeyframes; ++i) {
keyframes[i] = (Keyframe)values[i];
keyframes[i] = values[i];
}
mKeyframeSet = new KeyframeSet(keyframes);
}

View File

@@ -458,7 +458,7 @@ public class ValueAnimator extends Animator {
mValues = values;
mValuesMap = new HashMap<String, PropertyValuesHolder>(numValues);
for (int i = 0; i < numValues; ++i) {
PropertyValuesHolder valuesHolder = (PropertyValuesHolder) values[i];
PropertyValuesHolder valuesHolder = values[i];
mValuesMap.put(valuesHolder.getPropertyName(), valuesHolder);
}
// New property/values/target should cause re-initialization prior to starting

View File

@@ -0,0 +1,41 @@
package com.actionbarsherlock.internal.nineoldandroids.widget;
import android.content.Context;
import android.widget.HorizontalScrollView;
import com.actionbarsherlock.internal.nineoldandroids.view.animation.AnimatorProxy;
public class NineHorizontalScrollView extends HorizontalScrollView {
private final AnimatorProxy mProxy;
public NineHorizontalScrollView(Context context) {
super(context);
mProxy = AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(this) : null;
}
@Override
public void setVisibility(int visibility) {
if (mProxy != null) {
if (visibility == GONE) {
clearAnimation();
} else if (visibility == VISIBLE) {
setAnimation(mProxy);
}
}
super.setVisibility(visibility);
}
public float getAlpha() {
if (AnimatorProxy.NEEDS_PROXY) {
return mProxy.getAlpha();
} else {
return super.getAlpha();
}
}
public void setAlpha(float alpha) {
if (AnimatorProxy.NEEDS_PROXY) {
mProxy.setAlpha(alpha);
} else {
super.setAlpha(alpha);
}
}
}

View File

@@ -130,7 +130,13 @@ public class ActionMenuPresenter extends BaseMenuPresenter
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB);
} else {
return !ViewConfiguration.get(context).hasPermanentMenuKey();
return !HasPermanentMenuKey.get(context);
}
}
private static class HasPermanentMenuKey {
public static boolean get(Context context) {
return ViewConfiguration.get(context).hasPermanentMenuKey();
}
}
@@ -299,7 +305,7 @@ public class ActionMenuPresenter extends BaseMenuPresenter
*/
public boolean showOverflowMenu() {
if (mReserveOverflow && !isOverflowMenuShowing() && mMenu != null && mMenuView != null &&
mPostedOpenRunnable == null) {
mPostedOpenRunnable == null && !mMenu.getNonActionItems().isEmpty()) {
OverflowPopup popup = new OverflowPopup(mContext, mMenu, mOverflowButton, true);
mPostedOpenRunnable = new OpenOverflowRunnable(popup);
// Post this for later; we might still need a layout for the anchor to be right.

View File

@@ -417,9 +417,9 @@ public class ActionMenuView extends IcsLinearLayout implements MenuBuilder.ItemI
final int size = v.getMeasuredWidth() + p.leftMargin + p.rightMargin;
//UNUSED nonOverflowWidth += size;
widthRemaining -= size;
if (hasDividerBeforeChildAt(i)) {
//if (hasDividerBeforeChildAt(i)) {
//UNUSED nonOverflowWidth += dividerWidth;
}
//}
nonOverflowCount++;
}
}

View File

@@ -9,11 +9,12 @@ import com.actionbarsherlock.view.ActionProvider;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SubMenu;
public class MenuItemWrapper implements MenuItem, android.view.MenuItem.OnMenuItemClickListener, android.view.MenuItem.OnActionExpandListener {
public class MenuItemWrapper implements MenuItem, android.view.MenuItem.OnMenuItemClickListener {
private final android.view.MenuItem mNativeItem;
private SubMenu mSubMenu = null;
private OnMenuItemClickListener mMenuItemClickListener = null;
private OnActionExpandListener mActionExpandListener = null;
private android.view.MenuItem.OnActionExpandListener mNativeActionExpandListener = null;
public MenuItemWrapper(android.view.MenuItem nativeItem) {
@@ -262,24 +263,30 @@ public class MenuItemWrapper implements MenuItem, android.view.MenuItem.OnMenuIt
@Override
public MenuItem setOnActionExpandListener(OnActionExpandListener listener) {
mActionExpandListener = listener;
//Register ourselves as the listener to proxy
mNativeItem.setOnActionExpandListener(this);
if (mNativeActionExpandListener == null) {
mNativeActionExpandListener = new android.view.MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(android.view.MenuItem menuItem) {
if (mActionExpandListener != null) {
return mActionExpandListener.onMenuItemActionExpand(MenuItemWrapper.this);
}
return false;
}
@Override
public boolean onMenuItemActionCollapse(android.view.MenuItem menuItem) {
if (mActionExpandListener != null) {
return mActionExpandListener.onMenuItemActionCollapse(MenuItemWrapper.this);
}
return false;
}
};
//Register our inner-class as the listener to proxy method calls
mNativeItem.setOnActionExpandListener(mNativeActionExpandListener);
}
return this;
}
@Override
public boolean onMenuItemActionCollapse(android.view.MenuItem item) {
if (mActionExpandListener != null) {
return mActionExpandListener.onMenuItemActionCollapse(this);
}
return false;
}
@Override
public boolean onMenuItemActionExpand(android.view.MenuItem item) {
if (mActionExpandListener != null) {
return mActionExpandListener.onMenuItemActionExpand(this);
}
return false;
}
}

View File

@@ -15,6 +15,7 @@ public class MenuMule implements Menu {
private final com.actionbarsherlock.view.Menu mMenu;
public boolean mDispatchShow = false;
public MenuMule(com.actionbarsherlock.view.Menu menu) {
mMenu = menu;

View File

@@ -132,7 +132,7 @@ public class ActionBarView extends AbsActionBarView {
private SpinnerAdapter mSpinnerAdapter;
private OnNavigationListener mCallback;
private Runnable mTabSelector;
//UNUSED private Runnable mTabSelector;
private ExpandedActionViewMenuPresenter mExpandedMenuPresenter;
View mExpandedActionView;
@@ -250,7 +250,7 @@ public class ActionBarView extends AbsActionBarView {
final int customNavId = a.getResourceId(R.styleable.SherlockActionBar_customNavigationLayout, 0);
if (customNavId != 0) {
mCustomNavView = (View) inflater.inflate(customNavId, this, false);
mCustomNavView = inflater.inflate(customNavId, this, false);
mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
}
@@ -383,7 +383,7 @@ public class ActionBarView extends AbsActionBarView {
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
removeCallbacks(mTabSelector);
//UNUSED removeCallbacks(mTabSelector);
if (mActionMenuPresenter != null) {
mActionMenuPresenter.hideOverflowMenu();
mActionMenuPresenter.hideSubMenus();
@@ -825,7 +825,7 @@ public class ActionBarView extends AbsActionBarView {
this, false);
mTitleView = (TextView) mTitleLayout.findViewById(R.id.abs__action_bar_title);
mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.abs__action_bar_subtitle);
mTitleUpView = (View) mTitleLayout.findViewById(R.id.abs__up);
mTitleUpView = mTitleLayout.findViewById(R.id.abs__up);
mTitleLayout.setOnClickListener(mUpClickListener);

View File

@@ -18,6 +18,10 @@ public class CapitalizingTextView extends TextView {
private boolean mAllCaps;
public CapitalizingTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CapitalizingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

View File

@@ -10,7 +10,10 @@ import com.actionbarsherlock.internal.nineoldandroids.widget.NineLinearLayout;
/**
* A simple extension of a regular linear layout that supports the divider API
* of Android 4.0+.
* of Android 4.0+. The dividers are added adjacent to the children by changing
* their layout params. If you need to rely on the margins which fall in the
* same orientation as the layout you should wrap the child in a simple
* {@link android.widget.FrameLayout} so it can receive the margin.
*/
public class IcsLinearLayout extends NineLinearLayout {
private static final int[] LinearLayout = new int[] {
@@ -42,6 +45,7 @@ public class IcsLinearLayout extends NineLinearLayout {
private Drawable mDivider;
private int mDividerWidth;
private int mDividerHeight;
private int mShowDividers;
private int mDividerPadding;
@@ -58,6 +62,29 @@ public class IcsLinearLayout extends NineLinearLayout {
a.recycle();
}
/**
* Set how dividers should be shown between items in this layout
*
* @param showDividers One or more of {@link #SHOW_DIVIDER_BEGINNING},
* {@link #SHOW_DIVIDER_MIDDLE}, or {@link #SHOW_DIVIDER_END},
* or {@link #SHOW_DIVIDER_NONE} to show no dividers.
*/
public void setShowDividers(int showDividers) {
if (showDividers != mShowDividers) {
requestLayout();
invalidate(); //XXX This is required if you are toggling a divider off
}
mShowDividers = showDividers;
}
/**
* @return A flag set indicating how dividers should be shown around items.
* @see #setShowDividers(int)
*/
public int getShowDividers() {
return mShowDividers;
}
/**
* Set a drawable to be used as a divider between items.
* @param divider Drawable that will divide each item.
@@ -70,13 +97,39 @@ public class IcsLinearLayout extends NineLinearLayout {
mDivider = divider;
if (divider != null) {
mDividerWidth = divider.getIntrinsicWidth();
mDividerHeight = divider.getIntrinsicHeight();
} else {
mDividerWidth = 0;
mDividerHeight = 0;
}
setWillNotDraw(divider == null);
requestLayout();
}
/**
* Set padding displayed on both ends of dividers.
*
* @param padding Padding value in pixels that will be applied to each end
*
* @see #setShowDividers(int)
* @see #setDividerDrawable(Drawable)
* @see #getDividerPadding()
*/
public void setDividerPadding(int padding) {
mDividerPadding = padding;
}
/**
* Get the padding size used to inset dividers in pixels
*
* @see #setShowDividers(int)
* @see #setDividerDrawable(Drawable)
* @see #setDividerPadding(int)
*/
public int getDividerPadding() {
return mDividerPadding;
}
/**
* Get the width of the current divider drawable.
*
@@ -89,9 +142,27 @@ public class IcsLinearLayout extends NineLinearLayout {
@Override
protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
final int index = indexOfChild(child);
final int orientation = getOrientation();
final LayoutParams params = (LayoutParams) child.getLayoutParams();
if (hasDividerBeforeChildAt(index)) {
//Account for the divider by pushing everything left
((LayoutParams)child.getLayoutParams()).leftMargin = mDividerWidth;
if (orientation == VERTICAL) {
//Account for the divider by pushing everything up
params.topMargin = mDividerHeight;
} else {
//Account for the divider by pushing everything left
params.leftMargin = mDividerWidth;
}
}
final int count = getChildCount();
if (index == count - 1) {
if (hasDividerBeforeChildAt(count)) {
if (orientation == VERTICAL) {
params.bottomMargin = mDividerHeight;
} else {
params.rightMargin = mDividerWidth;
}
}
}
super.measureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed);
}
@@ -99,32 +170,73 @@ public class IcsLinearLayout extends NineLinearLayout {
@Override
protected void onDraw(Canvas canvas) {
if (mDivider != null) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child != null && child.getVisibility() != GONE) {
if (hasDividerBeforeChildAt(i)) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int left = child.getLeft() - lp.leftMargin;
drawVerticalDivider(canvas, left);
}
}
if (getOrientation() == VERTICAL) {
drawDividersVertical(canvas);
} else {
drawDividersHorizontal(canvas);
}
}
super.onDraw(canvas);
}
if (hasDividerBeforeChildAt(count)) {
final View child = getChildAt(count - 1);
int right = 0;
if (child == null) {
right = getWidth() - getPaddingRight() - mDividerWidth;
} else {
void drawDividersVertical(Canvas canvas) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child != null && child.getVisibility() != GONE) {
if (hasDividerBeforeChildAt(i)) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
right = child.getRight() + lp.rightMargin;
final int top = child.getTop() - lp.topMargin/* - mDividerHeight*/;
drawHorizontalDivider(canvas, top);
}
drawVerticalDivider(canvas, right);
}
}
super.onDraw(canvas);
if (hasDividerBeforeChildAt(count)) {
final View child = getChildAt(count - 1);
int bottom = 0;
if (child == null) {
bottom = getHeight() - getPaddingBottom() - mDividerHeight;
} else {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
bottom = child.getBottom()/* + lp.bottomMargin*/;
}
drawHorizontalDivider(canvas, bottom);
}
}
void drawDividersHorizontal(Canvas canvas) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child != null && child.getVisibility() != GONE) {
if (hasDividerBeforeChildAt(i)) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int left = child.getLeft() - lp.leftMargin/* - mDividerWidth*/;
drawVerticalDivider(canvas, left);
}
}
}
if (hasDividerBeforeChildAt(count)) {
final View child = getChildAt(count - 1);
int right = 0;
if (child == null) {
right = getWidth() - getPaddingRight() - mDividerWidth;
} else {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
right = child.getRight()/* + lp.rightMargin*/;
}
drawVerticalDivider(canvas, right);
}
}
void drawHorizontalDivider(Canvas canvas, int top) {
mDivider.setBounds(getPaddingLeft() + mDividerPadding, top,
getWidth() - getPaddingRight() - mDividerPadding, top + mDividerHeight);
mDivider.draw(canvas);
}
void drawVerticalDivider(Canvas canvas, int left) {

View File

@@ -74,6 +74,10 @@ public class IcsListPopupWindow {
public static final int POSITION_PROMPT_ABOVE = 0;
public static final int POSITION_PROMPT_BELOW = 1;
public IcsListPopupWindow(Context context) {
this(context, null, R.attr.listPopupWindowStyle);
}
public IcsListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr) {
mContext = context;
mPopup = new PopupWindow(context, attrs, defStyleAttr);

View File

@@ -78,6 +78,10 @@ public class IcsSpinner extends IcsAbsSpinner implements OnClickListener {
private Rect mTempRect = new Rect();
public IcsSpinner(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.actionDropDownStyle);
}
/**
* Construct a new spinner with the given context's theme, the supplied attribute set,
* and default style.

View File

@@ -29,7 +29,6 @@ import android.view.ViewParent;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.BaseAdapter;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
@@ -37,12 +36,13 @@ import com.actionbarsherlock.R;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.internal.nineoldandroids.animation.Animator;
import com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator;
import com.actionbarsherlock.internal.nineoldandroids.widget.NineHorizontalScrollView;
/**
* This widget implements the dynamic action bar tab behavior that can change
* across different configurations or circumstances.
*/
public class ScrollingTabContainerView extends HorizontalScrollView
public class ScrollingTabContainerView extends NineHorizontalScrollView
implements IcsAdapterView.OnItemSelectedListener {
//UNUSED private static final String TAG = "ScrollingTabContainerView";
Runnable mTabSelector;