Fields Summary |
---|
static final String | TAG |
public static final String | EXTRA_POSITION |
public static final String | RESTORE_CARRIERS_URI |
public static final String | PREFERRED_APN_URI |
public static final String | APN_ID |
private static final int | ID_INDEX |
private static final int | NAME_INDEX |
private static final int | APN_INDEX |
private static final int | TYPES_INDEX |
private static final int | MENU_NEW |
private static final int | MENU_RESTORE |
private static final int | EVENT_RESTORE_DEFAULTAPN_START |
private static final int | EVENT_RESTORE_DEFAULTAPN_COMPLETE |
private static final int | DIALOG_RESTORE_DEFAULTAPN |
private static final android.net.Uri | DEFAULTAPN_URI |
private static final android.net.Uri | PREFERAPN_URI |
private static boolean | mRestoreDefaultApnMode |
private RestoreApnUiHandler | mRestoreApnUiHandler |
private RestoreApnProcessHandler | mRestoreApnProcessHandler |
private String | mSelectedKey |
private android.content.IntentFilter | mMobileStateFilter |
private final android.content.BroadcastReceiver | mMobileStateReceiver |
Methods Summary |
---|
private void | addNewApn()
startActivity(new Intent(Intent.ACTION_INSERT, Telephony.Carriers.CONTENT_URI));
|
private void | fillList()
String where = "numeric=\""
+ android.os.SystemProperties.get(TelephonyProperties.PROPERTY_SIM_OPERATOR_NUMERIC, "")
+ "\"";
Cursor cursor = managedQuery(Telephony.Carriers.CONTENT_URI, new String[] {
"_id", "name", "apn", "type"}, where,
Telephony.Carriers.DEFAULT_SORT_ORDER);
PreferenceGroup apnList = (PreferenceGroup) findPreference("apn_list");
apnList.removeAll();
ArrayList<Preference> mmsApnList = new ArrayList<Preference>();
mSelectedKey = getSelectedApnKey();
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
String name = cursor.getString(NAME_INDEX);
String apn = cursor.getString(APN_INDEX);
String key = cursor.getString(ID_INDEX);
String type = cursor.getString(TYPES_INDEX);
ApnPreference pref = new ApnPreference(this);
pref.setKey(key);
pref.setTitle(name);
pref.setSummary(apn);
pref.setPersistent(false);
pref.setOnPreferenceChangeListener(this);
boolean selectable = ((type == null) || !type.equals("mms"));
pref.setSelectable(selectable);
if (selectable) {
if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
pref.setChecked(true);
}
apnList.addPreference(pref);
} else {
mmsApnList.add(pref);
}
cursor.moveToNext();
}
cursor.close();
for (Preference preference : mmsApnList) {
apnList.addPreference(preference);
}
|
private static Phone.DataState | getMobileDataState(android.content.Intent intent)
String str = intent.getStringExtra(Phone.STATE_KEY);
if (str != null) {
return Enum.valueOf(Phone.DataState.class, str);
} else {
return Phone.DataState.DISCONNECTED;
}
|
private java.lang.String | getSelectedApnKey()
String key = null;
Cursor cursor = managedQuery(PREFERAPN_URI, new String[] {"_id"},
null, Telephony.Carriers.DEFAULT_SORT_ORDER);
if (cursor.getCount() > 0) {
cursor.moveToFirst();
key = cursor.getString(ID_INDEX);
}
cursor.close();
return key;
|
protected void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
addPreferencesFromResource(R.xml.apn_settings);
getListView().setItemsCanFocus(true);
mMobileStateFilter = new IntentFilter(
TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
|
protected android.app.Dialog | onCreateDialog(int id)
if (id == DIALOG_RESTORE_DEFAULTAPN) {
ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage(getResources().getString(R.string.restore_default_apn));
dialog.setCancelable(false);
return dialog;
}
return null;
|
public boolean | onCreateOptionsMenu(android.view.Menu menu)
super.onCreateOptionsMenu(menu);
menu.add(0, MENU_NEW, 0,
getResources().getString(R.string.menu_new))
.setIcon(android.R.drawable.ic_menu_add);
menu.add(0, MENU_RESTORE, 0,
getResources().getString(R.string.menu_restore))
.setIcon(android.R.drawable.ic_menu_upload);
return true;
|
public boolean | onOptionsItemSelected(android.view.MenuItem item)
switch (item.getItemId()) {
case MENU_NEW:
addNewApn();
return true;
case MENU_RESTORE:
restoreDefaultApn();
return true;
}
return super.onOptionsItemSelected(item);
|
protected void | onPause()
super.onPause();
unregisterReceiver(mMobileStateReceiver);
|
public boolean | onPreferenceChange(android.preference.Preference preference, java.lang.Object newValue)
Log.d(TAG, "onPreferenceChange(): Preference - " + preference
+ ", newValue - " + newValue + ", newValue type - "
+ newValue.getClass());
if (newValue instanceof String) {
setSelectedApnKey((String) newValue);
}
return true;
|
public boolean | onPreferenceTreeClick(android.preference.PreferenceScreen preferenceScreen, android.preference.Preference preference)
int pos = Integer.parseInt(preference.getKey());
Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);
startActivity(new Intent(Intent.ACTION_EDIT, url));
return true;
|
protected void | onPrepareDialog(int id, android.app.Dialog dialog)
if (id == DIALOG_RESTORE_DEFAULTAPN) {
getPreferenceScreen().setEnabled(false);
}
|
protected void | onResume()
super.onResume();
registerReceiver(mMobileStateReceiver, mMobileStateFilter);
if (!mRestoreDefaultApnMode) {
fillList();
} else {
showDialog(DIALOG_RESTORE_DEFAULTAPN);
}
|
private boolean | restoreDefaultApn()
showDialog(DIALOG_RESTORE_DEFAULTAPN);
mRestoreDefaultApnMode = true;
if (mRestoreApnUiHandler == null) {
mRestoreApnUiHandler = new RestoreApnUiHandler();
}
if (mRestoreApnProcessHandler == null) {
HandlerThread restoreDefaultApnThread = new HandlerThread(
"Restore default APN Handler: Process Thread");
restoreDefaultApnThread.start();
mRestoreApnProcessHandler = new RestoreApnProcessHandler(
restoreDefaultApnThread.getLooper(), mRestoreApnUiHandler);
}
mRestoreApnProcessHandler
.sendEmptyMessage(EVENT_RESTORE_DEFAULTAPN_START);
return true;
|
private void | setSelectedApnKey(java.lang.String key)
mSelectedKey = key;
ContentResolver resolver = getContentResolver();
ContentValues values = new ContentValues();
values.put(APN_ID, mSelectedKey);
resolver.update(PREFERAPN_URI, values, null, null);
|