-
-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added parallax feature to simple slide
- Loading branch information
1 parent
2facd23
commit 32bafa3
Showing
4 changed files
with
96 additions
and
38 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
45 changes: 45 additions & 0 deletions
45
...rc/main/java/com/heinrichreimersoftware/materialintro/view/parallax/ParallaxFragment.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,45 @@ | ||
package com.heinrichreimersoftware.materialintro.view.parallax; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.FloatRange; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
|
||
public class ParallaxFragment extends Fragment implements Parallaxable { | ||
@Nullable | ||
private Parallaxable parallaxLayout; | ||
|
||
@Override | ||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
parallaxLayout = findParallaxLayout(view); | ||
} | ||
|
||
public Parallaxable findParallaxLayout(View root) { | ||
Queue<View> queue = new LinkedList<>(); | ||
queue.add(root); | ||
while (!queue.isEmpty()) { | ||
View child = queue.remove(); | ||
if (child instanceof Parallaxable) { | ||
return (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 null; | ||
} | ||
|
||
@Override | ||
public void setOffset(@FloatRange(from = -1.0, to = 1.0) float offset) { | ||
if (parallaxLayout != null) | ||
parallaxLayout.setOffset(offset); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...in/java/com/heinrichreimersoftware/materialintro/view/parallax/ParallaxSlideFragment.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,46 @@ | ||
package com.heinrichreimersoftware.materialintro.view.parallax; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.FloatRange; | ||
import android.support.annotation.Nullable; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.heinrichreimersoftware.materialintro.app.SlideFragment; | ||
|
||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
|
||
public class ParallaxSlideFragment extends SlideFragment implements Parallaxable { | ||
@Nullable | ||
private Parallaxable parallaxLayout; | ||
|
||
@Override | ||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
parallaxLayout = findParallaxLayout(view); | ||
} | ||
|
||
public Parallaxable findParallaxLayout(View root) { | ||
Queue<View> queue = new LinkedList<>(); | ||
queue.add(root); | ||
while (!queue.isEmpty()) { | ||
View child = queue.remove(); | ||
if (child instanceof Parallaxable) { | ||
return (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 null; | ||
} | ||
|
||
@Override | ||
public void setOffset(@FloatRange(from = -1.0, to = 1.0) float offset) { | ||
if (parallaxLayout != null) | ||
parallaxLayout.setOffset(offset); | ||
} | ||
} |