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

Commit 2ae9c85b authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Fixing bug in AnimationLayerSet where it sets the layer type to software

at the end of the animation instead fo setting it back to the original value

Change-Id: I528dc41fb896ae57905d5ceab7256a53bdb81489
parent ee544c5d
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -20,23 +20,29 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.view.View;

import java.util.HashSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Helper class to automatically build view hardware layers for the duration of an animation.
 */
public class AnimationLayerSet extends AnimatorListenerAdapter {

    private final HashSet<View> mViews = new HashSet<>();
    private final HashMap<View, Integer> mViewsToLayerTypeMap = new HashMap<>();

    public void addView(View v) {
        mViews.add(v);
        mViewsToLayerTypeMap.put(v, v.getLayerType());
    }

    @Override
    public void onAnimationStart(Animator animation) {
        // Enable all necessary layers
        for (View v : mViews) {
        Iterator<Map.Entry<View, Integer>> itr = mViewsToLayerTypeMap.entrySet().iterator();
        while (itr.hasNext()) {
            Map.Entry<View, Integer> entry = itr.next();
            View v = entry.getKey();
            entry.setValue(v.getLayerType());
            v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            if (v.isAttachedToWindow() && v.getVisibility() == View.VISIBLE) {
                v.buildLayer();
@@ -46,8 +52,10 @@ public class AnimationLayerSet extends AnimatorListenerAdapter {

    @Override
    public void onAnimationEnd(Animator animation) {
        for (View v : mViews) {
            v.setLayerType(View.LAYER_TYPE_NONE, null);
        Iterator<Map.Entry<View, Integer>> itr = mViewsToLayerTypeMap.entrySet().iterator();
        while (itr.hasNext()) {
            Map.Entry<View, Integer> entry = itr.next();
            entry.getKey().setLayerType(entry.getValue(), null);
        }
    }
}