package com.android.settings;
-import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentUris;
import android.preference.ListPreference;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
+import android.preference.PreferenceActivity;
import android.provider.Telephony;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
-import android.view.MenuInflater;
import android.view.MenuItem;
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstants;
+import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.TelephonyProperties;
-public class ApnEditor extends SettingsPreferenceFragment
+public class ApnEditor extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener,
Preference.OnPreferenceChangeListener {
@Override
- public void onCreate(Bundle icicle) {
+ protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.apn_editor);
mRes = getResources();
- final Intent intent = getActivity().getIntent();
+ final Intent intent = getIntent();
final String action = intent.getAction();
mFirstTime = icicle == null;
// original activity if they requested a result.
if (mUri == null) {
Log.w(TAG, "Failed to insert new telephony provider into "
- + getActivity().getIntent().getData());
+ + getIntent().getData());
finish();
return;
}
// The new entry was created, so assume all will end well and
// set the result to be returned.
- getActivity().setResult(Activity.RESULT_OK, (new Intent()).setAction(mUri.toString()));
+ setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));
} else {
finish();
return;
}
- mCursor = getActivity().getContentResolver().query(mUri, sProjection, null, null, null);
+ mCursor = managedQuery(mUri, sProjection, null, null);
mCursor.moveToFirst();
- mTelephonyManager = (TelephonyManager) getSystemService(Activity.TELEPHONY_SERVICE);
+ mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
fillUi();
}
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- super.onCreateOptionsMenu(menu, inflater);
+ public boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
// If it's a new APN, then cancel will delete the new entry in onPause
if (!mNewApn) {
menu.add(0, MENU_DELETE, 0, R.string.menu_delete)
.setIcon(android.R.drawable.ic_menu_save);
menu.add(0, MENU_CANCEL, 0, R.string.menu_cancel)
.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
+ return true;
}
@Override
}
@Override
- public void onSaveInstanceState(Bundle icicle) {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_BACK: {
+ if (validateAndSave(false)) {
+ finish();
+ }
+ return true;
+ }
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle icicle) {
super.onSaveInstanceState(icicle);
if (validateAndSave(true)) {
icicle.putInt(SAVED_POS, mCursor.getInt(ID_INDEX));
}
@Override
- public Dialog onCreateDialog(int id) {
+ protected Dialog onCreateDialog(int id) {
if (id == ERROR_DIALOG_ID) {
String msg = getErrorMsg();
- return new AlertDialog.Builder(getActivity())
+ return new AlertDialog.Builder(this)
.setTitle(R.string.error_title)
.setPositiveButton(android.R.string.ok, null)
.setMessage(msg)
return super.onCreateDialog(id);
}
+ @Override
+ protected void onPrepareDialog(int id, Dialog dialog) {
+ super.onPrepareDialog(id, dialog);
+
+ if (id == ERROR_DIALOG_ID) {
+ String msg = getErrorMsg();
+
+ if (msg != null) {
+ ((AlertDialog)dialog).setMessage(msg);
+ }
+ }
+ }
+
private void deleteApn() {
getContentResolver().delete(mUri, null, null);
finish();