OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.shell; | 5 package org.chromium.chrome.shell; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.res.Configuration; | 9 import android.content.res.Configuration; |
10 import android.util.AttributeSet; | 10 import android.util.AttributeSet; |
11 import android.view.KeyEvent; | 11 import android.view.KeyEvent; |
12 import android.view.MotionEvent; | 12 import android.view.MotionEvent; |
13 import android.view.View; | 13 import android.view.View; |
14 import android.view.inputmethod.EditorInfo; | 14 import android.view.inputmethod.EditorInfo; |
15 import android.view.inputmethod.InputMethodManager; | 15 import android.view.inputmethod.InputMethodManager; |
16 import android.widget.EditText; | 16 import android.widget.EditText; |
17 import android.widget.ImageButton; | 17 import android.widget.ImageButton; |
18 import android.widget.LinearLayout; | 18 import android.widget.LinearLayout; |
19 import android.widget.TextView; | 19 import android.widget.TextView; |
20 import android.widget.TextView.OnEditorActionListener; | 20 import android.widget.TextView.OnEditorActionListener; |
21 | 21 |
22 import org.chromium.base.ApiCompatibilityUtils; | 22 import org.chromium.base.ApiCompatibilityUtils; |
23 import org.chromium.base.CommandLine; | 23 import org.chromium.base.CommandLine; |
24 import org.chromium.chrome.browser.EmptyTabObserver; | 24 import org.chromium.chrome.browser.EmptyTabObserver; |
25 import org.chromium.chrome.browser.Tab; | 25 import org.chromium.chrome.browser.Tab; |
26 import org.chromium.chrome.browser.TabObserver; | 26 import org.chromium.chrome.browser.TabObserver; |
27 import org.chromium.chrome.browser.UrlUtilities; | 27 import org.chromium.chrome.browser.UrlUtilities; |
28 import org.chromium.chrome.browser.appmenu.AppMenuButtonHelper; | 28 import org.chromium.chrome.browser.appmenu.AppMenuButtonHelper; |
29 import org.chromium.chrome.browser.appmenu.AppMenuHandler; | 29 import org.chromium.chrome.browser.appmenu.AppMenuHandler; |
30 import org.chromium.chrome.browser.widget.SmoothProgressBar; | 30 import org.chromium.chrome.browser.widget.ClipDrawableProgressBar; |
31 import org.chromium.chrome.shell.omnibox.SuggestionPopup; | 31 import org.chromium.chrome.shell.omnibox.SuggestionPopup; |
32 import org.chromium.content.common.ContentSwitches; | 32 import org.chromium.content.common.ContentSwitches; |
33 | 33 |
34 /** | 34 /** |
35 * A Toolbar {@link View} that shows the URL and navigation buttons. | 35 * A Toolbar {@link View} that shows the URL and navigation buttons. |
36 */ | 36 */ |
37 public class ChromeShellToolbar extends LinearLayout { | 37 public class ChromeShellToolbar extends LinearLayout { |
38 private static final long COMPLETED_PROGRESS_TIMEOUT_MS = 200; | |
39 | |
40 private final Runnable mClearProgressRunnable = new Runnable() { | |
41 @Override | |
42 public void run() { | |
43 mProgressBar.setProgress(0); | |
44 } | |
45 }; | |
46 | 38 |
47 private final Runnable mUpdateProgressRunnable = new Runnable() { | 39 private final Runnable mUpdateProgressRunnable = new Runnable() { |
48 @Override | 40 @Override |
49 public void run() { | 41 public void run() { |
50 mProgressBar.setProgress(mProgress); | 42 mProgressBar.setProgress(100 * mProgress); |
51 if (mLoading) { | 43 if (mLoading) { |
52 mStopReloadButton.setImageResource( | 44 mStopReloadButton.setImageResource( |
53 R.drawable.btn_close); | 45 R.drawable.btn_close); |
54 } else { | 46 } else { |
55 mStopReloadButton.setImageResource(R.drawable.btn_toolbar_reload
); | 47 mStopReloadButton.setImageResource(R.drawable.btn_toolbar_reload
); |
56 ApiCompatibilityUtils.postOnAnimationDelayed(ChromeShellToolbar.
this, | |
57 mClearProgressRunnable, COMPLETED_PROGRESS_TIMEOUT_MS); | |
58 } | 48 } |
59 } | 49 } |
60 }; | 50 }; |
61 | 51 |
62 private EditText mUrlTextView; | 52 private EditText mUrlTextView; |
63 private SmoothProgressBar mProgressBar; | 53 private ClipDrawableProgressBar mProgressBar; |
64 | 54 |
65 private ChromeShellTab mTab; | 55 private ChromeShellTab mTab; |
66 private final TabObserver mTabObserver; | 56 private final TabObserver mTabObserver; |
67 | 57 |
68 private AppMenuHandler mMenuHandler; | 58 private AppMenuHandler mMenuHandler; |
69 private AppMenuButtonHelper mAppMenuButtonHelper; | 59 private AppMenuButtonHelper mAppMenuButtonHelper; |
70 | 60 |
71 private TabManager mTabManager; | 61 private TabManager mTabManager; |
72 | 62 |
73 private SuggestionPopup mSuggestionPopup; | 63 private SuggestionPopup mSuggestionPopup; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 */ | 106 */ |
117 public void setTabManager(TabManager tabManager) { | 107 public void setTabManager(TabManager tabManager) { |
118 mTabManager = tabManager; | 108 mTabManager = tabManager; |
119 } | 109 } |
120 | 110 |
121 private void onUpdateUrl(String url) { | 111 private void onUpdateUrl(String url) { |
122 mUrlTextView.setText(url); | 112 mUrlTextView.setText(url); |
123 } | 113 } |
124 | 114 |
125 private void onLoadProgressChanged(int progress) { | 115 private void onLoadProgressChanged(int progress) { |
126 removeCallbacks(mClearProgressRunnable); | |
127 removeCallbacks(mUpdateProgressRunnable); | 116 removeCallbacks(mUpdateProgressRunnable); |
128 mProgress = progress; | 117 mProgress = progress; |
129 mLoading = progress != 100; | 118 mLoading = progress != 100; |
130 ApiCompatibilityUtils.postOnAnimation(this, mUpdateProgressRunnable); | 119 ApiCompatibilityUtils.postOnAnimation(this, mUpdateProgressRunnable); |
131 } | 120 } |
132 | 121 |
133 /** | 122 /** |
134 * Closes the suggestion popup. | 123 * Closes the suggestion popup. |
135 */ | 124 */ |
136 public void hideSuggestions() { | 125 public void hideSuggestions() { |
137 if (mSuggestionPopup != null) mSuggestionPopup.hideSuggestions(); | 126 if (mSuggestionPopup != null) mSuggestionPopup.hideSuggestions(); |
138 } | 127 } |
139 | 128 |
140 @Override | 129 @Override |
141 protected void onFinishInflate() { | 130 protected void onFinishInflate() { |
142 super.onFinishInflate(); | 131 super.onFinishInflate(); |
143 | 132 |
144 mProgressBar = (SmoothProgressBar) findViewById(R.id.progress); | 133 mProgressBar = (ClipDrawableProgressBar) findViewById(R.id.progress); |
145 initializeUrlField(); | 134 initializeUrlField(); |
146 initializeTabSwitcherButton(); | 135 initializeTabSwitcherButton(); |
147 initializeMenuButton(); | 136 initializeMenuButton(); |
148 initializeStopReloadButton(); | 137 initializeStopReloadButton(); |
149 initializeAddButton(); | 138 initializeAddButton(); |
150 } | 139 } |
151 | 140 |
152 void setMenuHandler(AppMenuHandler menuHandler) { | 141 void setMenuHandler(AppMenuHandler menuHandler) { |
153 mMenuHandler = menuHandler; | 142 mMenuHandler = menuHandler; |
154 mAppMenuButtonHelper = new AppMenuButtonHelper(mMenuHandler); | 143 mAppMenuButtonHelper = new AppMenuButtonHelper(mMenuHandler); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 public void onLoadProgressChanged(Tab tab, int progress) { | 288 public void onLoadProgressChanged(Tab tab, int progress) { |
300 if (tab == mTab) ChromeShellToolbar.this.onLoadProgressChanged(progr
ess); | 289 if (tab == mTab) ChromeShellToolbar.this.onLoadProgressChanged(progr
ess); |
301 } | 290 } |
302 | 291 |
303 @Override | 292 @Override |
304 public void onUpdateUrl(Tab tab, String url) { | 293 public void onUpdateUrl(Tab tab, String url) { |
305 if (tab == mTab) ChromeShellToolbar.this.onUpdateUrl(url); | 294 if (tab == mTab) ChromeShellToolbar.this.onUpdateUrl(url); |
306 } | 295 } |
307 } | 296 } |
308 } | 297 } |
OLD | NEW |