Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

feat: Customisable WaveHz #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

WaveView
========
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/john990/WaveView?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/john990/WaveView?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-WaveView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1260)

A wave view of android,can be used as progress bar.
A wave view for android, which can be used as progress bar.


### Screenshot
Expand Down Expand Up @@ -34,7 +34,7 @@ A wave view of android,can be used as progress bar.
wave:blow_wave_color="@android:color/white"
wave:progress="80"
wave:wave_height="little"
wave:wave_hz="normal"
wave:wave_hz="0.09"
wave:wave_length="middle" />
````
or you can just use(default progress is 80%)
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':library')
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
wave:blow_wave_color="@android:color/white"
wave:progress="80"
wave:wave_height="little"
wave:wave_hz="normal"
wave:wave_hz="0.09"
wave:wave_length="middle" />

<SeekBar
Expand Down
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'com.android.tools.build:gradle:4.1.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Mar 10 13:55:47 CST 2015
#Sun Feb 21 12:55:46 SGT 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
Empty file modified gradlew
100644 → 100755
Empty file.
180 changes: 90 additions & 90 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,90 +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
@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
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
29 changes: 11 additions & 18 deletions library/src/main/java/com/john/waveview/Wave.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ class Wave extends View {
private final float WAVE_LENGTH_MULTIPLE_MIDDLE = 1f;
private final float WAVE_LENGTH_MULTIPLE_LITTLE = 0.5f;

private final float WAVE_HZ_FAST = 0.13f;
private final float WAVE_HZ_NORMAL = 0.09f;
private final float WAVE_HZ_SLOW = 0.05f;

public final int DEFAULT_ABOVE_WAVE_ALPHA = 50;
public final int DEFAULT_BLOW_WAVE_ALPHA = 30;

Expand Down Expand Up @@ -85,16 +81,25 @@ public Paint getBlowWavePaint() {
return mBlowWavePaint;
}

public void initializeWaveSize(int waveMultiple, int waveHeight, int waveHz) {
public void initializeWaveSize(int waveMultiple, int waveHeight, float waveHz) {
mWaveMultiple = getWaveMultiple(waveMultiple);
mWaveHeight = getWaveHeight(waveHeight);
mWaveHz = getWaveHz(waveHz);
mWaveHz = clampWaveHz(waveHz);
mBlowOffset = mWaveHeight * 0.4f;
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
mWaveHeight * 2);
setLayoutParams(params);
}

/**
* Clamps input Wave hertz to be within [0,1]
* @param waveHz User input wave hertz*/
private float clampWaveHz(float waveHz) {
if(waveHz>1) return 1;
else if(waveHz<0) return 0;
return waveHz;
}

public void initializePainters() {
mAboveWavePaint.setColor(mAboveWaveColor);
mAboveWavePaint.setAlpha(DEFAULT_ABOVE_WAVE_ALPHA);
Expand Down Expand Up @@ -131,18 +136,6 @@ private int getWaveHeight(int size) {
return 0;
}

private float getWaveHz(int size) {
switch (size) {
case WaveView.LARGE:
return WAVE_HZ_FAST;
case WaveView.MIDDLE:
return WAVE_HZ_NORMAL;
case WaveView.LITTLE:
return WAVE_HZ_SLOW;
}
return 0;
}

/**
* calculate wave track
*/
Expand Down
9 changes: 7 additions & 2 deletions library/src/main/java/com/john/waveview/WaveView.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class WaveView extends LinearLayout {
private int mProgress;
private int mWaveHeight;
private int mWaveMultiple;
private int mWaveHz;
private float mWaveHz;

private int mWaveToTop;

Expand All @@ -32,6 +32,7 @@ public class WaveView extends LinearLayout {
private final int DEFAULT_ABOVE_WAVE_COLOR = Color.WHITE;
private final int DEFAULT_BLOW_WAVE_COLOR = Color.WHITE;
private final int DEFAULT_PROGRESS = 80;
private final float DEFAULT_HZ = 0.15f;

public WaveView(Context context, AttributeSet attrs) {
super(context, attrs);
Expand All @@ -43,7 +44,7 @@ public WaveView(Context context, AttributeSet attrs) {
mProgress = attributes.getInt(R.styleable.WaveView_progress, DEFAULT_PROGRESS);
mWaveHeight = attributes.getInt(R.styleable.WaveView_wave_height, MIDDLE);
mWaveMultiple = attributes.getInt(R.styleable.WaveView_wave_length, LARGE);
mWaveHz = attributes.getInt(R.styleable.WaveView_wave_hz, MIDDLE);
mWaveHz = attributes.getFloat(R.styleable.WaveView_wave_hz, DEFAULT_HZ);
attributes.recycle();

mWave = new Wave(context, null);
Expand All @@ -67,6 +68,10 @@ public void setProgress(int progress) {
computeWaveToTop();
}

public int getProgress(){
return mProgress;
}

@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
Expand Down
6 changes: 2 additions & 4 deletions library/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
<enum name="middle" value="2"/>
<enum name="little" value="3"/>
</attr>
<attr name="wave_hz" format="enum">
<enum name="fast" value="1"/>
<enum name="normal" value="2"/>
<enum name="slow" value="3"/>
<attr name="wave_hz" format="float">

</attr>
</declare-styleable>

Expand Down