Search in sources :

Example 1 with INSTANT

use of com.android.launcher3.anim.Interpolators.INSTANT in project android_packages_apps_Launcher3 by crdroidandroid.

the class FolderPagedView method realTimeReorder.

/**
 * Reorders the items such that the {@param empty} spot moves to {@param target}
 */
public void realTimeReorder(int empty, int target) {
    if (!mViewsBound) {
        return;
    }
    completePendingPageChanges();
    int delay = 0;
    float delayAmount = START_VIEW_REORDER_DELAY;
    // Animation only happens on the current page.
    int pageToAnimate = getNextPage();
    int maxItemsPerPage = mOrganizer.getMaxItemsPerPage();
    int pageT = target / maxItemsPerPage;
    int pagePosT = target % maxItemsPerPage;
    if (pageT != pageToAnimate) {
        Log.e(TAG, "Cannot animate when the target cell is invisible");
    }
    int pagePosE = empty % maxItemsPerPage;
    int pageE = empty / maxItemsPerPage;
    int startPos, endPos;
    int moveStart, moveEnd;
    int direction;
    if (target == empty) {
        // No animation
        return;
    } else if (target > empty) {
        // Items will move backwards to make room for the empty cell.
        direction = 1;
        // If empty cell is in a different page, move them instantly.
        if (pageE < pageToAnimate) {
            moveStart = empty;
            // Instantly move the first item in the current page.
            moveEnd = pageToAnimate * maxItemsPerPage;
            // Animate the 2nd item in the current page, as the first item was already moved to
            // the last page.
            startPos = 0;
        } else {
            moveStart = moveEnd = -1;
            startPos = pagePosE;
        }
        endPos = pagePosT;
    } else {
        // The items will move forward.
        direction = -1;
        if (pageE > pageToAnimate) {
            // Move the items immediately.
            moveStart = empty;
            // Instantly move the last item in the current page.
            moveEnd = (pageToAnimate + 1) * maxItemsPerPage - 1;
            // Animations start with the second last item in the page
            startPos = maxItemsPerPage - 1;
        } else {
            moveStart = moveEnd = -1;
            startPos = pagePosE;
        }
        endPos = pagePosT;
    }
    // Instant moving views.
    while (moveStart != moveEnd) {
        int rankToMove = moveStart + direction;
        int p = rankToMove / maxItemsPerPage;
        int pagePos = rankToMove % maxItemsPerPage;
        int x = pagePos % mGridCountX;
        int y = pagePos / mGridCountX;
        final CellLayout page = getPageAt(p);
        final View v = page.getChildAt(x, y);
        if (v != null) {
            if (pageToAnimate != p) {
                page.removeView(v);
                addViewForRank(v, (WorkspaceItemInfo) v.getTag(), moveStart);
            } else {
                // Do a fake animation before removing it.
                final int newRank = moveStart;
                final float oldTranslateX = v.getTranslationX();
                Runnable endAction = new Runnable() {

                    @Override
                    public void run() {
                        mPendingAnimations.remove(v);
                        v.setTranslationX(oldTranslateX);
                        ((CellLayout) v.getParent().getParent()).removeView(v);
                        addViewForRank(v, (WorkspaceItemInfo) v.getTag(), newRank);
                    }
                };
                v.animate().translationXBy((direction > 0 ^ mIsRtl) ? -v.getWidth() : v.getWidth()).setDuration(REORDER_ANIMATION_DURATION).setStartDelay(0).withEndAction(endAction);
                mPendingAnimations.put(v, endAction);
            }
        }
        moveStart = rankToMove;
    }
    if ((endPos - startPos) * direction <= 0) {
        // No animation
        return;
    }
    CellLayout page = getPageAt(pageToAnimate);
    for (int i = startPos; i != endPos; i += direction) {
        int nextPos = i + direction;
        View v = page.getChildAt(nextPos % mGridCountX, nextPos / mGridCountX);
        if (page.animateChildToPosition(v, i % mGridCountX, i / mGridCountX, REORDER_ANIMATION_DURATION, delay, true, true)) {
            delay += delayAmount;
            delayAmount *= VIEW_REORDER_DELAY_FACTOR;
        }
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout) ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) SuppressLint(android.annotation.SuppressLint)

Example 2 with INSTANT

use of com.android.launcher3.anim.Interpolators.INSTANT in project android_packages_apps_Launcher3 by crdroidandroid.

the class PackageInstallStateChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    if (mInstallInfo.state == PackageInstallInfo.STATUS_INSTALLED) {
        try {
            // For instant apps we do not get package-add. Use setting events to update
            // any pinned icons.
            ApplicationInfo ai = app.getContext().getPackageManager().getApplicationInfo(mInstallInfo.packageName, 0);
            if (InstantAppResolver.newInstance(app.getContext()).isInstantApp(ai)) {
                app.getModel().onPackageAdded(ai.packageName, mInstallInfo.user);
            }
        } catch (PackageManager.NameNotFoundException e) {
        // Ignore
        }
        // Ignore install success events as they are handled by Package add events.
        return;
    }
    synchronized (apps) {
        List<AppInfo> updatedAppInfos = apps.updatePromiseInstallInfo(mInstallInfo);
        if (!updatedAppInfos.isEmpty()) {
            for (AppInfo appInfo : updatedAppInfos) {
                scheduleCallbackTask(c -> c.bindIncrementalDownloadProgressUpdated(appInfo));
            }
        }
        bindApplicationsIfNeeded();
    }
    synchronized (dataModel) {
        final HashSet<ItemInfo> updates = new HashSet<>();
        dataModel.forAllWorkspaceItemInfos(mInstallInfo.user, si -> {
            if (si.hasPromiseIconUi() && mInstallInfo.packageName.equals(si.getTargetPackage())) {
                si.setProgressLevel(mInstallInfo);
                updates.add(si);
            }
        });
        for (LauncherAppWidgetInfo widget : dataModel.appWidgets) {
            if (widget.providerName.getPackageName().equals(mInstallInfo.packageName)) {
                widget.installProgress = mInstallInfo.progress;
                updates.add(widget);
            }
        }
        if (!updates.isEmpty()) {
            scheduleCallbackTask(callbacks -> callbacks.bindRestoreItemsChange(updates));
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ItemInfo(com.android.launcher3.model.data.ItemInfo) ApplicationInfo(android.content.pm.ApplicationInfo) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) AppInfo(com.android.launcher3.model.data.AppInfo) HashSet(java.util.HashSet)

Example 3 with INSTANT

use of com.android.launcher3.anim.Interpolators.INSTANT in project android_packages_apps_Launcher3 by crdroidandroid.

the class ItemClickHandler method startAppShortcutOrInfoActivity.

private static void startAppShortcutOrInfoActivity(View v, ItemInfo item, Launcher launcher) {
    TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "start: startAppShortcutOrInfoActivity");
    Intent intent;
    if (item instanceof ItemInfoWithIcon && (((ItemInfoWithIcon) item).runtimeStatusFlags & ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE) != 0) {
        ItemInfoWithIcon appInfo = (ItemInfoWithIcon) item;
        intent = new PackageManagerHelper(launcher).getMarketIntent(appInfo.getTargetComponent().getPackageName());
    } else {
        intent = item.getIntent();
    }
    if (intent == null) {
        throw new IllegalArgumentException("Input must have a valid intent");
    }
    if (item instanceof WorkspaceItemInfo) {
        WorkspaceItemInfo si = (WorkspaceItemInfo) item;
        if (si.hasStatusFlag(WorkspaceItemInfo.FLAG_SUPPORTS_WEB_UI) && Intent.ACTION_VIEW.equals(intent.getAction())) {
            // make a copy of the intent that has the package set to null
            // we do this because the platform sometimes disables instant
            // apps temporarily (triggered by the user) and fallbacks to the
            // web ui. This only works though if the package isn't set
            intent = new Intent(intent);
            intent.setPackage(null);
        }
    }
    if (v != null && launcher.supportsAdaptiveIconAnimation(v)) {
        // Preload the icon to reduce latency b/w swapping the floating view with the original.
        FloatingIconView.fetchIcon(launcher, v, item, true);
    }
    TrustDatabaseHelper db = TrustDatabaseHelper.getInstance(launcher);
    ComponentName cn = item.getTargetComponent();
    boolean isProtected = cn != null && db.isPackageProtected(cn.getPackageName());
    if (isProtected) {
        launcher.startActivitySafelyAuth(v, intent, item);
    } else {
        launcher.startActivitySafely(v, intent, item);
    }
}
Also used : TrustDatabaseHelper(com.android.launcher3.lineage.trust.db.TrustDatabaseHelper) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) ComponentName(android.content.ComponentName) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 4 with INSTANT

use of com.android.launcher3.anim.Interpolators.INSTANT in project android_packages_apps_Launcher3 by crdroidandroid.

the class QuickstepAtomicAnimationFactory method prepareForAtomicAnimation.

@Override
public void prepareForAtomicAnimation(LauncherState fromState, LauncherState toState, StateAnimationConfig config) {
    RecentsView overview = mActivity.getOverviewPanel();
    if (toState == NORMAL && fromState == OVERVIEW) {
        config.setInterpolator(ANIM_OVERVIEW_ACTIONS_FADE, clampToProgress(LINEAR, 0, 0.25f));
        config.setInterpolator(ANIM_SCRIM_FADE, LINEAR);
        config.setInterpolator(ANIM_WORKSPACE_SCALE, DEACCEL);
        config.setInterpolator(ANIM_WORKSPACE_FADE, ACCEL);
        if (SysUINavigationMode.getMode(mActivity).hasGestures && overview.getTaskViewCount() > 0) {
            // Overview is going offscreen, so keep it at its current scale and opacity.
            config.setInterpolator(ANIM_OVERVIEW_SCALE, FINAL_FRAME);
            config.setInterpolator(ANIM_OVERVIEW_FADE, FINAL_FRAME);
            config.setInterpolator(ANIM_OVERVIEW_TRANSLATE_X, clampToProgress(FAST_OUT_SLOW_IN, 0, 0.75f));
            config.setInterpolator(ANIM_OVERVIEW_TRANSLATE_Y, FINAL_FRAME);
        } else {
            config.setInterpolator(ANIM_OVERVIEW_TRANSLATE_X, ACCEL_DEACCEL);
            config.setInterpolator(ANIM_OVERVIEW_SCALE, clampToProgress(ACCEL, 0, 0.9f));
            config.setInterpolator(ANIM_OVERVIEW_FADE, DEACCEL_1_7);
        }
        // Scroll RecentsView to page 0 as it goes offscreen, if necessary.
        int numPagesToScroll = overview.getNextPage() - DEFAULT_PAGE;
        long scrollDuration = Math.min(MAX_PAGE_SCROLL_DURATION, numPagesToScroll * PER_PAGE_SCROLL_DURATION);
        config.duration = Math.max(config.duration, scrollDuration);
        overview.snapToPage(DEFAULT_PAGE, Math.toIntExact(config.duration));
        Workspace workspace = mActivity.getWorkspace();
        // Start from a higher workspace scale, but only if we're invisible so we don't jump.
        boolean isWorkspaceVisible = workspace.getVisibility() == VISIBLE;
        if (isWorkspaceVisible) {
            CellLayout currentChild = (CellLayout) workspace.getChildAt(workspace.getCurrentPage());
            isWorkspaceVisible = currentChild.getVisibility() == VISIBLE && currentChild.getShortcutsAndWidgets().getAlpha() > 0;
        }
        if (!isWorkspaceVisible) {
            workspace.setScaleX(WORKSPACE_PREPARE_SCALE);
            workspace.setScaleY(WORKSPACE_PREPARE_SCALE);
        }
        Hotseat hotseat = mActivity.getHotseat();
        boolean isHotseatVisible = hotseat.getVisibility() == VISIBLE && hotseat.getAlpha() > 0;
        if (!isHotseatVisible) {
            hotseat.setScaleX(WORKSPACE_PREPARE_SCALE);
            hotseat.setScaleY(WORKSPACE_PREPARE_SCALE);
        }
    } else if ((fromState == NORMAL || fromState == HINT_STATE || fromState == HINT_STATE_TWO_BUTTON) && toState == OVERVIEW) {
        if (SysUINavigationMode.getMode(mActivity).hasGestures) {
            config.setInterpolator(ANIM_WORKSPACE_SCALE, fromState == NORMAL ? ACCEL : OVERSHOOT_1_2);
            config.setInterpolator(ANIM_WORKSPACE_TRANSLATE, ACCEL);
            // Scrolling in tasks, so show straight away
            if (overview.getTaskViewCount() > 0) {
                config.setInterpolator(ANIM_OVERVIEW_FADE, INSTANT);
            } else {
                config.setInterpolator(ANIM_OVERVIEW_FADE, OVERSHOOT_1_2);
            }
        } else {
            config.setInterpolator(ANIM_WORKSPACE_SCALE, OVERSHOOT_1_2);
            config.setInterpolator(ANIM_OVERVIEW_FADE, OVERSHOOT_1_2);
            // Scale up the recents, if it is not coming from the side
            if (overview.getVisibility() != VISIBLE || overview.getContentAlpha() == 0) {
                RECENTS_SCALE_PROPERTY.set(overview, RECENTS_PREPARE_SCALE);
            }
        }
        config.setInterpolator(ANIM_WORKSPACE_FADE, OVERSHOOT_1_2);
        config.setInterpolator(ANIM_ALL_APPS_FADE, OVERSHOOT_1_2);
        config.setInterpolator(ANIM_OVERVIEW_SCALE, OVERSHOOT_1_2);
        config.setInterpolator(ANIM_DEPTH, OVERSHOOT_1_2);
        config.setInterpolator(ANIM_SCRIM_FADE, t -> {
            // Animate at the same rate until reaching progress 1, and skip the overshoot.
            return Math.min(1, OVERSHOOT_1_2.getInterpolation(t));
        });
        config.setInterpolator(ANIM_OVERVIEW_TRANSLATE_X, OVERSHOOT_1_2);
        config.setInterpolator(ANIM_OVERVIEW_TRANSLATE_Y, OVERSHOOT_1_2);
    } else if (fromState == HINT_STATE && toState == NORMAL) {
        config.setInterpolator(ANIM_DEPTH, DEACCEL_3);
        if (mHintToNormalDuration == -1) {
            ValueAnimator va = getSpringScaleAnimator(mActivity, mActivity.getWorkspace(), toState.getWorkspaceScaleAndTranslation(mActivity).scale);
            mHintToNormalDuration = (int) va.getDuration();
        }
        config.duration = Math.max(config.duration, mHintToNormalDuration);
    }
}
Also used : ANIM_OVERVIEW_FADE(com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_FADE) ANIM_WORKSPACE_TRANSLATE(com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_TRANSLATE) Interpolators.clampToProgress(com.android.launcher3.anim.Interpolators.clampToProgress) DEACCEL(com.android.launcher3.anim.Interpolators.DEACCEL) ANIM_OVERVIEW_TRANSLATE_X(com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_X) OVERVIEW(com.android.launcher3.LauncherState.OVERVIEW) INSTANT(com.android.launcher3.anim.Interpolators.INSTANT) OVERSHOOT_1_2(com.android.launcher3.anim.Interpolators.OVERSHOOT_1_2) ANIM_OVERVIEW_TRANSLATE_Y(com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_Y) DEACCEL_1_7(com.android.launcher3.anim.Interpolators.DEACCEL_1_7) FAST_OUT_SLOW_IN(com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN) ANIM_OVERVIEW_SCALE(com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SCALE) VISIBLE(android.view.View.VISIBLE) SysUINavigationMode(com.android.quickstep.SysUINavigationMode) QuickstepLauncher(com.android.launcher3.uioverrides.QuickstepLauncher) ANIM_WORKSPACE_SCALE(com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_SCALE) ANIM_OVERVIEW_ACTIONS_FADE(com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_ACTIONS_FADE) DEACCEL_3(com.android.launcher3.anim.Interpolators.DEACCEL_3) RecentsAtomicAnimationFactory(com.android.quickstep.util.RecentsAtomicAnimationFactory) CellLayout(com.android.launcher3.CellLayout) LauncherState(com.android.launcher3.LauncherState) WorkspaceStateTransitionAnimation.getSpringScaleAnimator(com.android.launcher3.WorkspaceStateTransitionAnimation.getSpringScaleAnimator) LINEAR(com.android.launcher3.anim.Interpolators.LINEAR) Hotseat(com.android.launcher3.Hotseat) ANIM_DEPTH(com.android.launcher3.states.StateAnimationConfig.ANIM_DEPTH) RECENTS_SCALE_PROPERTY(com.android.quickstep.views.RecentsView.RECENTS_SCALE_PROPERTY) FINAL_FRAME(com.android.launcher3.anim.Interpolators.FINAL_FRAME) StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig) ANIM_WORKSPACE_FADE(com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_FADE) ANIM_ALL_APPS_FADE(com.android.launcher3.states.StateAnimationConfig.ANIM_ALL_APPS_FADE) RecentsView(com.android.quickstep.views.RecentsView) Workspace(com.android.launcher3.Workspace) ANIM_SCRIM_FADE(com.android.launcher3.states.StateAnimationConfig.ANIM_SCRIM_FADE) HINT_STATE(com.android.launcher3.LauncherState.HINT_STATE) NORMAL(com.android.launcher3.LauncherState.NORMAL) HINT_STATE_TWO_BUTTON(com.android.launcher3.LauncherState.HINT_STATE_TWO_BUTTON) ACCEL(com.android.launcher3.anim.Interpolators.ACCEL) ACCEL_DEACCEL(com.android.launcher3.anim.Interpolators.ACCEL_DEACCEL) ValueAnimator(android.animation.ValueAnimator) Hotseat(com.android.launcher3.Hotseat) CellLayout(com.android.launcher3.CellLayout) RecentsView(com.android.quickstep.views.RecentsView) ValueAnimator(android.animation.ValueAnimator) Workspace(com.android.launcher3.Workspace)

Aggregations

CellLayout (com.android.launcher3.CellLayout)2 ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 View (android.view.View)1 VISIBLE (android.view.View.VISIBLE)1 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)1 BubbleTextView (com.android.launcher3.BubbleTextView)1 Hotseat (com.android.launcher3.Hotseat)1 LauncherState (com.android.launcher3.LauncherState)1 HINT_STATE (com.android.launcher3.LauncherState.HINT_STATE)1 HINT_STATE_TWO_BUTTON (com.android.launcher3.LauncherState.HINT_STATE_TWO_BUTTON)1 NORMAL (com.android.launcher3.LauncherState.NORMAL)1 OVERVIEW (com.android.launcher3.LauncherState.OVERVIEW)1 PagedView (com.android.launcher3.PagedView)1 Workspace (com.android.launcher3.Workspace)1