diff options
-rw-r--r-- | res/layout/list_item_checkable.xml | 26 | ||||
-rw-r--r-- | res/layout/preference_font_style.xml | 11 | ||||
-rw-r--r-- | res/values/cm_arrays.xml | 13 | ||||
-rw-r--r-- | res/values/cm_strings.xml | 7 | ||||
-rw-r--r-- | res/values/preferences_defaults.xml | 4 | ||||
-rw-r--r-- | res/xml/preferences_general.xml | 17 | ||||
-rw-r--r-- | src/com/android/launcher3/AppsCustomizePagedView.java | 1 | ||||
-rw-r--r-- | src/com/android/launcher3/DynamicGrid.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher3/Folder.java | 1 | ||||
-rw-r--r-- | src/com/android/launcher3/FolderIcon.java | 1 | ||||
-rw-r--r-- | src/com/android/launcher3/Hotseat.java | 1 | ||||
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 1 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherAppState.java | 14 | ||||
-rw-r--r-- | src/com/android/launcher3/Utilities.java | 34 | ||||
-rw-r--r-- | src/com/android/launcher3/settings/FontStylePreference.java | 134 | ||||
-rw-r--r-- | src/com/android/launcher3/settings/SettingsProvider.java | 4 |
16 files changed, 253 insertions, 20 deletions
diff --git a/res/layout/list_item_checkable.xml b/res/layout/list_item_checkable.xml new file mode 100644 index 000000000..86d6b1a4c --- /dev/null +++ b/res/layout/list_item_checkable.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="?android:attr/listPreferredItemHeightSmall" + android:textAppearance="?android:attr/textAppearanceMedium" + android:textColor="?android:attr/textColorAlertDialogListItem" + android:gravity="center_vertical" + android:paddingStart="16dip" + android:paddingEnd="16dip" + android:checkMark="?android:attr/listChoiceIndicatorSingle" + android:ellipsize="marquee" /> diff --git a/res/layout/preference_font_style.xml b/res/layout/preference_font_style.xml new file mode 100644 index 000000000..5356ebdf1 --- /dev/null +++ b/res/layout/preference_font_style.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + <ListView android:id="@android:id/list" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:choiceMode="singleChoice"/> +</LinearLayout>
\ No newline at end of file diff --git a/res/values/cm_arrays.xml b/res/values/cm_arrays.xml new file mode 100644 index 000000000..580e89317 --- /dev/null +++ b/res/values/cm_arrays.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string-array name="preferences_interface_general_icons_text_font_family_entries"> + <item>Regular</item> + <item>Light</item> + <item>Condensed</item> + </string-array> + <string-array name="preferences_interface_general_icons_text_font_family_values"> + <item>sans-serif</item> + <item>sans-serif-light</item> + <item>sans-serif-condensed</item> + </string-array> +</resources>
\ No newline at end of file diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index d880bfb4b..2dc3fa4bc 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -44,6 +44,9 @@ <!-- General --> <string name="preferences_interface_general_title">General</string> - <string name="preferences_interface_general_large_icons_title">Larger icons</string> - <string name="preferences_interface_general_large_icons_summary">Use extra large application icons in homescreen and drawer</string> + <string name="preferences_interface_general_icons_category">Icons</string> + <string name="preferences_interface_general_icons_large_title">Larger icons</string> + <string name="preferences_interface_general_icons_large_summary">Use extra large application icons in homescreen and drawer</string> + <string name="preferences_interface_general_icons_text_style_title">Text font style</string> + <string name="preferences_interface_general_icons_text_style_summary">Variant and style of font to use for icon text</string> </resources>
\ No newline at end of file diff --git a/res/values/preferences_defaults.xml b/res/values/preferences_defaults.xml index ae2ee8037..9fa44b27e 100644 --- a/res/values/preferences_defaults.xml +++ b/res/values/preferences_defaults.xml @@ -3,5 +3,7 @@ <bool name="preferences_interface_homescreen_search_default">true</bool> <bool name="preferences_interface_homescreen_scrolling_wallpaper_scroll_default">true</bool> <bool name="preferences_interface_homescreen_scrolling_page_outlines_default">@bool/config_workspaceDefaultShowOutlines</bool> - <bool name="preferences_interface_general_large_icons_default">@bool/config_largeIcons</bool> + <bool name="preferences_interface_general_icons_large_default">@bool/config_largeIcons</bool> + <string name="preferences_interface_general_icons_text_font_family_default">sans-serif-condensed</string> + <integer name="preferences_interface_general_icons_text_font_style_default">0</integer> </resources>
\ No newline at end of file diff --git a/res/xml/preferences_general.xml b/res/xml/preferences_general.xml index 58e8a9aea..96b93ec44 100644 --- a/res/xml/preferences_general.xml +++ b/res/xml/preferences_general.xml @@ -18,8 +18,17 @@ xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher3" android:key="ui_general" android:title="@string/preferences_interface_general_title"> - <CheckBoxPreference android:key="ui_general_large_icons" - android:title="@string/preferences_interface_general_large_icons_title" - android:summary="@string/preferences_interface_general_large_icons_summary" - android:defaultValue="@bool/preferences_interface_general_large_icons_default" /> + <PreferenceCategory android:title="@string/preferences_interface_general_icons_category"> + <CheckBoxPreference android:key="ui_general_icons_large" + android:title="@string/preferences_interface_general_icons_large_title" + android:summary="@string/preferences_interface_general_icons_large_summary" + android:defaultValue="@bool/preferences_interface_general_icons_large_default" /> + <com.android.launcher3.settings.FontStylePreference android:key="ui_general_icons_text_font" + android:title="@string/preferences_interface_general_icons_text_style_title" + android:summary="@string/preferences_interface_general_icons_text_style_summary" + android:entries="@array/preferences_interface_general_icons_text_font_family_entries" + android:entryValues="@array/preferences_interface_general_icons_text_font_family_values" + android:defaultValue="@string/preferences_interface_general_icons_text_font_family_default" /> + </PreferenceCategory> + </PreferenceScreen> diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java index 34dd9294d..34625dfd7 100644 --- a/src/com/android/launcher3/AppsCustomizePagedView.java +++ b/src/com/android/launcher3/AppsCustomizePagedView.java @@ -1088,6 +1088,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen icon.setOnLongClickListener(this); icon.setOnTouchListener(this); icon.setOnKeyListener(this); + Utilities.applyTypeface(icon); int index = i - startIndex; int x = index % mCellCountX; diff --git a/src/com/android/launcher3/DynamicGrid.java b/src/com/android/launcher3/DynamicGrid.java index c6f2cb282..53332655e 100644 --- a/src/com/android/launcher3/DynamicGrid.java +++ b/src/com/android/launcher3/DynamicGrid.java @@ -518,8 +518,8 @@ public class DynamicGrid { ArrayList<DeviceProfile> deviceProfiles = new ArrayList<DeviceProfile>(); boolean hasAA = !AppsCustomizePagedView.DISABLE_ALL_APPS; - boolean useLargeIcons = SettingsProvider.getBoolean(context, SettingsProvider.SETTINGS_UI_GENERAL_LARGE_ICONS, - R.bool.preferences_interface_general_large_icons_default); + boolean useLargeIcons = SettingsProvider.getBoolean(context, SettingsProvider.SETTINGS_UI_GENERAL_ICONS_LARGE, + R.bool.preferences_interface_general_icons_large_default); // Our phone profiles include the bar sizes in each orientation deviceProfiles.add(new DeviceProfile("Super Short Stubby", 255, 300, 2, 3, (useLargeIcons ? 54 : 48), 13, (hasAA ? 5 : 4), (useLargeIcons ? 54 : 48))); diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java index 69d9a3d4b..1a25760ae 100644 --- a/src/com/android/launcher3/Folder.java +++ b/src/com/android/launcher3/Folder.java @@ -538,6 +538,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList textView.setTag(item); textView.setTextColor(getResources().getColor(R.color.folder_items_text_color)); textView.setShadowsEnabled(false); + Utilities.applyTypeface(textView); textView.setOnClickListener(this); textView.setOnLongClickListener(this); diff --git a/src/com/android/launcher3/FolderIcon.java b/src/com/android/launcher3/FolderIcon.java index cd1ff2c37..e80b0f4f2 100644 --- a/src/com/android/launcher3/FolderIcon.java +++ b/src/com/android/launcher3/FolderIcon.java @@ -139,6 +139,7 @@ public class FolderIcon extends LinearLayout implements FolderListener { icon.setClipToPadding(false); icon.mFolderName = (BubbleTextView) icon.findViewById(R.id.folder_icon_name); icon.mFolderName.setText(folderInfo.title); + Utilities.applyTypeface(icon.mFolderName); icon.mPreviewBackground = (ImageView) icon.findViewById(R.id.preview_background); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java index 094e188c7..c88cd1da5 100644 --- a/src/com/android/launcher3/Hotseat.java +++ b/src/com/android/launcher3/Hotseat.java @@ -151,6 +151,7 @@ public class Hotseat extends FrameLayout { inflater.inflate(R.layout.all_apps_button, mContent, false); Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon); Utilities.resizeIconDrawable(d); + Utilities.applyTypeface(allAppsButton); allAppsButton.setCompoundDrawables(null, d, null, null); allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label)); diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 53fa329fb..6347324ed 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -1321,6 +1321,7 @@ public class Launcher extends Activity BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); favorite.applyFromShortcutInfo(info, mIconCache); favorite.setOnClickListener(this); + Utilities.applyTypeface(favorite); return favorite; } diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index a255b89a2..cba0d61ac 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -24,7 +24,7 @@ import android.database.ContentObserver; import android.os.Handler; import android.provider.Settings; import android.util.Log; -import android.view.Display; +import com.android.launcher3.settings.SettingsProvider; import java.lang.ref.WeakReference; @@ -113,6 +113,18 @@ public class LauncherAppState { ContentResolver resolver = sContext.getContentResolver(); resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true, mFavoritesObserver); + + // Generate default typeface + String fontFamily = SettingsProvider.getString(sContext, + SettingsProvider.SETTINGS_UI_GENERAL_ICONS_TEXT_FONT_FAMILY, + R.string.preferences_interface_general_icons_text_font_family_default); + + // TODO: Implement font styles + int fontStyle = SettingsProvider.getInt(sContext, + SettingsProvider.SETTINGS_UI_GENERAL_ICONS_TEXT_FONT_STYLE, + R.integer.preferences_interface_general_icons_text_font_style_default); + + Utilities.generateTypeface(fontFamily, fontStyle); } /** diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 21c546d04..f41a1c2e5 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -21,21 +21,14 @@ import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BlurMaskFilter; -import android.graphics.Canvas; -import android.graphics.ColorMatrix; -import android.graphics.ColorMatrixColorFilter; -import android.graphics.Matrix; -import android.graphics.Paint; -import android.graphics.PaintFlagsDrawFilter; -import android.graphics.Rect; +import android.graphics.*; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.PaintDrawable; import android.util.DisplayMetrics; import android.util.Log; import android.view.View; +import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; @@ -58,6 +51,8 @@ final class Utilities { private static final Rect sOldBounds = new Rect(); private static final Canvas sCanvas = new Canvas(); + private static Typeface sTypeface; + static { sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, Paint.FILTER_BITMAP_FLAG)); @@ -202,6 +197,27 @@ final class Utilities { } /** + * Generates the default icon typeface for use in icons. + * + * @param familyName May be null. The name of the font family. + * @param style The style (normal, bold, italic) of the typeface. e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC + */ + static void generateTypeface(String familyName, int style) { + sTypeface = Typeface.create(familyName, style); + } + + /** + * Applies the default icon typeface to a textview. + * + * @param textView View to apply typeface to. + */ + static void applyTypeface(TextView textView) { + if (sTypeface != null) { + textView.setTypeface(sTypeface); + } + } + + /** * Given a coordinate relative to the descendant, find the coordinate in a parent view's * coordinates. * 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); |