diff options
author | Nebojsa Cvetkovic <nebkat@gmail.com> | 2013-12-31 17:16:15 +0000 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2014-01-24 16:25:19 -0800 |
commit | 9bbb6cf6d78824d4c68382f33b654c43f4aaa109 (patch) | |
tree | 96cb8961b56871f89949647514be711b161f3697 /src/com/android/launcher3/settings | |
parent | e297d9676bf5d4e7925e51e808bef063d22f2078 (diff) | |
download | android_packages_apps_Trebuchet-9bbb6cf6d78824d4c68382f33b654c43f4aaa109.tar.gz android_packages_apps_Trebuchet-9bbb6cf6d78824d4c68382f33b654c43f4aaa109.tar.bz2 android_packages_apps_Trebuchet-9bbb6cf6d78824d4c68382f33b654c43f4aaa109.zip |
FontStylePreference: Initial preference with choice of font family
Change-Id: Idbb400605e47cd4f64a7edd05ceea05504727efc
Diffstat (limited to 'src/com/android/launcher3/settings')
-rw-r--r-- | src/com/android/launcher3/settings/FontStylePreference.java | 134 | ||||
-rw-r--r-- | src/com/android/launcher3/settings/SettingsProvider.java | 4 |
2 files changed, 137 insertions, 1 deletions
diff --git a/src/com/android/launcher3/settings/FontStylePreference.java b/src/com/android/launcher3/settings/FontStylePreference.java new file mode 100644 index 000000000..6c1160d40 --- /dev/null +++ b/src/com/android/launcher3/settings/FontStylePreference.java @@ -0,0 +1,134 @@ +package com.android.launcher3.settings; + +import android.app.AlertDialog; +import android.content.Context; +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; +import android.widget.*; +import com.android.launcher3.R; + +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; + + public FontStylePreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { + return; + } + + @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; + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + + if (positiveResult && mClickedDialogEntryIndex >= 0 && getEntryValues() != null) { + String value = getEntryValues()[mClickedDialogEntryIndex].toString(); + if (callChangeListener(value)) { + setValue(value); + } + } + } + + @Override + protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { + setValue(restoreValue ? getPersistedString(mValue) : (String) defaultValue); + } + + /** + * Sets the value of the key. This should be one of the entries in + * {@link #getEntryValues()}. + * + * @param value The value to set for the key. + */ + @Override + public void setValue(String value) { + // Always persist/notify the first time. + final boolean changed = !TextUtils.equals(mValue, value); + if (changed || !mValueSet) { + mValue = value; + mValueSet = true; + persistString(value); + if (changed) { + notifyChanged(); + } + } + } + + /** + * Returns the value of the key. This should be one of the entries in + * {@link #getEntryValues()}. + * + * @return The value of the key. + */ + @Override + public String getValue() { + return mValue; + } + + private int getValueIndex() { + 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; + private List<CharSequence> mValues; + + public FontStyleAdapter(Context context) { + super(context, -1, getEntryValues()); + + mInflater = LayoutInflater.from(context); + mEntries = Arrays.asList(getEntries()); + mValues = Arrays.asList(getEntryValues()); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + CheckedTextView textView; + + if (convertView == null) { + textView = (CheckedTextView) mInflater.inflate(R.layout.list_item_checkable, parent, false); + } else { + textView = (CheckedTextView) convertView; + } + + if (textView != null) { + textView.setText(mEntries.get(position)); + textView.setTag(mValues.get(position)); + textView.setTypeface(Typeface.create((String) mValues.get(position), Typeface.NORMAL)); + } + + return textView; + } + } +} diff --git a/src/com/android/launcher3/settings/SettingsProvider.java b/src/com/android/launcher3/settings/SettingsProvider.java index 3d4f5d229..9c0a283ac 100644 --- a/src/com/android/launcher3/settings/SettingsProvider.java +++ b/src/com/android/launcher3/settings/SettingsProvider.java @@ -28,7 +28,9 @@ public final class SettingsProvider { public static final String SETTINGS_UI_HOMESCREEN_SEARCH = "ui_homescreen_search"; public static final String SETTINGS_UI_HOMESCREEN_SCROLLING_WALLPAPER_SCROLL = "ui_homescreen_scrolling_wallpaper_scroll"; public static final String SETTINGS_UI_HOMESCREEN_SCROLLING_PAGE_OUTLINES = "ui_homescreen_scrolling_page_outlines"; - public static final String SETTINGS_UI_GENERAL_LARGE_ICONS = "ui_general_large_icons"; + public static final String SETTINGS_UI_GENERAL_ICONS_LARGE = "ui_general_icons_large"; + public static final String SETTINGS_UI_GENERAL_ICONS_TEXT_FONT_FAMILY = "ui_general_icons_text_font"; + public static final String SETTINGS_UI_GENERAL_ICONS_TEXT_FONT_STYLE = "ui_general_icons_text_font_style"; public static SharedPreferences get(Context context) { return context.getSharedPreferences(SETTINGS_KEY, 0); |