diff options
Diffstat (limited to 'src/com/android/launcher3/Launcher.java')
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 478 |
1 files changed, 48 insertions, 430 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 07e35a870..a5c80a430 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -75,7 +75,6 @@ import android.os.StrictMode; import android.os.SystemClock; import android.os.UserHandle; import android.preference.PreferenceManager; -import android.speech.RecognizerIntent; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.Selection; @@ -240,15 +239,12 @@ public class Launcher extends Activity static final String ACTION_FIRST_LOAD_COMPLETE = "com.android.launcher3.action.FIRST_LOAD_COMPLETE"; - private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; - private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME = - "com.android.launcher.toolbar_search_icon"; - private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME = - "com.android.launcher.toolbar_voice_search_icon"; - public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem"; public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false; + private static final String QSB_WIDGET_ID = "qsb_widget_id"; + private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider"; + public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data"; @Override @@ -328,7 +324,7 @@ public class Launcher extends Activity private AppsCustomizeTabHost mAppsCustomizeTabHost; private AppsCustomizePagedView mAppsCustomizeContent; private boolean mAutoAdvanceRunning = false; - private View mQsb; + private AppWidgetHostView mQsb; private Bundle mSavedState; // We set the state in both onCreate and then onNewIntent in some cases, which causes both @@ -381,10 +377,6 @@ public class Launcher extends Activity // match the sensor state. private final int mRestoreScreenOrientationDelay = 500; - // External icons saved in case of resource changes, orientation, etc. - private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2]; - private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2]; - private Drawable mWorkspaceBackgroundDrawable; private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>(); @@ -573,8 +565,6 @@ public class Launcher extends Activity IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); registerReceiver(mCloseSystemDialogsReceiver, filter); - updateGlobalIcons(); - // On large interfaces, we want the screen to auto-rotate based on the current orientation unlockScreenOrientation(true); @@ -701,34 +691,6 @@ public class Launcher extends Activity } } - private void updateGlobalIcons() { - boolean searchVisible = false; - boolean voiceVisible = false; - if (mSearchWidgetId >= 0) { - // we're displaying a search widget - searchVisible = true; - voiceVisible = false; - } else { - // If we have a saved version of these external icons, we load them up immediately - int coi = getCurrentOrientationIndexForGlobalIcons(); - if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) { - searchVisible = updateGlobalSearchIcon(); - voiceVisible = updateVoiceSearchIcon(searchVisible); - } - if (sGlobalSearchIcon[coi] != null) { - updateGlobalSearchIcon(sGlobalSearchIcon[coi]); - searchVisible = true; - } - if (sVoiceSearchIcon[coi] != null) { - updateVoiceSearchIcon(sVoiceSearchIcon[coi]); - voiceVisible = true; - } - } - if (mSearchDropTargetBar != null) { - mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); - } - } - private void checkForLocaleChange() { if (sLocaleConfiguration == null) { new AsyncTask<Void, Void, LocaleConfiguration>() { @@ -1233,12 +1195,6 @@ public class Launcher extends Activity // Process any items that were added while Launcher was away. InstallShortcutReceiver.disableAndFlushInstallQueue(this); - // Update the voice search button proxy - updateVoiceButtonProxyVisible(false); - - // Again, as with the above scenario, it's possible that one or more of the global icons - // were updated in the wrong orientation. - updateGlobalIcons(); if (DEBUG_RESUME_TIME) { Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); } @@ -1796,6 +1752,7 @@ public class Launcher extends Activity dragController.addDropTarget(mWorkspace); if (mSearchDropTargetBar != null) { mSearchDropTargetBar.setup(this, dragController); + mSearchDropTargetBar.setQsbSearchBar(getQsbBar()); } if (getResources().getBoolean(R.bool.debug_memory_enabled)) { @@ -3080,50 +3037,6 @@ public class Launcher extends Activity } /** - * Event handler for the search button - * - * @param v The view that was clicked. - */ - public void onClickSearchButton(View v) { - v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); - - onSearchRequested(); - } - - /** - * Event handler for the voice button - * - * @param v The view that was clicked. - */ - public void onClickVoiceButton(View v) { - v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); - - startVoice(); - } - - public void startVoice() { - if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { - mLauncherCallbacks.startVoice(); - return; - } - try { - final SearchManager searchManager = - (SearchManager) getSystemService(Context.SEARCH_SERVICE); - ComponentName activityName = searchManager.getGlobalSearchActivity(); - Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - if (activityName != null) { - intent.setPackage(activityName.getPackageName()); - } - startActivity(null, intent, "onClickVoiceButton"); - } catch (ActivityNotFoundException e) { - Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivitySafely(null, intent, "onClickVoiceButton"); - } - } - - /** * Event handler for the "grid" button that appears on the home screen, which * enters all apps mode. * @@ -3436,10 +3349,8 @@ public class Launcher extends Activity } void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) { - String packageName = componentName.getPackageName(); try { LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this); - UserManagerCompat userManager = UserManagerCompat.getInstance(this); launcherApps.showAppDetailsForProfile(componentName, user); } catch (SecurityException e) { Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); @@ -3948,8 +3859,6 @@ public class Launcher extends Activity : toView.findViewById(R.id.app_drawer_view); final View revealView = toView.findViewById(R.id.fake_page); - final float initialPanelAlpha = 1f; - final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets; if (isWidgetTray) { revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark)); @@ -4649,137 +4558,8 @@ public class Launcher extends Activity // TODO } - /** - * Hides the hotseat area. - */ - void hideHotseat(boolean animated) { - if (!LauncherAppState.getInstance().isScreenLarge()) { - if (animated) { - if (mHotseat.getAlpha() != 0f) { - int duration = 0; - if (mSearchDropTargetBar != null) { - duration = mSearchDropTargetBar.getTransitionOutDuration(); - } - mHotseat.animate().alpha(0f).setDuration(duration); - } - } else { - mHotseat.setAlpha(0f); - } - } - } - - /** - * Add an item from all apps or customize onto the given workspace screen. - * If layout is null, add to the current screen. - */ - void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) { - if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) { - showOutOfSpaceMessage(isHotseatLayout(layout)); - } - } - - /** Maps the current orientation to an index for referencing orientation correct global icons */ - private int getCurrentOrientationIndexForGlobalIcons() { - // default - 0, landscape - 1 - switch (getResources().getConfiguration().orientation) { - case Configuration.ORIENTATION_LANDSCAPE: - return 1; - default: - return 0; - } - } - - private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) { - try { - PackageManager packageManager = getPackageManager(); - // Look for the toolbar icon specified in the activity meta-data - Bundle metaData = packageManager.getActivityInfo( - activityName, PackageManager.GET_META_DATA).metaData; - if (metaData != null) { - int iconResId = metaData.getInt(resourceName); - if (iconResId != 0) { - Resources res = packageManager.getResourcesForActivity(activityName); - return res.getDrawable(iconResId); - } - } - } catch (NameNotFoundException e) { - // This can happen if the activity defines an invalid drawable - Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() + - " not found", e); - } catch (Resources.NotFoundException nfe) { - // This can happen if the activity defines an invalid drawable - Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(), - nfe); - } - return null; - } - - // if successful in getting icon, return it; otherwise, set button to use default drawable - private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity( - int buttonId, ComponentName activityName, int fallbackDrawableId, - String toolbarResourceName) { - Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); - Resources r = getResources(); - int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); - int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); - - TextView button = (TextView) findViewById(buttonId); - // If we were unable to find the icon via the meta-data, use a generic one - if (toolbarIcon == null) { - toolbarIcon = r.getDrawable(fallbackDrawableId); - toolbarIcon.setBounds(0, 0, w, h); - if (button != null) { - button.setCompoundDrawables(toolbarIcon, null, null, null); - } - return null; - } else { - toolbarIcon.setBounds(0, 0, w, h); - if (button != null) { - button.setCompoundDrawables(toolbarIcon, null, null, null); - } - return toolbarIcon.getConstantState(); - } - } - - // if successful in getting icon, return it; otherwise, set button to use default drawable - private Drawable.ConstantState updateButtonWithIconFromExternalActivity( - int buttonId, ComponentName activityName, int fallbackDrawableId, - String toolbarResourceName) { - ImageView button = (ImageView) findViewById(buttonId); - Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); - - if (button != null) { - // If we were unable to find the icon via the meta-data, use a - // generic one - if (toolbarIcon == null) { - button.setImageResource(fallbackDrawableId); - } else { - button.setImageDrawable(toolbarIcon); - } - } - - return toolbarIcon != null ? toolbarIcon.getConstantState() : null; - - } - - private void updateTextButtonWithDrawable(int buttonId, Drawable d) { - TextView button = (TextView) findViewById(buttonId); - button.setCompoundDrawables(d, null, null, null); - } - - private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { - ImageView button = (ImageView) findViewById(buttonId); - button.setImageDrawable(d.newDrawable(getResources())); - } - - private void invalidatePressedFocusedStates(View container, View button) { - if (container instanceof HolographicLinearLayout) { - HolographicLinearLayout layout = (HolographicLinearLayout) container; - layout.invalidatePressedFocusedStates(); - } else if (button instanceof HolographicImageView) { - HolographicImageView view = (HolographicImageView) button; - view.invalidatePressedFocusedStates(); - } + protected void disableVoiceButtonProxy(boolean disable) { + // NO-OP } /** @@ -4807,217 +4587,53 @@ public class Launcher extends Activity return null; } - public Pair<Integer, AppWidgetProviderInfo> bindSearchAppWidget(AppWidgetHost host) { - if (mAppWidgetManager == null) return null; - - if (!mGrid.isPhone()) { - // tablets rotate and widget doesn't have a vertical layout - return null; - } - - // Find the first widget from the same package as the global assist activity - AppWidgetProviderInfo searchWidgetInfo = resolveSearchAppWidget(); - - // Return early if there is no search widget - if (searchWidgetInfo == null) return null; - - // Allocate a new widget id and try and bind the app widget (if that fails, then just skip) - int searchWidgetId = host.allocateAppWidgetId(); - Bundle opts = new Bundle(); - opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, - AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN); - if (!AppWidgetManager.getInstance(this).bindAppWidgetIdIfAllowed(searchWidgetId, - searchWidgetInfo.provider, opts)) { - host.deleteAppWidgetId(searchWidgetId); - return null; - } - return new Pair<Integer, AppWidgetProviderInfo>(searchWidgetId, searchWidgetInfo); - } - public View getQsbBar() { if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { return mLauncherCallbacks.getQsbBar(); } - if (mQsb == null) { - // bind search widget if possible - if (mSearchWidgetId >= 0) { - mSearchWidgetInfo - = AppWidgetManager.getInstance(this).getAppWidgetInfo(mSearchWidgetId); - if (mSearchWidgetInfo == null) { - mAppWidgetHost.deleteAppWidgetId(mSearchWidgetId); - mSearchWidgetId = -1; - } + AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this); + if (searchProvider == null) { + return null; } - - if (mSearchWidgetId < 0) { - final Pair<Integer, AppWidgetProviderInfo> newWidget - = bindSearchAppWidget(mAppWidgetHost); - if (newWidget != null) { - mSearchWidgetInfo = newWidget.second; - mSearchWidgetId = newWidget.first; - } else { - mSearchWidgetId = -1; + Bundle opts = new Bundle(); + opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, + AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); + SharedPreferences sp = getSharedPreferences( + LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE); + int widgetId = sp.getInt(QSB_WIDGET_ID, -1); + if (!searchProvider.provider.flattenToString().equals( + sp.getString(QSB_WIDGET_PROVIDER, null)) + || (widgetId == -1) + || !mAppWidgetManager.getAppWidgetInfo(widgetId).provider + .equals(searchProvider.provider)) { + // A valid widget is not already bound. + if (widgetId > -1) { + mAppWidgetHost.deleteAppWidgetId(widgetId); + widgetId = -1; + } + // Try to bind a new widget + widgetId = mAppWidgetHost.allocateAppWidgetId(); + if (!AppWidgetManagerCompat.getInstance(this) + .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) { + mAppWidgetHost.deleteAppWidgetId(widgetId); + widgetId = -1; } + sp.edit() + .putInt(QSB_WIDGET_ID, widgetId) + .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString()) + .commit(); } - - if (mSearchWidgetId < 0) { - // no widget, fall back to views - mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false); - } else { - final AppWidgetHostView searchWidget - = mAppWidgetHost.createView(this, mSearchWidgetId, mSearchWidgetInfo); - searchWidget.setAppWidget(mSearchWidgetId, mSearchWidgetInfo); - searchWidget.setPadding(0, 0, 0, 0); - - Bundle opts = new Bundle(); - opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, - AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN); - searchWidget.updateAppWidgetOptions(opts); - searchWidget.setVisibility(View.VISIBLE); - - mQsb = searchWidget; - mSearchViewHost = searchWidget; + if (widgetId != -1) { + mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider); + mQsb.updateAppWidgetOptions(opts); + mQsb.setPadding(0, 0, 0, 0); + mSearchDropTargetBar.addView(mQsb); } - - mSearchDropTargetBar.addView(mQsb); } return mQsb; } - protected boolean updateGlobalSearchIcon() { - if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { - return true; - } - if (mSearchWidgetId >= 0) return false; - final View searchButtonContainer = findViewById(R.id.search_button_container); - final ImageView searchButton = (ImageView) findViewById(R.id.search_button); - final View voiceButtonContainer = findViewById(R.id.voice_button_container); - final View voiceButton = findViewById(R.id.voice_button); - - final SearchManager searchManager = - (SearchManager) getSystemService(Context.SEARCH_SERVICE); - ComponentName activityName = searchManager.getGlobalSearchActivity(); - if (activityName != null) { - int coi = getCurrentOrientationIndexForGlobalIcons(); - sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( - R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, - TOOLBAR_SEARCH_ICON_METADATA_NAME); - if (sGlobalSearchIcon[coi] == null) { - sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( - R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, - TOOLBAR_ICON_METADATA_NAME); - } - - if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE); - searchButton.setVisibility(View.VISIBLE); - invalidatePressedFocusedStates(searchButtonContainer, searchButton); - return true; - } else { - // We disable both search and voice search when there is no global search provider - if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE); - if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); - if (searchButton != null) searchButton.setVisibility(View.GONE); - if (voiceButton != null) voiceButton.setVisibility(View.GONE); - mShouldShowVoice = false; - updateVoiceButtonProxyVisible(true); - return false; - } - } - - protected void updateGlobalSearchIcon(Drawable.ConstantState d) { - if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) return; - if (mSearchWidgetId >= 0) return; - final View searchButtonContainer = findViewById(R.id.search_button_container); - final View searchButton = (ImageView) findViewById(R.id.search_button); - updateButtonWithDrawable(R.id.search_button, d); - invalidatePressedFocusedStates(searchButtonContainer, searchButton); - } - - protected boolean updateVoiceSearchIcon(boolean searchVisible) { - if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { - return true; - } - if (mSearchWidgetId >= 0) return false; - final View voiceButtonContainer = findViewById(R.id.voice_button_container); - final View voiceButton = findViewById(R.id.voice_button); - - // We only show/update the voice search icon if the search icon is enabled as well - final SearchManager searchManager = - (SearchManager) getSystemService(Context.SEARCH_SERVICE); - ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); - - ComponentName activityName = null; - if (globalSearchActivity != null) { - // Check if the global search activity handles voice search - Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); - intent.setPackage(globalSearchActivity.getPackageName()); - activityName = intent.resolveActivity(getPackageManager()); - } - - if (activityName == null) { - // Fallback: check if an activity other than the global search activity - // resolves this - Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); - activityName = intent.resolveActivity(getPackageManager()); - } - if (searchVisible && activityName != null) { - int coi = getCurrentOrientationIndexForGlobalIcons(); - sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( - R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, - TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME); - if (sVoiceSearchIcon[coi] == null) { - sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( - R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, - TOOLBAR_ICON_METADATA_NAME); - } - if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); - voiceButton.setVisibility(View.VISIBLE); - updateVoiceButtonProxyVisible(false); - invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); - mShouldShowVoice = true; - return true; - } else { - if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); - if (voiceButton != null) voiceButton.setVisibility(View.GONE); - mShouldShowVoice = false; - updateVoiceButtonProxyVisible(true); - return false; - } - } - - protected void updateVoiceSearchIcon(Drawable.ConstantState d) { - if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { - return; - } - - final View voiceButtonContainer = findViewById(R.id.voice_button_container); - final View voiceButton = findViewById(R.id.voice_button); - updateButtonWithDrawable(R.id.voice_button, d); - invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); - } - - public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) { - if (mLauncherCallbacks != null) { - forceDisableVoiceButtonProxy |= mLauncherCallbacks.forceDisableVoiceButtonProxy(); - } - final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); - if (voiceButtonProxy != null) { - boolean visible = !forceDisableVoiceButtonProxy && - mWorkspace.shouldVoiceButtonProxyBeVisible() && mShouldShowVoice; - voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE); - voiceButtonProxy.bringToFront(); - } - } - - /** - * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy - * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns. - */ - public void disableVoiceButtonProxy(boolean disabled) { - updateVoiceButtonProxyVisible(disabled); - } - @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { final boolean result = super.dispatchPopulateAccessibilityEvent(event); @@ -5621,13 +5237,15 @@ public class Launcher extends Activity getDeviceProfile().getSearchBarBounds(); } - @Override public void bindSearchablesChanged() { - boolean searchVisible = updateGlobalSearchIcon(); - boolean voiceVisible = updateVoiceSearchIcon(searchVisible); - if (mSearchDropTargetBar != null) { - mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); + if (mSearchDropTargetBar == null) { + return; + } + if (mQsb != null) { + mSearchDropTargetBar.removeView(mQsb); + mQsb = null; } + mSearchDropTargetBar.setQsbSearchBar(getQsbBar()); } /** |