1a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung/* 2a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * Copyright (C) 2008 The Android Open Source Project 3a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * 4a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * Licensed under the Apache License, Version 2.0 (the "License"); 5a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * you may not use this file except in compliance with the License. 6a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * You may obtain a copy of the License at 7a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * 8a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * http://www.apache.org/licenses/LICENSE-2.0 9a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * 10a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * Unless required by applicable law or agreed to in writing, software 11a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * distributed under the License is distributed on an "AS IS" BASIS, 12a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * See the License for the specific language governing permissions and 14a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung * limitations under the License. 15a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung */ 16a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 17a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungpackage com.android.launcher3; 18a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 19a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungimport android.accounts.Account; 20a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungimport android.accounts.AccountManager; 21424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyalimport android.animation.ObjectAnimator; 22424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyalimport android.animation.PropertyValuesHolder; 237066003b2032a49ae5e59dab9b706259bdeb7e6eSunny Goyalimport android.annotation.TargetApi; 24a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungimport android.app.ActivityManager; 25a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungimport android.content.Context; 26a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungimport android.content.SharedPreferences; 277661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyalimport android.graphics.drawable.Drawable; 287066003b2032a49ae5e59dab9b706259bdeb7e6eSunny Goyalimport android.os.Build; 29a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungimport android.os.Bundle; 30a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungimport android.os.UserManager; 315ba21b6024ee8a3d4bdb2acad6fe30dfcf5cb3cdAmith Yamasaniimport android.provider.Settings; 32a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungimport android.view.LayoutInflater; 33a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungimport android.view.View; 34424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyalimport android.view.View.OnClickListener; 35424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyalimport android.view.View.OnLongClickListener; 36a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungimport android.view.ViewGroup; 37424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyalimport android.view.ViewTreeObserver.OnGlobalLayoutListener; 38a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chungimport android.view.accessibility.AccessibilityManager; 39091440a9cb9d4f42406631004aa484cbb79214caAdam Cohenimport com.android.launcher3.util.Thunk; 40091440a9cb9d4f42406631004aa484cbb79214caAdam Cohen 41424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyalclass LauncherClings implements OnClickListener { 42a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung private static final String MIGRATION_CLING_DISMISSED_KEY = "cling_gel.migration.dismissed"; 43a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling_gel.workspace.dismissed"; 44424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal 457661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal private static final String TAG_CROP_TOP_AND_SIDES = "crop_bg_top_and_sides"; 46a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 47a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung private static final boolean DISABLE_CLINGS = false; 48a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 49a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung private static final int SHOW_CLING_DURATION = 250; 50a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung private static final int DISMISS_CLING_DURATION = 200; 51a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 525ba21b6024ee8a3d4bdb2acad6fe30dfcf5cb3cdAmith Yamasani // New Secure Setting in L 535ba21b6024ee8a3d4bdb2acad6fe30dfcf5cb3cdAmith Yamasani private static final String SKIP_FIRST_USE_HINTS = "skip_first_use_hints"; 545ba21b6024ee8a3d4bdb2acad6fe30dfcf5cb3cdAmith Yamasani 55091440a9cb9d4f42406631004aa484cbb79214caAdam Cohen @Thunk Launcher mLauncher; 56a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung private LayoutInflater mInflater; 57a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 58a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung /** Ctor */ 59a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung public LauncherClings(Launcher launcher) { 60a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung mLauncher = launcher; 61e03b81294f046474cf4057bec20dc560a2e053d4Sunny Goyal mInflater = LayoutInflater.from(mLauncher); 62a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 63a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 64424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal @Override 65424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal public void onClick(View v) { 66424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal int id = v.getId(); 67424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal if (id == R.id.cling_dismiss_migration_use_default) { 68424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal // Disable the migration cling 69424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal dismissMigrationCling(); 70424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal } else if (id == R.id.cling_dismiss_migration_copy_apps) { 71424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal // Copy the shortcuts from the old database 72424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal LauncherModel model = mLauncher.getModel(); 73424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal model.resetLoadedState(false, true); 742bba4c37c6402dfdc965d0c412c840c57993c7ddSunny Goyal model.startLoader(PagedView.INVALID_RESTORE_PAGE, 75424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE 76424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); 77424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal // Set the flag to skip the folder cling 78424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal String spKey = LauncherAppState.getSharedPreferencesKey(); 79424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_PRIVATE); 80424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal SharedPreferences.Editor editor = sp.edit(); 81424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal editor.putBoolean(Launcher.USER_HAS_MIGRATED, true); 82424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal editor.apply(); 83424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal // Disable the migration cling 84424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal dismissMigrationCling(); 85424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal } else if (id == R.id.cling_dismiss_longpress_info) { 86424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal dismissLongPressCling(); 87a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 88a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 89a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 90424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal /** 91424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal * Shows the migration cling. 92424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal * 93424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal * This flow is mutually exclusive with showFirstRunCling, and only runs if this Launcher 94424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal * package was not preinstalled and there exists a db to migrate from. 95424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal */ 96424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal public void showMigrationCling() { 97424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal mLauncher.hideWorkspaceSearchAndHotseat(); 98a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 99424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal ViewGroup root = (ViewGroup) mLauncher.findViewById(R.id.launcher); 100424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal View inflated = mInflater.inflate(R.layout.migration_cling, root); 101424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal inflated.findViewById(R.id.cling_dismiss_migration_copy_apps).setOnClickListener(this); 102424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal inflated.findViewById(R.id.cling_dismiss_migration_use_default).setOnClickListener(this); 103424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal } 104a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 105424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal private void dismissMigrationCling() { 106424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal mLauncher.showWorkspaceSearchAndHotseat(); 107424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal Runnable dismissCb = new Runnable() { 108424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal public void run() { 109424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal Runnable cb = new Runnable() { 110424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal public void run() { 111424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal // Show the longpress cling next 112424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal showLongPressCling(false); 113424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal } 114424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal }; 115424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal dismissCling(mLauncher.findViewById(R.id.migration_cling), cb, 116424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal MIGRATION_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); 117a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 118424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal }; 119424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal mLauncher.getWorkspace().post(dismissCb); 120a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 121a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 122424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal public void showLongPressCling(boolean showWelcome) { 123424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal ViewGroup root = (ViewGroup) mLauncher.findViewById(R.id.launcher); 124424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal View cling = mInflater.inflate(R.layout.longpress_cling, root, false); 125a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 1267661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal cling.setOnLongClickListener(new OnLongClickListener() { 127a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 128424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal @Override 129424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal public boolean onLongClick(View v) { 130dc61c4d41468a8beced2863de1b863b340cf49baWinson Chung mLauncher.showOverviewMode(true); 131424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal dismissLongPressCling(); 132424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal return true; 133a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 134424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal }); 135a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 136424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal final ViewGroup content = (ViewGroup) cling.findViewById(R.id.cling_content); 137424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal mInflater.inflate(showWelcome ? R.layout.longpress_cling_welcome_content 138424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal : R.layout.longpress_cling_content, content); 139424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal content.findViewById(R.id.cling_dismiss_longpress_info).setOnClickListener(this); 140a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 1417661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal if (TAG_CROP_TOP_AND_SIDES.equals(content.getTag())) { 1427661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal Drawable bg = new BorderCropDrawable(mLauncher.getResources().getDrawable(R.drawable.cling_bg), 1437661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal true, true, true, false); 1447661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal content.setBackground(bg); 1457661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal } 1467661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal 147424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal root.addView(cling); 148a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 149424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal if (showWelcome) { 150424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal // This is the first cling being shown. No need to animate. 151424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal return; 152a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 153a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 154424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal // Animate 155424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal content.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 156a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 157424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal @Override 158424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal public void onGlobalLayout() { 159424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal content.getViewTreeObserver().removeOnGlobalLayoutListener(this); 160a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 1617661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal ObjectAnimator anim; 1627661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal if (TAG_CROP_TOP_AND_SIDES.equals(content.getTag())) { 163424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal content.setTranslationY(-content.getMeasuredHeight()); 1647661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal anim = LauncherAnimUtils.ofFloat(content, "translationY", 0); 165424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal } else { 166424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal content.setScaleX(0); 167424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal content.setScaleY(0); 168424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1); 169424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1); 1707661614383dc17d69a9b1fd819e4d610896d5205Sunny Goyal anim = LauncherAnimUtils.ofPropertyValuesHolder(content, scaleX, scaleY); 171424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal } 172a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 173424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal anim.setDuration(SHOW_CLING_DURATION); 174424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal anim.setInterpolator(new LogDecelerateInterpolator(100, 0)); 175424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal anim.start(); 17669dffdb83a614a6b02a2363e0ade510948549972Winson Chung } 177424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal }); 178a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 17971e03b9979b5ee4c30daa7eb0a704ec92b38431bAdam Cohen 180091440a9cb9d4f42406631004aa484cbb79214caAdam Cohen @Thunk void dismissLongPressCling() { 181424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal Runnable dismissCb = new Runnable() { 182424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal public void run() { 183424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal dismissCling(mLauncher.findViewById(R.id.longpress_cling), null, 184424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); 185205cd7727f3bd8b65892c580e6f243464878fe6eWinson Chung } 186424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal }; 187424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal mLauncher.getWorkspace().post(dismissCb); 188a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 189a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 190a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung /** Hides the specified Cling */ 191091440a9cb9d4f42406631004aa484cbb79214caAdam Cohen @Thunk void dismissCling(final View cling, final Runnable postAnimationCb, 192424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal final String flag, int duration) { 193a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung // To catch cases where siblings of top-level views are made invisible, just check whether 194a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung // the cling is directly set to GONE before dismissing it. 195a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung if (cling != null && cling.getVisibility() != View.GONE) { 196a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung final Runnable cleanUpClingCb = new Runnable() { 197a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung public void run() { 198424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal cling.setVisibility(View.GONE); 199424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal mLauncher.getSharedPrefs().edit() 200424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal .putBoolean(flag, true) 201424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal .apply(); 202a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung if (postAnimationCb != null) { 203a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung postAnimationCb.run(); 204a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 205a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 206a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung }; 207a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung if (duration <= 0) { 208a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung cleanUpClingCb.run(); 209a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } else { 210424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal cling.animate().alpha(0).setDuration(duration).withEndAction(cleanUpClingCb); 211a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 212a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 213a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 214a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 215424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal /** Returns whether the clings are enabled or should be shown */ 2167066003b2032a49ae5e59dab9b706259bdeb7e6eSunny Goyal @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) 217424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal private boolean areClingsEnabled() { 218424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal if (DISABLE_CLINGS) { 219424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal return false; 220a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 221a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 222424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal // disable clings when running in a test harness 223424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal if(ActivityManager.isRunningInTestHarness()) return false; 224a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 225424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal // Disable clings for accessibility when explore by touch is enabled 226424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal final AccessibilityManager a11yManager = (AccessibilityManager) mLauncher.getSystemService( 227424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal Launcher.ACCESSIBILITY_SERVICE); 228424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal if (a11yManager.isTouchExplorationEnabled()) { 229424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal return false; 2306268f2db4c129e33d8d77513cb9df0f4799c7520Adam Cohen } 231a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 232424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal // Restricted secondary users (child mode) will potentially have very few apps 233424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal // seeded when they start up for the first time. Clings won't work well with that 234424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal boolean supportsLimitedUsers = 235424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2; 236424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal Account[] accounts = AccountManager.get(mLauncher).getAccounts(); 237424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal if (supportsLimitedUsers && accounts.length == 0) { 238424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal UserManager um = (UserManager) mLauncher.getSystemService(Context.USER_SERVICE); 239424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal Bundle restrictions = um.getUserRestrictions(); 240424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) { 241424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal return false; 242424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal } 243424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal } 244424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal if (Settings.Secure.getInt(mLauncher.getContentResolver(), SKIP_FIRST_USE_HINTS, 0) 245424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal == 1) { 246424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal return false; 247424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal } 248424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal return true; 249a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 250a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 251424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal public boolean shouldShowFirstRunOrMigrationClings() { 252424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal SharedPreferences sharedPrefs = mLauncher.getSharedPrefs(); 253424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal return areClingsEnabled() && 254424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal !sharedPrefs.getBoolean(WORKSPACE_CLING_DISMISSED_KEY, false) && 255424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal !sharedPrefs.getBoolean(MIGRATION_CLING_DISMISSED_KEY, false); 256a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 257a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung 258424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal public static void synchonouslyMarkFirstRunClingDismissed(Context ctx) { 259424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal SharedPreferences prefs = ctx.getSharedPreferences( 260424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE); 261424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal SharedPreferences.Editor editor = prefs.edit(); 262424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal editor.putBoolean(WORKSPACE_CLING_DISMISSED_KEY, true); 263424418bb50ccf5d9270650b70cc51f423da51a65Sunny Goyal editor.commit(); 264a694524047fda0a51dede4eefb1201a598d2d3a7Winson Chung } 26571e03b9979b5ee4c30daa7eb0a704ec92b38431bAdam Cohen} 266