diff options
author | Michael Kolb <kolby@google.com> | 2010-09-30 12:57:59 -0700 |
---|---|---|
committer | Michael Kolb <kolby@google.com> | 2010-10-01 09:57:55 -0700 |
commit | ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27 (patch) | |
tree | 98a76bba878382a8341331d7121dad374d31f91b | |
parent | 9025bfb95a29b5e2497fce898abde4350f7686c7 (diff) | |
download | packages_apps_browser-ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27.zip packages_apps_browser-ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27.tar.gz packages_apps_browser-ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27.tar.bz2 |
move new tab button next to tabs
http://b/issue?id=3052018
moved tab button
added new tab option to menu
http://b/issue?id=3052583
changed text from window to tab
Change-Id: I079636f29ea529915a5f8c3ad55b4b4c7afe579f
-rw-r--r-- | res/layout/tab_bar.xml | 17 | ||||
-rw-r--r-- | res/menu-xlarge/browser.xml | 4 | ||||
-rw-r--r-- | res/values-xlarge/strings.xml | 25 | ||||
-rw-r--r-- | src/com/android/browser/BrowserActivity.java | 5 | ||||
-rw-r--r-- | src/com/android/browser/TabBar.java | 42 | ||||
-rw-r--r-- | src/com/android/browser/TabScrollView.java | 18 |
6 files changed, 78 insertions, 33 deletions
diff --git a/res/layout/tab_bar.xml b/res/layout/tab_bar.xml index 7967307..2726055 100644 --- a/res/layout/tab_bar.xml +++ b/res/layout/tab_bar.xml @@ -10,17 +10,24 @@ the specific language governing permissions and limitations under the License. --> -<LinearLayout +<merge xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tabbarcontent" android:layout_width="match_parent" android:layout_height="48dip" + android:orientation="horizontal" style="@style/ActionBarStyle" - android:orientation="horizontal"> + > <com.android.browser.TabScrollView android:id="@+id/tabs" - android:layout_width="0dp" + android:layout_width="wrap_content" android:layout_height="match_parent" - android:layout_weight="1.0" android:orientation="horizontal" /> -</LinearLayout> + <ImageButton + android:id="@+id/newtab" + android:src="@drawable/ic_menu_new_window" + android:layout_width="wrap_content" + android:layout_height="match_parent" + style="@style/HoloButton" + android:background="@drawable/browserbarbutton" /> +</merge>
\ No newline at end of file diff --git a/res/menu-xlarge/browser.xml b/res/menu-xlarge/browser.xml index cf29351..3b93835 100644 --- a/res/menu-xlarge/browser.xml +++ b/res/menu-xlarge/browser.xml @@ -19,10 +19,10 @@ <item android:id="@+id/newtab" android:icon="@drawable/ic_menu_new_window" android:title="@string/new_tab" - android:showAsAction="always" + android:showAsAction="never" android:alphabeticShortcut="n" /> <item android:id="@+id/incognito_menu_id" - android:title="@string/incognito_tab" + android:title="@string/new_incognito_tab" android:icon="@drawable/ic_menu_incognito_normal" /> <item android:id="@+id/find_menu_id" android:title="@*android:string/find_on_page" diff --git a/res/values-xlarge/strings.xml b/res/values-xlarge/strings.xml new file mode 100644 index 0000000..07b2b34 --- /dev/null +++ b/res/values-xlarge/strings.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 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. +--> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <!-- Name of menu item of a new tab. + Also used in the title bar when displaying a new tab [CHAR LIMIT=30] --> + <string name="new_tab">New tab</string> + <!-- Name of menu item of a new incognito tab. Also used in the + title bar when displaying a new tab [CHAR LIMIT=30] --> + <string name="new_incognito_tab">New incognito tab</string> + <!-- Name of menu item which brings up a list of the currently active tabs --> + <string name="active_tabs">Tabs</string> +</resources> diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index 4ea96bb..f5d72ac 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -1614,7 +1614,6 @@ public class BrowserActivity extends Activity final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id); newtab.setEnabled(mTabControl.canCreateNewTab()); } - // decide whether to show the share link option PackageManager pm = getPackageManager(); Intent send = new Intent(Intent.ACTION_SEND); @@ -3873,7 +3872,7 @@ public class BrowserActivity extends Activity popup.setOnMenuItemClickListener(this); popup.show(); } - + /** * popup menu item click listener * @param item @@ -3912,7 +3911,7 @@ public class BrowserActivity extends Activity return false; } } - + /* package */Dialog makeAddOrInstallDialog() { final Tab current = mTabControl.getCurrentTab(); Resources resources = getResources(); diff --git a/src/com/android/browser/TabBar.java b/src/com/android/browser/TabBar.java index 4c8ab26..9217ef2 100644 --- a/src/com/android/browser/TabBar.java +++ b/src/com/android/browser/TabBar.java @@ -16,6 +16,9 @@ package com.android.browser; +import com.android.browser.ScrollWebView.ScrollListener; +import com.android.browser.TabControl.TabChangeListener; + import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; @@ -36,9 +39,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import com.android.browser.ScrollWebView.ScrollListener; -import com.android.browser.TabControl.TabChangeListener; - import java.util.HashMap; import java.util.Map; @@ -59,10 +59,11 @@ public class TabBar extends LinearLayout private TabScrollView mTabs; private TabControl mControl; + private ImageButton mNewTab; + private int mButtonWidth; private Map<Tab, TabViewData> mTabMap; - private float mDensityScale; private boolean mUserRequestedUrlbar; private boolean mTitleVisible; private boolean mShowUrlMode; @@ -76,7 +77,6 @@ public class TabBar extends LinearLayout mTitleBar = titlebar; mTitleBar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); - mDensityScale = context.getResources().getDisplayMetrics().density; mTabMap = new HashMap<Tab, TabViewData>(); mBrowserActivity = context; mControl = tabcontrol; @@ -84,6 +84,8 @@ public class TabBar extends LinearLayout LayoutInflater factory = LayoutInflater.from(context); factory.inflate(R.layout.tab_bar, this); mTabs = (TabScrollView) findViewById(R.id.tabs); + mNewTab = (ImageButton) findViewById(R.id.newtab); + mNewTab.setOnClickListener(this); // TODO: Change enabled states based on whether you can go // back/forward. Probably should be done inside onPageStarted. @@ -101,22 +103,38 @@ public class TabBar extends LinearLayout mControl.setOnTabChangeListener(this); mUserRequestedUrlbar = false; mTitleVisible = true; + mButtonWidth = -1; + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + if (mButtonWidth == -1) { + mButtonWidth = mNewTab.getMeasuredWidth(); + } + int sw = mTabs.getMeasuredWidth(); + int w = right-left; + if (w-sw < mButtonWidth) { + sw = w - mButtonWidth; + } + mTabs.layout(0, 0, sw, bottom-top ); + mNewTab.layout(sw, 0, sw+mButtonWidth, bottom-top); } public void onClick(View view) { - if (mTabs.getSelectedTab() == view) { + if (mNewTab == view) { + mBrowserActivity.openTabToHomePage(); + } else if (mTabs.getSelectedTab() == view) { if (mBrowserActivity.isFakeTitleBarShowing() && !isLoading()) { mBrowserActivity.hideFakeTitleBar(); } else { showUrlBar(); } - // temporarily disabled - // mTitleBar.requestUrlInputFocus(); } else { - TabViewData data = (TabViewData) view.getTag(); - int ix = mControl.getTabIndex(data.mTab); - mTabs.setSelectedTab(ix); - mBrowserActivity.switchToTab(ix); + int ix = mTabs.getChildIndex(view); + if (ix >= 0) { + mTabs.setSelectedTab(ix); + mBrowserActivity.switchToTab(ix); + } } } diff --git a/src/com/android/browser/TabScrollView.java b/src/com/android/browser/TabScrollView.java index 435362d..fcd5a80 100644 --- a/src/com/android/browser/TabScrollView.java +++ b/src/com/android/browser/TabScrollView.java @@ -27,10 +27,8 @@ import android.widget.LinearLayout; */ public class TabScrollView extends HorizontalScrollView { - private Context mContext; - + private BrowserActivity mBrowserActivity; private LinearLayout mContentView; - private int mSelected; /** @@ -61,9 +59,9 @@ public class TabScrollView extends HorizontalScrollView { } private void init(Context ctx) { - mContext = ctx; + mBrowserActivity = (BrowserActivity)ctx; setHorizontalScrollBarEnabled(false); - mContentView = new LinearLayout(mContext); + mContentView = new LinearLayout(mBrowserActivity); mContentView.setOrientation(LinearLayout.HORIZONTAL); mContentView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); @@ -90,6 +88,10 @@ public class TabScrollView extends HorizontalScrollView { requestLayout(); } + int getChildIndex(View v) { + return mContentView.indexOfChild(v); + } + View getSelectedTab() { if ((mSelected >= 0) && (mSelected < mContentView.getChildCount())) { return mContentView.getChildAt(mSelected); @@ -107,11 +109,6 @@ public class TabScrollView extends HorizontalScrollView { tab.setActivated(false); } - void addTab(View tab, int pos) { - mContentView.addView(tab, pos); - tab.setActivated(false); - } - void removeTab(View tab) { int ix = mContentView.indexOfChild(tab); if (ix == mSelected) { @@ -138,5 +135,4 @@ public class TabScrollView extends HorizontalScrollView { } } - } |