adjust tab width for screen size

       Bug: 4427112
       make tabs smaller for portrait 7 inch screen

Change-Id: I0e02e68b1bae1fe7e81f1a3a49911707de40903b
diff --git a/src/com/android/browser/TabBar.java b/src/com/android/browser/TabBar.java
index 1d17cb3..7abb203 100644
--- a/src/com/android/browser/TabBar.java
+++ b/src/com/android/browser/TabBar.java
@@ -24,6 +24,7 @@
 import android.animation.ObjectAnimator;
 import android.app.Activity;
 import android.content.Context;
+import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapShader;
@@ -65,8 +66,8 @@
     private TabControl mTabControl;
     private XLargeUi mUi;
 
-    private final int mTabWidthSelected;
-    private final int mTabWidthUnselected;
+    private int mTabWidthSelected;
+    private int mTabWidthUnselected;
 
     private TabScrollView mTabs;
 
@@ -138,6 +139,16 @@
         mFocusPaint.setColor(res.getColor(R.color.tabFocusHighlight));
     }
 
+    @Override
+    public void onConfigurationChanged(Configuration config) {
+        super.onConfigurationChanged(config);
+        Resources res = mActivity.getResources();
+        mTabWidthSelected = (int) res.getDimension(R.dimen.tab_width_selected);
+        mTabWidthUnselected = (int) res.getDimension(R.dimen.tab_width_unselected);
+        // force update of tab bar
+        mTabs.updateLayout();
+    }
+
     void setUseQuickControls(boolean useQuickControls) {
         mUseQuickControls = useQuickControls;
         mNewTab.setVisibility(mUseQuickControls ? View.GONE
@@ -403,14 +414,18 @@
                     R.style.TabTitleSelected : R.style.TabTitleUnselected);
             setHorizontalFadingEdgeEnabled(!mSelected);
             super.setActivated(selected);
-            LayoutParams lp = (LinearLayout.LayoutParams) getLayoutParams();
-            lp.width = selected ? mTabWidthSelected : mTabWidthUnselected;
-            lp.height =  LayoutParams.MATCH_PARENT;
-            setLayoutParams(lp);
+            updateLayoutParams();
             setFocusable(!selected);
             postInvalidate();
         }
 
+        public void updateLayoutParams() {
+            LayoutParams lp = (LinearLayout.LayoutParams) getLayoutParams();
+            lp.width = mSelected ? mTabWidthSelected : mTabWidthUnselected;
+            lp.height =  LayoutParams.MATCH_PARENT;
+            setLayoutParams(lp);
+        }
+
         void setDisplayTitle(String title) {
             mTitle.setText(title);
         }
diff --git a/src/com/android/browser/TabScrollView.java b/src/com/android/browser/TabScrollView.java
index d0648b7..f43d6d6 100644
--- a/src/com/android/browser/TabScrollView.java
+++ b/src/com/android/browser/TabScrollView.java
@@ -16,6 +16,8 @@
 
 package com.android.browser;
 
+import com.android.browser.TabBar.TabView;
+
 import android.animation.ObjectAnimator;
 import android.content.Context;
 import android.util.AttributeSet;
@@ -85,6 +87,16 @@
         ensureChildVisible(getSelectedTab());
     }
 
+    // in case of a configuration change, adjust tab width
+    protected void updateLayout() {
+        final int count = mContentView.getChildCount();
+        for (int i = 0; i < count; i++) {
+            final TabView tv = (TabView) mContentView.getChildAt(i);
+            tv.updateLayoutParams();
+        }
+        ensureChildVisible(getSelectedTab());
+    }
+
     void setSelectedTab(int position) {
         View v = getSelectedTab();
         if (v != null) {