Convert data usage warning/limit to a edit text + dropdown
Now choose between MB and GB, then type in the number for the limit. Bug: 27238018 Change-Id: I049be2be3ded52a9ed87e57348ed87b82dbb819c
This commit is contained in:
@@ -17,25 +17,27 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:layout_width="wrap_content"
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<NumberPicker
|
<EditText
|
||||||
android:id="@+id/bytes"
|
android:id="@+id/bytes"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:minWidth="48dip"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:minWidth="48dip"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginStart="16dip"
|
|
||||||
android:layout_marginEnd="16dip"
|
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:focusableInTouchMode="true" />
|
android:focusableInTouchMode="true"
|
||||||
|
android:inputType="numberDecimal" />
|
||||||
|
|
||||||
<TextView
|
<Spinner
|
||||||
|
android:id="@+id/size_spinner"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:entries="@array/bytes_picker_sizes" />
|
||||||
android:text="@*android:string/megabyteShort" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@@ -7178,4 +7178,9 @@
|
|||||||
<!-- [CHAR_LIMIT=NONE] Label for when app is ignoring battery optimizations -->
|
<!-- [CHAR_LIMIT=NONE] Label for when app is ignoring battery optimizations -->
|
||||||
<string name="not_battery_optimizing">Not using battery optimization</string>
|
<string name="not_battery_optimizing">Not using battery optimization</string>
|
||||||
|
|
||||||
|
<string-array name="bytes_picker_sizes" translatable="false">
|
||||||
|
<item>@*android:string/megabyteShort</item>
|
||||||
|
<item>@*android:string/gigabyteShort</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -30,7 +30,9 @@ import android.text.format.Time;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.NumberPicker;
|
import android.widget.NumberPicker;
|
||||||
|
import android.widget.Spinner;
|
||||||
import com.android.settings.InstrumentedFragment;
|
import com.android.settings.InstrumentedFragment;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.NetworkPolicyEditor;
|
import com.android.settingslib.NetworkPolicyEditor;
|
||||||
@@ -172,7 +174,8 @@ public class BillingCycleSettings extends DataUsageBase implements
|
|||||||
|
|
||||||
final LayoutInflater dialogInflater = LayoutInflater.from(context);
|
final LayoutInflater dialogInflater = LayoutInflater.from(context);
|
||||||
mView = dialogInflater.inflate(R.layout.data_usage_bytes_editor, null, false);
|
mView = dialogInflater.inflate(R.layout.data_usage_bytes_editor, null, false);
|
||||||
setupPicker((NumberPicker) mView.findViewById(R.id.bytes));
|
setupPicker((EditText) mView.findViewById(R.id.bytes),
|
||||||
|
(Spinner) mView.findViewById(R.id.size_spinner));
|
||||||
return new AlertDialog.Builder(context)
|
return new AlertDialog.Builder(context)
|
||||||
.setTitle(R.string.data_usage_warning_editor_title)
|
.setTitle(R.string.data_usage_warning_editor_title)
|
||||||
.setView(mView)
|
.setView(mView)
|
||||||
@@ -180,32 +183,28 @@ public class BillingCycleSettings extends DataUsageBase implements
|
|||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupPicker(NumberPicker bytesPicker) {
|
private void setupPicker(EditText bytesPicker, Spinner type) {
|
||||||
final BillingCycleSettings target = (BillingCycleSettings) getTargetFragment();
|
final BillingCycleSettings target = (BillingCycleSettings) getTargetFragment();
|
||||||
final NetworkPolicyEditor editor = target.services.mPolicyEditor;
|
final NetworkPolicyEditor editor = target.services.mPolicyEditor;
|
||||||
|
|
||||||
final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE);
|
final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE);
|
||||||
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
|
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
|
||||||
final long warningBytes = editor.getPolicyWarningBytes(template);
|
final long bytes = isLimit ? editor.getPolicyLimitBytes(template)
|
||||||
final long limitBytes = editor.getPolicyLimitBytes(template);
|
: editor.getPolicyWarningBytes(template);
|
||||||
|
final long limitDisabled = isLimit ? LIMIT_DISABLED : WARNING_DISABLED;
|
||||||
|
|
||||||
if (isLimit) {
|
if (bytes > 1.5f * GB_IN_BYTES) {
|
||||||
bytesPicker.setMaxValue(Integer.MAX_VALUE);
|
bytesPicker.setText(formatText(bytes / (float) GB_IN_BYTES));
|
||||||
if (warningBytes != WARNING_DISABLED) {
|
type.setSelection(1);
|
||||||
bytesPicker.setMinValue((int) (warningBytes / MB_IN_BYTES) + 1);
|
|
||||||
} else {
|
|
||||||
bytesPicker.setMinValue(0);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
bytesPicker.setMinValue(0);
|
bytesPicker.setText(formatText(bytes / (float) MB_IN_BYTES));
|
||||||
if (limitBytes != LIMIT_DISABLED) {
|
type.setSelection(0);
|
||||||
bytesPicker.setMaxValue((int) (limitBytes / MB_IN_BYTES) - 1);
|
|
||||||
} else {
|
|
||||||
bytesPicker.setMaxValue(Integer.MAX_VALUE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bytesPicker.setValue((int) ((isLimit ? limitBytes : warningBytes) / MB_IN_BYTES));
|
}
|
||||||
bytesPicker.setWrapSelectorWheel(false);
|
|
||||||
|
private String formatText(float v) {
|
||||||
|
v = Math.round(v * 100) / 100f;
|
||||||
|
return String.valueOf(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -218,11 +217,15 @@ public class BillingCycleSettings extends DataUsageBase implements
|
|||||||
|
|
||||||
final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE);
|
final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE);
|
||||||
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
|
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
|
||||||
NumberPicker bytesPicker = (NumberPicker) mView.findViewById(R.id.bytes);
|
EditText bytesField = (EditText) mView.findViewById(R.id.bytes);
|
||||||
// clear focus to finish pending text edits
|
Spinner spinner = (Spinner) mView.findViewById(R.id.size_spinner);
|
||||||
bytesPicker.clearFocus();
|
|
||||||
|
|
||||||
final long bytes = bytesPicker.getValue() * MB_IN_BYTES;
|
String bytesString = bytesField.getText().toString();
|
||||||
|
if (bytesString.isEmpty()) {
|
||||||
|
bytesString = "0";
|
||||||
|
}
|
||||||
|
final long bytes = (long) (Float.valueOf(bytesString)
|
||||||
|
* (spinner.getSelectedItemPosition() == 0 ? MB_IN_BYTES : GB_IN_BYTES));
|
||||||
if (isLimit) {
|
if (isLimit) {
|
||||||
editor.setPolicyLimitBytes(template, bytes);
|
editor.setPolicyLimitBytes(template, bytes);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user