diff options
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/launcher3/DeviceProfile.java | 26 | ||||
-rw-r--r-- | src/com/android/launcher3/Folder.java | 16 | ||||
-rw-r--r-- | src/com/android/launcher3/HiddenFolderFragment.java | 41 | ||||
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 8 | ||||
-rw-r--r-- | src/com/android/launcher3/OverviewSettingsPanel.java | 5 | ||||
-rw-r--r-- | src/com/android/launcher3/Utilities.java | 9 | ||||
-rw-r--r-- | src/com/android/launcher3/WidgetPreviewLoader.java | 6 | ||||
-rw-r--r-- | src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java | 40 | ||||
-rw-r--r-- | src/com/android/launcher3/settings/SettingsProvider.java | 4 |
9 files changed, 124 insertions, 31 deletions
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 9bdfcf41b..d6c401d4f 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/Folder.java b/src/com/android/launcher3/Folder.java index e4f935cf3..7267f327c 100644 --- a/src/com/android/launcher3/Folder.java +++ b/src/com/android/launcher3/Folder.java @@ -299,7 +299,9 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList public void modifyProtectedApps(boolean protect) { ArrayList<ComponentName> components = new ArrayList<ComponentName>(); for (Pair<ComponentName, CharSequence> item : getComponents()) { - components.add(item.first); + if (item.first != null) { + components.add(item.first); + } } Intent intent = new Intent(); @@ -1490,6 +1492,18 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList return null; } + public ShortcutInfo getShortcutForPosition(int position) { + if (position < 0 || position >= mItemsInReadingOrder.size()) { + return null; + } + View v = mItemsInReadingOrder.get(position); + Object tag = v.getTag(); + if (tag instanceof ShortcutInfo) { + return (ShortcutInfo) tag; + } + return null; + } + public void getLocationInDragLayer(int[] loc) { mLauncher.getDragLayer().getLocationInDragLayer(this, loc); } diff --git a/src/com/android/launcher3/HiddenFolderFragment.java b/src/com/android/launcher3/HiddenFolderFragment.java index 94e1d2dbf..279448cdb 100644 --- a/src/com/android/launcher3/HiddenFolderFragment.java +++ b/src/com/android/launcher3/HiddenFolderFragment.java @@ -20,7 +20,9 @@ import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.widget.ArrayAdapter; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; @@ -115,6 +117,14 @@ public class HiddenFolderFragment extends Fragment { mListView = (ListView) v.findViewById(R.id.hidden_apps_list); mListView.setAdapter(mAppsAdapter); + // Apply insets + Launcher launcher = (Launcher) getActivity(); + LinearLayout.LayoutParams llp = + (LinearLayout.LayoutParams) mListView.getLayoutParams(); + llp.bottomMargin += ((FrameLayout.LayoutParams) launcher.getOverviewPanel() + .findViewById(R.id.settings_container).getLayoutParams()).bottomMargin; + mListView.setLayoutParams(llp); + return v; } @@ -128,16 +138,25 @@ public class HiddenFolderFragment extends Fragment { private ArrayList<AppEntry> loadApps(List<Pair<ComponentName, CharSequence>> items) { ArrayList<AppEntry> apps = new ArrayList<AppEntry>(); + int pos = 0; for (Pair<ComponentName, CharSequence> item : items) { - apps.add(new AppEntry(item.first, item.second)); + apps.add(new AppEntry(item.first, item.second, pos)); + pos++; } return apps; } private void removeComponentFromFolder(AppEntry app) { - mLauncher.mHiddenFolderIcon.getFolderInfo().remove( - mLauncher.mHiddenFolderIcon.getFolder() - .getShortcutForComponent(app.componentName)); + ShortcutInfo info; + if (app.componentName != null) { + info = mLauncher.mHiddenFolderIcon.getFolder() + .getShortcutForComponent(app.componentName); + } else { + // Shortcut does not have componentName, use position since it maps to + // reading order position in the folder + info = mLauncher.mHiddenFolderIcon.getFolder().getShortcutForPosition(app.position); + } + mLauncher.mHiddenFolderIcon.getFolderInfo().remove(info); mAppEntries.remove(app); mAppsAdapter.remove(app); @@ -227,7 +246,10 @@ public class HiddenFolderFragment extends Fragment { viewHolder.title.setText(app.title); - Drawable icon = mIcons.get(app.componentName.getPackageName()); + Drawable icon = null; + if (app.componentName != null) { + icon = mIcons.get(app.componentName.getPackageName()); + } viewHolder.icon.setImageDrawable(icon != null ? icon : mDefaultImg); viewHolder.remove.setOnClickListener(new OnClickListener() { @Override @@ -284,8 +306,9 @@ public class HiddenFolderFragment extends Fragment { protected Void doInBackground(AppEntry... apps) { for (AppEntry app : apps) { try { - if (mIcons.containsKey(app.componentName - .getPackageName())) { + // Widget icons do not have a + if (app.componentName == null || + mIcons.containsKey(app.componentName.getPackageName())) { continue; } Drawable icon = mPackageManager @@ -311,10 +334,12 @@ public class HiddenFolderFragment extends Fragment { private final class AppEntry { public final ComponentName componentName; public final CharSequence title; + public final int position; - public AppEntry(ComponentName component, CharSequence title) { + public AppEntry(ComponentName component, CharSequence title, int position) { this.componentName = component; this.title = title; + this.position = position; } } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index b1bafb189..5d857ce8c 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -2781,6 +2781,14 @@ public class Launcher extends Activity } else if (f2 != null) { mDynamicGridSizeFragment.setSize(); } else { + // if a user backs up twice very quickly from the widget add screen to the + // homescreen, the UI can get into a messed up state and mStateAnimation never + // completes or gets cancelled. Cancelling mStateAnimation here fixes this bug + if (mStateAnimation != null && mStateAnimation.isRunning()) { + mStateAnimation.cancel(); + mStateAnimation = null; + } + mWorkspace.exitOverviewMode(true); } } else if (mWorkspace.getOpenFolder() != null) { diff --git a/src/com/android/launcher3/OverviewSettingsPanel.java b/src/com/android/launcher3/OverviewSettingsPanel.java index acc700ad3..fef164383 100644 --- a/src/com/android/launcher3/OverviewSettingsPanel.java +++ b/src/com/android/launcher3/OverviewSettingsPanel.java @@ -209,8 +209,9 @@ public class OverviewSettingsPanel { frameAnimation.start(); if (mLauncher.updateGridIfNeeded()) { - if (mLauncher.getWorkspace().isInOverviewMode()) { - mLauncher.getWorkspace().showOutlines(); + Workspace workspace = mLauncher.getWorkspace(); + if (workspace.isInOverviewMode()) { + workspace.setChildrenOutlineAlpha(1.0f); mLauncher.mSearchDropTargetBar.hideSearchBar(false); } } diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index fcd4b8587..a594fd9f9 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/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java index d496c1c08..7fcb9f9ad 100644 --- a/src/com/android/launcher3/WidgetPreviewLoader.java +++ b/src/com/android/launcher3/WidgetPreviewLoader.java @@ -378,9 +378,13 @@ public class WidgetPreviewLoader { // Delete everything try { db.delete(CacheDb.TABLE_NAME, null, null); + } catch (SQLiteReadOnlyDatabaseException e) { + // After a DB update subsequent calls to getWritableDatabase seems always result in + // a SQLiteReadOnlyDatabaseException. Protect this code path for the time being to + // prevent FC + return; } catch (SQLiteDiskIOException e) { } catch (SQLiteCantOpenDatabaseException e) { - } catch (SQLiteReadOnlyDatabaseException e) { dumpOpenFiles(); throw e; } diff --git a/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java b/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java index 93b34b47e..9882c7625 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 4d09ed9ce..042053cef 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(); + } } |