blob: b07f0358c71f07c40daf49d84cd1e80999da6e3c [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;
John Reck0f602f32011-07-07 15:38:43 -070021import android.util.AttributeSet;
Enrico Ros1f5a0952014-11-18 20:15:48 -080022import android.util.TypedValue;
Michael Kolb11d19782011-03-20 10:17:40 -070023import android.view.View;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080024import org.codeaurora.swe.WebView;
Enrico Ros1f5a0952014-11-18 20:15:48 -080025import org.codeaurora.swe.util.Activator;
26import org.codeaurora.swe.util.Observable;
Michael Kolb11d19782011-03-20 10:17:40 -070027
Enrico Ros1f5a0952014-11-18 20:15:48 -080028import android.widget.ImageView;
29import android.widget.TextView;
Bijan Amirzada41242f22014-03-21 12:12:18 -070030import com.android.browser.UrlInputView.StateListener;
Michael Kolb305b1c52011-06-21 16:16:22 -070031
John Reck0f602f32011-07-07 15:38:43 -070032public class NavigationBarPhone extends NavigationBarBase implements
Enrico Ros1f5a0952014-11-18 20:15:48 -080033 StateListener {
Michael Kolb11d19782011-03-20 10:17:40 -070034
Michael Kolbc16c5952011-03-29 15:37:03 -070035 private ImageView mStopButton;
Michael Kolb94ec5272011-08-31 16:23:57 -070036 private ImageView mMagnify;
37 private ImageView mClearButton;
Michael Kolb0b129122012-06-04 16:31:58 -070038 private ImageView mVoiceButton;
Michael Kolb2814a362011-05-19 15:49:41 -070039 private Drawable mStopDrawable;
40 private Drawable mRefreshDrawable;
Michael Kolb30adae62011-07-29 13:37:05 -070041 private String mStopDescription;
42 private String mRefreshDescription;
John Reck8ac42902011-06-29 16:14:34 -070043 private View mTabSwitcher;
Enrico Ros1f5a0952014-11-18 20:15:48 -080044 private TextView mTabText;
Michael Kolb305b1c52011-06-21 16:16:22 -070045 private View mComboIcon;
John Reck419f6b42011-08-16 16:10:51 -070046 private View mIncognitoIcon;
Enrico Ros1f5a0952014-11-18 20:15:48 -080047 private float mTabSwitcherInitialTextSize = 0;
48 private float mTabSwitcherCompressedTextSize = 0;
49
Michael Kolb11d19782011-03-20 10:17:40 -070050
John Reck0f602f32011-07-07 15:38:43 -070051 public NavigationBarPhone(Context context) {
52 super(context);
53 }
54
55 public NavigationBarPhone(Context context, AttributeSet attrs) {
56 super(context, attrs);
57 }
58
59 public NavigationBarPhone(Context context, AttributeSet attrs, int defStyle) {
60 super(context, attrs, defStyle);
Michael Kolb11d19782011-03-20 10:17:40 -070061 }
62
63 @Override
John Reck0f602f32011-07-07 15:38:43 -070064 protected void onFinishInflate() {
65 super.onFinishInflate();
Michael Kolbc16c5952011-03-29 15:37:03 -070066 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolb11d19782011-03-20 10:17:40 -070067 mStopButton.setOnClickListener(this);
Michael Kolb94ec5272011-08-31 16:23:57 -070068 mClearButton = (ImageView) findViewById(R.id.clear);
69 mClearButton.setOnClickListener(this);
Michael Kolb0b129122012-06-04 16:31:58 -070070 mVoiceButton = (ImageView) findViewById(R.id.voice);
71 mVoiceButton.setOnClickListener(this);
Michael Kolb94ec5272011-08-31 16:23:57 -070072 mMagnify = (ImageView) findViewById(R.id.magnify);
John Reck8ac42902011-06-29 16:14:34 -070073 mTabSwitcher = findViewById(R.id.tab_switcher);
74 mTabSwitcher.setOnClickListener(this);
Enrico Ros1f5a0952014-11-18 20:15:48 -080075 mTabText = (TextView) findViewById(R.id.tab_switcher_text);
Michael Kolb305b1c52011-06-21 16:16:22 -070076 mComboIcon = findViewById(R.id.iconcombo);
Michael Kolb315d5022011-10-13 12:47:11 -070077 mComboIcon.setOnClickListener(this);
Michael Kolb11d19782011-03-20 10:17:40 -070078 setFocusState(false);
John Reck0f602f32011-07-07 15:38:43 -070079 Resources res = getContext().getResources();
Enrico Ros1f5a0952014-11-18 20:15:48 -080080 mStopDrawable = res.getDrawable(R.drawable.ic_action_stop);
81 mRefreshDrawable = res.getDrawable(R.drawable.ic_action_reload);
Michael Kolb30adae62011-07-29 13:37:05 -070082 mStopDescription = res.getString(R.string.accessibility_button_stop);
83 mRefreshDescription = res.getString(R.string.accessibility_button_refresh);
John Reck67f33632011-06-17 16:23:42 -070084 mUrlInput.setContainer(this);
Michael Kolb305b1c52011-06-21 16:16:22 -070085 mUrlInput.setStateListener(this);
John Reck419f6b42011-08-16 16:10:51 -070086 mIncognitoIcon = findViewById(R.id.incognito_icon);
Enrico Ros1f5a0952014-11-18 20:15:48 -080087
88 if (mTabSwitcherInitialTextSize == 0) {
89 mTabSwitcherInitialTextSize = mTabText.getTextSize();
90 mTabSwitcherCompressedTextSize = (float) (mTabSwitcherInitialTextSize / 1.2);
91 }
92 }
93
94 @Override
95 public void setTitleBar(TitleBar titleBar) {
96 super.setTitleBar(titleBar);
97 Activator.activate(
98 new Observable.Observer() {
99 @Override
100 public void onChange(Object... params) {
101 if ((Integer)params[0] > 9) {
102 mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabSwitcherCompressedTextSize);
103 } else {
104 mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabSwitcherInitialTextSize);
105 }
106
107 mTabText.setText(Integer.toString((Integer) params[0]));
108 }
109 },
110 mUiController.getTabControl().getTabCountObservable());
Michael Kolb11d19782011-03-20 10:17:40 -0700111 }
112
113 @Override
John Reck0f602f32011-07-07 15:38:43 -0700114 public void onProgressStarted() {
115 super.onProgressStarted();
116 if (mStopButton.getDrawable() != mStopDrawable) {
117 mStopButton.setImageDrawable(mStopDrawable);
Michael Kolb30adae62011-07-29 13:37:05 -0700118 mStopButton.setContentDescription(mStopDescription);
John Reck0f602f32011-07-07 15:38:43 -0700119 if (mStopButton.getVisibility() != View.VISIBLE) {
120 mComboIcon.setVisibility(View.GONE);
121 mStopButton.setVisibility(View.VISIBLE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700122 }
John Reck0f602f32011-07-07 15:38:43 -0700123 }
124 }
125
126 @Override
127 public void onProgressStopped() {
128 super.onProgressStopped();
John Reck0f602f32011-07-07 15:38:43 -0700129 mStopButton.setImageDrawable(mRefreshDrawable);
Michael Kolb30adae62011-07-29 13:37:05 -0700130 mStopButton.setContentDescription(mRefreshDescription);
John Reck0f602f32011-07-07 15:38:43 -0700131 if (!isEditingUrl()) {
132 mComboIcon.setVisibility(View.VISIBLE);
Michael Kolb2814a362011-05-19 15:49:41 -0700133 }
Michael Kolb5e8f2b92011-07-19 13:22:32 -0700134 onStateChanged(mUrlInput.getState());
Michael Kolb2814a362011-05-19 15:49:41 -0700135 }
136
Michael Kolb11d19782011-03-20 10:17:40 -0700137 /**
138 * Update the text displayed in the title bar.
139 * @param title String to display. If null, the new tab string will be
140 * shown.
141 */
142 @Override
143 void setDisplayTitle(String title) {
John Reck434e9f82011-08-10 18:16:52 -0700144 mUrlInput.setTag(title);
John Reck67f33632011-06-17 16:23:42 -0700145 if (!isEditingUrl()) {
Vivek Sekhar60dca802014-06-27 14:48:30 -0700146 // add for carrier requirement - show title from native instead of url
147 Tab currentTab = mUiController.getTabControl().getCurrentTab();
Panos Thomas4bdb5252014-11-13 16:20:11 -0800148 if (BrowserConfig.getInstance(getContext())
149 .hasFeature(BrowserConfig.Feature.TITLE_IN_URL_BAR) &&
150 currentTab != null && currentTab.getTitle() != null) {
Vivek Sekhar60dca802014-06-27 14:48:30 -0700151 mUrlInput.setText(currentTab.getTitle(), false);
152 } else if (title == null) {
John Reck67f33632011-06-17 16:23:42 -0700153 mUrlInput.setText(R.string.new_tab);
154 } else {
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700155 mUrlInput.setText(UrlUtils.stripUrl(title), false);
John Reck67f33632011-06-17 16:23:42 -0700156 }
157 mUrlInput.setSelection(0);
Michael Kolb11d19782011-03-20 10:17:40 -0700158 }
159 }
160
161 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700162 public void onClick(View v) {
163 if (v == mStopButton) {
John Reck0f602f32011-07-07 15:38:43 -0700164 if (mTitleBar.isInLoad()) {
Michael Kolb2814a362011-05-19 15:49:41 -0700165 mUiController.stopLoading();
166 } else {
167 WebView web = mBaseUi.getWebView();
168 if (web != null) {
Michael Kolb305b1c52011-06-21 16:16:22 -0700169 stopEditingUrl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800170 Tab currentTab = mUiController.getTabControl().getCurrentTab();
171 if (currentTab.hasCrashed) {
172 currentTab.replaceCrashView(web, currentTab.getViewContainer());
173 }
Michael Kolb2814a362011-05-19 15:49:41 -0700174 web.reload();
175 }
176 }
John Reck8ac42902011-06-29 16:14:34 -0700177 } else if (v == mTabSwitcher) {
Michael Kolb20be26d2011-07-18 16:38:02 -0700178 ((PhoneUi) mBaseUi).toggleNavScreen();
Michael Kolb94ec5272011-08-31 16:23:57 -0700179 } else if (mClearButton == v) {
180 mUrlInput.setText("");
Michael Kolb315d5022011-10-13 12:47:11 -0700181 } else if (mComboIcon == v) {
182 mUiController.showPageInfo();
Michael Kolb0b129122012-06-04 16:31:58 -0700183 } else if (mVoiceButton == v) {
184 mUiController.startVoiceRecognizer();
Michael Kolb11d19782011-03-20 10:17:40 -0700185 } else {
186 super.onClick(v);
187 }
188 }
189
John Reck58891902011-08-11 17:48:53 -0700190 @Override
John Reck434e9f82011-08-10 18:16:52 -0700191 public void onFocusChange(View view, boolean hasFocus) {
Panos Thomas6ea3a422014-10-09 23:42:59 -0700192 if (view == mUrlInput && !hasFocus) {
193 setDisplayTitle(mUrlInput.getText().toString());
John Reck434e9f82011-08-10 18:16:52 -0700194 }
195 super.onFocusChange(view, hasFocus);
196 }
197
198 @Override
Michael Kolb305b1c52011-06-21 16:16:22 -0700199 public void onStateChanged(int state) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800200 super.onStateChanged(state);
Michael Kolbe721cc32012-06-26 15:26:59 -0700201 mVoiceButton.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700202 switch(state) {
203 case StateListener.STATE_NORMAL:
204 mComboIcon.setVisibility(View.VISIBLE);
205 mStopButton.setVisibility(View.GONE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700206 mClearButton.setVisibility(View.GONE);
207 mMagnify.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700208 mTabSwitcher.setVisibility(View.VISIBLE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800209 mTabText.setVisibility(View.VISIBLE);
Pankaj Garg7b279f62014-08-12 14:47:18 -0700210 if (mUiController != null) {
211 mUiController.setWindowDimming(0f);
212 }
Michael Kolb305b1c52011-06-21 16:16:22 -0700213 break;
214 case StateListener.STATE_HIGHLIGHTED:
215 mComboIcon.setVisibility(View.GONE);
216 mStopButton.setVisibility(View.VISIBLE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700217 mClearButton.setVisibility(View.GONE);
Michael Kolbe721cc32012-06-26 15:26:59 -0700218 if ((mUiController != null) && mUiController.supportsVoice()) {
219 mVoiceButton.setVisibility(View.VISIBLE);
220 }
Michael Kolb94ec5272011-08-31 16:23:57 -0700221 mMagnify.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700222 mTabSwitcher.setVisibility(View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800223 mTabText.setVisibility(View.GONE);
Pankaj Garg7b279f62014-08-12 14:47:18 -0700224
Panos Thomas6ea3a422014-10-09 23:42:59 -0700225 if (!mUrlInput.getText().toString().equals(mUrlInput.getTag())) {
226 // only change text if different
227 mUrlInput.setText((String) mUrlInput.getTag(), false);
228 mUrlInput.selectAll();
229 }
Pankaj Garg7b279f62014-08-12 14:47:18 -0700230
231 if (mUiController != null) {
232 mUiController.setWindowDimming(0.75f);
233 }
Michael Kolb305b1c52011-06-21 16:16:22 -0700234 break;
235 case StateListener.STATE_EDITED:
236 mComboIcon.setVisibility(View.GONE);
237 mStopButton.setVisibility(View.GONE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700238 mClearButton.setVisibility(View.VISIBLE);
239 mMagnify.setVisibility(View.VISIBLE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700240 mTabSwitcher.setVisibility(View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800241 mTabText.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700242 break;
Michael Kolb2814a362011-05-19 15:49:41 -0700243 }
244 }
John Reck419f6b42011-08-16 16:10:51 -0700245
246 @Override
247 public void onTabDataChanged(Tab tab) {
248 super.onTabDataChanged(tab);
Enrico Rosd6efa972014-12-02 19:49:59 -0800249 boolean isPrivate = tab.isPrivateBrowsingEnabled();
250 mIncognitoIcon.setVisibility(isPrivate ? View.VISIBLE : View.GONE);
251 // change the background to a darker tone to reflect the 'incognito' state
252 setBackgroundColor(getResources().getColor(isPrivate ?
253 R.color.NavigationBarBackgroundIncognito : R.color.NavigationBarBackground));
254
John Reck419f6b42011-08-16 16:10:51 -0700255 }
Michael Kolb11d19782011-03-20 10:17:40 -0700256}