diff options
Diffstat (limited to 'src/com/android/launcher3')
20 files changed, 284 insertions, 728 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 88e1532d3..ec09cf149 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -152,8 +152,6 @@ public class Launcher extends Activity static final boolean DEBUG_RESUME_TIME = false; static final boolean DEBUG_LOGGING = false; - static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run - private static final int REQUEST_CREATE_SHORTCUT = 1; private static final int REQUEST_CREATE_APPWIDGET = 5; private static final int REQUEST_PICK_APPWIDGET = 9; @@ -201,9 +199,6 @@ public class Launcher extends Activity 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"; - private static final String MIGRATE_AUTHORITY = "com.android.launcher2.settings"; - /** The different states that Launcher can be in. */ enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED, WIDGETS, WIDGETS_SPRING_LOADED } @@ -1621,15 +1616,6 @@ public class Launcher extends Activity } else if (Intent.ACTION_USER_PRESENT.equals(action)) { mUserPresent = true; updateAutoAdvanceState(); - } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) { - mModel.resetLoadedState(false, true); - mModel.startLoader(PagedView.INVALID_RESTORE_PAGE, - LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE); - } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) { - mModel.resetLoadedState(false, true); - mModel.startLoader(PagedView.INVALID_RESTORE_PAGE, - LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE - | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); } } }; @@ -1642,11 +1628,6 @@ public class Launcher extends Activity final IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_USER_PRESENT); - // For handling managed profiles - if (ENABLE_DEBUG_INTENTS) { - filter.addAction(DebugIntents.DELETE_DATABASE); - filter.addAction(DebugIntents.MIGRATE_DATABASE); - } registerReceiver(mReceiver, filter); FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); mAttached = true; @@ -3552,7 +3533,12 @@ public class Launcher extends Activity if (widgetId != -1) { mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider); mQsb.setId(R.id.qsb_widget); - mQsb.updateAppWidgetOptions(opts); + if (!Utilities.containsAll( + AppWidgetManager.getInstance(this).getAppWidgetOptions(widgetId), opts)) { + // Launcher should not be updating the options often. + FileLog.d(TAG, "Options for QSB were not same"); + mQsb.updateAppWidgetOptions(opts); + } mQsb.setPadding(0, 0, 0, 0); mSearchDropTargetBar.addView(mQsb); mSearchDropTargetBar.setQsbSearchBar(mQsb); @@ -4511,43 +4497,10 @@ public class Launcher extends Activity LauncherClings launcherClings = new LauncherClings(this); if (launcherClings.shouldShowFirstRunOrMigrationClings()) { mClings = launcherClings; - if (canMigrateFromOldLauncherDb()) { - launcherClings.showMigrationCling(); - } else { - launcherClings.showLongPressCling(true); - } + launcherClings.showLongPressCling(true); } } - private boolean canMigrateFromOldLauncherDb() { - // Return true if launcher was not preinstalled and and old content provider exists. - return ((getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) && - providerExists(MIGRATE_AUTHORITY) && - providerExists(Uri.parse(getString(R.string.old_launcher_provider_uri)).getAuthority()); - - } - - private boolean providerExists(String authority) { - return getPackageManager().resolveContentProvider(authority, 0) != null; - } - - - void showWorkspaceSearchAndHotseat() { - if (mWorkspace != null) mWorkspace.setAlpha(1f); - if (mHotseat != null) mHotseat.setAlpha(1f); - if (mPageIndicator != null) mPageIndicator.setAlpha(1f); - if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState( - SearchDropTargetBar.State.SEARCH_BAR, 0); - } - - void hideWorkspaceSearchAndHotseat() { - if (mWorkspace != null) mWorkspace.setAlpha(0f); - if (mHotseat != null) mHotseat.setAlpha(0f); - if (mPageIndicator != null) mPageIndicator.setAlpha(0f); - if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState( - SearchDropTargetBar.State.INVISIBLE, 0); - } - // TODO: These method should be a part of LauncherSearchCallback @TargetApi(Build.VERSION_CODES.LOLLIPOP) public ItemInfo createAppDragInfo(Intent appLaunchIntent) { @@ -4701,8 +4654,3 @@ public class Launcher extends Activity } } } - -interface DebugIntents { - static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE"; - static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE"; -} diff --git a/src/com/android/launcher3/LauncherClings.java b/src/com/android/launcher3/LauncherClings.java index 1cfa3f7b3..c44969f8d 100644 --- a/src/com/android/launcher3/LauncherClings.java +++ b/src/com/android/launcher3/LauncherClings.java @@ -21,10 +21,7 @@ import android.animation.PropertyValuesHolder; import android.annotation.TargetApi; import android.app.ActivityManager; import android.content.Context; -import android.content.SharedPreferences; -import android.content.pm.ApplicationInfo; import android.graphics.drawable.Drawable; -import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.UserManager; @@ -42,7 +39,6 @@ import android.view.accessibility.AccessibilityManager; import com.android.launcher3.util.Thunk; class LauncherClings implements OnClickListener, OnKeyListener { - private static final String MIGRATION_CLING_DISMISSED_KEY = "cling_gel.migration.dismissed"; private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling_gel.workspace.dismissed"; private static final String TAG_CROP_TOP_AND_SIDES = "crop_bg_top_and_sides"; @@ -62,24 +58,7 @@ class LauncherClings implements OnClickListener, OnKeyListener { @Override public void onClick(View v) { - int id = v.getId(); - if (id == R.id.cling_dismiss_migration_use_default) { - // Disable the migration cling - dismissMigrationCling(); - } else if (id == R.id.cling_dismiss_migration_copy_apps) { - // Copy the shortcuts from the old database - LauncherModel model = mLauncher.getModel(); - model.resetLoadedState(false, true); - model.startLoader(PagedView.INVALID_RESTORE_PAGE, - LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE - | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); - // Set the flag to skip the folder cling - SharedPreferences.Editor editor = Utilities.getPrefs(mLauncher).edit(); - editor.putBoolean(Launcher.USER_HAS_MIGRATED, true); - editor.apply(); - // Disable the migration cling - dismissMigrationCling(); - } else if (id == R.id.cling_dismiss_longpress_info) { + if (v.getId() == R.id.cling_dismiss_longpress_info) { dismissLongPressCling(); } } @@ -98,40 +77,6 @@ class LauncherClings implements OnClickListener, OnKeyListener { return false; } - /** - * Shows the migration cling. - * - * This flow is mutually exclusive with showFirstRunCling, and only runs if this Launcher - * package was not preinstalled and there exists a db to migrate from. - */ - public void showMigrationCling() { - mLauncher.onLauncherClingShown(); - mIsVisible = true; - mLauncher.hideWorkspaceSearchAndHotseat(); - - ViewGroup root = (ViewGroup) mLauncher.findViewById(R.id.launcher); - View inflated = mInflater.inflate(R.layout.migration_cling, root); - inflated.findViewById(R.id.cling_dismiss_migration_copy_apps).setOnClickListener(this); - inflated.findViewById(R.id.cling_dismiss_migration_use_default).setOnClickListener(this); - } - - private void dismissMigrationCling() { - mLauncher.showWorkspaceSearchAndHotseat(); - Runnable dismissCb = new Runnable() { - public void run() { - Runnable cb = new Runnable() { - public void run() { - // Show the longpress cling next - showLongPressCling(false); - } - }; - dismissCling(mLauncher.findViewById(R.id.migration_cling), cb, - MIGRATION_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); - } - }; - mLauncher.getWorkspace().post(dismissCb); - } - public void showLongPressCling(boolean showWelcome) { mIsVisible = true; ViewGroup root = (ViewGroup) mLauncher.findViewById(R.id.launcher); @@ -197,44 +142,28 @@ class LauncherClings implements OnClickListener, OnKeyListener { @Thunk void dismissLongPressCling() { Runnable dismissCb = new Runnable() { public void run() { - Runnable cb = new Runnable() { - public void run() { - mLauncher.onLauncherClingDismissed(); - } - }; - dismissCling(mLauncher.findViewById(R.id.longpress_cling), cb, - WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); + final View cling = mLauncher.findViewById(R.id.longpress_cling); + // To catch cases where siblings of top-level views are made invisible, just check whether + // the cling is directly set to GONE before dismissing it. + if (cling != null && cling.getVisibility() != View.GONE) { + final Runnable cleanUpClingCb = new Runnable() { + public void run() { + cling.setVisibility(View.GONE); + mLauncher.getSharedPrefs().edit() + .putBoolean(WORKSPACE_CLING_DISMISSED_KEY, true) + .apply(); + mIsVisible = false; + mLauncher.onLauncherClingDismissed(); + } + }; + cling.animate().alpha(0).setDuration(DISMISS_CLING_DURATION) + .withEndAction(cleanUpClingCb); + } } }; mLauncher.getWorkspace().post(dismissCb); } - /** Hides the specified Cling */ - @Thunk void dismissCling(final View cling, final Runnable postAnimationCb, - final String flag, int duration) { - // To catch cases where siblings of top-level views are made invisible, just check whether - // the cling is directly set to GONE before dismissing it. - if (cling != null && cling.getVisibility() != View.GONE) { - final Runnable cleanUpClingCb = new Runnable() { - public void run() { - cling.setVisibility(View.GONE); - mLauncher.getSharedPrefs().edit() - .putBoolean(flag, true) - .apply(); - mIsVisible = false; - if (postAnimationCb != null) { - postAnimationCb.run(); - } - } - }; - if (duration <= 0) { - cleanUpClingCb.run(); - } else { - cling.animate().alpha(0).setDuration(duration).withEndAction(cleanUpClingCb); - } - } - } - public boolean isVisible() { return mIsVisible; } @@ -269,10 +198,8 @@ class LauncherClings implements OnClickListener, OnKeyListener { } public boolean shouldShowFirstRunOrMigrationClings() { - SharedPreferences sharedPrefs = mLauncher.getSharedPrefs(); return areClingsEnabled() && - !sharedPrefs.getBoolean(WORKSPACE_CLING_DISMISSED_KEY, false) && - !sharedPrefs.getBoolean(MIGRATION_CLING_DISMISSED_KEY, false); + !mLauncher.getSharedPrefs().getBoolean(WORKSPACE_CLING_DISMISSED_KEY, false); } public static void markFirstRunClingDismissed(Context ctx) { diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index fec96ca2e..f9cb9edea 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -97,10 +97,6 @@ public class LauncherModel extends BroadcastReceiver static final String TAG = "Launcher.Model"; - public static final int LOADER_FLAG_NONE = 0; - public static final int LOADER_FLAG_CLEAR_WORKSPACE = 1 << 0; - public static final int LOADER_FLAG_MIGRATE_SHORTCUTS = 1 << 1; - private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons private static final long INVALID_SCREEN_ID = -1L; @@ -1221,10 +1217,6 @@ public class LauncherModel extends BroadcastReceiver } public void startLoader(int synchronousBindPage) { - startLoader(synchronousBindPage, LOADER_FLAG_NONE); - } - - public void startLoader(int synchronousBindPage, int loadFlags) { // Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems InstallShortcutReceiver.enableInstallQueue(); synchronized (mLock) { @@ -1240,7 +1232,7 @@ public class LauncherModel extends BroadcastReceiver // If there is already one running, tell it to stop. stopLoaderLocked(); - mLoaderTask = new LoaderTask(mApp.getContext(), loadFlags, synchronousBindPage); + mLoaderTask = new LoaderTask(mApp.getContext(), synchronousBindPage); if (synchronousBindPage != PagedView.INVALID_RESTORE_PAGE && mAllAppsLoaded && mWorkspaceLoaded && !mIsLoaderTaskRunning) { mLoaderTask.runBindSynchronousPage(synchronousBindPage); @@ -1299,11 +1291,9 @@ public class LauncherModel extends BroadcastReceiver @Thunk boolean mIsLoadingAndBindingWorkspace; private boolean mStopped; @Thunk boolean mLoadAndBindStepFinished; - private int mFlags; - LoaderTask(Context context, int flags, int pageToBindFirst) { + LoaderTask(Context context, int pageToBindFirst) { mContext = context; - mFlags = flags; mPageToBindFirst = pageToBindFirst; } @@ -1599,29 +1589,22 @@ public class LauncherModel extends BroadcastReceiver int countX = profile.numColumns; int countY = profile.numRows; + boolean clearDb = false; if (GridSizeMigrationTask.ENABLED && !GridSizeMigrationTask.migrateGridIfNeeded(mContext)) { // Migration failed. Clear workspace. - mFlags = mFlags | LOADER_FLAG_CLEAR_WORKSPACE; + clearDb = true; } - if ((mFlags & LOADER_FLAG_CLEAR_WORKSPACE) != 0) { + if (clearDb) { Log.d(TAG, "loadWorkspace: resetting launcher database"); LauncherSettings.Settings.call(contentResolver, LauncherSettings.Settings.METHOD_DELETE_DB); } - if ((mFlags & LOADER_FLAG_MIGRATE_SHORTCUTS) != 0) { - // append the user's Launcher2 shortcuts - Log.d(TAG, "loadWorkspace: migrating from launcher2"); - LauncherSettings.Settings.call(contentResolver, - LauncherSettings.Settings.METHOD_MIGRATE_LAUNCHER2_SHORTCUTS); - } else { - // Make sure the default workspace is loaded - Log.d(TAG, "loadWorkspace: loading default favorites"); - LauncherSettings.Settings.call(contentResolver, - LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES); - } + Log.d(TAG, "loadWorkspace: loading default favorites"); + LauncherSettings.Settings.call(contentResolver, + LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES); synchronized (sBgLock) { clearSBgDataStructures(); diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 7ebee31e4..11d61d02f 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -363,13 +363,6 @@ public class LauncherProvider extends ContentProvider { loadDefaultFavoritesIfNecessary(); return null; } - case LauncherSettings.Settings.METHOD_MIGRATE_LAUNCHER2_SHORTCUTS: { - mOpenHelper.migrateLauncher2Shortcuts(mOpenHelper.getWritableDatabase(), - Uri.parse(getContext().getString(R.string.old_launcher_provider_uri))); - Utilities.getPrefs(getContext()).edit().putBoolean(EMPTY_DATABASE_CREATED, false) - .commit(); - return null; - } case LauncherSettings.Settings.METHOD_UPDATE_FOLDER_ITEMS_RANK: { mOpenHelper.updateFolderItemsRank(mOpenHelper.getWritableDatabase(), false); return null; @@ -1033,278 +1026,6 @@ public class LauncherProvider extends ContentProvider { return count; } - - @Thunk void migrateLauncher2Shortcuts(SQLiteDatabase db, Uri uri) { - final ContentResolver resolver = mContext.getContentResolver(); - Cursor c = null; - int count = 0; - int curScreen = 0; - - try { - c = resolver.query(uri, null, null, null, "title ASC"); - } catch (Exception e) { - // Ignore - } - - // We already have a favorites database in the old provider - if (c != null) { - try { - if (c.getCount() > 0) { - final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID); - final int intentIndex - = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT); - final int titleIndex - = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE); - final int iconIndex - = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON); - final int iconPackageIndex - = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_PACKAGE); - final int iconResourceIndex - = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_RESOURCE); - final int containerIndex - = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER); - final int itemTypeIndex - = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE); - final int screenIndex - = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN); - final int cellXIndex - = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX); - final int cellYIndex - = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY); - final int profileIndex - = c.getColumnIndex(LauncherSettings.Favorites.PROFILE_ID); - - int i = 0; - int curX = 0; - int curY = 0; - - final LauncherAppState app = LauncherAppState.getInstance(); - final InvariantDeviceProfile profile = app.getInvariantDeviceProfile(); - final int width = (int) profile.numColumns; - final int height = (int) profile.numRows; - final int hotseatWidth = (int) profile.numHotseatIcons; - - final HashSet<String> seenIntents = new HashSet<String>(c.getCount()); - - final ArrayList<ContentValues> shortcuts = new ArrayList<ContentValues>(); - final ArrayList<ContentValues> folders = new ArrayList<ContentValues>(); - final SparseArray<ContentValues> hotseat = new SparseArray<ContentValues>(); - - while (c.moveToNext()) { - final int itemType = c.getInt(itemTypeIndex); - if (itemType != Favorites.ITEM_TYPE_APPLICATION - && itemType != Favorites.ITEM_TYPE_SHORTCUT - && itemType != Favorites.ITEM_TYPE_FOLDER) { - continue; - } - - final int cellX = c.getInt(cellXIndex); - final int cellY = c.getInt(cellYIndex); - final int screen = c.getInt(screenIndex); - int container = c.getInt(containerIndex); - final String intentStr = c.getString(intentIndex); - - UserManagerCompat userManager = UserManagerCompat.getInstance(mContext); - UserHandleCompat userHandle; - final long userSerialNumber; - if (profileIndex != -1 && !c.isNull(profileIndex)) { - userSerialNumber = c.getInt(profileIndex); - userHandle = userManager.getUserForSerialNumber(userSerialNumber); - } else { - // Default to the serial number of this user, for older - // shortcuts. - userHandle = UserHandleCompat.myUserHandle(); - userSerialNumber = userManager.getSerialNumberForUser(userHandle); - } - - if (userHandle == null) { - Log.d(TAG, "skipping deleted user"); - continue; - } - - if (itemType != Favorites.ITEM_TYPE_FOLDER) { - - final Intent intent; - final ComponentName cn; - try { - intent = Intent.parseUri(intentStr, 0); - } catch (URISyntaxException e) { - // bogus intent? - Log.d(TAG, "skipping invalid intent uri"); - continue; - } - - cn = intent.getComponent(); - if (TextUtils.isEmpty(intentStr)) { - // no intent? no icon - Log.d(TAG, "skipping empty intent"); - continue; - } else if (cn != null && - !LauncherModel.isValidPackageActivity(mContext, cn, - userHandle)) { - // component no longer exists. - Log.d(TAG, "skipping item whose component no longer exists."); - continue; - } else if (container == - LauncherSettings.Favorites.CONTAINER_DESKTOP) { - // Dedupe icons directly on the workspace - - // Canonicalize - // the Play Store sets the package parameter, but Launcher - // does not, so we clear that out to keep them the same. - // Also ignore intent flags for the purposes of deduping. - intent.setPackage(null); - int flags = intent.getFlags(); - intent.setFlags(0); - final String key = intent.toUri(0); - intent.setFlags(flags); - if (seenIntents.contains(key)) { - Log.d(TAG, "skipping duplicate"); - continue; - } else { - seenIntents.add(key); - } - } - } - - ContentValues values = new ContentValues(c.getColumnCount()); - values.put(LauncherSettings.Favorites._ID, c.getInt(idIndex)); - values.put(LauncherSettings.Favorites.INTENT, intentStr); - values.put(LauncherSettings.Favorites.TITLE, c.getString(titleIndex)); - values.put(LauncherSettings.Favorites.ICON, c.getBlob(iconIndex)); - values.put(LauncherSettings.Favorites.ICON_PACKAGE, - c.getString(iconPackageIndex)); - values.put(LauncherSettings.Favorites.ICON_RESOURCE, - c.getString(iconResourceIndex)); - values.put(LauncherSettings.Favorites.ITEM_TYPE, itemType); - values.put(LauncherSettings.Favorites.APPWIDGET_ID, -1); - values.put(LauncherSettings.Favorites.PROFILE_ID, userSerialNumber); - - if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { - hotseat.put(screen, values); - } - - if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP) { - // In a folder or in the hotseat, preserve position - values.put(LauncherSettings.Favorites.SCREEN, screen); - values.put(LauncherSettings.Favorites.CELLX, cellX); - values.put(LauncherSettings.Favorites.CELLY, cellY); - } else { - // For items contained directly on one of the workspace screen, - // we'll determine their location (screen, x, y) in a second pass. - } - - values.put(LauncherSettings.Favorites.CONTAINER, container); - - if (itemType != Favorites.ITEM_TYPE_FOLDER) { - shortcuts.add(values); - } else { - folders.add(values); - } - } - - // Now that we have all the hotseat icons, let's go through them left-right - // and assign valid locations for them in the new hotseat - final int N = hotseat.size(); - for (int idx=0; idx<N; idx++) { - int hotseatX = hotseat.keyAt(idx); - ContentValues values = hotseat.valueAt(idx); - - if (hotseatX == profile.hotseatAllAppsRank) { - // let's drop this in the next available hole in the hotseat - while (++hotseatX < hotseatWidth) { - if (hotseat.get(hotseatX) == null) { - // found a spot! move it here - values.put(LauncherSettings.Favorites.SCREEN, - hotseatX); - break; - } - } - } - if (hotseatX >= hotseatWidth) { - // no room for you in the hotseat? it's off to the desktop with you - values.put(LauncherSettings.Favorites.CONTAINER, - Favorites.CONTAINER_DESKTOP); - } - } - - final ArrayList<ContentValues> allItems = new ArrayList<ContentValues>(); - // Folders first - allItems.addAll(folders); - // Then shortcuts - allItems.addAll(shortcuts); - - // Layout all the folders - for (ContentValues values: allItems) { - if (values.getAsInteger(LauncherSettings.Favorites.CONTAINER) != - LauncherSettings.Favorites.CONTAINER_DESKTOP) { - // Hotseat items and folder items have already had their - // location information set. Nothing to be done here. - continue; - } - values.put(LauncherSettings.Favorites.SCREEN, curScreen); - values.put(LauncherSettings.Favorites.CELLX, curX); - values.put(LauncherSettings.Favorites.CELLY, curY); - curX = (curX + 1) % width; - if (curX == 0) { - curY = (curY + 1); - } - // Leave the last row of icons blank on every screen - if (curY == height - 1) { - curScreen = (int) generateNewScreenId(); - curY = 0; - } - } - - if (allItems.size() > 0) { - db.beginTransaction(); - try { - for (ContentValues row: allItems) { - if (row == null) continue; - if (dbInsertAndCheck(this, db, Favorites.TABLE_NAME, null, row) - < 0) { - return; - } else { - count++; - } - } - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } - - db.beginTransaction(); - try { - for (i=0; i<=curScreen; i++) { - final ContentValues values = new ContentValues(); - values.put(LauncherSettings.WorkspaceScreens._ID, i); - values.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i); - if (dbInsertAndCheck(this, db, WorkspaceScreens.TABLE_NAME, null, values) - < 0) { - return; - } - } - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - - updateFolderItemsRank(db, false); - } - } finally { - c.close(); - } - } - - Log.d(TAG, "migrated " + count + " icons from Launcher2 into " - + (curScreen+1) + " screens"); - - // Update max IDs; very important since we just grabbed IDs from another database - mMaxItemId = initializeMaxItemId(db); - mMaxScreenId = initializeMaxScreenId(db); - if (LOGD) Log.d(TAG, "mMaxItemId: " + mMaxItemId + " mMaxScreenId: " + mMaxScreenId); - } } /** diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java index 45a87cc02..52668d721 100644 --- a/src/com/android/launcher3/LauncherSettings.java +++ b/src/com/android/launcher3/LauncherSettings.java @@ -291,7 +291,6 @@ public class LauncherSettings { public static final String METHOD_DELETE_DB = "delete_db"; public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites"; - public static final String METHOD_MIGRATE_LAUNCHER2_SHORTCUTS = "migrate_l2_shortcuts"; public static final String METHOD_SET_EXTRACTED_COLORS_AND_WALLPAPER_ID = "set_extracted_colors_and_wallpaper_id_setting"; diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index 86a1a397c..fdca9f2fe 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -259,9 +259,9 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc OnClickListener listener = getPageIndicatorClickListener(); if (listener != null) { - mPageIndicator.getView().setOnClickListener(listener); + mPageIndicator.setOnClickListener(listener); } - mPageIndicator.getView().setContentDescription(getPageIndicatorDescription()); + mPageIndicator.setContentDescription(getPageIndicatorDescription()); } } @@ -467,7 +467,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc private void updatePageIndicator() { // Update the page indicator (when we aren't reordering) if (mPageIndicator != null) { - mPageIndicator.getView().setContentDescription(getPageIndicatorDescription()); + mPageIndicator.setContentDescription(getPageIndicatorDescription()); if (!isReordering(false)) { mPageIndicator.setActiveMarker(getNextPage()); } diff --git a/src/com/android/launcher3/PinchAnimationManager.java b/src/com/android/launcher3/PinchAnimationManager.java index 477b92cc0..c8c8fa4c8 100644 --- a/src/com/android/launcher3/PinchAnimationManager.java +++ b/src/com/android/launcher3/PinchAnimationManager.java @@ -194,7 +194,7 @@ public class PinchAnimationManager { animateShowHideView(INDEX_HOTSEAT, mLauncher.getHotseat(), show); if (mWorkspace.getPageIndicator() != null) { // There aren't page indicators in landscape mode on phones, hence the null check. - animateShowHideView(INDEX_PAGE_INDICATOR, mWorkspace.getPageIndicator().getView(), show); + animateShowHideView(INDEX_PAGE_INDICATOR, mWorkspace.getPageIndicator(), show); } } diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index e3b959b39..2f460bcec 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -849,7 +849,7 @@ public final class Utilities { if (isNycOrAbove()) { try { WallpaperManager wm = context.getSystemService(WallpaperManager.class); - return (Boolean) wm.getClass().getDeclaredMethod("isWallpaperSettingAllowed") + return (Boolean) wm.getClass().getDeclaredMethod("isSetWallpaperAllowed") .invoke(wm); } catch (Exception e) { } } @@ -869,6 +869,26 @@ public final class Utilities { } /** + * Returns true if {@param original} contains all entries defined in {@param updates} and + * have the same value. + * The comparison uses {@link Object#equals(Object)} to compare the values. + */ + public static boolean containsAll(Bundle original, Bundle updates) { + for (String key : updates.keySet()) { + Object value1 = updates.get(key); + Object value2 = original.get(key); + if (value1 == null) { + if (value2 != null) { + return false; + } + } else if (!value1.equals(value2)) { + return false; + } + } + return true; + } + + /** * An extension of {@link BitmapDrawable} which returns the bitmap pixel size as intrinsic size. * This allows the badging to be done based on the action bitmap size rather than * the scaled bitmap size. diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index f8eff6987..62c1bc814 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1275,13 +1275,15 @@ public class Workspace extends PagedView // Update the page indicator progress. boolean isTransitioning = mIsSwitchingState || (getLayoutTransition() != null && getLayoutTransition().isRunning()); - if (mPageIndicator != null && !isTransitioning) { + if (!isTransitioning) { showPageIndicatorAtCurrentScroll(); } } private void showPageIndicatorAtCurrentScroll() { - mPageIndicator.setScroll(getScrollX(), computeMaxScrollX()); + if (mPageIndicator != null) { + mPageIndicator.setScroll(getScrollX(), computeMaxScrollX()); + } } @Override @@ -1337,7 +1339,7 @@ public class Workspace extends PagedView // different effects based on device performance. On at least one relatively high-end // device I've tried, translating the launcher causes things to get quite laggy. setTranslationAndAlpha(mLauncher.getSearchDropTargetBar(), transX, alpha); - setTranslationAndAlpha(getPageIndicator().getView(), transX, alpha); + setTranslationAndAlpha(getPageIndicator(), transX, alpha); setTranslationAndAlpha(getChildAt(getCurrentPage()), transX, alpha); setTranslationAndAlpha(mLauncher.getHotseat(), transX, alpha); @@ -1550,7 +1552,7 @@ public class Workspace extends PagedView } if (getPageIndicator() != null) { - getPageIndicator().getView().setTranslationX(translationX); + getPageIndicator().setTranslationX(translationX); } if (mCustomContentCallbacks != null) { @@ -1599,7 +1601,7 @@ public class Workspace extends PagedView // attach to window OnClickListener listener = getPageIndicatorClickListener(); if (listener != null) { - getPageIndicator().getView().setOnClickListener(listener); + getPageIndicator().setOnClickListener(listener); } showPageIndicatorAtCurrentScroll(); diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java index 60070a810..e26864087 100644 --- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java +++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java @@ -357,7 +357,7 @@ public class WorkspaceStateTransitionAnimation { final ViewGroup overviewPanel = mLauncher.getOverviewPanel(); final View hotseat = mLauncher.getHotseat(); - final View pageIndicator = mWorkspace.getPageIndicator().getView(); + final View pageIndicator = mWorkspace.getPageIndicator(); if (animated) { LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(mWorkspace); scale.scaleX(mNewScale) diff --git a/src/com/android/launcher3/compat/AlphabeticIndexCompat.java b/src/com/android/launcher3/compat/AlphabeticIndexCompat.java index 463278ab4..ec65c3e8a 100644 --- a/src/com/android/launcher3/compat/AlphabeticIndexCompat.java +++ b/src/com/android/launcher3/compat/AlphabeticIndexCompat.java @@ -1,6 +1,8 @@ package com.android.launcher3.compat; import android.content.Context; +import android.content.res.Configuration; +import android.util.Log; import com.android.launcher3.Utilities; @@ -8,108 +10,41 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.Locale; -/** - * Fallback class to support Alphabetic indexing if not supported by the framework. - * TODO(winsonc): disable for non-english locales - */ -class BaseAlphabeticIndex { - - private static final String BUCKETS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-"; - private static final int UNKNOWN_BUCKET_INDEX = BUCKETS.length() - 1; - - public BaseAlphabeticIndex() {} - - /** - * Sets the max number of the label buckets in this index. - */ - public void setMaxLabelCount(int count) { - // Not currently supported - } - - /** - * Returns the index of the bucket in which the given string should appear. - */ - protected int getBucketIndex(String s) { - if (s.isEmpty()) { - return UNKNOWN_BUCKET_INDEX; - } - int index = BUCKETS.indexOf(s.substring(0, 1).toUpperCase()); - if (index != -1) { - return index; - } - return UNKNOWN_BUCKET_INDEX; - } - - /** - * Returns the label for the bucket at the given index (as returned by getBucketIndex). - */ - protected String getBucketLabel(int index) { - return BUCKETS.substring(index, index + 1); - } -} - -/** - * Reflected libcore.icu.AlphabeticIndex implementation, falls back to the base alphabetic index. - */ -public class AlphabeticIndexCompat extends BaseAlphabeticIndex { +public class AlphabeticIndexCompat { + private static final String TAG = "AlphabeticIndexCompat"; private static final String MID_DOT = "\u2219"; + private final BaseIndex mBaseIndex; + private final String mDefaultMiscLabel; - private Object mAlphabeticIndex; - private Method mAddLabelsMethod; - private Method mSetMaxLabelCountMethod; - private Method mGetBucketIndexMethod; - private Method mGetBucketLabelMethod; - private boolean mHasValidAlphabeticIndex; - private String mDefaultMiscLabel; - - @SuppressWarnings({"unchecked", "rawtypes"}) public AlphabeticIndexCompat(Context context) { - super(); + BaseIndex index = null; + try { - Locale curLocale = context.getResources().getConfiguration().locale; - Class clazz = Class.forName("libcore.icu.AlphabeticIndex"); - Constructor ctor = clazz.getConstructor(Locale.class); - mAddLabelsMethod = clazz.getDeclaredMethod("addLabels", Locale.class); - mSetMaxLabelCountMethod = clazz.getDeclaredMethod("setMaxLabelCount", int.class); - mGetBucketIndexMethod = clazz.getDeclaredMethod("getBucketIndex", String.class); - mGetBucketLabelMethod = clazz.getDeclaredMethod("getBucketLabel", int.class); - mAlphabeticIndex = ctor.newInstance(curLocale); - try { - // Ensure we always have some base English locale buckets - if (!curLocale.getLanguage().equals(Locale.ENGLISH.getLanguage())) { - mAddLabelsMethod.invoke(mAlphabeticIndex, Locale.ENGLISH); - } - } catch (Exception e) { - e.printStackTrace(); - } - if (curLocale.getLanguage().equals(Locale.JAPANESE.getLanguage())) { - // Japanese character 他 ("misc") - mDefaultMiscLabel = "\u4ed6"; - // TODO(winsonc, omakoto): We need to handle Japanese sections better, especially the kanji - } else { - // Dot - mDefaultMiscLabel = MID_DOT; + if (Utilities.isNycOrAbove()) { + index = new AlphabeticIndexVN(context); } - mHasValidAlphabeticIndex = true; } catch (Exception e) { - mHasValidAlphabeticIndex = false; + Log.d(TAG, "Unable to load the system index", e); } - } - - /** - * Sets the max number of the label buckets in this index. - * (ICU 51 default is 99) - */ - public void setMaxLabelCount(int count) { - if (mHasValidAlphabeticIndex) { + if (index == null) { try { - mSetMaxLabelCountMethod.invoke(mAlphabeticIndex, count); + index = new AlphabeticIndexV16(context); } catch (Exception e) { - e.printStackTrace(); + Log.d(TAG, "Unable to load the system index", e); } + } + + mBaseIndex = index == null ? new BaseIndex() : index; + + if (context.getResources().getConfiguration().locale + .getLanguage().equals(Locale.JAPANESE.getLanguage())) { + // Japanese character 他 ("misc") + mDefaultMiscLabel = "\u4ed6"; + // TODO(winsonc, omakoto): We need to handle Japanese sections better, especially the kanji } else { - super.setMaxLabelCount(count); + // Dot + mDefaultMiscLabel = MID_DOT; } } @@ -118,7 +53,7 @@ public class AlphabeticIndexCompat extends BaseAlphabeticIndex { */ public String computeSectionName(CharSequence cs) { String s = Utilities.trim(cs); - String sectionName = getBucketLabel(getBucketIndex(s)); + String sectionName = mBaseIndex.getBucketLabel(mBaseIndex.getBucketIndex(s)); if (Utilities.trim(sectionName).isEmpty() && s.length() > 0) { int c = s.codePointAt(0); boolean startsWithDigit = Character.isDigit(c); @@ -141,32 +76,150 @@ public class AlphabeticIndexCompat extends BaseAlphabeticIndex { } /** - * Returns the index of the bucket in which {@param s} should appear. - * Function is synchronized because underlying routine walks an iterator - * whose state is maintained inside the index object. + * Base class to support Alphabetic indexing if not supported by the framework. + * TODO(winsonc): disable for non-english locales */ - protected int getBucketIndex(String s) { - if (mHasValidAlphabeticIndex) { + private static class BaseIndex { + + private static final String BUCKETS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-"; + private static final int UNKNOWN_BUCKET_INDEX = BUCKETS.length() - 1; + + /** + * Returns the index of the bucket in which the given string should appear. + */ + protected int getBucketIndex(String s) { + if (s.isEmpty()) { + return UNKNOWN_BUCKET_INDEX; + } + int index = BUCKETS.indexOf(s.substring(0, 1).toUpperCase()); + if (index != -1) { + return index; + } + return UNKNOWN_BUCKET_INDEX; + } + + /** + * Returns the label for the bucket at the given index (as returned by getBucketIndex). + */ + protected String getBucketLabel(int index) { + return BUCKETS.substring(index, index + 1); + } + } + + /** + * Reflected libcore.icu.AlphabeticIndex implementation, falls back to the base + * alphabetic index. + */ + private static class AlphabeticIndexV16 extends BaseIndex { + + private Object mAlphabeticIndex; + private Method mGetBucketIndexMethod; + private Method mGetBucketLabelMethod; + + public AlphabeticIndexV16(Context context) throws Exception { + Locale curLocale = context.getResources().getConfiguration().locale; + Class clazz = Class.forName("libcore.icu.AlphabeticIndex"); + mGetBucketIndexMethod = clazz.getDeclaredMethod("getBucketIndex", String.class); + mGetBucketLabelMethod = clazz.getDeclaredMethod("getBucketLabel", int.class); + mAlphabeticIndex = clazz.getConstructor(Locale.class).newInstance(curLocale); + + if (!curLocale.getLanguage().equals(Locale.ENGLISH.getLanguage())) { + clazz.getDeclaredMethod("addLabels", Locale.class) + .invoke(mAlphabeticIndex, Locale.ENGLISH); + } + } + + /** + * Returns the index of the bucket in which {@param s} should appear. + * Function is synchronized because underlying routine walks an iterator + * whose state is maintained inside the index object. + */ + protected int getBucketIndex(String s) { try { return (Integer) mGetBucketIndexMethod.invoke(mAlphabeticIndex, s); } catch (Exception e) { e.printStackTrace(); } + return super.getBucketIndex(s); + } + + /** + * Returns the label for the bucket at the given index (as returned by getBucketIndex). + */ + protected String getBucketLabel(int index) { + try { + return (String) mGetBucketLabelMethod.invoke(mAlphabeticIndex, index); + } catch (Exception e) { + e.printStackTrace(); + } + return super.getBucketLabel(index); } - return super.getBucketIndex(s); } /** - * Returns the label for the bucket at the given index (as returned by getBucketIndex). + * Reflected android.icu.text.AlphabeticIndex implementation, falls back to the base + * alphabetic index. */ - protected String getBucketLabel(int index) { - if (mHasValidAlphabeticIndex) { + private static class AlphabeticIndexVN extends BaseIndex { + + private Object mAlphabeticIndex; + private Method mGetBucketIndexMethod; + + private Method mGetBucketMethod; + private Method mGetLabelMethod; + + public AlphabeticIndexVN(Context context) throws Exception { + // TODO: Replace this with locale list once available. + Object locales = Configuration.class.getDeclaredMethod("getLocales").invoke( + context.getResources().getConfiguration()); + int localeCount = (Integer) locales.getClass().getDeclaredMethod("size").invoke(locales); + Method localeGetter = locales.getClass().getDeclaredMethod("get", int.class); + Locale primaryLocale = localeCount == 0 ? Locale.ENGLISH : + (Locale) localeGetter.invoke(locales, 0); + + Class clazz = Class.forName("android.icu.text.AlphabeticIndex"); + mAlphabeticIndex = clazz.getConstructor(Locale.class).newInstance(primaryLocale); + + Method addLocales = clazz.getDeclaredMethod("addLabels", Locale[].class); + for (int i = 1; i < localeCount; i++) { + Locale l = (Locale) localeGetter.invoke(locales, i); + addLocales.invoke(mAlphabeticIndex, new Object[]{ new Locale[] {l}}); + } + addLocales.invoke(mAlphabeticIndex, new Object[]{ new Locale[] {Locale.ENGLISH}}); + + mAlphabeticIndex = mAlphabeticIndex.getClass() + .getDeclaredMethod("buildImmutableIndex") + .invoke(mAlphabeticIndex); + + mGetBucketIndexMethod = mAlphabeticIndex.getClass().getDeclaredMethod( + "getBucketIndex", CharSequence.class); + mGetBucketMethod = mAlphabeticIndex.getClass().getDeclaredMethod("getBucket", int.class); + mGetLabelMethod = mGetBucketMethod.getReturnType().getDeclaredMethod("getLabel"); + } + + /** + * Returns the index of the bucket in which {@param s} should appear. + */ + protected int getBucketIndex(String s) { try { - return (String) mGetBucketLabelMethod.invoke(mAlphabeticIndex, index); + return (Integer) mGetBucketIndexMethod.invoke(mAlphabeticIndex, s); + } catch (Exception e) { + e.printStackTrace(); + } + return super.getBucketIndex(s); + } + + /** + * Returns the label for the bucket at the given index + */ + protected String getBucketLabel(int index) { + try { + return (String) mGetLabelMethod.invoke( + mGetBucketMethod.invoke(mAlphabeticIndex, index)); } catch (Exception e) { e.printStackTrace(); } + return super.getBucketLabel(index); } - return super.getBucketLabel(index); } } diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java deleted file mode 100644 index 34c6663e9..000000000 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3.config; - -/** - * Defines a set of flags used to control various launcher behaviors - */ -public final class FeatureFlags { - private FeatureFlags() {} - - // Custom flags go below this - public static boolean LAUNCHER3_DISABLE_ICON_NORMALIZATION = false; - // As opposed to the new spring-loaded workspace. - public static boolean LAUNCHER3_LEGACY_WORKSPACE_DND = false; - public static boolean LAUNCHER3_LEGACY_FOLDER_ICON = false; - public static boolean LAUNCHER3_USE_SYSTEM_DRAG_DRIVER = false; - public static boolean LAUNCHER3_DISABLE_PINCH_TO_OVERVIEW = false; -} diff --git a/src/com/android/launcher3/config/ProviderConfig.java b/src/com/android/launcher3/config/ProviderConfig.java deleted file mode 100644 index 1d964b1b2..000000000 --- a/src/com/android/launcher3/config/ProviderConfig.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3.config; - -public class ProviderConfig { - - public static final String AUTHORITY = "com.android.launcher3.settings".intern(); - - public static boolean IS_DOGFOOD_BUILD = true; -} diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java index bb8ca160d..d8b83ad6c 100644 --- a/src/com/android/launcher3/folder/FolderPagedView.java +++ b/src/com/android/launcher3/folder/FolderPagedView.java @@ -365,7 +365,7 @@ public class FolderPagedView extends PagedView { setEnableOverscroll(getPageCount() > 1); // Update footer - mPageIndicator.getView().setVisibility(getPageCount() > 1 ? View.VISIBLE : View.GONE); + mPageIndicator.setVisibility(getPageCount() > 1 ? View.VISIBLE : View.GONE); // Set the gravity as LEFT or RIGHT instead of START, as START depends on the actual text. mFolder.mFolderName.setGravity(getPageCount() > 1 ? (mIsRtl ? Gravity.RIGHT : Gravity.LEFT) : Gravity.CENTER_HORIZONTAL); diff --git a/src/com/android/launcher3/pageindicators/PageIndicator.java b/src/com/android/launcher3/pageindicators/PageIndicator.java index 77c579c93..7c5949598 100644 --- a/src/com/android/launcher3/pageindicators/PageIndicator.java +++ b/src/com/android/launcher3/pageindicators/PageIndicator.java @@ -1,16 +1,37 @@ package com.android.launcher3.pageindicators; +import android.content.Context; +import android.util.AttributeSet; import android.view.View; -import java.util.ArrayList; +/** + * Base class for a page indicator. + */ +public abstract class PageIndicator extends View { -public interface PageIndicator { - View getView(); - void setScroll(int currentScroll, int totalScroll); + protected int mNumPages = 1; - void setActiveMarker(int activePage); + public PageIndicator(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - void addMarker(); - void removeMarker(); - void setMarkersCount(int numMarkers); + public abstract void setScroll(int currentScroll, int totalScroll); + + public abstract void setActiveMarker(int activePage); + + public void addMarker() { + mNumPages++; + onPageCountChanged(); + } + + public void removeMarker() { + mNumPages--; + onPageCountChanged(); + } + public void setMarkersCount(int numMarkers) { + mNumPages = numMarkers; + onPageCountChanged(); + } + + protected abstract void onPageCountChanged(); } diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorDots.java b/src/com/android/launcher3/pageindicators/PageIndicatorDots.java index 4a1238ddd..7d84a0c76 100644 --- a/src/com/android/launcher3/pageindicators/PageIndicatorDots.java +++ b/src/com/android/launcher3/pageindicators/PageIndicatorDots.java @@ -42,7 +42,7 @@ import com.android.launcher3.Utilities; * {@link PageIndicator} which shows dots per page. The active page is shown with the current * accent color. */ -public class PageIndicatorDots extends View implements PageIndicator { +public class PageIndicatorDots extends PageIndicator { private static final float SHIFT_PER_ANIMATION = 0.5f; private static final float SHIFT_THRESHOLD = 0.1f; @@ -90,7 +90,6 @@ public class PageIndicatorDots extends View implements PageIndicator { private final int mInActiveColor; private final boolean mIsRtl; - private int mNumPages; private int mActivePage; /** @@ -131,11 +130,6 @@ public class PageIndicatorDots extends View implements PageIndicator { } @Override - public View getView() { - return this; - } - - @Override public void setScroll(int currentScroll, int totalScroll) { if (mNumPages > 1) { if (mIsRtl) { @@ -235,20 +229,7 @@ public class PageIndicatorDots extends View implements PageIndicator { } @Override - public void addMarker() { - mNumPages++; - requestLayout(); - } - - @Override - public void removeMarker() { - mNumPages--; - requestLayout(); - } - - @Override - public void setMarkersCount(int numMarkers) { - mNumPages = numMarkers; + protected void onPageCountChanged() { requestLayout(); } diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorLine.java b/src/com/android/launcher3/pageindicators/PageIndicatorLine.java index e48168616..a358e7be0 100644 --- a/src/com/android/launcher3/pageindicators/PageIndicatorLine.java +++ b/src/com/android/launcher3/pageindicators/PageIndicatorLine.java @@ -25,7 +25,7 @@ import com.android.launcher3.dynamicui.ExtractedColors; * * The fraction is 1 / number of pages and the position is based on the progress of the page scroll. */ -public class PageIndicatorLine extends View implements PageIndicator { +public class PageIndicatorLine extends PageIndicator { private static final String TAG = "PageIndicatorLine"; private static final int LINE_FADE_DURATION = ViewConfiguration.getScrollBarFadeDuration(); @@ -38,7 +38,6 @@ public class PageIndicatorLine extends View implements PageIndicator { private ValueAnimator mLineAlphaAnimator; private int mAlpha = 0; private float mProgress = 0f; - private int mNumPages = 1; private Paint mLinePaint; private static final Property<PageIndicatorLine, Integer> PAINT_ALPHA @@ -78,8 +77,6 @@ public class PageIndicatorLine extends View implements PageIndicator { @Override protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - if (mNumPages == 0) { return; } @@ -92,11 +89,6 @@ public class PageIndicatorLine extends View implements PageIndicator { } @Override - public View getView() { - return this; - } - - @Override public void setScroll(int currentScroll, int totalScroll) { if (getAlpha() == 0) { return; @@ -115,18 +107,8 @@ public class PageIndicatorLine extends View implements PageIndicator { } @Override - public void addMarker() { - mNumPages++; - } - - @Override - public void removeMarker() { - mNumPages--; - } - - @Override - public void setMarkersCount(int numMarkers) { - mNumPages = numMarkers; + protected void onPageCountChanged() { + invalidate(); } /** diff --git a/src/com/android/launcher3/widget/WidgetsListAdapter.java b/src/com/android/launcher3/widget/WidgetsListAdapter.java index de966f9f1..e68450d60 100644 --- a/src/com/android/launcher3/widget/WidgetsListAdapter.java +++ b/src/com/android/launcher3/widget/WidgetsListAdapter.java @@ -51,14 +51,13 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> { private static final String TAG = "WidgetsListAdapter"; private static final boolean DEBUG = false; - private Launcher mLauncher; - private LayoutInflater mLayoutInflater; + private final WidgetPreviewLoader mWidgetPreviewLoader; + private final LayoutInflater mLayoutInflater; - private WidgetsModel mWidgetsModel; - private WidgetPreviewLoader mWidgetPreviewLoader; + private final View.OnClickListener mIconClickListener; + private final View.OnLongClickListener mIconLongClickListener; - private View.OnClickListener mIconClickListener; - private View.OnLongClickListener mIconLongClickListener; + private WidgetsModel mWidgetsModel; private final int mIndent; @@ -66,10 +65,10 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> { View.OnLongClickListener iconLongClickListener, Launcher launcher) { mLayoutInflater = launcher.getLayoutInflater(); + mWidgetPreviewLoader = LauncherAppState.getInstance().getWidgetCache(); mIconClickListener = iconClickListener; mIconLongClickListener = iconLongClickListener; - mLauncher = launcher; mIndent = launcher.getResources().getDimensionPixelSize(R.dimen.widget_section_indent); } @@ -89,7 +88,7 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> { public void onBindViewHolder(WidgetsRowViewHolder holder, int pos) { List<WidgetItem> infoList = mWidgetsModel.getSortedWidgets(pos); - ViewGroup row = ((ViewGroup) holder.getContent().findViewById(R.id.widgets_cell_list)); + ViewGroup row = holder.cellContainer; if (DEBUG) { Log.d(TAG, String.format( "onBindViewHolder [pos=%d, widget#=%d, row.getChildCount=%d]", @@ -122,14 +121,9 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> { } // Bind the views in the application info section. - PackageItemInfo infoOut = mWidgetsModel.getPackageItemInfo(pos); - BubbleTextView tv = ((BubbleTextView) holder.getContent().findViewById(R.id.section)); - tv.applyFromPackageItemInfo(infoOut); + holder.title.applyFromPackageItemInfo(mWidgetsModel.getPackageItemInfo(pos)); // Bind the view in the widget horizontal tray region. - if (getWidgetPreviewLoader() == null) { - return; - } for (int i=0; i < infoList.size(); i++) { WidgetCell widget = (WidgetCell) row.getChildAt(i); widget.applyFromCellItem(infoList.get(i), mWidgetPreviewLoader); @@ -162,10 +156,9 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> { @Override public void onViewRecycled(WidgetsRowViewHolder holder) { - ViewGroup row = ((ViewGroup) holder.getContent().findViewById(R.id.widgets_cell_list)); - - for (int i = 0; i < row.getChildCount(); i++) { - WidgetCell widget = (WidgetCell) row.getChildAt(i); + int total = holder.cellContainer.getChildCount(); + for (int i = 0; i < total; i++) { + WidgetCell widget = (WidgetCell) holder.cellContainer.getChildAt(i); widget.clear(); } } @@ -182,11 +175,4 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> { public long getItemId(int pos) { return pos; } - - private WidgetPreviewLoader getWidgetPreviewLoader() { - if (mWidgetPreviewLoader == null) { - mWidgetPreviewLoader = LauncherAppState.getInstance().getWidgetCache(); - } - return mWidgetPreviewLoader; - } } diff --git a/src/com/android/launcher3/widget/WidgetsRecyclerView.java b/src/com/android/launcher3/widget/WidgetsRecyclerView.java index 9c13b44fc..2e3cc1aa1 100644 --- a/src/com/android/launcher3/widget/WidgetsRecyclerView.java +++ b/src/com/android/launcher3/widget/WidgetsRecyclerView.java @@ -91,19 +91,14 @@ public class WidgetsRecyclerView extends BaseRecyclerView { @Override public String scrollToPositionAtProgress(float touchFraction) { // Skip early if widgets are not bound. - if (mWidgets == null) { - return ""; - } - - // Skip early if there are no widgets. - int rowCount = mWidgets.getPackageSize(); - if (rowCount == 0) { + if (isModelNotReady()) { return ""; } // Stop the scroller if it is scrolling stopScroll(); + int rowCount = mWidgets.getPackageSize(); getCurScrollState(mScrollPosState, -1); float pos = rowCount * touchFraction; int availableScrollHeight = getAvailableScrollHeight(rowCount); @@ -121,14 +116,7 @@ public class WidgetsRecyclerView extends BaseRecyclerView { @Override public void onUpdateScrollbar(int dy) { // Skip early if widgets are not bound. - if (mWidgets == null) { - return; - } - - // Skip early if there are no widgets. - int rowCount = mWidgets.getPackageSize(); - if (rowCount == 0) { - mScrollbar.setThumbOffset(-1, -1); + if (isModelNotReady()) { return; } @@ -139,7 +127,7 @@ public class WidgetsRecyclerView extends BaseRecyclerView { return; } - synchronizeScrollBarThumbOffsetToViewScroll(mScrollPosState, rowCount); + synchronizeScrollBarThumbOffsetToViewScroll(mScrollPosState, mWidgets.getPackageSize()); } /** @@ -151,15 +139,10 @@ public class WidgetsRecyclerView extends BaseRecyclerView { stateOut.itemPos = -1; // Skip early if widgets are not bound. - if (mWidgets == null) { + if (isModelNotReady()) { return; } - // Return early if there are no items - int rowCount = mWidgets.getPackageSize(); - if (rowCount == 0) { - return; - } View child = getChildAt(0); int position = getChildPosition(child); @@ -178,4 +161,8 @@ public class WidgetsRecyclerView extends BaseRecyclerView { View child = getChildAt(0); return child.getMeasuredHeight() * rowIndex; } + + private boolean isModelNotReady() { + return mWidgets == null || mWidgets.getPackageSize() == 0; + } }
\ No newline at end of file diff --git a/src/com/android/launcher3/widget/WidgetsRowViewHolder.java b/src/com/android/launcher3/widget/WidgetsRowViewHolder.java index 19bc868a4..bc85db610 100644 --- a/src/com/android/launcher3/widget/WidgetsRowViewHolder.java +++ b/src/com/android/launcher3/widget/WidgetsRowViewHolder.java @@ -18,16 +18,18 @@ package com.android.launcher3.widget; import android.support.v7.widget.RecyclerView.ViewHolder; import android.view.ViewGroup; +import com.android.launcher3.BubbleTextView; +import com.android.launcher3.R; + public class WidgetsRowViewHolder extends ViewHolder { - ViewGroup mContent; + public final ViewGroup cellContainer; + public final BubbleTextView title; public WidgetsRowViewHolder(ViewGroup v) { super(v); - mContent = v; - } - ViewGroup getContent() { - return mContent; + cellContainer = (ViewGroup) v.findViewById(R.id.widgets_cell_list); + title = (BubbleTextView) v.findViewById(R.id.section); } } |