Search in sources :

Example 11 with Utilities.getPrefs

use of com.android.launcher3.Utilities.getPrefs in project android_packages_apps_Trebuchet by LineageOS.

the class GridSizeMigrationTask method migrateGridIfNeeded.

/**
 * Run the migration algorithm if needed. For preview, we provide the intended idp because it
 * has not been changed. If idp is null, we read it from the context, for actual grid migration.
 *
 * @return false if the migration failed.
 */
public static boolean migrateGridIfNeeded(Context context, InvariantDeviceProfile idp) {
    boolean migrateForPreview = idp != null;
    if (!migrateForPreview) {
        idp = LauncherAppState.getIDP(context);
    }
    if (!needsToMigrate(context, idp)) {
        return true;
    }
    SharedPreferences prefs = Utilities.getPrefs(context);
    String gridSizeString = getPointString(idp.numColumns, idp.numRows);
    long migrationStartTime = SystemClock.elapsedRealtime();
    try (SQLiteTransaction transaction = (SQLiteTransaction) Settings.call(context.getContentResolver(), Settings.METHOD_NEW_TRANSACTION).getBinder(Settings.EXTRA_VALUE)) {
        int srcHotseatCount = prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numHotseatIcons);
        Point sourceSize = parsePoint(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, gridSizeString));
        boolean dbChanged = false;
        if (migrateForPreview) {
            copyTable(transaction.getDb(), Favorites.TABLE_NAME, transaction.getDb(), Favorites.PREVIEW_TABLE_NAME, context);
        }
        GridBackupTable backupTable = new GridBackupTable(context, transaction.getDb(), srcHotseatCount, sourceSize.x, sourceSize.y);
        if (migrateForPreview ? backupTable.restoreToPreviewIfBackupExists() : backupTable.backupOrRestoreAsNeeded()) {
            dbChanged = true;
            srcHotseatCount = backupTable.getRestoreHotseatAndGridSize(sourceSize);
        }
        HashSet<String> validPackages = getValidPackages(context);
        // Hotseat.
        if (srcHotseatCount != idp.numHotseatIcons && new GridSizeMigrationTask(context, transaction.getDb(), validPackages, migrateForPreview, srcHotseatCount, idp.numHotseatIcons).migrateHotseat()) {
            dbChanged = true;
        }
        // Grid size
        Point targetSize = new Point(idp.numColumns, idp.numRows);
        if (new MultiStepMigrationTask(validPackages, context, transaction.getDb(), migrateForPreview).migrate(sourceSize, targetSize)) {
            dbChanged = true;
        }
        if (dbChanged) {
            // Make sure we haven't removed everything.
            final Cursor c = context.getContentResolver().query(migrateForPreview ? Favorites.PREVIEW_CONTENT_URI : Favorites.CONTENT_URI, null, null, null, null);
            boolean hasData = c.moveToNext();
            c.close();
            if (!hasData) {
                throw new Exception("Removed every thing during grid resize");
            }
        }
        transaction.commit();
        if (!migrateForPreview) {
            Settings.call(context.getContentResolver(), Settings.METHOD_REFRESH_BACKUP_TABLE);
        }
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Error during preview grid migration", e);
        return false;
    } finally {
        Log.v(TAG, "Preview workspace migration completed in " + (SystemClock.elapsedRealtime() - migrationStartTime));
        if (!migrateForPreview) {
            // Save current configuration, so that the migration does not run again.
            prefs.edit().putString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, gridSizeString).putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numHotseatIcons).apply();
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction) Utilities.getPointString(com.android.launcher3.Utilities.getPointString) Utilities.parsePoint(com.android.launcher3.Utilities.parsePoint) Point(android.graphics.Point) Cursor(android.database.Cursor) Utilities.parsePoint(com.android.launcher3.Utilities.parsePoint) Point(android.graphics.Point)

Example 12 with Utilities.getPrefs

use of com.android.launcher3.Utilities.getPrefs in project Neo-Launcher by NeoApplications.

the class Launcher method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    RaceConditionTracker.onEvent(ON_CREATE_EVT, ENTER);
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }
    TraceHelper.beginSection("Launcher-onCreate");
    super.onCreate(savedInstanceState);
    TraceHelper.partitionSection("Launcher-onCreate", "super call");
    LauncherAppState app = LauncherAppState.getInstance(this);
    OmegaPreferences prefs = Utilities.getOmegaPrefs(this);
    prefs.getDrawerGridSize();
    prefs.getGridSize();
    prefs.getDockGridSize();
    mOldConfig = new Configuration(getResources().getConfiguration());
    mModel = app.setLauncher(this);
    mRotationHelper = new RotationHelper(this);
    InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
    initDeviceProfile(idp);
    idp.addOnChangeListener(this);
    mSharedPrefs = Utilities.getPrefs(this);
    mIconCache = app.getIconCache();
    mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);
    mDragController = new DragController(this);
    mAllAppsController = new AllAppsTransitionController(this);
    mStateManager = new LauncherStateManager(this);
    UiFactory.onCreate(this);
    mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
    mAppWidgetHost = new LauncherAppWidgetHost(this, appWidgetId -> getWorkspace().removeWidget(appWidgetId));
    mAppWidgetHost.startListening();
    mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null);
    setupViews();
    mPopupDataProvider = new PopupDataProvider(this);
    mAppTransitionManager = LauncherAppTransitionManager.newInstance(this);
    boolean internalStateHandled = InternalStateHandler.handleCreate(this, getIntent());
    if (internalStateHandled) {
        if (savedInstanceState != null) {
            // InternalStateHandler has already set the appropriate state.
            // We dont need to do anything.
            savedInstanceState.remove(RUNTIME_STATE);
        }
    }
    restoreState(savedInstanceState);
    mStateManager.reapplyState();
    // We only load the page synchronously if the user rotates (or triggers a
    // configuration change) while launcher is in the foreground
    int currentScreen = PagedView.INVALID_RESTORE_PAGE;
    if (savedInstanceState != null) {
        currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
    }
    if (!mModel.startLoader(currentScreen)) {
        if (!internalStateHandled) {
            // If we are not binding synchronously, show a fade in animation when
            // the first page bind completes.
            mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD).setValue(0);
        }
    } else {
        // Pages bound synchronously.
        mWorkspace.setCurrentPage(currentScreen);
        setWorkspaceLoading(true);
    }
    // For handling default keys
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    setContentView(mLauncherView);
    getRootView().dispatchInsets();
    // Listen for broadcasts
    registerReceiver(mScreenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
    getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW, Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onCreate(savedInstanceState);
    }
    mRotationHelper.initialize();
    TraceHelper.endSection("Launcher-onCreate");
    RaceConditionTracker.onEvent(ON_CREATE_EVT, EXIT);
    mStateManager.addStateListener(new LauncherStateManager.StateListener() {

        @Override
        public void onStateTransitionStart(LauncherState toState) {
        }

        @Override
        public void onStateTransitionComplete(LauncherState finalState) {
            float alpha = 1f - mCurrentAssistantVisibility;
            if (finalState == NORMAL) {
                mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
            } else if (finalState == OVERVIEW || finalState == OVERVIEW_PEEK) {
                mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
                mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(alpha);
            } else {
                mAppsView.getAlphaProperty(APPS_VIEW_ALPHA_CHANNEL_INDEX).setValue(1f);
                mScrimView.getAlphaProperty(SCRIM_VIEW_ALPHA_CHANNEL_INDEX).setValue(1f);
            }
        }
    });
}
Also used : Bundle(android.os.Bundle) AllAppsTransitionController(com.android.launcher3.allapps.AllAppsTransitionController) ViewOnDrawExecutor(com.android.launcher3.util.ViewOnDrawExecutor) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) CustomActionsPopup(com.android.launcher3.keyboard.CustomActionsPopup) CONFIG_ORIENTATION(android.content.pm.ActivityInfo.CONFIG_ORIENTATION) OVERVIEW(com.android.launcher3.LauncherState.OVERVIEW) CustomWidgetParser(com.android.launcher3.widget.custom.CustomWidgetParser) Process(android.os.Process) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Handler(android.os.Handler) Display(android.view.Display) Target(com.android.launcher3.userevent.nano.LauncherLogProto.Target) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) OmegaLauncher(com.saggitt.omega.OmegaLauncher) RotationMode(com.android.launcher3.graphics.RotationMode) TargetApi(android.annotation.TargetApi) Log(android.util.Log) OVERVIEW_PEEK(com.android.launcher3.LauncherState.OVERVIEW_PEEK) PrintWriter(java.io.PrintWriter) KeyboardShortcutInfo(android.view.KeyboardShortcutInfo) ALPHA_INDEX_LAUNCHER_LOAD(com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_LAUNCHER_LOAD) IntentFilter(android.content.IntentFilter) AllAppsStore(com.android.launcher3.allapps.AllAppsStore) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) LauncherAccessibilityDelegate(com.android.launcher3.accessibility.LauncherAccessibilityDelegate) Nullable(androidx.annotation.Nullable) ShortcutUtil(com.android.launcher3.util.ShortcutUtil) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) ItemInfoMatcher(com.android.launcher3.util.ItemInfoMatcher) DiscoveryBounce(com.android.launcher3.allapps.DiscoveryBounce) TextKeyListener(android.text.method.TextKeyListener) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) NORMAL(com.android.launcher3.LauncherState.NORMAL) LauncherLogProto(com.android.launcher3.userevent.nano.LauncherLogProto) TYPE_REBIND_SAFE(com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE) ViewGroupFocusHelper(com.android.launcher3.keyboard.ViewGroupFocusHelper) FileLog(com.android.launcher3.logging.FileLog) UserEventDispatcher(com.android.launcher3.logging.UserEventDispatcher) InternalStateHandler(com.android.launcher3.states.InternalStateHandler) SystemUiController(com.android.launcher3.util.SystemUiController) AppLaunchTracker(com.android.launcher3.model.AppLaunchTracker) ArrayList(java.util.ArrayList) IntentSender(android.content.IntentSender) REQUEST_NONE(com.android.launcher3.states.RotationHelper.REQUEST_NONE) AppWidgetHostView(android.appwidget.AppWidgetHostView) PendingRequestArgs(com.android.launcher3.util.PendingRequestArgs) Toast(android.widget.Toast) Menu(android.view.Menu) DragObject(com.android.launcher3.DropTarget.DragObject) TYPE_ALL(com.android.launcher3.AbstractFloatingView.TYPE_ALL) PopupDataProvider(com.android.launcher3.popup.PopupDataProvider) IntArray(com.android.launcher3.util.IntArray) Parcelable(android.os.Parcelable) ActivityContext(com.android.launcher3.views.ActivityContext) DragController(com.android.launcher3.dragndrop.DragController) TextUtils(android.text.TextUtils) FeatureFlags(com.android.launcher3.config.FeatureFlags) ItemClickHandler(com.android.launcher3.touch.ItemClickHandler) EXIT(com.android.launcher3.util.RaceConditionTracker.EXIT) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentCallbacks2(android.content.ComponentCallbacks2) ENTER(com.android.launcher3.util.RaceConditionTracker.ENTER) FolderGridOrganizer(com.android.launcher3.folder.FolderGridOrganizer) SharedPreferences(android.content.SharedPreferences) Configuration(android.content.res.Configuration) ComponentKey(com.android.launcher3.util.ComponentKey) AlphaProperty(com.android.launcher3.util.MultiValueAlpha.AlphaProperty) ValueAnimator(android.animation.ValueAnimator) DotInfo(com.android.launcher3.dot.DotInfo) Rect(android.graphics.Rect) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) PackageManager(android.content.pm.PackageManager) SPRING_LOADED_EXIT_DELAY(com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY) LauncherAppsCompatVO(com.android.launcher3.compat.LauncherAppsCompatVO) Animator(android.animation.Animator) IconCache(com.android.launcher3.icons.IconCache) OptionsPopupView(com.android.launcher3.views.OptionsPopupView) WidgetsFullSheet(com.android.launcher3.widget.WidgetsFullSheet) UiFactory(com.android.launcher3.uioverrides.UiFactory) ActivityOptions(android.app.ActivityOptions) KeyboardShortcutGroup(android.view.KeyboardShortcutGroup) RotationHelper(com.android.launcher3.states.RotationHelper) View(android.view.View) Predicate(java.util.function.Predicate) ObjectAnimator(android.animation.ObjectAnimator) Collection(java.util.Collection) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) MultiValueAlpha(com.android.launcher3.util.MultiValueAlpha) SparseArray(android.util.SparseArray) List(java.util.List) ALL_APPS(com.android.launcher3.LauncherState.ALL_APPS) NotificationListener(com.android.launcher3.notification.NotificationListener) OmegaPreferences(com.saggitt.omega.OmegaPreferences) ActivityNotFoundException(android.content.ActivityNotFoundException) WidgetHostViewLoader(com.android.launcher3.widget.WidgetHostViewLoader) FolderNameProvider(com.android.launcher3.folder.FolderNameProvider) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) Themes(com.android.launcher3.util.Themes) ModelWriter(com.android.launcher3.model.ModelWriter) Context(android.content.Context) CONFIG_SCREEN_SIZE(android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE) KeyEvent(android.view.KeyEvent) ActivityResultInfo(com.android.launcher3.util.ActivityResultInfo) WidgetAddFlowHandler(com.android.launcher3.widget.WidgetAddFlowHandler) TYPE_SNACKBAR(com.android.launcher3.AbstractFloatingView.TYPE_SNACKBAR) FolderIcon(com.android.launcher3.folder.FolderIcon) Intent(android.content.Intent) HashMap(java.util.HashMap) UiThreadHelper(com.android.launcher3.util.UiThreadHelper) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) HashSet(java.util.HashSet) LoggerUtils.newTarget(com.android.launcher3.logging.LoggerUtils.newTarget) AnimatorSet(android.animation.AnimatorSet) DragLayer(com.android.launcher3.dragndrop.DragLayer) Build(android.os.Build) StatsLogUtils(com.android.launcher3.logging.StatsLogUtils) Action(com.android.launcher3.userevent.nano.LauncherLogProto.Action) ContainerType(com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType) LayoutInflater(android.view.LayoutInflater) PackageUserKey(com.android.launcher3.util.PackageUserKey) Point(android.graphics.Point) RaceConditionTracker(com.android.launcher3.util.RaceConditionTracker) AppWidgetManagerCompat(com.android.launcher3.compat.AppWidgetManagerCompat) WidgetListRowEntry(com.android.launcher3.widget.WidgetListRowEntry) PropertyListBuilder(com.android.launcher3.anim.PropertyListBuilder) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) StrictMode(android.os.StrictMode) OvershootInterpolator(android.view.animation.OvershootInterpolator) LoggerUtils.newContainerTarget(com.android.launcher3.logging.LoggerUtils.newContainerTarget) FileDescriptor(java.io.FileDescriptor) UserEventDelegate(com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate) ScrimView(com.android.launcher3.views.ScrimView) Thunk(com.android.launcher3.util.Thunk) VisibleForTesting(androidx.annotation.VisibleForTesting) DragView(com.android.launcher3.dragndrop.DragView) TraceHelper(com.android.launcher3.util.TraceHelper) IntentFilter(android.content.IntentFilter) Configuration(android.content.res.Configuration) RotationHelper(com.android.launcher3.states.RotationHelper) PropertyListBuilder(com.android.launcher3.anim.PropertyListBuilder) PopupDataProvider(com.android.launcher3.popup.PopupDataProvider) OmegaPreferences(com.saggitt.omega.OmegaPreferences) Point(android.graphics.Point) StrictMode(android.os.StrictMode) AllAppsTransitionController(com.android.launcher3.allapps.AllAppsTransitionController) DragController(com.android.launcher3.dragndrop.DragController) LauncherAccessibilityDelegate(com.android.launcher3.accessibility.LauncherAccessibilityDelegate)

Example 13 with Utilities.getPrefs

use of com.android.launcher3.Utilities.getPrefs in project Neo-Launcher by NeoApplications.

the class InvariantDeviceProfile method initGrid.

private String initGrid(Context context, String gridName) {
    DefaultDisplay.Info displayInfo = DefaultDisplay.INSTANCE.get(context).getInfo();
    Point smallestSize = new Point(displayInfo.smallestSize);
    Point largestSize = new Point(displayInfo.largestSize);
    // This guarantees that width < height
    float minWidthDps = Utilities.dpiFromPx(Math.min(smallestSize.x, smallestSize.y), displayInfo.metrics);
    float minHeightDps = Utilities.dpiFromPx(Math.min(largestSize.x, largestSize.y), displayInfo.metrics);
    Point realSize = new Point(displayInfo.realSize);
    // The real size never changes. smallSide and largeSide will remain the
    // same in any orientation.
    int smallSide = Math.min(realSize.x, realSize.y);
    int largeSide = max(realSize.x, realSize.y);
    // We want a list of all options as well as the list of filtered options. This allows us
    // to have a consistent UI for areas that the grid size change should not affect
    // ie. All Apps should be consistent between grid sizes.
    ArrayList<DisplayOption> allOptions = new ArrayList<>();
    ArrayList<DisplayOption> filteredOptions = new ArrayList<>();
    getPredefinedDeviceProfiles(context, gridName, filteredOptions, allOptions);
    if (allOptions.isEmpty() && filteredOptions.isEmpty()) {
        throw new RuntimeException("No display option with canBeDefault=true");
    }
    // Sort the profiles based on the closeness to the device size
    Comparator<DisplayOption> comparator = (a, b) -> Float.compare(dist(minWidthDps, minHeightDps, a.minWidthDps, a.minHeightDps), dist(minWidthDps, minHeightDps, b.minWidthDps, b.minHeightDps));
    // Calculate the device profiles as if there is no grid override.
    Collections.sort(allOptions, comparator);
    DisplayOption interpolatedDisplayOption = invDistWeightedInterpolate(minWidthDps, minHeightDps, allOptions);
    initGridOption(context, allOptions, interpolatedDisplayOption, displayInfo.metrics);
    // Create IDP with no grid override values.
    InvariantDeviceProfile originalIDP = new InvariantDeviceProfile(this);
    originalIDP.landscapeProfile = new DeviceProfile(context, this, null, smallestSize, largestSize, largeSide, smallSide, true, /* isLandscape */
    false);
    originalIDP.portraitProfile = new DeviceProfile(context, this, null, smallestSize, largestSize, smallSide, largeSide, false, /* isLandscape */
    false);
    if (filteredOptions.isEmpty()) {
        filteredOptions = allOptions;
        landscapeProfile = originalIDP.landscapeProfile;
        portraitProfile = originalIDP.portraitProfile;
    } else {
        Collections.sort(filteredOptions, comparator);
        interpolatedDisplayOption = invDistWeightedInterpolate(minWidthDps, minHeightDps, filteredOptions);
        initGridOption(context, filteredOptions, interpolatedDisplayOption, displayInfo.metrics);
        numAllAppsColumns = originalIDP.numAllAppsColumns;
        landscapeProfile = new DeviceProfile(context, this, originalIDP, smallestSize, largestSize, largeSide, smallSide, true, /* isLandscape */
        false);
        portraitProfile = new DeviceProfile(context, this, originalIDP, smallestSize, largestSize, smallSide, largeSide, false, /* isLandscape */
        false);
    }
    GridOption closestProfile = filteredOptions.get(0).grid;
    if (!closestProfile.name.equals(gridName)) {
        Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, closestProfile.name).apply();
    }
    // for the intended parallax effects
    if (context.getResources().getConfiguration().smallestScreenWidthDp >= 720) {
        defaultWallpaperSize = new Point((int) (largeSide * wallpaperTravelToScreenWidthRatio(largeSide, smallSide)), largeSide);
    } else {
        defaultWallpaperSize = new Point(max(smallSide * 2, largeSide), largeSide);
    }
    ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
    defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
    return closestProfile.name;
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) APPLY_CONFIG_AT_RUNTIME(com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME) XmlResourceParser(android.content.res.XmlResourceParser) Intent(android.content.Intent) IconShape(com.android.launcher3.graphics.IconShape) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) DefaultDisplay(com.android.launcher3.util.DefaultDisplay) Utilities.getDevicePrefs(com.android.launcher3.Utilities.getDevicePrefs) AttributeSet(android.util.AttributeSet) AppWidgetHostView(android.appwidget.AppWidgetHostView) MAIN_EXECUTOR(com.android.launcher3.util.Executors.MAIN_EXECUTOR) TargetApi(android.annotation.TargetApi) Log(android.util.Log) IconShapeManager(com.saggitt.omega.adaptive.IconShapeManager) XmlPullParser(org.xmlpull.v1.XmlPullParser) IntArray(com.android.launcher3.util.IntArray) MainThreadInitializedObject(com.android.launcher3.util.MainThreadInitializedObject) GRID_OPTIONS_PREFERENCE_KEY(com.saggitt.omega.settings.SettingsActivity.GRID_OPTIONS_PREFERENCE_KEY) Xml(android.util.Xml) ComponentName(android.content.ComponentName) Point(android.graphics.Point) TextUtils(android.text.TextUtils) IOException(java.io.IOException) BroadcastReceiver(android.content.BroadcastReceiver) DisplayMetrics(android.util.DisplayMetrics) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) SparseArray(android.util.SparseArray) Nullable(androidx.annotation.Nullable) ConfigMonitor(com.android.launcher3.util.ConfigMonitor) PackageManagerHelper.getPackageFilter(com.android.launcher3.util.PackageManagerHelper.getPackageFilter) TypedValue(android.util.TypedValue) OmegaPreferences(com.saggitt.omega.OmegaPreferences) Configuration(android.content.res.Configuration) Math.max(java.lang.Math.max) Themes(com.android.launcher3.util.Themes) Comparator(java.util.Comparator) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) Resources(android.content.res.Resources) DefaultDisplay(com.android.launcher3.util.DefaultDisplay) ArrayList(java.util.ArrayList) Point(android.graphics.Point) Point(android.graphics.Point) ComponentName(android.content.ComponentName)

Example 14 with Utilities.getPrefs

use of com.android.launcher3.Utilities.getPrefs in project Neo-Launcher by NeoApplications.

the class GridSizeMigrationTask method migrateGridIfNeeded.

/**
 * Migrates the workspace and hotseat in case their sizes changed.
 *
 * @return false if the migration failed.
 */
public static boolean migrateGridIfNeeded(Context context) {
    SharedPreferences prefs = Utilities.getPrefs(context);
    InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
    String gridSizeString = getPointString(idp.numColumns, idp.numRows);
    if (gridSizeString.equals(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, "")) && idp.numHotseatIcons == prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numHotseatIcons)) {
        // Skip if workspace and hotseat sizes have not changed.
        return true;
    }
    long migrationStartTime = System.currentTimeMillis();
    try (SQLiteTransaction transaction = (SQLiteTransaction) Settings.call(context.getContentResolver(), Settings.METHOD_NEW_TRANSACTION).getBinder(Settings.EXTRA_VALUE)) {
        int srcHotseatCount = prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numHotseatIcons);
        Point sourceSize = parsePoint(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, gridSizeString));
        boolean dbChanged = false;
        GridBackupTable backupTable = new GridBackupTable(context, transaction.getDb(), srcHotseatCount, sourceSize.x, sourceSize.y);
        if (backupTable.backupOrRestoreAsNeeded()) {
            dbChanged = true;
            srcHotseatCount = backupTable.getRestoreHotseatAndGridSize(sourceSize);
        }
        HashSet<String> validPackages = getValidPackages(context);
        // Hotseat
        if (srcHotseatCount != idp.numHotseatIcons) {
            // Migrate hotseat.
            dbChanged = new GridSizeMigrationTask(context, transaction.getDb(), validPackages, srcHotseatCount, idp.numHotseatIcons).migrateHotseat();
        }
        // Grid size
        Point targetSize = new Point(idp.numColumns, idp.numRows);
        if (new MultiStepMigrationTask(validPackages, context, transaction.getDb()).migrate(sourceSize, targetSize)) {
            dbChanged = true;
        }
        if (dbChanged) {
            // Make sure we haven't removed everything.
            final Cursor c = context.getContentResolver().query(Favorites.CONTENT_URI, null, null, null, null);
            boolean hasData = c.moveToNext();
            c.close();
            if (!hasData) {
                throw new Exception("Removed every thing during grid resize");
            }
        }
        transaction.commit();
        Settings.call(context.getContentResolver(), Settings.METHOD_REFRESH_BACKUP_TABLE);
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Error during grid migration", e);
        return false;
    } finally {
        Log.v(TAG, "Workspace migration completed in " + (System.currentTimeMillis() - migrationStartTime));
        // Save current configuration, so that the migration does not run again.
        prefs.edit().putString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, gridSizeString).putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numHotseatIcons).apply();
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) SQLiteTransaction(com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction) Utilities.getPointString(com.android.launcher3.Utilities.getPointString) Utilities.parsePoint(com.android.launcher3.Utilities.parsePoint) Point(android.graphics.Point) Cursor(android.database.Cursor) Utilities.parsePoint(com.android.launcher3.Utilities.parsePoint) Point(android.graphics.Point)

Example 15 with Utilities.getPrefs

use of com.android.launcher3.Utilities.getPrefs in project Neo-Launcher by NeoApplications.

the class OmegaLauncherCallbacks method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    mPrefs = Utilities.getPrefs(mLauncher);
    mOverlayCallbacks = new OverlayCallbackImpl(mLauncher);
    mLauncherClient = new CustomLauncherClient(mLauncher, mOverlayCallbacks, getClientOptions(mPrefs));
    mQsbController = new QsbAnimationController(mLauncher);
    mOverlayCallbacks.setClient(mLauncherClient);
    mUiInformation.putInt("system_ui_visibility", mLauncher.getWindow().getDecorView().getSystemUiVisibility());
    applyFeedTheme(false);
    WallpaperColorInfo instance = WallpaperColorInfo.getInstance(mLauncher);
    instance.addOnChangeListener(this);
    onExtractedColorsChanged(instance);
    mPrefs.registerOnSharedPreferenceChangeListener(this);
    predictionUiStateManager = PredictionUiStateManager.INSTANCE.get(mLauncher);
    predictionUiStateManager.setTargetAppsView(mLauncher.getAppsView());
    if (FeatureFlags.REFLECTION_FORCE_OVERVIEW_MODE) {
        predictionUiStateManager.switchClient(Client.OVERVIEW);
    }
}
Also used : CustomLauncherClient(com.saggitt.omega.util.CustomLauncherClient) QsbAnimationController(com.saggitt.omega.qsb.QsbAnimationController) WallpaperColorInfo(com.android.launcher3.uioverrides.WallpaperColorInfo)

Aggregations

SharedPreferences (android.content.SharedPreferences)23 Point (android.graphics.Point)15 Utilities.getPointString (com.android.launcher3.Utilities.getPointString)11 SQLiteTransaction (com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction)10 Intent (android.content.Intent)8 Configuration (android.content.res.Configuration)8 TargetApi (android.annotation.TargetApi)7 IntentFilter (android.content.IntentFilter)7 StrictMode (android.os.StrictMode)7 DragObject (com.android.launcher3.DropTarget.DragObject)7 AllAppsTransitionController (com.android.launcher3.allapps.AllAppsTransitionController)7 PropertyListBuilder (com.android.launcher3.anim.PropertyListBuilder)7 PopupDataProvider (com.android.launcher3.popup.PopupDataProvider)7 RotationHelper (com.android.launcher3.states.RotationHelper)7 ArrayList (java.util.ArrayList)7 Resources (android.content.res.Resources)6 Notification (android.app.Notification)5 AppWidgetHost (android.appwidget.AppWidgetHost)5 LauncherAppWidgetHost (com.android.launcher3.widget.LauncherAppWidgetHost)5 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)5