Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher3; |
| 18 | |
| 19 | import android.accounts.Account; |
| 20 | import android.accounts.AccountManager; |
| 21 | import android.animation.Animator; |
| 22 | import android.animation.AnimatorListenerAdapter; |
| 23 | import android.app.ActivityManager; |
Winson Chung | 69dffdb | 2014-04-04 16:53:17 -0700 | [diff] [blame] | 24 | import android.content.ComponentName; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.SharedPreferences; |
Winson Chung | 69dffdb | 2014-04-04 16:53:17 -0700 | [diff] [blame] | 27 | import android.content.pm.ApplicationInfo; |
| 28 | import android.content.pm.PackageManager; |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 29 | import android.graphics.Rect; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 30 | import android.os.Bundle; |
| 31 | import android.os.UserManager; |
| 32 | import android.view.LayoutInflater; |
| 33 | import android.view.View; |
| 34 | import android.view.ViewGroup; |
| 35 | import android.view.accessibility.AccessibilityManager; |
| 36 | import android.widget.TextView; |
| 37 | |
| 38 | class LauncherClings { |
| 39 | private static final String FIRST_RUN_CLING_DISMISSED_KEY = "cling_gel.first_run.dismissed"; |
| 40 | private static final String MIGRATION_CLING_DISMISSED_KEY = "cling_gel.migration.dismissed"; |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 41 | private static final String MIGRATION_WORKSPACE_CLING_DISMISSED_KEY = |
| 42 | "cling_gel.migration_workspace.dismissed"; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 43 | private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling_gel.workspace.dismissed"; |
| 44 | private static final String FOLDER_CLING_DISMISSED_KEY = "cling_gel.folder.dismissed"; |
| 45 | |
| 46 | private static final boolean DISABLE_CLINGS = false; |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 47 | |
| 48 | private static final int SHOW_CLING_DURATION = 250; |
| 49 | private static final int DISMISS_CLING_DURATION = 200; |
| 50 | |
| 51 | private Launcher mLauncher; |
| 52 | private LayoutInflater mInflater; |
| 53 | private HideFromAccessibilityHelper mHideFromAccessibilityHelper |
| 54 | = new HideFromAccessibilityHelper(); |
| 55 | |
| 56 | /** Ctor */ |
| 57 | public LauncherClings(Launcher launcher) { |
| 58 | mLauncher = launcher; |
| 59 | mInflater = mLauncher.getLayoutInflater(); |
| 60 | } |
| 61 | |
| 62 | /** Initializes a cling */ |
| 63 | private Cling initCling(int clingId, int scrimId, boolean animate, |
| 64 | boolean dimNavBarVisibilty) { |
| 65 | Cling cling = (Cling) mLauncher.findViewById(clingId); |
| 66 | View scrim = null; |
| 67 | if (scrimId > 0) { |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 68 | scrim = mLauncher.findViewById(scrimId); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 69 | } |
| 70 | if (cling != null) { |
| 71 | cling.init(mLauncher, scrim); |
| 72 | cling.show(animate, SHOW_CLING_DURATION); |
| 73 | |
| 74 | if (dimNavBarVisibilty) { |
| 75 | cling.setSystemUiVisibility(cling.getSystemUiVisibility() | |
| 76 | View.SYSTEM_UI_FLAG_LOW_PROFILE); |
| 77 | } |
| 78 | } |
| 79 | return cling; |
| 80 | } |
| 81 | |
| 82 | /** Returns whether the clings are enabled or should be shown */ |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 83 | private boolean areClingsEnabled() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 84 | if (DISABLE_CLINGS) { |
| 85 | return false; |
| 86 | } |
| 87 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 88 | // disable clings when running in a test harness |
| 89 | if(ActivityManager.isRunningInTestHarness()) return false; |
| 90 | |
| 91 | // Disable clings for accessibility when explore by touch is enabled |
| 92 | final AccessibilityManager a11yManager = (AccessibilityManager) mLauncher.getSystemService( |
| 93 | Launcher.ACCESSIBILITY_SERVICE); |
| 94 | if (a11yManager.isTouchExplorationEnabled()) { |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | // Restricted secondary users (child mode) will potentially have very few apps |
| 99 | // seeded when they start up for the first time. Clings won't work well with that |
| 100 | boolean supportsLimitedUsers = |
| 101 | android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2; |
| 102 | Account[] accounts = AccountManager.get(mLauncher).getAccounts(); |
| 103 | if (supportsLimitedUsers && accounts.length == 0) { |
| 104 | UserManager um = (UserManager) mLauncher.getSystemService(Context.USER_SERVICE); |
| 105 | Bundle restrictions = um.getUserRestrictions(); |
| 106 | if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) { |
| 107 | return false; |
| 108 | } |
| 109 | } |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | /** Returns whether the folder cling is visible. */ |
| 114 | public boolean isFolderClingVisible() { |
| 115 | Cling cling = (Cling) mLauncher.findViewById(R.id.folder_cling); |
| 116 | if (cling != null) { |
| 117 | return cling.getVisibility() == View.VISIBLE; |
| 118 | } |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | private boolean skipCustomClingIfNoAccounts() { |
| 123 | Cling cling = (Cling) mLauncher.findViewById(R.id.workspace_cling); |
| 124 | boolean customCling = cling.getDrawIdentifier().equals("workspace_custom"); |
| 125 | if (customCling) { |
| 126 | AccountManager am = AccountManager.get(mLauncher); |
| 127 | if (am == null) return false; |
| 128 | Account[] accounts = am.getAccountsByType("com.google"); |
| 129 | return accounts.length == 0; |
| 130 | } |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | /** Updates the first run cling custom content hint */ |
| 135 | private void setCustomContentHintVisibility(Cling cling, String ccHintStr, boolean visible, |
| 136 | boolean animate) { |
| 137 | final TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint); |
| 138 | if (ccHint != null) { |
| 139 | if (visible && !ccHintStr.isEmpty()) { |
| 140 | ccHint.setText(ccHintStr); |
| 141 | ccHint.setVisibility(View.VISIBLE); |
| 142 | if (animate) { |
| 143 | ccHint.setAlpha(0f); |
| 144 | ccHint.animate().alpha(1f) |
| 145 | .setDuration(SHOW_CLING_DURATION) |
| 146 | .start(); |
| 147 | } else { |
| 148 | ccHint.setAlpha(1f); |
| 149 | } |
| 150 | } else { |
| 151 | if (animate) { |
| 152 | ccHint.animate().alpha(0f) |
| 153 | .setDuration(SHOW_CLING_DURATION) |
| 154 | .setListener(new AnimatorListenerAdapter() { |
| 155 | @Override |
| 156 | public void onAnimationEnd(Animator animation) { |
| 157 | ccHint.setVisibility(View.GONE); |
| 158 | } |
| 159 | }) |
| 160 | .start(); |
| 161 | } else { |
| 162 | ccHint.setAlpha(0f); |
| 163 | ccHint.setVisibility(View.GONE); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /** Updates the first run cling custom content hint */ |
| 170 | public void updateCustomContentHintVisibility() { |
| 171 | Cling cling = (Cling) mLauncher.findViewById(R.id.first_run_cling); |
| 172 | String ccHintStr = mLauncher.getFirstRunCustomContentHint(); |
| 173 | |
| 174 | if (mLauncher.getWorkspace().hasCustomContent()) { |
| 175 | // Show the custom content hint if ccHintStr is not empty |
| 176 | if (cling != null) { |
| 177 | setCustomContentHintVisibility(cling, ccHintStr, true, true); |
| 178 | } |
| 179 | } else { |
| 180 | // Hide the custom content hint |
| 181 | if (cling != null) { |
| 182 | setCustomContentHintVisibility(cling, ccHintStr, false, true); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /** Updates the first run cling search bar hint. */ |
| 188 | public void updateSearchBarHint(String hint) { |
| 189 | Cling cling = (Cling) mLauncher.findViewById(R.id.first_run_cling); |
| 190 | if (cling != null && cling.getVisibility() == View.VISIBLE && !hint.isEmpty()) { |
| 191 | TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint); |
| 192 | sbHint.setText(hint); |
| 193 | sbHint.setVisibility(View.VISIBLE); |
| 194 | } |
| 195 | } |
| 196 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 197 | public boolean shouldShowFirstRunOrMigrationClings() { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 198 | SharedPreferences sharedPrefs = mLauncher.getSharedPrefs(); |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 199 | return areClingsEnabled() && |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 200 | !sharedPrefs.getBoolean(FIRST_RUN_CLING_DISMISSED_KEY, false) && |
Adam Cohen | 71e03b9 | 2014-02-21 14:09:53 -0800 | [diff] [blame] | 201 | !sharedPrefs.getBoolean(MIGRATION_CLING_DISMISSED_KEY, false); |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 202 | } |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 203 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 204 | public void removeFirstRunAndMigrationClings() { |
| 205 | removeCling(R.id.first_run_cling); |
| 206 | removeCling(R.id.migration_cling); |
| 207 | } |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 208 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 209 | /** |
| 210 | * Shows the first run cling. |
| 211 | * |
| 212 | * This flow is mutually exclusive with showMigrationCling, and only runs if this Launcher |
| 213 | * package was preinstalled or there is no db to migrate from. |
| 214 | */ |
| 215 | public void showFirstRunCling() { |
| 216 | if (!skipCustomClingIfNoAccounts()) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 217 | Cling cling = (Cling) mLauncher.findViewById(R.id.first_run_cling); |
| 218 | if (cling != null) { |
| 219 | String sbHintStr = mLauncher.getFirstRunClingSearchBarHint(); |
| 220 | String ccHintStr = mLauncher.getFirstRunCustomContentHint(); |
| 221 | if (!sbHintStr.isEmpty()) { |
| 222 | TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint); |
| 223 | sbHint.setText(sbHintStr); |
| 224 | sbHint.setVisibility(View.VISIBLE); |
| 225 | } |
| 226 | setCustomContentHintVisibility(cling, ccHintStr, true, false); |
| 227 | } |
| 228 | initCling(R.id.first_run_cling, 0, false, true); |
| 229 | } else { |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 230 | removeFirstRunAndMigrationClings(); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 234 | /** |
| 235 | * Shows the migration cling. |
| 236 | * |
| 237 | * This flow is mutually exclusive with showFirstRunCling, and only runs if this Launcher |
| 238 | * package was not preinstalled and there exists a db to migrate from. |
| 239 | */ |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 240 | public void showMigrationCling() { |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 241 | mLauncher.hideWorkspaceSearchAndHotseat(); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 242 | |
Winson Chung | e43a1e7 | 2014-01-15 10:33:02 -0800 | [diff] [blame] | 243 | Cling c = initCling(R.id.migration_cling, 0, false, true); |
| 244 | c.bringScrimToFront(); |
| 245 | c.bringToFront(); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | public void showMigrationWorkspaceCling() { |
| 249 | // Enable the clings only if they have not been dismissed before |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 250 | if (areClingsEnabled() && !mLauncher.getSharedPrefs().getBoolean( |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 251 | MIGRATION_WORKSPACE_CLING_DISMISSED_KEY, false)) { |
| 252 | Cling c = initCling(R.id.migration_workspace_cling, 0, false, true); |
| 253 | c.updateMigrationWorkspaceBubblePosition(); |
| 254 | c.bringScrimToFront(); |
| 255 | c.bringToFront(); |
| 256 | } else { |
| 257 | removeCling(R.id.migration_workspace_cling); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | public void showWorkspaceCling() { |
| 262 | // Enable the clings only if they have not been dismissed before |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 263 | if (areClingsEnabled() && !mLauncher.getSharedPrefs().getBoolean( |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 264 | WORKSPACE_CLING_DISMISSED_KEY, false)) { |
| 265 | Cling c = initCling(R.id.workspace_cling, 0, false, true); |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 266 | c.updateWorkspaceBubblePosition(); |
Adam Cohen | 5eed5d8 | 2014-05-19 13:12:13 -0700 | [diff] [blame^] | 267 | if (mLauncher.shouldClingFocusHotseatApp()) { |
| 268 | // Set the focused hotseat app |
| 269 | c.setFocusedHotseatApp(mLauncher.getFirstRunFocusedHotseatAppDrawableId(), |
| 270 | mLauncher.getFirstRunFocusedHotseatAppRank(), |
| 271 | mLauncher.getFirstRunFocusedHotseatAppComponentName(), |
| 272 | mLauncher.getFirstRunFocusedHotseatAppBubbleTitle(), |
| 273 | mLauncher.getFirstRunFocusedHotseatAppBubbleDescription()); |
Winson Chung | 69dffdb | 2014-04-04 16:53:17 -0700 | [diff] [blame] | 274 | } |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 275 | } else { |
| 276 | removeCling(R.id.workspace_cling); |
| 277 | } |
| 278 | } |
Adam Cohen | 71e03b9 | 2014-02-21 14:09:53 -0800 | [diff] [blame] | 279 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 280 | public Cling showFoldersCling() { |
| 281 | SharedPreferences sharedPrefs = mLauncher.getSharedPrefs(); |
| 282 | // Enable the clings only if they have not been dismissed before |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 283 | if (areClingsEnabled() && |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 284 | !sharedPrefs.getBoolean(FOLDER_CLING_DISMISSED_KEY, false) && |
| 285 | !sharedPrefs.getBoolean(Launcher.USER_HAS_MIGRATED, false)) { |
| 286 | Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim, |
| 287 | true, true); |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 288 | Folder openFolder = mLauncher.getWorkspace().getOpenFolder(); |
| 289 | if (openFolder != null) { |
| 290 | Rect openFolderRect = new Rect(); |
| 291 | openFolder.getHitRect(openFolderRect); |
| 292 | cling.setOpenFolderRect(openFolderRect); |
| 293 | openFolder.bringToFront(); |
| 294 | } |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 295 | return cling; |
| 296 | } else { |
| 297 | removeCling(R.id.folder_cling); |
| 298 | return null; |
| 299 | } |
| 300 | } |
| 301 | |
Adam Cohen | 71e03b9 | 2014-02-21 14:09:53 -0800 | [diff] [blame] | 302 | public static void synchonouslyMarkFirstRunClingDismissed(Context ctx) { |
| 303 | SharedPreferences prefs = ctx.getSharedPreferences( |
Winson Chung | c6c0367 | 2014-03-06 10:12:02 -0800 | [diff] [blame] | 304 | LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE); |
Adam Cohen | 71e03b9 | 2014-02-21 14:09:53 -0800 | [diff] [blame] | 305 | SharedPreferences.Editor editor = prefs.edit(); |
| 306 | editor.putBoolean(LauncherClings.FIRST_RUN_CLING_DISMISSED_KEY, true); |
| 307 | editor.commit(); |
| 308 | } |
| 309 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 310 | /** Removes the cling outright from the DragLayer */ |
| 311 | private void removeCling(int id) { |
| 312 | final View cling = mLauncher.findViewById(id); |
| 313 | if (cling != null) { |
| 314 | final ViewGroup parent = (ViewGroup) cling.getParent(); |
| 315 | parent.post(new Runnable() { |
| 316 | @Override |
| 317 | public void run() { |
| 318 | parent.removeView(cling); |
| 319 | } |
| 320 | }); |
| 321 | mHideFromAccessibilityHelper.restoreImportantForAccessibility(mLauncher.getDragLayer()); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /** Hides the specified Cling */ |
| 326 | private void dismissCling(final Cling cling, final Runnable postAnimationCb, |
| 327 | final String flag, int duration, boolean restoreNavBarVisibilty) { |
| 328 | // To catch cases where siblings of top-level views are made invisible, just check whether |
| 329 | // the cling is directly set to GONE before dismissing it. |
| 330 | if (cling != null && cling.getVisibility() != View.GONE) { |
| 331 | final Runnable cleanUpClingCb = new Runnable() { |
| 332 | public void run() { |
| 333 | cling.cleanup(); |
| 334 | SharedPreferences.Editor editor = mLauncher.getSharedPrefs().edit(); |
| 335 | editor.putBoolean(flag, true); |
| 336 | editor.apply(); |
| 337 | if (postAnimationCb != null) { |
| 338 | postAnimationCb.run(); |
| 339 | } |
| 340 | } |
| 341 | }; |
| 342 | if (duration <= 0) { |
| 343 | cleanUpClingCb.run(); |
| 344 | } else { |
| 345 | cling.hide(duration, cleanUpClingCb); |
| 346 | } |
| 347 | mHideFromAccessibilityHelper.restoreImportantForAccessibility(mLauncher.getDragLayer()); |
| 348 | |
| 349 | if (restoreNavBarVisibilty) { |
| 350 | cling.setSystemUiVisibility(cling.getSystemUiVisibility() & |
| 351 | ~View.SYSTEM_UI_FLAG_LOW_PROFILE); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | public void dismissFirstRunCling(View v) { |
| 357 | Cling cling = (Cling) mLauncher.findViewById(R.id.first_run_cling); |
| 358 | Runnable cb = new Runnable() { |
| 359 | public void run() { |
| 360 | // Show the workspace cling next |
| 361 | showWorkspaceCling(); |
| 362 | } |
| 363 | }; |
| 364 | dismissCling(cling, cb, FIRST_RUN_CLING_DISMISSED_KEY, |
| 365 | DISMISS_CLING_DURATION, false); |
| 366 | |
| 367 | // Fade out the search bar for the workspace cling coming up |
| 368 | mLauncher.getSearchBar().hideSearchBar(true); |
| 369 | } |
| 370 | |
| 371 | private void dismissMigrationCling() { |
| 372 | mLauncher.showWorkspaceSearchAndHotseat(); |
| 373 | Runnable dismissCb = new Runnable() { |
| 374 | public void run() { |
| 375 | Cling cling = (Cling) mLauncher.findViewById(R.id.migration_cling); |
| 376 | Runnable cb = new Runnable() { |
| 377 | public void run() { |
| 378 | // Show the migration workspace cling next |
| 379 | showMigrationWorkspaceCling(); |
| 380 | } |
| 381 | }; |
Winson Chung | 285b6e1 | 2014-01-14 10:30:27 -0800 | [diff] [blame] | 382 | dismissCling(cling, cb, MIGRATION_CLING_DISMISSED_KEY, |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 383 | DISMISS_CLING_DURATION, true); |
| 384 | } |
| 385 | }; |
| 386 | mLauncher.getWorkspace().post(dismissCb); |
| 387 | } |
| 388 | |
Winson Chung | 285b6e1 | 2014-01-14 10:30:27 -0800 | [diff] [blame] | 389 | private void dismissAnyWorkspaceCling(Cling cling, String key, View v) { |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 390 | Runnable cb = null; |
| 391 | if (v == null) { |
| 392 | cb = new Runnable() { |
| 393 | public void run() { |
| 394 | mLauncher.getWorkspace().enterOverviewMode(); |
| 395 | } |
| 396 | }; |
| 397 | } |
Winson Chung | 285b6e1 | 2014-01-14 10:30:27 -0800 | [diff] [blame] | 398 | dismissCling(cling, cb, key, DISMISS_CLING_DURATION, true); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 399 | |
| 400 | // Fade in the search bar |
| 401 | mLauncher.getSearchBar().showSearchBar(true); |
| 402 | } |
| 403 | |
Adam Cohen | 6268f2d | 2014-05-16 16:42:35 -0700 | [diff] [blame] | 404 | public void markFolderClingDismissedIfNecessary() { |
| 405 | SharedPreferences prefs = mLauncher.getSharedPrefs(); |
| 406 | if (!prefs.getBoolean(FOLDER_CLING_DISMISSED_KEY, false)) { |
| 407 | SharedPreferences.Editor editor = prefs.edit(); |
| 408 | editor.putBoolean(FOLDER_CLING_DISMISSED_KEY, true); |
| 409 | editor.apply(); |
| 410 | } |
| 411 | } |
| 412 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 413 | public void dismissMigrationClingCopyApps(View v) { |
| 414 | // Copy the shortcuts from the old database |
| 415 | LauncherModel model = mLauncher.getModel(); |
Winson Chung | 5317c2b | 2014-01-10 16:46:15 -0800 | [diff] [blame] | 416 | model.resetLoadedState(false, true); |
| 417 | model.startLoader(false, PagedView.INVALID_RESTORE_PAGE, |
| 418 | LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE |
| 419 | | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 420 | |
| 421 | // Set the flag to skip the folder cling |
| 422 | String spKey = LauncherAppState.getSharedPreferencesKey(); |
| 423 | SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_PRIVATE); |
| 424 | SharedPreferences.Editor editor = sp.edit(); |
| 425 | editor.putBoolean(Launcher.USER_HAS_MIGRATED, true); |
| 426 | editor.apply(); |
| 427 | |
| 428 | // Disable the migration cling |
| 429 | dismissMigrationCling(); |
| 430 | } |
| 431 | |
| 432 | public void dismissMigrationClingUseDefault(View v) { |
Adam Cohen | 8457d49 | 2014-05-16 17:05:49 -0700 | [diff] [blame] | 433 | // Don't need to do anything special here. We've already loaded the default workspace, |
| 434 | // (which is the default loader behavior triggered from Launcher#onCreate.). |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 435 | |
| 436 | // Disable the migration cling |
| 437 | dismissMigrationCling(); |
| 438 | } |
| 439 | |
| 440 | public void dismissMigrationWorkspaceCling(View v) { |
| 441 | Cling cling = (Cling) mLauncher.findViewById(R.id.migration_workspace_cling); |
Winson Chung | 285b6e1 | 2014-01-14 10:30:27 -0800 | [diff] [blame] | 442 | dismissAnyWorkspaceCling(cling, MIGRATION_WORKSPACE_CLING_DISMISSED_KEY, v); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | public void dismissWorkspaceCling(View v) { |
| 446 | Cling cling = (Cling) mLauncher.findViewById(R.id.workspace_cling); |
Winson Chung | 285b6e1 | 2014-01-14 10:30:27 -0800 | [diff] [blame] | 447 | dismissAnyWorkspaceCling(cling, WORKSPACE_CLING_DISMISSED_KEY, v); |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | public void dismissFolderCling(View v) { |
| 451 | Cling cling = (Cling) mLauncher.findViewById(R.id.folder_cling); |
| 452 | dismissCling(cling, null, FOLDER_CLING_DISMISSED_KEY, |
| 453 | DISMISS_CLING_DURATION, true); |
| 454 | } |
Adam Cohen | 71e03b9 | 2014-02-21 14:09:53 -0800 | [diff] [blame] | 455 | } |