blob: 9abc35696da8581c9bbdf86b4241b9d0d2cce791 [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;
John Reck0f602f32011-07-07 15:38:43 -070019import android.util.AttributeSet;
Enrico Ros1f5a0952014-11-18 20:15:48 -080020import android.util.TypedValue;
jrizzoli7324f6e2016-05-01 22:31:14 +020021import android.view.MotionEvent;
Michael Kolb11d19782011-03-20 10:17:40 -070022import android.view.View;
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070023
Enrico Ros1f5a0952014-11-18 20:15:48 -080024import org.codeaurora.swe.util.Activator;
25import org.codeaurora.swe.util.Observable;
Michael Kolb11d19782011-03-20 10:17:40 -070026
Enrico Ros1f5a0952014-11-18 20:15:48 -080027import android.widget.TextView;
Bijan Amirzada41242f22014-03-21 12:12:18 -070028import com.android.browser.UrlInputView.StateListener;
Pankaj Garg32e1b942015-06-03 18:13:24 -070029
Pankaj Garg66f8cef2015-07-07 17:29:03 -070030public class NavigationBarPhone extends NavigationBarBase implements StateListener {
Michael Kolb305b1c52011-06-21 16:16:22 -070031
John Reck8ac42902011-06-29 16:14:34 -070032 private View mTabSwitcher;
Enrico Ros1f5a0952014-11-18 20:15:48 -080033 private TextView mTabText;
John Reck419f6b42011-08-16 16:10:51 -070034 private View mIncognitoIcon;
Enrico Ros1f5a0952014-11-18 20:15:48 -080035 private float mTabSwitcherInitialTextSize = 0;
36 private float mTabSwitcherCompressedTextSize = 0;
37
John Reck0f602f32011-07-07 15:38:43 -070038 public NavigationBarPhone(Context context) {
39 super(context);
40 }
41
42 public NavigationBarPhone(Context context, AttributeSet attrs) {
43 super(context, attrs);
44 }
45
46 public NavigationBarPhone(Context context, AttributeSet attrs, int defStyle) {
47 super(context, attrs, defStyle);
Michael Kolb11d19782011-03-20 10:17:40 -070048 }
49
50 @Override
John Reck0f602f32011-07-07 15:38:43 -070051 protected void onFinishInflate() {
52 super.onFinishInflate();
John Reck8ac42902011-06-29 16:14:34 -070053 mTabSwitcher = findViewById(R.id.tab_switcher);
54 mTabSwitcher.setOnClickListener(this);
Enrico Ros1f5a0952014-11-18 20:15:48 -080055 mTabText = (TextView) findViewById(R.id.tab_switcher_text);
Michael Kolb11d19782011-03-20 10:17:40 -070056 setFocusState(false);
John Reck67f33632011-06-17 16:23:42 -070057 mUrlInput.setContainer(this);
Michael Kolb305b1c52011-06-21 16:16:22 -070058 mUrlInput.setStateListener(this);
John Reck419f6b42011-08-16 16:10:51 -070059 mIncognitoIcon = findViewById(R.id.incognito_icon);
Enrico Ros1f5a0952014-11-18 20:15:48 -080060
jrizzoli7324f6e2016-05-01 22:31:14 +020061 mTabSwitcher.setOnTouchListener(new OnTouchListener() {
62 @Override
63 public boolean onTouch(View v, MotionEvent event) {
64 if (event.getAction() == MotionEvent.ACTION_DOWN) {
65 ((PhoneUi) mBaseUi).toggleNavScreen();
66 }
67 return true;
68 }
69 });
70
Enrico Ros1f5a0952014-11-18 20:15:48 -080071 if (mTabSwitcherInitialTextSize == 0) {
72 mTabSwitcherInitialTextSize = mTabText.getTextSize();
73 mTabSwitcherCompressedTextSize = (float) (mTabSwitcherInitialTextSize / 1.2);
74 }
75 }
76
77 @Override
78 public void setTitleBar(TitleBar titleBar) {
79 super.setTitleBar(titleBar);
80 Activator.activate(
81 new Observable.Observer() {
82 @Override
83 public void onChange(Object... params) {
84 if ((Integer)params[0] > 9) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -070085 mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX,
86 mTabSwitcherCompressedTextSize);
Enrico Ros1f5a0952014-11-18 20:15:48 -080087 } else {
Pankaj Garg66f8cef2015-07-07 17:29:03 -070088 mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX,
89 mTabSwitcherInitialTextSize);
Enrico Ros1f5a0952014-11-18 20:15:48 -080090 }
91
92 mTabText.setText(Integer.toString((Integer) params[0]));
93 }
94 },
95 mUiController.getTabControl().getTabCountObservable());
Michael Kolb11d19782011-03-20 10:17:40 -070096 }
97
98 @Override
John Reck0f602f32011-07-07 15:38:43 -070099 public void onProgressStopped() {
100 super.onProgressStopped();
Michael Kolb5e8f2b92011-07-19 13:22:32 -0700101 onStateChanged(mUrlInput.getState());
Michael Kolb2814a362011-05-19 15:49:41 -0700102 }
103
Michael Kolb11d19782011-03-20 10:17:40 -0700104 /**
105 * Update the text displayed in the title bar.
106 * @param title String to display. If null, the new tab string will be
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700107 * @param url
Michael Kolb11d19782011-03-20 10:17:40 -0700108 */
109 @Override
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700110 void setDisplayTitle(String title, String url) {
John Reck434e9f82011-08-10 18:16:52 -0700111 mUrlInput.setTag(title);
John Reck67f33632011-06-17 16:23:42 -0700112 if (!isEditingUrl()) {
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700113 // add for carrier requirement - show title from native instead of url
114 if ((BrowserConfig.getInstance(getContext())
115 .hasFeature(BrowserConfig.Feature.TITLE_IN_URL_BAR) ||
116 mTrustLevel == SiteTileView.TRUST_TRUSTED) && title != null) {
117 mUrlInput.setText(title, false);
118 } else if (url == null) {
John Reck67f33632011-06-17 16:23:42 -0700119 mUrlInput.setText(R.string.new_tab);
120 } else {
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700121 mUrlInput.setText(UrlUtils.stripUrl(url), false);
John Reck67f33632011-06-17 16:23:42 -0700122 }
123 mUrlInput.setSelection(0);
Michael Kolb11d19782011-03-20 10:17:40 -0700124 }
125 }
126
127 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700128 public void onClick(View v) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700129 if (v == mTabSwitcher) {
Michael Kolb20be26d2011-07-18 16:38:02 -0700130 ((PhoneUi) mBaseUi).toggleNavScreen();
Michael Kolb11d19782011-03-20 10:17:40 -0700131 } else {
132 super.onClick(v);
133 }
134 }
135
John Reck58891902011-08-11 17:48:53 -0700136 @Override
John Reck434e9f82011-08-10 18:16:52 -0700137 public void onFocusChange(View view, boolean hasFocus) {
Panos Thomas6ea3a422014-10-09 23:42:59 -0700138 if (view == mUrlInput && !hasFocus) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700139 Tab currentTab = mUiController.getTabControl().getCurrentTab();
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700140 setDisplayTitle(currentTab.getTitle(), currentTab.getUrl());
John Reck434e9f82011-08-10 18:16:52 -0700141 }
142 super.onFocusChange(view, hasFocus);
143 }
144
145 @Override
Michael Kolb305b1c52011-06-21 16:16:22 -0700146 public void onStateChanged(int state) {
147 switch(state) {
148 case StateListener.STATE_NORMAL:
Michael Kolb305b1c52011-06-21 16:16:22 -0700149 mStopButton.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700150 mTabSwitcher.setVisibility(View.VISIBLE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800151 mTabText.setVisibility(View.VISIBLE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700152 break;
153 case StateListener.STATE_HIGHLIGHTED:
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700154 mTabSwitcher.setVisibility(View.GONE);
155 mTabText.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700156 break;
157 case StateListener.STATE_EDITED:
Michael Kolb305b1c52011-06-21 16:16:22 -0700158 mStopButton.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700159 mTabSwitcher.setVisibility(View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800160 mTabText.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700161 break;
Michael Kolb2814a362011-05-19 15:49:41 -0700162 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700163 super.onStateChanged(state);
Michael Kolb2814a362011-05-19 15:49:41 -0700164 }
John Reck419f6b42011-08-16 16:10:51 -0700165
166 @Override
167 public void onTabDataChanged(Tab tab) {
168 super.onTabDataChanged(tab);
Enrico Rosd6efa972014-12-02 19:49:59 -0800169 boolean isPrivate = tab.isPrivateBrowsingEnabled();
170 mIncognitoIcon.setVisibility(isPrivate ? View.VISIBLE : View.GONE);
171 // change the background to a darker tone to reflect the 'incognito' state
172 setBackgroundColor(getResources().getColor(isPrivate ?
173 R.color.NavigationBarBackgroundIncognito : R.color.NavigationBarBackground));
174
John Reck419f6b42011-08-16 16:10:51 -0700175 }
Michael Kolb11d19782011-03-20 10:17:40 -0700176}