Repository: YuanClouds/WaveView
Branch: master
Commit: 7bd89d2262d9
Files: 45
Total size: 71.7 KB
Directory structure:
gitextract_a4vqsdf9/
├── .idea/
│ ├── libraries/
│ │ ├── animated_vector_drawable_24_0_0_beta1.xml
│ │ ├── appcompat_v7_24_0_0_beta1.xml
│ │ ├── espresso_core_2_2_2.xml
│ │ ├── espresso_idling_resource_2_2_2.xml
│ │ ├── exposed_instrumentation_api_publish_0_5.xml
│ │ ├── rules_0_5.xml
│ │ ├── runner_0_5.xml
│ │ ├── support_annotations_24_0_0_beta1.xml
│ │ ├── support_v4_24_0_0_beta1.xml
│ │ └── support_vector_drawable_24_0_0_beta1.xml
│ └── vcs.xml
├── .travis.yml
├── README.md
├── app/
│ └── build/
│ ├── BUILD_README
│ └── sample-debug.apk
├── build.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── sample/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ ├── androidTest/
│ │ └── java/
│ │ └── com/
│ │ └── wave/
│ │ └── sample/
│ │ └── ExampleInstrumentedTest.java
│ ├── main/
│ │ ├── AndroidManifest.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── wave/
│ │ │ └── sample/
│ │ │ └── MainActivity.java
│ │ └── res/
│ │ ├── layout/
│ │ │ └── activity_main.xml
│ │ ├── values/
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── values-w820dp/
│ │ └── dimens.xml
│ └── test/
│ └── java/
│ └── com/
│ └── wave/
│ └── sample/
│ └── ExampleUnitTest.java
├── settings.gradle
└── wavekit/
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src/
├── androidTest/
│ └── java/
│ └── com/
│ └── yuan/
│ └── waveview/
│ └── ExampleInstrumentedTest.java
├── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── com/
│ │ └── yuan/
│ │ └── waveview/
│ │ ├── WaveView.java
│ │ └── utils/
│ │ └── DensityUtil.java
│ └── res/
│ └── values/
│ ├── attrs.xml
│ ├── colors.xml
│ └── strings.xml
└── test/
└── java/
└── com/
└── yuan/
└── waveview/
└── ExampleUnitTest.java
================================================
FILE CONTENTS
================================================
================================================
FILE: .idea/libraries/animated_vector_drawable_24_0_0_beta1.xml
================================================
================================================
FILE: .idea/libraries/appcompat_v7_24_0_0_beta1.xml
================================================
================================================
FILE: .idea/libraries/espresso_core_2_2_2.xml
================================================
================================================
FILE: .idea/libraries/espresso_idling_resource_2_2_2.xml
================================================
================================================
FILE: .idea/libraries/exposed_instrumentation_api_publish_0_5.xml
================================================
================================================
FILE: .idea/libraries/rules_0_5.xml
================================================
================================================
FILE: .idea/libraries/runner_0_5.xml
================================================
================================================
FILE: .idea/libraries/support_annotations_24_0_0_beta1.xml
================================================
================================================
FILE: .idea/libraries/support_v4_24_0_0_beta1.xml
================================================
================================================
FILE: .idea/libraries/support_vector_drawable_24_0_0_beta1.xml
================================================
================================================
FILE: .idea/vcs.xml
================================================
================================================
FILE: .travis.yml
================================================
language: android
android:
components:
- tools
- build-tools-24.0.1
- android-24
- extra-android-m2repository
jdk: oraclejdk8
sudo: false
cache:
directories:
- "$HOME/.gradle"
before_install:
- chmod +x gradlew
script:
- "./gradlew assembleRelease"
deploy:
provider: releases
api_key:
secure: wLTt8G7RWQsF2KGMwmHlYoTBSSP/YkZxy+nyIc+yekwoRgZGhxHoI6pZbime2BhAJ0Ag7ZDEulpjYzJkjZ08OMlWoFa+eelykyzcR+S+o43frVnafYlWDR6XTrjGoKzPZ+KqyNVwrTU5csu1bJ16DqCCQqK+WC6LsRvRX0m0LREMNdgEJ5sVuoVbE/Do2wTZPRri9VBLVYwyFBsmNHLhW4xKhPUNwmHRU6zEhO1uVg8JCn4z3PJaRblcapdrp/JOFDFfOR/u4AW9ctzIRaTcSqV82mWvRyiWbFjilgw9tNlVCTykcLvNZKDa+Z8sWXpTpLlmgS43HxDZewdQ+NGIy8ihdKXz8x6EonGMM4mWeIkS1osm5EdpBlhfx+tt7mpHkp+r/FzZh7qrbT98JquZBYkqzEsOR8BXv6sw0Jai9KMPHDzkgAtDGS6Ir9FBIw3Kf+3r/iCe6wxdvnTzySPnPCffQ/fbENHVqvMAZqNRpolF7l3O40ZRhNPEpYG/9WekzDs37Udl8q2w80FTniDtgZWxnc1vIdbj5yHwRW1ipQLMNUBiQIgYx9Axiw96WzJMo0J6ezGWYQwrbdZ54TpluXGbCSQv5s3qChniKK+45FWWXPu4LXPSrqu+IT8swgeJR33f9aZ2jfp2Qbm2mhZPY5xXbSV/Cawh5F5eDQz+lEg=
file: app/build/sample-debug.apk
skip_cleanup: true
on:
tags: false
all_branches: true
================================================
FILE: README.md
================================================
# WaveView
### Thank you for your support!
Imitate the Android progress of method, At present support functions:
1. waveview to support the dynamic change of progress
2. waveview to support the progress callback Activity or fragments, use mask effect and the property animation
3. waveview to support custom change wave properties, including color wave, wave speed, wave shape of container (currently support circle, rectangular, and mask drawable)
Details you can run the Demo and study the source code.
### My :
E-mail : sy.wu@foxmail.com
Blog : http://www.jianshu.com/users/d388bcf9c4d3/
**KeyWord** rolling wave ,normal wave.waveview shapes,speed mode,shado...
### Demo :

### How to use it?
#### First
Add repositories and dependencies into your project
```java
// repositories
repositories {
maven { url = 'https://dl.bintray.com/yuancloud/maven/' }
}
// dependencies
compile 'cn.yuancloud.app:wavekit:1.0'
```
Add a WaveView into your XML
```java
```
"backgroundColor" is the view color
"progressColor" is the wave color
"max" is the max progress
#### Second
You can be a series of operations in the Activity or Fragment.such as :
(1) set WaveView Shape
```
waveView.setMode(WaveView.MODE_RECT);
```
(2) set WaveView Color
```
waveView.setWaveColor(Color.RED);
waveView.setbgColor(Color.WHITE);
```
(3) set WaveView flowing speed
```
waveView.setSpeed(WaveView.SPEED_FAST);
```
(4) set WaveView progress or max
```
waveView.setProgress(progress);
waveView.setMax(100);
```
#### Last
How to listen progress of waveView in Activity or Fragmenet?
```
waveView.setProgressListener(new WaveView.waveProgressListener() {
@Override
public void onPorgress(boolean isDone, long progress, long max) {
if (isDone){
Toast.makeText(MainActivity.this,"Loading completed!!!",Toast.LENGTH_SHORT).show();
}
}
});
```
### Thank you for your support!
### Enjoy ~
================================================
FILE: app/build/BUILD_README
================================================
================================================
FILE: build.gradle
================================================
// 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.1.0'
// 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
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
================================================
FILE: gradlew
================================================
#!/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 "$@"
================================================
FILE: gradlew.bat
================================================
@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
================================================
FILE: sample/.gitignore
================================================
local.properties
.idea
*.iml
.gradle
build
================================================
FILE: sample/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.wave.sample"
minSdkVersion 18
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url = 'https://dl.bintray.com/yuancloud/maven/' }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
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:24.0.0-beta1'
testCompile 'junit:junit:4.12'
compile project(':wavekit')
// compile 'cn.yuancloud.app:wavekit:1.0'
}
================================================
FILE: sample/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\AndroidStudio_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 *;
#}
================================================
FILE: sample/src/androidTest/java/com/wave/sample/ExampleInstrumentedTest.java
================================================
package com.wave.sample;
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.wave.sample", appContext.getPackageName());
}
}
================================================
FILE: sample/src/main/AndroidManifest.xml
================================================
================================================
FILE: sample/src/main/java/com/wave/sample/MainActivity.java
================================================
package com.wave.sample;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.yuan.waveview.WaveView;
import java.text.NumberFormat;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
WaveView waveView;
Button button,speedBtn;
TextView progressTv;
RadioGroup radioGroup;
RadioGroup radioGroupColor;
RadioGroup radioGroupSpeed;
int count = 0;
private static final int max = 10;
int speed = 5;
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == 100){
if (max >= count) {
Log.d("demo",count + "");
waveView.setProgress(count);
}else {
resetTimer();
}
count++;
}
}
};
private TimerTask timerTask = new TimerTask() {
@Override
public void run() {
handler.sendEmptyMessage(100);
}
};
private Timer timer = new Timer();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initListener();
}
private void initView(){
waveView = (WaveView) findViewById(R.id.waveview);
button = (Button) findViewById(R.id.button);
radioGroup = (RadioGroup) findViewById(R.id.radio_group);
radioGroupColor = (RadioGroup) findViewById(R.id.radio_group_color);
radioGroupSpeed = (RadioGroup) findViewById(R.id.radio_group_speed);
progressTv = (TextView) findViewById(R.id.pb_show_tv);
speedBtn = (Button) findViewById(R.id.speed);
waveView.setMax(max);
waveView.setWaveColor(ContextCompat.getColor(MainActivity.this,R.color.light_blue));
// waveView.setProgress(10);
}
private void initListener(){
final NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(2);
waveView.setProgressListener(new WaveView.waveProgressListener() {
@Override
public void onPorgress(boolean isDone, long progress, long max) {
Log.i("yuan","max " + max + "prgress "+progress);
progressTv.setText(numberFormat.format(progress/(float)max * 100) + "%");
if (isDone){
Toast.makeText(MainActivity.this,"Loading completed!!!",Toast.LENGTH_SHORT).show();
}
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//先重置
resetTimer();
doing();
}
});
speedBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int p = (int) (waveView.getProgress()+3);
waveView.setProgress(p);
}
});
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i){
case R.id.mode_circle:
waveView.setMode(WaveView.MODE_CIRCLE);
break;
case R.id.mode_rect:
waveView.setMode(WaveView.MODE_RECT);
break;
case R.id.mode_drawable:
waveView.setMode(WaveView.MODE_DRAWABLE);
break;
}
}
});
radioGroupColor.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i){
case R.id.color_black:
waveView.setWaveColor(ContextCompat.getColor(MainActivity.this,R.color.light_black));
break;
case R.id.color_red:
waveView.setWaveColor(ContextCompat.getColor(MainActivity.this,R.color.light_red));
break;
case R.id.color_blue:
waveView.setWaveColor(ContextCompat.getColor(MainActivity.this,R.color.light_blue));
break;
case R.id.color_green:
waveView.setWaveColor(ContextCompat.getColor(MainActivity.this,R.color.light_green));
break;
}
}
});
radioGroupSpeed.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i){
case R.id.speed_normal:
waveView.setSpeed(WaveView.SPEED_NORMAL);
break;
case R.id.speed_slow:
waveView.setSpeed(WaveView.SPEED_SLOW);
break;
case R.id.speed_fast:
waveView.setSpeed(WaveView.SPEED_FAST);
break;
}
}
});
}
public void doing(){
timerTask = new TimerTask() {
@Override
public void run() {
handler.sendEmptyMessage(100);
}
};
timer = new Timer();
timer.schedule(timerTask,1000,1000);
}
private void resetTimer(){
count = 0;
if (timer != null)
timer.cancel();
timer = null;
if (timerTask !=null)
timerTask.cancel();
timerTask = null;
}
}
================================================
FILE: sample/src/main/res/layout/activity_main.xml
================================================
================================================
FILE: sample/src/main/res/values/colors.xml
================================================
#6C7B8B
#00000000
#FF4081
================================================
FILE: sample/src/main/res/values/dimens.xml
================================================
16dp
16dp
================================================
FILE: sample/src/main/res/values/strings.xml
================================================
WaveView
傻小孩b \n welcome to QQ group : 450302004
================================================
FILE: sample/src/main/res/values/styles.xml
================================================
================================================
FILE: sample/src/main/res/values-w820dp/dimens.xml
================================================
64dp
================================================
FILE: sample/src/test/java/com/wave/sample/ExampleUnitTest.java
================================================
package com.wave.sample;
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);
}
}
================================================
FILE: settings.gradle
================================================
include ':sample', ':wavekit'
================================================
FILE: wavekit/.gitignore
================================================
local.properties
.idea
*.iml
.gradle
build
================================================
FILE: wavekit/build.gradle
================================================
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
minSdkVersion 18
targetSdkVersion 24
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:24.0.0-beta1'
testCompile 'junit:junit:4.12'
}
================================================
FILE: wavekit/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\AndroidStudio_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 *;
#}
================================================
FILE: wavekit/src/androidTest/java/com/yuan/waveview/ExampleInstrumentedTest.java
================================================
package com.yuan.waveview;
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.yuan.waveview.test", appContext.getPackageName());
}
}
================================================
FILE: wavekit/src/main/AndroidManifest.xml
================================================
================================================
FILE: wavekit/src/main/java/com/yuan/waveview/WaveView.java
================================================
package com.yuan.waveview;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.LinearInterpolator;
import com.yuan.waveview.utils.DensityUtil;
import java.util.ArrayList;
import java.util.List;
import static android.view.animation.Animation.INFINITE;
/**
* Created by Yuan on 2016/10/8.
* Detail wave for view
* --
* Thank you for your support!
* Imitate the Android progress of method, At present support functions:
*
* 1. waveview to support the dynamic change of progress,
* 2. waveview to support the progress callback Activity or fragments, use mask effect and the property animation,
* 3. waveview to support custom change wave properties, including color wave, wave speed, wave shape of container (currently support circle, rectangular, and mask drawable).
*
* Details you can run the Demo and study the source code.
*
* My :
* E-mail : sy.wu@foxmail.com
* Blog : http://www.jianshu.com/users/d388bcf9c4d3/
* --
*
* KeyWord rolling wave ,normal wave.waveview shapes,speed mode,shadow...
*/
public class WaveView extends View {
private final String TAG = "WaveView";
private Context mContext;
private Paint mPaint;
private Paint wavePaint;
/**
* The wave of the normal grain
*/
private Path wavePath;
/**
* The wave of the rolling grain
*/
private Path shadPath;
//mode
private int WAVE_COLOR = Color.BLUE;// Color for wave
private int BG_COLOR = Color.WHITE;// Color for view of background
/**
* the width and height for view < width and height is 300 dpi by default >>
*/
private float VIEW_WIDTH = 0f;
private float VIEW_HEIGHT = 0f;
private float VIEW_WIDTH_TMP = 0f;
private float VIEW_HEIGHT_TMP = 0f;
/**
* the width and height for wave < Width is half the width of view , Height is auto >>
*/
private float WAVE_WIDTH = 0f;
private float WAVE_HEIGHT = 0f;
/**
* There are three kinds of waveview shapes(mode), including circle、rect and drawable
* -- Drawable shape , you need to have default drawable
*/
public final static String MODE_CIRCLE = "circle";
public final static String MODE_RECT = "rect";
public final static String MODE_DRAWABLE = "drawable";
private String mode = MODE_CIRCLE; //default shape is circle
/**
* pointList : normal wave of original collection point
* shadpointList : rolling wave of original collection point
*/
private List pointList = new ArrayList<>();
private List shadpointList = new ArrayList<>();
/**
* < Sign control variables >>
*/
private boolean isInitPoint = true; // Init original collection point
private boolean isStartAnimation = false;// The first time for start the flowingAnimation
private boolean isDone = false;// whether to end
private boolean isMeasure = false;// The first time for measure view
private boolean isCompleteLayout = false;//just action when drawing finish
boolean isHasWindowFocus = false;// is hasWindowFocus
/**
* < value >>
*/
private float dy = 0;// height of the rise
private float old_dy = 0; //height of the rise ,often change
private float sum_dy = 0;// defalut height
private float beforDy = 0;//The last time the height of the rise
private float dx = 0;// Distance for Horizontal-Moving < normal wave >
private float shd_dx = 0;// Distance for Horizontal-Moving < rolling wave >
private float runRatio = 1.5f;
/**
* There are three kinds of waveview mode of speed , including slow、normal and fast
*/
public static float SPEED_SLOW = 10f; // Slow speed
public static float SPEED_NORMAL = 30f;// normal speed
public static float SPEED_FAST = 40f;// fast speed
private int isSlow = 0x01;
private int isNormal = 0x02;
private int isFast = 0x03;
private float speed = SPEED_NORMAL;// default speed
private int curSpeedMode = isNormal;
/**
* < the progress for waveview >>
*/
private long progress = 0;// The current progress
private long curProgress = 0;// The current progress , in order to deal with some logical work
private long max = 0;// The max progress
private float progressRatio = 0f;// ratio < result = progress / max >
private waveProgressListener progressListener;
private ValueAnimator reiseAnimator;
private ObjectAnimator flowingAnimato;
public WaveView(Context context) {
super(context);
init(context,null);
}
public WaveView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context,attrs);
}
private void init(Context context, AttributeSet attrs){
if (attrs != null){
//attars
TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.WaveView);
int bgColor = typedArray.getColor(R.styleable.WaveView_backgroudColor,BG_COLOR);
int pColor = typedArray.getColor(R.styleable.WaveView_progressColor,WAVE_COLOR);
int aMax = typedArray.getInt(R.styleable.WaveView_max, (int) max);
int aP = typedArray.getInteger(R.styleable.WaveView_progress, (int) progress);
BG_COLOR = bgColor;
WAVE_COLOR = pColor;
max = aMax;
progress = aP;
typedArray.recycle();
}
VIEW_WIDTH = DensityUtil.dip2px(context,300);
VIEW_HEIGHT = DensityUtil.dip2px(context,300);
wavePath = new Path();
shadPath = new Path();
wavePath.setFillType(Path.FillType.EVEN_ODD);
// shadPath.setFillType(Path.FillType.EVEN_ODD);
this.mContext = context;
mPaint= new Paint();
mPaint.setColor(BG_COLOR);
mPaint.setStrokeWidth(1);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setAntiAlias(true);
wavePaint = new Paint();
wavePaint.setColor(BG_COLOR);
wavePaint.setStrokeWidth(1);
wavePaint.setStyle(Paint.Style.FILL);
wavePaint.setAntiAlias(true);
// wavePaint.setAlpha(50);
this.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// TODO Auto-generated method stub
Log.i(TAG,"绘制完成");
setSpeed(speed);
if (isHasWindowFocus){
isCompleteLayout = true;
long cP = max - progress;
if (max >= progress) {
progressRatio = progress / (float) max;
dy = updateDyData();
// Log.i(TAG,"update dy " + dy);
getViewTreeObserver().removeOnGlobalLayoutListener(this);
isMeasure = true;
}
}
if (isHasWindowFocus){
}
VIEW_HEIGHT_TMP = VIEW_HEIGHT;
VIEW_WIDTH_TMP = VIEW_WIDTH;
Log.i(TAG,"tmp of width and tmp of hight is init ! "+VIEW_WIDTH_TMP +" "+VIEW_WIDTH_TMP);
}
});
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// Log.d(TAG,"onMeasure " +isHasWindowFocus);
if (!isMeasure) {
// 修正 高度 宽度必须一致,以较大的作为标准
getRealWidthMeasureSpec(widthMeasureSpec);
getRealHeightMeasureSpec(heightMeasureSpec);
if (VIEW_HEIGHT > VIEW_WIDTH){
VIEW_WIDTH = VIEW_HEIGHT;
}else{
VIEW_HEIGHT = VIEW_WIDTH;
}
setMeasuredDimension((int)VIEW_WIDTH,(int)VIEW_HEIGHT);
}
initPoint();
}
/**
* Initialize the original wave arts collection point , including normal wave ,rolling wave
*/
private void initPoint(){
if (isInitPoint){
isInitPoint = false;
pointList.clear();
shadpointList.clear();
WAVE_WIDTH = (float) (VIEW_WIDTH / 2.5);
// WAVE_HEIGHT = (float) (VIEW_HEIGHT / 50);
WAVE_HEIGHT = VIEW_HEIGHT/getWaveHeight();
dy = VIEW_HEIGHT;//Started from the bottom, when the height is rise, dy gradually reduce
//How many points calculated maximum support
int n = Math.round(VIEW_WIDTH / WAVE_WIDTH);
//start point for normal wave
int startX = 0;
Log.i(TAG,"begin point ("+DensityUtil.px2dip(mContext,startX)+" , "+DensityUtil.px2dip(mContext,dy)+")");
for (int i = 0; i < 4*n+1; i++) {
Point point = new Point();
point.y = (int) dy;
if (i == 0) {
point.x = startX;
} else {
startX += WAVE_WIDTH;
point.x = startX;
}
pointList.add(point);
}
// start point for rolling wave
startX = (int) VIEW_WIDTH;
for (int i = 0; i < 4*n+1; i++) {
Point point = new Point();
point.y = (int) dy;
if (i == 0) {
point.x = startX;
} else {
startX -= WAVE_WIDTH;
point.x = startX;
}
shadpointList.add(point);
}
//change speed base on view_width
SPEED_NORMAL = (DensityUtil.px2dip(mContext,VIEW_WIDTH)/20);
SPEED_SLOW = SPEED_NORMAL/2;
SPEED_FAST = SPEED_NORMAL * 2;
SPEED_NORMAL = SPEED_NORMAL ==0?1:SPEED_NORMAL;
SPEED_SLOW = SPEED_SLOW ==0?0.5f:SPEED_SLOW;
SPEED_FAST = SPEED_FAST ==0?2:SPEED_FAST;
if (curSpeedMode == isSlow){
speed = SPEED_SLOW;
}else if (curSpeedMode == isFast){
speed = SPEED_FAST;
}else{
speed = SPEED_NORMAL;
}
Log.i(TAG,"init speed ( normal : " + SPEED_NORMAL +" slow : "+SPEED_SLOW +" fast : "+SPEED_FAST +" )");
}
}
/**
* set waveProgressListener
* @param progressListener
*/
public void setProgressListener(waveProgressListener progressListener) {
this.progressListener = progressListener;
isDone = false;
}
private int getWaveHeight(){
if (speed == SPEED_FAST){
return 30;
}else if (speed == SPEED_SLOW){
return 70;
}else{
return 50;
}
}
/**
* set speed
* @param speed including slow、normal and fast
*/
public void setSpeed(float speed) {
if (speed == SPEED_FAST || speed == SPEED_NORMAL || speed == SPEED_SLOW) {
if (speed == SPEED_FAST){
curSpeedMode = isFast;
}else if (speed == SPEED_SLOW){
curSpeedMode = isSlow;
}else{
curSpeedMode = isNormal;
}
this.speed = speed;
dx = 0;
shd_dx = 0;
// rerefreshPoints();
}
}
/**
* set shape (mode)
* @param mode including circle、rect and drawable
*/
public void setMode(String mode) {
this.mode = mode;
}
/**
* set max progress
* @param max
*/
public void setMax(long max) {
this.max = max;
isDone = false;
}
/**
* set color for view of background
* @param color
*/
public void setbgColor(int color) {
this.BG_COLOR = color;
}
/**
* set color for wave of background
* @param color
*/
public void setWaveColor(int color) {
this.WAVE_COLOR = color;
}
/**
* set progress
* @param progress
*/
public void setProgress(long progress) {
mPaint.setColor(BG_COLOR);
mPaint.setAlpha(255);
isDone = false;
if (progress > max) {
if (this.progress < max) progress = max;
else return;
}
if (flowingAnimato == null) flowingAnimation();
if (reiseAnimator!=null && reiseAnimator.isRunning()){
// reiseAnimator.cancel();//不应该取消,应该让其直接结束
reiseAnimator.end();
}
this.progress = progress;
if (progress == 0){ resetWave();}
if (!isCompleteLayout){return ;}
long cP = max - progress;
if (max >= progress) {
progressRatio = cP / (float)max;
updateProgress();
}
}
public long getProgress() {
return progress;
}
public long getMax() {
return max;
}
/**
* reset point set
* < When in onDraw need to measure the initialization point set>>
*/
private void rerefreshPoints(){
pointList.clear();
shadpointList.clear();
WAVE_HEIGHT = VIEW_HEIGHT/getWaveHeight();
//计算最多能支持多少点 非控制点
int n = Math.round(VIEW_WIDTH / WAVE_WIDTH);
//起始点
int startX = (int) -dx;
for (int i = 0; i < 4*n+1; i++) {
Point point = new Point();
point.y = (int) dy;
if (i == 0) {
point.x = startX;
} else {
startX += WAVE_WIDTH;
point.x = startX;
}
pointList.add(point);
}
startX = (int) VIEW_WIDTH;
for (int i = 0; i < 4*n+1; i++) {
Point point = new Point();
point.y = (int) dy;
if (i == 0) {
point.x = startX;
} else {
startX -= WAVE_WIDTH;
point.x = startX;
}
shadpointList.add(point);
}
// Log.i("wusy","test v : y " +shadpointList.get(0).y);
}
public void resetWave(){
isDone = false;
dy = VIEW_HEIGHT;
beforDy = 0;
}
private int updateDyData(){
// TODO: 2017/4/18 解决不能自定义大小
if (sum_dy == 0 && isHasWindowFocus){sum_dy = VIEW_HEIGHT;}
old_dy = dy;
int offsetDy = (int) (sum_dy - sum_dy * progressRatio - beforDy);
beforDy = sum_dy - sum_dy * progressRatio;
return offsetDy;
}
/**
* In a second riseAnimation when set the progress !!
* >
*/
private void updateProgress(){
riseAnimation();
}
/**
* for measure width
* @param widthMeasureSpec
* @return
*/
private int getRealWidthMeasureSpec(int widthMeasureSpec){
int mode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
if (mode == MeasureSpec.AT_MOST){
Log.i(TAG,"AT_MOST width :"+ DensityUtil.px2dip(mContext,widthSize));//warp
// VIEW_WIDTH = widthSize;
}else if (mode == MeasureSpec.EXACTLY){
Log.i(TAG,"EXACTLY width :"+ DensityUtil.px2dip(mContext,widthSize));
VIEW_WIDTH = widthSize;
}else if (mode == MeasureSpec.UNSPECIFIED){
Log.i(TAG,"UNSPECIFIED width :"+ DensityUtil.px2dip(mContext,widthSize));
// VIEW_WIDTH = VIEW_WIDTH_TMP;
}
return (int) VIEW_WIDTH;
}
/**
* for measure height
* @param heightMeasureSpec
* @return
*/
private int getRealHeightMeasureSpec(int heightMeasureSpec){
int mode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if (mode == MeasureSpec.AT_MOST){
Log.i(TAG,"AT_MOST heitht :"+ DensityUtil.px2dip(mContext,heightSize));
// VIEW_HEIGHT = heightSize;
}else if (mode == MeasureSpec.EXACTLY){
Log.i(TAG,"EXACTLY heitht :"+ DensityUtil.px2dip(mContext,heightSize));
VIEW_HEIGHT = heightSize;
}else if (mode == MeasureSpec.UNSPECIFIED){
Log.i(TAG,"UNSPECIFIED heitht :"+ DensityUtil.px2dip(mContext,heightSize));
// VIEW_HEIGHT = VIEW_HEIGHT_TMP;
}
if (!isHasWindowFocus){updateDyData();}else {
dy = VIEW_HEIGHT;//为了防止多次测量,必须重新更新初始高度
old_dy = dy;
sum_dy = dy;
}
return (int) VIEW_HEIGHT;
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
// Log.i(TAG,"onLayout");
}
@Override
protected void onDraw(Canvas canvas) {
//To prevent repeated drawing
wavePath.reset();
shadPath.reset();
float radius = VIEW_WIDTH / 2f;
int saveFlags = Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG;
canvas.saveLayer(0, 0, VIEW_WIDTH, VIEW_HEIGHT, null, saveFlags);
// set shape
if (mode.equals(MODE_DRAWABLE)){
drawableToBitamp(ContextCompat.getDrawable(mContext,R.drawable.wave_icon),canvas);
} else if (mode.equals(MODE_RECT)){
canvas.drawRect(0,0,VIEW_WIDTH,VIEW_HEIGHT,mPaint);
} else{
canvas.drawCircle(VIEW_WIDTH / 2f, VIEW_HEIGHT / 2f, radius, mPaint);
}
wavePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
if (!isDone) {
// drawing normal wave
wavePaint.setColor(WAVE_COLOR);
wavePaint.setAlpha(100);
float end1 = 0;
for (int i = 0; i < pointList.size(); i++) {
int j = i + 1;
if (pointList.size() > i) {
float start1 = pointList.get(i).x;
wavePath.moveTo(start1, dy);//+dy
if (j % 2 == 0 && j >= 2) {
end1 = start1;
wavePath.quadTo(start1 + WAVE_WIDTH / 2, dy + WAVE_HEIGHT, start1 + WAVE_WIDTH, dy);//+dy
} else {
end1 = start1;
wavePath.quadTo(start1 + WAVE_WIDTH / 2, dy - WAVE_HEIGHT, start1 + WAVE_WIDTH, dy);
}
}
}
if (end1 >= VIEW_WIDTH) {
wavePath.lineTo(VIEW_WIDTH, VIEW_HEIGHT);
wavePath.lineTo(0, VIEW_HEIGHT);
wavePath.lineTo(0, dy);
wavePath.close();
canvas.drawPath(wavePath, wavePaint);
}
// drawing rolling wave
wavePaint.setAlpha(200);
for (int i = 0; i < shadpointList.size(); i++) {
int j = i + 1;
if (shadpointList.size() > i) {
float start1 = shadpointList.get(i).x + shd_dx;
shadPath.moveTo(start1, dy);//+dy
if (j % 2 == 0 && j >= 2) {
end1 = start1;
shadPath.quadTo(start1 - WAVE_WIDTH / 2, (float) (dy + WAVE_HEIGHT * runRatio), start1 - WAVE_WIDTH, dy);//+dy
} else {
end1 = start1;
shadPath.quadTo(start1 - WAVE_WIDTH / 2, (float) (dy - WAVE_HEIGHT * runRatio), start1 - WAVE_WIDTH, dy);
}
}
}
if (end1 <= -VIEW_WIDTH) {
shadPath.lineTo(0, VIEW_HEIGHT);
shadPath.lineTo(VIEW_WIDTH, VIEW_HEIGHT);
shadPath.lineTo(VIEW_WIDTH, dy);
shadPath.close();
canvas.drawPath(shadPath, wavePaint);
}
// xfer
wavePaint.setXfermode(null);
canvas.restore();
// super.onDraw(canvas);
// display listener for activity or fragment
if (this.progressListener != null) {
if (!isDone && curProgress != this.progress) {
this.progressListener.onPorgress(this.progress == this.max, this.progress, this.max);
curProgress = this.progress;
}
if (this.progress == this.max) {
isDone = true;
// dy = -10;//In order to complete fill finally effect
// resetWave();
}
}
if (isDone) doneAnimation();
}
}
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
isHasWindowFocus = hasWindowFocus;
// Log.d("yuan"," onWindowFocusChanged " + hasWindowFocus);
if (!isDone){
if (!isStartAnimation) {
isStartAnimation = true;
flowingAnimation();
}
// TODO: 2016/10/26 屏幕重新点亮的时候 一定要重新测量!!!
if (!hasWindowFocus) {
if (flowingAnimato != null)
flowingAnimato.cancel();
if (reiseAnimator != null)
reiseAnimator.end();
isMeasure = false;
} else {
if (flowingAnimato != null && !flowingAnimato.isRunning()) {
flowingAnimation();
}
if (reiseAnimator != null && !reiseAnimator.isRunning()) {
setProgress(this.progress);
}
}
}else{
// Log.d("yuan"," onWindowFocusChanged " + isDone);
if (isHasWindowFocus) {
doneAnimation();
}
}
}
private void flowingAnimation(){
flowingAnimato = ObjectAnimator.ofFloat(this,"wave",0,100)
.setDuration(100);
flowingAnimato.setRepeatCount(INFINITE);
flowingAnimato.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
dx = dx + speed;
shd_dx = shd_dx + speed/2;//Half the speed of the normal waves
// 20171026
if (shd_dx >= WAVE_WIDTH *2){
shd_dx = 0;
}
if (dx >= WAVE_WIDTH *2){
dx = 0;
}
rerefreshPoints();
postInvalidate();
}
})
;
flowingAnimato.start();
}
private void riseAnimation(){
if (!isHasWindowFocus){
// TODO: 2016/10/26 不可视的时候停止
return ;
}
isMeasure = true;
Log.i("yuan", "move " + "dy " + dy);
if (dy > 0) {
float offset = updateDyData();
Log.i("yuan", "move s " + offset + "and sum_dy" + sum_dy);
reiseAnimator = ValueAnimator.ofFloat(0, offset)
.setDuration(500);
reiseAnimator.setInterpolator(new LinearInterpolator());
reiseAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {}
@Override
public void onAnimationEnd(Animator animator) {
// TODO: 2016/10/26 必须重置dy,修正偏移
dy = sum_dy - beforDy;
}
@Override
public void onAnimationCancel(Animator animator) {}
@Override
public void onAnimationRepeat(Animator animator) {}
});
reiseAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float m = (float) valueAnimator.getAnimatedValue();
float s = old_dy - m;
dy = s;
// Log.i("yuan", "move m " + m + "dy " + dy);
}
});
reiseAnimator.start();
}
}
private void doneAnimation(){
if (reiseAnimator != null) {
reiseAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
justDone();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
reiseAnimator.end();
}else{
justDone();
}
}
private void justDone(){
mPaint.setColor(WAVE_COLOR);
// mPaint.setAlpha(200);
if (flowingAnimato != null && flowingAnimato.isRunning()) {
flowingAnimato.end();
flowingAnimato = null;
}
else invalidate();
}
/**
* drawable to bitmap
* @param drawable
* @param canvas
* @return
*/
private void drawableToBitamp(Drawable drawable,Canvas canvas)
{
int w = (int) VIEW_WIDTH;
int h = (int) VIEW_HEIGHT;
Bitmap.Config config =
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
Bitmap bitmap = Bitmap.createBitmap(w,h,config);
canvas.drawBitmap(bitmap,0,0,mPaint);
drawable.setBounds(0, 0, w, h);
drawable.draw(canvas);
}
public interface waveProgressListener{
void onPorgress(boolean isDone, long progress, long max);
}
}
================================================
FILE: wavekit/src/main/java/com/yuan/waveview/utils/DensityUtil.java
================================================
package com.yuan.waveview.utils;
import android.content.Context;
/**
* Created by Yuan on 2016/10/9.
* Detail
*/
public class DensityUtil {
/**
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
*/
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
/**
* 根据手机的分辨率从 px(像素) 的单位 转成为 dp
*/
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
}
================================================
FILE: wavekit/src/main/res/values/attrs.xml
================================================
================================================
FILE: wavekit/src/main/res/values/colors.xml
================================================
#6C7B8B
#00000000
#FF4081
#FFFFFF
#000000
#99000000
#9963B8FF
#99CD0000
#99C1FFC1
================================================
FILE: wavekit/src/main/res/values/strings.xml
================================================
waveKit
================================================
FILE: wavekit/src/test/java/com/yuan/waveview/ExampleUnitTest.java
================================================
package com.yuan.waveview;
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);
}
}