Bug 1268647 - Add Tab queue panel. r=sebastian draft
authorChenxia Liu <liuche@mozilla.com>
Tue, 10 May 2016 20:46:58 -0700
changeset 366175 b85ab019bb1559d09df4fb0a55a303a663a2eef9
parent 366174 73173f7c1e55eaf127c84f65175ab998c92de850
child 366176 e21ec356415e2d56879ce112f19cd701ae154517
push id17914
push usercliu@mozilla.com
push dateThu, 12 May 2016 04:08:30 +0000
reviewerssebastian
bugs1268647
milestone49.0a1
Bug 1268647 - Add Tab queue panel. r=sebastian MozReview-Commit-ID: wac02N7Lh6
mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPagerConfig.java
mobile/android/base/java/org/mozilla/gecko/firstrun/TabQueuePanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPagerConfig.java
+++ b/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPagerConfig.java
@@ -21,28 +21,30 @@ public class FirstrunPagerConfig {
     public static final String LOGTAG = "FirstrunPagerConfig";
 
     public static final String KEY_IMAGE = "imageRes";
     public static final String KEY_TEXT = "textRes";
     public static final String KEY_SUBTEXT = "subtextRes";
 
    public static List<FirstrunPanelConfig> getDefault(Context context) {
         final List<FirstrunPanelConfig> panels = new LinkedList<>();
+
         if (Experiments.isInExperimentLocal(context, Experiments.ONBOARDING3_A)) {
             Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING3_A);
             GeckoSharedPrefs.forProfile(context).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING3_A).apply();
         } else if (Experiments.isInExperimentLocal(context, Experiments.ONBOARDING3_B)) {
             panels.add(SimplePanelConfigs.urlbarPanelConfig);
             panels.add(SimplePanelConfigs.bookmarksPanelConfig);
             panels.add(SimplePanelConfigs.dataPanelConfig);
             panels.add(SimplePanelConfigs.syncPanelConfig);
             panels.add(SimplePanelConfigs.signInPanelConfig);
             Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING3_B);
             GeckoSharedPrefs.forProfile(context).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING3_B).apply();
         } else if (Experiments.isInExperimentLocal(context, Experiments.ONBOARDING3_C)) {
+            panels.add(SimplePanelConfigs.tabqueuePanelConfig);
             panels.add(SimplePanelConfigs.notificationsPanelConfig);
             panels.add(SimplePanelConfigs.readerviewPanelConfig);
             panels.add(SimplePanelConfigs.accountPanelConfig);
             Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING3_C);
             GeckoSharedPrefs.forProfile(context).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING3_C).apply();
         } else {
             Log.d(LOGTAG, "Not in an experiment!");
         }
@@ -96,13 +98,14 @@ public class FirstrunPagerConfig {
 
     protected static class SimplePanelConfigs {
         public static final FirstrunPanelConfig urlbarPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_panel_title_welcome, R.drawable.firstrun_urlbar, R.string.firstrun_urlbar_message, R.string.firstrun_urlbar_subtext);
         public static final FirstrunPanelConfig bookmarksPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_bookmarks_title, R.drawable.firstrun_bookmarks, R.string.firstrun_bookmarks_message, R.string.firstrun_bookmarks_subtext);
         public static final FirstrunPanelConfig dataPanelConfig = new FirstrunPanelConfig(DataPanel.class.getName(), R.string.firstrun_data_title, R.drawable.firstrun_data_off, R.string.firstrun_data_message, R.string.firstrun_data_subtext);
         public static final FirstrunPanelConfig syncPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_sync_title, R.drawable.firstrun_sync, R.string.firstrun_sync_message, R.string.firstrun_sync_subtext);
         public static final FirstrunPanelConfig signInPanelConfig = new FirstrunPanelConfig(SyncPanel.class.getName(), R.string.pref_sync, R.drawable.firstrun_signin, R.string.firstrun_signin_message, R.string.firstrun_welcome_button_browser);
 
+        public static final FirstrunPanelConfig tabqueuePanelConfig = new FirstrunPanelConfig(TabQueuePanel.class.getName(), R.string.firstrun_tabqueue_title, R.drawable.firstrun_tabqueue_off, R.string.firstrun_tabqueue_message_off, R.string.firstrun_tabqueue_subtext_off);
         public static final FirstrunPanelConfig notificationsPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_notifications_title, R.drawable.firstrun_notifications, R.string.firstrun_notifications_message, R.string.firstrun_notifications_subtext);
         public static final FirstrunPanelConfig readerviewPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_readerview_title, R.drawable.firstrun_readerview, R.string.firstrun_readerview_message, R.string.firstrun_readerview_subtext);
         public static final FirstrunPanelConfig accountPanelConfig = new FirstrunPanelConfig(SyncPanel.class.getName(), R.string.firstrun_account_title, R.drawable.firstrun_account, R.string.firstrun_account_message, R.string.firstrun_button_notnow);
     }
 }
copy from mobile/android/base/java/org/mozilla/gecko/firstrun/DataPanel.java
copy to mobile/android/base/java/org/mozilla/gecko/firstrun/TabQueuePanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/firstrun/DataPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/firstrun/TabQueuePanel.java
@@ -1,47 +1,92 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.firstrun;
 
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.graphics.Typeface;
 import android.os.Bundle;
-import android.util.Log;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.widget.SwitchCompat;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.CompoundButton;
 import android.widget.ImageView;
+import android.widget.TextView;
 import org.mozilla.gecko.GeckoSharedPrefs;
-import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
+import org.mozilla.gecko.preferences.GeckoPreferences;
+import org.mozilla.gecko.tabqueue.TabQueueHelper;
+import org.mozilla.gecko.tabqueue.TabQueuePrompt;
 
-public class DataPanel extends FirstrunPanel {
-    private boolean isEnabled = false;
+public class TabQueuePanel extends FirstrunPanel {
+    private static final int REQUEST_CODE_TAB_QUEUE = 1;
+    private SwitchCompat toggleSwitch;
+    private ImageView imageView;
+    private TextView messageTextView;
+    private TextView subtextTextView;
+    private Context context;
 
     @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
+    public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstance) {
+        context = getContext();
         final View root = super.onCreateView(inflater, container, savedInstance);
-        final ImageView clickableImage = (ImageView) root.findViewById(R.id.firstrun_image);
-        clickableImage.setOnClickListener(new View.OnClickListener() {
+
+        imageView = (ImageView) root.findViewById(R.id.firstrun_image);
+        messageTextView = (TextView) root.findViewById(R.id.firstrun_text);
+        subtextTextView = (TextView) root.findViewById(R.id.firstrun_subtext);
+
+        toggleSwitch = (SwitchCompat) root.findViewById(R.id.firstrun_switch);
+        toggleSwitch.setVisibility(View.VISIBLE);
+        toggleSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
             @Override
-            public void onClick(View view) {
-                // Set new state.
-                isEnabled = !isEnabled;
-                int newResource = isEnabled ? R.drawable.firstrun_data_on : R.drawable.firstrun_data_off;
-                ((ImageView) view).setImageResource(newResource);
-                if (isEnabled) {
-                    // Always block images.
-                    PrefsHelper.setPref("browser.image_blocking", 0);
-                } else {
-                    // Default: always load images.
-                    PrefsHelper.setPref("browser.image_blocking", 1);
+            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+                Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.DIALOG, "firstrun_tabqueue-permissions");
+                if (b && !TabQueueHelper.canDrawOverlays(context)) {
+                    Intent promptIntent = new Intent(context, TabQueuePrompt.class);
+                    startActivityForResult(promptIntent, REQUEST_CODE_TAB_QUEUE);
+                    return;
                 }
-                Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, "firstrun-datasaving-" + isEnabled);
+
+                Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, "firstrun-tabqueue-" + b);
+
+                final SharedPreferences prefs = GeckoSharedPrefs.forApp(context);
+                final SharedPreferences.Editor editor = prefs.edit();
+                editor.putBoolean(GeckoPreferences.PREFS_TAB_QUEUE, b).apply();
+
+                // Set image, text, and typeface changes.
+                imageView.setImageResource(b ? R.drawable.firstrun_tabqueue_on : R.drawable.firstrun_tabqueue_off);
+                messageTextView.setText(b ? R.string.firstrun_tabqueue_message_on : R.string.firstrun_tabqueue_message_off);
+                messageTextView.setTypeface(b ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
+                subtextTextView.setText(b ? R.string.firstrun_tabqueue_subtext_on : R.string.firstrun_tabqueue_subtext_off);
+                subtextTextView.setTypeface(b ? Typeface.defaultFromStyle(Typeface.ITALIC) : Typeface.DEFAULT);
+                subtextTextView.setTextColor(b ? ContextCompat.getColor(context, R.color.fennec_ui_orange) : ContextCompat.getColor(context, R.color.placeholder_grey));
             }
         });
 
         return root;
     }
+
+    @Override
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+        switch (requestCode) {
+            case REQUEST_CODE_TAB_QUEUE:
+                final boolean accepted = TabQueueHelper.processTabQueuePromptResponse(resultCode, context);
+                if (accepted) {
+                    Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.DIALOG, "firstrun_tabqueue-permissions-yes");
+                    toggleSwitch.setChecked(true);
+                    Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, "firstrun-tabqueue-true");
+                }
+                Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.DIALOG, "firstrun_tabqueue-permissions-" + (accepted ? "accepted" : "rejected"));
+                break;
+        }
+    }
+
 }