blob: 23df7fce723b39fd8a74ee48a3bb3fc25337cf9f [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
96 * shown.
97 */
98 @Override
99 void setDisplayTitle(String title) {
John Reck434e9f82011-08-10 18:16:52 -0700100 mUrlInput.setTag(title);
John Reck67f33632011-06-17 16:23:42 -0700101 if (!isEditingUrl()) {
Vivek Sekhar60dca802014-06-27 14:48:30 -0700102 // add for carrier requirement - show title from native instead of url
103 Tab currentTab = mUiController.getTabControl().getCurrentTab();
Panos Thomas4bdb5252014-11-13 16:20:11 -0800104 if (BrowserConfig.getInstance(getContext())
105 .hasFeature(BrowserConfig.Feature.TITLE_IN_URL_BAR) &&
106 currentTab != null && currentTab.getTitle() != null) {
Vivek Sekhar60dca802014-06-27 14:48:30 -0700107 mUrlInput.setText(currentTab.getTitle(), false);
108 } else if (title == null) {
John Reck67f33632011-06-17 16:23:42 -0700109 mUrlInput.setText(R.string.new_tab);
110 } else {
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700111 mUrlInput.setText(UrlUtils.stripUrl(title), false);
John Reck67f33632011-06-17 16:23:42 -0700112 }
113 mUrlInput.setSelection(0);
Michael Kolb11d19782011-03-20 10:17:40 -0700114 }
115 }
116
117 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700118 public void onClick(View v) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700119 if (v == mTabSwitcher) {
Michael Kolb20be26d2011-07-18 16:38:02 -0700120 ((PhoneUi) mBaseUi).toggleNavScreen();
Michael Kolb11d19782011-03-20 10:17:40 -0700121 } else {
122 super.onClick(v);
123 }
124 }
125
John Reck58891902011-08-11 17:48:53 -0700126 @Override
John Reck434e9f82011-08-10 18:16:52 -0700127 public void onFocusChange(View view, boolean hasFocus) {
Panos Thomas6ea3a422014-10-09 23:42:59 -0700128 if (view == mUrlInput && !hasFocus) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700129 Tab currentTab = mUiController.getTabControl().getCurrentTab();
130 setDisplayTitle(currentTab.getUrl());
John Reck434e9f82011-08-10 18:16:52 -0700131 }
132 super.onFocusChange(view, hasFocus);
133 }
134
135 @Override
Michael Kolb305b1c52011-06-21 16:16:22 -0700136 public void onStateChanged(int state) {
137 switch(state) {
138 case StateListener.STATE_NORMAL:
Michael Kolb305b1c52011-06-21 16:16:22 -0700139 mStopButton.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700140 mTabSwitcher.setVisibility(View.VISIBLE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800141 mTabText.setVisibility(View.VISIBLE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700142 break;
143 case StateListener.STATE_HIGHLIGHTED:
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700144 mTabSwitcher.setVisibility(View.GONE);
145 mTabText.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700146 break;
147 case StateListener.STATE_EDITED:
Michael Kolb305b1c52011-06-21 16:16:22 -0700148 mStopButton.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700149 mTabSwitcher.setVisibility(View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800150 mTabText.setVisibility(View.GONE);
Michael Kolb305b1c52011-06-21 16:16:22 -0700151 break;
Michael Kolb2814a362011-05-19 15:49:41 -0700152 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700153 super.onStateChanged(state);
Michael Kolb2814a362011-05-19 15:49:41 -0700154 }
John Reck419f6b42011-08-16 16:10:51 -0700155
156 @Override
157 public void onTabDataChanged(Tab tab) {
158 super.onTabDataChanged(tab);
Enrico Rosd6efa972014-12-02 19:49:59 -0800159 boolean isPrivate = tab.isPrivateBrowsingEnabled();
160 mIncognitoIcon.setVisibility(isPrivate ? View.VISIBLE : View.GONE);
161 // change the background to a darker tone to reflect the 'incognito' state
162 setBackgroundColor(getResources().getColor(isPrivate ?
163 R.color.NavigationBarBackgroundIncognito : R.color.NavigationBarBackground));
164
John Reck419f6b42011-08-16 16:10:51 -0700165 }
Michael Kolb11d19782011-03-20 10:17:40 -0700166}