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

feat: Fill to brim #26

Open
wants to merge 2 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
11 changes: 6 additions & 5 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,8 +34,9 @@ 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_length="middle" />
wave:wave_hz="little"
wave:wave_length="middle"
wave:fill_to_brim="true"/>
````
or you can just use(default progress is 80%)
````xml
Expand All @@ -59,4 +60,4 @@ allprojects {
dependencies {
compile 'com.github.john990:WaveView:v0.9'
}
````
````
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')
}
10 changes: 5 additions & 5 deletions app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:wave="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.john.waveview.WaveView
android:id="@+id/wave_view"
Expand All @@ -14,7 +14,8 @@
wave:progress="80"
wave:wave_height="little"
wave:wave_hz="normal"
wave:wave_length="middle" />
wave:wave_length="middle"
wave:fill_to_brim="true"/>

<SeekBar
android:id="@+id/seek_bar"
Expand All @@ -23,5 +24,4 @@
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="20dp"
android:progress="80" />
</FrameLayout>

</FrameLayout>
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
buildscript {
repositories {
jcenter()
google()
}
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
Expand All @@ -13,5 +14,6 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ 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
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'])
}
10 changes: 10 additions & 0 deletions library/src/main/java/com/john/waveview/Wave.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Wave extends View {
private float mMaxRight;
private float mWaveHz;

private float mWaveMaxHeight;

// wave animation
private float mAboveOffset = 0.0f;
private float mBlowOffset;
Expand Down Expand Up @@ -143,6 +145,14 @@ private float getWaveHz(int size) {
return 0;
}

public float getMaxHeight(){
/* y = (float) (mWaveHeight * Math.sin(omega * x + mBlowOffset) + mWaveHeight);
* Max value of Math.sin(omega * x + mBlowOffset) = 1
* Hence, Max height = mWaveHeight * 1 + mWaveHeight
* = mWaveHeight * 2 */
return mWaveHeight * 2;
}

/**
* calculate wave track
*/
Expand Down
5 changes: 4 additions & 1 deletion library/src/main/java/com/john/waveview/WaveView.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class WaveView extends LinearLayout {

private Wave mWave;
private Solid mSolid;
private boolean mIsFilledTillBrim;

private final int DEFAULT_ABOVE_WAVE_COLOR = Color.WHITE;
private final int DEFAULT_BLOW_WAVE_COLOR = Color.WHITE;
Expand All @@ -43,6 +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);
mIsFilledTillBrim = attributes.getBoolean(R.styleable.WaveView_fill_to_brim,false);
mWaveHz = attributes.getInt(R.styleable.WaveView_wave_hz, MIDDLE);
attributes.recycle();

Expand Down Expand Up @@ -76,7 +78,8 @@ public void onWindowFocusChanged(boolean hasWindowFocus) {
}

private void computeWaveToTop() {
mWaveToTop = (int) (getHeight() * (1f - mProgress / 100f));
boolean isViewFilled = mProgress==100 && mIsFilledTillBrim;
mWaveToTop = (int)((isViewFilled)? (-mWave.getMaxHeight()) : (getHeight() * (1f - mProgress / 100f)));
ViewGroup.LayoutParams params = mWave.getLayoutParams();
if (params != null) {
((LayoutParams) params).topMargin = mWaveToTop;
Expand Down
7 changes: 7 additions & 0 deletions library/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,30 @@

<declare-styleable name="WaveView">
<attr name="above_wave_color" format="color"/>

<attr name="blow_wave_color" format="color"/>

<attr name="progress" format="integer"/>

<attr name="wave_length" format="enum">
<enum name="large" value="1"/>
<enum name="middle" value="2"/>
<enum name="little" value="3"/>
</attr>

<attr name="wave_height" format="enum">
<enum name="large" value="1"/>
<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>

<attr name="fill_to_brim" format="boolean"/>
</declare-styleable>

<declare-styleable name="Themes">
Expand Down