diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..66e2f6f --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/animated_vector_drawable_25_1_0.xml b/.idea/libraries/animated_vector_drawable_25_1_0.xml new file mode 100644 index 0000000..a3d1914 --- /dev/null +++ b/.idea/libraries/animated_vector_drawable_25_1_0.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/appcompat_v7_25_1_0.xml b/.idea/libraries/appcompat_v7_25_1_0.xml new file mode 100644 index 0000000..10b7a36 --- /dev/null +++ b/.idea/libraries/appcompat_v7_25_1_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/design_25_1_0.xml b/.idea/libraries/design_25_1_0.xml new file mode 100644 index 0000000..e684824 --- /dev/null +++ b/.idea/libraries/design_25_1_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/espresso_core_2_2_2.xml b/.idea/libraries/espresso_core_2_2_2.xml new file mode 100644 index 0000000..fc9bec0 --- /dev/null +++ b/.idea/libraries/espresso_core_2_2_2.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/espresso_idling_resource_2_2_2.xml b/.idea/libraries/espresso_idling_resource_2_2_2.xml new file mode 100644 index 0000000..ae9e21b --- /dev/null +++ b/.idea/libraries/espresso_idling_resource_2_2_2.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml b/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml new file mode 100644 index 0000000..965dbb4 --- /dev/null +++ b/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/hamcrest_core_1_3.xml b/.idea/libraries/hamcrest_core_1_3.xml new file mode 100644 index 0000000..157e3f3 --- /dev/null +++ b/.idea/libraries/hamcrest_core_1_3.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/hamcrest_integration_1_3.xml b/.idea/libraries/hamcrest_integration_1_3.xml new file mode 100644 index 0000000..bab4b95 --- /dev/null +++ b/.idea/libraries/hamcrest_integration_1_3.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/hamcrest_library_1_3.xml b/.idea/libraries/hamcrest_library_1_3.xml new file mode 100644 index 0000000..923d5fc --- /dev/null +++ b/.idea/libraries/hamcrest_library_1_3.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/javawriter_2_1_1.xml b/.idea/libraries/javawriter_2_1_1.xml new file mode 100644 index 0000000..6630dda --- /dev/null +++ b/.idea/libraries/javawriter_2_1_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/javax_annotation_api_1_2.xml b/.idea/libraries/javax_annotation_api_1_2.xml new file mode 100644 index 0000000..4179473 --- /dev/null +++ b/.idea/libraries/javax_annotation_api_1_2.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/javax_inject_1.xml b/.idea/libraries/javax_inject_1.xml new file mode 100644 index 0000000..eebeedd --- /dev/null +++ b/.idea/libraries/javax_inject_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/jsr305_2_0_1.xml b/.idea/libraries/jsr305_2_0_1.xml new file mode 100644 index 0000000..cdf9878 --- /dev/null +++ b/.idea/libraries/jsr305_2_0_1.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/junit_4_12.xml b/.idea/libraries/junit_4_12.xml new file mode 100644 index 0000000..305df30 --- /dev/null +++ b/.idea/libraries/junit_4_12.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/recyclerview_v7_25_1_0.xml b/.idea/libraries/recyclerview_v7_25_1_0.xml new file mode 100644 index 0000000..235cc84 --- /dev/null +++ b/.idea/libraries/recyclerview_v7_25_1_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/rules_0_5.xml b/.idea/libraries/rules_0_5.xml new file mode 100644 index 0000000..246a509 --- /dev/null +++ b/.idea/libraries/rules_0_5.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/runner_0_5.xml b/.idea/libraries/runner_0_5.xml new file mode 100644 index 0000000..773948e --- /dev/null +++ b/.idea/libraries/runner_0_5.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_annotations_25_1_0.xml b/.idea/libraries/support_annotations_25_1_0.xml new file mode 100644 index 0000000..28e7e5f --- /dev/null +++ b/.idea/libraries/support_annotations_25_1_0.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_compat_25_1_0.xml b/.idea/libraries/support_compat_25_1_0.xml new file mode 100644 index 0000000..7a4610f --- /dev/null +++ b/.idea/libraries/support_compat_25_1_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_core_ui_25_1_0.xml b/.idea/libraries/support_core_ui_25_1_0.xml new file mode 100644 index 0000000..b5c02dd --- /dev/null +++ b/.idea/libraries/support_core_ui_25_1_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_core_utils_25_1_0.xml b/.idea/libraries/support_core_utils_25_1_0.xml new file mode 100644 index 0000000..16c70c6 --- /dev/null +++ b/.idea/libraries/support_core_utils_25_1_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_fragment_25_1_0.xml b/.idea/libraries/support_fragment_25_1_0.xml new file mode 100644 index 0000000..ae5b04b --- /dev/null +++ b/.idea/libraries/support_fragment_25_1_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_media_compat_25_1_0.xml b/.idea/libraries/support_media_compat_25_1_0.xml new file mode 100644 index 0000000..f12c6eb --- /dev/null +++ b/.idea/libraries/support_media_compat_25_1_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_v4_25_1_0.xml b/.idea/libraries/support_v4_25_1_0.xml new file mode 100644 index 0000000..d1d6929 --- /dev/null +++ b/.idea/libraries/support_v4_25_1_0.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_vector_drawable_25_1_0.xml b/.idea/libraries/support_vector_drawable_25_1_0.xml new file mode 100644 index 0000000..7df1c78 --- /dev/null +++ b/.idea/libraries/support_vector_drawable_25_1_0.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/transition_25_1_0.xml b/.idea/libraries/transition_25_1_0.xml new file mode 100644 index 0000000..5fdc7f5 --- /dev/null +++ b/.idea/libraries/transition_25_1_0.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7158618 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..09aaf31 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..fa672f0 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.1" + defaultConfig { + applicationId "com.dx.waverefresh" + minSdkVersion 16 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:25.1.0' + compile 'com.android.support:design:25.1.0' + compile project(':library') + testCompile 'junit:junit:4.12' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..e849e16 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/Miutrip_iMac/Documents/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/dx/waverefresh/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/dx/waverefresh/ExampleInstrumentedTest.java new file mode 100644 index 0000000..6aa16a3 --- /dev/null +++ b/app/src/androidTest/java/com/dx/waverefresh/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.dx.waverefresh; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.dx.waverefresh", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..74462d4 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/dx/waverefresh/DemoActivity.java b/app/src/main/java/com/dx/waverefresh/DemoActivity.java new file mode 100644 index 0000000..56e819b --- /dev/null +++ b/app/src/main/java/com/dx/waverefresh/DemoActivity.java @@ -0,0 +1,65 @@ +package com.dx.waverefresh; + +import android.graphics.Color; +import android.os.Build; +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.FrameLayout; + +import com.dx.waverefresh.lib.WaveRefreshLayout; +import com.dx.waverefresh.widget.RefreshScrollView; + + +public class DemoActivity extends AppCompatActivity { + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_demo); + + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ + getWindow().setStatusBarColor(Color.TRANSPARENT); + getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } + + final RefreshScrollView scrollView = (RefreshScrollView) findViewById(R.id.scrollView); + scrollView.setOnStartRefreshingListener(new RefreshScrollView.OnStartRefreshingListener() { + @Override + public void startRefreshing() { + scrollView.postDelayed(new Runnable() { + @Override + public void run() { + scrollView.stopLoading(); + } + },3000); + } + }); + + WaveRefreshLayout layout = (WaveRefreshLayout)findViewById(R.id.contentLayout); + FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab); + fab.setImageResource(R.drawable.share); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + } + }); + + /** + * calculate & set the top margin of float action button + */ + FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)fab.getLayoutParams(); + int fabSize = (int)(49*getResources().getDisplayMetrics().density); + int top = (int)layout.getGradientTop(params.rightMargin + fabSize/2)-fabSize/2; + layout.setPaddingTop(top); + + /** + * scale the fab with gesture,hide the fab when loading + */ + scrollView.setAnimatableView(fab); + } + +} diff --git a/app/src/main/java/com/dx/waverefresh/widget/RefreshScrollView.java b/app/src/main/java/com/dx/waverefresh/widget/RefreshScrollView.java new file mode 100644 index 0000000..365cd24 --- /dev/null +++ b/app/src/main/java/com/dx/waverefresh/widget/RefreshScrollView.java @@ -0,0 +1,216 @@ +package com.dx.waverefresh.widget; + + +import android.animation.Animator; +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewConfiguration; +import android.view.animation.AccelerateDecelerateInterpolator; +import android.view.animation.BounceInterpolator; +import android.widget.ScrollView; + +import com.dx.waverefresh.lib.WaveRefreshLayout; + +public class RefreshScrollView extends ScrollView{ + + + private float downY; + + private WaveRefreshLayout mContentLayout; + + private float touchSlop; + + private OnStartRefreshingListener mOnStartRefreshingListener; + + private View mAnimatableView; + + private int animationDuration; + + private boolean startRefresh = false; + + public RefreshScrollView(Context context) { + super(context); + init(); + } + + public RefreshScrollView(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public RefreshScrollView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + private void init(){ + touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); + animationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime); + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + mContentLayout = (WaveRefreshLayout) getChildAt(0); + } + + /** + * process pull down to refresh touch event + * @param ev + * @return + */ + @Override + public boolean onTouchEvent(MotionEvent ev) { + + if(mContentLayout.isLoading()){ + return super.onTouchEvent(ev); + } + + if(ev.getAction() == MotionEvent.ACTION_DOWN && getScrollY() == 0){ + startRefresh = true; + downY = ev.getY(); + } + + if(ev.getAction() == MotionEvent.ACTION_MOVE && startRefresh){ + float diff = ev.getY() - downY; + if(diff > touchSlop && diff < getHeight()/5.0f){ + float p = diff/(getHeight()/5.0f); + mContentLayout.setBackgroundOffset(p); + scaleAnimationView(p); + } + } + + if(ev.getAction() == MotionEvent.ACTION_UP && startRefresh){ + float diff = ev.getY() - downY; + + if(diff >= getHeight()/5.0f){ + mContentLayout.startLoadingAnimation(); + if(mOnStartRefreshingListener != null){ + mOnStartRefreshingListener.startRefreshing(); + playScaleAnimation(); + } + }else if(diff > touchSlop){ + mContentLayout.restoreBackground(); + playRestoreScaleAnimation(); + } + + startRefresh = false; + downY = 0; + } + + return super.onTouchEvent(ev); + } + + + public void setOnStartRefreshingListener(OnStartRefreshingListener listener){ + this.mOnStartRefreshingListener = listener; + } + + + public void stopLoading(){ + mContentLayout.stopLoading(); + playStopAnimation(); + } + + /** + * set the view that animate with user's gesture. + */ + public void setAnimatableView(View view){ + this.mAnimatableView = view; + } + + private void scaleAnimationView(float p){ + if(mAnimatableView != null){ + float scale = p > 0.9 ? 0 : 1 - p - .1f; + mAnimatableView.setScaleX(scale); + mAnimatableView.setScaleY(scale); + } + } + + private void playRestoreScaleAnimation(){ + + if(mAnimatableView == null){ + return; + } + + ObjectAnimator animatorSX = ObjectAnimator.ofFloat(mAnimatableView,"scaleX",mAnimatableView.getScaleX(),1); + ObjectAnimator animatorSY = ObjectAnimator.ofFloat(mAnimatableView,"scaleY",mAnimatableView.getScaleY(),1); + + AnimatorSet set = new AnimatorSet(); + set.setDuration(animationDuration); + set.playTogether(animatorSX,animatorSY); + set.setInterpolator(new BounceInterpolator()); + set.start(); + } + + private void playScaleAnimation(){ + + if(mAnimatableView == null){ + return; + } + + ObjectAnimator animatorSX = ObjectAnimator.ofFloat(mAnimatableView,"scaleX",mAnimatableView.getScaleX(),0); + ObjectAnimator animatorSY = ObjectAnimator.ofFloat(mAnimatableView,"scaleY",mAnimatableView.getScaleY(),0); + + AnimatorSet set = new AnimatorSet(); + set.setDuration(animationDuration); + set.playTogether(animatorSX,animatorSY); + set.setInterpolator(new BounceInterpolator()); + set.addListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animator) { + + } + + @Override + public void onAnimationEnd(Animator animator) { + mAnimatableView.setVisibility(View.INVISIBLE); + } + + @Override + public void onAnimationCancel(Animator animator) { + + } + + @Override + public void onAnimationRepeat(Animator animator) { + + } + }); + set.start(); + } + + private void playStopAnimation(){ + + if(mAnimatableView == null){ + return; + } + + if(mAnimatableView.getVisibility() != View.VISIBLE){ + mAnimatableView.setVisibility(View.VISIBLE); + } + + ObjectAnimator animatorSX = ObjectAnimator.ofFloat(mAnimatableView,"scaleX",0,1); + ObjectAnimator animatorSY = ObjectAnimator.ofFloat(mAnimatableView,"scaleY",0,1); + + AnimatorSet set = new AnimatorSet(); + set.setDuration(animationDuration); + set.setStartDelay(animationDuration); + set.playTogether(animatorSX,animatorSY); + set.setInterpolator(new AccelerateDecelerateInterpolator()); + set.start(); + } + + /** + * start refreshing callback + */ + public interface OnStartRefreshingListener{ + void startRefreshing(); + + } + +} diff --git a/app/src/main/res/drawable-hdpi/image.jpg b/app/src/main/res/drawable-hdpi/image.jpg new file mode 100644 index 0000000..9e84ec0 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/image.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/share.png b/app/src/main/res/drawable-xhdpi/share.png new file mode 100644 index 0000000..3fc26b3 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/share.png differ diff --git a/app/src/main/res/layout/activity_demo.xml b/app/src/main/res/layout/activity_demo.xml new file mode 100644 index 0000000..9f256b5 --- /dev/null +++ b/app/src/main/res/layout/activity_demo.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..9a078e3 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..efc028a Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..3af2608 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..9bec2e6 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..aee44e1 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..34947cd Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..ddc59ea --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,7 @@ + + + #3F51B5 + #303F9F + #FF4081 + #FFFFFF + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..19ea162 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,8 @@ + + DxWaveRefresh + Blockchain + A blockchain [originally block chain] is a distributed database that maintains a continuously-growing list of ordered records called blocks.Each block contains a timestamp and a link to a previous block.By design blockchains are inherently resistant to modification of the data - once recorded, the data in a block cannot be altered retroactively. + Blockchains are secure by design and an example of a distributed computing system with high byzantine fault tolerance.Decentralised consensus can therefore be achieved with a blockchain.This makes blockchains suitable for the recording of events, title, medical records and other records management activities,identity management, transaction processing and proving provenance.[citation needed] This offers the potential of mass disintermediation and vast repercussions for how global trade is conducted.The first blockchain was conceptualised by Satoshi Nakamoto in 2008 and implemented the following year as a core component of the digital currency bitcoin,where it serves as the public ledger for all transactions.Through the use of a peer-to-peer network and a distributed timestamping server a blockchain database is managed autonomously.The invention of the blockchain for bitcoin made it the first digital currency to solve the double spending problem.The bitcoin design has been the inspiration for other applications. + History\nFirst work on cryptographically secured chain of blocks was described in 1991 by Stuart Haber and W. Scott Stornetta.Followed by publications in 1996 by Ross J. Anderson and 1998 by Bruce Schneier and John Kelsey.In parallel there was work going on in 1998 by Nick Szabo working on a mechanism for a decentralized digital currency that he called bit gold.In 2000 Stefan Konst published a general theory for cryptographic secured chains and suggested a set of solutions for implementation. + The first blockchain was then conceptualised by Satoshi Nakamoto in 2008 and implemented the following year as a core component of the digital currency bitcoin,where it serves as the public ledger for all transactions.Through the use of a peer-to-peer network and a distributed timestamping server a blockchain database is managed autonomously. + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..b97380e --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/app/src/test/java/com/dx/waverefresh/ExampleUnitTest.java b/app/src/test/java/com/dx/waverefresh/ExampleUnitTest.java new file mode 100644 index 0000000..e7a8016 --- /dev/null +++ b/app/src/test/java/com/dx/waverefresh/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.dx.waverefresh; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..ec6c86a --- /dev/null +++ b/build.gradle @@ -0,0 +1,23 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.3.0-beta1' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..aac7c9b --- /dev/null +++ b/gradle.properties @@ -0,0 +1,17 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..e421c7c --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Dec 26 16:23:12 CST 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..9d82f78 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..aec9973 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/library/.gitignore b/library/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/library/.gitignore @@ -0,0 +1 @@ +/build diff --git a/library/build.gradle b/library/build.gradle new file mode 100644 index 0000000..9226528 --- /dev/null +++ b/library/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.android.library' +apply plugin: 'com.github.dcendents.android-maven' + +group='com.github.StevenDXC' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.1" + + defaultConfig { + minSdkVersion 16 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:25.1.0' + testCompile 'junit:junit:4.12' +} diff --git a/library/proguard-rules.pro b/library/proguard-rules.pro new file mode 100644 index 0000000..e849e16 --- /dev/null +++ b/library/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/Miutrip_iMac/Documents/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/library/src/androidTest/java/com/dx/waverefresh/ExampleInstrumentedTest.java b/library/src/androidTest/java/com/dx/waverefresh/ExampleInstrumentedTest.java new file mode 100644 index 0000000..7615f40 --- /dev/null +++ b/library/src/androidTest/java/com/dx/waverefresh/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.dx.waverefresh; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.dx.waverefresh.test", appContext.getPackageName()); + } +} diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml new file mode 100644 index 0000000..7c21a04 --- /dev/null +++ b/library/src/main/AndroidManifest.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/library/src/main/java/com/dx/waverefresh/lib/ShapeBackgroundDrawable.java b/library/src/main/java/com/dx/waverefresh/lib/ShapeBackgroundDrawable.java new file mode 100644 index 0000000..a2d78dc --- /dev/null +++ b/library/src/main/java/com/dx/waverefresh/lib/ShapeBackgroundDrawable.java @@ -0,0 +1,330 @@ +package com.dx.waverefresh.lib; + + +import android.animation.Animator; +import android.animation.AnimatorSet; +import android.animation.ValueAnimator; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.PixelFormat; +import android.graphics.Rect; +import android.graphics.drawable.Animatable; +import android.graphics.drawable.Drawable; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.view.Choreographer; + + +class ShapeBackgroundDrawable extends Drawable implements Animatable{ + + + public int color; + /*** + * angle of tilt + */ + public int angle; + + /** + * amplitude of wave + */ + public float waveAmplitude; + /** + * top margin of shape + */ + public float topMargin; + + /** + * the direction of tilt, 0:left, 1:right + */ + public int gravity; + + + private Paint mPaint; + private Path mPath; + + /** + * tilting height + */ + private float initOffset; + + /** + * dynamic tilting height,change the value for frame animation. + */ + private float offset; + + /** + * dynamic top margin,change the value for frame animation. + */ + private float topMarginOffset; + + /** + * bounds of this drawable + */ + private Rect rect; + + + private boolean isLoading; + + /** + * wave bitmap transition x and y + */ + private float tx = 0,ty = 0; + + /** + * wave bitmap Matrix + */ + private Matrix mMatrix; + + /** + * draw 4 arc to this bitmap, simulate the shape of wave + */ + private Bitmap mWaveBitmap; //waveImage + + /** + * the top of waveBitmap + */ + private float mWaveTop; + + private Choreographer.FrameCallback mFrameCallback = new Choreographer.FrameCallback() { + @Override + public void doFrame(long l) { + invalidateSelf(); + if (isLoading) { + Choreographer.getInstance().postFrameCallback(this); + } + } + }; + + + public ShapeBackgroundDrawable(){ + + mPath = new Path(); + + mPaint = new Paint(); + mPaint.setAntiAlias(true); + mPaint.setStyle(Paint.Style.FILL); + + mMatrix = new Matrix(); + isLoading = false; + } + + + @Override + public void setBounds(int left, int top, int right, int bottom) { + super.setBounds(left, top, right, bottom); + + if(rect == null) { + rect = new Rect(left, top, right, bottom); + topMarginOffset = topMargin; + mPaint.setColor(color); + offset = initOffset = (float) Math.abs(Math.tan(angle / 180.0f * Math.PI) * (right - left)); + mWaveTop = topMargin - initOffset/2; + ty = waveAmplitude/2; // set wave bitmap transition to half of waveAmplitude + + //draw filled arc to bitmap + mWaveBitmap = Bitmap.createBitmap(right * 2, (int)waveAmplitude * 2, Bitmap.Config.ARGB_4444); + Canvas c = new Canvas(mWaveBitmap); + Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); + p.setColor(color); + p.setStyle(Paint.Style.FILL); + + Path path = new Path(); + path.moveTo(0, waveAmplitude); + path.quadTo(rect.right / 4, 0, rect.right / 2, waveAmplitude); + path.quadTo(rect.right / 4 * 3, waveAmplitude * 2, rect.right, waveAmplitude); + path.quadTo(rect.right / 4 * 5, 0, rect.right * 1.5f, waveAmplitude); + path.quadTo(rect.right / 4 * 7, waveAmplitude * 2, rect.right * 2f, waveAmplitude); + path.lineTo(rect.right * 2, waveAmplitude * 2); + path.lineTo(0, waveAmplitude * 2); + path.close(); + + c.drawPath(path, p); + } + } + + @Override + public void draw(@NonNull Canvas canvas) { + + int sc = canvas.saveLayer(0, 0, rect.width(), rect.height(), null, Canvas.ALL_SAVE_FLAG); + + if(isLoading){ + //while loading,draw wave bitmap,and translate the bitmap from left to right. + canvas.drawRect(0,mWaveTop+waveAmplitude*2,rect.right,rect.bottom,mPaint); + mMatrix.setTranslate(tx,mWaveTop+ty); + canvas.drawBitmap(mWaveBitmap,mMatrix,mPaint); + tx -= 10; + if(tx <= -rect.right){ + tx += rect.right; + } + }else{ + mPath.reset(); + if(gravity == 0){ + mPath.moveTo(0,topMarginOffset); + mPath.lineTo(rect.right,topMarginOffset-offset); + }else{ + mPath.moveTo(0,topMarginOffset-offset); + mPath.lineTo(rect.right,topMarginOffset); + } + mPath.lineTo(rect.right,rect.bottom); + mPath.lineTo(0,rect.bottom); + mPath.close(); + canvas.drawPath(mPath,mPaint); + } + + canvas.restoreToCount(sc); + + } + + @Override + public void setAlpha(@IntRange(from = 0, to = 255) int i) { + mPaint.setAlpha(i); + } + + @Override + public void setColorFilter(@Nullable ColorFilter colorFilter) { + mPaint.setColorFilter(colorFilter); + } + + @Override + public int getOpacity() { + return PixelFormat.TRANSLUCENT; + } + + + @Override + public void start() { + isLoading = true; + Choreographer.getInstance().postFrameCallback(mFrameCallback); + } + + @Override + public void stop() { + stopLoadingAnimation(); + } + + @Override + public boolean isRunning() { + return isLoading; + } + + public void setLoading(boolean isLoading){ + this.isLoading = isLoading; + } + + public float getOffsetY(){ + return initOffset; + } + + /** + * get the top of wave in the middle of drawable + */ + public int getCurrentWaveTop(){ + float x = -tx; + float f = x%(rect.right/4); + int d = (int)(x/(rect.right/4)); + float v = 0; + switch (d){ + case 0: + v = f/(rect.right/4) * -waveAmplitude; + break; + case 1: + v = -waveAmplitude + waveAmplitude*f/(rect.right/4); + break; + case 2: + v = waveAmplitude*f/(rect.right/4); + break; + case 3: + v = waveAmplitude - waveAmplitude*f/(rect.right/4); + break; + } + return (int)v; + } + + public float getTopMargin(){ + return topMargin; + } + + public void setTopMargin(float progress){ + topMarginOffset = topMargin + initOffset*progress; + offset = initOffset * (1.0f - progress); + invalidateSelf(); + } + + public float getGradientTop(float x){ + return topMargin - (float)Math.abs(Math.tan(angle/180.0f*Math.PI)) * x; + } + + public Animator getPreLoadingAnimator(){ + ValueAnimator animator = ValueAnimator.ofFloat(waveAmplitude/2,0); + animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator valueAnimator) { + ty = (Float) valueAnimator.getAnimatedValue(); + invalidateSelf(); + } + }); + return animator; + } + + private void stopLoadingAnimation(){ + ValueAnimator animator = ValueAnimator.ofFloat(0,waveAmplitude); + animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator valueAnimator) { + ty = (Float) valueAnimator.getAnimatedValue(); + } + }); + + ValueAnimator animator2 = ValueAnimator.ofFloat(0,initOffset); + animator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator valueAnimator) { + offset = (Float) valueAnimator.getAnimatedValue(); + } + }); + + ValueAnimator animator3 = ValueAnimator.ofFloat(topMargin, topMargin); + animator3.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator valueAnimator) { + topMargin = (Float) valueAnimator.getAnimatedValue(); + invalidateSelf(); + } + }); + + AnimatorSet set = new AnimatorSet(); + set.setDuration(300); + set.playTogether(animator,animator2,animator3); + set.addListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animator) { + + } + + @Override + public void onAnimationEnd(Animator animator) { + isLoading = false; + Choreographer.getInstance().removeFrameCallback(mFrameCallback); + invalidateSelf(); + } + + @Override + public void onAnimationCancel(Animator animator) { + + } + + @Override + public void onAnimationRepeat(Animator animator) { + + } + }); + set.start(); + } + + +} diff --git a/library/src/main/java/com/dx/waverefresh/lib/WaveRefreshLayout.java b/library/src/main/java/com/dx/waverefresh/lib/WaveRefreshLayout.java new file mode 100644 index 0000000..2860239 --- /dev/null +++ b/library/src/main/java/com/dx/waverefresh/lib/WaveRefreshLayout.java @@ -0,0 +1,176 @@ +package com.dx.waverefresh.lib; + + +import android.animation.Animator; +import android.animation.AnimatorSet; +import android.animation.ValueAnimator; +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Color; +import android.util.AttributeSet; +import android.view.animation.BounceInterpolator; +import android.widget.LinearLayout; + +public class WaveRefreshLayout extends LinearLayout{ + + private ShapeBackgroundDrawable background; + private boolean isLoading; + private float topImageHeight; + private int mPaddingTop; + + public WaveRefreshLayout(Context context) { + super(context); + init(null); + } + + public WaveRefreshLayout(Context context, AttributeSet attrs) { + super(context, attrs); + init(attrs); + } + + public WaveRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(attrs); + } + + + private void init(AttributeSet attrs){ + + background = new ShapeBackgroundDrawable(); + if(attrs != null){ + + TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.WaveRefreshLayout); + background.color = ta.getInt(R.styleable.WaveRefreshLayout_wr_bgColor, Color.WHITE); + background.topMargin = topImageHeight = ta.getDimensionPixelSize(R.styleable.WaveRefreshLayout_wr_topImageHeight,getResources().getDimensionPixelOffset(R.dimen.defaultTopImageHeight)); + background.angle = ta.getInt(R.styleable.WaveRefreshLayout_wr_angle,10); + background.gravity = ta.getInt(R.styleable.WaveRefreshLayout_wr_gravity,1); + background.waveAmplitude = ta.getDimensionPixelSize(R.styleable.WaveRefreshLayout_wr_waveHeight,40); + ta.recycle(); + + }else{ + background.color = Color.WHITE; + background.topMargin = topImageHeight = getResources().getDimensionPixelOffset(R.dimen.defaultTopImageHeight); + background.angle = 10; + background.gravity = 1; + background.waveAmplitude = 40; + } + mPaddingTop = (int)topImageHeight; + setPadding(getPaddingLeft(),(int)topImageHeight,getPaddingRight(),getPaddingBottom()); + setBackground(background); + } + + /** + * set the shape background margin and shape. and change the top padding of this view when user dragging + * @param progress + */ + public void setBackgroundOffset(float progress){ + background.setTopMargin(progress); + adjustPaddingTop((int)(background.getOffsetY()*progress)); + } + + + public void setPaddingTop(int paddingTop){ + mPaddingTop = paddingTop; + setPadding(getPaddingLeft(),mPaddingTop,getPaddingRight(),getPaddingBottom()); + } + + private void adjustPaddingTop(int padding){ + setPadding(getPaddingLeft(),mPaddingTop+padding,getPaddingRight(),getPaddingBottom()); + } + + /** + * while touch up,restore the background to the initial state + */ + public void restoreBackground(){ + background.setLoading(false); + startAnimation(false); + } + + /** + * start play loading animation + */ + public void startLoadingAnimation(){ + background.setLoading(true); + startAnimation(true); + } + + public Boolean isLoading(){ + return isLoading; + } + + private void startLoading(){ + isLoading = true; + background.start(); + } + + private void startAnimation(boolean startLoading){ + + ValueAnimator animator = ValueAnimator.ofFloat(background.getTopMargin(),topImageHeight); + animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator valueAnimator) { + float value = (Float) valueAnimator.getAnimatedValue(); + background.setTopMargin(value - topImageHeight); + } + }); + + ValueAnimator animatorPadding = ValueAnimator.ofInt(getPaddingTop(),mPaddingTop); + animatorPadding.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator valueAnimator) { + int value = (Integer) valueAnimator.getAnimatedValue(); + setPadding(0,value,0,0); + } + }); + + AnimatorSet set = new AnimatorSet(); + if(startLoading){ + set.playTogether(animator,animatorPadding,background.getPreLoadingAnimator()); + }else{ + set.playTogether(animator,animatorPadding); + } + set.setDuration(300); + set.setInterpolator(new BounceInterpolator()); + if(startLoading){ + set.addListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animator) { } + + @Override + public void onAnimationEnd(Animator animator) { + startLoading(); + } + + @Override + public void onAnimationCancel(Animator animator) { } + + @Override + public void onAnimationRepeat(Animator animator) { } + }); + } + set.start(); + } + + + /** + * stop play the loading animation + */ + public void stopLoading(){ + if(!isLoading){ + return; + } + + isLoading = false; + background.stop(); + } + + /** + * get the y value of point that in oblique line. + * @param x the distance of from lowest point to current point in the oblique line + * @return y in the oblique line + */ + public float getGradientTop(float x){ + return background.getGradientTop(x); + } + +} diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml new file mode 100644 index 0000000..136313c --- /dev/null +++ b/library/src/main/res/values/attrs.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/library/src/main/res/values/dimens.xml b/library/src/main/res/values/dimens.xml new file mode 100644 index 0000000..54fd9b1 --- /dev/null +++ b/library/src/main/res/values/dimens.xml @@ -0,0 +1,4 @@ + + + 240dp + diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml new file mode 100644 index 0000000..6d51856 --- /dev/null +++ b/library/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Library + diff --git a/library/src/test/java/com/dx/waverefresh/ExampleUnitTest.java b/library/src/test/java/com/dx/waverefresh/ExampleUnitTest.java new file mode 100644 index 0000000..e7a8016 --- /dev/null +++ b/library/src/test/java/com/dx/waverefresh/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.dx.waverefresh; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..3306997 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':app', ':library'