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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java

Issue 2022313002: UI for the Data Saver InfoBar Promo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@infobarPromo
Patch Set: use app_icon Created 4 years, 6 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/infobar/DataReductionPromoInfoBar.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java
index 9010d0290f3eb61f6ca7512734f85f08fada20f6..e22f66b88f2e2ee7ff4c48998b56cda664a05394 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java
@@ -7,13 +7,21 @@ package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.text.SpannableString;
+import org.chromium.base.CommandLine;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.UrlConstants;
+import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
+import org.chromium.chrome.browser.preferences.PrefServiceBridge.AboutVersionStrings;
import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoUtils;
+import org.chromium.chrome.browser.preferences.datareduction.DataReductionProxyUma;
import org.chromium.content_public.browser.WebContents;
import org.chromium.net.GURLUtils;
+import org.chromium.ui.widget.Toast;
import java.sql.Date;
import java.util.Calendar;
@@ -23,9 +31,10 @@ import java.util.TimeZone;
* Generates an InfoBar to promote the data reduction proxy. The InfoBar contains a message and a
* button to enable the proxy.
Raj 2016/06/13 17:52:18 Add something like this at the end. The InfoBar is
megjablon 2016/06/23 23:17:30 Done.
*/
-public class DataReductionPromoInfoBar {
+public class DataReductionPromoInfoBar extends ConfirmInfoBar {
private static final String M48_RELEASE_DATE = "2016-01-26";
+ private static Bitmap sIcon;
Raj 2016/06/13 17:52:18 These could be nonstatic final, similar to how oth
megjablon 2016/06/23 23:17:30 I believe the other classes are using native image
Raj 2016/06/25 01:21:10 Acknowledged.
private static String sTitle;
private static String sText;
private static String sPrimaryButtonText;
@@ -74,10 +83,14 @@ public class DataReductionPromoInfoBar {
}
// Only show the promo if the current version is at least two milestones after the last
- // promo was displayed.
- if (currentMilestone < lastPromoMilestone + 2) return;
+ // promo was displayed or the command line switch is on.
+ if (!CommandLine.getInstance().hasSwitch("enable-data-reduction-promo-infobar")
+ && currentMilestone < lastPromoMilestone + 2) {
+ return;
+ }
DataReductionPromoInfoBar.launch(webContents,
+ BitmapFactory.decodeResource(context.getResources(), R.mipmap.app_icon),
context.getString(R.string.data_reduction_promo_infobar_title),
context.getString(R.string.data_reduction_promo_infobar_text),
context.getString(R.string.data_reduction_promo_infobar_button),
@@ -131,12 +144,15 @@ public class DataReductionPromoInfoBar {
/**
* Launch a data reduction proxy {@link InfoBar} with the specified title and link
* text. Clicking the link will open the specified settings page.
+ *
* @param webContents The {@link WebContents} in which to open the {@link InfoBar}.
+ * @param context An Android context.
* @param title The text to display in the {@link InfoBar}.
* @param primaryButtonText The text to display on the primary button.
* @param secondaryButtonText The text to display on the secondary button.
*/
private static void launch(WebContents webContents,
+ Bitmap icon,
String title,
String text,
String primaryButtonText,
@@ -145,7 +161,40 @@ public class DataReductionPromoInfoBar {
sText = text;
sPrimaryButtonText = primaryButtonText;
sSecondaryButtonText = secondaryButtonText;
- // TODO(megjablon): Show infobar.
- DataReductionPromoUtils.saveInfoBarPromoDisplayed();
+ sIcon = icon;
+ DataReductionPromoInfoBarDelegate.launch(webContents);
+ AboutVersionStrings versionStrings = PrefServiceBridge.getInstance()
+ .getAboutVersionStrings();
+ DataReductionPromoUtils
+ .saveInfoBarPromoDisplayed(versionStrings.getApplicationVersion());
+ }
+
+ DataReductionPromoInfoBar() {
+ super(0, sIcon, sTitle, null, sPrimaryButtonText, sSecondaryButtonText);
+ }
+
+ @Override
+ public void onButtonClicked(boolean isPrimaryButton) {
+ super.onButtonClicked(isPrimaryButton);
+ if (isPrimaryButton) {
+ DataReductionProxyUma
+ .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_INFOBAR_ENABLED);
+ DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
+ getContext(), true);
+ Toast.makeText(getContext(),
+ getContext().getString(R.string.data_reduction_enabled_toast),
+ Toast.LENGTH_LONG).show();
+ } else {
+ DataReductionProxyUma
+ .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_INFOBAR_DISABLED);
+ }
+ }
+
+ @Override
+ public void createContent(InfoBarLayout layout) {
+ super.createContent(layout);
+ InfoBarControlLayout control = layout.addControlLayout();
+ SpannableString text = new SpannableString(sText);
+ control.addDescription(text);
}
}

Powered by Google App Engine
This is Rietveld 408576698