diff options
-rw-r--r-- | AndroidManifest.xml | 14 | ||||
-rw-r--r-- | src/com/android/settings/ApnEditor.java | 78 | ||||
-rw-r--r-- | src/com/android/settings/ApnPreference.java | 29 | ||||
-rw-r--r-- | src/com/android/settings/ApnSettings.java | 67 | ||||
-rw-r--r-- | src/com/android/settings/Settings.java | 2 |
5 files changed, 83 insertions, 107 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f55d7d3..adbd457 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -252,15 +252,17 @@ </intent-filter> </activity-alias> - <activity android:name="ApnSettings" android:label="@string/apn_settings" + <activity android:name="Settings$ApnSettingsActivity" android:label="@string/apn_settings" android:configChanges="orientation|keyboardHidden|screenSize" - android:launchMode="singleTask"> + android:launchMode="singleTask" android:clearTaskOnLaunch="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <action android:name="android.settings.APN_SETTINGS" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.VOICE_LAUNCH" /> </intent-filter> + <meta-data android:name="com.android.settings.FRAGMENT_CLASS" + android:value="com.android.settings.ApnSettings" /> </activity> <activity android:name="Settings$BluetoothSettingsActivity" @@ -1008,9 +1010,9 @@ <activity android:name=".deviceinfo.MiscFilesHandler" android:theme="@android:style/Theme.Holo.DialogWhenLarge"/> - <activity android:name="ApnEditor" + <activity android:name="Settings$ApnEditorActivity" android:label="@string/apn_edit" - android:theme="@android:style/Theme.Holo.DialogWhenLarge"> + android:clearTaskOnLaunch="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.EDIT" /> @@ -1023,6 +1025,8 @@ <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="vnd.android.cursor.dir/telephony-carrier" /> </intent-filter> + <meta-data android:name="com.android.settings.FRAGMENT_CLASS" + android:value="com.android.settings.ApnEditor" /> </activity> <activity android:name="MediaFormat" android:label="@string/media_format_title"> @@ -1488,6 +1492,8 @@ <activity android:name=".notificationlight.BatteryLightSettings" /> + <activity android:name=".ApnEditor" /> + <activity android:name="Settings$AnonymousStatsActivity" android:label="@string/anonymous_statistics_title" android:configChanges="orientation|keyboardHidden|screenSize" diff --git a/src/com/android/settings/ApnEditor.java b/src/com/android/settings/ApnEditor.java index 79b6d15..30ba54e 100644 --- a/src/com/android/settings/ApnEditor.java +++ b/src/com/android/settings/ApnEditor.java @@ -16,10 +16,12 @@ package com.android.settings; +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.ContentUris; import android.content.ContentValues; +import android.content.CursorLoader; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; @@ -27,16 +29,15 @@ import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.os.SystemProperties; +import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; 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; @@ -45,7 +46,7 @@ import com.android.internal.telephony.RILConstants; import com.android.internal.telephony.TelephonyProperties; -public class ApnEditor extends PreferenceActivity +public class ApnEditor extends SettingsPreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener, Preference.OnPreferenceChangeListener { @@ -57,6 +58,8 @@ 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"; + protected static final String EDIT_ACTION = "edit_action"; + protected static final String EDIT_DATA = "edit_data"; private static final int MENU_DELETE = Menu.FIRST; private static final int MENU_SAVE = Menu.FIRST + 1; @@ -140,7 +143,7 @@ public class ApnEditor extends PreferenceActivity @Override - protected void onCreate(Bundle icicle) { + public void onCreate(Bundle icicle) { super.onCreate(icicle); addPreferencesFromResource(R.xml.apn_editor); @@ -176,16 +179,22 @@ public class ApnEditor extends PreferenceActivity mRes = getResources(); - final Intent intent = getIntent(); - final String action = intent.getAction(); + final Intent intent = getActivity().getIntent(); + String action = intent.getAction(); + Bundle fragArgs = getArguments(); + + if (fragArgs != null && fragArgs.containsKey(EDIT_ACTION)) { + mUri = Uri.parse(fragArgs.getString(EDIT_DATA)); + action = fragArgs.getString(EDIT_ACTION); + } else { + mUri = intent.getData(); + } mFirstTime = icicle == null; - if (action.equals(Intent.ACTION_EDIT)) { - mUri = intent.getData(); - } else if (action.equals(Intent.ACTION_INSERT)) { + if (action.equals(Intent.ACTION_INSERT)) { if (mFirstTime || icicle.getInt(SAVED_POS) == 0) { - mUri = getContentResolver().insert(intent.getData(), new ContentValues()); + mUri = getContentResolver().insert(mUri, new ContentValues()); } else { mUri = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, icicle.getInt(SAVED_POS)); @@ -196,24 +205,26 @@ public class ApnEditor extends PreferenceActivity // original activity if they requested a result. if (mUri == null) { Log.w(TAG, "Failed to insert new telephony provider into " - + getIntent().getData()); + + getActivity().getIntent().getData()); finish(); return; } // The new entry was created, so assume all will end well and // set the result to be returned. - setResult(RESULT_OK, (new Intent()).setAction(mUri.toString())); + getActivity().setResult(Activity.RESULT_OK, (new Intent()).setAction(mUri.toString())); - } else { + } else if (!action.equals(Intent.ACTION_EDIT)) { finish(); return; } - mCursor = managedQuery(mUri, sProjection, null, null); + CursorLoader qCursor = new CursorLoader(getActivity(), mUri, sProjection, null, null, null); + mCursor = qCursor.loadInBackground(); mCursor.moveToFirst(); fillUi(); + setHasOptionsMenu(true); } @Override @@ -381,8 +392,8 @@ public class ApnEditor extends PreferenceActivity } @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); // 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) @@ -392,7 +403,6 @@ public class ApnEditor extends PreferenceActivity .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 @@ -417,20 +427,7 @@ public class ApnEditor extends PreferenceActivity } @Override - 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) { + public void onSaveInstanceState(Bundle icicle) { super.onSaveInstanceState(icicle); if (validateAndSave(true)) { icicle.putInt(SAVED_POS, mCursor.getInt(ID_INDEX)); @@ -535,12 +532,12 @@ public class ApnEditor extends PreferenceActivity } @Override - protected Dialog onCreateDialog(int id) { + public Dialog onCreateDialog(int id) { if (id == ERROR_DIALOG_ID) { String msg = getErrorMsg(); - return new AlertDialog.Builder(this) + return new AlertDialog.Builder(getActivity()) .setTitle(R.string.error_title) .setPositiveButton(android.R.string.ok, null) .setMessage(msg) @@ -550,19 +547,6 @@ public class ApnEditor extends PreferenceActivity 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(); diff --git a/src/com/android/settings/ApnPreference.java b/src/com/android/settings/ApnPreference.java index 710eda2..ff24d29 100644 --- a/src/com/android/settings/ApnPreference.java +++ b/src/com/android/settings/ApnPreference.java @@ -16,23 +16,17 @@ package com.android.settings; -import android.content.ContentUris; import android.content.Context; -import android.content.Intent; -import android.net.Uri; import android.preference.Preference; -import android.provider.Telephony; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.view.ViewGroup; -import android.view.View.OnClickListener; import android.widget.CompoundButton; import android.widget.RadioButton; -import android.widget.RelativeLayout; public class ApnPreference extends Preference implements - CompoundButton.OnCheckedChangeListener, OnClickListener { + CompoundButton.OnCheckedChangeListener { final static String TAG = "ApnPreference"; /** @@ -71,9 +65,10 @@ public class ApnPreference extends Preference implements public View getView(View convertView, ViewGroup parent) { View view = super.getView(convertView, parent); - View widget = view.findViewById(R.id.apn_radiobutton); + View widget = view.findViewById(android.R.id.checkbox); if ((widget != null) && widget instanceof RadioButton) { RadioButton rb = (RadioButton) widget; + rb.setClickable(true); if (mSelectable) { rb.setOnCheckedChangeListener(this); @@ -91,16 +86,11 @@ public class ApnPreference extends Preference implements } } - View textLayout = view.findViewById(R.id.text_layout); - if ((textLayout != null) && textLayout instanceof RelativeLayout) { - textLayout.setOnClickListener(this); - } - return view; } private void init() { - setLayoutResource(R.layout.apn_preference_layout); + setWidgetLayoutResource(R.layout.preference_profiles_widget); } public boolean isChecked() { @@ -130,17 +120,6 @@ public class ApnPreference extends Preference implements } } - public void onClick(android.view.View v) { - if ((v != null) && (R.id.text_layout == v.getId())) { - Context context = getContext(); - if (context != null) { - int pos = Integer.parseInt(getKey()); - Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos); - context.startActivity(new Intent(Intent.ACTION_EDIT, url)); - } - } - } - public void setSelectable(boolean selectable) { mSelectable = selectable; } diff --git a/src/com/android/settings/ApnSettings.java b/src/com/android/settings/ApnSettings.java index 56ee7a9..95a6f1e 100644 --- a/src/com/android/settings/ApnSettings.java +++ b/src/com/android/settings/ApnSettings.java @@ -16,6 +16,8 @@ package com.android.settings; +import java.util.ArrayList; + import android.app.Dialog; import android.app.ProgressDialog; import android.content.BroadcastReceiver; @@ -33,12 +35,12 @@ import android.os.HandlerThread; import android.os.Looper; import android.os.Message; import android.preference.Preference; -import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; import android.provider.Telephony; import android.util.Log; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.widget.Toast; @@ -47,9 +49,7 @@ import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.TelephonyIntents; import com.android.internal.telephony.TelephonyProperties; -import java.util.ArrayList; - -public class ApnSettings extends PreferenceActivity implements +public class ApnSettings extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener { static final String TAG = "ApnSettings"; @@ -116,21 +116,20 @@ public class ApnSettings extends PreferenceActivity implements } @Override - protected void onCreate(Bundle icicle) { + public 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); + setHasOptionsMenu(true); } @Override - protected void onResume() { + public void onResume() { super.onResume(); - registerReceiver(mMobileStateReceiver, mMobileStateFilter); + getActivity().registerReceiver(mMobileStateReceiver, mMobileStateFilter); if (!mRestoreDefaultApnMode) { fillList(); @@ -140,14 +139,13 @@ public class ApnSettings extends PreferenceActivity implements } @Override - protected void onPause() { + public void onPause() { super.onPause(); - - unregisterReceiver(mMobileStateReceiver); + getActivity().unregisterReceiver(mMobileStateReceiver); } @Override - protected void onDestroy() { + public void onDestroy() { super.onDestroy(); if (mRestoreDefaultApnThread != null) { @@ -164,7 +162,7 @@ public class ApnSettings extends PreferenceActivity implements "_id", "name", "apn", "type"}, where, null, Telephony.Carriers.DEFAULT_SORT_ORDER); - PreferenceGroup apnList = (PreferenceGroup) findPreference("apn_list"); + PreferenceGroup apnList = (PreferenceGroup) getPreferenceScreen().findPreference("apn_list"); apnList.removeAll(); ArrayList<Preference> mmsApnList = new ArrayList<Preference>(); @@ -177,7 +175,7 @@ public class ApnSettings extends PreferenceActivity implements String key = cursor.getString(ID_INDEX); String type = cursor.getString(TYPES_INDEX); - ApnPreference pref = new ApnPreference(this); + ApnPreference pref = new ApnPreference(getActivity()); pref.setKey(key); pref.setTitle(name); @@ -205,15 +203,14 @@ public class ApnSettings extends PreferenceActivity implements } @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); 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; } @Override @@ -231,14 +228,20 @@ public class ApnSettings extends PreferenceActivity implements } private void addNewApn() { - startActivity(new Intent(Intent.ACTION_INSERT, Telephony.Carriers.CONTENT_URI)); + Bundle editBundle = new Bundle(); + editBundle.putString(ApnEditor.EDIT_ACTION, Intent.ACTION_INSERT); + editBundle.putString(ApnEditor.EDIT_DATA, Telephony.Carriers.CONTENT_URI.toSafeString()); + startFragment(null, ApnEditor.class.getName(), 0, editBundle); } @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { int pos = Integer.parseInt(preference.getKey()); Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos); - startActivity(new Intent(Intent.ACTION_EDIT, url)); + Bundle editBundle = new Bundle(); + editBundle.putString(ApnEditor.EDIT_ACTION, Intent.ACTION_EDIT); + editBundle.putString(ApnEditor.EDIT_DATA, url.toSafeString()); + startFragment(null, ApnEditor.class.getName(), 0, editBundle); return true; } @@ -275,6 +278,12 @@ public class ApnSettings extends PreferenceActivity implements return key; } + @Override + protected void showDialog(int dialogId) { + removeDialog(dialogId); + super.showDialog(dialogId); + } + private boolean restoreDefaultApn() { showDialog(DIALOG_RESTORE_DEFAULTAPN); mRestoreDefaultApnMode = true; @@ -305,9 +314,9 @@ public class ApnSettings extends PreferenceActivity implements fillList(); getPreferenceScreen().setEnabled(true); mRestoreDefaultApnMode = false; - dismissDialog(DIALOG_RESTORE_DEFAULTAPN); + removeDialog(DIALOG_RESTORE_DEFAULTAPN); Toast.makeText( - ApnSettings.this, + getActivity(), getResources().getString( R.string.restore_default_apn_completed), Toast.LENGTH_LONG).show(); @@ -329,7 +338,7 @@ public class ApnSettings extends PreferenceActivity implements switch (msg.what) { case EVENT_RESTORE_DEFAULTAPN_START: ContentResolver resolver = getContentResolver(); - resolver.delete(DEFAULTAPN_URI, null, null); + resolver.delete(DEFAULTAPN_URI, null, null); mRestoreApnUiHandler .sendEmptyMessage(EVENT_RESTORE_DEFAULTAPN_COMPLETE); break; @@ -338,20 +347,16 @@ public class ApnSettings extends PreferenceActivity implements } @Override - protected Dialog onCreateDialog(int id) { + public Dialog onCreateDialog(int id) { if (id == DIALOG_RESTORE_DEFAULTAPN) { - ProgressDialog dialog = new ProgressDialog(this); + ProgressDialog dialog = new ProgressDialog(getActivity()); dialog.setMessage(getResources().getString(R.string.restore_default_apn)); dialog.setCancelable(false); + dialog.setCanceledOnTouchOutside(false); + getPreferenceScreen().setEnabled(false); return dialog; } return null; } - @Override - protected void onPrepareDialog(int id, Dialog dialog) { - if (id == DIALOG_RESTORE_DEFAULTAPN) { - getPreferenceScreen().setEnabled(false); - } - } } diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index dc63831..83b06c3 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -864,4 +864,6 @@ public class Settings extends PreferenceActivity public static class AndroidBeamSettingsActivity extends Settings { /* empty */ } public static class WifiDisplaySettingsActivity extends Settings { /* empty */ } public static class AnonymousStatsActivity extends Settings { /* empty */ } + public static class ApnSettingsActivity extends Settings { /* empty */ } + public static class ApnEditorActivity extends Settings { /* empty */ } } |