blob: e5f76ff87a9e13c42aa0e2332680318d0c811709 [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;
Pankaj Garg32e1b942015-06-03 18:13:24 -070020import android.graphics.Bitmap;
Michael Kolb2814a362011-05-19 15:49:41 -070021import android.graphics.drawable.Drawable;
Pankaj Garg32e1b942015-06-03 18:13:24 -070022import android.os.Bundle;
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070023import android.os.Handler;
24import android.os.Message;
John Reck0f602f32011-07-07 15:38:43 -070025import android.util.AttributeSet;
Enrico Ros1f5a0952014-11-18 20:15:48 -080026import android.util.TypedValue;
Michael Kolb11d19782011-03-20 10:17:40 -070027import android.view.View;
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070028
Pankaj Garg32e1b942015-06-03 18:13:24 -070029import org.codeaurora.swe.Engine;
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070030import org.codeaurora.swe.WebRefiner;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080031import org.codeaurora.swe.WebView;
Enrico Ros1f5a0952014-11-18 20:15:48 -080032import org.codeaurora.swe.util.Activator;
33import org.codeaurora.swe.util.Observable;
Michael Kolb11d19782011-03-20 10:17:40 -070034
Enrico Ros1f5a0952014-11-18 20:15:48 -080035import android.widget.ImageView;
36import android.widget.TextView;
Bijan Amirzada41242f22014-03-21 12:12:18 -070037import com.android.browser.UrlInputView.StateListener;
Pankaj Garg32e1b942015-06-03 18:13:24 -070038import com.android.browser.preferences.AboutPreferencesFragment;
39import com.android.browser.preferences.SiteSpecificPreferencesFragment;
40
41import java.io.ByteArrayOutputStream;
Michael Kolb305b1c52011-06-21 16:16:22 -070042
John Reck0f602f32011-07-07 15:38:43 -070043public class NavigationBarPhone extends NavigationBarBase implements
Enrico Ros1f5a0952014-11-18 20:15:48 -080044 StateListener {
Michael Kolb11d19782011-03-20 10:17:40 -070045
Michael Kolbc16c5952011-03-29 15:37:03 -070046 private ImageView mStopButton;
Michael Kolb94ec5272011-08-31 16:23:57 -070047 private ImageView mMagnify;
48 private ImageView mClearButton;
Michael Kolb0b129122012-06-04 16:31:58 -070049 private ImageView mVoiceButton;
Michael Kolb2814a362011-05-19 15:49:41 -070050 private Drawable mStopDrawable;
51 private Drawable mRefreshDrawable;
Michael Kolb30adae62011-07-29 13:37:05 -070052 private String mStopDescription;
53 private String mRefreshDescription;
John Reck8ac42902011-06-29 16:14:34 -070054 private View mTabSwitcher;
Enrico Ros1f5a0952014-11-18 20:15:48 -080055 private TextView mTabText;
Michael Kolb305b1c52011-06-21 16:16:22 -070056 private View mComboIcon;
John Reck419f6b42011-08-16 16:10:51 -070057 private View mIncognitoIcon;
Enrico Ros1f5a0952014-11-18 20:15:48 -080058 private float mTabSwitcherInitialTextSize = 0;
59 private float mTabSwitcherCompressedTextSize = 0;
60
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070061 private static final int MSG_UPDATE_NOTIFICATION_COUNTER = 4242;
62 private static final int NOTIFICATION_COUNTER_UPDATE_DELAY = 3000;
63 private TextView mNotificationCounter;
64 private Handler mHandler;
Michael Kolb11d19782011-03-20 10:17:40 -070065
John Reck0f602f32011-07-07 15:38:43 -070066 public NavigationBarPhone(Context context) {
67 super(context);
68 }
69
70 public NavigationBarPhone(Context context, AttributeSet attrs) {
71 super(context, attrs);
72 }
73
74 public NavigationBarPhone(Context context, AttributeSet attrs, int defStyle) {
75 super(context, attrs, defStyle);
Michael Kolb11d19782011-03-20 10:17:40 -070076 }
77
78 @Override
John Reck0f602f32011-07-07 15:38:43 -070079 protected void onFinishInflate() {
80 super.onFinishInflate();
Michael Kolbc16c5952011-03-29 15:37:03 -070081 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolb11d19782011-03-20 10:17:40 -070082 mStopButton.setOnClickListener(this);
Michael Kolb94ec5272011-08-31 16:23:57 -070083 mClearButton = (ImageView) findViewById(R.id.clear);
84 mClearButton.setOnClickListener(this);
Michael Kolb0b129122012-06-04 16:31:58 -070085 mVoiceButton = (ImageView) findViewById(R.id.voice);
86 mVoiceButton.setOnClickListener(this);
Michael Kolb94ec5272011-08-31 16:23:57 -070087 mMagnify = (ImageView) findViewById(R.id.magnify);
John Reck8ac42902011-06-29 16:14:34 -070088 mTabSwitcher = findViewById(R.id.tab_switcher);
89 mTabSwitcher.setOnClickListener(this);
Enrico Ros1f5a0952014-11-18 20:15:48 -080090 mTabText = (TextView) findViewById(R.id.tab_switcher_text);
Michael Kolb305b1c52011-06-21 16:16:22 -070091 mComboIcon = findViewById(R.id.iconcombo);
Michael Kolb315d5022011-10-13 12:47:11 -070092 mComboIcon.setOnClickListener(this);
Michael Kolb11d19782011-03-20 10:17:40 -070093 setFocusState(false);
John Reck0f602f32011-07-07 15:38:43 -070094 Resources res = getContext().getResources();
Enrico Ros1f5a0952014-11-18 20:15:48 -080095 mStopDrawable = res.getDrawable(R.drawable.ic_action_stop);
96 mRefreshDrawable = res.getDrawable(R.drawable.ic_action_reload);
Michael Kolb30adae62011-07-29 13:37:05 -070097 mStopDescription = res.getString(R.string.accessibility_button_stop);
98 mRefreshDescription = res.getString(R.string.accessibility_button_refresh);
John Reck67f33632011-06-17 16:23:42 -070099 mUrlInput.setContainer(this);
Michael Kolb305b1c52011-06-21 16:16:22 -0700100 mUrlInput.setStateListener(this);
John Reck419f6b42011-08-16 16:10:51 -0700101 mIncognitoIcon = findViewById(R.id.incognito_icon);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800102
103 if (mTabSwitcherInitialTextSize == 0) {
104 mTabSwitcherInitialTextSize = mTabText.getTextSize();
105 mTabSwitcherCompressedTextSize = (float) (mTabSwitcherInitialTextSize / 1.2);
106 }
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -0700107
108 mNotificationCounter = (TextView) findViewById(R.id.notification_counter);
109 mHandler = new Handler() {
110 @Override
111 public void handleMessage(Message m) {
112 switch (m.what) {
113 case MSG_UPDATE_NOTIFICATION_COUNTER:
114 WebView wv = mUiController.getCurrentTopWebView();
115 if (wv != null && WebRefiner.isInitialized()) {
116 int count = WebRefiner.getInstance().getBlockedURLCount(wv);
117 if (count > 0) {
118 mNotificationCounter.setText(String.valueOf(count));
119 mNotificationCounter.setVisibility(View.VISIBLE);
120 }
121 }
122 mHandler.sendEmptyMessageDelayed(MSG_UPDATE_NOTIFICATION_COUNTER, NOTIFICATION_COUNTER_UPDATE_DELAY);
123 break;
124 }
125 }
126 };
Enrico Ros1f5a0952014-11-18 20:15:48 -0800127 }
128
129 @Override
130 public void setTitleBar(TitleBar titleBar) {
131 super.setTitleBar(titleBar);
132 Activator.activate(
133 new Observable.Observer() {
134 @Override
135 public void onChange(Object... params) {
136 if ((Integer)params[0] > 9) {
137 mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabSwitcherCompressedTextSize);
138 } else {
139 mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabSwitcherInitialTextSize);
140 }
141
142 mTabText.setText(Integer.toString((Integer) params[0]));
143 }
144 },
145 mUiController.getTabControl().getTabCountObservable());
Michael Kolb11d19782011-03-20 10:17:40 -0700146 }
147
148 @Override
John Reck0f602f32011-07-07 15:38:43 -0700149 public void onProgressStarted() {
150 super.onProgressStarted();
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -0700151 /*if (mStopButton.getDrawable() != mStopDrawable) {
John Reck0f602f32011-07-07 15:38:43 -0700152 mStopButton.setImageDrawable(mStopDrawable);
Michael Kolb30adae62011-07-29 13:37:05 -0700153 mStopButton.setContentDescription(mStopDescription);
John Reck0f602f32011-07-07 15:38:43 -0700154 if (mStopButton.getVisibility() != View.VISIBLE) {
155 mComboIcon.setVisibility(View.GONE);
156 mStopButton.setVisibility(View.VISIBLE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700157 }
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -0700158 }*/
Pankaj Garg32e1b942015-06-03 18:13:24 -0700159 mFaviconBadge.setImageResource(R.drawable.ic_fav_overlay_normal);
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -0700160 mNotificationCounter.setVisibility(View.INVISIBLE);
161 mHandler.removeMessages(MSG_UPDATE_NOTIFICATION_COUNTER);
162 mHandler.sendEmptyMessageDelayed(MSG_UPDATE_NOTIFICATION_COUNTER, NOTIFICATION_COUNTER_UPDATE_DELAY);
John Reck0f602f32011-07-07 15:38:43 -0700163 }
164
165 @Override
166 public void onProgressStopped() {
167 super.onProgressStopped();
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -0700168 //mStopButton.setImageDrawable(mRefreshDrawable);
169 //mStopButton.setContentDescription(mRefreshDescription);
John Reck0f602f32011-07-07 15:38:43 -0700170 if (!isEditingUrl()) {
171 mComboIcon.setVisibility(View.VISIBLE);
Michael Kolb2814a362011-05-19 15:49:41 -0700172 }
Michael Kolb5e8f2b92011-07-19 13:22:32 -0700173 onStateChanged(mUrlInput.getState());
Michael Kolb2814a362011-05-19 15:49:41 -0700174 }
175
Michael Kolb11d19782011-03-20 10:17:40 -0700176 /**
177 * Update the text displayed in the title bar.
178 * @param title String to display. If null, the new tab string will be
179 * shown.
180 */
181 @Override
182 void setDisplayTitle(String title) {
John Reck434e9f82011-08-10 18:16:52 -0700183 mUrlInput.setTag(title);
John Reck67f33632011-06-17 16:23:42 -0700184 if (!isEditingUrl()) {
Vivek Sekhar60dca802014-06-27 14:48:30 -0700185 // add for carrier requirement - show title from native instead of url
186 Tab currentTab = mUiController.getTabControl().getCurrentTab();
Panos Thomas4bdb5252014-11-13 16:20:11 -0800187 if (BrowserConfig.getInstance(getContext())
188 .hasFeature(BrowserConfig.Feature.TITLE_IN_URL_BAR) &&
189 currentTab != null && currentTab.getTitle() != null) {
Vivek Sekhar60dca802014-06-27 14:48:30 -0700190 mUrlInput.setText(currentTab.getTitle(), false);
191 } else if (title == null) {
John Reck67f33632011-06-17 16:23:42 -0700192 mUrlInput.setText(R.string.new_tab);
193 } else {
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700194 mUrlInput.setText(UrlUtils.stripUrl(title), false);
John Reck67f33632011-06-17 16:23:42 -0700195 }
196 mUrlInput.setSelection(0);
Michael Kolb11d19782011-03-20 10:17:40 -0700197 }
198 }
199
200 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700201 public void onClick(View v) {
202 if (v == mStopButton) {
John Reck0f602f32011-07-07 15:38:43 -0700203 if (mTitleBar.isInLoad()) {
Michael Kolb2814a362011-05-19 15:49:41 -0700204 mUiController.stopLoading();
205 } else {
206 WebView web = mBaseUi.getWebView();
207 if (web != null) {
Michael Kolb305b1c52011-06-21 16:16:22 -0700208 stopEditingUrl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800209 Tab currentTab = mUiController.getTabControl().getCurrentTab();
Michael Kolb2814a362011-05-19 15:49:41 -0700210 web.reload();
211 }
212 }
John Reck8ac42902011-06-29 16:14:34 -0700213 } else if (v == mTabSwitcher) {
Michael Kolb20be26d2011-07-18 16:38:02 -0700214 ((PhoneUi) mBaseUi).toggleNavScreen();
Michael Kolb94ec5272011-08-31 16:23:57 -0700215 } else if (mClearButton == v) {
216 mUrlInput.setText("");
Michael Kolb315d5022011-10-13 12:47:11 -0700217 } else if (mComboIcon == v) {
Pankaj Garg32e1b942015-06-03 18:13:24 -0700218 showSiteSpecificSettings();
Michael Kolb0b129122012-06-04 16:31:58 -0700219 } else if (mVoiceButton == v) {
220 mUiController.startVoiceRecognizer();
Michael Kolb11d19782011-03-20 10:17:40 -0700221 } else {
222 super.onClick(v);
223 }
224 }
225
John Reck58891902011-08-11 17:48:53 -0700226 @Override
John Reck434e9f82011-08-10 18:16:52 -0700227 public void onFocusChange(View view, boolean hasFocus) {
Panos Thomas6ea3a422014-10-09 23:42:59 -0700228 if (view == mUrlInput && !hasFocus) {
229 setDisplayTitle(mUrlInput.getText().toString());
John Reck434e9f82011-08-10 18:16:52 -0700230 }
231 super.onFocusChange(view, hasFocus);
232 }
233
234 @Override
Michael Kolb305b1c52011-06-21 16:16:22 -0700235 public void onStateChanged(int state) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800236 super.onStateChanged(state);
Michael Kolbe721cc32012-06-26 15:26:59 -0700237 mVoiceButton.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700238 switch(state) {
239 case StateListener.STATE_NORMAL:
240 mComboIcon.setVisibility(View.VISIBLE);
241 mStopButton.setVisibility(View.GONE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700242 mClearButton.setVisibility(View.GONE);
243 mMagnify.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700244 mTabSwitcher.setVisibility(View.VISIBLE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800245 mTabText.setVisibility(View.VISIBLE);
Pankaj Garg7b279f62014-08-12 14:47:18 -0700246 if (mUiController != null) {
Vivek Sekharb991edb2014-12-17 18:18:07 -0800247 mUiController.setWindowDimming(0.0f);
Pankaj Garg7b279f62014-08-12 14:47:18 -0700248 }
Michael Kolb305b1c52011-06-21 16:16:22 -0700249 break;
250 case StateListener.STATE_HIGHLIGHTED:
251 mComboIcon.setVisibility(View.GONE);
252 mStopButton.setVisibility(View.VISIBLE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700253 mClearButton.setVisibility(View.GONE);
Michael Kolbe721cc32012-06-26 15:26:59 -0700254 if ((mUiController != null) && mUiController.supportsVoice()) {
255 mVoiceButton.setVisibility(View.VISIBLE);
256 }
Michael Kolb94ec5272011-08-31 16:23:57 -0700257 mMagnify.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700258 mTabSwitcher.setVisibility(View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800259 mTabText.setVisibility(View.GONE);
Pankaj Garg7b279f62014-08-12 14:47:18 -0700260
Panos Thomas6ea3a422014-10-09 23:42:59 -0700261 if (!mUrlInput.getText().toString().equals(mUrlInput.getTag())) {
262 // only change text if different
263 mUrlInput.setText((String) mUrlInput.getTag(), false);
264 mUrlInput.selectAll();
265 }
Pankaj Garg7b279f62014-08-12 14:47:18 -0700266
267 if (mUiController != null) {
268 mUiController.setWindowDimming(0.75f);
269 }
Michael Kolb305b1c52011-06-21 16:16:22 -0700270 break;
271 case StateListener.STATE_EDITED:
272 mComboIcon.setVisibility(View.GONE);
273 mStopButton.setVisibility(View.GONE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700274 mClearButton.setVisibility(View.VISIBLE);
275 mMagnify.setVisibility(View.VISIBLE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700276 mTabSwitcher.setVisibility(View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800277 mTabText.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700278 break;
Michael Kolb2814a362011-05-19 15:49:41 -0700279 }
280 }
John Reck419f6b42011-08-16 16:10:51 -0700281
282 @Override
283 public void onTabDataChanged(Tab tab) {
284 super.onTabDataChanged(tab);
Enrico Rosd6efa972014-12-02 19:49:59 -0800285 boolean isPrivate = tab.isPrivateBrowsingEnabled();
286 mIncognitoIcon.setVisibility(isPrivate ? View.VISIBLE : View.GONE);
287 // change the background to a darker tone to reflect the 'incognito' state
288 setBackgroundColor(getResources().getColor(isPrivate ?
289 R.color.NavigationBarBackgroundIncognito : R.color.NavigationBarBackground));
290
John Reck419f6b42011-08-16 16:10:51 -0700291 }
Michael Kolb11d19782011-03-20 10:17:40 -0700292}