Skip to content

Commit

Permalink
add new anim mode
Browse files Browse the repository at this point in the history
  • Loading branch information
codeestX committed Feb 24, 2017
1 parent 40c1844 commit 3b5b724
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 16 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Step 1. Add the JitPack repository to your build file
Step 2. Add the dependency

dependencies {
compile 'com.github.codeestX:ECardFlow:v1.0.3'
compile 'com.github.codeestX:ECardFlow:v1.0.5'
}

Step 3. Just use it as a ViewPager
Expand Down Expand Up @@ -119,7 +119,7 @@ Step 1. Add the JitPack repository to your build file
Step 2. Add the dependency

dependencies {
compile 'com.github.codeestX:ECardFlow:v1.0.4'
compile 'com.github.codeestX:ECardFlow:v1.0.5'
}

Step 3. Just put a ViewPager in ECardFlowLayout
Expand Down Expand Up @@ -176,6 +176,8 @@ Java Code:
| DefaultAnimMode | No Effect |
| BlurAnimMode | Blur Effect |
| MoveAnimMode | Parallax Effect |
| ScaleAnimMode | Scale Effect |
| CrossMoveAnimMode | Cross Parallax Effect |
You can custom AnimMode with class which implements `AnimMode`

| ImageProvider | Des |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

import moe.codeest.ecardflow.ECardFlowLayout;
import moe.codeest.ecardflow.mode.BlurAnimMode;
import moe.codeest.ecardflow.mode.CrossMoveAnimMode;
import moe.codeest.ecardflow.mode.DefaultAnimMode;
import moe.codeest.ecardflow.mode.MoveAnimMode;
import moe.codeest.ecardflow.mode.ScaleAnimMode;
import moe.codeest.ecardflow.provider.DrawableImageProvider;
import moe.codeest.ecardflow.util.DimenUtils;
import moe.codeest.ecardflowdemo.R;
Expand All @@ -24,9 +26,12 @@

public class CardFlowLayoutActivity extends AppCompatActivity {

public static int MODE_DEFAULT = 0;
public static int MODE_BLUR = 1;
public static int MODE_MOVE = 2;
public final static int MODE_DEFAULT = 0;
public final static int MODE_BLUR = 1;
public final static int MODE_MOVE = 2;
public final static int MODE_SCALE = 3;
public final static int MODE_CROSS_MOVE = 4;
public final static String ANIM_MODE = "mode";

private ECardFlowLayout mVPLayout;
private ViewPager mViewPager;
Expand All @@ -40,7 +45,7 @@ public class CardFlowLayoutActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cardflow_layout);
mMode = getIntent().getIntExtra("mode", MODE_DEFAULT);
mMode = getIntent().getIntExtra(ANIM_MODE, MODE_DEFAULT);
init();
}

Expand All @@ -58,6 +63,12 @@ private void init() {
case 2:
mVPLayout.setAnimMode(new MoveAnimMode());
break;
case 3:
mVPLayout.setAnimMode(new ScaleAnimMode());
break;
case 4:
mVPLayout.setAnimMode(new CrossMoveAnimMode());
break;
}
mVPLayout.setImageProvider(new DrawableImageProvider(this, res, DimenUtils.getScreenWidth(getApplicationContext()), DimenUtils.getScreenHeight(getApplicationContext())));
for (int i = 0; i < 4; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import moe.codeest.ecardflowdemo.R;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
import static moe.codeest.ecardflowdemo.activity.CardFlowLayoutActivity.ANIM_MODE;

AppCompatButton btnCard, btnLayout, btnLayoutBlur, btnLayoutMove;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

AppCompatButton btnCard, btnLayout, btnLayoutBlur, btnLayoutMove, btnLayoutScale, btnLayoutCrossMove;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -22,11 +23,15 @@ public void onCreate(Bundle savedInstanceState) {
btnLayout = (AppCompatButton) findViewById(R.id.btn_layout);
btnLayoutBlur = (AppCompatButton) findViewById(R.id.btn_layout_blur);
btnLayoutMove = (AppCompatButton) findViewById(R.id.btn_layout_move);
btnLayoutScale = (AppCompatButton) findViewById(R.id.btn_layout_scale);
btnLayoutCrossMove = (AppCompatButton) findViewById(R.id.btn_layout_cross);

btnCard.setOnClickListener(this);
btnLayout.setOnClickListener(this);
btnLayoutBlur.setOnClickListener(this);
btnLayoutMove.setOnClickListener(this);
btnLayoutScale.setOnClickListener(this);
btnLayoutCrossMove.setOnClickListener(this);
}

@Override
Expand All @@ -36,15 +41,23 @@ public void onClick(View v) {
startActivity(it);
} else if (v == btnLayout) {
Intent it = new Intent(this, CardFlowLayoutActivity.class);
it.putExtra("mode", CardFlowLayoutActivity.MODE_DEFAULT);
it.putExtra(CardFlowLayoutActivity.ANIM_MODE, CardFlowLayoutActivity.MODE_DEFAULT);
startActivity(it);
} else if (v == btnLayoutBlur) {
Intent it = new Intent(this, CardFlowLayoutActivity.class);
it.putExtra("mode", CardFlowLayoutActivity.MODE_BLUR);
it.putExtra(CardFlowLayoutActivity.ANIM_MODE, CardFlowLayoutActivity.MODE_BLUR);
startActivity(it);
} else if (v == btnLayoutMove) {
Intent it = new Intent(this, CardFlowLayoutActivity.class);
it.putExtra(CardFlowLayoutActivity.ANIM_MODE, CardFlowLayoutActivity.MODE_MOVE);
startActivity(it);
} else if (v == btnLayoutScale) {
Intent it = new Intent(this, CardFlowLayoutActivity.class);
it.putExtra(CardFlowLayoutActivity.ANIM_MODE, CardFlowLayoutActivity.MODE_SCALE);
startActivity(it);
} else {
Intent it = new Intent(this, CardFlowLayoutActivity.class);
it.putExtra("mode", CardFlowLayoutActivity.MODE_MOVE);
it.putExtra(CardFlowLayoutActivity.ANIM_MODE, CardFlowLayoutActivity.MODE_CROSS_MOVE);
startActivity(it);
}
}
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,20 @@
android:textAllCaps="false"
android:layout_marginTop="20dp"
android:text="ECardFlowLayout(Move)"/>

<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_layout_scale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:layout_marginTop="20dp"
android:text="ECardFlowLayout(Scale)"/>

<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_layout_cross"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:layout_marginTop="20dp"
android:text="ECardFlowLayout(CrossMove)"/>
</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void initViewPager() {
}
}
if (mViewPager == null) {
throw new RuntimeException("Can't find ViewPager in ECardFlowLayout");
throw new IllegalStateException("Can't find ViewPager in ECardFlowLayout");
}
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
Expand Down Expand Up @@ -225,7 +225,7 @@ public void run() {
}
});
} else {
throw new RuntimeException("setImageProvider is necessary");
throw new IllegalArgumentException("setImageProvider is necessary");
}
}

Expand Down Expand Up @@ -373,7 +373,7 @@ public void setImageProvider(ImageProvider provider) {
curBp = loadBitmap(0);
nextBp = loadBitmap(1);
if (mAnimMode == null) {
throw new RuntimeException("You should setAnimMode before setImageProvider");
throw new IllegalStateException("You should setAnimMode before setImageProvider");
}
if (mBlurImage != null) {
curBlurBp = blurBitmap(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public BlurAnimMode() {
this.mRadius = DEFAULT_BLUR_RADIUS;
}

public BlurAnimMode(int mRadius) {
this.mRadius = mRadius;
public BlurAnimMode(int radius) {
this.mRadius = radius;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package moe.codeest.ecardflow.mode;

import android.widget.ImageView;

/**
* Created by codeest on 2017/2/25.
*/

public class CrossMoveAnimMode implements AnimMode {

private static final float DEFAULT_MOVE_SCALE = 1.3f;
private float mScale;

public CrossMoveAnimMode() {
this.mScale = DEFAULT_MOVE_SCALE;
}

public CrossMoveAnimMode(float mScale) {
this.mScale = mScale;
}

@Override
public void transformPage(ImageView ivBg, float position, int direction) {
ivBg.setScaleX(mScale);
ivBg.setScaleY(mScale);
float totalMoveWidth = ivBg.getWidth() * ((mScale - 1) / 2);
int lastPosition = Math.round(position);
float mFraction;
if (lastPosition % 2 == 0) {
mFraction = -1 * (float) Math.sin(Math.PI * position);
} else {
mFraction = (float) Math.sin(Math.PI * position);
}
ivBg.setTranslationY(totalMoveWidth * mFraction);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package moe.codeest.ecardflow.mode;

import android.widget.ImageView;

/**
* Created by codeest on 2017/2/25.
*/

public class ScaleAnimMode implements AnimMode {

private static final int DEFAULT_SCALE_RATE = 1;
private int mScaleRate;

public ScaleAnimMode() {
this.mScaleRate = DEFAULT_SCALE_RATE;
}

public ScaleAnimMode(int scaleRate) {
this.mScaleRate = scaleRate;
}

@Override
public void transformPage(ImageView ivBg, float position, int direction) {
float mFraction = mScaleRate * (float) Math.abs(Math.sin(Math.PI * position));
ivBg.setScaleX(1 + mFraction);
ivBg.setScaleY(1 + mFraction);
}
}

0 comments on commit 3b5b724

Please sign in to comment.