Use Drawer in Settings app

- get rid of PreferenceActivity as much as we can and use fragments instead
- add Drawer widget
- add Dashboard high level entry into the Drawer (but this is work in progress and would be done in another CL)
- add bypass of fragment's Header  validation when launched from the Drawer but *force* validation if external
call thru an Intent

Be aware that WifiPickerActivity should remain for now a PreferenceActivity. It is used by SetupWizard and should
not trigger running the SettingsActivity's header building code. SetupWizard is a Home during the provisionnig process
and then deactivate itself as a Home but would make the Home header to appear in the Drawer (because momentarily we
would have two Home).

Also, verified that:

- the WiFi settings still work when called from SetupWizard
- when you have multiple Launchers, the Home header will appear in the list of Headers in the Drawer

Change-Id: I407a5e0fdd843ad7615d3d511c416a44e3d97c90
This commit is contained in:
Fabrice Di Meglio
2014-01-17 19:17:58 -08:00
parent af79ddb358
commit 263bcc8b73
76 changed files with 2475 additions and 1494 deletions

View File

@@ -16,6 +16,7 @@
package com.android.settings;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentUris;
@@ -31,21 +32,18 @@ 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;
import com.android.internal.telephony.PhoneConstants;
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 {
@@ -148,7 +146,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);
@@ -188,7 +186,7 @@ public class ApnEditor extends PreferenceActivity
mRes = getResources();
final Intent intent = getIntent();
final Intent intent = getActivity().getIntent();
final String action = intent.getAction();
mFirstTime = icicle == null;
@@ -208,24 +206,24 @@ 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 {
finish();
return;
}
mCursor = managedQuery(mUri, sProjection, null, null);
mCursor = getActivity().getContentResolver().query(mUri, sProjection, null, null, null);
mCursor.moveToFirst();
mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
mTelephonyManager = (TelephonyManager) getSystemService(Activity.TELEPHONY_SERVICE);
fillUi();
}
@@ -441,8 +439,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)
@@ -452,7 +450,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
@@ -477,20 +474,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));
@@ -598,12 +582,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)
@@ -613,19 +597,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();