Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 1 | /* |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 3 | * |
| 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 Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 16 | package com.android.browser; |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 17 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 18 | import android.content.Context; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 19 | import android.util.AttributeSet; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 20 | import android.util.TypedValue; |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 21 | import android.view.View; |
Kulanthaivel Palanichamy | f36e1db | 2015-04-08 16:11:06 -0700 | [diff] [blame] | 22 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 23 | import org.codeaurora.swe.util.Activator; |
| 24 | import org.codeaurora.swe.util.Observable; |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 25 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 26 | import android.widget.TextView; |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 27 | import com.android.browser.UrlInputView.StateListener; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 28 | |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 29 | public class NavigationBarPhone extends NavigationBarBase implements StateListener { |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 30 | |
John Reck | 8ac4290 | 2011-06-29 16:14:34 -0700 | [diff] [blame] | 31 | private View mTabSwitcher; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 32 | private TextView mTabText; |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 33 | private View mIncognitoIcon; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 34 | private float mTabSwitcherInitialTextSize = 0; |
| 35 | private float mTabSwitcherCompressedTextSize = 0; |
| 36 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 37 | 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 Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 50 | protected void onFinishInflate() { |
| 51 | super.onFinishInflate(); |
John Reck | 8ac4290 | 2011-06-29 16:14:34 -0700 | [diff] [blame] | 52 | mTabSwitcher = findViewById(R.id.tab_switcher); |
| 53 | mTabSwitcher.setOnClickListener(this); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 54 | mTabText = (TextView) findViewById(R.id.tab_switcher_text); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 55 | setFocusState(false); |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 56 | mUrlInput.setContainer(this); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 57 | mUrlInput.setStateListener(this); |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 58 | mIncognitoIcon = findViewById(R.id.incognito_icon); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 59 | |
| 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 Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 74 | mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 75 | mTabSwitcherCompressedTextSize); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 76 | } else { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 77 | mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 78 | mTabSwitcherInitialTextSize); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | mTabText.setText(Integer.toString((Integer) params[0])); |
| 82 | } |
| 83 | }, |
| 84 | mUiController.getTabControl().getTabCountObservable()); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 88 | public void onProgressStopped() { |
| 89 | super.onProgressStopped(); |
Michael Kolb | 5e8f2b9 | 2011-07-19 13:22:32 -0700 | [diff] [blame] | 90 | onStateChanged(mUrlInput.getState()); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 93 | /** |
| 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 Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 100 | mUrlInput.setTag(title); |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 101 | if (!isEditingUrl()) { |
Vivek Sekhar | 60dca80 | 2014-06-27 14:48:30 -0700 | [diff] [blame] | 102 | // add for carrier requirement - show title from native instead of url |
| 103 | Tab currentTab = mUiController.getTabControl().getCurrentTab(); |
Panos Thomas | 4bdb525 | 2014-11-13 16:20:11 -0800 | [diff] [blame] | 104 | if (BrowserConfig.getInstance(getContext()) |
| 105 | .hasFeature(BrowserConfig.Feature.TITLE_IN_URL_BAR) && |
| 106 | currentTab != null && currentTab.getTitle() != null) { |
Vivek Sekhar | 60dca80 | 2014-06-27 14:48:30 -0700 | [diff] [blame] | 107 | mUrlInput.setText(currentTab.getTitle(), false); |
| 108 | } else if (title == null) { |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 109 | mUrlInput.setText(R.string.new_tab); |
| 110 | } else { |
Bijan Amirzada | e75909d | 2014-05-06 14:18:54 -0700 | [diff] [blame] | 111 | mUrlInput.setText(UrlUtils.stripUrl(title), false); |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 112 | } |
| 113 | mUrlInput.setSelection(0); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
| 117 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 118 | public void onClick(View v) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 119 | if (v == mTabSwitcher) { |
Michael Kolb | 20be26d | 2011-07-18 16:38:02 -0700 | [diff] [blame] | 120 | ((PhoneUi) mBaseUi).toggleNavScreen(); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 121 | } else { |
| 122 | super.onClick(v); |
| 123 | } |
| 124 | } |
| 125 | |
John Reck | 5889190 | 2011-08-11 17:48:53 -0700 | [diff] [blame] | 126 | @Override |
John Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 127 | public void onFocusChange(View view, boolean hasFocus) { |
Panos Thomas | 6ea3a42 | 2014-10-09 23:42:59 -0700 | [diff] [blame] | 128 | if (view == mUrlInput && !hasFocus) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 129 | Tab currentTab = mUiController.getTabControl().getCurrentTab(); |
| 130 | setDisplayTitle(currentTab.getUrl()); |
John Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 131 | } |
| 132 | super.onFocusChange(view, hasFocus); |
| 133 | } |
| 134 | |
| 135 | @Override |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 136 | public void onStateChanged(int state) { |
| 137 | switch(state) { |
| 138 | case StateListener.STATE_NORMAL: |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 139 | mStopButton.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 140 | mTabSwitcher.setVisibility(View.VISIBLE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 141 | mTabText.setVisibility(View.VISIBLE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 142 | break; |
| 143 | case StateListener.STATE_HIGHLIGHTED: |
Panos Thomas | 6ea3a42 | 2014-10-09 23:42:59 -0700 | [diff] [blame] | 144 | if (!mUrlInput.getText().toString().equals(mUrlInput.getTag())) { |
| 145 | // only change text if different |
| 146 | mUrlInput.setText((String) mUrlInput.getTag(), false); |
| 147 | mUrlInput.selectAll(); |
| 148 | } |
Pankaj Garg | 7b279f6 | 2014-08-12 14:47:18 -0700 | [diff] [blame] | 149 | |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 150 | mStopButton.setVisibility(View.VISIBLE); |
| 151 | mTabSwitcher.setVisibility(View.GONE); |
| 152 | mTabText.setVisibility(View.GONE); |
| 153 | |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 154 | break; |
| 155 | case StateListener.STATE_EDITED: |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 156 | mStopButton.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 157 | mTabSwitcher.setVisibility(View.GONE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 158 | mTabText.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 159 | break; |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 160 | } |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 161 | super.onStateChanged(state); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 162 | } |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 163 | |
| 164 | @Override |
| 165 | public void onTabDataChanged(Tab tab) { |
| 166 | super.onTabDataChanged(tab); |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 167 | boolean isPrivate = tab.isPrivateBrowsingEnabled(); |
| 168 | mIncognitoIcon.setVisibility(isPrivate ? View.VISIBLE : View.GONE); |
| 169 | // change the background to a darker tone to reflect the 'incognito' state |
| 170 | setBackgroundColor(getResources().getColor(isPrivate ? |
| 171 | R.color.NavigationBarBackgroundIncognito : R.color.NavigationBarBackground)); |
| 172 | |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 173 | } |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 174 | } |