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 | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 36 | private View mNavButtons; |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 37 | private boolean mHideNavButtons; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 38 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 39 | public NavigationBarTablet(Context context) { |
| 40 | super(context); |
| 41 | init(context); |
| 42 | } |
| 43 | |
| 44 | public NavigationBarTablet(Context context, AttributeSet attrs) { |
| 45 | super(context, attrs); |
| 46 | init(context); |
| 47 | } |
| 48 | |
| 49 | public NavigationBarTablet(Context context, AttributeSet attrs, int defStyle) { |
| 50 | super(context, attrs, defStyle); |
| 51 | init(context); |
| 52 | } |
| 53 | |
| 54 | private void init(Context context) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 55 | mHideNavButtons = getResources().getBoolean(R.bool.hide_nav_buttons); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 56 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 57 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 58 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 59 | protected void onFinishInflate() { |
| 60 | super.onFinishInflate(); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 61 | mNavButtons = findViewById(R.id.navbuttons); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 62 | mBackButton = (ImageButton) findViewById(R.id.back); |
| 63 | mForwardButton = (ImageButton) findViewById(R.id.forward); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 64 | mStar = (ImageView) findViewById(R.id.star); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 65 | mUrlContainer = findViewById(R.id.urlbar_focused); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 66 | mBackButton.setOnClickListener(this); |
| 67 | mForwardButton.setOnClickListener(this); |
| 68 | mStar.setOnClickListener(this); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 69 | mUrlInput.setContainer(mUrlContainer); |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 70 | mUrlInput.setStateListener(this); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 73 | public void onConfigurationChanged(Configuration config) { |
| 74 | super.onConfigurationChanged(config); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 75 | Resources res = getContext().getResources(); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 76 | mHideNavButtons = res.getBoolean(R.bool.hide_nav_buttons); |
| 77 | if (mUrlInput.hasFocus()) { |
| 78 | if (mHideNavButtons && (mNavButtons.getVisibility() == View.VISIBLE)) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 79 | hideNavButtons(); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 80 | } else if (!mHideNavButtons && (mNavButtons.getVisibility() == View.GONE)) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 81 | showNavButtons(); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 86 | @Override |
| 87 | public void setTitleBar(TitleBar titleBar) { |
| 88 | super.setTitleBar(titleBar); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 89 | setFocusState(false); |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 92 | void updateNavigationState(Tab tab) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 93 | if (tab != null) { |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 94 | mBackButton.setEnabled(tab.canGoBack()); |
Pankaj Garg | 5ae52a0 | 2014-12-12 11:06:17 -0800 | [diff] [blame] | 95 | mForwardButton.setEnabled(tab.canGoForward()); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 99 | @Override |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 100 | public void onTabDataChanged(Tab tab) { |
| 101 | super.onTabDataChanged(tab); |
| 102 | showHideStar(tab); |
| 103 | } |
| 104 | |
| 105 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 106 | public void setCurrentUrlIsBookmark(boolean isBookmark) { |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 107 | mStar.setActivated(isBookmark); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 108 | } |
| 109 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 110 | @Override |
| 111 | public void onClick(View v) { |
Michael Kolb | c832e5e | 2012-03-09 15:08:23 -0800 | [diff] [blame] | 112 | if ((mBackButton == v) && (mUiController.getCurrentTab() != null)) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 113 | mUiController.getCurrentTab().goBack(); |
Michael Kolb | c832e5e | 2012-03-09 15:08:23 -0800 | [diff] [blame] | 114 | } else if ((mForwardButton == v) && (mUiController.getCurrentTab() != null)) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 115 | mUiController.getCurrentTab().goForward(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 116 | } else if (mStar == v) { |
John Reck | a60fffa | 2011-09-06 16:30:29 -0700 | [diff] [blame] | 117 | Intent intent = mUiController.createBookmarkCurrentPageIntent(true); |
| 118 | if (intent != null) { |
| 119 | getContext().startActivity(intent); |
| 120 | } |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 121 | } else { |
| 122 | super.onClick(v); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 126 | @Override |
| 127 | protected void setFocusState(boolean focus) { |
| 128 | super.setFocusState(focus); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 129 | if (focus) { |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 130 | if (mHideNavButtons) { |
| 131 | hideNavButtons(); |
| 132 | } |
Michael Kolb | 31d469b | 2010-12-09 20:49:54 -0800 | [diff] [blame] | 133 | mStar.setVisibility(View.GONE); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 134 | } else { |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 135 | if (mHideNavButtons) { |
| 136 | showNavButtons(); |
| 137 | } |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 138 | showHideStar(mUiController.getCurrentTab()); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 142 | private void hideNavButtons() { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 143 | int aw = mNavButtons.getMeasuredWidth(); |
| 144 | mNavButtons.setVisibility(View.GONE); |
| 145 | mNavButtons.setAlpha(0f); |
| 146 | mNavButtons.setTranslationX(-aw); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | private void showNavButtons() { |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 150 | mNavButtons.setVisibility(View.VISIBLE); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 151 | mNavButtons.setAlpha(1f); |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 152 | mNavButtons.setTranslationX(0); |
Michael Kolb | de46376 | 2011-07-14 15:25:45 -0700 | [diff] [blame] | 153 | } |
| 154 | |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 155 | private void showHideStar(Tab tab) { |
| 156 | // hide the bookmark star for data URLs |
| 157 | if (tab != null && tab.inForeground()) { |
| 158 | int starVisibility = View.VISIBLE; |
| 159 | String url = tab.getUrl(); |
| 160 | if (DataUri.isDataUri(url)) { |
| 161 | starVisibility = View.GONE; |
| 162 | } |
| 163 | mStar.setVisibility(starVisibility); |
| 164 | } |
| 165 | } |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 166 | } |