Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e4897d93 authored by Jason Monk's avatar Jason Monk
Browse files

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
parent 18d98653
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -17,25 +17,27 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:gravity="center"
    android:layout_width="wrap_content"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <NumberPicker
    <EditText
        android:id="@+id/bytes"
        android:layout_width="wrap_content"
        android:minWidth="48dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:minWidth="48dip"
        android:layout_gravity="center_vertical"
        android:layout_marginStart="16dip"
        android:layout_marginEnd="16dip"
        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_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@*android:string/megabyteShort" />
        android:entries="@array/bytes_picker_sizes" />

</LinearLayout>
+5 −0
Original line number Diff line number Diff line
@@ -7178,4 +7178,9 @@
    <!-- [CHAR_LIMIT=NONE] Label for when app is ignoring battery optimizations -->
    <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>
+26 −23
Original line number Diff line number Diff line
@@ -30,7 +30,9 @@ import android.text.format.Time;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.Spinner;
import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
import com.android.settingslib.NetworkPolicyEditor;
@@ -172,7 +174,8 @@ public class BillingCycleSettings extends DataUsageBase implements

            final LayoutInflater dialogInflater = LayoutInflater.from(context);
            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)
                    .setTitle(R.string.data_usage_warning_editor_title)
                    .setView(mView)
@@ -180,32 +183,28 @@ public class BillingCycleSettings extends DataUsageBase implements
                    .create();
        }

        private void setupPicker(NumberPicker bytesPicker) {
        private void setupPicker(EditText bytesPicker, Spinner type) {
            final BillingCycleSettings target = (BillingCycleSettings) getTargetFragment();
            final NetworkPolicyEditor editor = target.services.mPolicyEditor;

            final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE);
            final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
            final long warningBytes = editor.getPolicyWarningBytes(template);
            final long limitBytes = editor.getPolicyLimitBytes(template);
            final long bytes = isLimit ? editor.getPolicyLimitBytes(template)
                    : editor.getPolicyWarningBytes(template);
            final long limitDisabled = isLimit ? LIMIT_DISABLED : WARNING_DISABLED;

            if (isLimit) {
                bytesPicker.setMaxValue(Integer.MAX_VALUE);
                if (warningBytes != WARNING_DISABLED) {
                    bytesPicker.setMinValue((int) (warningBytes / MB_IN_BYTES) + 1);
                } else {
                    bytesPicker.setMinValue(0);
                }
            } else {
                bytesPicker.setMinValue(0);
                if (limitBytes != LIMIT_DISABLED) {
                    bytesPicker.setMaxValue((int) (limitBytes / MB_IN_BYTES) - 1);
            if (bytes > 1.5f * GB_IN_BYTES) {
                bytesPicker.setText(formatText(bytes / (float) GB_IN_BYTES));
                type.setSelection(1);
            } else {
                    bytesPicker.setMaxValue(Integer.MAX_VALUE);
                bytesPicker.setText(formatText(bytes / (float) MB_IN_BYTES));
                type.setSelection(0);
            }
        }
            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
@@ -218,11 +217,15 @@ public class BillingCycleSettings extends DataUsageBase implements

            final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE);
            final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
            NumberPicker bytesPicker = (NumberPicker) mView.findViewById(R.id.bytes);
            // clear focus to finish pending text edits
            bytesPicker.clearFocus();
            EditText bytesField = (EditText) mView.findViewById(R.id.bytes);
            Spinner spinner = (Spinner) mView.findViewById(R.id.size_spinner);

            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) {
                editor.setPolicyLimitBytes(template, bytes);
            } else {