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; |
jrizzoli | 7324f6e | 2016-05-01 22:31:14 +0200 | [diff] [blame] | 21 | import android.view.MotionEvent; |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 22 | import android.view.View; |
Kulanthaivel Palanichamy | f36e1db | 2015-04-08 16:11:06 -0700 | [diff] [blame] | 23 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 24 | import org.codeaurora.swe.util.Activator; |
| 25 | import org.codeaurora.swe.util.Observable; |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 26 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 27 | import android.widget.TextView; |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 28 | import com.android.browser.UrlInputView.StateListener; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 29 | |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 30 | public class NavigationBarPhone extends NavigationBarBase implements StateListener { |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 31 | |
John Reck | 8ac4290 | 2011-06-29 16:14:34 -0700 | [diff] [blame] | 32 | private View mTabSwitcher; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 33 | private TextView mTabText; |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 34 | private View mIncognitoIcon; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 35 | private float mTabSwitcherInitialTextSize = 0; |
| 36 | private float mTabSwitcherCompressedTextSize = 0; |
| 37 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 38 | 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 Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 51 | protected void onFinishInflate() { |
| 52 | super.onFinishInflate(); |
John Reck | 8ac4290 | 2011-06-29 16:14:34 -0700 | [diff] [blame] | 53 | mTabSwitcher = findViewById(R.id.tab_switcher); |
| 54 | mTabSwitcher.setOnClickListener(this); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 55 | mTabText = (TextView) findViewById(R.id.tab_switcher_text); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 56 | setFocusState(false); |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 57 | mUrlInput.setContainer(this); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 58 | mUrlInput.setStateListener(this); |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 59 | mIncognitoIcon = findViewById(R.id.incognito_icon); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 60 | |
jrizzoli | 7324f6e | 2016-05-01 22:31:14 +0200 | [diff] [blame] | 61 | 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 Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 71 | 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 Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 85 | mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 86 | mTabSwitcherCompressedTextSize); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 87 | } else { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 88 | mTabText.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 89 | mTabSwitcherInitialTextSize); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | mTabText.setText(Integer.toString((Integer) params[0])); |
| 93 | } |
| 94 | }, |
| 95 | mUiController.getTabControl().getTabCountObservable()); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 99 | public void onProgressStopped() { |
| 100 | super.onProgressStopped(); |
Michael Kolb | 5e8f2b9 | 2011-07-19 13:22:32 -0700 | [diff] [blame] | 101 | onStateChanged(mUrlInput.getState()); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 104 | /** |
| 105 | * Update the text displayed in the title bar. |
| 106 | * @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] | 107 | * @param url |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 108 | */ |
| 109 | @Override |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 110 | void setDisplayTitle(String title, String url) { |
John Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 111 | mUrlInput.setTag(title); |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 112 | if (!isEditingUrl()) { |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 113 | // 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 Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 119 | mUrlInput.setText(R.string.new_tab); |
| 120 | } else { |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 121 | mUrlInput.setText(UrlUtils.stripUrl(url), false); |
John Reck | 67f3363 | 2011-06-17 16:23:42 -0700 | [diff] [blame] | 122 | } |
| 123 | mUrlInput.setSelection(0); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 128 | public void onClick(View v) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 129 | if (v == mTabSwitcher) { |
Michael Kolb | 20be26d | 2011-07-18 16:38:02 -0700 | [diff] [blame] | 130 | ((PhoneUi) mBaseUi).toggleNavScreen(); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 131 | } else { |
| 132 | super.onClick(v); |
| 133 | } |
| 134 | } |
| 135 | |
John Reck | 5889190 | 2011-08-11 17:48:53 -0700 | [diff] [blame] | 136 | @Override |
John Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 137 | public void onFocusChange(View view, boolean hasFocus) { |
Panos Thomas | 6ea3a42 | 2014-10-09 23:42:59 -0700 | [diff] [blame] | 138 | if (view == mUrlInput && !hasFocus) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 139 | Tab currentTab = mUiController.getTabControl().getCurrentTab(); |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 140 | setDisplayTitle(currentTab.getTitle(), currentTab.getUrl()); |
John Reck | 434e9f8 | 2011-08-10 18:16:52 -0700 | [diff] [blame] | 141 | } |
| 142 | super.onFocusChange(view, hasFocus); |
| 143 | } |
| 144 | |
| 145 | @Override |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 146 | public void onStateChanged(int state) { |
| 147 | switch(state) { |
| 148 | case StateListener.STATE_NORMAL: |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 149 | mStopButton.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 150 | mTabSwitcher.setVisibility(View.VISIBLE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 151 | mTabText.setVisibility(View.VISIBLE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 152 | break; |
| 153 | case StateListener.STATE_HIGHLIGHTED: |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 154 | mTabSwitcher.setVisibility(View.GONE); |
| 155 | mTabText.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 156 | break; |
| 157 | case StateListener.STATE_EDITED: |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 158 | mStopButton.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 159 | mTabSwitcher.setVisibility(View.GONE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 160 | mTabText.setVisibility(View.GONE); |
Michael Kolb | 305b1c5 | 2011-06-21 16:16:22 -0700 | [diff] [blame] | 161 | break; |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 162 | } |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 163 | super.onStateChanged(state); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 164 | } |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 165 | |
| 166 | @Override |
| 167 | public void onTabDataChanged(Tab tab) { |
| 168 | super.onTabDataChanged(tab); |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 169 | 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 Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 175 | } |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 176 | } |