Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

HardwareLayerSpringListener #68

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

package com.facebook.rebound;

import android.view.View;
import java.util.WeakHashMap;

/**
* Spring Listener with Hardware Layer implementation, it's useful if
* you use with complex transition in your views.
*/
public class HardwareLayerSpringListener implements SpringListener {

/**
* WeakHashMap can avoid any memory leak, needs to be tested.
*/
private WeakHashMap<Integer, View> weakViews = new WeakHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just use

List<WeakReference<View>> 


public HardwareLayerSpringListener(View... views) {
int countViews = views.length;
for(int i = 0; i < countViews; i++) {
weakViews.put(i, views[i]);
}
}

@Override
public void onSpringUpdate(Spring spring) {
}

/**
* Removes the all views of the Hardware Layer.
*
* @param spring the spring that's now resting.
*/
@Override
public void onSpringAtRest(Spring spring) {
for(View view : weakViews.values()) {
view.setLayerType(View.LAYER_TYPE_NONE, null);
}
}

/**
* Set the layer type of the all views to View.LAYER_TYPE_HARDWARE.
*
* @param spring the spring that has left its resting state.
*/
@Override
public void onSpringActivate(Spring spring) {
for(View view : weakViews.values()) {
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
}

@Override
public void onSpringEndStateChange(Spring spring) {
}

}