blob: e73f218fa9c2036b3b5d1d143783e8f03e942fbb [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();
148 if (currentTab != null && currentTab.getTitle() != null) {
149 mUrlInput.setText(currentTab.getTitle(), false);
150 } else if (title == null) {
John Reck67f33632011-06-17 16:23:42 -0700151 mUrlInput.setText(R.string.new_tab);
152 } else {
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700153 mUrlInput.setText(UrlUtils.stripUrl(title), false);
John Reck67f33632011-06-17 16:23:42 -0700154 }
155 mUrlInput.setSelection(0);
Michael Kolb11d19782011-03-20 10:17:40 -0700156 }
157 }
158
159 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700160 public void onClick(View v) {
161 if (v == mStopButton) {
John Reck0f602f32011-07-07 15:38:43 -0700162 if (mTitleBar.isInLoad()) {
Michael Kolb2814a362011-05-19 15:49:41 -0700163 mUiController.stopLoading();
164 } else {
165 WebView web = mBaseUi.getWebView();
166 if (web != null) {
Michael Kolb305b1c52011-06-21 16:16:22 -0700167 stopEditingUrl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800168 Tab currentTab = mUiController.getTabControl().getCurrentTab();
169 if (currentTab.hasCrashed) {
170 currentTab.replaceCrashView(web, currentTab.getViewContainer());
171 }
Michael Kolb2814a362011-05-19 15:49:41 -0700172 web.reload();
173 }
174 }
John Reck8ac42902011-06-29 16:14:34 -0700175 } else if (v == mTabSwitcher) {
Michael Kolb20be26d2011-07-18 16:38:02 -0700176 ((PhoneUi) mBaseUi).toggleNavScreen();
Michael Kolb94ec5272011-08-31 16:23:57 -0700177 } else if (mClearButton == v) {
178 mUrlInput.setText("");
Michael Kolb315d5022011-10-13 12:47:11 -0700179 } else if (mComboIcon == v) {
180 mUiController.showPageInfo();
Michael Kolb0b129122012-06-04 16:31:58 -0700181 } else if (mVoiceButton == v) {
182 mUiController.startVoiceRecognizer();
Michael Kolb11d19782011-03-20 10:17:40 -0700183 } else {
184 super.onClick(v);
185 }
186 }
187
John Reck58891902011-08-11 17:48:53 -0700188 @Override
John Reck434e9f82011-08-10 18:16:52 -0700189 public void onFocusChange(View view, boolean hasFocus) {
Panos Thomas6ea3a422014-10-09 23:42:59 -0700190 if (view == mUrlInput && !hasFocus) {
191 setDisplayTitle(mUrlInput.getText().toString());
John Reck434e9f82011-08-10 18:16:52 -0700192 }
193 super.onFocusChange(view, hasFocus);
194 }
195
196 @Override
Michael Kolb305b1c52011-06-21 16:16:22 -0700197 public void onStateChanged(int state) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800198 super.onStateChanged(state);
Michael Kolbe721cc32012-06-26 15:26:59 -0700199 mVoiceButton.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700200 switch(state) {
201 case StateListener.STATE_NORMAL:
202 mComboIcon.setVisibility(View.VISIBLE);
203 mStopButton.setVisibility(View.GONE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700204 mClearButton.setVisibility(View.GONE);
205 mMagnify.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700206 mTabSwitcher.setVisibility(View.VISIBLE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800207 mTabText.setVisibility(View.VISIBLE);
Pankaj Garg7b279f62014-08-12 14:47:18 -0700208 if (mUiController != null) {
209 mUiController.setWindowDimming(0f);
210 }
Michael Kolb305b1c52011-06-21 16:16:22 -0700211 break;
212 case StateListener.STATE_HIGHLIGHTED:
213 mComboIcon.setVisibility(View.GONE);
214 mStopButton.setVisibility(View.VISIBLE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700215 mClearButton.setVisibility(View.GONE);
Michael Kolbe721cc32012-06-26 15:26:59 -0700216 if ((mUiController != null) && mUiController.supportsVoice()) {
217 mVoiceButton.setVisibility(View.VISIBLE);
218 }
Michael Kolb94ec5272011-08-31 16:23:57 -0700219 mMagnify.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700220 mTabSwitcher.setVisibility(View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800221 mTabText.setVisibility(View.GONE);
Pankaj Garg7b279f62014-08-12 14:47:18 -0700222
Panos Thomas6ea3a422014-10-09 23:42:59 -0700223 if (!mUrlInput.getText().toString().equals(mUrlInput.getTag())) {
224 // only change text if different
225 mUrlInput.setText((String) mUrlInput.getTag(), false);
226 mUrlInput.selectAll();
227 }
Pankaj Garg7b279f62014-08-12 14:47:18 -0700228
229 if (mUiController != null) {
230 mUiController.setWindowDimming(0.75f);
231 }
Michael Kolb305b1c52011-06-21 16:16:22 -0700232 break;
233 case StateListener.STATE_EDITED:
234 mComboIcon.setVisibility(View.GONE);
235 mStopButton.setVisibility(View.GONE);
Michael Kolb94ec5272011-08-31 16:23:57 -0700236 mClearButton.setVisibility(View.VISIBLE);
237 mMagnify.setVisibility(View.VISIBLE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700238 mTabSwitcher.setVisibility(View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800239 mTabText.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700240 break;
Michael Kolb2814a362011-05-19 15:49:41 -0700241 }
242 }
John Reck419f6b42011-08-16 16:10:51 -0700243
244 @Override
245 public void onTabDataChanged(Tab tab) {
246 super.onTabDataChanged(tab);
Enrico Rosd6efa972014-12-02 19:49:59 -0800247 boolean isPrivate = tab.isPrivateBrowsingEnabled();
248 mIncognitoIcon.setVisibility(isPrivate ? View.VISIBLE : View.GONE);
249 // change the background to a darker tone to reflect the 'incognito' state
250 setBackgroundColor(getResources().getColor(isPrivate ?
251 R.color.NavigationBarBackgroundIncognito : R.color.NavigationBarBackground));
252
John Reck419f6b42011-08-16 16:10:51 -0700253 }
Michael Kolb11d19782011-03-20 10:17:40 -0700254}