Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5fd3505 authored by Winson's avatar Winson Committed by Winson Chung
Browse files

Removing extraneous calls.

- Removing calls to ensureCapacity, which was causing reallocations when
  using a temporary set with multiple uses.
- Fixing issue with update callback not being called when immediately 
  updating a TaskView’s transform
- Adding utility methods in preparation for refactoring code


Change-Id: If62c3751ed6af15092a34435df08bb4d627536ea
parent c8a4cdc0
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ public class SwipeHelper implements Gefingerpoken {

    private ObjectAnimator createTranslationAnimation(View v, float newPos) {
        ObjectAnimator anim = ObjectAnimator.ofFloat(v,
                mSwipeDirection == X ? "translationX" : "translationY", newPos);
                mSwipeDirection == X ? View.TRANSLATION_X : View.TRANSLATION_Y, newPos);
        return anim;
    }

@@ -401,9 +401,17 @@ public class SwipeHelper implements Gefingerpoken {
                mCallback.onChildSnappedBack(animView);
            }
        });
        updateSnapBackAnimation(anim);
        anim.start();
    }

    /**
     * Called to update the snap back animation.
     */
    protected void updateSnapBackAnimation(Animator anim) {
        // Do nothing
    }

    public boolean onTouchEvent(MotionEvent ev) {
        if (mLongPressSent) {
            return true;
+46 −0
Original line number Diff line number Diff line
@@ -21,10 +21,16 @@ import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.ArraySet;
import android.util.IntProperty;
import android.util.Property;
import android.view.View;
import android.view.ViewParent;
import com.android.systemui.recents.model.Task;
import com.android.systemui.recents.views.TaskViewTransform;

import java.util.Collections;
import java.util.List;

/* Common code */
public class Utilities {
@@ -71,6 +77,28 @@ public class Utilities {
        return null;
    }

    /**
     * Initializes the {@param setOut} with the given object.
     */
    public static <T> ArraySet<T> objectToSet(T obj, ArraySet<T> setOut) {
        setOut.clear();
        if (obj != null) {
            setOut.add(obj);
        }
        return setOut;
    }

    /**
     * Replaces the contents of {@param setOut} with the contents of the {@param array}.
     */
    public static <T> ArraySet<T> arrayToSet(T[] array, ArraySet<T> setOut) {
        setOut.clear();
        if (array != null) {
            Collections.addAll(setOut, array);
        }
        return setOut;
    }

    /** Scales a rect about its centroid */
    public static void scaleRectAboutCenter(RectF r, float scale) {
        if (scale != 1.0f) {
@@ -127,4 +155,22 @@ public class Utilities {
            animator.cancel();
        }
    }

    /**
     * Updates {@param transforms} to be the same size as {@param tasks}.
     */
    public static void matchTaskListSize(List<Task> tasks, List<TaskViewTransform> transforms) {
        // We can reuse the task transforms where possible to reduce object allocation
        int taskTransformCount = transforms.size();
        int taskCount = tasks.size();
        if (taskTransformCount < taskCount) {
            // If there are less transforms than tasks, then add as many transforms as necessary
            for (int i = taskTransformCount; i < taskCount; i++) {
                transforms.add(new TaskViewTransform());
            }
        } else if (taskTransformCount > taskCount) {
            // If there are more transforms than tasks, then just subset the transform list
            transforms.subList(taskCount, taskTransformCount).clear();
        }
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -98,7 +98,6 @@ public class TaskGrouping {
        int taskCount = mTaskKeys.size();
        mFrontMostTaskKey = mTaskKeys.get(mTaskKeys.size() - 1);
        mTaskKeyIndices.clear();
        mTaskKeyIndices.ensureCapacity(taskCount);
        for (int i = 0; i < taskCount; i++) {
            Task.TaskKey k = mTaskKeys.get(i);
            mTaskKeyIndices.put(k, i);
+0 −2
Original line number Diff line number Diff line
@@ -193,7 +193,6 @@ class FilteredTaskList {
    private void updateFilteredTaskIndices() {
        int taskCount = mFilteredTasks.size();
        mTaskIndices.clear();
        mTaskIndices.ensureCapacity(taskCount);
        for (int i = 0; i < taskCount; i++) {
            Task t = mFilteredTasks.get(i);
            mTaskIndices.put(t.key, i);
@@ -841,7 +840,6 @@ public class TaskStack {
            ArrayMap<Task.TaskKey, Task> tasksMap = new ArrayMap<>();
            ArrayList<Task> tasks = mStackTaskList.getTasks();
            int taskCount = tasks.size();
            tasksMap.ensureCapacity(taskCount);
            for (int i = 0; i < taskCount; i++) {
                Task t = tasks.get(i);
                TaskGrouping group;
+2 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ public class AnimateableViewBounds extends ViewOutlineProvider {
    void setAlpha(float alpha) {
        if (Float.compare(alpha, mAlpha) != 0) {
            mAlpha = alpha;
            // TODO, If both clip and alpha change in the same frame, only invalidate once
            mSourceView.invalidateOutline();
        }
    }
@@ -79,6 +80,7 @@ public class AnimateableViewBounds extends ViewOutlineProvider {
                mSourceView.getHeight() - Math.max(0, mClipRect.bottom));
        if (!mLastClipBounds.equals(mClipBounds)) {
            mSourceView.setClipBounds(mClipBounds);
            // TODO, If both clip and alpha change in the same frame, only invalidate once
            mSourceView.invalidateOutline();
            mLastClipBounds.set(mClipBounds);
        }
Loading