Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1223)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/toolbar/TabSwitcherCallout.java

Issue 1909763002: Add callout for the tab switcher button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/toolbar/TabSwitcherCallout.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/TabSwitcherCallout.java b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/TabSwitcherCallout.java
new file mode 100644
index 0000000000000000000000000000000000000000..742ed43d53e371999c961a7ef31d1c9f68ce37c3
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/TabSwitcherCallout.java
@@ -0,0 +1,92 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.toolbar;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Handler;
+import android.preference.PreferenceManager;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+
+import org.chromium.chrome.R;
+import org.chromium.chrome.browser.widget.TextBubble;
+
+/**
+ * Draws a bubble pointing upward at the tab switcher button.
+ */
+public class TabSwitcherCallout extends TextBubble {
+ public static final String PREF_NEED_TO_SHOW_TAB_SWITCHER_CALLOUT =
+ "org.chromium.chrome.browser.toolbar.NEED_TO_SHOW_TAB_SWITCHER_CALLOUT";
+
+ private static final int TAB_SWITCHER_CALLOUT_DISMISS_MS = 10000;
+ private static final float Y_OVERLAP_PERCENTAGE = 0.33f;
+
+ private static Boolean sIsTabSwitcherCalloutNecessary = null;
+
+ /**
+ * Show the TabSwitcherCallout, if necessary.
+ * @param context Context to draw resources from.
+ * @param tabSwitcherButton Button that triggers the tab switcher.
+ * @return TabSwitcherCallout if one was shown, null otherwise.
+ */
+ public static TabSwitcherCallout showIfNecessary(Context context, View tabSwitcherButton) {
+ if (!isTabSwitcherCalloutNecessary(context)) return null;
+ setIsTabSwitcherCalloutNecessary(context, false);
+
+ final TabSwitcherCallout callout = new TabSwitcherCallout(context);
+ callout.show(tabSwitcherButton);
+
+ // Dismiss the popup automatically after a delay.
+ new Handler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ callout.dismiss();
+ }
+ }, TAB_SWITCHER_CALLOUT_DISMISS_MS);
+
+ return callout;
+ }
+
+ @Override
+ protected View createContent(Context context) {
+ View content = LayoutInflater.from(context).inflate(R.layout.tab_switcher_callout, null);
+
+ // Dismiss the popup when the "OK" button is clicked.
+ View okButton = content.findViewById(R.id.confirm_button);
+ okButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dismiss();
+ }
+ });
+
+ return content;
+ }
+
+ /** @return Whether or not the tab switcher button callout needs to be shown. */
+ public static boolean isTabSwitcherCalloutNecessary(Context context) {
+ if (sIsTabSwitcherCalloutNecessary == null) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ sIsTabSwitcherCalloutNecessary =
+ prefs.getBoolean(PREF_NEED_TO_SHOW_TAB_SWITCHER_CALLOUT, false);
+ }
+ return sIsTabSwitcherCalloutNecessary;
+ }
+
+ /**
+ * Sets whether the tab switcher callout should be shown when the browser starts up.
+ */
+ public static void setIsTabSwitcherCalloutNecessary(Context context, boolean shouldShow) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ prefs.edit().putBoolean(PREF_NEED_TO_SHOW_TAB_SWITCHER_CALLOUT, shouldShow).apply();
+ sIsTabSwitcherCalloutNecessary = shouldShow;
+ }
+
+ private TabSwitcherCallout(Context context) {
+ super(context, 0.33f);
Ted C 2016/04/21 16:31:48 Y_OVERLAP_PERCENTAGE?
gone 2016/04/21 21:18:26 Knew there was a reason that I added that constant
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698