summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaj Yengisetty <rajesh@cyngn.com>2015-03-17 22:59:06 (GMT)
committerniks255 <niks255@mail.ru>2017-01-06 22:41:05 (GMT)
commitfc63173d40be981cd6ac43b53cde852f1e8d5be0 (patch)
tree08c86e06c806a81e20f7181dcb781a72152ff9c1
parent877614ce90533ae4b267e3a78c50368b07fef2f4 (diff)
downloadandroid_packages_apps_Trebuchet-cm-11.0.zip
android_packages_apps_Trebuchet-cm-11.0.tar.gz
android_packages_apps_Trebuchet-cm-11.0.tar.bz2
Trebuchet: disable search bar when there are no search activitiescm-11.0
- 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-ru/cm_strings.xml1
-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.java10
-rw-r--r--src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java40
-rw-r--r--src/com/android/launcher3/settings/SettingsProvider.java4
6 files changed, 65 insertions, 19 deletions
diff --git a/res/values-ru/cm_strings.xml b/res/values-ru/cm_strings.xml
index 7078dc0..4f69d98 100644
--- a/res/values-ru/cm_strings.xml
+++ b/res/values-ru/cm_strings.xml
@@ -49,4 +49,5 @@
<string name="dialog_confirm">Подтвердить</string>
<string name="permission_label_read_extension_data">Запрос данных расширений DashClock</string>
<string name="permission_desc_read_extension_data">Приложение сможет считывать данные расширений DashClock.</string>
+ <string name="search_activity_not_found">Отсутсвует приложение поиска!</string>
</resources>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 3d98bf0..bd8cacd 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -86,4 +86,7 @@
<!-- Dashclock permission info (for CMHome) -->
<string name="permission_label_read_extension_data">request DashClock extension data</string>
<string name="permission_desc_read_extension_data">Allows the app to request DashClock extension data</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 ec6e47f..78ebb7f 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -294,8 +294,7 @@ public class DeviceProfile {
updateAvailableDimensions(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);
}
@@ -705,8 +704,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();
@@ -884,4 +882,24 @@ public class DeviceProfile {
// overviewMode.setLayoutParams(lp);
// }
}
+
+ 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 d1c5a0f..add60a7 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -17,7 +17,9 @@
package com.android.launcher3;
import android.app.Activity;
+import android.app.SearchManager;
import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
@@ -364,4 +366,12 @@ public final class Utilities {
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
return um.getUserInfo(um.getUserHandle()).isRestricted();
}
+
+ 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 eca6492..a61bab6 100644
--- a/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java
+++ b/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java
@@ -14,11 +14,13 @@ 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.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 {
@@ -279,9 +281,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:
@@ -351,17 +351,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(
@@ -374,12 +388,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 8cde925..2ad45ef 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();
+ }
}