From bd9793a7c059a616745f636128c665860d78ed8d Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Mon, 29 Apr 2013 00:59:24 +0200 Subject: Trebuchet: Lock homescreen Allow lock shortcuts and folders positions in the workspace, hotseat and apps and widgets drawer. When is enabled the system avoids to move any shortcut or folder, change its names and access to widgets. Patchset 2: Fixed typo Change-Id: I832da526cf1eb32752218656a7c2dafc53010236 JIRA: CYAN-686 Issue: https://jira.cyanogenmod.org/browse/CYAN-686 Signed-off-by: Jorge Ruesga --- src/com/cyanogenmod/trebuchet/Folder.java | 10 ++++++- src/com/cyanogenmod/trebuchet/Launcher.java | 32 ++++++++++++++++++---- .../trebuchet/PagedViewWithDraggableItems.java | 11 +++++++- .../trebuchet/preference/PreferencesProvider.java | 3 ++ 4 files changed, 49 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/com/cyanogenmod/trebuchet/Folder.java b/src/com/cyanogenmod/trebuchet/Folder.java index cdb4dd345..28a9aefdf 100644 --- a/src/com/cyanogenmod/trebuchet/Folder.java +++ b/src/com/cyanogenmod/trebuchet/Folder.java @@ -158,7 +158,12 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false); mFolderName = (FolderEditText) findViewById(R.id.folder_name); mFolderName.setFolder(this); - mFolderName.setOnFocusChangeListener(this); + if (mLauncher.getLockWorkspace()) { + mFolderName.setKeyListener(null); + mFolderName.setFocusable(false); + } else { + mFolderName.setOnFocusChangeListener(this); + } // We find out how tall the text view wants to be (it is set to wrap_content), so that // we can allocate the appropriate amount of space for it. @@ -211,6 +216,9 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList } public boolean onLongClick(View v) { + // Only if workspace is not locked + if (mLauncher.getLockWorkspace()) return false; + // Return if global dragging is not enabled if (!mLauncher.isDraggingEnabled()) return true; diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java index f90a1eb7e..c82c8fe2d 100644 --- a/src/com/cyanogenmod/trebuchet/Launcher.java +++ b/src/com/cyanogenmod/trebuchet/Launcher.java @@ -134,7 +134,8 @@ public final class Launcher extends Activity private static final int MENU_GROUP_WALLPAPER = 1; private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1; - private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1; + private static final int MENU_LOCK_WORKSPACE = MENU_WALLPAPER_SETTINGS + 1; + private static final int MENU_MANAGE_APPS = MENU_LOCK_WORKSPACE + 1; private static final int MENU_PREFERENCES = MENU_MANAGE_APPS + 1; private static final int MENU_SYSTEM_SETTINGS = MENU_PREFERENCES + 1; private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1; @@ -319,6 +320,7 @@ public final class Launcher extends Activity private boolean mShowDockDivider; private boolean mHideIconLabels; private boolean mAutoRotate; + private boolean mLockWorkspace; private boolean mFullscreenMode; private boolean mWallpaperVisible; @@ -403,6 +405,7 @@ public final class Launcher extends Activity mShowDockDivider = PreferencesProvider.Interface.Dock.getShowDivider() && mShowHotseat; mHideIconLabels = PreferencesProvider.Interface.Homescreen.getHideIconLabels(); mAutoRotate = PreferencesProvider.Interface.General.getAutoRotate(getResources().getBoolean(R.bool.allow_rotation)); + mLockWorkspace = PreferencesProvider.Interface.General.getLockWorkspace(getResources().getBoolean(R.bool.lock_workspace)); mFullscreenMode = PreferencesProvider.Interface.General.getFullscreenMode(); if (PROFILE_STARTUP) { @@ -1775,6 +1778,8 @@ public final class Launcher extends Activity menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) .setIcon(android.R.drawable.ic_menu_gallery) .setAlphabeticShortcut('W'); + menu.add(0, MENU_LOCK_WORKSPACE, 0, !mLockWorkspace ? R.string.menu_lock_workspace : R.string.menu_unlock_workspace) + .setAlphabeticShortcut('L'); menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps) .setIcon(android.R.drawable.ic_menu_manage) .setIntent(manageApps) @@ -1808,6 +1813,8 @@ public final class Launcher extends Activity boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE); menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible); + menu.findItem(MENU_LOCK_WORKSPACE).setTitle(!mLockWorkspace ? R.string.menu_lock_workspace : R.string.menu_unlock_workspace); + Intent launcherIntent = new Intent(Intent.ACTION_MAIN); launcherIntent.addCategory(Intent.CATEGORY_HOME); launcherIntent.addCategory(Intent.CATEGORY_DEFAULT); @@ -1823,11 +1830,18 @@ public final class Launcher extends Activity @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case MENU_WALLPAPER_SETTINGS: - startWallpaper(); - return true; + case MENU_WALLPAPER_SETTINGS: + startWallpaper(); + return true; + case MENU_LOCK_WORKSPACE: + mLockWorkspace = !mLockWorkspace; + SharedPreferences.Editor editor = mSharedPrefs.edit(); + editor.putBoolean("ui_general_lock_workspace", mLockWorkspace); + editor.commit(); + return true; } + return super.onOptionsItemSelected(item); } @@ -2548,7 +2562,11 @@ public final class Launcher extends Activity startWallpaper(); } else { if (!(itemUnderLongClick instanceof Folder)) { - // User long pressed on an item + // User long pressed on an item (only if workspace is not locked) + if (mLockWorkspace) { + Toast.makeText(this, getString(R.string.workspace_locked), Toast.LENGTH_SHORT).show(); + return false; + } mWorkspace.startDrag(longClickCellInfo); } } @@ -2567,6 +2585,10 @@ public final class Launcher extends Activity return mSearchDropTargetBar; } + boolean getLockWorkspace() { + return mLockWorkspace; + } + /** * Returns the CellLayout of the specified container at the specified screen. */ diff --git a/src/com/cyanogenmod/trebuchet/PagedViewWithDraggableItems.java b/src/com/cyanogenmod/trebuchet/PagedViewWithDraggableItems.java index 1f0befa6c..1674060ff 100644 --- a/src/com/cyanogenmod/trebuchet/PagedViewWithDraggableItems.java +++ b/src/com/cyanogenmod/trebuchet/PagedViewWithDraggableItems.java @@ -20,6 +20,7 @@ import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; +import android.widget.Toast; /* Class that does most of the work of enabling dragging items out of a PagedView by performing a @@ -73,7 +74,10 @@ public abstract class PagedViewWithDraggableItems extends PagedView break; case MotionEvent.ACTION_MOVE: if (mTouchState != TOUCH_STATE_SCROLLING && !mIsDragging && mIsDragEnabled) { - determineDraggingStart(ev); + // Only if workspace is not locked + if (!mLauncher.getLockWorkspace()) { + determineDraggingStart(ev); + } } break; } @@ -100,6 +104,11 @@ public abstract class PagedViewWithDraggableItems extends PagedView @Override public boolean onLongClick(View v) { + // Only if workspace is not locked + if (mLauncher.getLockWorkspace()) { + Toast.makeText(mLauncher, mLauncher.getString(R.string.workspace_locked), Toast.LENGTH_SHORT).show(); + return false; + } // Return early if this is not initiated from a touch if (!v.isInTouchMode()) return false; // Return early if we are still animating the pages diff --git a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java index ca034917d..c4039ffa9 100644 --- a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java +++ b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java @@ -204,6 +204,9 @@ public final class PreferencesProvider { public static boolean getAutoRotate(boolean def) { return getBoolean("ui_general_orientation", def); } + public static boolean getLockWorkspace(boolean def) { + return getBoolean("ui_general_lock_workspace", def); + } public static boolean getFullscreenMode() { return getBoolean("ui_general_fullscreen", false); } -- cgit v1.2.3