diff options
author | Nebojsa Cvetkovic <nebkat@gmail.com> | 2014-01-05 23:15:15 +0000 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2014-01-24 16:25:19 -0800 |
commit | 233a1403274298f510bb57f02ffde54e40d3ec0b (patch) | |
tree | 60e2ca8e683ec2ed4a5c62caa463d22614bade0a /src/com/android/launcher3/settings | |
parent | cd7dd3299ed70b82aad991063769eb6f3d33ce42 (diff) | |
download | android_packages_apps_Trebuchet-233a1403274298f510bb57f02ffde54e40d3ec0b.tar.gz android_packages_apps_Trebuchet-233a1403274298f510bb57f02ffde54e40d3ec0b.tar.bz2 android_packages_apps_Trebuchet-233a1403274298f510bb57f02ffde54e40d3ec0b.zip |
FontStylePreference: Simplify using onPrepareDialogBuilder()
Change-Id: I26b0886564e863bdf8fe601003220e612ed95cbf
Diffstat (limited to 'src/com/android/launcher3/settings')
-rw-r--r-- | src/com/android/launcher3/settings/FontStylePreference.java | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/src/com/android/launcher3/settings/FontStylePreference.java b/src/com/android/launcher3/settings/FontStylePreference.java index 6c1160d40..50df4b280 100644 --- a/src/com/android/launcher3/settings/FontStylePreference.java +++ b/src/com/android/launcher3/settings/FontStylePreference.java @@ -2,11 +2,11 @@ package com.android.launcher3.settings; import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; import android.graphics.Typeface; import android.preference.ListPreference; import android.text.TextUtils; import android.util.AttributeSet; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -17,7 +17,6 @@ import java.util.Arrays; import java.util.List; public class FontStylePreference extends ListPreference { - private ListView mListView; private String mValue; public int mClickedDialogEntryIndex; private boolean mValueSet; @@ -28,17 +27,32 @@ public class FontStylePreference extends ListPreference { @Override protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { - return; - } + if (getEntries() == null || getEntryValues() == null) { + throw new IllegalStateException( + "ListPreference requires an entries array and an entryValues array."); + } - @Override - public View onCreateDialogView() { - View view = LayoutInflater.from(getContext()).inflate(R.layout.preference_font_style, null); - mListView = (ListView) view.findViewById(android.R.id.list); - mListView.setAdapter(new FontStyleAdapter(getContext())); - mListView.setOnItemClickListener(mOnClickListener); - mListView.setItemChecked(getValueIndex(), true); - return view; + mClickedDialogEntryIndex = getValueIndex(); + builder.setSingleChoiceItems(new FontStyleAdapter(getContext()), mClickedDialogEntryIndex, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + mClickedDialogEntryIndex = which; + + /* + * Clicking on an item simulates the positive button + * click, and dismisses the dialog. + */ + FontStylePreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE); + dialog.dismiss(); + } + }); + + /* + * The typical interaction for list-based dialogs is to have + * click-on-an-item dismiss the dialog instead of the user having to + * press 'Ok'. + */ + builder.setPositiveButton(null, null); } @Override @@ -93,12 +107,6 @@ public class FontStylePreference extends ListPreference { return findIndexOfValue(mValue); } - private AdapterView.OnItemClickListener mOnClickListener = new AdapterView.OnItemClickListener() { - public void onItemClick(AdapterView<?> parent, View v, int position, long id) { - mClickedDialogEntryIndex = position; - } - }; - private class FontStyleAdapter extends ArrayAdapter<CharSequence> { private LayoutInflater mInflater; private List<CharSequence> mEntries; |