diff options
author | Arham Jamal <arhamjamal@gmail.com> | 2012-04-28 05:01:12 +0200 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-11-07 13:57:35 -0800 |
commit | 1fd4bec1891e40dfe2e04c1ffe0bbd9f4e649cee (patch) | |
tree | c599a877c3b6b2d4a49102d97d8909f4862181c9 | |
parent | cfc55f1967f309ab077eded9aa6afa542cd4f00a (diff) | |
download | packages_apps_Browser-1fd4bec1891e40dfe2e04c1ffe0bbd9f4e649cee.tar.gz packages_apps_Browser-1fd4bec1891e40dfe2e04c1ffe0bbd9f4e649cee.tar.bz2 packages_apps_Browser-1fd4bec1891e40dfe2e04c1ffe0bbd9f4e649cee.zip |
Browser: New navbar buttons
Added 2 new buttons to navigation bar:
- New Incognito Tab
- Goto home screen
Signed-off-by: Arham Jamal <arhamjamal@gmail.com>
Change-Id: I4c4b611ccc7fc3de4fa4bc7c855e4481de440a87
-rw-r--r-- | res/layout-land/nav_screen.xml | 16 | ||||
-rw-r--r-- | res/layout/nav_screen.xml | 16 | ||||
-rw-r--r-- | res/values/cm_strings.xml | 20 | ||||
-rw-r--r-- | src/com/android/browser/NavScreen.java | 66 | ||||
-rw-r--r-- | src/com/android/browser/NavTabView.java | 5 |
5 files changed, 117 insertions, 6 deletions
diff --git a/res/layout-land/nav_screen.xml b/res/layout-land/nav_screen.xml index 97a230a82..dc95217ee 100644 --- a/res/layout-land/nav_screen.xml +++ b/res/layout-land/nav_screen.xml @@ -34,6 +34,22 @@ android:background="@color/primary" android:elevation="8dp"> <ImageButton + android:id="@+id/gotohome" + android:layout_width="wrap_content" + android:layout_height="match_parent" + style="@style/HoloButton" + android:gravity="center_vertical" + android:contentDescription="@string/accessibility_button_homescreen" + android:src="@drawable/ic_home_dark" /> + <ImageButton + android:id="@+id/newincognitotab" + android:layout_width="wrap_content" + android:layout_height="match_parent" + style="@style/HoloButton" + android:gravity="center_vertical" + android:contentDescription="@string/accessibility_button_newincognitotab" + android:src="@drawable/ic_new_incognito_dark" /> + <ImageButton android:id="@+id/newtab" android:layout_width="wrap_content" android:layout_height="match_parent" diff --git a/res/layout/nav_screen.xml b/res/layout/nav_screen.xml index 356bf1943..46a86cfc3 100644 --- a/res/layout/nav_screen.xml +++ b/res/layout/nav_screen.xml @@ -35,6 +35,22 @@ android:background="@color/primary" android:elevation="8dp"> <ImageButton + android:id="@+id/gotohome" + android:layout_width="wrap_content" + android:layout_height="match_parent" + style="@style/HoloButton" + android:gravity="center_vertical" + android:contentDescription="@string/accessibility_button_homescreen" + android:src="@drawable/ic_home_dark" /> + <ImageButton + android:id="@+id/newincognitotab" + android:layout_width="wrap_content" + android:layout_height="match_parent" + style="@style/HoloButton" + android:gravity="center_vertical" + android:contentDescription="@string/accessibility_button_newincognitotab" + android:src="@drawable/ic_new_incognito_dark" /> + <ImageButton android:id="@+id/newtab" android:layout_width="wrap_content" android:layout_height="match_parent" diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml new file mode 100644 index 000000000..63b04e93f --- /dev/null +++ b/res/values/cm_strings.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2015 The CyanogenMod 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"> + <!-- Content description for home screen button [CHAR LIMIT=NONE] --> + <string name="accessibility_button_homescreen">Home screen</string> +</resources> diff --git a/src/com/android/browser/NavScreen.java b/src/com/android/browser/NavScreen.java index 85eaa41b8..277df1876 100644 --- a/src/com/android/browser/NavScreen.java +++ b/src/com/android/browser/NavScreen.java @@ -19,6 +19,7 @@ package com.android.browser; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; +import android.graphics.Point; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -26,6 +27,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewConfiguration; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.BaseAdapter; import android.widget.FrameLayout; import android.widget.ImageButton; @@ -42,6 +44,7 @@ import com.android.browser.TabControl.OnThumbnailUpdatedListener; import com.android.browser.UI.ComboViews; import java.util.HashMap; +import java.util.List; public class NavScreen extends RelativeLayout implements OnClickListener, OnMenuItemClickListener, OnThumbnailUpdatedListener { @@ -56,6 +59,8 @@ public class NavScreen extends RelativeLayout ImageButton mForward; ImageButton mBookmarks; ImageButton mMore; + ImageButton mHomeTab; + ImageButton mNewIncognitoTab; ImageButton mNewTab; FrameLayout mHolder; @@ -67,6 +72,7 @@ public class NavScreen extends RelativeLayout NavTabScroller mScroller; TabAdapter mAdapter; int mOrientation; + Point mSize; HashMap<Tab, View> mTabViews; public NavScreen(Activity activity, UiController ctl, PhoneUi ui) { @@ -75,6 +81,9 @@ public class NavScreen extends RelativeLayout mUiController = ctl; mUi = ui; mOrientation = activity.getResources().getConfiguration().orientation; + WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE); + mSize = new Point(); + wm.getDefaultDisplay().getSize(mSize); init(); } @@ -118,9 +127,13 @@ public class NavScreen extends RelativeLayout setContentDescription(mContext.getResources().getString( R.string.accessibility_transition_navscreen)); mBookmarks = (ImageButton) findViewById(R.id.bookmarks); + mHomeTab = (ImageButton) findViewById(R.id.gotohome); + mNewIncognitoTab = (ImageButton) findViewById(R.id.newincognitotab); mNewTab = (ImageButton) findViewById(R.id.newtab); mMore = (ImageButton) findViewById(R.id.more); mBookmarks.setOnClickListener(this); + mHomeTab.setOnClickListener(this); + mNewIncognitoTab.setOnClickListener(this); mNewTab.setOnClickListener(this); mMore.setOnClickListener(this); mScroller = (NavTabScroller) findViewById(R.id.scroller); @@ -143,7 +156,7 @@ public class NavScreen extends RelativeLayout new View.OnClickListener() { @Override public void onClick(View v) { - openNewTab(); + openNewTab(false); } }); } @@ -152,8 +165,10 @@ public class NavScreen extends RelativeLayout public void onClick(View v) { if (mBookmarks == v) { mUiController.bookmarksOrHistoryPicker(ComboViews.Bookmarks); - } else if (mNewTab == v) { - openNewTab(); + } else if (mNewIncognitoTab == v || mNewTab == v) { + openNewTab(mNewIncognitoTab == v); + } else if (mHomeTab == v) { + gotoHomePage(); } else if (mMore == v) { showMenu(); } @@ -170,10 +185,12 @@ public class NavScreen extends RelativeLayout } } - private void openNewTab() { + private void openNewTab(boolean incognito) { // need to call openTab explicitely with setactive false - final Tab tab = mUiController.openTab(BrowserSettings.getInstance().getHomePage(), - false, false, false); + final Tab tab = incognito ? + mUiController.openIncognitoTab() : + mUiController.openTab(BrowserSettings.getInstance().getHomePage(), + false, false, false); if (tab != null) { mUiController.setBlockEvents(true); final int tix = mUi.mTabControl.getTabPosition(tab); @@ -191,6 +208,43 @@ public class NavScreen extends RelativeLayout } } + private void gotoHomePage() { + final Tab tab = findCenteredTab(); + if (tab != null) { + mUiController.setBlockEvents(true); + final int tix = mUi.mTabControl.getTabPosition(tab); + mScroller.setOnLayoutListener(new OnLayoutListener() { + @Override + public void onLayout(int l, int t, int r, int b) { + mUi.hideNavScreen(tix, true); + switchToTab(tab); + } + }); + mScroller.handleDataChanged(tix); + mUiController.setBlockEvents(false); + mUiController.loadUrl(tab, + BrowserSettings.getInstance().getHomePage()); + } + } + + private Tab findCenteredTab(){ + View v = mOrientation == Configuration.ORIENTATION_LANDSCAPE ? + mScroller.findViewAt(mSize.y/2, mSize.x/2): + mScroller.findViewAt(mSize.x/2, mSize.y/2); + if( v != null && v instanceof NavTabView ){ + Long tabId = ((NavTabView)v).getWebViewId(); + if( tabId != null ){ + List<Tab> tabs = mUiController.getTabs(); + for( int i=0; i<tabs.size(); i++ ){ + if( tabs.get(i).getId() == tabId.longValue() ) { + return tabs.get(i); + } + } + } + } + return null; + } + private void switchToTab(Tab tab) { if (tab != mUi.getActiveTab()) { mUiController.setActiveTab(tab); diff --git a/src/com/android/browser/NavTabView.java b/src/com/android/browser/NavTabView.java index 91f074c10..de50317a9 100644 --- a/src/com/android/browser/NavTabView.java +++ b/src/com/android/browser/NavTabView.java @@ -107,6 +107,11 @@ public class NavTabView extends LinearLayout { return mHighlighted; } + protected Long getWebViewId(){ + if(mTab == null) return null; + return new Long(mTab.getId()); + } + protected void setWebView(Tab tab) { mTab = tab; setTitle(); |