This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 816
HardwareLayerSpringListener #68
Open
ppamorim
wants to merge
6
commits into
facebookarchive:master
Choose a base branch
from
ppamorim:HardwareLayerSpringListener
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
058c26b
HardwareLayerSpringListener added at rebound-android project, we need…
ppamorim 311511b
update
ppamorim 6f47584
licenses added and minor changes
ppamorim dcc4c8a
typo fix
ppamorim 81b1749
unecessary methods removed
ppamorim 0ad575c
WeakHashMap removed and List<WeakReference<View>> is implemented
ppamorim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
rebound-android/src/main/java/com/facebook/rebound/HardwareLayerSpringListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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 { | ||
|
||
/** | ||
* WeakHashMap can avoid any memory leak, needs to be tested. | ||
*/ | ||
private WeakHashMap<Integer, View> weakViews = new WeakHashMap<>(); | ||
|
||
public HardwareLayerSpringListener(View... views) { | ||
addViews(views); | ||
} | ||
|
||
public HardwareLayerSpringListener(WeakHashMap<Integer, View> weakViews) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constructor seems unnecessary. I'd prefer to just have the var args version. Sharing a HashMap between a caller and this class seems fragile. |
||
this.weakViews = weakViews; | ||
} | ||
|
||
public void addViews(ArrayList<View> views) { | ||
int countViews = views.size(); | ||
for(int i = 0; i < countViews; i++) { | ||
addView(i, views.get(i)); | ||
} | ||
} | ||
|
||
public void addViews(WeakHashMap<Integer, View> weakViews) { | ||
int countViews = weakViews.size(); | ||
for(int i = 0; i < countViews; i++) { | ||
addView(i, weakViews.get(i)); | ||
} | ||
} | ||
|
||
public void addViews(View... views) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be private, I don't see a reason to update the views dynamically |
||
int countViews = views.length; | ||
for(int i = 0; i < countViews; i++) { | ||
addView(i, views[i]); | ||
} | ||
} | ||
|
||
public void addView(int index, View view) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
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()) { | ||
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) { | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just use