Bug 958889 - Part 2: Miscellaneous code clean up. r=bnicholson

This commit is contained in:
Michael Comella 2014-04-29 11:21:38 -07:00
parent fb36dffe1a
commit 460163d290
3 changed files with 35 additions and 24 deletions

View File

@ -33,7 +33,7 @@ import android.widget.RelativeLayout;
public class TabsPanel extends LinearLayout
implements LightweightTheme.OnChangeListener,
IconTabWidget.OnTabChangedListener {
private static final String LOGTAG = "GeckoTabsPanel";
private static final String LOGTAG = "Gecko" + TabsPanel.class.getSimpleName();
public static enum Panel {
NORMAL_TABS,
@ -78,8 +78,8 @@ public class TabsPanel extends LinearLayout
mActivity = (GeckoApp) context;
mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme();
setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
setOrientation(LinearLayout.VERTICAL);
mCurrentPanel = Panel.NORMAL_TABS;
@ -127,10 +127,11 @@ public class TabsPanel extends LinearLayout
}
public void addTab() {
if (mCurrentPanel == Panel.NORMAL_TABS)
if (mCurrentPanel == Panel.NORMAL_TABS) {
mActivity.addTab();
else
} else {
mActivity.addPrivateTab();
}
mActivity.autoHideTabs();
}
@ -180,6 +181,7 @@ public class TabsPanel extends LinearLayout
}
@Override
@SuppressWarnings("deprecation") // setBackgroundDrawable deprecated by API level 16
public void onLightweightThemeChanged() {
final int background = getResources().getColor(R.color.background_tabs);
final LightweightThemeDrawable drawable = mTheme.getColorDrawable(this, background, true);
@ -241,7 +243,7 @@ public class TabsPanel extends LinearLayout
super(context, attrs);
mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme();
setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
(int) context.getResources().getDimension(R.dimen.browser_toolbar_height)));
setOrientation(LinearLayout.HORIZONTAL);
@ -260,6 +262,7 @@ public class TabsPanel extends LinearLayout
}
@Override
@SuppressWarnings("deprecation") // setBackgroundDrawable deprecated by API level 16
public void onLightweightThemeChanged() {
final int background = getResources().getColor(R.color.background_tabs);
final LightweightThemeDrawable drawable = mTheme.getColorDrawable(this, background);
@ -286,7 +289,7 @@ public class TabsPanel extends LinearLayout
show(panel, true);
}
public void show(Panel panel, boolean shouldResize) {
public void show(Panel panelToShow, boolean shouldResize) {
if (!isShown())
setVisibility(View.VISIBLE);
@ -297,19 +300,25 @@ public class TabsPanel extends LinearLayout
final boolean showAnimation = !mVisible;
mVisible = true;
mCurrentPanel = panel;
mCurrentPanel = panelToShow;
int index = panel.ordinal();
int index = panelToShow.ordinal();
mTabWidget.setCurrentTab(index);
if (index == 0) {
mPanel = mPanelNormal;
} else if (index == 1) {
mPanel = mPanelPrivate;
} else {
mPanel = mPanelRemote;
}
switch (panelToShow) {
case NORMAL_TABS:
mPanel = mPanelNormal;
break;
case PRIVATE_TABS:
mPanel = mPanelPrivate;
break;
case REMOTE_TABS:
mPanel = mPanelRemote;
break;
default:
throw new IllegalArgumentException("Unknown panel type " + panelToShow);
}
mPanel.show();
if (mCurrentPanel == Panel.REMOTE_TABS) {

View File

@ -39,7 +39,7 @@ import android.widget.TextView;
class TabsTray extends TwoWayView
implements TabsPanel.PanelView {
private static final String LOGTAG = "GeckoTabsTray";
private static final String LOGTAG = "Gecko" + TabsTray.class.getSimpleName();
private Context mContext;
private TabsPanel mTabsPanel;
@ -54,7 +54,6 @@ class TabsTray extends TwoWayView
// Time to animate non-flinged tabs of screen, in milliseconds
private static final int ANIMATION_DURATION = 250;
private static final String ABOUT_HOME = "about:home";
private int mOriginalSize = 0;
public TabsTray(Context context, AttributeSet attrs) {
@ -430,7 +429,6 @@ class TabsTray extends TwoWayView
private int mListHeight = 1;
private View mSwipeView;
private int mSwipeViewPosition;
private Runnable mPendingCheckForTap;
private float mSwipeStartX;
@ -440,7 +438,6 @@ class TabsTray extends TwoWayView
public TabSwipeGestureListener() {
mSwipeView = null;
mSwipeViewPosition = TwoWayView.INVALID_POSITION;
mSwiping = false;
mEnabled = true;
@ -492,7 +489,6 @@ class TabsTray extends TwoWayView
if (mSwipeView != null) {
mSwipeStartX = e.getRawX();
mSwipeStartY = e.getRawY();
mSwipeViewPosition = TabsTray.this.getPositionForView(mSwipeView);
mVelocityTracker = VelocityTracker.obtain();
mVelocityTracker.addMovement(e);
@ -513,6 +509,9 @@ class TabsTray extends TwoWayView
TabRow tab = (TabRow) mSwipeView.getTag();
Tabs.getInstance().selectTab(tab.id);
autoHidePanel();
mVelocityTracker.recycle();
mVelocityTracker = null;
break;
}
@ -559,9 +558,9 @@ class TabsTray extends TwoWayView
else
animateCancel(mSwipeView);
mVelocityTracker.recycle();
mVelocityTracker = null;
mSwipeView = null;
mSwipeViewPosition = TwoWayView.INVALID_POSITION;
mSwipeStartX = 0;
mSwipeStartY = 0;
@ -604,6 +603,7 @@ class TabsTray extends TwoWayView
cancelEvent.setAction(MotionEvent.ACTION_CANCEL |
(e.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
TabsTray.this.onTouchEvent(cancelEvent);
cancelEvent.recycle();
}
if (mSwiping) {

View File

@ -1329,7 +1329,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
if (maybeStartScrolling(delta)) {
return true;
}
break;
}
@ -1448,6 +1448,8 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
}
case MotionEvent.ACTION_CANCEL:
// If this MotionEvent has been created by us, be sure not to store
// pointers to it outside of this method call because we recycle it.
cancelCheckForTap();
mTouchMode = TOUCH_MODE_REST;
reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
@ -2384,7 +2386,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
if (mFirstPosition == 0) {
final View firstChild = getChildAt(0);
final int firstChildStart = (mIsVertical ? firstChild.getTop() : firstChild.getLeft());
final int firstChildStart = (mIsVertical ? firstChild.getTop() : firstChild.getLeft());
// First is first in list -> make sure we don't scroll past it
final int max = start - firstChildStart;