From 058c26b3ac8717808be41c15132cdf50dfcef53c Mon Sep 17 00:00:00 2001 From: ppamorim Date: Fri, 4 Sep 2015 14:08:51 -0300 Subject: [PATCH 1/6] HardwareLayerSpringListener added at rebound-android project, we need to analyse the source to provide a better code interaction as possible --- .../rebound/HardwareLayerSpringListener.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java diff --git a/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java new file mode 100644 index 0000000..4d55d7f --- /dev/null +++ b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java @@ -0,0 +1,43 @@ +package com.facebook.rebound; + +import android.view.View; +import java.util.WeakHashMap; + +public class HardwareLayerSpringListener implements SpringListener { + + private WeakHashMap weakViews = new WeakHashMap<>(); + + public HardwareLayerSpringListener(View... views) { + int countViews = views.length; + for(int i = 0; i < countViews; i++) { + weakViews.put(i, views[i]); + } + } + + public HardwareLayerSpringListener(WeakHashMap weakViews) { + this.weakViews = weakViews; + } + + @Override + public void onSpringUpdate(Spring spring) { + } + + @Override + public void onSpringAtRest(Spring spring) { + for(View view : weakViews.values()) { + view.setLayerType(View.LAYER_TYPE_NONE, null); + } + } + + @Override + public void onSpringActivate(Spring spring) { + for(View view : weakViews.values()) { + view.setLayerType(View.LAYER_TYPE_HARDWARE, null); + } + } + + @Override + public void onSpringEndStateChange(Spring spring) { + } + +} From 311511b117ed9f8acb6c0f051dd132ea69248b15 Mon Sep 17 00:00:00 2001 From: ppamorim Date: Fri, 4 Sep 2015 14:26:00 -0300 Subject: [PATCH 2/6] update --- .../rebound/HardwareLayerSpringListener.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java index 4d55d7f..3c340ad 100644 --- a/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java +++ b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java @@ -1,27 +1,58 @@ package com.facebook.rebound; import android.view.View; +import java.util.ArrayList; import java.util.WeakHashMap; public class HardwareLayerSpringListener implements SpringListener { + /** + * I think that WeakHashMap can avoid any memory leak, needs to be tested... + */ private WeakHashMap weakViews = new WeakHashMap<>(); public HardwareLayerSpringListener(View... views) { + addViews(views); + } + + public HardwareLayerSpringListener(WeakHashMap weakViews) { + this.weakViews = weakViews; + } + + public void addViews(ArrayList views) { + int countViews = views.size(); + for(int i = 0; i < countViews; i++) { + addView(i, views.get(i)); + } + } + + public void addViews(WeakHashMap weakViews) { + int countViews = weakViews.size(); + for(int i = 0; i < countViews; i++) { + addView(i, weakViews.get(i)); + } + } + + public void addViews(View... views) { int countViews = views.length; for(int i = 0; i < countViews; i++) { - weakViews.put(i, views[i]); + addView(i, views[i]); } } - public HardwareLayerSpringListener(WeakHashMap weakViews) { - this.weakViews = weakViews; + public void addView(int index, View view) { + weakViews.put(index, view); } @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()) { @@ -29,6 +60,11 @@ public void onSpringAtRest(Spring spring) { } } + /** + * 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()) { From 6f47584236344246fe19e3c5ae6ff8b21d84e399 Mon Sep 17 00:00:00 2001 From: ppamorim Date: Fri, 4 Sep 2015 14:29:12 -0300 Subject: [PATCH 3/6] licenses added and minor changes --- .../rebound/HardwareLayerSpringListener.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java index 3c340ad..beff326 100644 --- a/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java +++ b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java @@ -1,9 +1,23 @@ +/* + * 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.ArrayList; 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 { /** From dcc4c8a01105884d06962f5642abfadb5eeb2fe8 Mon Sep 17 00:00:00 2001 From: ppamorim Date: Fri, 4 Sep 2015 14:30:18 -0300 Subject: [PATCH 4/6] typo fix --- .../rebound/HardwareLayerSpringListener.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java index beff326..2b6f0ce 100644 --- a/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java +++ b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java @@ -16,12 +16,12 @@ /** * Spring Listener with Hardware Layer implementation, it's useful if - * you use with complex transition in your views + * you use with complex transition in your views. */ public class HardwareLayerSpringListener implements SpringListener { /** - * I think that WeakHashMap can avoid any memory leak, needs to be tested... + * WeakHashMap can avoid any memory leak, needs to be tested. */ private WeakHashMap weakViews = new WeakHashMap<>(); @@ -63,9 +63,9 @@ public void onSpringUpdate(Spring spring) { } /** - * Removes the all views of the Hardware Layer + * Removes the all views of the Hardware Layer. * - * @param spring the spring that's now resting + * @param spring the spring that's now resting. */ @Override public void onSpringAtRest(Spring spring) { @@ -75,9 +75,9 @@ public void onSpringAtRest(Spring spring) { } /** - * Set the layer type of the all views to View.LAYER_TYPE_HARDWARE + * Set the layer type of the all views to View.LAYER_TYPE_HARDWARE. * - * @param spring the spring that has left its resting state + * @param spring the spring that has left its resting state. */ @Override public void onSpringActivate(Spring spring) { From 81b1749016c77d52233870376dc0af6f55934119 Mon Sep 17 00:00:00 2001 From: ppamorim Date: Fri, 4 Sep 2015 17:26:04 -0300 Subject: [PATCH 5/6] unecessary methods removed --- .../rebound/HardwareLayerSpringListener.java | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java index 2b6f0ce..49d5a1d 100644 --- a/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java +++ b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java @@ -11,7 +11,6 @@ package com.facebook.rebound; import android.view.View; -import java.util.ArrayList; import java.util.WeakHashMap; /** @@ -26,38 +25,12 @@ public class HardwareLayerSpringListener implements SpringListener { private WeakHashMap weakViews = new WeakHashMap<>(); public HardwareLayerSpringListener(View... views) { - addViews(views); - } - - public HardwareLayerSpringListener(WeakHashMap weakViews) { - this.weakViews = weakViews; - } - - public void addViews(ArrayList views) { - int countViews = views.size(); - for(int i = 0; i < countViews; i++) { - addView(i, views.get(i)); - } - } - - public void addViews(WeakHashMap weakViews) { - int countViews = weakViews.size(); - for(int i = 0; i < countViews; i++) { - addView(i, weakViews.get(i)); - } - } - - public void addViews(View... views) { int countViews = views.length; for(int i = 0; i < countViews; i++) { - addView(i, views[i]); + weakViews.put(i, views[i]); } } - public void addView(int index, View view) { - weakViews.put(index, view); - } - @Override public void onSpringUpdate(Spring spring) { } From 0ad575caecaab4b2aa630465d6cc0038de0d5c5c Mon Sep 17 00:00:00 2001 From: ppamorim Date: Wed, 9 Sep 2015 08:48:56 -0300 Subject: [PATCH 6/6] WeakHashMap removed and List> is implemented --- .../rebound/HardwareLayerSpringListener.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java index 49d5a1d..cb4c2b0 100644 --- a/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java +++ b/rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java @@ -11,7 +11,9 @@ package com.facebook.rebound; import android.view.View; -import java.util.WeakHashMap; +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.List; /** * Spring Listener with Hardware Layer implementation, it's useful if @@ -20,14 +22,13 @@ public class HardwareLayerSpringListener implements SpringListener { /** - * WeakHashMap can avoid any memory leak, needs to be tested. + * WeakReference can avoid any memory leak, needs to be tested. */ - private WeakHashMap weakViews = new WeakHashMap<>(); + private List> weakViews = new ArrayList<>(); public HardwareLayerSpringListener(View... views) { - int countViews = views.length; - for(int i = 0; i < countViews; i++) { - weakViews.put(i, views[i]); + for(View view : views) { + weakViews.add(new WeakReference<>(view)); } } @@ -42,20 +43,20 @@ public void onSpringUpdate(Spring spring) { */ @Override public void onSpringAtRest(Spring spring) { - for(View view : weakViews.values()) { - view.setLayerType(View.LAYER_TYPE_NONE, null); + for(WeakReference weakReference : weakViews) { + ((View) weakReference.get()).setLayerType(View.LAYER_TYPE_NONE, null); } } /** - * Set the layer type of the all views to View.LAYER_TYPE_HARDWARE. + * Set the layer type of the all views to Hardware Layer * * @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); + for(WeakReference weakReference : weakViews) { + ((View) weakReference.get()).setLayerType(View.LAYER_TYPE_HARDWARE, null); } }