Commit a2320352 authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Add Android metrics for the back/forward popup menu.

BUG=800033

Change-Id: Id64a04b6f46ec54ce4ec0a6a6a29de74e398b37a
Reviewed-on: https://chromium-review.googlesource.com/1220190Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590469}
parent 6080d055
......@@ -2071,7 +2071,8 @@ public class ChromeTabbedActivity
if (tab == null || tab.getWebContents() == null || !tab.isUserInteractable()) return;
mNavigationPopup = new NavigationPopup(tab.getProfile(), this,
tab.getWebContents().getNavigationController(), false, true);
tab.getWebContents().getNavigationController(),
NavigationPopup.Type.ANDROID_SYSTEM_BACK);
mNavigationPopup.setWidth(
getResources().getDimensionPixelSize(R.dimen.navigation_popup_width));
mNavigationPopup.setAnchorView(findViewById(R.id.navigation_popup_anchor_stub));
......
......@@ -10,6 +10,7 @@ import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.IntDef;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
......@@ -26,6 +27,7 @@ import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.favicon.FaviconHelper;
import org.chromium.chrome.browser.favicon.FaviconHelper.DefaultFaviconHelper;
......@@ -37,6 +39,8 @@ import org.chromium.content_public.browser.NavigationEntry;
import org.chromium.content_public.browser.NavigationHistory;
import org.chromium.ui.base.LocalizationUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.HashSet;
import java.util.Set;
......@@ -48,12 +52,22 @@ public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt
private static final int MAXIMUM_HISTORY_ITEMS = 8;
private static final int FULL_HISTORY_ENTRY_INDEX = -1;
/** Specifies the type of navigation popup being shown */
@IntDef({Type.ANDROID_SYSTEM_BACK, Type.TABLET_BACK, Type.TABLET_FORWARD})
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
int ANDROID_SYSTEM_BACK = 0;
int TABLET_BACK = 1;
int TABLET_FORWARD = 2;
}
private final Profile mProfile;
private final Context mContext;
private final NavigationController mNavigationController;
private NavigationHistory mHistory;
private final NavigationAdapter mAdapter;
private final ListItemFactory mListItemFactory;
private final @Type int mType;
private final int mFaviconSize;
......@@ -72,15 +86,18 @@ public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt
* @param profile The profile used for fetching favicons.
* @param context The context used for building the popup.
* @param navigationController The controller which takes care of page navigations.
* @param isForward Whether to request forward navigation entries.
* @param anchorToBottom Whether the popup is anchored to the bottom of the screen.
* @param type The type of navigation popup being triggered.
*/
public NavigationPopup(Profile profile, Context context,
NavigationController navigationController, boolean isForward, boolean anchorToBottom) {
NavigationController navigationController, @Type int type) {
super(context, null, android.R.attr.popupMenuStyle);
mProfile = profile;
mContext = context;
mNavigationController = navigationController;
mType = type;
boolean isForward = type == Type.TABLET_FORWARD;
boolean anchorToBottom = type == Type.ANDROID_SYSTEM_BACK;
mHistory = mNavigationController.getDirectedNavigationHistory(
isForward, MAXIMUM_HISTORY_ITEMS);
......@@ -114,9 +131,14 @@ public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt
mListItemFactory = new ListItemFactory(context);
}
private String buildComputedAction(String action) {
return (mType == Type.TABLET_FORWARD ? "ForwardMenu_" : "BackMenu_") + action;
}
@Override
public void show() {
if (!mInitialized) initialize();
if (!isShowing()) RecordUserAction.record(buildComputedAction("Popup"));
super.show();
if (mAdapter.mInReverseOrder) scrollToBottom();
}
......@@ -185,10 +207,15 @@ public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
NavigationEntry entry = (NavigationEntry) parent.getItemAtPosition(position);
if (entry.getIndex() == FULL_HISTORY_ENTRY_INDEX) {
RecordUserAction.record(buildComputedAction("ShowFullHistory"));
assert mContext instanceof ChromeActivity;
ChromeActivity activity = (ChromeActivity) mContext;
HistoryManagerUtils.showHistoryManager(activity, activity.getActivityTab());
} else {
int originalPosition =
mAdapter.mInReverseOrder ? mAdapter.getCount() - position - 1 : position;
// 1-based index to keep in line with Desktop implementation.
RecordUserAction.record(buildComputedAction("HistoryClick" + (originalPosition + 1)));
mNavigationController.goToNavigationIndex(entry.getIndex());
}
......
......@@ -298,7 +298,8 @@ public class ToolbarTablet
Tab tab = getToolbarDataProvider().getTab();
if (tab == null || tab.getWebContents() == null) return;
mNavigationPopup = new NavigationPopup(tab.getProfile(), getContext(),
tab.getWebContents().getNavigationController(), isForward, false);
tab.getWebContents().getNavigationController(),
isForward ? NavigationPopup.Type.TABLET_FORWARD : NavigationPopup.Type.TABLET_BACK);
mNavigationPopup.setAnchorView(anchorView);
......
......@@ -293,8 +293,8 @@ public class NavigationPopupTest {
private NavigationPopup showPopup(NavigationController controller) throws ExecutionException {
return ThreadUtils.runOnUiThreadBlocking(() -> {
NavigationPopup popup = new NavigationPopup(
mProfile, mActivityTestRule.getActivity(), controller, true, false);
NavigationPopup popup = new NavigationPopup(mProfile, mActivityTestRule.getActivity(),
controller, NavigationPopup.Type.TABLET_FORWARD);
popup.setWidth(300);
popup.setHeight(300);
popup.setAnchorView(mActivityTestRule.getActivity().getActivityTab().getContentView());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment