Merge "Format number to local locale." into pi-dev

This commit is contained in:
Fan Zhang
2018-04-20 00:01:01 +00:00
committed by Android (Google) Code Review
2 changed files with 23 additions and 17 deletions

View File

@@ -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();

View File

@@ -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);