Data Usage summary creates a dialog to change data warning level am: 25437d7c61
am: 68e8770d17
Change-Id: I0524bddab4a490ed30fdbff5b5a42d7e9d95b686
This commit is contained in:
@@ -17,6 +17,7 @@ package com.android.settings.datausage;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
@@ -44,7 +45,7 @@ import static android.net.TrafficStats.GB_IN_BYTES;
|
||||
import static android.net.TrafficStats.MB_IN_BYTES;
|
||||
|
||||
public class BillingCycleSettings extends DataUsageBase implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
Preference.OnPreferenceChangeListener, DataUsageEditController {
|
||||
|
||||
private static final String TAG = "BillingCycleSettings";
|
||||
private static final boolean LOGD = false;
|
||||
@@ -147,33 +148,52 @@ public class BillingCycleSettings extends DataUsageBase implements
|
||||
updatePrefs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkPolicyEditor getNetworkPolicyEditor() {
|
||||
return services.mPolicyEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkTemplate getNetworkTemplate() {
|
||||
return mNetworkTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDataUsage() {
|
||||
updatePrefs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dialog to edit {@link NetworkPolicy#warningBytes}.
|
||||
*/
|
||||
public static class BytesEditorFragment extends DialogFragment
|
||||
implements DialogInterface.OnClickListener{
|
||||
implements DialogInterface.OnClickListener {
|
||||
private static final String EXTRA_TEMPLATE = "template";
|
||||
private static final String EXTRA_LIMIT = "limit";
|
||||
private View mView;
|
||||
|
||||
public static void show(BillingCycleSettings parent, boolean isLimit) {
|
||||
if (!parent.isAdded()) return;
|
||||
public static void show(DataUsageEditController parent, boolean isLimit) {
|
||||
if (!(parent instanceof Fragment)) {
|
||||
return;
|
||||
}
|
||||
Fragment targetFragment = (Fragment) parent;
|
||||
if (!targetFragment.isAdded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable(EXTRA_TEMPLATE, parent.mNetworkTemplate);
|
||||
args.putParcelable(EXTRA_TEMPLATE, parent.getNetworkTemplate());
|
||||
args.putBoolean(EXTRA_LIMIT, isLimit);
|
||||
|
||||
final BytesEditorFragment dialog = new BytesEditorFragment();
|
||||
dialog.setArguments(args);
|
||||
dialog.setTargetFragment(parent, 0);
|
||||
dialog.show(parent.getFragmentManager(), TAG_WARNING_EDITOR);
|
||||
dialog.setTargetFragment(targetFragment, 0);
|
||||
dialog.show(targetFragment.getFragmentManager(), TAG_WARNING_EDITOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Context context = getActivity();
|
||||
|
||||
|
||||
final LayoutInflater dialogInflater = LayoutInflater.from(context);
|
||||
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
|
||||
mView = dialogInflater.inflate(R.layout.data_usage_bytes_editor, null, false);
|
||||
@@ -188,8 +208,8 @@ public class BillingCycleSettings extends DataUsageBase implements
|
||||
}
|
||||
|
||||
private void setupPicker(EditText bytesPicker, Spinner type) {
|
||||
final BillingCycleSettings target = (BillingCycleSettings) getTargetFragment();
|
||||
final NetworkPolicyEditor editor = target.services.mPolicyEditor;
|
||||
final DataUsageEditController target = (DataUsageEditController) getTargetFragment();
|
||||
final NetworkPolicyEditor editor = target.getNetworkPolicyEditor();
|
||||
|
||||
final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE);
|
||||
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
|
||||
@@ -222,8 +242,8 @@ public class BillingCycleSettings extends DataUsageBase implements
|
||||
if (which != DialogInterface.BUTTON_POSITIVE) {
|
||||
return;
|
||||
}
|
||||
final BillingCycleSettings target = (BillingCycleSettings) getTargetFragment();
|
||||
final NetworkPolicyEditor editor = target.services.mPolicyEditor;
|
||||
final DataUsageEditController target = (DataUsageEditController) getTargetFragment();
|
||||
final NetworkPolicyEditor editor = target.getNetworkPolicyEditor();
|
||||
|
||||
final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE);
|
||||
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
|
||||
@@ -241,7 +261,7 @@ public class BillingCycleSettings extends DataUsageBase implements
|
||||
} else {
|
||||
editor.setPolicyWarningBytes(template, bytes);
|
||||
}
|
||||
target.updatePrefs();
|
||||
target.updateDataUsage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +269,7 @@ public class BillingCycleSettings extends DataUsageBase implements
|
||||
* Dialog to edit {@link NetworkPolicy#cycleDay}.
|
||||
*/
|
||||
public static class CycleEditorFragment extends DialogFragment implements
|
||||
DialogInterface.OnClickListener{
|
||||
DialogInterface.OnClickListener {
|
||||
private static final String EXTRA_TEMPLATE = "template";
|
||||
private NumberPicker mCycleDayPicker;
|
||||
|
||||
@@ -268,8 +288,8 @@ public class BillingCycleSettings extends DataUsageBase implements
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Context context = getActivity();
|
||||
final BillingCycleSettings target = (BillingCycleSettings) getTargetFragment();
|
||||
final NetworkPolicyEditor editor = target.services.mPolicyEditor;
|
||||
final DataUsageEditController target = (DataUsageEditController) getTargetFragment();
|
||||
final NetworkPolicyEditor editor = target.getNetworkPolicyEditor();
|
||||
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
final LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext());
|
||||
@@ -294,8 +314,8 @@ public class BillingCycleSettings extends DataUsageBase implements
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE);
|
||||
final BillingCycleSettings target = (BillingCycleSettings) getTargetFragment();
|
||||
final NetworkPolicyEditor editor = target.services.mPolicyEditor;
|
||||
final DataUsageEditController target = (DataUsageEditController) getTargetFragment();
|
||||
final NetworkPolicyEditor editor = target.getNetworkPolicyEditor();
|
||||
|
||||
// clear focus to finish pending text edits
|
||||
mCycleDayPicker.clearFocus();
|
||||
@@ -303,7 +323,7 @@ public class BillingCycleSettings extends DataUsageBase implements
|
||||
final int cycleDay = mCycleDayPicker.getValue();
|
||||
final String cycleTimezone = new Time().timezone;
|
||||
editor.setPolicyCycleDay(template, cycleDay, cycleTimezone);
|
||||
target.updatePrefs();
|
||||
target.updateDataUsage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +332,7 @@ public class BillingCycleSettings extends DataUsageBase implements
|
||||
* {@link NetworkPolicy#limitBytes}.
|
||||
*/
|
||||
public static class ConfirmLimitFragment extends DialogFragment implements
|
||||
DialogInterface.OnClickListener{
|
||||
DialogInterface.OnClickListener {
|
||||
private static final String EXTRA_MESSAGE = "message";
|
||||
private static final String EXTRA_LIMIT_BYTES = "limitBytes";
|
||||
public static final float FLOAT = 1.2f;
|
||||
|
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the
|
||||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import android.net.NetworkTemplate;
|
||||
import com.android.settingslib.NetworkPolicyEditor;
|
||||
|
||||
/**
|
||||
* Used to create a dialog that modifies the Cellular data warning amount.
|
||||
*/
|
||||
public interface DataUsageEditController {
|
||||
/**
|
||||
* @return NetworkPolicyEditor to update the values of the data warning and usage limits.
|
||||
*/
|
||||
NetworkPolicyEditor getNetworkPolicyEditor();
|
||||
|
||||
/**
|
||||
* @return NetworkTemplate to get the currently set values of the data warning and usage limits.
|
||||
*/
|
||||
NetworkTemplate getNetworkTemplate();
|
||||
|
||||
/**
|
||||
* Callback to update the UI and values changed by the Dialog.
|
||||
*/
|
||||
void updateDataUsage();
|
||||
}
|
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.INetworkStatsSession;
|
||||
import android.net.NetworkPolicy;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.net.TrafficStats;
|
||||
import android.os.Bundle;
|
||||
@@ -48,6 +49,7 @@ import com.android.settings.Utils;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settingslib.NetworkPolicyEditor;
|
||||
import com.android.settingslib.net.DataUsageController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -56,7 +58,7 @@ import java.util.List;
|
||||
import static android.net.ConnectivityManager.TYPE_ETHERNET;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
|
||||
public class DataUsageSummary extends DataUsageBase implements Indexable {
|
||||
public class DataUsageSummary extends DataUsageBase implements Indexable, DataUsageEditController {
|
||||
|
||||
private static final String TAG = "DataUsageSummary";
|
||||
static final boolean LOGD = false;
|
||||
@@ -87,15 +89,13 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
|
||||
hasMobileData = false;
|
||||
}
|
||||
mDefaultTemplate = getDefaultTemplate(getContext(), defaultSubId);
|
||||
if (hasMobileData) {
|
||||
mLimitPreference = findPreference(KEY_LIMIT_SUMMARY);
|
||||
} else {
|
||||
removePreference(KEY_LIMIT_SUMMARY);
|
||||
}
|
||||
mSummaryPreference = (SummaryPreference) findPreference(KEY_STATUS_HEADER);
|
||||
|
||||
if (!hasMobileData || !isAdmin()) {
|
||||
removePreference(KEY_RESTRICT_BACKGROUND);
|
||||
}
|
||||
if (hasMobileData) {
|
||||
mLimitPreference = findPreference(KEY_LIMIT_SUMMARY);
|
||||
List<SubscriptionInfo> subscriptions =
|
||||
services.mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
if (subscriptions == null || subscriptions.size() == 0) {
|
||||
@@ -104,6 +104,10 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
|
||||
for (int i = 0; subscriptions != null && i < subscriptions.size(); i++) {
|
||||
addMobileSection(subscriptions.get(i).getSubscriptionId());
|
||||
}
|
||||
mSummaryPreference.setSelectable(true);
|
||||
} else {
|
||||
removePreference(KEY_LIMIT_SUMMARY);
|
||||
mSummaryPreference.setSelectable(false);
|
||||
}
|
||||
boolean hasWifiRadio = hasWifiRadio(getContext());
|
||||
if (hasWifiRadio) {
|
||||
@@ -116,7 +120,6 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
|
||||
: hasWifiRadio ? R.string.wifi_data_template
|
||||
: R.string.ethernet_data_template;
|
||||
|
||||
mSummaryPreference = (SummaryPreference) findPreference(KEY_STATUS_HEADER);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@@ -142,6 +145,15 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
if (preference == findPreference(KEY_STATUS_HEADER)) {
|
||||
BillingCycleSettings.BytesEditorFragment.show(this, false);
|
||||
return false;
|
||||
}
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
private void addMobileSection(int subId) {
|
||||
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
|
||||
inflatePreferences(R.xml.data_usage_cellular);
|
||||
@@ -224,6 +236,8 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
|
||||
DataUsageController.DataUsageInfo info = mDataUsageController.getDataUsageInfo(
|
||||
mDefaultTemplate);
|
||||
Context context = getContext();
|
||||
NetworkPolicy policy = services.mPolicyEditor.getPolicy(mDefaultTemplate);
|
||||
info.warningLevel = policy.warningBytes;
|
||||
if (mSummaryPreference != null) {
|
||||
mSummaryPreference.setTitle(
|
||||
formatTitle(context, getString(mDataUsageTemplate), info.usageLevel));
|
||||
@@ -258,6 +272,21 @@ public class DataUsageSummary extends DataUsageBase implements Indexable {
|
||||
return MetricsEvent.DATA_USAGE_SUMMARY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkPolicyEditor getNetworkPolicyEditor() {
|
||||
return services.mPolicyEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkTemplate getNetworkTemplate() {
|
||||
return mDefaultTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDataUsage() {
|
||||
updateState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if device has an ethernet network connection.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user