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

Commit 040df90c authored by Fan Zhang's avatar Fan Zhang
Browse files

Format number to local locale.

Change-Id: Iffa91eb8c40f09e5ac4cce10f355e348e62d8fce
Fixes: 78134172
Test: robotests
parent 1257466d
Loading
Loading
Loading
Loading
+13 −17
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.provider.Telephony;
import android.support.annotation.VisibleForTesting;
import android.support.v14.preference.MultiSelectListPreference;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.EditTextPreference;
@@ -47,7 +48,6 @@ import android.view.MenuItem;
import android.view.View;
import android.view.View.OnKeyListener;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.util.ArrayUtils;
@@ -309,6 +309,16 @@ public class ApnEditor extends SettingsPreferenceFragment
        fillUI(icicle == null);
    }

    @VisibleForTesting
    static String formatInteger(String value) {
        try {
            final int intValue = Integer.parseInt(value);
            return String.format("%d", intValue);
        } catch (NumberFormatException e) {
            return value;
        }
    }

    /**
     * Check if passed in array of APN types indicates all APN types
     * @param apnTypes array of APN types. "*" indicates all types.
@@ -547,8 +557,8 @@ public class ApnEditor extends SettingsPreferenceFragment
        mMmsProxy.setSummary(checkNull(mMmsProxy.getText()));
        mMmsPort.setSummary(checkNull(mMmsPort.getText()));
        mMmsc.setSummary(checkNull(mMmsc.getText()));
        mMcc.setSummary(checkNull(mMcc.getText()));
        mMnc.setSummary(checkNull(mMnc.getText()));
        mMcc.setSummary(formatInteger(checkNull(mMcc.getText())));
        mMnc.setSummary(formatInteger(checkNull(mMnc.getText())));
        mApnType.setSummary(checkNull(mApnType.getText()));

        String authVal = mAuthType.getValue();
@@ -598,20 +608,6 @@ public class ApnEditor extends SettingsPreferenceFragment
        }
    }

    private String bearerDescription(String raw) {
        int mBearerIndex = mBearerMulti.findIndexOfValue(raw);
        if (mBearerIndex == -1) {
            return null;
        } else {
            String[] values = getResources().getStringArray(R.array.bearer_entries);
            try {
                return values[mBearerIndex];
            } catch (ArrayIndexOutOfBoundsException e) {
                return null;
            }
        }
    }

    private String bearerMultiDescription(Set<String> raw) {
        String[] values = getResources().getStringArray(R.array.bearer_entries);
        StringBuilder retVal = new StringBuilder();
+10 −0
Original line number Diff line number Diff line
@@ -437,6 +437,16 @@ public class ApnEditorTest {
        assertThat(str).isNull();
    }

    @Test
    public void formatInteger_shouldParseString() {
        assertThat(ApnEditor.formatInteger("42")).isEqualTo("42");
    }

    @Test
    public void formatInteger_shouldIgnoreNonIntegers() {
        assertThat(ApnEditor.formatInteger("not an int")).isEqualTo("not an int");
    }

    private void initCursor() {
        doReturn(2).when(mCursor).getColumnCount();
        doReturn(Integer.valueOf(2)).when(mCursor).getInt(CURSOR_INTEGER_INDEX);