blob: cb6f7fc63bf08c548c28fafcf58689fce735f6a9 [file] [log] [blame]
Michael Kolb11d19782011-03-20 10:17:40 -07001/*
John Reck0f602f32011-07-07 15:38:43 -07002 * Copyright (C) 2011 The Android Open Source Project
Michael Kolb11d19782011-03-20 10:17:40 -07003 *
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 Amirzada41242f22014-03-21 12:12:18 -070016package com.android.browser;
Michael Kolb11d19782011-03-20 10:17:40 -070017
Michael Kolb11d19782011-03-20 10:17:40 -070018import android.content.Context;
Michael Kolb2814a362011-05-19 15:49:41 -070019import android.content.res.Resources;
20import android.graphics.drawable.Drawable;
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070021import android.os.Handler;
22import android.os.Message;
John Reck0f602f32011-07-07 15:38:43 -070023import android.util.AttributeSet;
Enrico Ros1f5a0952014-11-18 20:15:48 -080024import android.util.TypedValue;
Michael Kolb11d19782011-03-20 10:17:40 -070025import android.view.View;
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070026
27import org.codeaurora.swe.WebRefiner;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080028import org.codeaurora.swe.WebView;
Enrico Ros1f5a0952014-11-18 20:15:48 -080029import org.codeaurora.swe.util.Activator;
30import org.codeaurora.swe.util.Observable;
Michael Kolb11d19782011-03-20 10:17:40 -070031
Enrico Ros1f5a0952014-11-18 20:15:48 -080032import android.widget.ImageView;
33import android.widget.TextView;
Bijan Amirzada41242f22014-03-21 12:12:18 -070034import com.android.browser.UrlInputView.StateListener;
Michael Kolb305b1c52011-06-21 16:16:22 -070035
John Reck0f602f32011-07-07 15:38:43 -070036public class NavigationBarPhone extends NavigationBarBase implements
Enrico Ros1f5a0952014-11-18 20:15:48 -080037 StateListener {
Michael Kolb11d19782011-03-20 10:17:40 -070038
Michael Kolbc16c5952011-03-29 15:37:03 -070039 private ImageView mStopButton;
Michael Kolb94ec5272011-08-31 16:23:57 -070040 private ImageView mMagnify;
41 private ImageView mClearButton;
Michael Kolb0b129122012-06-04 16:31:58 -070042 private ImageView mVoiceButton;
Michael Kolb2814a362011-05-19 15:49:41 -070043 private Drawable mStopDrawable;
44 private Drawable mRefreshDrawable;
Michael Kolb30adae62011-07-29 13:37:05 -070045 private String mStopDescription;
46 private String mRefreshDescription;
John Reck8ac42902011-06-29 16:14:34 -070047 private View mTabSwitcher;
Enrico Ros1f5a0952014-11-18 20:15:48 -080048 private TextView mTabText;
Michael Kolb305b1c52011-06-21 16:16:22 -070049 private View mComboIcon;
John Reck419f6b42011-08-16 16:10:51 -070050 private View mIncognitoIcon;
Enrico Ros1f5a0952014-11-18 20:15:48 -080051 private float mTabSwitcherInitialTextSize = 0;
52 private float mTabSwitcherCompressedTextSize = 0;
53
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070054 private static final int MSG_UPDATE_NOTIFICATION_COUNTER = 4242;
55 private static final int NOTIFICATION_COUNTER_UPDATE_DELAY = 3000;
56 private TextView mNotificationCounter;
57 private Handler mHandler;
Michael Kolb11d19782011-03-20 10:17:40 -070058
John Reck0f602f32011-07-07 15:38:43 -070059 public NavigationBarPhone(Context context) {
60 super(context);
61 }
62
63 public NavigationBarPhone(Context context, AttributeSet attrs) {
64 super(context, attrs);
65 }
66
67 public NavigationBarPhone(Context context, AttributeSet attrs, int defStyle) {
68 super(context, attrs, defStyle);
Michael Kolb11d19782011-03-20 10:17:40 -070069 }
70
71 @Override
John Reck0f602f32011-07-07 15:38:43 -070072 protected void onFinishInflate() {
73 super.onFinishInflate();
Michael Kolbc16c5952011-03-29 15:37:03 -070074 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolb11d19782011-03-20 10:17:40 -070075 mStopButton.setOnClickListener(this);
Michael Kolb94ec5272011-08-31 16:23:57 -070076 mClearButton = (ImageView) findViewById(R.id.clear);
77 mClearButton.setOnClickListener(this);
Michael Kolb0b129122012-06-04 16:31:58 -070078 mVoiceButton = (ImageView) findViewById(R.id.voice);
79 mVoiceButton.setOnClickListener(this);
Michael Kolb94ec5272011-08-31 16:23:57 -070080 mMagnify = (ImageView) findViewById(R.id.magnify);
John Reck8ac42902011-06-29 16:14:34 -070081 mTabSwitcher = findViewById(R.id.tab_switcher);
82 mTabSwitcher.setOnClickListener(this);
Enrico Ros1f5a0952014-11-18 20:15:48 -080083 mTabText = (TextView) findViewById(R.id.tab_switcher_text);
Michael Kolb305b1c52011-06-21 16:16:22 -070084 mComboIcon = findViewById(R.id.iconcombo);
Michael Kolb315d5022011-10-13 12:47:11 -070085 mComboIcon.setOnClickListener(this);
Michael Kolb11d19782011-03-20 10:17:40 -070086 setFocusState(false);
John Reck0f602f32011-07-07 15:38:43 -070087 Resources res = getContext().getResources();
Enrico Ros1f5a0952014-11-18 20:15:48 -080088 mStopDrawable = res.getDrawable(R.drawable.ic_action_stop);
89 mRefreshDrawable = res.getDrawable(R.drawable.ic_action_reload);
Michael Kolb30adae62011-07-29 13:37:05 -070090 mStopDescription = res.getString(R.string.accessibility_button_stop);
91 mRefreshDescription = res.getString(R.string.accessibility_button_refresh);
John Reck67f33632011-06-17 16:23:42 -070092 mUrlInput.setContainer(this);
Michael Kolb305b1c52011-06-21 16:16:22 -070093 mUrlInput.setStateListener(this);
John Reck419f6b42011-08-16 16:10:51 -070094 mIncognitoIcon = findViewById(R.id.incognito_icon);
Enrico Ros1f5a0952014-11-18 20:15:48 -080095
96 if (mTabSwitcherInitialTextSize == 0) {
97 mTabSwitcherInitialTextSize = mTabText.getTextSize();
98 mTabSwitcherCompressedTextSize = (float) (mTabSwitcherInitialTextSize / 1.2);
99 }
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -0700100
101 mNotificationCounter = (TextView) findViewById(R.id.notification_counter);
102 mHandler = new Handler() {
103 @Override
104 public void handleMessage(Message m) {
105 switch (m.what) {
106 case MSG_UPDATE_NOTIFICATION_COUNTER:
107 WebView wv = mUiController.getCurrentTopWebView();
108 if (wv != null && WebRefiner.isInitialized()) {
109 int count = WebRefiner.getInstance().getBlockedURLCount(wv);
110 if (count > 0) {
111 mNotificationCounter.setText(String.valueOf(count));
112 mNotificationCounter.setVisibility(View.VISIBLE);
113 }
114 }
115 mHandler.sendEmptyMessageDelayed(MSG_UPDATE_NOTIFICATION_COUNTER, NOTIFICATION_COUNTER_UPDATE_DELAY);
116 break;
117 }
118 }
119 };
Enrico Ros1f5a0952014-11-18 20:15:48 -0800120 }
121
122 @Override
123 public void setTitleBar(TitleBar titleBar) {
124 super.setTitleBar(titleBar);
125 Activator.activate(
126 new Observable.Observer() {
127 @Override
128 public void onChange(Object... params) {
129 if ((Integer)params[0] > 9) {
130 mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabSwitcherCompressedTextSize);
131 } else {
132 mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabSwitcherInitialTextSize);
133 }
134
135 mTabText.setText(Integer.toString((Integer) params[0]));
136 }
137 },
138 mUiController.getTabControl().getTabCountObservable());
Michael Kolb11d19782011-03-20 10:17:40 -0700139 }
140
141 @Override
John Reck0f602f32011-07-07 15:38:43 -0700142 public void onProgressStarted() {
143 super.onProgressStarted();
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -0700144 /*if (mStopButton.getDrawable() != mStopDrawable) {
John Reck0f602f32011-07-07 15:38:43 -0700145 mStopButton.setImageDrawable(mStopDrawable);
Michael Kolb30adae62011-07-29 13:37:05 -0700146 mStopButton.setContentDescription(mStopDescription);
John Reck0f602f32011-07-07 15:38:43 -0700147 if (mStopButton.getVisibility() != View.VISIBLE) {
148 mComboIcon.setVisibility(View.GONE);
149 mStopButton.setVisibility(View.VISIBLE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700150 }
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -0700151 }*/
152 mNotificationCounter.setVisibility(View.INVISIBLE);
153 mHandler.removeMessages(MSG_UPDATE_NOTIFICATION_COUNTER);
154 mHandler.sendEmptyMessageDelayed(MSG_UPDATE_NOTIFICATION_COUNTER, NOTIFICATION_COUNTER_UPDATE_DELAY);
John Reck0f602f32011-07-07 15:38:43 -0700155 }
156
157 @Override
158 public void onProgressStopped() {
159 super.onProgressStopped();
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -0700160 //mStopButton.setImageDrawable(mRefreshDrawable);
161 //mStopButton.setContentDescription(mRefreshDescription);
John Reck0f602f32011-07-07 15:38:43 -0700162 if (!isEditingUrl()) {
163 mComboIcon.setVisibility(View.VISIBLE);
Michael Kolb2814a362011-05-19 15:49:41 -0700164 }
Michael Kolb5e8f2b92011-07-19 13:22:32 -0700165 onStateChanged(mUrlInput.getState());
Michael Kolb2814a362011-05-19 15:49:41 -0700166 }
167
Michael Kolb11d19782011-03-20 10:17:40 -0700168 /**
169 * Update the text displayed in the title bar.
170 * @param title String to display. If null, the new tab string will be
171 * shown.
172 */
173 @Override
174 void setDisplayTitle(String title) {
John Reck434e9f82011-08-10 18:16:52 -0700175 mUrlInput.setTag(title);
John Reck67f33632011-06-17 16:23:42 -0700176 if (!isEditingUrl()) {
Vivek Sekhar60dca802014-06-27 14:48:30 -0700177 // add for carrier requirement - show title from native instead of url
178 Tab currentTab = mUiController.getTabControl().getCurrentTab();
Panos Thomas4bdb5252014-11-13 16:20:11 -0800179 if (BrowserConfig.getInstance(getContext())
180 .hasFeature(BrowserConfig.Feature.TITLE_IN_URL_BAR) &&
181 currentTab != null && currentTab.getTitle() != null) {
Vivek Sekhar60dca802014-06-27 14:48:30 -0700182 mUrlInput.setText(currentTab.getTitle(), false);
183 } else if (title == null) {
John Reck67f33632011-06-17 16:23:42 -0700184 mUrlInput.setText(R.string.new_tab);
185 } else {
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700186 mUrlInput.setText(UrlUtils.stripUrl(title), false);
John Reck67f33632011-06-17 16:23:42 -0700187 }
188 mUrlInput.setSelection(0);
Michael Kolb11d19782011-03-20 10:17:40 -0700189 }
190 }
191
192 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700193 public void onClick(View v) {
194 if (v == mStopButton) {
John Reck0f602f32011-07-07 15:38:43 -0700195 if (mTitleBar.isInLoad()) {
Michael Kolb2814a362011-05-19 15:49:41 -0700196 mUiController.stopLoading();
197 } else {
198 WebView web = mBaseUi.getWebView();
199 if (web != null) {
Michael Kolb305b1c52011-06-21 16:16:22 -0700200 stopEditingUrl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800201 Tab currentTab = mUiController.getTabControl().getCurrentTab();
Michael Kolb2814a362011-05-19 15:49:41 -0700202 web.reload();
203 }
204 }
John Reck8ac42902011-06-29 16:14:34 -0700205 } else if (v == mTabSwitcher) {
Michael Kolb20be26d2011-07-18 16:38:02 -0700206 ((PhoneUi) mBaseUi).toggleNavScreen();
Michael Kolb94ec5272011-08-31 16:23:57 -0700207 } else if (mClearButton == v) {
208 mUrlInput.setText("");
Michael Kolb315d5022011-10-13 12:47:11 -0700209 } else if (mComboIcon == v) {
210 mUiController.showPageInfo();
Michael Kolb0b129122012-06-04 16:31:58 -0700211 } else if (mVoiceButton == v) {
212 mUiController.startVoiceRecognizer();
Michael Kolb11d19782011-03-20 10:17:40 -0700213 } else {
214 super.onClick(v);
215 }
216 }
217
John Reck58891902011-08-11 17:48:53 -0700218 @Override
John Reck434e9f82011-08-10 18:16:52 -0700219 public void onFocusChange(View view, boolean hasFocus) {
Panos Thomas6ea3a422014-10-09 23:42:59 -0700220 if (view == mUrlInput && !hasFocus) {
221 setDisplayTitle(mUrlInput.getText().toString());
John Reck434e9f82011-08-10 18:16:52 -0700222 }
223 super.onFocusChange(view, hasFocus);
224 }
225
226 @Override
Michael Kolb305b1c52011-06-21 16:16:22 -0700227 public void onStateChanged(int state) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800228 super.onStateChanged(state);
Michael Kolbe721cc32012-06-26 15:26:59 -0700229 mVoiceButton.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700230 switch(state) {
231 case StateListener.STATE_NORMAL:
232 mComboIcon.setVisibility(View.VISIBLE);
233 mStopButton.setVisibility(View.GONE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700234 mClearButton.setVisibility(View.GONE);
235 mMagnify.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700236 mTabSwitcher.setVisibility(View.VISIBLE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800237 mTabText.setVisibility(View.VISIBLE);
Pankaj Garg7b279f62014-08-12 14:47:18 -0700238 if (mUiController != null) {
Vivek Sekharb991edb2014-12-17 18:18:07 -0800239 mUiController.setWindowDimming(0.0f);
Pankaj Garg7b279f62014-08-12 14:47:18 -0700240 }
Michael Kolb305b1c52011-06-21 16:16:22 -0700241 break;
242 case StateListener.STATE_HIGHLIGHTED:
243 mComboIcon.setVisibility(View.GONE);
244 mStopButton.setVisibility(View.VISIBLE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700245 mClearButton.setVisibility(View.GONE);
Michael Kolbe721cc32012-06-26 15:26:59 -0700246 if ((mUiController != null) && mUiController.supportsVoice()) {
247 mVoiceButton.setVisibility(View.VISIBLE);
248 }
Michael Kolb94ec5272011-08-31 16:23:57 -0700249 mMagnify.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700250 mTabSwitcher.setVisibility(View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800251 mTabText.setVisibility(View.GONE);
Pankaj Garg7b279f62014-08-12 14:47:18 -0700252
Panos Thomas6ea3a422014-10-09 23:42:59 -0700253 if (!mUrlInput.getText().toString().equals(mUrlInput.getTag())) {
254 // only change text if different
255 mUrlInput.setText((String) mUrlInput.getTag(), false);
256 mUrlInput.selectAll();
257 }
Pankaj Garg7b279f62014-08-12 14:47:18 -0700258
259 if (mUiController != null) {
260 mUiController.setWindowDimming(0.75f);
261 }
Michael Kolb305b1c52011-06-21 16:16:22 -0700262 break;
263 case StateListener.STATE_EDITED:
264 mComboIcon.setVisibility(View.GONE);
265 mStopButton.setVisibility(View.GONE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700266 mClearButton.setVisibility(View.VISIBLE);
267 mMagnify.setVisibility(View.VISIBLE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700268 mTabSwitcher.setVisibility(View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800269 mTabText.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700270 break;
Michael Kolb2814a362011-05-19 15:49:41 -0700271 }
272 }
John Reck419f6b42011-08-16 16:10:51 -0700273
274 @Override
275 public void onTabDataChanged(Tab tab) {
276 super.onTabDataChanged(tab);
Enrico Rosd6efa972014-12-02 19:49:59 -0800277 boolean isPrivate = tab.isPrivateBrowsingEnabled();
278 mIncognitoIcon.setVisibility(isPrivate ? View.VISIBLE : View.GONE);
279 // change the background to a darker tone to reflect the 'incognito' state
280 setBackgroundColor(getResources().getColor(isPrivate ?
281 R.color.NavigationBarBackgroundIncognito : R.color.NavigationBarBackground));
282
John Reck419f6b42011-08-16 16:10:51 -0700283 }
Michael Kolb11d19782011-03-20 10:17:40 -0700284}