Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions material-intro-screen/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ android {
})
compile "com.android.support:appcompat-v7:${project.androidSupport}"
compile "com.android.support:design:${project.androidSupport}"
compile "com.android.support:percent:${project.androidSupport}"
}

publish {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package agency.tango.materialintroscreen.parallax;


import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.FloatRange;
import android.support.percent.PercentFrameLayout;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import agency.tango.materialintroscreen.R;

public class ParallaxPercentFrameLayout extends PercentFrameLayout implements Parallaxable {

public ParallaxPercentFrameLayout(Context context) {
super(context);
}

public ParallaxPercentFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

public ParallaxPercentFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
return p instanceof LayoutParams;
}

@Override
protected LayoutParams generateDefaultLayoutParams() {
return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}

@Override
public LayoutParams generateLayoutParams(AttributeSet attrs) {
return new LayoutParams(getContext(), attrs);
}

@Override
protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
return new LayoutParams(p);
}

@Override
public void setOffset(@FloatRange(from = -1.0, to = 1.0) float offset) {
for (int i = getChildCount() - 1; i >= 0; i--) {
View child = getChildAt(i);
LayoutParams p = (LayoutParams) child.getLayoutParams();
if (p.parallaxFactor == 0)
continue;
child.setTranslationX(getWidth() * -offset * p.parallaxFactor);
}
}

public static class LayoutParams extends PercentFrameLayout.LayoutParams {
float parallaxFactor = 0f;

LayoutParams(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.mis_ParallaxLayout_Layout);
parallaxFactor = typedArray.getFloat(R.styleable.mis_ParallaxLayout_Layout_mis_layout_parallaxFactor, parallaxFactor);
typedArray.recycle();
}

LayoutParams(int width, int height) {
super(width, height);
}

@SuppressWarnings("unused")
LayoutParams(int width, int height, int gravity) {
super(width, height, gravity);
}

LayoutParams(ViewGroup.LayoutParams source) {
super(source);
}

@SuppressWarnings("unused")
LayoutParams(MarginLayoutParams source) {
super(source);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package agency.tango.materialintroscreen.parallax;


import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.FloatRange;
import android.support.percent.PercentRelativeLayout;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import agency.tango.materialintroscreen.R;

public class ParallaxPercentRelativeLayout extends PercentRelativeLayout implements Parallaxable {

public ParallaxPercentRelativeLayout(Context context) {
super(context);
}

public ParallaxPercentRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

public ParallaxPercentRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
return p instanceof LayoutParams;
}

@Override
protected LayoutParams generateDefaultLayoutParams() {
return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}

@Override
public LayoutParams generateLayoutParams(AttributeSet attrs) {
return new LayoutParams(getContext(), attrs);
}

@Override
protected PercentRelativeLayout.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
return new LayoutParams(p);
}

@Override
public void setOffset(@FloatRange(from = -1.0, to = 1.0) float offset) {
for (int i = getChildCount() - 1; i >= 0; i--) {
View child = getChildAt(i);
LayoutParams p = (LayoutParams) child.getLayoutParams();
if (p.parallaxFactor == 0)
continue;
child.setTranslationX(getWidth() * -offset * p.parallaxFactor);
}
}

public static class LayoutParams extends PercentRelativeLayout.LayoutParams {
float parallaxFactor = 0f;

LayoutParams(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.mis_ParallaxLayout_Layout);
parallaxFactor = typedArray.getFloat(R.styleable.mis_ParallaxLayout_Layout_mis_layout_parallaxFactor, parallaxFactor);
typedArray.recycle();
}

LayoutParams(int width, int height) {
super(width, height);
}

LayoutParams(ViewGroup.LayoutParams source) {
super(source);
}

@SuppressWarnings("unused")
LayoutParams(MarginLayoutParams source) {
super(source);
}
}
}
2 changes: 1 addition & 1 deletion versions.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ext.androidSupport = "25.0.1"
ext.androidSupport = "25.1.1"