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 ; | |
26 import org.chromium.third_party.android.datausagechart.NetworkStats; | 27 import org.chromium.third_party.android.datausagechart.NetworkStats; |
27 import org.chromium.third_party.android.datausagechart.NetworkStatsHistory; | 28 import org.chromium.third_party.android.datausagechart.NetworkStatsHistory; |
28 | 29 |
29 /** | 30 /** |
30 * Settings fragment that allows the user to configure Data Saver. | 31 * Settings fragment that allows the user to configure Data Saver. |
31 */ | 32 */ |
32 public class DataReductionPreferences extends PreferenceFragment { | 33 public class DataReductionPreferences extends PreferenceFragment { |
33 | 34 |
34 public static final String PREF_DATA_REDUCTION_SWITCH = "data_reduction_swit ch"; | 35 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"; | 36 private static final String PREF_DATA_REDUCTION_STATS = "data_reduction_stat s"; |
36 | 37 |
37 // This is the same as Chromium data_reduction_proxy::switches::kEnableDataR eductionProxy. | 38 // 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"; | 39 private static final String ENABLE_DATA_REDUCTION_PROXY = "enable-spdy-proxy -auth"; |
39 | 40 |
40 private boolean mIsEnabled; | 41 private boolean mIsEnabled; |
41 private boolean mWasEnabledAtCreation; | 42 private boolean mWasEnabledAtCreation; |
43 // Whether the current activity is started from the snackbar promo. | |
gone
2016/10/13 01:03:11
Maybe use single line javadoc syntax here so it sh
megjablon
2016/10/24 23:59:00
Done.
| |
44 private boolean mFromPromo; | |
42 | 45 |
43 @Override | 46 @Override |
44 public void onCreate(Bundle savedInstanceState) { | 47 public void onCreate(Bundle savedInstanceState) { |
45 super.onCreate(savedInstanceState); | 48 super.onCreate(savedInstanceState); |
46 | 49 |
47 addPreferencesFromResource(R.xml.data_reduction_preferences); | 50 addPreferencesFromResource(R.xml.data_reduction_preferences); |
48 getActivity().setTitle(R.string.data_reduction_title); | 51 getActivity().setTitle(R.string.data_reduction_title); |
49 boolean isEnabled = | 52 boolean isEnabled = |
50 DataReductionProxySettings.getInstance().isDataReductionProxyEna bled(); | 53 DataReductionProxySettings.getInstance().isDataReductionProxyEna bled(); |
51 mIsEnabled = !isEnabled; | 54 mIsEnabled = !isEnabled; |
52 mWasEnabledAtCreation = isEnabled; | 55 mWasEnabledAtCreation = isEnabled; |
53 updatePreferences(isEnabled); | 56 updatePreferences(isEnabled); |
54 | 57 |
55 setHasOptionsMenu(true); | 58 setHasOptionsMenu(true); |
59 Bundle extras = getActivity().getIntent().getExtras(); | |
gone
2016/10/13 01:03:11
Add another method to IntentUtils to handle this c
megjablon
2016/10/24 23:59:00
Using the existing safeGetBooleanExtra
| |
60 | |
61 if (extras != null) { | |
62 mFromPromo = extras.getBoolean(DataReductionPromoSnackbarController. FROM_PROMO); | |
63 } | |
56 } | 64 } |
57 | 65 |
58 @Override | 66 @Override |
59 public void onDestroy() { | 67 public void onDestroy() { |
60 super.onDestroy(); | 68 super.onDestroy(); |
61 | 69 |
70 if (mFromPromo) { | |
71 if (mIsEnabled) { | |
72 DataReductionProxyUma.dataReductionProxyUIAction( | |
73 DataReductionProxyUma.ACTION_SNACKBAR_LINK_CLICKED); | |
74 return; | |
75 } | |
gone
2016/10/13 01:03:11
Could you integrate this into the conditional belo
megjablon
2016/10/24 23:59:00
Done.
| |
76 DataReductionProxyUma.dataReductionProxyUIAction( | |
77 DataReductionProxyUma.ACTION_SNACKBAR_LINK_CLICKED_DISABLED) ; | |
78 return; | |
79 } | |
80 | |
62 int statusChange; | 81 int statusChange; |
63 if (mWasEnabledAtCreation) { | 82 if (mWasEnabledAtCreation) { |
64 statusChange = mIsEnabled | 83 statusChange = mIsEnabled |
65 ? DataReductionProxyUma.ACTION_ON_TO_ON | 84 ? DataReductionProxyUma.ACTION_ON_TO_ON |
66 : DataReductionProxyUma.ACTION_ON_TO_OFF; | 85 : DataReductionProxyUma.ACTION_ON_TO_OFF; |
67 } else { | 86 } else { |
68 statusChange = mIsEnabled | 87 statusChange = mIsEnabled |
69 ? DataReductionProxyUma.ACTION_OFF_TO_ON | 88 ? DataReductionProxyUma.ACTION_OFF_TO_ON |
70 : DataReductionProxyUma.ACTION_OFF_TO_OFF; | 89 : DataReductionProxyUma.ACTION_OFF_TO_OFF; |
71 } | 90 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 | 202 |
184 getPreferenceScreen().addPreference(dataReductionSwitch); | 203 getPreferenceScreen().addPreference(dataReductionSwitch); |
185 | 204 |
186 // Note: setting the switch state before the preference is added to the screen results in | 205 // 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 | 206 // 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 | 207 // (e.g. the switch will say "On" when data reduction is really turned o ff), so |
189 // .setChecked() should be called after .addPreference() | 208 // .setChecked() should be called after .addPreference() |
190 dataReductionSwitch.setChecked(isEnabled); | 209 dataReductionSwitch.setChecked(isEnabled); |
191 } | 210 } |
192 } | 211 } |
OLD | NEW |