Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 1 | /* |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 16 | package com.android.browser; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 17 | |
| 18 | import android.content.Context; |
John Reck | a60fffa | 2011-09-06 16:30:29 -0700 | [diff] [blame] | 19 | import android.content.Intent; |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 21 | import android.content.res.Resources; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 22 | import android.util.AttributeSet; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 23 | import android.view.View; |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 24 | import android.widget.ImageButton; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 25 | import android.widget.ImageView; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 26 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 27 | import com.android.browser.UI.ComboViews; |
| 28 | import com.android.browser.UrlInputView.StateListener; |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 29 | |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 30 | public class NavigationBarTablet extends NavigationBarBase implements StateListener { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 31 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 32 | private View mUrlContainer; |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 33 | private ImageButton mBackButton; |
| 34 | private ImageButton mForwardButton; |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 35 | private ImageView mStar; |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 36 | private ImageView mSearchButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 37 | private View mAllButton; |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 38 | private View mNavButtons; |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 39 | private boolean mHideNavButtons; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 40 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 41 | public NavigationBarTablet(Context context) { |
| 42 | super(context); |
| 43 | init(context); |
| 44 | } |
| 45 | |
| 46 | public NavigationBarTablet(Context context, AttributeSet attrs) { |
| 47 | super(context, attrs); |
| 48 | init(context); |
| 49 | } |
| 50 | |
| 51 | public NavigationBarTablet(Context context, AttributeSet attrs, int defStyle) { |
| 52 | super(context, attrs, defStyle); |
| 53 | init(context); |
| 54 | } |
| 55 | |
| 56 | private void init(Context context) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 57 | mHideNavButtons = getResources().getBoolean(R.bool.hide_nav_buttons); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 58 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 59 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 60 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 61 | protected void onFinishInflate() { |
| 62 | super.onFinishInflate(); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 63 | mAllButton = findViewById(R.id.all_btn); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 64 | mNavButtons = findViewById(R.id.navbuttons); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 65 | mBackButton = (ImageButton) findViewById(R.id.back); |
| 66 | mForwardButton = (ImageButton) findViewById(R.id.forward); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 67 | mStar = (ImageView) findViewById(R.id.star); |
Michael Kolb | e3524d8 | 2011-03-02 14:53:15 -0800 | [diff] [blame] | 68 | mSearchButton = (ImageView) findViewById(R.id.search); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 69 | mUrlContainer = findViewById(R.id.urlbar_focused); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 70 | mBackButton.setOnClickListener(this); |
| 71 | mForwardButton.setOnClickListener(this); |
| 72 | mStar.setOnClickListener(this); |
| 73 | mAllButton.setOnClickListener(this); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 74 | mSearchButton.setOnClickListener(this); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 75 | mUrlInput.setContainer(mUrlContainer); |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 76 | mUrlInput.setStateListener(this); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 79 | public void onConfigurationChanged(Configuration config) { |
| 80 | super.onConfigurationChanged(config); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 81 | Resources res = getContext().getResources(); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 82 | mHideNavButtons = res.getBoolean(R.bool.hide_nav_buttons); |
| 83 | if (mUrlInput.hasFocus()) { |
| 84 | if (mHideNavButtons && (mNavButtons.getVisibility() == View.VISIBLE)) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 85 | hideNavButtons(); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 86 | } else if (!mHideNavButtons && (mNavButtons.getVisibility() == View.GONE)) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 87 | showNavButtons(); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 92 | @Override |
| 93 | public void setTitleBar(TitleBar titleBar) { |
| 94 | super.setTitleBar(titleBar); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 95 | setFocusState(false); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 98 | void updateNavigationState(Tab tab) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 99 | if (tab != null) { |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 100 | mBackButton.setEnabled(tab.canGoBack()); |
Pankaj Garg | 5ae52a0 | 2014-12-12 11:06:17 -0800 | [diff] [blame] | 101 | mForwardButton.setEnabled(tab.canGoForward()); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 105 | @Override |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 106 | public void onTabDataChanged(Tab tab) { |
| 107 | super.onTabDataChanged(tab); |
| 108 | showHideStar(tab); |
| 109 | } |
| 110 | |
| 111 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 112 | public void setCurrentUrlIsBookmark(boolean isBookmark) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 113 | mStar.setActivated(isBookmark); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 116 | @Override |
| 117 | public void onClick(View v) { |
Michael Kolb | c832e5e | 2012-03-09 15:08:23 -0800 | [diff] [blame] | 118 | if ((mBackButton == v) && (mUiController.getCurrentTab() != null)) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 119 | mUiController.getCurrentTab().goBack(); |
Michael Kolb | c832e5e | 2012-03-09 15:08:23 -0800 | [diff] [blame] | 120 | } else if ((mForwardButton == v) && (mUiController.getCurrentTab() != null)) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 121 | mUiController.getCurrentTab().goForward(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 122 | } else if (mStar == v) { |
John Reck | a60fffa | 2011-09-06 16:30:29 -0700 | [diff] [blame] | 123 | Intent intent = mUiController.createBookmarkCurrentPageIntent(true); |
| 124 | if (intent != null) { |
| 125 | getContext().startActivity(intent); |
| 126 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 127 | } else if (mAllButton == v) { |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 128 | mUiController.bookmarksOrHistoryPicker(ComboViews.Bookmarks); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 129 | } else if (mSearchButton == v) { |
Michael Kolb | 5ff5c8b | 2012-05-03 11:37:58 -0700 | [diff] [blame] | 130 | mBaseUi.editUrl(true, true); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 131 | } else { |
| 132 | super.onClick(v); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 136 | @Override |
| 137 | protected void setFocusState(boolean focus) { |
| 138 | super.setFocusState(focus); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 139 | if (focus) { |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 140 | if (mHideNavButtons) { |
| 141 | hideNavButtons(); |
| 142 | } |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 143 | mSearchButton.setVisibility(View.GONE); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 144 | mStar.setVisibility(View.GONE); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 145 | } else { |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 146 | if (mHideNavButtons) { |
| 147 | showNavButtons(); |
| 148 | } |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 149 | showHideStar(mUiController.getCurrentTab()); |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 150 | mSearchButton.setVisibility(View.VISIBLE); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 154 | private void hideNavButtons() { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 155 | int aw = mNavButtons.getMeasuredWidth(); |
| 156 | mNavButtons.setVisibility(View.GONE); |
| 157 | mNavButtons.setAlpha(0f); |
| 158 | mNavButtons.setTranslationX(-aw); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | private void showNavButtons() { |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 162 | mNavButtons.setVisibility(View.VISIBLE); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 163 | mNavButtons.setAlpha(1f); |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 164 | mNavButtons.setTranslationX(0); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 165 | } |
| 166 | |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 167 | private void showHideStar(Tab tab) { |
| 168 | // hide the bookmark star for data URLs |
| 169 | if (tab != null && tab.inForeground()) { |
| 170 | int starVisibility = View.VISIBLE; |
| 171 | String url = tab.getUrl(); |
| 172 | if (DataUri.isDataUri(url)) { |
| 173 | starVisibility = View.GONE; |
| 174 | } |
| 175 | mStar.setVisibility(starVisibility); |
| 176 | } |
| 177 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 178 | } |