Search in sources :

Example 1 with StateManager

use of com.android.launcher3.statemanager.StateManager in project android_packages_apps_Launcher3 by crdroidandroid.

the class TaskViewUtils method composeRecentsSplitLaunchAnimatorLegacy.

/**
 * Legacy version (until shell transitions are enabled)
 */
public static void composeRecentsSplitLaunchAnimatorLegacy(@NonNull AnimatorSet anim, @NonNull TaskView v, @NonNull RemoteAnimationTargetCompat[] appTargets, @NonNull RemoteAnimationTargetCompat[] wallpaperTargets, @NonNull RemoteAnimationTargetCompat[] nonAppTargets, boolean launcherClosing, @NonNull StateManager stateManager, @NonNull DepthController depthController, int targetStage) {
    PendingAnimation out = new PendingAnimation(RECENTS_LAUNCH_DURATION);
    boolean isRunningTask = v.isRunningTask();
    TransformParams params = null;
    TaskViewSimulator tvs = null;
    RecentsView recentsView = v.getRecentsView();
    if (ENABLE_QUICKSTEP_LIVE_TILE.get() && isRunningTask) {
        params = recentsView.getLiveTileParams();
        tvs = recentsView.getLiveTileTaskViewSimulator();
    }
    boolean inLiveTileMode = ENABLE_QUICKSTEP_LIVE_TILE.get() && recentsView.getRunningTaskIndex() != -1;
    final RemoteAnimationTargets targets = new RemoteAnimationTargets(appTargets, wallpaperTargets, nonAppTargets, inLiveTileMode ? MODE_CLOSING : MODE_OPENING);
    if (params == null) {
        SurfaceTransactionApplier applier = new SurfaceTransactionApplier(v);
        targets.addReleaseCheck(applier);
        params = new TransformParams().setSyncTransactionApplier(applier).setTargetSet(targets);
    }
    Rect crop = new Rect();
    Context context = v.getContext();
    DeviceProfile dp = BaseActivity.fromContext(context).getDeviceProfile();
    if (tvs == null && targets.apps.length > 0) {
        tvs = new TaskViewSimulator(recentsView.getContext(), recentsView.getSizeStrategy());
        tvs.setDp(dp);
        // RecentsView never updates the display rotation until swipe-up so the value may
        // be stale. Use the display value instead.
        int displayRotation = DisplayController.INSTANCE.get(recentsView.getContext()).getInfo().rotation;
        tvs.getOrientationState().update(displayRotation, displayRotation);
        tvs.setPreview(targets.apps[targets.apps.length - 1]);
        tvs.fullScreenProgress.value = 0;
        tvs.recentsViewScale.value = 1;
        // tvs.setScroll(startScroll);
        // Fade in the task during the initial 20% of the animation
        out.addFloat(params, TransformParams.TARGET_ALPHA, 0, 1, clampToProgress(LINEAR, 0, 0.2f));
    }
    TaskViewSimulator topMostSimulator = null;
    if (tvs != null) {
        out.setFloat(tvs.fullScreenProgress, AnimatedFloat.VALUE, 1, TOUCH_RESPONSE_INTERPOLATOR);
        out.setFloat(tvs.recentsViewScale, AnimatedFloat.VALUE, tvs.getFullScreenScale(), TOUCH_RESPONSE_INTERPOLATOR);
        out.setFloat(tvs.recentsViewScroll, AnimatedFloat.VALUE, 0, TOUCH_RESPONSE_INTERPOLATOR);
        TaskViewSimulator finalTsv = tvs;
        TransformParams finalParams = params;
        out.addOnFrameCallback(() -> finalTsv.apply(finalParams));
        topMostSimulator = tvs;
    }
    anim.play(out.buildAnim());
}
Also used : Context(android.content.Context) PendingAnimation(com.android.launcher3.anim.PendingAnimation) DeviceProfile(com.android.launcher3.DeviceProfile) Rect(android.graphics.Rect) SurfaceTransactionApplier(com.android.quickstep.util.SurfaceTransactionApplier) TaskViewSimulator(com.android.quickstep.util.TaskViewSimulator) TransformParams(com.android.quickstep.util.TransformParams) RecentsView(com.android.quickstep.views.RecentsView)

Example 2 with StateManager

use of com.android.launcher3.statemanager.StateManager in project android_packages_apps_Launcher3 by crdroidandroid.

the class TaskViewUtils method composeRecentsLaunchAnimator.

public static void composeRecentsLaunchAnimator(@NonNull AnimatorSet anim, @NonNull View v, @NonNull RemoteAnimationTargetCompat[] appTargets, @NonNull RemoteAnimationTargetCompat[] wallpaperTargets, @NonNull RemoteAnimationTargetCompat[] nonAppTargets, boolean launcherClosing, @NonNull StateManager stateManager, @NonNull RecentsView recentsView, @NonNull DepthController depthController) {
    boolean skipLauncherChanges = !launcherClosing;
    TaskView taskView = findTaskViewToLaunch(recentsView, v, appTargets);
    PendingAnimation pa = new PendingAnimation(RECENTS_LAUNCH_DURATION);
    createRecentsWindowAnimator(taskView, skipLauncherChanges, appTargets, wallpaperTargets, nonAppTargets, depthController, pa);
    Animator childStateAnimation = null;
    // Found a visible recents task that matches the opening app, lets launch the app from there
    Animator launcherAnim;
    final AnimatorListenerAdapter windowAnimEndListener;
    if (launcherClosing) {
        Context context = v.getContext();
        DeviceProfile dp = BaseActivity.fromContext(context).getDeviceProfile();
        launcherAnim = dp.isTablet && FeatureFlags.ENABLE_OVERVIEW_GRID.get() ? ObjectAnimator.ofFloat(recentsView, RecentsView.CONTENT_ALPHA, 0) : recentsView.createAdjacentPageAnimForTaskLaunch(taskView);
        launcherAnim.setInterpolator(Interpolators.TOUCH_RESPONSE_INTERPOLATOR);
        launcherAnim.setDuration(RECENTS_LAUNCH_DURATION);
        // Make sure recents gets fixed up by resetting task alphas and scales, etc.
        windowAnimEndListener = new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                recentsView.finishRecentsAnimation(false, /* toRecents */
                () -> {
                    recentsView.post(() -> {
                        stateManager.moveToRestState();
                        stateManager.reapplyState();
                    });
                });
            }
        };
    } else {
        AnimatorPlaybackController controller = stateManager.createAnimationToNewWorkspace(NORMAL, RECENTS_LAUNCH_DURATION);
        controller.dispatchOnStart();
        childStateAnimation = controller.getTarget();
        launcherAnim = controller.getAnimationPlayer().setDuration(RECENTS_LAUNCH_DURATION);
        windowAnimEndListener = new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                recentsView.finishRecentsAnimation(false, /* toRecents */
                () -> stateManager.goToState(NORMAL, false));
            }
        };
    }
    pa.add(launcherAnim);
    if (ENABLE_QUICKSTEP_LIVE_TILE.get() && recentsView.getRunningTaskIndex() != -1) {
        pa.addOnFrameCallback(recentsView::redrawLiveTile);
    }
    anim.play(pa.buildAnim());
    // Set the current animation first, before adding windowAnimEndListener. Setting current
    // animation adds some listeners which need to be called before windowAnimEndListener
    // (the ordering of listeners matter in this case).
    stateManager.setCurrentAnimation(anim, childStateAnimation);
    anim.addListener(windowAnimEndListener);
}
Also used : Context(android.content.Context) PendingAnimation(com.android.launcher3.anim.PendingAnimation) DeviceProfile(com.android.launcher3.DeviceProfile) TaskView(com.android.quickstep.views.TaskView) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorPlaybackController(com.android.launcher3.anim.AnimatorPlaybackController)

Example 3 with StateManager

use of com.android.launcher3.statemanager.StateManager in project android_packages_apps_Launcher3 by crdroidandroid.

the class AbstractLauncherUiTest method checkLauncherIntegrity.

private void checkLauncherIntegrity(Launcher launcher, ContainerType expectedContainerType) {
    if (launcher != null) {
        final StateManager<LauncherState> stateManager = launcher.getStateManager();
        final LauncherState stableState = stateManager.getCurrentStableState();
        assertTrue("Stable state != state: " + stableState.getClass().getSimpleName() + ", " + stateManager.getState().getClass().getSimpleName(), stableState == stateManager.getState());
        final boolean isResumed = launcher.hasBeenResumed();
        final boolean isStarted = launcher.isStarted();
        checkLauncherState(launcher, expectedContainerType, isResumed, isStarted);
        final int ordinal = stableState.ordinal;
        switch(expectedContainerType) {
            case WORKSPACE:
            case WIDGETS:
                {
                    assertTrue("Launcher is not resumed in state: " + expectedContainerType, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
                    break;
                }
            case ALL_APPS:
                {
                    assertTrue("Launcher is not resumed in state: " + expectedContainerType, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.ALL_APPS_STATE_ORDINAL);
                    break;
                }
            case OVERVIEW:
                {
                    checkLauncherStateInOverview(launcher, expectedContainerType, isStarted, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.OVERVIEW_STATE_ORDINAL);
                    break;
                }
            case BACKGROUND:
                {
                    assertTrue("Launcher is resumed in state: " + expectedContainerType, !isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
                    break;
                }
            default:
                throw new IllegalArgumentException("Illegal container: " + expectedContainerType);
        }
    } else {
        assertTrue("Container type is not BACKGROUND or FALLBACK_OVERVIEW: " + expectedContainerType, expectedContainerType == ContainerType.BACKGROUND || expectedContainerType == ContainerType.FALLBACK_OVERVIEW);
    }
}
Also used : LauncherState(com.android.launcher3.LauncherState)

Example 4 with StateManager

use of com.android.launcher3.statemanager.StateManager in project android_packages_apps_Launcher3 by crdroidandroid.

the class Launcher method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Object traceToken = TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT, TraceHelper.FLAG_UI_EVENT);
    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());
    }
    if (Utilities.IS_DEBUG_DEVICE && FeatureFlags.NOTIFY_CRASHES.get()) {
        final String notificationChannelId = "com.android.launcher3.Debug";
        final String notificationChannelName = "Debug";
        final String notificationTag = "Debug";
        final int notificationId = 0;
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(new NotificationChannel(notificationChannelId, notificationChannelName, NotificationManager.IMPORTANCE_HIGH));
        Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> {
            String stackTrace = Log.getStackTraceString(throwable);
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(Intent.EXTRA_TEXT, stackTrace);
            shareIntent = Intent.createChooser(shareIntent, null);
            PendingIntent sharePendingIntent = PendingIntent.getActivity(this, 0, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            Notification notification = new Notification.Builder(this, notificationChannelId).setSmallIcon(android.R.drawable.ic_menu_close_clear_cancel).setContentTitle("Launcher crash detected!").setStyle(new Notification.BigTextStyle().bigText(stackTrace)).addAction(android.R.drawable.ic_menu_share, "Share", sharePendingIntent).build();
            notificationManager.notify(notificationTag, notificationId, notification);
            Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
            if (defaultUncaughtExceptionHandler != null) {
                defaultUncaughtExceptionHandler.uncaughtException(thread, throwable);
            }
        });
    }
    super.onCreate(savedInstanceState);
    LauncherAppState app = LauncherAppState.getInstance(this);
    mOldConfig = new Configuration(getResources().getConfiguration());
    mModel = app.getModel();
    mRotationHelper = new RotationHelper(this);
    InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
    initDeviceProfile(idp);
    idp.addOnChangeListener(this);
    mSharedPrefs = Utilities.getPrefs(this);
    mIconCache = app.getIconCache();
    mAccessibilityDelegate = createAccessibilityDelegate();
    mDragController = new LauncherDragController(this);
    mAllAppsController = new AllAppsTransitionController(this);
    mStateManager = new StateManager<>(this, NORMAL);
    mOnboardingPrefs = createOnboardingPrefs(mSharedPrefs);
    mAppWidgetManager = new WidgetManagerHelper(this);
    mAppWidgetHost = createAppWidgetHost();
    mAppWidgetHost.startListening();
    inflateRootView(R.layout.launcher);
    setupViews();
    crossFadeWithPreviousAppearance();
    mPopupDataProvider = new PopupDataProvider(this::updateNotificationDots);
    boolean internalStateHandled = ACTIVITY_TRACKER.handleCreate(this);
    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_PAGE;
    if (savedInstanceState != null) {
        currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
    }
    mPageToBindSynchronously = currentScreen;
    if (!mModel.addCallbacksAndLoad(this)) {
        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);
        }
    }
    // For handling default keys
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    setContentView(getRootView());
    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);
    }
    mOverlayManager = getDefaultOverlay();
    PluginManagerWrapper.INSTANCE.get(this).addPluginListener(this, OverlayPlugin.class, false);
    mRotationHelper.initialize();
    TraceHelper.INSTANCE.endSection(traceToken);
    mUserChangedCallbackCloseable = UserCache.INSTANCE.get(this).addUserChangeListener(() -> getStateManager().goToState(NORMAL));
    if (Utilities.ATLEAST_R) {
        getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
    }
}
Also used : Configuration(android.content.res.Configuration) PropertyListBuilder(com.android.launcher3.anim.PropertyListBuilder) Notification(android.app.Notification) StrictMode(android.os.StrictMode) AllAppsTransitionController(com.android.launcher3.allapps.AllAppsTransitionController) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) RotationHelper(com.android.launcher3.states.RotationHelper) PopupDataProvider(com.android.launcher3.popup.PopupDataProvider) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) NotificationChannel(android.app.NotificationChannel) DragObject(com.android.launcher3.DropTarget.DragObject) LauncherDragController(com.android.launcher3.dragndrop.LauncherDragController) PendingIntent(android.app.PendingIntent)

Example 5 with StateManager

use of com.android.launcher3.statemanager.StateManager in project android_packages_apps_Launcher3 by crdroidandroid.

the class OverviewToHomeAnim method animateWithVelocity.

/**
 * Starts the animation. If velocity < 0 (i.e. upwards), also plays a
 * {@link WorkspaceRevealAnim}.
 */
public void animateWithVelocity(float velocity) {
    StateManager<LauncherState> stateManager = mLauncher.getStateManager();
    LauncherState startState = stateManager.getState();
    if (startState != OVERVIEW) {
        Log.e(TAG, "animateFromOverviewToHome: unexpected start state " + startState);
    }
    AnimatorSet anim = new AnimatorSet();
    boolean playWorkspaceRevealAnim = velocity < 0;
    if (playWorkspaceRevealAnim) {
        WorkspaceRevealAnim workspaceRevealAnim = new WorkspaceRevealAnim(mLauncher, false);
        workspaceRevealAnim.addAnimatorListener(new AnimationSuccessListener() {

            @Override
            public void onAnimationSuccess(Animator animator) {
                mIsHomeStaggeredAnimFinished = true;
                maybeOverviewToHomeAnimComplete();
            }
        });
        anim.play(workspaceRevealAnim.getAnimators());
    } else {
        mIsHomeStaggeredAnimFinished = true;
    }
    StateAnimationConfig config = new StateAnimationConfig();
    if (playWorkspaceRevealAnim) {
        // WorkspaceRevealAnim handles the depth, so don't interfere.
        config.animFlags |= StateAnimationConfig.SKIP_DEPTH_CONTROLLER;
    }
    config.duration = startState.getTransitionDuration(mLauncher);
    AnimatorSet stateAnim = stateManager.createAtomicAnimation(startState, NORMAL, config);
    stateAnim.addListener(new AnimationSuccessListener() {

        @Override
        public void onAnimationSuccess(Animator animator) {
            mIsOverviewHidden = true;
            maybeOverviewToHomeAnimComplete();
        }
    });
    anim.play(stateAnim);
    stateManager.setCurrentAnimation(anim, NORMAL);
    anim.start();
}
Also used : LauncherState(com.android.launcher3.LauncherState) Animator(android.animation.Animator) StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig) AnimatorSet(android.animation.AnimatorSet) AnimationSuccessListener(com.android.launcher3.anim.AnimationSuccessListener)

Aggregations

Animator (android.animation.Animator)2 Context (android.content.Context)2 DeviceProfile (com.android.launcher3.DeviceProfile)2 LauncherState (com.android.launcher3.LauncherState)2 PendingAnimation (com.android.launcher3.anim.PendingAnimation)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 Notification (android.app.Notification)1 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Configuration (android.content.res.Configuration)1 Rect (android.graphics.Rect)1 StrictMode (android.os.StrictMode)1 DragObject (com.android.launcher3.DropTarget.DragObject)1 AllAppsTransitionController (com.android.launcher3.allapps.AllAppsTransitionController)1 AnimationSuccessListener (com.android.launcher3.anim.AnimationSuccessListener)1