Update minitab assets and behavior to match spec.
diff --git a/src/com/android/contacts/NoDragHorizontalScrollView.java b/src/com/android/contacts/NoDragHorizontalScrollView.java
deleted file mode 100644
index 94d8c13..0000000
--- a/src/com/android/contacts/NoDragHorizontalScrollView.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.contacts;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.widget.HorizontalScrollView;
-
-/* Simple extension of {@link HorizontalScrollView} that disallows drag scrolling */
-public class NoDragHorizontalScrollView extends HorizontalScrollView {
-
- public NoDragHorizontalScrollView(Context context) {
- super(context);
- }
-
- public NoDragHorizontalScrollView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public NoDragHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- @Override
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- return false;
- }
-
-}
diff --git a/src/com/android/contacts/ScrollingTabWidget.java b/src/com/android/contacts/ScrollingTabWidget.java
index 2f703aa..ddd101b 100644
--- a/src/com/android/contacts/ScrollingTabWidget.java
+++ b/src/com/android/contacts/ScrollingTabWidget.java
@@ -18,8 +18,10 @@
import android.content.Context;
import android.graphics.Canvas;
+import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
@@ -27,6 +29,8 @@
import android.view.ViewTreeObserver;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
+import android.widget.HorizontalScrollView;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
@@ -41,12 +45,11 @@
private OnTabSelectionChangedListener mSelectionChangedListener;
private int mSelectedTab = 0;
- private LinearLayout mLeftArrowView;
- private LinearLayout mRightArrowView;
- private NoDragHorizontalScrollView mTabsScrollWrapper;
- private LinearLayout mTabsView;
+ private ImageView mLeftArrowView;
+ private ImageView mRightArrowView;
+ private HorizontalScrollView mTabsScrollWrapper;
+ private TabStripView mTabsView;
private LayoutInflater mInflater;
- private Drawable mDividerDrawable;
// Keeps track of the left most visible tab.
private int mLeftMostVisibleTabIndex = 0;
@@ -67,20 +70,17 @@
setFocusable(true);
setOnFocusChangeListener(this);
- onLoseFocus();
-// if (!hasFocus()) {
-// setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
-// }
+ if (!hasFocus()) {
+ setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
+ }
- mLeftArrowView = (LinearLayout) mInflater.inflate(R.layout.tab_left_arrow, this, false);
+ mLeftArrowView = (ImageView) mInflater.inflate(R.layout.tab_left_arrow, this, false);
mLeftArrowView.setOnClickListener(this);
- mRightArrowView = (LinearLayout) mInflater.inflate(R.layout.tab_right_arrow, this, false);
+ mRightArrowView = (ImageView) mInflater.inflate(R.layout.tab_right_arrow, this, false);
mRightArrowView.setOnClickListener(this);
- mTabsScrollWrapper = (NoDragHorizontalScrollView) mInflater.inflate(
+ mTabsScrollWrapper = (HorizontalScrollView) mInflater.inflate(
R.layout.tab_layout, this, false);
- mTabsView = (LinearLayout) mTabsScrollWrapper.findViewById(android.R.id.tabs);
- mDividerDrawable = mContext.getResources().getDrawable(
- R.drawable.tab_divider);
+ mTabsView = (TabStripView) mTabsScrollWrapper.findViewById(android.R.id.tabs);
mLeftArrowView.setVisibility(View.INVISIBLE);
mRightArrowView.setVisibility(View.INVISIBLE);
@@ -140,7 +140,7 @@
* @return the tab indicator view at the given index
*/
public View getChildTabViewAt(int index) {
- return mTabsView.getChildAt(index*2);
+ return mTabsView.getChildAt(index);
}
/**
@@ -149,8 +149,7 @@
* @return the number of tab indicator views.
*/
public int getTabCount() {
- int children = mTabsView.getChildCount();
- return (children + 1) / 2;
+ return mTabsView.getChildCount();
}
public void removeAllTabs() {
@@ -195,9 +194,9 @@
return;
}
- getChildTabViewAt(mSelectedTab).setSelected(false);
+ mTabsView.setSelected(mSelectedTab, false);
mSelectedTab = index;
- getChildTabViewAt(mSelectedTab).setSelected(true);
+ mTabsView.setSelected(mSelectedTab, true);
}
/**
@@ -266,17 +265,6 @@
child.setOnClickListener(new TabClickListener());
child.setOnFocusChangeListener(this);
- // If we already have at least one tab, then add a divider before adding the next tab.
- if (getTabCount() > 0) {
- View divider = new View(mContext);
- final LayoutParams lp = new LayoutParams(
- mDividerDrawable.getIntrinsicWidth(),
- ViewGroup.LayoutParams.FILL_PARENT);
- lp.setMargins(0, 0, 0, 0);
- divider.setLayoutParams(lp);
- divider.setBackgroundDrawable(mDividerDrawable);
- mTabsView.addView(divider);
- }
mTabsView.addView(child);
}
@@ -369,23 +357,8 @@
void onTabSelectionChanged(int tabIndex, boolean clicked);
}
- @Override
- public boolean dispatchKeyEvent(KeyEvent event) {
- boolean handled = super.dispatchKeyEvent(event);
- if (event.getAction() == KeyEvent.ACTION_DOWN) {
- switch (event.getKeyCode()) {
- case KeyEvent.KEYCODE_DPAD_LEFT:
- case KeyEvent.KEYCODE_DPAD_RIGHT:
- // If tabs move from left/right events we must update mLeftMostVisibleTabIndex.
- updateLeftMostVisible();
- break;
- }
- }
-
- return handled;
- }
-
public void onClick(View v) {
+ updateLeftMostVisible();
if (v == mRightArrowView && (mLeftMostVisibleTabIndex + 1 < getTabCount())) {
tabScroll(true /* right */);
} else if (v == mLeftArrowView && mLeftMostVisibleTabIndex > 0) {
diff --git a/src/com/android/contacts/TabStripView.java b/src/com/android/contacts/TabStripView.java
new file mode 100644
index 0000000..70878ea
--- /dev/null
+++ b/src/com/android/contacts/TabStripView.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.contacts;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Rect;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.HorizontalScrollView;
+import android.widget.LinearLayout;
+
+/** Extension of LinearLayout that takes care of drawing bottom strips over the tab children. */
+public class TabStripView extends LinearLayout {
+
+ private Drawable mBottomLeftStrip;
+ private Drawable mBottomRightStrip;
+ private int mSelectedTabIndex;
+
+ public TabStripView(Context context) {
+ this(context, null);
+ }
+
+ public TabStripView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init();
+ }
+
+ private void init() {
+ mBottomLeftStrip = mContext.getResources().getDrawable(
+ R.drawable.tab_bottom);
+ mBottomRightStrip = mContext.getResources().getDrawable(
+ R.drawable.tab_bottom);
+ }
+
+ public void setSelected(int index, boolean selected) {
+ mSelectedTabIndex = index;
+ getChildAt(index).setSelected(selected);
+ }
+
+ @Override
+ public void childDrawableStateChanged(View child) {
+ if (child == getChildAt(mSelectedTabIndex)) {
+ // To make sure that the bottom strip is redrawn
+ invalidate();
+ }
+ super.childDrawableStateChanged(child);
+ }
+
+ @Override
+ public void dispatchDraw(Canvas canvas) {
+ super.dispatchDraw(canvas);
+
+ View selectedChild = getChildAt(mSelectedTabIndex);
+
+ mBottomRightStrip.setState(selectedChild.getDrawableState());
+ mBottomLeftStrip.setState(selectedChild.getDrawableState());
+
+ Rect selBounds = new Rect(); // Bounds of the selected tab indicator
+ selBounds.left = selectedChild.getLeft() - getScrollX();
+ selBounds.right = selectedChild.getRight() - getScrollX();
+ final int myHeight = getHeight();
+ mBottomLeftStrip.setBounds(
+ Math.min(0, selBounds.left
+ - mBottomLeftStrip.getIntrinsicWidth()),
+ myHeight - mBottomLeftStrip.getIntrinsicHeight(),
+ selBounds.left,
+ myHeight);
+ mBottomRightStrip.setBounds(
+ selBounds.right,
+ myHeight - mBottomRightStrip.getIntrinsicHeight(),
+ Math.max(getWidth(),
+ selBounds.right + mBottomRightStrip.getIntrinsicWidth()),
+ myHeight);
+
+ mBottomLeftStrip.draw(canvas);
+ mBottomRightStrip.draw(canvas);
+ }
+
+}