Skip to content

Commit

Permalink
Easy define default value.
Browse files Browse the repository at this point in the history
You can change the default duration and colorOrImageRes when enter app.
  • Loading branch information
XunMengWinter committed Sep 24, 2016
1 parent 992a33c commit 9a86152
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 15 deletions.
8 changes: 4 additions & 4 deletions circularanim/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ group='com.github.XunMengWinter'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
buildToolsVersion "24.0.2"

defaultConfig {
minSdkVersion 14
minSdkVersion 9
targetSdkVersion 24
versionCode 5
versionName "0.3.2"
versionCode 6
versionName "0.3.4"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ public class CircularAnim {
public static final long PERFECT_MILLS = 618;
public static final int MINI_RADIUS = 0;

private static Long sPerfectMills;
private static Long sFullActivityPerfectMills;
private static Integer sColorOrImageRes;

private static long getPerfectMills() {
if (sPerfectMills != null)
return sPerfectMills;
else
return PERFECT_MILLS;
}

private static long getFullActivityMills() {
if (sFullActivityPerfectMills != null)
return sFullActivityPerfectMills;
else
return PERFECT_MILLS;
}

private static int getColorOrImageRes() {
if (sColorOrImageRes != null)
return sColorOrImageRes;
else
return android.R.color.white;
}


public interface OnAnimationEndListener {
void onAnimationEnd();
}
Expand All @@ -36,7 +62,7 @@ public static class VisibleBuilder {

private Float mStartRadius, mEndRadius;

private long mDurationMills = PERFECT_MILLS;
private long mDurationMills = getPerfectMills();

private boolean isShow;

Expand Down Expand Up @@ -178,7 +204,7 @@ public static class FullActivityBuilder {
private Activity mActivity;
private View mTriggerView;
private float mStartRadius = MINI_RADIUS;
private int mColorOrImageRes = android.R.color.white;
private int mColorOrImageRes = getColorOrImageRes();
private Long mDurationMills;
private OnAnimationEndListener mOnAnimationEndListener;
private int mEnterAnim = android.R.anim.fade_in, mExitAnim = android.R.anim.fade_out;
Expand Down Expand Up @@ -244,7 +270,7 @@ public void go(OnAnimationEndListener onAnimationEndListener) {
// 算出实际边距与最大边距的比率
double rate = 1d * finalRadius / maxRadius;
// 为了让用户便于感触到水波,速度应随最大边距的变小而越慢,扩散时间应随最大边距的变小而变小,因此比率应在 @rate 与 1 之间。
mDurationMills = (long) (PERFECT_MILLS * Math.sqrt(rate));
mDurationMills = (long) (getFullActivityMills() * Math.sqrt(rate));
}
final long finalDuration = mDurationMills;
// 由于thisActivity.startActivity()会有所停顿,所以进入的水波动画应比退出的水波动画时间短才能保持视觉上的一致。
Expand Down Expand Up @@ -323,4 +349,11 @@ public static FullActivityBuilder fullActivity(Activity activity, View triggerVi
return new FullActivityBuilder(activity, triggerView);
}

/* 设置默认时长,设置充满activity的默认颜色或图片资源 */
public static void init(long perfectMills, long fullActivityPerfectMills, int colorOrImageRes) {
sPerfectMills = perfectMills;
sFullActivityPerfectMills = fullActivityPerfectMills;
sColorOrImageRes = colorOrImageRes;
}

}
12 changes: 6 additions & 6 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
buildToolsVersion "24.0.2"

defaultConfig {
applicationId "top.wefor.circularanim"
minSdkVersion 14
targetSdkVersion 24
versionCode 2
versionName "1.2"
versionCode 3
versionName "1.3"
}
buildTypes {
release {
Expand All @@ -22,13 +22,13 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'

compile project(path: ':circularanim')

// CircularAnim 可通过compile导入,记得在Project的build.gradle里添加:maven { url "https://jitpack.io" }
// 也可以直接复制 CircularAnim.class,这样更轻量更便于修改与拓展.
// compile 'com.github.XunMengWinter:CircularAnim:master-SNAPSHOT'
// compile 'com.github.XunMengWinter:CircularAnim:0.3.4'

}
1 change: 1 addition & 0 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
21 changes: 21 additions & 0 deletions demo/src/main/java/top/wefor/circularanimdemo/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package top.wefor.circularanimdemo;

import android.app.Application;

import top.wefor.circularanim.CircularAnim;

/**
* Created on 16/9/24.
*
* @author ice
*/
public class App extends Application {

@Override
public void onCreate() {
super.onCreate();
// optional. change default duration and fullActivity resource.
// the original value is (618, 618,android.R.color.white).
CircularAnim.init(700, 500, R.color.colorPrimary);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public MyViewHolder(View itemView) {
@Override
public void onClick(View view) {
CircularAnim.fullActivity(ListActivity.this, view)
.colorOrImageRes(R.color.colorPrimary)
// .colorOrImageRes(R.color.colorPrimary) //注释掉,因为该颜色已经在App.class 里配置为默认色
.go(new CircularAnim.OnAnimationEndListener() {
@Override
public void onAnimationEnd() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void onAnimationEnd() {
public void onClick(View view) {
// 先将颜色展出铺满,然后启动新的Activity
CircularAnim.fullActivity(MainActivity.this, view)
.colorOrImageRes(R.color.colorPrimary)
// .colorOrImageRes(R.color.colorPrimary) //注释掉,因为该颜色已经在App.class 里配置为默认色
.go(new CircularAnim.OnAnimationEndListener() {
@Override
public void onAnimationEnd() {
Expand Down

0 comments on commit 9a86152

Please sign in to comment.