Search in sources :

Example 1 with EXIT

use of com.android.launcher3.util.RaceConditionTracker.EXIT in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherModel method startLoader.

/**
 * Starts the loader. Tries to bind {@params synchronousBindPage} synchronously if possible.
 * @return true if the page could be bound synchronously.
 */
public boolean startLoader() {
    // Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
    ItemInstallQueue.INSTANCE.get(mApp.getContext()).pauseModelPush(ItemInstallQueue.FLAG_LOADER_RUNNING);
    synchronized (mLock) {
        // Don't bother to start the thread if we know it's not going to do anything
        final Callbacks[] callbacksList = getCallbacks();
        if (callbacksList.length > 0) {
            // Clear any pending bind-runnables from the synchronized load process.
            for (Callbacks cb : callbacksList) {
                MAIN_EXECUTOR.execute(cb::clearPendingBinds);
            }
            // If there is already one running, tell it to stop.
            stopLoader();
            LoaderResults loaderResults = new LoaderResults(mApp, mBgDataModel, mBgAllAppsList, callbacksList);
            if (mModelLoaded && !mIsLoaderTaskRunning) {
                // 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();
                // 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 2 with EXIT

use of com.android.launcher3.util.RaceConditionTracker.EXIT in project android_packages_apps_Launcher3 by crdroidandroid.

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 3 with EXIT

use of com.android.launcher3.util.RaceConditionTracker.EXIT in project android_packages_apps_Launcher3 by crdroidandroid.

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 4 with EXIT

use of com.android.launcher3.util.RaceConditionTracker.EXIT in project android_packages_apps_Trebuchet by LineageOS.

the class LauncherModel method startLoaderForResults.

public void startLoaderForResults(LoaderResults results) {
    synchronized (mLock) {
        stopLoader();
        mLoaderTask = new LoaderTask(mApp, mBgAllAppsList, mBgDataModel, results);
        // 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);
    }
}
Also used : LoaderTask(com.android.launcher3.model.LoaderTask)

Example 5 with EXIT

use of com.android.launcher3.util.RaceConditionTracker.EXIT in project android_packages_apps_Trebuchet by LineageOS.

the class DragController method startDrag.

/**
 * Starts a drag.
 * When the drag is started, the UI automatically goes into spring loaded mode. On a successful
 * drop, it is the responsibility of the {@link DropTarget} to exit out of the spring loaded
 * mode. If the drop was cancelled for some reason, the UI will automatically exit out of this mode.
 *
 * @param b The bitmap to display as the drag image.  It will be re-scaled to the
 *          enlarged size.
 * @param originalView The source view (ie. icon, widget etc.) that is being dragged
 *          and which the DragView represents
 * @param dragLayerX The x position in the DragLayer of the left-top of the bitmap.
 * @param dragLayerY The y position in the DragLayer of the left-top of the bitmap.
 * @param source An object representing where the drag originated
 * @param dragInfo The data associated with the object that is being dragged
 * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
 *          Makes dragging feel more precise, e.g. you can clip out a transparent border
 */
public DragView startDrag(Bitmap b, DraggableView originalView, int dragLayerX, int dragLayerY, DragSource source, ItemInfo dragInfo, Point dragOffset, Rect dragRegion, float initialDragViewScale, float dragViewScaleOnDrop, DragOptions options) {
    if (PROFILE_DRAWING_DURING_DRAG) {
        android.os.Debug.startMethodTracing("Launcher");
    }
    mLauncher.hideKeyboard();
    AbstractFloatingView.closeOpenViews(mLauncher, false, TYPE_DISCOVERY_BOUNCE);
    mOptions = options;
    if (mOptions.simulatedDndStartPoint != null) {
        mLastTouch.x = mMotionDown.x = mOptions.simulatedDndStartPoint.x;
        mLastTouch.y = mMotionDown.y = mOptions.simulatedDndStartPoint.y;
    }
    final int registrationX = mMotionDown.x - dragLayerX;
    final int registrationY = mMotionDown.y - dragLayerY;
    final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left;
    final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top;
    mLastDropTarget = null;
    mDragObject = new DropTarget.DragObject(mLauncher.getApplicationContext());
    mDragObject.originalView = originalView;
    mIsInPreDrag = mOptions.preDragCondition != null && !mOptions.preDragCondition.shouldStartDrag(0);
    final Resources res = mLauncher.getResources();
    final float scaleDps = mIsInPreDrag ? res.getDimensionPixelSize(R.dimen.pre_drag_view_scale) : 0f;
    final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX, registrationY, initialDragViewScale, dragViewScaleOnDrop, scaleDps);
    dragView.setItemInfo(dragInfo);
    mDragObject.dragComplete = false;
    mDragObject.xOffset = mMotionDown.x - (dragLayerX + dragRegionLeft);
    mDragObject.yOffset = mMotionDown.y - (dragLayerY + dragRegionTop);
    mDragDriver = DragDriver.create(this, mOptions, mFlingToDeleteHelper::recordMotionEvent);
    if (!mOptions.isAccessibleDrag) {
        mDragObject.stateAnnouncer = DragViewStateAnnouncer.createFor(dragView);
    }
    mDragObject.dragSource = source;
    mDragObject.dragInfo = dragInfo;
    mDragObject.originalDragInfo = mDragObject.dragInfo.makeShallowCopy();
    if (dragOffset != null) {
        dragView.setDragVisualizeOffset(new Point(dragOffset));
    }
    if (dragRegion != null) {
        dragView.setDragRegion(new Rect(dragRegion));
    }
    mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    dragView.show(mLastTouch.x, mLastTouch.y);
    mDistanceSinceScroll = 0;
    if (!mIsInPreDrag) {
        callOnDragStart();
    } else if (mOptions.preDragCondition != null) {
        mOptions.preDragCondition.onPreDragStart(mDragObject);
    }
    handleMoveEvent(mLastTouch.x, mLastTouch.y);
    mLauncher.getUserEventDispatcher().resetActionDurationMillis();
    if (!mLauncher.isTouchInProgress() && options.simulatedDndStartPoint == null) {
        // If it is an internal drag and the touch is already complete, cancel immediately
        MAIN_EXECUTOR.submit(this::cancelDrag);
    }
    return dragView;
}
Also used : Rect(android.graphics.Rect) DropTarget(com.android.launcher3.DropTarget) Resources(android.content.res.Resources) Point(android.graphics.Point) 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