Commit 0ae49c6c authored by Thomas Krex's avatar Thomas Krex

Warnungen im sherlock unterdrückt

parent a696b275
......@@ -16,8 +16,6 @@
package com.actionbarsherlock.internal.view.menu;
import com.actionbarsherlock.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
......@@ -32,6 +30,8 @@ import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import com.actionbarsherlock.R;
/**
* The item view for each item in the ListView-based MenuViews.
*/
......@@ -49,7 +49,7 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
private Context mTextAppearanceContext;
private boolean mPreserveIconSpacing;
//UNUSED private int mMenuType;
// UNUSED private int mMenuType;
private LayoutInflater mInflater;
......@@ -61,13 +61,13 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
super(context, attrs);
mContext = context;
TypedArray a =
context.obtainStyledAttributes(
attrs, R.styleable.SherlockMenuView, defStyle, 0);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.SherlockMenuView, defStyle, 0);
mBackground = a.getDrawable(R.styleable.SherlockMenuView_itemBackground);
mTextAppearance = a.getResourceId(R.styleable.
SherlockMenuView_itemTextAppearance, -1);
mBackground = a
.getDrawable(R.styleable.SherlockMenuView_itemBackground);
mTextAppearance = a.getResourceId(
R.styleable.SherlockMenuView_itemTextAppearance, -1);
mPreserveIconSpacing = a.getBoolean(
R.styleable.SherlockMenuView_preserveIconSpacing, false);
mTextAppearanceContext = context;
......@@ -79,6 +79,7 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
this(context, attrs, 0);
}
@SuppressWarnings("deprecation")
@Override
protected void onFinishInflate() {
super.onFinishInflate();
......@@ -96,7 +97,7 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
public void initialize(MenuItemImpl itemData, int menuType) {
mItemData = itemData;
//UNUSED mMenuType = menuType;
// UNUSED mMenuType = menuType;
setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE);
......@@ -115,9 +116,11 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
if (title != null) {
mTitleView.setText(title);
if (mTitleView.getVisibility() != VISIBLE) mTitleView.setVisibility(VISIBLE);
if (mTitleView.getVisibility() != VISIBLE)
mTitleView.setVisibility(VISIBLE);
} else {
if (mTitleView.getVisibility() != GONE) mTitleView.setVisibility(GONE);
if (mTitleView.getVisibility() != GONE)
mTitleView.setVisibility(GONE);
}
}
......@@ -139,7 +142,8 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
}
// Depending on whether its exclusive check or not, the checkbox or
// radio button will be the one in use (and the other will be otherCompoundButton)
// radio button will be the one in use (and the other will be
// otherCompoundButton)
final CompoundButton compoundButton;
final CompoundButton otherCompoundButton;
......@@ -188,8 +192,8 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
}
public void setShortcut(boolean showShortcut, char shortcutKey) {
final int newVisibility = (showShortcut && mItemData.shouldShowShortcut())
? VISIBLE : GONE;
final int newVisibility = (showShortcut && mItemData
.shouldShowShortcut()) ? VISIBLE : GONE;
if (newVisibility == VISIBLE) {
mShortcutView.setText(mItemData.getShortcutLabel());
......@@ -240,24 +244,22 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
private void insertIconView() {
LayoutInflater inflater = getInflater();
mIconView = (ImageView) inflater.inflate(R.layout.abs__list_menu_item_icon,
this, false);
mIconView = (ImageView) inflater.inflate(
R.layout.abs__list_menu_item_icon, this, false);
addView(mIconView, 0);
}
private void insertRadioButton() {
LayoutInflater inflater = getInflater();
mRadioButton =
(RadioButton) inflater.inflate(R.layout.abs__list_menu_item_radio,
this, false);
mRadioButton = (RadioButton) inflater.inflate(
R.layout.abs__list_menu_item_radio, this, false);
addView(mRadioButton);
}
private void insertCheckBox() {
LayoutInflater inflater = getInflater();
mCheckBox =
(CheckBox) inflater.inflate(R.layout.abs__list_menu_item_checkbox,
this, false);
mCheckBox = (CheckBox) inflater.inflate(
R.layout.abs__list_menu_item_checkbox, this, false);
addView(mCheckBox);
}
......
......@@ -17,6 +17,7 @@
package com.actionbarsherlock.internal.view.menu;
import java.util.ArrayList;
import android.content.Context;
import android.content.res.Resources;
import android.database.DataSetObserver;
......@@ -32,6 +33,7 @@ import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ListAdapter;
import android.widget.PopupWindow;
import com.actionbarsherlock.R;
import com.actionbarsherlock.internal.view.View_HasStateListenerSupport;
import com.actionbarsherlock.internal.view.View_OnAttachStateChangeListener;
......@@ -40,12 +42,14 @@ import com.actionbarsherlock.view.MenuItem;
/**
* Presents a menu as a small, simple popup anchored to another view.
*
* @hide
*/
public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.OnKeyListener,
ViewTreeObserver.OnGlobalLayoutListener, PopupWindow.OnDismissListener,
View_OnAttachStateChangeListener, MenuPresenter {
//UNUSED private static final String TAG = "MenuPopupHelper";
public class MenuPopupHelper implements AdapterView.OnItemClickListener,
View.OnKeyListener, ViewTreeObserver.OnGlobalLayoutListener,
PopupWindow.OnDismissListener, View_OnAttachStateChangeListener,
MenuPresenter {
// UNUSED private static final String TAG = "MenuPopupHelper";
static final int ITEM_LAYOUT = R.layout.abs__popup_menu_item_layout;
......@@ -74,8 +78,8 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
this(context, menu, anchorView, false);
}
public MenuPopupHelper(Context context, MenuBuilder menu,
View anchorView, boolean overflowOnly) {
public MenuPopupHelper(Context context, MenuBuilder menu, View anchorView,
boolean overflowOnly) {
mContext = context;
mInflater = LayoutInflater.from(context);
mMenu = menu;
......@@ -100,10 +104,12 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
public void show() {
if (!tryShow()) {
throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
throw new IllegalStateException(
"MenuPopupHelper cannot be used without an anchor");
}
}
@SuppressWarnings("deprecation")
public boolean tryShow() {
mPopup = new IcsListPopupWindow(mContext, null, R.attr.popupMenuStyle);
mPopup.setOnDismissListener(this);
......@@ -115,7 +121,8 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
View anchor = mAnchorView;
if (anchor != null) {
// Don't attach to the VTO unless the anchor itself is attached to avoid VTO-related leaks.
// Don't attach to the VTO unless the anchor itself is attached to
// avoid VTO-related leaks.
if (anchor.getWindowToken() != null) {
ViewTreeObserver vto = anchor.getViewTreeObserver();
if (vto != mTreeObserver) {
......@@ -127,14 +134,16 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
}
}
} else if (anchor instanceof View_HasStateListenerSupport) {
((View_HasStateListenerSupport) anchor).addOnAttachStateChangeListener(this);
((View_HasStateListenerSupport) anchor)
.addOnAttachStateChangeListener(this);
}
mPopup.setAnchorView(anchor);
} else {
return false;
}
mPopup.setContentWidth(Math.min(measureContentWidth(mAdapter), mPopupMaxWidth));
mPopup.setContentWidth(Math.min(measureContentWidth(mAdapter),
mPopupMaxWidth));
mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
mPopup.show();
mPopup.getListView().setOnKeyListener(this);
......@@ -147,14 +156,17 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
}
}
@SuppressWarnings("deprecation")
public void onDismiss() {
mPopup = null;
mMenu.close();
if (mTreeObserver != null) {
if (mTreeObserver.isAlive()) mTreeObserver.removeGlobalOnLayoutListener(this);
if (mTreeObserver.isAlive())
mTreeObserver.removeGlobalOnLayoutListener(this);
mTreeObserver = null;
} else if (mAnchorView instanceof View_HasStateListenerSupport) {
((View_HasStateListenerSupport) mAnchorView).removeOnAttachStateChangeListener(this);
((View_HasStateListenerSupport) mAnchorView)
.removeOnAttachStateChangeListener(this);
}
}
......@@ -163,13 +175,15 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
MenuAdapter adapter = mAdapter;
adapter.mAdapterMenu.performItemAction(adapter.getItem(position), 0);
}
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_MENU) {
if (event.getAction() == KeyEvent.ACTION_UP
&& keyCode == KeyEvent.KEYCODE_MENU) {
dismiss();
return true;
}
......@@ -181,10 +195,10 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
int width = 0;
View itemView = null;
int itemType = 0;
final int widthMeasureSpec =
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final int heightMeasureSpec =
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
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);
......@@ -217,11 +231,14 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
@Override
public void onViewAttachedToWindow(View v) {
((View_HasStateListenerSupport) v).removeOnAttachStateChangeListener(this);
((View_HasStateListenerSupport) v)
.removeOnAttachStateChangeListener(this);
// The anchor wasn't attached in tryShow(), attach to the ViewRoot VTO now.
// The anchor wasn't attached in tryShow(), attach to the ViewRoot VTO
// now.
if (mPopup != null && mTreeObserver == null) {
(mTreeObserver = v.getViewTreeObserver()).addOnGlobalLayoutListener(this);
(mTreeObserver = v.getViewTreeObserver())
.addOnGlobalLayoutListener(this);
}
}
......@@ -231,17 +248,20 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
@Override
public void initForMenu(Context context, MenuBuilder menu) {
// Don't need to do anything; we added as a presenter in the constructor.
// Don't need to do anything; we added as a presenter in the
// constructor.
}
@Override
public MenuView getMenuView(ViewGroup root) {
throw new UnsupportedOperationException("MenuPopupHelpers manage their own views");
throw new UnsupportedOperationException(
"MenuPopupHelpers manage their own views");
}
@Override
public void updateMenuView(boolean cleared) {
if (mAdapter != null) mAdapter.notifyDataSetChanged();
if (mAdapter != null)
mAdapter.notifyDataSetChanged();
}
@Override
......@@ -252,7 +272,8 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
@Override
public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
if (subMenu.hasVisibleItems()) {
MenuPopupHelper subPopup = new MenuPopupHelper(mContext, subMenu, mAnchorView, false);
MenuPopupHelper subPopup = new MenuPopupHelper(mContext, subMenu,
mAnchorView, false);
subPopup.setCallback(mPresenterCallback);
boolean preserveIconSpacing = false;
......@@ -279,7 +300,8 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
@Override
public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
// Only care about the (sub)menu we're presenting.
if (menu != mMenu) return;
if (menu != mMenu)
return;
dismiss();
if (mPresenterCallback != null) {
......@@ -325,8 +347,8 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
}
public int getCount() {
ArrayList<MenuItemImpl> items = mOverflowOnly ?
mAdapterMenu.getNonActionItems() : mAdapterMenu.getVisibleItems();
ArrayList<MenuItemImpl> items = mOverflowOnly ? mAdapterMenu
.getNonActionItems() : mAdapterMenu.getVisibleItems();
if (mExpandedIndex < 0) {
return items.size();
}
......@@ -334,8 +356,8 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
}
public MenuItemImpl getItem(int position) {
ArrayList<MenuItemImpl> items = mOverflowOnly ?
mAdapterMenu.getNonActionItems() : mAdapterMenu.getVisibleItems();
ArrayList<MenuItemImpl> items = mOverflowOnly ? mAdapterMenu
.getNonActionItems() : mAdapterMenu.getVisibleItems();
if (mExpandedIndex >= 0 && position >= mExpandedIndex) {
position++;
}
......
......@@ -26,15 +26,19 @@ import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import com.actionbarsherlock.R;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.internal.nineoldandroids.widget.NineFrameLayout;
/**
* This class acts as a container for the action bar view and action mode context views.
* It applies special styles as needed to help handle animated transitions between them.
* This class acts as a container for the action bar view and action mode
* context views. It applies special styles as needed to help handle animated
* transitions between them.
*
* @hide
*/
@SuppressWarnings("deprecation")
public class ActionBarContainer extends NineFrameLayout {
private boolean mIsTransitioning;
private View mTabContainer;
......@@ -58,23 +62,25 @@ public class ActionBarContainer extends NineFrameLayout {
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.SherlockActionBar);
mBackground = a.getDrawable(R.styleable.SherlockActionBar_background);
mStackedBackground = a.getDrawable(
R.styleable.SherlockActionBar_backgroundStacked);
mStackedBackground = a
.getDrawable(R.styleable.SherlockActionBar_backgroundStacked);
//Fix for issue #379
if (mStackedBackground instanceof ColorDrawable && Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
mStackedBackground = new IcsColorDrawable((ColorDrawable) mStackedBackground);
// Fix for issue #379
if (mStackedBackground instanceof ColorDrawable
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
mStackedBackground = new IcsColorDrawable(
(ColorDrawable) mStackedBackground);
}
if (getId() == R.id.abs__split_action_bar) {
mIsSplit = true;
mSplitBackground = a.getDrawable(
R.styleable.SherlockActionBar_backgroundSplit);
mSplitBackground = a
.getDrawable(R.styleable.SherlockActionBar_backgroundSplit);
}
a.recycle();
setWillNotDraw(mIsSplit ? mSplitBackground == null :
mBackground == null && mStackedBackground == null);
setWillNotDraw(mIsSplit ? mSplitBackground == null
: mBackground == null && mStackedBackground == null);
}
@Override
......@@ -99,12 +105,12 @@ public class ActionBarContainer extends NineFrameLayout {
}
/**
* Set the action bar into a "transitioning" state. While transitioning
* the bar will block focus and touch from all of its descendants. This
* prevents the user from interacting with the bar while it is animating
* in or out.
* Set the action bar into a "transitioning" state. While transitioning the
* bar will block focus and touch from all of its descendants. This prevents
* the user from interacting with the bar while it is animating in or out.
*
* @param isTransitioning true if the bar is currently transitioning, false otherwise.
* @param isTransitioning
* true if the bar is currently transitioning, false otherwise.
*/
public void setTransitioning(boolean isTransitioning) {
mIsTransitioning = isTransitioning;
......@@ -158,7 +164,8 @@ public class ActionBarContainer extends NineFrameLayout {
}
if (mIsSplit) {
if (mSplitBackground != null) mSplitBackground.draw(canvas);
if (mSplitBackground != null)
mSplitBackground.draw(canvas);
} else {
if (mBackground != null) {
mBackground.draw(canvas);
......@@ -169,29 +176,35 @@ public class ActionBarContainer extends NineFrameLayout {
}
}
//This causes the animation reflection to fail on pre-HC platforms
//@Override
//public android.view.ActionMode startActionModeForChild(View child, android.view.ActionMode.Callback callback) {
// // No starting an action mode for an action bar child! (Where would it go?)
// This causes the animation reflection to fail on pre-HC platforms
// @Override
// public android.view.ActionMode startActionModeForChild(View child,
// android.view.ActionMode.Callback callback) {
// // No starting an action mode for an action bar child! (Where would it
// go?)
// return null;
//}
// }
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (mActionBarView == null) return;
if (mActionBarView == null)
return;
final LayoutParams lp = (LayoutParams) mActionBarView.getLayoutParams();
final int actionBarViewHeight = mActionBarView.isCollapsed() ? 0 :
mActionBarView.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
final int actionBarViewHeight = mActionBarView.isCollapsed() ? 0
: mActionBarView.getMeasuredHeight() + lp.topMargin
+ lp.bottomMargin;
if (mTabContainer != null && mTabContainer.getVisibility() != GONE) {
final int mode = MeasureSpec.getMode(heightMeasureSpec);
if (mode == MeasureSpec.AT_MOST) {
final int maxHeight = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(),
Math.min(actionBarViewHeight + mTabContainer.getMeasuredHeight(),
Math.min(
actionBarViewHeight
+ mTabContainer.getMeasuredHeight(),
maxHeight));
}
}
......@@ -201,7 +214,8 @@ public class ActionBarContainer extends NineFrameLayout {
public void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
final boolean hasTabs = mTabContainer != null && mTabContainer.getVisibility() != GONE;
final boolean hasTabs = mTabContainer != null
&& mTabContainer.getVisibility() != GONE;
if (mTabContainer != null && mTabContainer.getVisibility() != GONE) {
final int containerHeight = getMeasuredHeight();
......@@ -213,7 +227,8 @@ public class ActionBarContainer extends NineFrameLayout {
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child == mTabContainer) continue;
if (child == mTabContainer)
continue;
if (!mActionBarView.isCollapsed()) {
child.offsetTopAndBottom(tabHeight);
......@@ -221,25 +236,29 @@ public class ActionBarContainer extends NineFrameLayout {
}
mTabContainer.layout(l, 0, r, tabHeight);
} else {
mTabContainer.layout(l, containerHeight - tabHeight, r, containerHeight);
mTabContainer.layout(l, containerHeight - tabHeight, r,
containerHeight);
}
}
boolean needsInvalidate = false;
if (mIsSplit) {
if (mSplitBackground != null) {
mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
mSplitBackground.setBounds(0, 0, getMeasuredWidth(),
getMeasuredHeight());
needsInvalidate = true;
}
} else {
if (mBackground != null) {
mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(),
mActionBarView.getRight(), mActionBarView.getBottom());
mBackground.setBounds(mActionBarView.getLeft(),
mActionBarView.getTop(), mActionBarView.getRight(),
mActionBarView.getBottom());
needsInvalidate = true;
}
if ((mIsStacked = hasTabs && mStackedBackground != null)) {
mStackedBackground.setBounds(mTabContainer.getLeft(), mTabContainer.getTop(),
mTabContainer.getRight(), mTabContainer.getBottom());
mStackedBackground.setBounds(mTabContainer.getLeft(),
mTabContainer.getTop(), mTabContainer.getRight(),
mTabContainer.getBottom());
needsInvalidate = true;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment