Automated import from //branches/master/...@140758,140758
This commit is contained in:

committed by
The Android Open Source Project
parent
d670277239
commit
6829688706
@@ -18,10 +18,13 @@ package com.android.settings;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@@ -34,20 +37,33 @@ import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.Telephony;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ApnSettings extends PreferenceActivity {
|
||||
import com.android.internal.telephony.Phone;
|
||||
import com.android.internal.telephony.TelephonyIntents;
|
||||
import com.android.internal.telephony.TelephonyProperties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ApnSettings extends PreferenceActivity implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
static final String TAG = "ApnSettings";
|
||||
|
||||
public static final String EXTRA_POSITION = "position";
|
||||
public static final String RESTORE_CARRIERS_URI =
|
||||
"content://telephony/carriers/restore";
|
||||
public static final String PREFERRED_APN_URI =
|
||||
"content://telephony/carriers/preferapn";
|
||||
|
||||
public static final String APN_ID = "apn_id";
|
||||
|
||||
private static final int ID_INDEX = 0;
|
||||
private static final int NAME_INDEX = 1;
|
||||
private static final int APN_INDEX = 2;
|
||||
private static final int TYPES_INDEX = 3;
|
||||
|
||||
private static final int MENU_NEW = Menu.FIRST;
|
||||
private static final int MENU_RESTORE = Menu.FIRST + 1;
|
||||
@@ -58,25 +74,62 @@ public class ApnSettings extends PreferenceActivity {
|
||||
private static final int DIALOG_RESTORE_DEFAULTAPN = 1001;
|
||||
|
||||
private static final Uri DEFAULTAPN_URI = Uri.parse(RESTORE_CARRIERS_URI);
|
||||
private static final Uri PREFERAPN_URI = Uri.parse(PREFERRED_APN_URI);
|
||||
|
||||
private static boolean mRestoreDefaultApnMode;
|
||||
|
||||
private RestoreApnUiHandler mRestoreApnUiHandler;
|
||||
private RestoreApnProcessHandler mRestoreApnProcessHandler;
|
||||
|
||||
private Cursor mCursor;
|
||||
private String mSelectedKey;
|
||||
|
||||
private IntentFilter mMobileStateFilter;
|
||||
|
||||
private final BroadcastReceiver mMobileStateReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(
|
||||
TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
|
||||
Phone.DataState state = getMobileDataState(intent);
|
||||
switch (state) {
|
||||
case CONNECTED:
|
||||
if (!mRestoreDefaultApnMode) {
|
||||
fillList();
|
||||
} else {
|
||||
showDialog(DIALOG_RESTORE_DEFAULTAPN);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static Phone.DataState getMobileDataState(Intent intent) {
|
||||
String str = intent.getStringExtra(Phone.STATE_KEY);
|
||||
if (str != null) {
|
||||
return Enum.valueOf(Phone.DataState.class, str);
|
||||
} else {
|
||||
return Phone.DataState.DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.apn_settings);
|
||||
getListView().setItemsCanFocus(true);
|
||||
|
||||
mMobileStateFilter = new IntentFilter(
|
||||
TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
registerReceiver(mMobileStateReceiver, mMobileStateFilter);
|
||||
|
||||
if (!mRestoreDefaultApnMode) {
|
||||
fillList();
|
||||
} else {
|
||||
@@ -84,29 +137,59 @@ public class ApnSettings extends PreferenceActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
unregisterReceiver(mMobileStateReceiver);
|
||||
}
|
||||
|
||||
private void fillList() {
|
||||
mCursor = managedQuery(Telephony.Carriers.CONTENT_URI, new String[] {
|
||||
"_id", "name", "apn"}, null, Telephony.Carriers.DEFAULT_SORT_ORDER);
|
||||
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();
|
||||
|
||||
mCursor.moveToFirst();
|
||||
while (!mCursor.isAfterLast()) {
|
||||
String name = mCursor.getString(NAME_INDEX);
|
||||
String apn = mCursor.getString(APN_INDEX);
|
||||
ArrayList<Preference> mmsApnList = new ArrayList<Preference>();
|
||||
|
||||
if (name != null && apn != null && TextUtils.getTrimmedLength(name) > 0
|
||||
&& TextUtils.getTrimmedLength(apn) > 0) {
|
||||
Preference pref = new Preference((Context) this);
|
||||
pref.setKey(mCursor.getString(ID_INDEX));
|
||||
pref.setTitle(name);
|
||||
pref.setSummary(apn);
|
||||
pref.setPersistent(false);
|
||||
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();
|
||||
|
||||
mCursor.moveToNext();
|
||||
for (Preference preference : mmsApnList) {
|
||||
apnList.addPreference(preference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +231,39 @@ public class ApnSettings extends PreferenceActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Log.d(TAG, "onPreferenceChange(): Preference - " + preference
|
||||
+ ", newValue - " + newValue + ", newValue type - "
|
||||
+ newValue.getClass());
|
||||
if (newValue instanceof String) {
|
||||
setSelectedApnKey((String) newValue);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setSelectedApnKey(String key) {
|
||||
mSelectedKey = key;
|
||||
ContentResolver resolver = getContentResolver();
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(APN_ID, mSelectedKey);
|
||||
resolver.update(PREFERAPN_URI, values, null, null);
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
private boolean restoreDefaultApn() {
|
||||
showDialog(DIALOG_RESTORE_DEFAULTAPN);
|
||||
mRestoreDefaultApnMode = true;
|
||||
|
Reference in New Issue
Block a user