Add ability to disable data warning.

- Add a preference to disable data warning.
- Disable data usage chart in summary page when data warning is turned
  off.

Bug: 26934313
Test: Manually turned on/off data warning and inspected UI.
Test: ag/1440361

Change-Id: I6d5b86b8502647781c52cf940f276e1969251b59
This commit is contained in:
Fan Zhang
2016-09-12 15:00:53 -07:00
parent c88805713d
commit 7bd19b8891
4 changed files with 64 additions and 14 deletions

View File

@@ -21,6 +21,10 @@
android:key="billing_cycle"
android:title="@string/billing_cycle" />
<SwitchPreference
android:key="set_data_warning"
android:title="@string/set_data_warning"/>
<Preference
android:key="data_warning"
android:title="@string/data_warning" />

View File

@@ -34,6 +34,7 @@ public class SummaryPreference extends Preference {
private int mLeft, mMiddle, mRight;
private boolean mColorsSet = false;
private boolean mChartEnabled = true;
private float mLeftRatio, mMiddleRatio, mRightRatio;
private String mStartLabel;
private String mEndLabel;
@@ -43,6 +44,13 @@ public class SummaryPreference extends Preference {
setLayoutResource(R.layout.settings_summary_preference);
}
public void setChartEnabled(boolean enabled) {
if (mChartEnabled != enabled) {
mChartEnabled = enabled;
notifyChanged();
}
}
public void setAmount(String amount) {
mAmount = amount;
if (mAmount != null && mUnits != null) {
@@ -85,12 +93,18 @@ public class SummaryPreference extends Preference {
super.onBindViewHolder(holder);
LinearColorBar colorBar = (LinearColorBar) holder.itemView.findViewById(R.id.color_bar);
colorBar.setRatios(mLeftRatio, mMiddleRatio, mRightRatio);
if (mColorsSet) {
colorBar.setColors(mLeft, mMiddle, mRight);
if (mChartEnabled) {
colorBar.setVisibility(View.VISIBLE);
colorBar.setRatios(mLeftRatio, mMiddleRatio, mRightRatio);
if (mColorsSet) {
colorBar.setColors(mLeft, mMiddle, mRight);
}
} else {
colorBar.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(mStartLabel) || !TextUtils.isEmpty(mEndLabel)) {
if (mChartEnabled && (!TextUtils.isEmpty(mStartLabel) || !TextUtils.isEmpty(mEndLabel))) {
holder.findViewById(R.id.label_bar).setVisibility(View.VISIBLE);
((TextView) holder.findViewById(android.R.id.text1)).setText(mStartLabel);
((TextView) holder.findViewById(android.R.id.text2)).setText(mEndLabel);

View File

@@ -34,6 +34,7 @@ import android.view.View;
import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.Spinner;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settingslib.NetworkPolicyEditor;
@@ -55,6 +56,7 @@ public class BillingCycleSettings extends DataUsageBase implements
private static final String TAG_WARNING_EDITOR = "warningEditor";
private static final String KEY_BILLING_CYCLE = "billing_cycle";
private static final String KEY_SET_DATA_WARNING = "set_data_warning";
private static final String KEY_DATA_WARNING = "data_warning";
private static final String KEY_SET_DATA_LIMIT = "set_data_limit";
private static final String KEY_DATA_LIMIT = "data_limit";
@@ -62,6 +64,7 @@ public class BillingCycleSettings extends DataUsageBase implements
private NetworkTemplate mNetworkTemplate;
private Preference mBillingCycle;
private Preference mDataWarning;
private SwitchPreference mEnableDataWarning;
private SwitchPreference mEnableDataLimit;
private Preference mDataLimit;
private DataUsageController mDataUsageController;
@@ -77,6 +80,8 @@ public class BillingCycleSettings extends DataUsageBase implements
addPreferencesFromResource(R.xml.billing_cycle);
mBillingCycle = findPreference(KEY_BILLING_CYCLE);
mEnableDataWarning = (SwitchPreference) findPreference(KEY_SET_DATA_WARNING);
mEnableDataWarning.setOnPreferenceChangeListener(this);
mDataWarning = findPreference(KEY_DATA_WARNING);
mEnableDataLimit = (SwitchPreference) findPreference(KEY_SET_DATA_LIMIT);
mEnableDataLimit.setOnPreferenceChangeListener(this);
@@ -93,10 +98,15 @@ public class BillingCycleSettings extends DataUsageBase implements
NetworkPolicy policy = services.mPolicyEditor.getPolicy(mNetworkTemplate);
mBillingCycle.setSummary(getString(R.string.billing_cycle_summary, policy != null ?
policy.cycleDay : 1));
mDataWarning.setSummary(Formatter.formatFileSize(getContext(),
policy != null
? policy.warningBytes
: mDataUsageController.getDefaultWarningLevel()));
if (policy != null && policy.warningBytes != WARNING_DISABLED) {
mDataWarning.setSummary(Formatter.formatFileSize(getContext(), policy.warningBytes));
mDataWarning.setEnabled(true);
mEnableDataWarning.setChecked(true);
} else {
mDataWarning.setSummary(null);
mDataWarning.setEnabled(false);
mEnableDataWarning.setChecked(false);
}
if (policy != null && policy.limitBytes != LIMIT_DISABLED) {
mDataLimit.setSummary(Formatter.formatFileSize(getContext(), policy.limitBytes));
mDataLimit.setEnabled(true);
@@ -133,6 +143,14 @@ public class BillingCycleSettings extends DataUsageBase implements
setPolicyLimitBytes(LIMIT_DISABLED);
}
return true;
} else if (mEnableDataWarning == preference) {
boolean enabled = (Boolean) newValue;
if (enabled) {
setPolicyWarningBytes(mDataUsageController.getDefaultWarningLevel());
} else {
setPolicyWarningBytes(WARNING_DISABLED);
}
return true;
}
return false;
}
@@ -148,6 +166,12 @@ public class BillingCycleSettings extends DataUsageBase implements
updatePrefs();
}
private void setPolicyWarningBytes(long warningBytes) {
if (LOGD) Log.d(TAG, "setPolicyWarningBytes()");
services.mPolicyEditor.setPolicyWarningBytes(mNetworkTemplate, warningBytes);
updatePrefs();
}
@Override
public NetworkPolicyEditor getNetworkPolicyEditor() {
return services.mPolicyEditor;
@@ -255,7 +279,7 @@ public class BillingCycleSettings extends DataUsageBase implements
bytesString = "0";
}
final long bytes = (long) (Float.valueOf(bytesString)
* (spinner.getSelectedItemPosition() == 0 ? MB_IN_BYTES : GB_IN_BYTES));
* (spinner.getSelectedItemPosition() == 0 ? MB_IN_BYTES : GB_IN_BYTES));
if (isLimit) {
editor.setPolicyLimitBytes(template, bytes);
} else {

View File

@@ -246,16 +246,24 @@ public class DataUsageSummary extends DataUsageBase implements Indexable, DataUs
formatTitle(context, getString(mDataUsageTemplate), info.usageLevel));
long limit = mDataInfoController.getSummaryLimit(info);
mSummaryPreference.setSummary(info.period);
mSummaryPreference.setLabels(Formatter.formatFileSize(context, 0),
Formatter.formatFileSize(context, limit));
mSummaryPreference.setRatios(info.usageLevel / (float) limit, 0,
(limit - info.usageLevel) / (float) limit);
if (limit <= 0) {
mSummaryPreference.setChartEnabled(false);
} else {
mSummaryPreference.setChartEnabled(true);
mSummaryPreference.setLabels(Formatter.formatFileSize(context, 0),
Formatter.formatFileSize(context, limit));
mSummaryPreference.setRatios(info.usageLevel / (float) limit, 0,
(limit - info.usageLevel) / (float) limit);
}
}
if (mLimitPreference != null) {
if (mLimitPreference != null && (info.warningLevel > 0 || info.limitLevel > 0)) {
String warning = Formatter.formatFileSize(context, info.warningLevel);
String limit = Formatter.formatFileSize(context, info.limitLevel);
mLimitPreference.setSummary(getString(info.limitLevel <= 0 ? R.string.cell_warning_only
: R.string.cell_warning_and_limit, warning, limit));
} else if (mLimitPreference != null) {
mLimitPreference.setSummary(null);
}
PreferenceScreen screen = getPreferenceScreen();