From dd90bda0676e315363e576a71af3fb6fd2af70a5 Mon Sep 17 00:00:00 2001 From: nebkat Date: Wed, 30 Nov 2011 16:28:21 +0000 Subject: Preferences: Hide search bar preference + others - Restart Launcher on preferences changed - Implement "getCurrentOrientation()" Change-Id: I0728824ab994984c1dc798b61efa26b727ca3ea2 --- AndroidManifest.xml | 3 +- res/values/dimens.xml | 1 + res/values/strings.xml | 3 ++ res/xml/preferences.xml | 7 ++- src/com/android/launcher2/Launcher.java | 46 +++++++++++++++---- src/com/android/launcher2/SearchDropTargetBar.java | 33 ++++++++++---- src/com/android/launcher2/Workspace.java | 53 ++++++++++++++++++---- .../android/launcher2/preference/Preferences.java | 10 +++- .../launcher2/preference/PreferencesProvider.java | 10 +++- 9 files changed, 134 insertions(+), 32 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 193542b8f..a07b4453e 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -68,8 +68,7 @@ android:clearTaskOnLaunch="true" android:stateNotNeeded="true" android:theme="@style/Theme" - android:windowSoftInputMode="adjustPan" - android:screenOrientation="nosensor"> + android:windowSoftInputMode="adjustPan"> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 124cf16b2..f4ef20148 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -23,6 +23,7 @@ 34dp + 14dp 40dp 40dp 80dp diff --git a/res/values/strings.xml b/res/values/strings.xml index 41215fcd1..9ba4ff356 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -252,6 +252,9 @@ s --> Homescreen + General + Search Bar + Enable persistent search bar Drawer diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 6679751a3..46f0af5f3 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -20,7 +20,12 @@ - + + + diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index c940ac5fb..b7de4329c 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -92,7 +92,7 @@ import android.widget.Toast; import com.android.common.Search; import com.android.launcher.R; import com.android.launcher2.DropTarget.DragObject; -import com.android.launcher2.preference.Preferences; +import com.android.launcher2.preference.*; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -246,6 +246,9 @@ public final class Launcher extends Activity private BubbleTextView mWaitingForResume; + // Preferences + private boolean mShowSearchBar; + private Runnable mBuildLayersRunnable = new Runnable() { public void run() { if (mWorkspace != null) { @@ -279,6 +282,9 @@ public final class Launcher extends Activity mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); mAppWidgetHost.startListening(); + // Preferences + mShowSearchBar = PreferencesProvider.Interface.Homescreen.getShowSearchBar(this); + if (PROFILE_STARTUP) { android.os.Debug.startMethodTracing( Environment.getExternalStorageDirectory() + "/launcher"); @@ -345,7 +351,7 @@ public final class Launcher extends Activity mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); // On large interfaces, we want the screen to auto-rotate based on the current orientation - if (LauncherApplication.isScreenLarge() || Build.TYPE.contentEquals("eng")) { + if (LauncherApplication.isScreenLarge()) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } } @@ -548,6 +554,10 @@ public final class Launcher extends Activity protected void onResume() { super.onResume(); mPaused = false; + // Restart launcher when preferences are changed + if (preferencesChanged()) { + android.os.Process.killProcess(android.os.Process.myPid()); + } if (mRestoring || mOnResumeNeedsLoad) { mWorkspaceLoading = true; mModel.startLoader(this, true); @@ -746,6 +756,11 @@ public final class Launcher extends Activity // Get the search/delete bar mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar); + // Hide the search divider if we are hiding search bar + if (!mShowSearchBar && getCurrentOrientation() == Configuration.ORIENTATION_LANDSCAPE) { + ((View) findViewById(R.id.qsb_divider)).setVisibility(View.GONE); + } + // Setup AppsCustomize mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane); @@ -2551,10 +2566,14 @@ public final class Launcher extends Activity } } + public int getCurrentOrientation() { + return getResources().getConfiguration().orientation; + } + /** Maps the current orientation to an index for referencing orientation correct global icons */ private int getCurrentOrientationIndexForGlobalIcons() { // default - 0, landscape - 1 - switch (getResources().getConfiguration().orientation) { + switch (getCurrentOrientation()) { case Configuration.ORIENTATION_LANDSCAPE: return 1; default: @@ -3144,7 +3163,6 @@ public final class Launcher extends Activity } /* Cling related */ - private static final String PREFS_KEY = "com.android.launcher2.prefs"; private boolean isClingsEnabled() { // TEMPORARY: DISABLE CLINGS ON LARGE UI if (LauncherApplication.isScreenLarge()) return false; @@ -3183,7 +3201,7 @@ public final class Launcher extends Activity cling.setVisibility(View.GONE); cling.cleanup(); SharedPreferences prefs = - getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE); + getSharedPreferences(PreferencesProvider.PREFERENCES_KEY, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(flag, true); editor.commit(); @@ -3207,7 +3225,7 @@ public final class Launcher extends Activity public void showFirstRunWorkspaceCling() { // Enable the clings only if they have not been dismissed before SharedPreferences prefs = - getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE); + getSharedPreferences(PreferencesProvider.PREFERENCES_KEY, Context.MODE_PRIVATE); if (isClingsEnabled() && !prefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) { initCling(R.id.workspace_cling, null, false, 0); } else { @@ -3217,7 +3235,7 @@ public final class Launcher extends Activity public void showFirstRunAllAppsCling(int[] position) { // Enable the clings only if they have not been dismissed before SharedPreferences prefs = - getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE); + getSharedPreferences(PreferencesProvider.PREFERENCES_KEY, Context.MODE_PRIVATE); if (isClingsEnabled() && !prefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) { initCling(R.id.all_apps_cling, position, true, 0); } else { @@ -3227,7 +3245,7 @@ public final class Launcher extends Activity public Cling showFirstRunFoldersCling() { // Enable the clings only if they have not been dismissed before SharedPreferences prefs = - getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE); + getSharedPreferences(PreferencesProvider.PREFERENCES_KEY, Context.MODE_PRIVATE); Cling cling = null; if (isClingsEnabled() && !prefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) { cling = initCling(R.id.folder_cling, null, true, 0); @@ -3256,6 +3274,18 @@ public final class Launcher extends Activity dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); } + public boolean preferencesChanged() { + SharedPreferences prefs = + getSharedPreferences(PreferencesProvider.PREFERENCES_KEY, Context.MODE_PRIVATE); + boolean preferencesChanged = prefs.getBoolean(PreferencesProvider.PREFERENCES_CHANGED, false); + if (preferencesChanged) { + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean(PreferencesProvider.PREFERENCES_CHANGED, false); + editor.commit(); + } + return preferencesChanged; + } + /** * Prints out out state for debugging. */ diff --git a/src/com/android/launcher2/SearchDropTargetBar.java b/src/com/android/launcher2/SearchDropTargetBar.java index b4a9fc9c0..667c0629c 100644 --- a/src/com/android/launcher2/SearchDropTargetBar.java +++ b/src/com/android/launcher2/SearchDropTargetBar.java @@ -29,6 +29,7 @@ import android.view.animation.DecelerateInterpolator; import android.widget.FrameLayout; import com.android.launcher.R; +import com.android.launcher2.preference.PreferencesProvider; /* * Ths bar will manage the transition between the QSB search bar and the delete drop @@ -44,6 +45,8 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D private ObjectAnimator mQSBSearchBarFadeInAnim; private ObjectAnimator mQSBSearchBarFadeOutAnim; + private boolean mShowQSBSearchBar; + private boolean mIsSearchBarHidden; private View mQSBSearchBar; private View mDropTargetBar; @@ -60,6 +63,8 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D public SearchDropTargetBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + + mShowQSBSearchBar = PreferencesProvider.Interface.Homescreen.getShowSearchBar(context); } public void setup(Launcher launcher, DragController dragController) { @@ -89,6 +94,10 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D boolean enableDropDownDropTargets = getResources().getBoolean(R.bool.config_useDropTargetDownTransition); + if (!mShowQSBSearchBar) { + mQSBSearchBar.setVisibility(View.GONE); + } + // Create the various fade animations mDropTargetBar.setAlpha(0f); ObjectAnimator fadeInAlphaAnim = ObjectAnimator.ofFloat(mDropTargetBar, "alpha", 1f); @@ -153,20 +162,28 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D public void showSearchBar(boolean animated) { cancelAnimations(); if (animated) { - mQSBSearchBarFadeInAnim.start(); + if (mShowQSBSearchBar) { + mQSBSearchBarFadeInAnim.start(); + } } else { - mQSBSearchBar.setVisibility(View.VISIBLE); - mQSBSearchBar.setAlpha(1f); + if (mShowQSBSearchBar) { + mQSBSearchBar.setVisibility(View.VISIBLE); + mQSBSearchBar.setAlpha(1f); + } } mIsSearchBarHidden = false; } public void hideSearchBar(boolean animated) { cancelAnimations(); if (animated) { - mQSBSearchBarFadeOutAnim.start(); + if (mShowQSBSearchBar) { + mQSBSearchBarFadeOutAnim.start(); + } } else { - mQSBSearchBar.setVisibility(View.GONE); - mQSBSearchBar.setAlpha(0f); + if (mShowQSBSearchBar) { + mQSBSearchBar.setVisibility(View.GONE); + mQSBSearchBar.setAlpha(0f); + } } mIsSearchBarHidden = true; } @@ -191,7 +208,7 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D mDropTargetBar.buildLayer(); mDropTargetBarFadeOutAnim.cancel(); mDropTargetBarFadeInAnim.start(); - if (!mIsSearchBarHidden) { + if (!mIsSearchBarHidden && mShowQSBSearchBar) { mQSBSearchBarFadeInAnim.cancel(); mQSBSearchBarFadeOutAnim.start(); } @@ -207,7 +224,7 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D // Restore the QSB search bar, and animate out the drop target bar mDropTargetBarFadeInAnim.cancel(); mDropTargetBarFadeOutAnim.start(); - if (!mIsSearchBarHidden) { + if (!mIsSearchBarHidden && mShowQSBSearchBar) { mQSBSearchBarFadeOutAnim.cancel(); mQSBSearchBarFadeInAnim.start(); } diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 44d0d943f..e2c94ed91 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -33,6 +33,7 @@ import android.content.ClipDescription; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; @@ -65,6 +66,7 @@ import android.widget.Toast; import com.android.launcher.R; import com.android.launcher2.FolderIcon.FolderRingAnimator; import com.android.launcher2.InstallWidgetReceiver.WidgetMimeTypeHandlerData; +import com.android.launcher2.preference.PreferencesProvider; import java.util.ArrayList; import java.util.HashSet; @@ -236,6 +238,9 @@ public class Workspace extends SmoothPagedView private float[] mNewRotationYs; private float mTransitionProgress; + // Preferences + private boolean mShowSearchBar; + /** * Used to inflate the Workspace from XML. * @@ -307,6 +312,9 @@ public class Workspace extends SmoothPagedView LauncherModel.updateWorkspaceLayoutCells(cellCountX, cellCountY); setHapticFeedbackEnabled(false); + // Preferences + mShowSearchBar = PreferencesProvider.Interface.Homescreen.getShowSearchBar(context); + mLauncher = (Launcher) context; initWorkspace(); @@ -349,13 +357,22 @@ public class Workspace extends SmoothPagedView setWillNotDraw(false); setChildrenDrawnWithCacheEnabled(true); + final Resources res = getResources(); + try { - final Resources res = getResources(); mBackground = res.getDrawable(R.drawable.apps_customize_bg); } catch (Resources.NotFoundException e) { // In this case, we will skip drawing background protection } + if (!mShowSearchBar) { + int paddingTop = 0; + if (mLauncher.getCurrentOrientation() == Configuration.ORIENTATION_PORTRAIT) { + paddingTop = (int)res.getDimension(R.dimen.qsb_bar_hidden_inset); + } + setPadding(0, paddingTop, getPaddingRight(), getPaddingBottom()); + } + mChangeStateAnimationListener = new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { @@ -3462,19 +3479,27 @@ public class Workspace extends SmoothPagedView final View qsbDivider = (ImageView) (parent.findViewById(R.id.qsb_divider)); final View dockDivider = (ImageView) (parent.findViewById(R.id.dock_divider)); if (qsbDivider != null && dockDivider != null) { - qsbDivider.setVisibility(View.VISIBLE); + if (mShowSearchBar) { + qsbDivider.setVisibility(View.VISIBLE); + } dockDivider.setVisibility(View.VISIBLE); if (mDividerAnimator != null) { mDividerAnimator.cancel(); mDividerAnimator = null; } if (immediately) { - qsbDivider.setAlpha(1f); + if (mShowSearchBar) { + qsbDivider.setAlpha(1f); + } dockDivider.setAlpha(1f); } else { mDividerAnimator = new AnimatorSet(); - mDividerAnimator.playTogether(ObjectAnimator.ofFloat(qsbDivider, "alpha", 1f), - ObjectAnimator.ofFloat(dockDivider, "alpha", 1f)); + if (mShowSearchBar) { + mDividerAnimator.playTogether(ObjectAnimator.ofFloat(qsbDivider, "alpha", 1f), + ObjectAnimator.ofFloat(dockDivider, "alpha", 1f)); + } else { + mDividerAnimator.play(ObjectAnimator.ofFloat(dockDivider, "alpha", 1f)); + } mDividerAnimator.setDuration(sScrollIndicatorFadeInDuration); mDividerAnimator.start(); } @@ -3491,14 +3516,20 @@ public class Workspace extends SmoothPagedView mDividerAnimator = null; } if (immediately) { - qsbDivider.setVisibility(View.GONE); + if (mShowSearchBar) { + qsbDivider.setVisibility(View.GONE); + qsbDivider.setAlpha(0f); + } dockDivider.setVisibility(View.GONE); - qsbDivider.setAlpha(0f); dockDivider.setAlpha(0f); } else { mDividerAnimator = new AnimatorSet(); - mDividerAnimator.playTogether(ObjectAnimator.ofFloat(qsbDivider, "alpha", 0f), - ObjectAnimator.ofFloat(dockDivider, "alpha", 0f)); + if (mShowSearchBar) { + mDividerAnimator.playTogether(ObjectAnimator.ofFloat(qsbDivider, "alpha", 0f), + ObjectAnimator.ofFloat(dockDivider, "alpha", 0f)); + } else { + mDividerAnimator.play(ObjectAnimator.ofFloat(dockDivider, "alpha", 0f)); + } mDividerAnimator.addListener(new AnimatorListenerAdapter() { private boolean cancelled = false; @Override @@ -3508,7 +3539,9 @@ public class Workspace extends SmoothPagedView @Override public void onAnimationEnd(android.animation.Animator animation) { if (!cancelled) { - qsbDivider.setVisibility(View.GONE); + if (mShowSearchBar) { + qsbDivider.setVisibility(View.GONE); + } dockDivider.setVisibility(View.GONE); } } diff --git a/src/com/android/launcher2/preference/Preferences.java b/src/com/android/launcher2/preference/Preferences.java index 24337c5d7..8e6c27d5c 100644 --- a/src/com/android/launcher2/preference/Preferences.java +++ b/src/com/android/launcher2/preference/Preferences.java @@ -16,9 +16,11 @@ package com.android.launcher2.preference; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.Preference; import android.preference.PreferenceActivity; + import com.android.launcher.R; public class Preferences extends PreferenceActivity { @@ -29,5 +31,11 @@ public class Preferences extends PreferenceActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); + + SharedPreferences prefs = + getSharedPreferences(PreferencesProvider.PREFERENCES_KEY, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean(PreferencesProvider.PREFERENCES_CHANGED, true); + editor.commit(); } } diff --git a/src/com/android/launcher2/preference/PreferencesProvider.java b/src/com/android/launcher2/preference/PreferencesProvider.java index a53b3bd8d..0bb721349 100644 --- a/src/com/android/launcher2/preference/PreferencesProvider.java +++ b/src/com/android/launcher2/preference/PreferencesProvider.java @@ -4,10 +4,16 @@ import android.content.Context; import android.content.SharedPreferences; public final class PreferencesProvider { - private static final String PREFERENCES_FILE = "com.android.launcher2_preferences"; + public static final String PREFERENCES_KEY = "com.android.launcher_preferences"; + + public static final String PREFERENCES_CHANGED = "preferences_changed"; + public static class Interface { public static class Homescreen { - + public static boolean getShowSearchBar(Context context) { + final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); + return preferences.getBoolean("ui_homescreen_general_search", true); + } } public static class Drawer { -- cgit v1.2.3