summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaj Yengisetty <rajesh@cyngn.com>2015-03-17 22:59:06 (GMT)
committerRajesh Yengisetty <rajesh@cyngn.com>2015-03-17 23:01:20 (GMT)
commit5482c2f488e7ce312a85e7440b72865d1f2cf598 (patch)
treee833b7bf5af7febbf8ab45d8118c6f86b5500e0e
parentb4b01cdc995309f0b850c5de928d147b83e97fbd (diff)
downloadandroid_packages_apps_Trebuchet-5482c2f488e7ce312a85e7440b72865d1f2cf598.zip
android_packages_apps_Trebuchet-5482c2f488e7ce312a85e7440b72865d1f2cf598.tar.gz
android_packages_apps_Trebuchet-5482c2f488e7ce312a85e7440b72865d1f2cf598.tar.bz2
Trebuchet: disable search bar when there are no search activities
- On non-GMS devices, there are no Search apps which can support the search bar implementation. - Disable the search bar entirely if there is no search activity - Add a new utility method in SettingsProvider Change-Id: I3bcbceae4ceab308e4d797dad107e0a2ab72d673
-rw-r--r--res/values/cm_strings.xml3
-rw-r--r--src/com/android/launcher3/DeviceProfile.java26
-rw-r--r--src/com/android/launcher3/Utilities.java9
-rw-r--r--src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java40
-rw-r--r--src/com/android/launcher3/settings/SettingsProvider.java4
5 files changed, 63 insertions, 19 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 389605e..4169251 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -82,4 +82,7 @@
<string name="drawer_type_pager">Paged</string>
<string name="setting_state_disabled">DISABLED</string>
+
+ <!-- Search Manager doesn't exist -->
+ <string name="search_activity_not_found">A search activity could not be found!</string>
</resources>
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 9bdfcf4..d6c401d 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -315,8 +315,7 @@ public class DeviceProfile {
updateAvailableDimensions(context);
computeAllAppsButtonSize(context);
// Search Bar
- searchBarVisible = SettingsProvider.getBoolean(context, SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
- R.bool.preferences_interface_homescreen_search_default);
+ searchBarVisible = isSearchBarEnabled(context);
searchBarSpaceWidthPx = Math.min(searchBarSpaceMaxWidthPx, widthPx);
searchBarSpaceHeightPx = 2 * edgeMarginPx + (searchBarVisible ? searchBarHeightPx : 3 * edgeMarginPx);
}
@@ -780,8 +779,7 @@ public class DeviceProfile {
public void layout(Launcher launcher) {
// Update search bar for live settings
- searchBarVisible = SettingsProvider.getBoolean(launcher, SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
- R.bool.preferences_interface_homescreen_search_default);
+ searchBarVisible = isSearchBarEnabled(launcher);
searchBarSpaceHeightPx = 2 * edgeMarginPx + (searchBarVisible ? searchBarHeightPx : 3 * edgeMarginPx);
FrameLayout.LayoutParams lp;
Resources res = launcher.getResources();
@@ -960,4 +958,24 @@ public class DeviceProfile {
}
}
}
+
+ private boolean isSearchBarEnabled(Context context) {
+ boolean searchActivityExists = Utilities.searchActivityExists(context);
+
+ boolean isSearchEnabled = SettingsProvider.getBoolean(context,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
+ R.bool.preferences_interface_homescreen_search_default);
+
+ if (searchActivityExists) {
+ return isSearchEnabled;
+ } else {
+ if (isSearchEnabled) {
+ // Disable search bar
+ SettingsProvider.putBoolean(context,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH, false);
+ }
+
+ return false;
+ }
+ }
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index fcd4b85..a594fd9 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -17,6 +17,7 @@
package com.android.launcher3;
import android.app.Activity;
+import android.app.SearchManager;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
@@ -566,4 +567,12 @@ public final class Utilities {
float px = dp * (metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT);
return px;
}
+
+ public static boolean searchActivityExists(Context context) {
+ SearchManager searchManager =
+ (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
+ ComponentName activityName = searchManager.getGlobalSearchActivity();
+
+ return activityName != null;
+ }
}
diff --git a/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java b/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java
index 93b34b4..9882c76 100644
--- a/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java
+++ b/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java
@@ -16,12 +16,14 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
+import android.widget.Toast;
import com.android.launcher3.AppDrawerListAdapter;
import com.android.launcher3.AppsCustomizePagedView;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.OverviewSettingsPanel;
import com.android.launcher3.R;
+import com.android.launcher3.Utilities;
import com.android.launcher3.settings.SettingsProvider;
public class SettingsPinnedHeaderAdapter extends PinnedHeaderListAdapter {
@@ -285,9 +287,7 @@ public class SettingsPinnedHeaderAdapter extends PinnedHeaderListAdapter {
case OverviewSettingsPanel.HOME_SETTINGS_POSITION:
switch (position) {
case 0:
- onSettingsBooleanChanged(v,
- SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
- R.bool.preferences_interface_homescreen_search_default);
+ updateSearchBarVisibility(v);
mLauncher.setUpdateDynamicGrid();
break;
case 1:
@@ -354,17 +354,31 @@ public class SettingsPinnedHeaderAdapter extends PinnedHeaderListAdapter {
}
};
+ private void updateSearchBarVisibility(View v) {
+ boolean isSearchEnabled = SettingsProvider.getBoolean(mContext,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
+ R.bool.preferences_interface_homescreen_search_default);
+
+ if (!isSearchEnabled) {
+ if (!Utilities.searchActivityExists(mContext)) {
+ Toast.makeText(mContext, mContext.getString(R.string.search_activity_not_found),
+ Toast.LENGTH_SHORT).show();
+ return;
+ }
+ }
+
+ onSettingsBooleanChanged(v,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
+ R.bool.preferences_interface_homescreen_search_default);
+ }
+
private void onSettingsBooleanChanged(View v, String key, int res) {
boolean current = SettingsProvider.getBoolean(
mContext, key, res);
// Set new state
- SharedPreferences sharedPref = SettingsProvider
- .get(mContext);
- sharedPref.edit().putBoolean(key, !current).commit();
- sharedPref.edit()
- .putBoolean(SettingsProvider.SETTINGS_CHANGED, true)
- .commit();
+ SettingsProvider.putBoolean(mContext, key, !current);
+ SettingsProvider.putBoolean(mContext, SettingsProvider.SETTINGS_CHANGED, true);
String state = current ? mLauncher.getResources().getString(
R.string.setting_state_off) : mLauncher.getResources().getString(
@@ -377,12 +391,8 @@ public class SettingsPinnedHeaderAdapter extends PinnedHeaderListAdapter {
mContext, key, res);
// Set new state
- SharedPreferences sharedPref = SettingsProvider
- .get(mContext);
- sharedPref.edit().putBoolean(key, !current).commit();
- sharedPref.edit()
- .putBoolean(SettingsProvider.SETTINGS_CHANGED, true)
- .commit();
+ SettingsProvider.putBoolean(mContext, key, !current);
+ SettingsProvider.putBoolean(mContext, SettingsProvider.SETTINGS_CHANGED, true);
String state = current ? mLauncher.getResources().getString(
R.string.icon_labels_show) : mLauncher.getResources().getString(
diff --git a/src/com/android/launcher3/settings/SettingsProvider.java b/src/com/android/launcher3/settings/SettingsProvider.java
index 4d09ed9..042053c 100644
--- a/src/com/android/launcher3/settings/SettingsProvider.java
+++ b/src/com/android/launcher3/settings/SettingsProvider.java
@@ -88,4 +88,8 @@ public final class SettingsProvider {
public static void putInt(Context context, String key, int value) {
get(context).edit().putInt(key, value).commit();
}
+
+ public static void putBoolean(Context context, String key, boolean value) {
+ get(context).edit().putBoolean(key, value).commit();
+ }
}