diff options
Diffstat (limited to 'src/com/cyanogenmod')
14 files changed, 396 insertions, 79 deletions
diff --git a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java index f3ca9e794..eb1642c2f 100644 --- a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java +++ b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java @@ -493,7 +493,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } public void showAllAppsCling() { - Cling allAppsCling = (Cling) getTabHost().findViewById(R.id.all_apps_cling); + AppsCustomizeTabHost tabHost = getTabHost(); + if (tabHost == null) return; + Cling allAppsCling = (Cling) tabHost.findViewById(R.id.all_apps_cling); if (!mHasShownAllAppsCling && isDataReady() && testDataReady()) { mHasShownAllAppsCling = true; // Calculate the position for the cling punch through diff --git a/src/com/cyanogenmod/trebuchet/BubbleTextView.java b/src/com/cyanogenmod/trebuchet/BubbleTextView.java index 0fa3d910f..83ab2aabf 100644 --- a/src/com/cyanogenmod/trebuchet/BubbleTextView.java +++ b/src/com/cyanogenmod/trebuchet/BubbleTextView.java @@ -62,6 +62,9 @@ public class BubbleTextView extends TextView { private boolean mStayPressed; + private boolean mTextVisible = true; + private CharSequence mVisibleText; + public BubbleTextView(Context context) { super(context); init(); @@ -314,4 +317,15 @@ public class BubbleTextView extends TextView { } return true; } + + public void setTextVisible(boolean visible) { + if (mTextVisible == visible) return; + mTextVisible = visible; + if (visible) { + setText(mVisibleText); + } else { + mVisibleText = getText(); + setText(""); + } + } } diff --git a/src/com/cyanogenmod/trebuchet/CellLayout.java b/src/com/cyanogenmod/trebuchet/CellLayout.java index 8bb5b567f..0586d296d 100644 --- a/src/com/cyanogenmod/trebuchet/CellLayout.java +++ b/src/com/cyanogenmod/trebuchet/CellLayout.java @@ -255,7 +255,6 @@ public class CellLayout extends ViewGroup { mForegroundRect = new Rect(); mChildren = new CellLayoutChildren(context); - mChildren.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap); addView(mChildren); } @@ -835,6 +834,11 @@ public class CellLayout extends ViewGroup { int numWidthGaps = mCountX - 1; int numHeightGaps = mCountY - 1; + if (!LauncherApplication.isScreenLarge()){ + mCellWidth = mOriginalCellWidth = (widthSpecSize - mPaddingLeft - mPaddingRight) / mCountX; + mCellHeight = mOriginalCellHeight = (heightSpecSize - mPaddingTop - mPaddingBottom) / mCountY; + } + if (mOriginalWidthGap < 0 || mOriginalHeightGap < 0) { int hSpace = widthSpecSize - mPaddingLeft - mPaddingRight; int vSpace = heightSpecSize - mPaddingTop - mPaddingBottom; @@ -848,6 +852,8 @@ public class CellLayout extends ViewGroup { mHeightGap = mOriginalHeightGap; } + mChildren.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap); + // Initial values correspond to widthSpecMode == MeasureSpec.EXACTLY int newWidth = widthSpecSize; int newHeight = heightSpecSize; diff --git a/src/com/cyanogenmod/trebuchet/DeleteDropTarget.java b/src/com/cyanogenmod/trebuchet/DeleteDropTarget.java index 7c23677cb..28fabef61 100644 --- a/src/com/cyanogenmod/trebuchet/DeleteDropTarget.java +++ b/src/com/cyanogenmod/trebuchet/DeleteDropTarget.java @@ -28,6 +28,7 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Handler; import android.util.AttributeSet; +import android.view.HapticFeedbackConstants; import android.view.View; import android.view.ViewGroup; import android.view.animation.DecelerateInterpolator; @@ -59,6 +60,7 @@ public class DeleteDropTarget extends ButtonDropTarget { private final Runnable mShowUninstaller = new Runnable() { public void run() { + performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); switchToUninstallTarget(); } }; @@ -88,6 +90,9 @@ public class DeleteDropTarget extends ButtonDropTarget { } } + private boolean isAllAppsItem(DragSource source, Object info) { + return isAllAppsApplication(source, info) || isAllAppsWidget(source, info); + } private boolean isAllAppsApplication(DragSource source, Object info) { return (source instanceof AppsCustomizeView) && (info instanceof ApplicationInfo); } @@ -143,7 +148,11 @@ public class DeleteDropTarget extends ButtonDropTarget { setTextColor(mOriginalTextColor); ((ViewGroup) getParent()).setVisibility(View.VISIBLE); if (getText().length() > 0) { - setText(R.string.delete_target_label); + if (isAllAppsItem(source, info)) { + setText(R.string.cancel_target_label); + } else { + setText(R.string.delete_target_label); + } } } @@ -191,7 +200,11 @@ public class DeleteDropTarget extends ButtonDropTarget { mMode = MODE_DELETE; if (getText().length() > 0) { - setText(R.string.delete_target_label); + if (isAllAppsItem(d.dragSource, d.dragInfo)) { + setText(R.string.cancel_target_label); + } else { + setText(R.string.delete_target_label); + } } setCompoundDrawablesWithIntrinsicBounds(mRemoveNormalDrawable, null, null, null); diff --git a/src/com/cyanogenmod/trebuchet/Folder.java b/src/com/cyanogenmod/trebuchet/Folder.java index 509bc96f8..57fcfcb69 100644 --- a/src/com/cyanogenmod/trebuchet/Folder.java +++ b/src/com/cyanogenmod/trebuchet/Folder.java @@ -47,6 +47,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import com.cyanogenmod.trebuchet.FolderInfo.FolderListener; +import com.cyanogenmod.trebuchet.preference.PreferencesProvider; import java.util.ArrayList; @@ -172,6 +173,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList mFolderName.setSelectAllOnFocus(true); mFolderName.setInputType(mFolderName.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS); + + if (PreferencesProvider.Interface.Homescreen.getHideIconLabels(mLauncher)){ + mFolderName.setVisibility(View.GONE); + mFolderNameHeight = getPaddingBottom(); + } } private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { @@ -250,7 +256,9 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList // Convert to a string here to ensure that no other state associated with the text field // gets saved. String newTitle = mFolderName.getText().toString(); - mInfo.setTitle(newTitle); + if (!PreferencesProvider.Interface.Homescreen.getHideIconLabels(mLauncher)) { + mInfo.setTitle(newTitle); + } LauncherModel.updateItemInDatabase(mLauncher, mInfo); if (commit) { diff --git a/src/com/cyanogenmod/trebuchet/FolderIcon.java b/src/com/cyanogenmod/trebuchet/FolderIcon.java index 4042f4c88..44f1c7ac5 100644 --- a/src/com/cyanogenmod/trebuchet/FolderIcon.java +++ b/src/com/cyanogenmod/trebuchet/FolderIcon.java @@ -37,8 +37,10 @@ import android.view.animation.DecelerateInterpolator; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; + import com.cyanogenmod.trebuchet.DropTarget.DragObject; import com.cyanogenmod.trebuchet.FolderInfo.FolderListener; +import com.cyanogenmod.trebuchet.preference.PreferencesProvider; import java.util.ArrayList; diff --git a/src/com/cyanogenmod/trebuchet/Hotseat.java b/src/com/cyanogenmod/trebuchet/Hotseat.java index f75333ccc..524da5acf 100644 --- a/src/com/cyanogenmod/trebuchet/Hotseat.java +++ b/src/com/cyanogenmod/trebuchet/Hotseat.java @@ -35,6 +35,9 @@ public class Hotseat extends FrameLayout { private int mCellCountY; private boolean mIsLandscape; + private static final int DEFAULT_CELL_COUNT_X = 5; + private static final int DEFAULT_CELL_COUNT_Y = 1; + public Hotseat(Context context) { this(context, null); } @@ -81,8 +84,8 @@ public class Hotseat extends FrameLayout { @Override protected void onFinishInflate() { super.onFinishInflate(); - if (mCellCountX < 0) mCellCountX = LauncherModel.getCellCountX(); - if (mCellCountY < 0) mCellCountY = LauncherModel.getCellCountY(); + if (mCellCountX < 0) mCellCountX = DEFAULT_CELL_COUNT_X; + if (mCellCountY < 0) mCellCountY = DEFAULT_CELL_COUNT_Y; mContent = (CellLayout) findViewById(R.id.layout); mContent.setGridSize(mCellCountX, mCellCountY); diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java index cf1ccd88d..9283243e6 100644 --- a/src/com/cyanogenmod/trebuchet/Launcher.java +++ b/src/com/cyanogenmod/trebuchet/Launcher.java @@ -164,7 +164,7 @@ public final class Launcher extends Activity // Type: long private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; - private static final String TOOLBAR_ICON_METADATA_NAME = "com.cyanogenmod.trebuchet.toolbar_icon"; + private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; /** The different states that Launcher can be in. */ private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; @@ -260,6 +260,7 @@ public final class Launcher extends Activity // Preferences private boolean mShowSearchBar; private boolean mShowDockDivider; + private boolean mHideIconLabels; private boolean mAutoRotate; private Runnable mBuildLayersRunnable = new Runnable() { @@ -298,6 +299,7 @@ public final class Launcher extends Activity // Preferences mShowSearchBar = PreferencesProvider.Interface.Homescreen.getShowSearchBar(this); mShowDockDivider = PreferencesProvider.Interface.Homescreen.Indicator.getShowDockDivider(this); + mHideIconLabels = PreferencesProvider.Interface.Homescreen.getHideIconLabels(this); mAutoRotate = PreferencesProvider.Interface.General.getAutoRotate(this, getResources().getBoolean(R.bool.config_defaultAutoRotate)); if (PROFILE_STARTUP) { @@ -605,7 +607,12 @@ public final class Launcher extends Activity if (mFirstTime) { mFirstTime = false; } else { - workspace.post(mBuildLayersRunnable); + // We delay the layer building a bit in order to give + // other message processing a time to run. In particular + // this avoids a delay in hiding the IME if it was + // currently shown, because doing that may involve + // some communication back with the app. + workspace.postDelayed(mBuildLayersRunnable, 500); observer.removeOnPreDrawListener(this); } return true; @@ -860,6 +867,9 @@ public final class Launcher extends Activity View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); favorite.applyFromShortcutInfo(info, mIconCache); + if (mHideIconLabels) { + favorite.setTextVisible(false); + } favorite.setOnClickListener(this); return favorite; } @@ -1620,6 +1630,9 @@ public final class Launcher extends Activity // Create the view FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); + if (mHideIconLabels) { + newFolder.setTextVisible(false); + } mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1, isWorkspaceLocked()); return newFolder; @@ -2905,10 +2918,14 @@ public final class Launcher extends Activity // Find the app market activity by resolving an intent. // (If multiple app markets are installed, it will return the ResolverActivity.) ComponentName activityName = intent.resolveActivity(getPackageManager()); + + if (activityName != null) { + mAppMarketIntent = intent; + } + if (activityName != null && (ViewConfiguration.get(this).hasPermanentMenuKey() || getResources().getBoolean(R.bool.config_cyanogenmod))) { int coi = getCurrentOrientationIndexForGlobalIcons(); - mAppMarketIntent = intent; sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity( R.id.market_button, activityName, R.drawable.ic_launcher_market_holo); marketButton.setVisibility(View.VISIBLE); @@ -2948,7 +2965,7 @@ public final class Launcher extends Activity Dialog createDialog() { mAdapter = new AddAdapter(Launcher.this); - final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this, + final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this, AlertDialog.THEME_HOLO_DARK); builder.setAdapter(mAdapter, this); @@ -3122,6 +3139,9 @@ public final class Launcher extends Activity FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item, mIconCache); + if (!mHideIconLabels) { + newFolder.setTextVisible(false); + } workspace.addInScreen(newFolder, item.container, item.screen, item.cellX, item.cellY, 1, 1, false); break; diff --git a/src/com/cyanogenmod/trebuchet/LauncherApplication.java b/src/com/cyanogenmod/trebuchet/LauncherApplication.java index a17498599..cfb4905f8 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherApplication.java +++ b/src/com/cyanogenmod/trebuchet/LauncherApplication.java @@ -40,10 +40,7 @@ public class LauncherApplication extends Application { super.onCreate(); // set sIsScreenXLarge and sScreenDensity *before* creating icon cache - final int screenSize = getResources().getConfiguration().screenLayout & - Configuration.SCREENLAYOUT_SIZE_MASK; - sIsScreenLarge = screenSize == Configuration.SCREENLAYOUT_SIZE_LARGE || - screenSize == Configuration.SCREENLAYOUT_SIZE_XLARGE; + sIsScreenLarge = getResources().getConfiguration().smallestScreenWidthDp >= 600; sScreenDensity = getResources().getDisplayMetrics().density; mIconCache = new IconCache(this); diff --git a/src/com/cyanogenmod/trebuchet/Workspace.java b/src/com/cyanogenmod/trebuchet/Workspace.java index 35d1b71b0..16d92c380 100644 --- a/src/com/cyanogenmod/trebuchet/Workspace.java +++ b/src/com/cyanogenmod/trebuchet/Workspace.java @@ -258,8 +258,11 @@ public class Workspace extends PagedView // Preferences private int mNumberHomescreens; private int mDefaultHomescreen; + private int mScreenPaddingVertical; + private int mScreenPaddingHorizontal; private boolean mShowSearchBar; private boolean mResizeAnyWidget; + private boolean mHideIconLabels; private boolean mScrollWallpaper; private boolean mShowScrollingIndicator; private boolean mFadeScrollingIndicator; @@ -303,26 +306,9 @@ public class Workspace extends PagedView final Resources res = context.getResources(); if (LauncherApplication.isScreenLarge()) { - // Determine number of rows/columns dynamically - // TODO: This code currently fails on tablets with an aspect ratio < 1.3. - // Around that ratio we should make cells the same size in portrait and - // landscape - TypedArray actionBarSizeTypedArray = - context.obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); - final float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f); - final float systemBarHeight = res.getDimension(R.dimen.status_bar_height); - final float smallestScreenDim = res.getConfiguration().smallestScreenWidthDp; - - cellCountX = 1; - while (CellLayout.widthInPortrait(res, cellCountX + 1) <= smallestScreenDim) { - cellCountX++; - } - - cellCountY = 1; - while (actionBarHeight + CellLayout.heightInLandscape(res, cellCountY + 1) - <= smallestScreenDim - systemBarHeight) { - cellCountY++; - } + int[] cellCount = getCellCountsForLarge(context); + cellCountX = cellCount[0]; + cellCountY = cellCount[1]; } mSpringLoadedShrinkFactor = @@ -334,6 +320,12 @@ public class Workspace extends PagedView cellCountY = a.getInt(R.styleable.Workspace_cellCountY, cellCountY); a.recycle(); + // if there is a value set it the preferences, use that instead + if (!LauncherApplication.isScreenLarge()) { + cellCountX = PreferencesProvider.Interface.Homescreen.getCellCountX(context, cellCountX); + cellCountY = PreferencesProvider.Interface.Homescreen.getCellCountY(context, cellCountY); + } + LauncherModel.updateWorkspaceLayoutCells(cellCountX, cellCountY); setHapticFeedbackEnabled(false); @@ -344,8 +336,11 @@ public class Workspace extends PagedView if (mDefaultHomescreen >= mNumberHomescreens) { mDefaultHomescreen = mNumberHomescreens / 2; } + mScreenPaddingVertical = PreferencesProvider.Interface.Homescreen.getScreenPaddingVertical(context); + mScreenPaddingHorizontal = PreferencesProvider.Interface.Homescreen.getScreenPaddingHorizontal(context); mShowSearchBar = PreferencesProvider.Interface.Homescreen.getShowSearchBar(context); mResizeAnyWidget = PreferencesProvider.Interface.Homescreen.getResizeAnyWidget(context); + mHideIconLabels = PreferencesProvider.Interface.Homescreen.getHideIconLabels(context); mScrollWallpaper = PreferencesProvider.Interface.Homescreen.Scrolling.getScrollWallpaper(context); mTransitionEffect = PreferencesProvider.Interface.Homescreen.Scrolling.getTransitionEffect(context, res.getString(R.string.config_workspaceDefaultTransitionEffect)); @@ -362,6 +357,33 @@ public class Workspace extends PagedView setMotionEventSplittingEnabled(true); } + public static int[] getCellCountsForLarge(Context context) { + int[] cellCount = new int[2]; + + final Resources res = context.getResources(); + // Determine number of rows/columns dynamically + // TODO: This code currently fails on tablets with an aspect ratio < 1.3. + // Around that ratio we should make cells the same size in portrait and + // landscape + TypedArray actionBarSizeTypedArray = + context.obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); + final float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f); + final float systemBarHeight = res.getDimension(R.dimen.status_bar_height); + final float smallestScreenDim = res.getConfiguration().smallestScreenWidthDp; + + cellCount[0] = 1; + while (CellLayout.widthInPortrait(res, cellCount[0] + 1) <= smallestScreenDim) { + cellCount[0]++; + } + + cellCount[1] = 1; + while (actionBarHeight + CellLayout.heightInLandscape(res, cellCount[1] + 1) + <= smallestScreenDim - systemBarHeight) { + cellCount[1]++; + } + return cellCount; + } + // estimate the size of a widget with spans hSpan, vSpan. return MAX_VALUE for each // dimension if unsuccessful public int[] estimateItemSize(int hSpan, int vSpan, @@ -447,8 +469,12 @@ public class Workspace extends PagedView LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (int i = 0; i < mNumberHomescreens; i++) { - inflater.inflate(R.layout.workspace_screen, this); - } + View screen = inflater.inflate(R.layout.workspace_screen, null); + screen.setPadding(screen.getPaddingLeft() + mScreenPaddingHorizontal, + screen.getPaddingTop() + mScreenPaddingVertical, + screen.getPaddingRight() + mScreenPaddingHorizontal, + screen.getPaddingBottom() + mScreenPaddingVertical); + addView(screen); } try { mBackground = res.getDrawable(R.drawable.apps_customize_bg); @@ -571,9 +597,13 @@ public class Workspace extends PagedView layout = mLauncher.getHotseat().getLayout(); child.setOnKeyListener(null); - // Hide folder title in the hotseat - if (child instanceof FolderIcon) { - ((FolderIcon) child).setTextVisible(false); + if (!mHideIconLabels) { + // Hide titles in the hotseat + if (child instanceof FolderIcon) { + ((FolderIcon) child).setTextVisible(false); + } else if (child instanceof BubbleTextView) { + ((BubbleTextView) child).setTextVisible(false); + } } if (screen < 0) { @@ -585,9 +615,13 @@ public class Workspace extends PagedView y = mLauncher.getHotseat().getCellYFromOrder(screen); } } else { - // Show folder title if not in the hotseat - if (child instanceof FolderIcon) { - ((FolderIcon) child).setTextVisible(true); + if (!mHideIconLabels) { + // Show titles if not in the hotseat + if (child instanceof FolderIcon) { + ((FolderIcon) child).setTextVisible(true); + } else if (child instanceof BubbleTextView) { + ((BubbleTextView) child).setTextVisible(true); + } } layout = (CellLayout) getPageAt(screen); @@ -911,8 +945,7 @@ public class Workspace extends PagedView return offset; } private void syncWallpaperOffsetWithScroll() { - final boolean enableWallpaperEffects = isHardwareAccelerated(); - if (enableWallpaperEffects) { + if (mScrollWallpaper) { mWallpaperOffset.setFinalX(wallpaperOffsetForCurrentScroll()); } } @@ -2024,7 +2057,7 @@ public class Workspace extends PagedView invalidate(); for (int i = 0; i < getChildCount(); i++) { final CellLayout cl = (CellLayout) getPageAt(i); - cl.fastInvalidate(); + cl.invalidate(); cl.setFastTranslationX(a * mOldTranslationXs[i] + b * mNewTranslationXs[i]); cl.setFastTranslationY(a * mOldTranslationYs[i] + b * mNewTranslationYs[i]); cl.setFastScaleX(a * mOldScaleXs[i] + b * mNewScaleXs[i]); @@ -2034,6 +2067,7 @@ public class Workspace extends PagedView cl.setBackgroundAlphaMultiplier(a * mOldBackgroundAlphaMultipliers[i] + b * mNewBackgroundAlphaMultipliers[i]); cl.setFastAlpha(a * mOldAlphas[i] + b * mNewAlphas[i]); + cl.invalidate(); } syncChildrenLayersEnabledOnVisiblePages(); } @@ -2100,11 +2134,13 @@ public class Workspace extends PagedView d.draw(destCanvas); } else { if (v instanceof FolderIcon) { - // For FolderIcons the text can bleed into the icon area, and so we need to - // hide the text completely (which can't be achieved by clipping). - if (((FolderIcon) v).getTextVisible()) { - ((FolderIcon) v).setTextVisible(false); - textVisible = true; + if (!mHideIconLabels) { + // For FolderIcons the text can bleed into the icon area, and so we need to + // hide the text completely (which can't be achieved by clipping). + if (((FolderIcon) v).getTextVisible()) { + ((FolderIcon) v).setTextVisible(false); + textVisible = true; + } } } else if (v instanceof BubbleTextView) { final BubbleTextView tv = (BubbleTextView) v; @@ -2120,7 +2156,7 @@ public class Workspace extends PagedView v.draw(destCanvas); // Restore text visibility of FolderIcon if necessary - if (textVisible) { + if (!mHideIconLabels && textVisible) { ((FolderIcon) v).setTextVisible(true); } } @@ -3313,6 +3349,9 @@ public class Workspace extends PagedView case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher, cellLayout, (FolderInfo) info, mIconCache); + if (mHideIconLabels) { + ((FolderIcon) view).setTextVisible(false); + } break; default: throw new IllegalStateException("Unknown item type: " + info.itemType); diff --git a/src/com/cyanogenmod/trebuchet/preference/DoubleNumberPickerPreference.java b/src/com/cyanogenmod/trebuchet/preference/DoubleNumberPickerPreference.java new file mode 100644 index 000000000..1a386395c --- /dev/null +++ b/src/com/cyanogenmod/trebuchet/preference/DoubleNumberPickerPreference.java @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2011 The CyanogenMod 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. + */ + +package com.cyanogenmod.trebuchet.preference; + +import android.content.Context; +import android.content.res.TypedArray; +import android.preference.DialogPreference; +import android.preference.Preference; +import android.util.AttributeSet; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; +import android.widget.EditText; +import android.widget.NumberPicker; +import com.cyanogenmod.trebuchet.R; + +/* + * @author Danesh + * @author nebkat + */ + +public class DoubleNumberPickerPreference extends DialogPreference { + private int mMin1, mMax1, mDefault1; + private int mMin2, mMax2, mDefault2; + + private String mMaxExternalKey1, mMinExternalKey1; + private String mMaxExternalKey2, mMinExternalKey2; + + private String mPickerTitle1; + private String mPickerTitle2; + + private NumberPicker mNumberPicker1; + private NumberPicker mNumberPicker2; + + public DoubleNumberPickerPreference(Context context, AttributeSet attrs) { + super(context, attrs); + TypedArray dialogType = context.obtainStyledAttributes(attrs, + com.android.internal.R.styleable.DialogPreference, 0, 0); + TypedArray doubleNumberPickerType = context.obtainStyledAttributes(attrs, + R.styleable.DoubleNumberPickerPreference, 0, 0); + + mMaxExternalKey1 = doubleNumberPickerType.getString(R.styleable.DoubleNumberPickerPreference_maxExternal1); + mMinExternalKey1 = doubleNumberPickerType.getString(R.styleable.DoubleNumberPickerPreference_minExternal1); + mMaxExternalKey2 = doubleNumberPickerType.getString(R.styleable.DoubleNumberPickerPreference_maxExternal2); + mMinExternalKey2 = doubleNumberPickerType.getString(R.styleable.DoubleNumberPickerPreference_minExternal2); + + mPickerTitle1 = doubleNumberPickerType.getString(R.styleable.DoubleNumberPickerPreference_pickerTitle1); + mPickerTitle2 = doubleNumberPickerType.getString(R.styleable.DoubleNumberPickerPreference_pickerTitle2); + + mMax1 = doubleNumberPickerType.getInt(R.styleable.DoubleNumberPickerPreference_max1, 5); + mMin1 = doubleNumberPickerType.getInt(R.styleable.DoubleNumberPickerPreference_min1, 0); + mMax2 = doubleNumberPickerType.getInt(R.styleable.DoubleNumberPickerPreference_max2, 5); + mMin2 = doubleNumberPickerType.getInt(R.styleable.DoubleNumberPickerPreference_min2, 0); + + mDefault1 = doubleNumberPickerType.getInt(R.styleable.DoubleNumberPickerPreference_defaultValue1, mMin1); + mDefault2 = doubleNumberPickerType.getInt(R.styleable.DoubleNumberPickerPreference_defaultValue2, mMin2); + + dialogType.recycle(); + doubleNumberPickerType.recycle(); + } + + @Override + protected View onCreateDialogView() { + int max1 = mMax1; + int min1 = mMin1; + int max2 = mMax2; + int min2 = mMin2; + + // External values + if (mMaxExternalKey1 != null) { + max1 = getSharedPreferences().getInt(mMaxExternalKey1, mMax1); + } + if (mMinExternalKey1 != null) { + min1 = getSharedPreferences().getInt(mMinExternalKey1, mMin1); + } + if (mMaxExternalKey2 != null) { + max2 = getSharedPreferences().getInt(mMaxExternalKey2, mMax2); + } + if (mMinExternalKey2 != null) { + min2 = getSharedPreferences().getInt(mMinExternalKey2, mMin2); + } + + LayoutInflater inflater = + (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View view = inflater.inflate(R.layout.double_number_picker_dialog, null); + + mNumberPicker1 = (NumberPicker) view.findViewById(R.id.number_picker_1); + mNumberPicker2 = (NumberPicker) view.findViewById(R.id.number_picker_2); + + if (mNumberPicker1 == null || mNumberPicker2 == null) { + throw new RuntimeException("mNumberPicker1 or mNumberPicker2 is null!"); + } + + // Initialize state + mNumberPicker1.setWrapSelectorWheel(false); + mNumberPicker1.setMaxValue(max1); + mNumberPicker1.setMinValue(min1); + mNumberPicker1.setValue(getPersistedValue(1)); + mNumberPicker2.setWrapSelectorWheel(false); + mNumberPicker2.setMaxValue(max2); + mNumberPicker2.setMinValue(min2); + mNumberPicker2.setValue(getPersistedValue(2)); + + // Titles + TextView pickerTitle1 = (TextView) view.findViewById(R.id.picker_title_1); + TextView pickerTitle2 = (TextView) view.findViewById(R.id.picker_title_2); + + if (pickerTitle1 != null && pickerTitle2 != null) { + pickerTitle1.setText(mPickerTitle1); + pickerTitle2.setText(mPickerTitle2); + } + + // No keyboard popup + EditText textInput1 = (EditText) mNumberPicker1.findViewById(com.android.internal.R.id.numberpicker_input); + EditText textInput2 = (EditText) mNumberPicker2.findViewById(com.android.internal.R.id.numberpicker_input); + if (textInput1 != null && textInput2 != null) { + textInput1.setCursorVisible(false); + textInput1.setFocusable(false); + textInput1.setFocusableInTouchMode(false); + textInput2.setCursorVisible(false); + textInput2.setFocusable(false); + textInput2.setFocusableInTouchMode(false); + } + + return view; + } + + private int getPersistedValue(int value) { + String[] values = getPersistedString(mDefault1 + "|" + mDefault2).split("\\|"); + if (value == 1) { + try { + return Integer.parseInt(values[0]); + } catch (NumberFormatException e) { + return mDefault1; + } + } else { + try { + return Integer.parseInt(values[1]); + } catch (NumberFormatException e) { + return mDefault2; + } + } + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + if (positiveResult) { + persistString(mNumberPicker1.getValue() + "|" + mNumberPicker2.getValue());; + } + } + + public void setMin1(int min) { + mMin1 = min; + } + public void setMax1(int max) { + mMax1 = max; + } + public void setMin2(int min) { + mMin2 = min; + } + public void setMax2(int max) { + mMax2 = max; + } + public void setDefault1(int def) { + mDefault1 = def; + } + public void setDefault2(int def) { + mDefault2 = def; + } + +} diff --git a/src/com/cyanogenmod/trebuchet/preference/NumberPickerPreference.java b/src/com/cyanogenmod/trebuchet/preference/NumberPickerPreference.java index 31f87562d..810ff407b 100644 --- a/src/com/cyanogenmod/trebuchet/preference/NumberPickerPreference.java +++ b/src/com/cyanogenmod/trebuchet/preference/NumberPickerPreference.java @@ -36,7 +36,6 @@ public class NumberPickerPreference extends DialogPreference { private int mMin, mMax, mDefault; private String mMaxExternalKey, mMinExternalKey; - private Preference mMaxExternalPreference, mMinExternalPreference; private NumberPicker mNumberPicker; @@ -59,38 +58,17 @@ public class NumberPickerPreference extends DialogPreference { numberPickerType.recycle(); } - - protected void onAttachedToActivity() { - // External values - if (mMaxExternalKey != null) { - Preference maxPreference = findPreferenceInHierarchy(mMaxExternalKey); - if (maxPreference != null) { - if (maxPreference instanceof NumberPickerPreference) { - mMaxExternalPreference = maxPreference; - } - } - } - if (mMinExternalKey != null) { - Preference minPreference = findPreferenceInHierarchy(mMinExternalKey); - if (minPreference != null) { - if (minPreference instanceof NumberPickerPreference) { - mMinExternalPreference = minPreference; - } - } - } - } - @Override protected View onCreateDialogView() { int max = mMax; int min = mMin; // External values - if (mMaxExternalKey != null && mMaxExternalPreference != null) { - max = mMaxExternalPreference.getSharedPreferences().getInt(mMaxExternalKey, mMax); + if (mMaxExternalKey != null) { + max = getSharedPreferences().getInt(mMaxExternalKey, mMax); } - if (mMinExternalKey != null && mMinExternalPreference != null) { - min = mMinExternalPreference.getSharedPreferences().getInt(mMinExternalKey, mMin); + if (mMinExternalKey != null) { + min = getSharedPreferences().getInt(mMinExternalKey, mMin); } LayoutInflater inflater = diff --git a/src/com/cyanogenmod/trebuchet/preference/Preferences.java b/src/com/cyanogenmod/trebuchet/preference/Preferences.java index f50852472..6952b39e1 100644 --- a/src/com/cyanogenmod/trebuchet/preference/Preferences.java +++ b/src/com/cyanogenmod/trebuchet/preference/Preferences.java @@ -21,6 +21,10 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceActivity; +import android.preference.PreferenceGroup; + +import com.cyanogenmod.trebuchet.LauncherApplication; + import com.cyanogenmod.trebuchet.R; public class Preferences extends PreferenceActivity { @@ -38,7 +42,19 @@ public class Preferences extends PreferenceActivity { editor.putBoolean(PreferencesProvider.PREFERENCES_CHANGED, true); editor.commit(); + // Remove some preferences on large screens + if (LauncherApplication.isScreenLarge()) { + PreferenceGroup homescreen = (PreferenceGroup) findPreference("ui_homescreen"); + homescreen.removePreference(findPreference("ui_homescreen_grid")); + homescreen.removePreference(findPreference("ui_homescreen_screen_padding_vertical")); + homescreen.removePreference(findPreference("ui_homescreen_screen_padding_horizontal")); + homescreen.removePreference(findPreference("ui_homescreen_indicator")); + + PreferenceGroup drawer = (PreferenceGroup) findPreference("ui_drawer"); + drawer.removePreference(findPreference("ui_drawer_indicator")); + } + Preference version = findPreference("application_version"); - version.setTitle(getString(R.string.application_name) + " " + getString(R.string.application_version)); + version.setTitle(getString(R.string.application_name)); } } diff --git a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java index 4e9c03a83..2b68ffdcd 100644 --- a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java +++ b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java @@ -19,6 +19,7 @@ package com.cyanogenmod.trebuchet.preference; import android.content.Context; import android.content.SharedPreferences; +import com.cyanogenmod.trebuchet.LauncherApplication; import com.cyanogenmod.trebuchet.Workspace; import com.cyanogenmod.trebuchet.AppsCustomizePagedView; @@ -37,6 +38,34 @@ public final class PreferencesProvider { final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); return preferences.getInt("ui_homescreen_default_screen", def + 1) - 1; } + public static int getCellCountX(Context context, int def) { + final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); + String[] values = preferences.getString("ui_homescreen_grid", "0|" + def).split("\\|"); + try { + return Integer.parseInt(values[1]); + } catch (NumberFormatException e) { + return def; + } + } + public static int getCellCountY(Context context, int def) { + final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); + String[] values = preferences.getString("ui_homescreen_grid", def + "|0").split("\\|");; + try { + return Integer.parseInt(values[0]); + } catch (NumberFormatException e) { + return def; + } + } + public static int getScreenPaddingVertical(Context context) { + final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); + return (int)((float) preferences.getInt("ui_homescreen_screen_padding_vertical", 0) * 3.0f * + LauncherApplication.getScreenDensity()); + } + public static int getScreenPaddingHorizontal(Context context) { + final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); + return (int)((float) preferences.getInt("ui_homescreen_screen_padding_horizontal", 0) * 3.0f * + LauncherApplication.getScreenDensity()); + } public static boolean getShowSearchBar(Context context) { final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); return preferences.getBoolean("ui_homescreen_general_search", true); @@ -45,6 +74,10 @@ public final class PreferencesProvider { final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); return preferences.getBoolean("ui_homescreen_general_resize_any_widget", false); } + public static boolean getHideIconLabels(Context context) { + final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); + return preferences.getBoolean("ui_homescreen_general_hide_icon_labels", false); + } public static class Scrolling { public static boolean getScrollWallpaper(Context context) { final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); |