OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.browser.widget.bottomsheet; | 5 package org.chromium.chrome.browser.widget.bottomsheet; |
6 | 6 |
7 import android.animation.Animator; | 7 import android.animation.Animator; |
8 import android.animation.AnimatorListenerAdapter; | 8 import android.animation.AnimatorListenerAdapter; |
9 import android.animation.AnimatorSet; | 9 import android.animation.AnimatorSet; |
10 import android.animation.ObjectAnimator; | 10 import android.animation.ObjectAnimator; |
(...skipping 25 matching lines...) Expand all Loading... |
36 import org.chromium.chrome.browser.TabLoadStatus; | 36 import org.chromium.chrome.browser.TabLoadStatus; |
37 import org.chromium.chrome.browser.firstrun.FirstRunStatus; | 37 import org.chromium.chrome.browser.firstrun.FirstRunStatus; |
38 import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; | 38 import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; |
39 import org.chromium.chrome.browser.ntp.NativePageFactory; | 39 import org.chromium.chrome.browser.ntp.NativePageFactory; |
40 import org.chromium.chrome.browser.ntp.NewTabPage; | 40 import org.chromium.chrome.browser.ntp.NewTabPage; |
41 import org.chromium.chrome.browser.tab.Tab; | 41 import org.chromium.chrome.browser.tab.Tab; |
42 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; | 42 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; |
43 import org.chromium.chrome.browser.tabmodel.TabModel; | 43 import org.chromium.chrome.browser.tabmodel.TabModel; |
44 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 44 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
45 import org.chromium.chrome.browser.toolbar.BottomToolbarPhone; | 45 import org.chromium.chrome.browser.toolbar.BottomToolbarPhone; |
| 46 import org.chromium.chrome.browser.util.FeatureUtilities; |
46 import org.chromium.chrome.browser.util.MathUtils; | 47 import org.chromium.chrome.browser.util.MathUtils; |
47 import org.chromium.chrome.browser.widget.FadingBackgroundView; | 48 import org.chromium.chrome.browser.widget.FadingBackgroundView; |
48 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentControll
er.ContentType; | 49 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentControll
er.ContentType; |
49 import org.chromium.chrome.browser.widget.textbubble.ViewAnchoredTextBubble; | 50 import org.chromium.chrome.browser.widget.textbubble.ViewAnchoredTextBubble; |
50 import org.chromium.content_public.browser.LoadUrlParams; | 51 import org.chromium.content_public.browser.LoadUrlParams; |
51 | 52 |
52 import java.lang.annotation.Retention; | 53 import java.lang.annotation.Retention; |
53 import java.lang.annotation.RetentionPolicy; | 54 import java.lang.annotation.RetentionPolicy; |
54 import java.util.ArrayList; | 55 import java.util.ArrayList; |
55 import java.util.List; | 56 import java.util.List; |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 addObserver(mMetrics); | 376 addObserver(mMetrics); |
376 } | 377 } |
377 | 378 |
378 /** | 379 /** |
379 * Sets whether the {@link BottomSheet} and its children should react to tou
ch events. | 380 * Sets whether the {@link BottomSheet} and its children should react to tou
ch events. |
380 */ | 381 */ |
381 public void setTouchEnabled(boolean enabled) { | 382 public void setTouchEnabled(boolean enabled) { |
382 mIsTouchEnabled = enabled; | 383 mIsTouchEnabled = enabled; |
383 } | 384 } |
384 | 385 |
| 386 /** |
| 387 * A notification that the "expand" button for the bottom sheet has been pre
ssed. |
| 388 */ |
| 389 public void onExpandButtonPressed() { |
| 390 mMetrics.recordSheetOpenReason(BottomSheetMetrics.OPENED_BY_EXPAND_BUTTO
N); |
| 391 setSheetState(BottomSheet.SHEET_STATE_HALF, true); |
| 392 } |
| 393 |
385 @Override | 394 @Override |
386 public boolean onInterceptTouchEvent(MotionEvent e) { | 395 public boolean onInterceptTouchEvent(MotionEvent e) { |
387 // If touch is disabled, act like a black hole and consume touch events
without doing | 396 // If touch is disabled, act like a black hole and consume touch events
without doing |
388 // anything with them. | 397 // anything with them. |
389 if (!mIsTouchEnabled) return true; | 398 if (!mIsTouchEnabled) return true; |
390 | 399 |
391 if (!canMoveSheet()) return false; | 400 if (!canMoveSheet()) return false; |
392 | 401 |
393 // The incoming motion event may have been adjusted by the view sending
it down. Create a | 402 // The incoming motion event may have been adjusted by the view sending
it down. Create a |
394 // motion event with the raw (x, y) coordinates of the original so the g
esture detector | 403 // motion event with the raw (x, y) coordinates of the original so the g
esture detector |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 | 1148 |
1140 /** | 1149 /** |
1141 * Checks whether the sheet can be moved. It cannot be moved when the activi
ty is in overview | 1150 * Checks whether the sheet can be moved. It cannot be moved when the activi
ty is in overview |
1142 * mode, when "find in page" is visible, or when the toolbar is hidden. | 1151 * mode, when "find in page" is visible, or when the toolbar is hidden. |
1143 */ | 1152 */ |
1144 private boolean canMoveSheet() { | 1153 private boolean canMoveSheet() { |
1145 boolean isInOverviewMode = mTabModelSelector != null | 1154 boolean isInOverviewMode = mTabModelSelector != null |
1146 && (mTabModelSelector.getCurrentTab() == null | 1155 && (mTabModelSelector.getCurrentTab() == null |
1147 || mTabModelSelector.getCurrentTab().getActivity().is
InOverviewMode()); | 1156 || mTabModelSelector.getCurrentTab().getActivity().is
InOverviewMode()); |
1148 | 1157 |
| 1158 // If the expand button is enabled, do not allow swiping when the sheet
is in the peeking |
| 1159 // position. |
| 1160 boolean blockPeekingSwipes = FeatureUtilities.isChromeHomeExpandButtonEn
abled() |
| 1161 && getSheetState() == SHEET_STATE_PEEK; |
| 1162 |
1149 if (mFindInPageView == null) mFindInPageView = findViewById(R.id.find_to
olbar); | 1163 if (mFindInPageView == null) mFindInPageView = findViewById(R.id.find_to
olbar); |
1150 boolean isFindInPageVisible = | 1164 boolean isFindInPageVisible = |
1151 mFindInPageView != null && mFindInPageView.getVisibility() == Vi
ew.VISIBLE; | 1165 mFindInPageView != null && mFindInPageView.getVisibility() == Vi
ew.VISIBLE; |
1152 return !isToolbarAndroidViewHidden() && !isInOverviewMode && !isFindInPa
geVisible; | 1166 return !isToolbarAndroidViewHidden() && !isInOverviewMode && !isFindInPa
geVisible |
| 1167 && !blockPeekingSwipes; |
1153 } | 1168 } |
1154 | 1169 |
1155 private void showHelpBubbleIfNecessary() { | 1170 private void showHelpBubbleIfNecessary() { |
1156 // The help bubble should only be shown after layout has occurred so tha
t the anchor view is | 1171 // The help bubble should only be shown after layout has occurred so tha
t the anchor view is |
1157 // in the correct position on the screen. It also must be shown after th
e tab state has been | 1172 // in the correct position on the screen. It also must be shown after th
e tab state has been |
1158 // initialized so that any tab that auto-opens the BottomSheet has had a
chance to do so. | 1173 // initialized so that any tab that auto-opens the BottomSheet has had a
chance to do so. |
1159 assert mHasRootLayoutOccurred && mTabModelSelector != null | 1174 assert mHasRootLayoutOccurred && mTabModelSelector != null |
1160 && mTabModelSelector.isTabStateInitialized(); | 1175 && mTabModelSelector.isTabStateInitialized(); |
1161 | 1176 |
1162 // If FRE is not complete, the FRE screen is likely covering ChromeTabbe
dActivity so the | 1177 // If FRE is not complete, the FRE screen is likely covering ChromeTabbe
dActivity so the |
1163 // help bubble should not be shown. Also skip showing if the bottom shee
t is already open. | 1178 // help bubble should not be shown. Also skip showing if the bottom shee
t is already open. |
1164 if (!FirstRunStatus.getFirstRunFlowComplete() || mCurrentState != SHEET_
STATE_PEEK) return; | 1179 if (!FirstRunStatus.getFirstRunFlowComplete() || mCurrentState != SHEET_
STATE_PEEK) return; |
1165 | 1180 |
1166 SharedPreferences preferences = ContextUtils.getAppSharedPreferences(); | 1181 SharedPreferences preferences = ContextUtils.getAppSharedPreferences(); |
1167 if (preferences.getBoolean(BOTTOM_SHEET_HELP_BUBBLE_SHOWN, false)) retur
n; | 1182 if (preferences.getBoolean(BOTTOM_SHEET_HELP_BUBBLE_SHOWN, false)) retur
n; |
1168 | 1183 |
1169 ViewAnchoredTextBubble helpBubble = new ViewAnchoredTextBubble( | 1184 ViewAnchoredTextBubble helpBubble = new ViewAnchoredTextBubble( |
1170 getContext(), mControlContainer, R.string.bottom_sheet_help_bubb
le_message); | 1185 getContext(), mControlContainer, R.string.bottom_sheet_help_bubb
le_message); |
1171 int inset = getContext().getResources().getDimensionPixelSize( | 1186 int inset = getContext().getResources().getDimensionPixelSize( |
1172 R.dimen.bottom_sheet_help_bubble_inset); | 1187 R.dimen.bottom_sheet_help_bubble_inset); |
1173 helpBubble.setInsetPx(0, inset, 0, inset); | 1188 helpBubble.setInsetPx(0, inset, 0, inset); |
1174 helpBubble.setDismissOnTouchInteraction(true); | 1189 helpBubble.setDismissOnTouchInteraction(true); |
1175 helpBubble.show(); | 1190 helpBubble.show(); |
1176 | 1191 |
1177 preferences.edit().putBoolean(BOTTOM_SHEET_HELP_BUBBLE_SHOWN, true).appl
y(); | 1192 preferences.edit().putBoolean(BOTTOM_SHEET_HELP_BUBBLE_SHOWN, true).appl
y(); |
1178 } | 1193 } |
1179 } | 1194 } |
OLD | NEW |