forked from janheinrichmerker/material-intro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request janheinrichmerker#211 from meierjan/feature/multi-…
…parallaxable-layouts Parallax*Fragment; support multiple parallax-layouts
- Loading branch information
Showing
3 changed files
with
67 additions
and
49 deletions.
There are no files selected for viewing
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
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
51 changes: 51 additions & 0 deletions
51
...c/main/java/com/heinrichreimersoftware/materialintro/view/parallax/util/ParallaxUtil.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,51 @@ | ||
package com.heinrichreimersoftware.materialintro.view.parallax.util; | ||
|
||
import android.support.annotation.FloatRange; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.heinrichreimersoftware.materialintro.view.parallax.Parallaxable; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Queue; | ||
|
||
public class ParallaxUtil { | ||
private ParallaxUtil() {} | ||
|
||
public static List<Parallaxable> findParallaxableChildren(View root) { | ||
List<Parallaxable> parallaxableChildrenFound = new LinkedList<>(); | ||
Queue<View> queue = new LinkedList<>(); | ||
queue.add(root); | ||
while (!queue.isEmpty()) { | ||
View child = queue.remove(); | ||
if (child instanceof Parallaxable) { | ||
parallaxableChildrenFound.add((Parallaxable) child); | ||
} else if (child instanceof ViewGroup) { | ||
ViewGroup viewGroup = (ViewGroup) child; | ||
for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) { | ||
queue.add(viewGroup.getChildAt(i)); | ||
} | ||
} | ||
} | ||
return parallaxableChildrenFound; | ||
} | ||
|
||
/** | ||
* Set the provided offset to a list of parallaxable items. | ||
* | ||
* @param parallaxableChildren The list of parallaxable items to set the offset to. | ||
* @param offset The offset to assign. | ||
*/ | ||
public static void setOffsetToParallaxableList( | ||
final List<Parallaxable> parallaxableChildren, | ||
@FloatRange(from = -1.0, to = 1.0) float offset | ||
) { | ||
if (!parallaxableChildren.isEmpty()) { | ||
for (Parallaxable parallaxable : parallaxableChildren) { | ||
parallaxable.setOffset(offset); | ||
} | ||
} | ||
} | ||
|
||
} |