Search in sources :

Example 11 with EXIT

use of com.android.launcher3.util.RaceConditionTracker.EXIT in project Launcher3 by chislon.

the class CellLayout method animateChildToPosition.

public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, int delay, boolean permanent, boolean adjustOccupied) {
    ShortcutAndWidgetContainer clc = getShortcutsAndWidgets();
    boolean[][] occupied = mOccupied;
    if (!permanent) {
        occupied = mTmpOccupied;
    }
    if (clc.indexOfChild(child) != -1) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final ItemInfo info = (ItemInfo) child.getTag();
        // We cancel any existing animations
        if (mReorderAnimators.containsKey(lp)) {
            mReorderAnimators.get(lp).cancel();
            mReorderAnimators.remove(lp);
        }
        final int oldX = lp.x;
        final int oldY = lp.y;
        if (adjustOccupied) {
            occupied[lp.cellX][lp.cellY] = false;
            occupied[cellX][cellY] = true;
        }
        lp.isLockedToGrid = true;
        if (permanent) {
            lp.cellX = info.cellX = cellX;
            lp.cellY = info.cellY = cellY;
        } else {
            lp.tmpCellX = cellX;
            lp.tmpCellY = cellY;
        }
        clc.setupLp(lp);
        lp.isLockedToGrid = false;
        final int newX = lp.x;
        final int newY = lp.y;
        lp.x = oldX;
        lp.y = oldY;
        // Exit early if we're not actually moving the view
        if (oldX == newX && oldY == newY) {
            lp.isLockedToGrid = true;
            return true;
        }
        ValueAnimator va = LauncherAnimUtils.ofFloat(child, 0f, 1f);
        va.setDuration(duration);
        mReorderAnimators.put(lp, va);
        va.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float r = ((Float) animation.getAnimatedValue()).floatValue();
                lp.x = (int) ((1 - r) * oldX + r * newX);
                lp.y = (int) ((1 - r) * oldY + r * newY);
                child.requestLayout();
            }
        });
        va.addListener(new AnimatorListenerAdapter() {

            boolean cancelled = false;

            public void onAnimationEnd(Animator animation) {
                // place just yet.
                if (!cancelled) {
                    lp.isLockedToGrid = true;
                    child.requestLayout();
                }
                if (mReorderAnimators.containsKey(lp)) {
                    mReorderAnimators.remove(lp);
                }
            }

            public void onAnimationCancel(Animator animation) {
                cancelled = true;
            }
        });
        va.setStartDelay(delay);
        va.start();
        return true;
    }
    return false;
}
Also used : FolderRingAnimator(com.android.launcher3.FolderIcon.FolderRingAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 12 with EXIT

use of com.android.launcher3.util.RaceConditionTracker.EXIT in project android_packages_apps_404Launcher by P-404.

the class CellLayout method animateChildToPosition.

public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, int delay, boolean permanent, boolean adjustOccupied) {
    ShortcutAndWidgetContainer clc = getShortcutsAndWidgets();
    if (clc.indexOfChild(child) != -1 && (child instanceof Reorderable)) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final ItemInfo info = (ItemInfo) child.getTag();
        final Reorderable item = (Reorderable) child;
        // We cancel any existing animations
        if (mReorderAnimators.containsKey(lp)) {
            mReorderAnimators.get(lp).cancel();
            mReorderAnimators.remove(lp);
        }
        if (adjustOccupied) {
            GridOccupancy occupied = permanent ? mOccupied : mTmpOccupied;
            occupied.markCells(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, false);
            occupied.markCells(cellX, cellY, lp.cellHSpan, lp.cellVSpan, true);
        }
        // Compute the new x and y position based on the new cellX and cellY
        // We leverage the actual layout logic in the layout params and hence need to modify
        // state and revert that state.
        final int oldX = lp.x;
        final int oldY = lp.y;
        lp.isLockedToGrid = true;
        if (permanent) {
            lp.cellX = info.cellX = cellX;
            lp.cellY = info.cellY = cellY;
        } else {
            lp.tmpCellX = cellX;
            lp.tmpCellY = cellY;
        }
        clc.setupLp(child);
        final int newX = lp.x;
        final int newY = lp.y;
        lp.x = oldX;
        lp.y = oldY;
        lp.isLockedToGrid = false;
        // End compute new x and y
        item.getReorderPreviewOffset(mTmpPointF);
        final float initPreviewOffsetX = mTmpPointF.x;
        final float initPreviewOffsetY = mTmpPointF.y;
        final float finalPreviewOffsetX = newX - oldX;
        final float finalPreviewOffsetY = newY - oldY;
        // Exit early if we're not actually moving the view
        if (finalPreviewOffsetX == 0 && finalPreviewOffsetY == 0 && initPreviewOffsetX == 0 && initPreviewOffsetY == 0) {
            lp.isLockedToGrid = true;
            return true;
        }
        ValueAnimator va = ValueAnimator.ofFloat(0f, 1f);
        va.setDuration(duration);
        mReorderAnimators.put(lp, va);
        va.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float r = (Float) animation.getAnimatedValue();
                float x = (1 - r) * initPreviewOffsetX + r * finalPreviewOffsetX;
                float y = (1 - r) * initPreviewOffsetY + r * finalPreviewOffsetY;
                item.setReorderPreviewOffset(x, y);
            }
        });
        va.addListener(new AnimatorListenerAdapter() {

            boolean cancelled = false;

            public void onAnimationEnd(Animator animation) {
                // place just yet.
                if (!cancelled) {
                    lp.isLockedToGrid = true;
                    item.setReorderPreviewOffset(0, 0);
                    child.requestLayout();
                }
                if (mReorderAnimators.containsKey(lp)) {
                    mReorderAnimators.remove(lp);
                }
            }

            public void onAnimationCancel(Animator animation) {
                cancelled = true;
            }
        });
        va.setStartDelay(delay);
        va.start();
        return true;
    }
    return false;
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) GridOccupancy(com.android.launcher3.util.GridOccupancy) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 13 with EXIT

use of com.android.launcher3.util.RaceConditionTracker.EXIT in project android_packages_apps_404Launcher by P-404.

the class WidgetsDiffReporter method process.

/**
 * Notifies the difference between {@code currentEntries} & {@code newEntries} by calling the
 * relevant {@link androidx.recyclerview.widget.RecyclerView.RecyclerViewDataObserver} methods.
 */
public void process(ArrayList<WidgetsListBaseEntry> currentEntries, List<WidgetsListBaseEntry> newEntries, WidgetListBaseRowEntryComparator comparator) {
    if (DEBUG) {
        Log.d(TAG, "process oldEntries#=" + currentEntries.size() + " newEntries#=" + newEntries.size());
    }
    // Early exit if either of the list is empty
    if (currentEntries.isEmpty() || newEntries.isEmpty()) {
        // when the bind actually completes.
        if (currentEntries.size() != newEntries.size()) {
            currentEntries.clear();
            currentEntries.addAll(newEntries);
            mListener.notifyDataSetChanged();
        }
        return;
    }
    ArrayList<WidgetsListBaseEntry> orgEntries = (ArrayList<WidgetsListBaseEntry>) currentEntries.clone();
    Iterator<WidgetsListBaseEntry> orgIter = orgEntries.iterator();
    Iterator<WidgetsListBaseEntry> newIter = newEntries.iterator();
    WidgetsListBaseEntry orgRowEntry = orgIter.next();
    WidgetsListBaseEntry newRowEntry = newIter.next();
    do {
        int diff = compareAppNameAndType(orgRowEntry, newRowEntry, comparator);
        if (DEBUG) {
            Log.d(TAG, String.format("diff=%d orgRowEntry (%s) newRowEntry (%s)", diff, orgRowEntry != null ? orgRowEntry.toString() : null, newRowEntry != null ? newRowEntry.toString() : null));
        }
        int index = -1;
        if (diff < 0) {
            index = currentEntries.indexOf(orgRowEntry);
            mListener.notifyItemRemoved(index);
            if (DEBUG) {
                Log.d(TAG, String.format("notifyItemRemoved called (%d)%s", index, orgRowEntry.mTitleSectionName));
            }
            currentEntries.remove(index);
            orgRowEntry = orgIter.hasNext() ? orgIter.next() : null;
        } else if (diff > 0) {
            index = orgRowEntry != null ? currentEntries.indexOf(orgRowEntry) : currentEntries.size();
            currentEntries.add(index, newRowEntry);
            if (DEBUG) {
                Log.d(TAG, String.format("notifyItemInserted called (%d)%s", index, newRowEntry.mTitleSectionName));
            }
            newRowEntry = newIter.hasNext() ? newIter.next() : null;
            mListener.notifyItemInserted(index);
        } else {
            // or did the widget size and desc, span, etc change?
            if (!isSamePackageItemInfo(orgRowEntry.mPkgItem, newRowEntry.mPkgItem) || hasHeaderUpdated(orgRowEntry, newRowEntry) || hasWidgetsListContentChanged(orgRowEntry, newRowEntry)) {
                index = currentEntries.indexOf(orgRowEntry);
                currentEntries.set(index, newRowEntry);
                mListener.notifyItemChanged(index);
                if (DEBUG) {
                    Log.d(TAG, String.format("notifyItemChanged called (%d)%s", index, newRowEntry.mTitleSectionName));
                }
            }
            orgRowEntry = orgIter.hasNext() ? orgIter.next() : null;
            newRowEntry = newIter.hasNext() ? newIter.next() : null;
        }
    } while (orgRowEntry != null || newRowEntry != null);
}
Also used : WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ArrayList(java.util.ArrayList)

Example 14 with EXIT

use of com.android.launcher3.util.RaceConditionTracker.EXIT in project android_packages_apps_404Launcher by P-404.

the class LauncherModel method startLoader.

private boolean startLoader(Callbacks[] newCallbacks) {
    // Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
    ItemInstallQueue.INSTANCE.get(mApp.getContext()).pauseModelPush(ItemInstallQueue.FLAG_LOADER_RUNNING);
    synchronized (mLock) {
        // If there is already one running, tell it to stop.
        boolean wasRunning = stopLoader();
        boolean bindDirectly = mModelLoaded && !mIsLoaderTaskRunning;
        boolean bindAllCallbacks = wasRunning || !bindDirectly || newCallbacks.length == 0;
        final Callbacks[] callbacksList = bindAllCallbacks ? getCallbacks() : newCallbacks;
        if (callbacksList.length > 0) {
            // Clear any pending bind-runnables from the synchronized load process.
            for (Callbacks cb : callbacksList) {
                MAIN_EXECUTOR.execute(cb::clearPendingBinds);
            }
            LoaderResults loaderResults = new LoaderResults(mApp, mBgDataModel, mBgAllAppsList, callbacksList);
            if (bindDirectly) {
                // Divide the set of loaded items into those that we are binding synchronously,
                // and everything else that is to be bound normally (asynchronously).
                loaderResults.bindWorkspace(bindAllCallbacks);
                // For now, continue posting the binding of AllApps as there are other
                // issues that arise from that.
                loaderResults.bindAllApps();
                loaderResults.bindDeepShortcuts();
                loaderResults.bindWidgets();
                return true;
            } else {
                stopLoader();
                mLoaderTask = new LoaderTask(mApp, mBgAllAppsList, mBgDataModel, mModelDelegate, loaderResults);
                // Always post the loader task, instead of running directly
                // (even on same thread) so that we exit any nested synchronized blocks
                MODEL_EXECUTOR.post(mLoaderTask);
            }
        }
    }
    return false;
}
Also used : Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) LoaderTask(com.android.launcher3.model.LoaderTask) LoaderResults(com.android.launcher3.model.LoaderResults)

Example 15 with EXIT

use of com.android.launcher3.util.RaceConditionTracker.EXIT in project Neo-Launcher by NeoApplications.

the class CellLayout method animateChildToPosition.

public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, int delay, boolean permanent, boolean adjustOccupied) {
    ShortcutAndWidgetContainer clc = getShortcutsAndWidgets();
    if (clc.indexOfChild(child) != -1) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final ItemInfo info = (ItemInfo) child.getTag();
        // We cancel any existing animations
        if (mReorderAnimators.containsKey(lp)) {
            mReorderAnimators.get(lp).cancel();
            mReorderAnimators.remove(lp);
        }
        final int oldX = lp.x;
        final int oldY = lp.y;
        if (adjustOccupied) {
            GridOccupancy occupied = permanent ? mOccupied : mTmpOccupied;
            occupied.markCells(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, false);
            occupied.markCells(cellX, cellY, lp.cellHSpan, lp.cellVSpan, true);
        }
        lp.isLockedToGrid = true;
        if (permanent) {
            lp.cellX = info.cellX = cellX;
            lp.cellY = info.cellY = cellY;
        } else {
            lp.tmpCellX = cellX;
            lp.tmpCellY = cellY;
        }
        clc.setupLp(child);
        lp.isLockedToGrid = false;
        final int newX = lp.x;
        final int newY = lp.y;
        lp.x = oldX;
        lp.y = oldY;
        // Exit early if we're not actually moving the view
        if (oldX == newX && oldY == newY) {
            lp.isLockedToGrid = true;
            return true;
        }
        ValueAnimator va = ValueAnimator.ofFloat(0f, 1f);
        va.setDuration(duration);
        mReorderAnimators.put(lp, va);
        va.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float r = (Float) animation.getAnimatedValue();
                lp.x = (int) ((1 - r) * oldX + r * newX);
                lp.y = (int) ((1 - r) * oldY + r * newY);
                child.requestLayout();
            }
        });
        va.addListener(new AnimatorListenerAdapter() {

            boolean cancelled = false;

            public void onAnimationEnd(Animator animation) {
                // place just yet.
                if (!cancelled) {
                    lp.isLockedToGrid = true;
                    child.requestLayout();
                }
                if (mReorderAnimators.containsKey(lp)) {
                    mReorderAnimators.remove(lp);
                }
            }

            public void onAnimationCancel(Animator animation) {
                cancelled = true;
            }
        });
        va.setStartDelay(delay);
        va.start();
        return true;
    }
    return false;
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) GridOccupancy(com.android.launcher3.util.GridOccupancy) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Aggregations

Point (android.graphics.Point)11 Animator (android.animation.Animator)9 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)9 ValueAnimator (android.animation.ValueAnimator)9 ObjectAnimator (android.animation.ObjectAnimator)8 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)8 Paint (android.graphics.Paint)8 SuppressLint (android.annotation.SuppressLint)7 LoaderTask (com.android.launcher3.model.LoaderTask)7 Callbacks (com.android.launcher3.model.BgDataModel.Callbacks)6 GridOccupancy (com.android.launcher3.util.GridOccupancy)6 ArrayList (java.util.ArrayList)6 LoaderResults (com.android.launcher3.model.LoaderResults)5 ItemInfo (com.android.launcher3.model.data.ItemInfo)5 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)5 Rect (android.graphics.Rect)3 Resources (android.content.res.Resources)2 DropTarget (com.android.launcher3.DropTarget)2 AnimatorSet (android.animation.AnimatorSet)1 TargetApi (android.annotation.TargetApi)1