Skip to content

Commit

Permalink
[Home] Record some user actions for the Chrome Home BottomSheet
Browse files Browse the repository at this point in the history
Record user actions for:
 * Android.ChromeHome.Closed
 * Android.ChromeHome.FullState
 * Android.ChromeHome.HalfState
 * Android.ChromeHome.Opened
 * Android.ChromeHome.ShowBookmarks
 * Android.ChromeHome.ShowDownloads
 * Android.ChromeHome.ShowHistory
 * Android.ChromeHome.ShowSuggestions

BUG=700589

Review-Url: https://codereview.chromium.org/2754313002
Cr-Commit-Position: refs/heads/master@{#458229}
  • Loading branch information
twellington authored and Commit bot committed Mar 20, 2017
1 parent de52d16 commit 09e0b1f
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.toolbar.BottomToolbarPhone;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentController;

/**
* A {@link BottomSheetContent} holding a {@link BookmarkManager} for display in the BottomSheet.
Expand Down Expand Up @@ -52,4 +53,9 @@ public void destroy() {
mBookmarkManager.destroy();
mBookmarkManager = null;
}

@Override
public int getType() {
return BottomSheetContentController.TYPE_BOOKMARKS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.chromium.chrome.browser.download.ui.DownloadManagerUi;
import org.chromium.chrome.browser.toolbar.BottomToolbarPhone;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentController;

/**
* A {@link BottomSheetContent} holding a {@link DownloadManagerUi} for display in the BottomSheet.
Expand Down Expand Up @@ -78,4 +79,9 @@ public void destroy() {
mDownloadManager = null;
ApplicationStatus.unregisterActivityStateListener(mActivityStateListener);
}

@Override
public int getType() {
return BottomSheetContentController.TYPE_DOWNLOADS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.toolbar.BottomToolbarPhone;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentController;

/**
* A {@link BottomSheetContent} holding a {@link HistoryManager} for display in the BottomSheet.
Expand Down Expand Up @@ -50,4 +51,9 @@ public void destroy() {
mHistoryManager.onDestroyed();
mHistoryManager = null;
}

@Override
public int getType() {
return BottomSheetContentController.TYPE_HISTORY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentController;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
import org.chromium.chrome.browser.widget.displaystyle.UiConfig;

Expand Down Expand Up @@ -93,11 +94,17 @@ public ContextMenuManager getContextMenuManager() {
return mContextMenuManager;
}

@Override
public void destroy() {
mSuggestionsManager.onDestroy();
mTileGroupDelegate.destroy();
}

@Override
public int getType() {
return BottomSheetContentController.TYPE_SUGGESTIONS;
}

public static void setSuggestionsSourceForTesting(SuggestionsSource suggestionsSource) {
sSuggestionsSourceForTesting = suggestionsSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,45 @@
import org.chromium.chrome.R;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;

/**
* Phone specific toolbar that exists at the bottom of the screen.
*/
public class BottomToolbarPhone extends ToolbarPhone implements BottomSheetObserver {
public class BottomToolbarPhone extends ToolbarPhone {
/**
* The observer used to listen to {@link BottomSheet} events.
*/
private final BottomSheetObserver mBottomSheetObserver = new EmptyBottomSheetObserver() {
@Override
public void onTransitionPeekToHalf(float transitionFraction) {
// TODO(twellington): animate end toolbar button appearance/disappearance.
if (transitionFraction >= 0.5 && !mShouldHideEndToolbarButtons) {
mShouldHideEndToolbarButtons = true;
updateUrlExpansionAnimation();
} else if (transitionFraction < 0.5 && mShouldHideEndToolbarButtons) {
mShouldHideEndToolbarButtons = false;
updateUrlExpansionAnimation();
}

boolean buttonsClickable = transitionFraction == 0.f;
mToggleTabStackButton.setClickable(buttonsClickable);
mMenuButton.setClickable(buttonsClickable);
}

@Override
public void onSheetOffsetChanged(float heightFraction) {
boolean isMovingDown = heightFraction < mLastHeightFraction;
mLastHeightFraction = heightFraction;

// The only time the omnibox should have focus is when the sheet is fully expanded. Any
// movement of the sheet should unfocus it.
if (isMovingDown && getLocationBar().isUrlBarFocused()) {
getLocationBar().setUrlBarFocus(false);
}
}
};

/** The white version of the toolbar handle; used for dark themes and incognito. */
private final Bitmap mHandleLight;

Expand Down Expand Up @@ -87,7 +121,7 @@ public void setBottomSheet(BottomSheet sheet) {

mBottomSheet = sheet;
getLocationBar().setBottomSheet(mBottomSheet);
mBottomSheet.addObserver(this);
mBottomSheet.addObserver(mBottomSheetObserver);
}

@Override
Expand Down Expand Up @@ -195,43 +229,6 @@ protected boolean shouldHideEndToolbarButtons() {
return mShouldHideEndToolbarButtons;
}

@Override
public void onSheetOpened() {}

@Override
public void onSheetClosed() {}

@Override
public void onLoadUrl(String url) {}

@Override
public void onTransitionPeekToHalf(float transitionFraction) {
// TODO(twellington): animate end toolbar button appearance/disappearance.
if (transitionFraction >= 0.5 && !mShouldHideEndToolbarButtons) {
mShouldHideEndToolbarButtons = true;
updateUrlExpansionAnimation();
} else if (transitionFraction < 0.5 && mShouldHideEndToolbarButtons) {
mShouldHideEndToolbarButtons = false;
updateUrlExpansionAnimation();
}

boolean buttonsClickable = transitionFraction == 0.f;
mToggleTabStackButton.setClickable(buttonsClickable);
mMenuButton.setClickable(buttonsClickable);
}

@Override
public void onSheetOffsetChanged(float heightFraction) {
boolean isMovingDown = heightFraction < mLastHeightFraction;
mLastHeightFraction = heightFraction;

// The only time the omnibox should have focus is when the sheet is fully expanded. Any
// movement of the sheet should unfocus it.
if (isMovingDown && getLocationBar().isUrlBarFocused()) {
getLocationBar().setUrlBarFocus(false);
}
}

/**
* Sets the height and title text appearance of the provided toolbar so that its style is
* consistent with BottomToolbarPhone.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.util.MathUtils;
import org.chromium.chrome.browser.widget.FadingBackgroundView;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentController.ContentType;
import org.chromium.content_public.browser.LoadUrlParams;

import java.lang.annotation.Retention;
Expand Down Expand Up @@ -151,6 +152,9 @@ public class BottomSheet
/** The last non-default toolbar view that was attached to mToolbarHolder. */
private View mLastToolbarView;

/** Whether the sheet is currently open. */
private boolean mIsSheetOpen;

/**
* An interface defining content that can be displayed inside of the bottom sheet for Chrome
* Home.
Expand Down Expand Up @@ -182,6 +186,12 @@ public interface BottomSheetContent {
* Called to destroy the BottomSheetContent when it is no longer in use.
*/
void destroy();

/**
* @return The {@link BottomSheetContentController.ContentType} for this content.
*/
@ContentType
int getType();
}

/**
Expand Down Expand Up @@ -271,6 +281,8 @@ public BottomSheet(Context context, AttributeSet atts) {

mGestureDetector = new GestureDetector(context, new BottomSheetSwipeDetector());
mGestureDetector.setIsLongpressEnabled(false);

addObserver(new BottomSheetMetrics());
}

@Override
Expand Down Expand Up @@ -505,6 +517,10 @@ public void showContent(BottomSheetContent content) {
} else {
mDefaultToolbarView.setVisibility(View.VISIBLE);
}

for (BottomSheetObserver o : mObservers) {
o.onSheetContentChanged(mSheetContent);
}
}

/**
Expand All @@ -525,13 +541,19 @@ private boolean isTouchEventInToolbar(MotionEvent e) {
* A notification that the sheet is exiting the peek state into one that shows content.
*/
private void onSheetOpened() {
if (mIsSheetOpen) return;

mIsSheetOpen = true;
for (BottomSheetObserver o : mObservers) o.onSheetOpened();
}

/**
* A notification that the sheet has returned to the peeking state.
*/
private void onSheetClosed() {
if (!mIsSheetOpen) return;

mIsSheetOpen = false;
for (BottomSheetObserver o : mObservers) o.onSheetClosed();
}

Expand Down Expand Up @@ -728,13 +750,20 @@ private void sendOffsetChangeEvents() {
* move there instantly.
*/
public void setSheetState(@SheetState int state, boolean animate) {
boolean stateChanged = state != mCurrentState;
mCurrentState = state;

if (animate) {
createSettleAnimation(state);
} else {
setSheetOffsetFromBottom(getSheetHeightForState(state));
}

if (!stateChanged) return;

for (BottomSheetObserver o : mObservers) {
o.onSheetStateChanged(mCurrentState);
}
}

/**
Expand Down
Loading

0 comments on commit 09e0b1f

Please sign in to comment.