blob: 5fa093bece13c4e826e7bcf925407987c1d8a81d [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;
Michael Kolb11d19782011-03-20 10:17:40 -070021import android.view.View;
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070022
Enrico Ros1f5a0952014-11-18 20:15:48 -080023import org.codeaurora.swe.util.Activator;
24import org.codeaurora.swe.util.Observable;
Michael Kolb11d19782011-03-20 10:17:40 -070025
Enrico Ros1f5a0952014-11-18 20:15:48 -080026import android.widget.TextView;
Bijan Amirzada41242f22014-03-21 12:12:18 -070027import com.android.browser.UrlInputView.StateListener;
Pankaj Garg32e1b942015-06-03 18:13:24 -070028
Pankaj Garg66f8cef2015-07-07 17:29:03 -070029public class NavigationBarPhone extends NavigationBarBase implements StateListener {
Michael Kolb305b1c52011-06-21 16:16:22 -070030
John Reck8ac42902011-06-29 16:14:34 -070031 private View mTabSwitcher;
Enrico Ros1f5a0952014-11-18 20:15:48 -080032 private TextView mTabText;
John Reck419f6b42011-08-16 16:10:51 -070033 private View mIncognitoIcon;
Enrico Ros1f5a0952014-11-18 20:15:48 -080034 private float mTabSwitcherInitialTextSize = 0;
35 private float mTabSwitcherCompressedTextSize = 0;
36
John Reck0f602f32011-07-07 15:38:43 -070037 public NavigationBarPhone(Context context) {
38 super(context);
39 }
40
41 public NavigationBarPhone(Context context, AttributeSet attrs) {
42 super(context, attrs);
43 }
44
45 public NavigationBarPhone(Context context, AttributeSet attrs, int defStyle) {
46 super(context, attrs, defStyle);
Michael Kolb11d19782011-03-20 10:17:40 -070047 }
48
49 @Override
John Reck0f602f32011-07-07 15:38:43 -070050 protected void onFinishInflate() {
51 super.onFinishInflate();
John Reck8ac42902011-06-29 16:14:34 -070052 mTabSwitcher = findViewById(R.id.tab_switcher);
53 mTabSwitcher.setOnClickListener(this);
Enrico Ros1f5a0952014-11-18 20:15:48 -080054 mTabText = (TextView) findViewById(R.id.tab_switcher_text);
Michael Kolb11d19782011-03-20 10:17:40 -070055 setFocusState(false);
John Reck67f33632011-06-17 16:23:42 -070056 mUrlInput.setContainer(this);
Michael Kolb305b1c52011-06-21 16:16:22 -070057 mUrlInput.setStateListener(this);
John Reck419f6b42011-08-16 16:10:51 -070058 mIncognitoIcon = findViewById(R.id.incognito_icon);
Enrico Ros1f5a0952014-11-18 20:15:48 -080059
60 if (mTabSwitcherInitialTextSize == 0) {
61 mTabSwitcherInitialTextSize = mTabText.getTextSize();
62 mTabSwitcherCompressedTextSize = (float) (mTabSwitcherInitialTextSize / 1.2);
63 }
64 }
65
66 @Override
67 public void setTitleBar(TitleBar titleBar) {
68 super.setTitleBar(titleBar);
69 Activator.activate(
70 new Observable.Observer() {
71 @Override
72 public void onChange(Object... params) {
73 if ((Integer)params[0] > 9) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -070074 mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX,
75 mTabSwitcherCompressedTextSize);
Enrico Ros1f5a0952014-11-18 20:15:48 -080076 } else {
Pankaj Garg66f8cef2015-07-07 17:29:03 -070077 mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX,
78 mTabSwitcherInitialTextSize);
Enrico Ros1f5a0952014-11-18 20:15:48 -080079 }
80
81 mTabText.setText(Integer.toString((Integer) params[0]));
82 }
83 },
84 mUiController.getTabControl().getTabCountObservable());
Michael Kolb11d19782011-03-20 10:17:40 -070085 }
86
87 @Override
John Reck0f602f32011-07-07 15:38:43 -070088 public void onProgressStopped() {
89 super.onProgressStopped();
Michael Kolb5e8f2b92011-07-19 13:22:32 -070090 onStateChanged(mUrlInput.getState());
Michael Kolb2814a362011-05-19 15:49:41 -070091 }
92
Michael Kolb11d19782011-03-20 10:17:40 -070093 /**
94 * Update the text displayed in the title bar.
95 * @param title String to display. If null, the new tab string will be
Pankaj Garg8d2e98f2015-08-07 10:01:49 -070096 * @param url
Michael Kolb11d19782011-03-20 10:17:40 -070097 */
98 @Override
Pankaj Garg8d2e98f2015-08-07 10:01:49 -070099 void setDisplayTitle(String title, String url) {
John Reck434e9f82011-08-10 18:16:52 -0700100 mUrlInput.setTag(title);
John Reck67f33632011-06-17 16:23:42 -0700101 if (!isEditingUrl()) {
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700102 // add for carrier requirement - show title from native instead of url
103 if ((BrowserConfig.getInstance(getContext())
104 .hasFeature(BrowserConfig.Feature.TITLE_IN_URL_BAR) ||
105 mTrustLevel == SiteTileView.TRUST_TRUSTED) && title != null) {
106 mUrlInput.setText(title, false);
107 } else if (url == null) {
John Reck67f33632011-06-17 16:23:42 -0700108 mUrlInput.setText(R.string.new_tab);
109 } else {
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700110 mUrlInput.setText(UrlUtils.stripUrl(url), false);
John Reck67f33632011-06-17 16:23:42 -0700111 }
112 mUrlInput.setSelection(0);
Michael Kolb11d19782011-03-20 10:17:40 -0700113 }
114 }
115
116 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700117 public void onClick(View v) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700118 if (v == mTabSwitcher) {
Michael Kolb20be26d2011-07-18 16:38:02 -0700119 ((PhoneUi) mBaseUi).toggleNavScreen();
Michael Kolb11d19782011-03-20 10:17:40 -0700120 } else {
121 super.onClick(v);
122 }
123 }
124
John Reck58891902011-08-11 17:48:53 -0700125 @Override
John Reck434e9f82011-08-10 18:16:52 -0700126 public void onFocusChange(View view, boolean hasFocus) {
Panos Thomas6ea3a422014-10-09 23:42:59 -0700127 if (view == mUrlInput && !hasFocus) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700128 Tab currentTab = mUiController.getTabControl().getCurrentTab();
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700129 setDisplayTitle(currentTab.getTitle(), currentTab.getUrl());
John Reck434e9f82011-08-10 18:16:52 -0700130 }
131 super.onFocusChange(view, hasFocus);
132 }
133
134 @Override
Michael Kolb305b1c52011-06-21 16:16:22 -0700135 public void onStateChanged(int state) {
136 switch(state) {
137 case StateListener.STATE_NORMAL:
Michael Kolb305b1c52011-06-21 16:16:22 -0700138 mStopButton.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700139 mTabSwitcher.setVisibility(View.VISIBLE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800140 mTabText.setVisibility(View.VISIBLE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700141 break;
142 case StateListener.STATE_HIGHLIGHTED:
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700143 mTabSwitcher.setVisibility(View.GONE);
144 mTabText.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700145 break;
146 case StateListener.STATE_EDITED:
Michael Kolb305b1c52011-06-21 16:16:22 -0700147 mStopButton.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700148 mTabSwitcher.setVisibility(View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800149 mTabText.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700150 break;
Michael Kolb2814a362011-05-19 15:49:41 -0700151 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700152 super.onStateChanged(state);
Michael Kolb2814a362011-05-19 15:49:41 -0700153 }
John Reck419f6b42011-08-16 16:10:51 -0700154
155 @Override
156 public void onTabDataChanged(Tab tab) {
157 super.onTabDataChanged(tab);
Enrico Rosd6efa972014-12-02 19:49:59 -0800158 boolean isPrivate = tab.isPrivateBrowsingEnabled();
159 mIncognitoIcon.setVisibility(isPrivate ? View.VISIBLE : View.GONE);
160 // change the background to a darker tone to reflect the 'incognito' state
161 setBackgroundColor(getResources().getColor(isPrivate ?
162 R.color.NavigationBarBackgroundIncognito : R.color.NavigationBarBackground));
163
John Reck419f6b42011-08-16 16:10:51 -0700164 }
Michael Kolb11d19782011-03-20 10:17:40 -0700165}