OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.preferences.datareduction; | 5 package org.chromium.chrome.browser.preferences.datareduction; |
6 | 6 |
7 import static org.chromium.third_party.android.datausagechart.ChartDataUsageView
.DAYS_IN_CHART; | 7 import static org.chromium.third_party.android.datausagechart.ChartDataUsageView
.DAYS_IN_CHART; |
8 | 8 |
9 import android.content.res.Resources; | 9 import android.content.res.Resources; |
10 import android.os.Bundle; | 10 import android.os.Bundle; |
11 import android.preference.Preference; | 11 import android.preference.Preference; |
12 import android.preference.Preference.OnPreferenceChangeListener; | 12 import android.preference.Preference.OnPreferenceChangeListener; |
13 import android.preference.PreferenceFragment; | 13 import android.preference.PreferenceFragment; |
14 import android.text.format.DateUtils; | 14 import android.text.format.DateUtils; |
15 import android.view.Menu; | 15 import android.view.Menu; |
16 import android.view.MenuInflater; | 16 import android.view.MenuInflater; |
17 import android.view.MenuItem; | 17 import android.view.MenuItem; |
18 | 18 |
19 import org.chromium.base.CommandLine; | 19 import org.chromium.base.CommandLine; |
20 import org.chromium.chrome.R; | 20 import org.chromium.chrome.R; |
21 import org.chromium.chrome.browser.help.HelpAndFeedback; | 21 import org.chromium.chrome.browser.help.HelpAndFeedback; |
22 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; | 22 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; |
23 import org.chromium.chrome.browser.preferences.ChromeSwitchPreference; | 23 import org.chromium.chrome.browser.preferences.ChromeSwitchPreference; |
24 import org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate; | 24 import org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate; |
25 import org.chromium.chrome.browser.profiles.Profile; | 25 import org.chromium.chrome.browser.profiles.Profile; |
| 26 import org.chromium.chrome.browser.snackbar.DataReductionPromoSnackbarController
; |
| 27 import org.chromium.chrome.browser.util.IntentUtils; |
26 import org.chromium.third_party.android.datausagechart.NetworkStats; | 28 import org.chromium.third_party.android.datausagechart.NetworkStats; |
27 import org.chromium.third_party.android.datausagechart.NetworkStatsHistory; | 29 import org.chromium.third_party.android.datausagechart.NetworkStatsHistory; |
28 | 30 |
29 /** | 31 /** |
30 * Settings fragment that allows the user to configure Data Saver. | 32 * Settings fragment that allows the user to configure Data Saver. |
31 */ | 33 */ |
32 public class DataReductionPreferences extends PreferenceFragment { | 34 public class DataReductionPreferences extends PreferenceFragment { |
33 | 35 |
34 public static final String PREF_DATA_REDUCTION_SWITCH = "data_reduction_swit
ch"; | 36 public static final String PREF_DATA_REDUCTION_SWITCH = "data_reduction_swit
ch"; |
35 private static final String PREF_DATA_REDUCTION_STATS = "data_reduction_stat
s"; | 37 private static final String PREF_DATA_REDUCTION_STATS = "data_reduction_stat
s"; |
36 | 38 |
37 // This is the same as Chromium data_reduction_proxy::switches::kEnableDataR
eductionProxy. | 39 // This is the same as Chromium data_reduction_proxy::switches::kEnableDataR
eductionProxy. |
38 private static final String ENABLE_DATA_REDUCTION_PROXY = "enable-spdy-proxy
-auth"; | 40 private static final String ENABLE_DATA_REDUCTION_PROXY = "enable-spdy-proxy
-auth"; |
39 | 41 |
40 private boolean mIsEnabled; | 42 private boolean mIsEnabled; |
41 private boolean mWasEnabledAtCreation; | 43 private boolean mWasEnabledAtCreation; |
| 44 /** Whether the current Activity is started from the snackbar promo. */ |
| 45 private boolean mFromPromo; |
42 | 46 |
43 @Override | 47 @Override |
44 public void onCreate(Bundle savedInstanceState) { | 48 public void onCreate(Bundle savedInstanceState) { |
45 super.onCreate(savedInstanceState); | 49 super.onCreate(savedInstanceState); |
46 | 50 |
47 addPreferencesFromResource(R.xml.data_reduction_preferences); | 51 addPreferencesFromResource(R.xml.data_reduction_preferences); |
48 getActivity().setTitle(R.string.data_reduction_title); | 52 getActivity().setTitle(R.string.data_reduction_title); |
49 boolean isEnabled = | 53 boolean isEnabled = |
50 DataReductionProxySettings.getInstance().isDataReductionProxyEna
bled(); | 54 DataReductionProxySettings.getInstance().isDataReductionProxyEna
bled(); |
51 mIsEnabled = !isEnabled; | 55 mIsEnabled = !isEnabled; |
52 mWasEnabledAtCreation = isEnabled; | 56 mWasEnabledAtCreation = isEnabled; |
53 updatePreferences(isEnabled); | 57 updatePreferences(isEnabled); |
54 | 58 |
55 setHasOptionsMenu(true); | 59 setHasOptionsMenu(true); |
| 60 |
| 61 if (getActivity() != null) { |
| 62 mFromPromo = IntentUtils.safeGetBooleanExtra(getActivity().getIntent
(), |
| 63 DataReductionPromoSnackbarController.FROM_PROMO, false); |
| 64 } |
56 } | 65 } |
57 | 66 |
58 @Override | 67 @Override |
59 public void onDestroy() { | 68 public void onDestroy() { |
60 super.onDestroy(); | 69 super.onDestroy(); |
61 | 70 |
62 int statusChange; | 71 int statusChange; |
63 if (mWasEnabledAtCreation) { | 72 if (mFromPromo) { |
| 73 statusChange = mIsEnabled |
| 74 ? DataReductionProxyUma.ACTION_SNACKBAR_LINK_CLICKED |
| 75 : DataReductionProxyUma.ACTION_SNACKBAR_LINK_CLICKED_DISABLE
D; |
| 76 } else if (mWasEnabledAtCreation) { |
64 statusChange = mIsEnabled | 77 statusChange = mIsEnabled |
65 ? DataReductionProxyUma.ACTION_ON_TO_ON | 78 ? DataReductionProxyUma.ACTION_ON_TO_ON |
66 : DataReductionProxyUma.ACTION_ON_TO_OFF; | 79 : DataReductionProxyUma.ACTION_ON_TO_OFF; |
67 } else { | 80 } else { |
68 statusChange = mIsEnabled | 81 statusChange = mIsEnabled |
69 ? DataReductionProxyUma.ACTION_OFF_TO_ON | 82 ? DataReductionProxyUma.ACTION_OFF_TO_ON |
70 : DataReductionProxyUma.ACTION_OFF_TO_OFF; | 83 : DataReductionProxyUma.ACTION_OFF_TO_OFF; |
71 } | 84 } |
72 DataReductionProxyUma.dataReductionProxyUIAction(statusChange); | 85 DataReductionProxyUma.dataReductionProxyUIAction(statusChange); |
73 } | 86 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 196 |
184 getPreferenceScreen().addPreference(dataReductionSwitch); | 197 getPreferenceScreen().addPreference(dataReductionSwitch); |
185 | 198 |
186 // Note: setting the switch state before the preference is added to the
screen results in | 199 // Note: setting the switch state before the preference is added to the
screen results in |
187 // some odd behavior where the switch state doesn't always match the int
ernal enabled state | 200 // some odd behavior where the switch state doesn't always match the int
ernal enabled state |
188 // (e.g. the switch will say "On" when data reduction is really turned o
ff), so | 201 // (e.g. the switch will say "On" when data reduction is really turned o
ff), so |
189 // .setChecked() should be called after .addPreference() | 202 // .setChecked() should be called after .addPreference() |
190 dataReductionSwitch.setChecked(isEnabled); | 203 dataReductionSwitch.setChecked(isEnabled); |
191 } | 204 } |
192 } | 205 } |
OLD | NEW |