add MVNO field for APN Editor

For MVNO, add related data fields.

Bug: 8143480
Change-Id: Idfa06c6f39a2c15ff4f0815724823f44b76ac819
This commit is contained in:
Sungmin Choi
2013-01-30 13:53:03 +09:00
parent a7d2fd80c2
commit aa4d4c653b
4 changed files with 89 additions and 1 deletions

View File

@@ -57,6 +57,7 @@ public class ApnEditor extends PreferenceActivity
private final static String KEY_ROAMING_PROTOCOL = "apn_roaming_protocol";
private final static String KEY_CARRIER_ENABLED = "carrier_enabled";
private final static String KEY_BEARER = "bearer";
private final static String KEY_MVNO_TYPE = "mvno_type";
private static final int MENU_DELETE = Menu.FIRST;
private static final int MENU_SAVE = Menu.FIRST + 1;
@@ -82,6 +83,8 @@ public class ApnEditor extends PreferenceActivity
private ListPreference mRoamingProtocol;
private CheckBoxPreference mCarrierEnabled;
private ListPreference mBearer;
private ListPreference mMvnoType;
private EditTextPreference mMvnoMatchData;
private String mCurMnc;
private String mCurMcc;
@@ -115,7 +118,9 @@ public class ApnEditor extends PreferenceActivity
Telephony.Carriers.PROTOCOL, // 16
Telephony.Carriers.CARRIER_ENABLED, // 17
Telephony.Carriers.BEARER, // 18
Telephony.Carriers.ROAMING_PROTOCOL // 19
Telephony.Carriers.ROAMING_PROTOCOL, // 19
Telephony.Carriers.MVNO_TYPE, // 20
Telephony.Carriers.MVNO_MATCH_DATA // 21
};
private static final int ID_INDEX = 0;
@@ -137,6 +142,8 @@ public class ApnEditor extends PreferenceActivity
private static final int CARRIER_ENABLED_INDEX = 17;
private static final int BEARER_INDEX = 18;
private static final int ROAMING_PROTOCOL_INDEX = 19;
private static final int MVNO_TYPE_INDEX = 20;
private static final int MVNO_MATCH_DATA_INDEX = 21;
@Override
@@ -174,6 +181,10 @@ public class ApnEditor extends PreferenceActivity
mBearer = (ListPreference) findPreference(KEY_BEARER);
mBearer.setOnPreferenceChangeListener(this);
mMvnoType = (ListPreference) findPreference(KEY_MVNO_TYPE);
mMvnoType.setOnPreferenceChangeListener(this);
mMvnoMatchData = (EditTextPreference) findPreference("mvno_match_data");
mRes = getResources();
final Intent intent = getIntent();
@@ -274,6 +285,9 @@ public class ApnEditor extends PreferenceActivity
mRoamingProtocol.setValue(mCursor.getString(ROAMING_PROTOCOL_INDEX));
mCarrierEnabled.setChecked(mCursor.getInt(CARRIER_ENABLED_INDEX)==1);
mBearer.setValue(mCursor.getString(BEARER_INDEX));
mMvnoType.setValue(mCursor.getString(MVNO_TYPE_INDEX));
mMvnoMatchData.setEnabled(false);
mMvnoMatchData.setText(mCursor.getString(MVNO_MATCH_DATA_INDEX));
}
mName.setSummary(checkNull(mName.getText()));
@@ -307,6 +321,9 @@ public class ApnEditor extends PreferenceActivity
checkNull(protocolDescription(mRoamingProtocol.getValue(), mRoamingProtocol)));
mBearer.setSummary(
checkNull(bearerDescription(mBearer.getValue())));
mMvnoType.setSummary(
checkNull(mvnoDescription(mMvnoType.getValue())));
mMvnoMatchData.setSummary(checkNull(mMvnoMatchData.getText()));
}
/**
@@ -342,6 +359,27 @@ public class ApnEditor extends PreferenceActivity
}
}
private String mvnoDescription(String raw) {
int mvnoIndex = mMvnoType.findIndexOfValue(raw);
if (mvnoIndex == -1) {
return null;
} else {
String[] values = mRes.getStringArray(R.array.mvno_type_entries);
if (values[mvnoIndex].equals("None")) {
mMvnoMatchData.setEnabled(false);
mMvnoMatchData.setText("");
} else {
mMvnoMatchData.setEnabled(true);
}
try {
return values[mvnoIndex];
} catch (ArrayIndexOutOfBoundsException e) {
return null;
}
}
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (KEY_AUTH_TYPE.equals(key)) {
@@ -375,6 +413,13 @@ public class ApnEditor extends PreferenceActivity
}
mBearer.setValue((String) newValue);
mBearer.setSummary(bearer);
} else if (KEY_MVNO_TYPE.equals(key)) {
String mvno = mvnoDescription((String) newValue);
if (mvno == null) {
return false;
}
mMvnoType.setValue((String) newValue);
mMvnoType.setSummary(mvno);
}
return true;
@@ -508,6 +553,9 @@ public class ApnEditor extends PreferenceActivity
values.put(Telephony.Carriers.BEARER, Integer.parseInt(bearerVal));
}
values.put(Telephony.Carriers.MVNO_TYPE, checkNotSet(mMvnoType.getValue()));
values.put(Telephony.Carriers.MVNO_MATCH_DATA, checkNotSet(mMvnoMatchData.getText()));
getContentResolver().update(mUri, values, null, null);
return true;