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 |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 96 | * @param url |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 97 | */ |
| 98 | @Override |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 99 | void setDisplayTitle(String title, String url) { |
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()) { |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 102 | // 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 Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 108 | mUrlInput.setText(R.string.new_tab); |
| 109 | } else { |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 110 | mUrlInput.setText(UrlUtils.stripUrl(url), false); |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 111 | } |
| 112 | mUrlInput.setSelection(0); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 117 | public void onClick(View v) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 118 | if (v == mTabSwitcher) { |
Michael Kolb | 20be26d | 2011-07-18 16:38:02 -0700 | [diff] [blame] | 119 | ((PhoneUi) mBaseUi).toggleNavScreen(); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 120 | } else { |
| 121 | super.onClick(v); |
| 122 | } |
| 123 | } |
| 124 | |
John Reck | 5889190 | 2011-08-11 17:48:53 -0700 | [diff] [blame] | 125 | @Override |
John Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 126 | public void onFocusChange(View view, boolean hasFocus) { |
Panos Thomas | 6ea3a42 | 2014-10-09 23:42:59 -0700 | [diff] [blame] | 127 | if (view == mUrlInput && !hasFocus) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 128 | Tab currentTab = mUiController.getTabControl().getCurrentTab(); |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 129 | setDisplayTitle(currentTab.getTitle(), currentTab.getUrl()); |
John Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 130 | } |
| 131 | super.onFocusChange(view, hasFocus); |
| 132 | } |
| 133 | |
| 134 | @Override |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 135 | public void onStateChanged(int state) { |
| 136 | switch(state) { |
| 137 | case StateListener.STATE_NORMAL: |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 138 | mStopButton.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 139 | mTabSwitcher.setVisibility(View.VISIBLE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 140 | mTabText.setVisibility(View.VISIBLE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 141 | break; |
| 142 | case StateListener.STATE_HIGHLIGHTED: |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 143 | mTabSwitcher.setVisibility(View.GONE); |
| 144 | mTabText.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 145 | break; |
| 146 | case StateListener.STATE_EDITED: |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 147 | mStopButton.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 148 | mTabSwitcher.setVisibility(View.GONE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 149 | mTabText.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 150 | break; |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 151 | } |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 152 | super.onStateChanged(state); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 153 | } |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 154 | |
| 155 | @Override |
| 156 | public void onTabDataChanged(Tab tab) { |
| 157 | super.onTabDataChanged(tab); |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 158 | 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 Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 164 | } |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 165 | } |