From aac349bacb4b21dfa4d4f7b0178c699ed4e085db Mon Sep 17 00:00:00 2001 From: kalai Date: Sun, 21 Feb 2021 20:15:01 +0800 Subject: [PATCH 1/2] feat: Fill to brim feat: Fill to brim - Current implementation does not give an option to fill the view till the brim, hence, I added a feature to allow users to let the view fill to the brim on their discretion via the newly created boolean attribute: `fill_to_brim` chore: Includes Gradle update done in #25 chore: README update - Badge fix from #25 and code update based on this feature --- README.md | 11 ++++++----- app/build.gradle | 4 ++-- app/src/main/res/layout/main.xml | 10 +++++----- build.gradle | 4 +++- gradle/wrapper/gradle-wrapper.properties | 2 +- library/build.gradle | 2 +- library/src/main/java/com/john/waveview/Wave.java | 10 ++++++++++ library/src/main/java/com/john/waveview/WaveView.java | 5 ++++- library/src/main/res/values/attr.xml | 7 +++++++ 9 files changed, 39 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4df412c..ce0ca25 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -59,4 +60,4 @@ allprojects { dependencies { compile 'com.github.john990:WaveView:v0.9' } -```` +```` \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 7a9ac8d..abfec88 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,6 +20,6 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':library') + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation project(':library') } diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml index ed439bd..b1425cf 100644 --- a/app/src/main/res/layout/main.xml +++ b/app/src/main/res/layout/main.xml @@ -1,8 +1,8 @@ + android:layout_width="match_parent" + android:layout_height="match_parent"> + wave:wave_length="middle" + wave:fill_to_brim="true"/> - - + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3a4c082..955d73b 100644 --- a/build.gradle +++ b/build.gradle @@ -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 @@ -13,5 +14,6 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 58b1e16..33d123c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/library/build.gradle b/library/build.gradle index c20db03..f7c9cd3 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -19,5 +19,5 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + implementation fileTree(dir: 'libs', include: ['*.jar']) } diff --git a/library/src/main/java/com/john/waveview/Wave.java b/library/src/main/java/com/john/waveview/Wave.java index 020211b..bb366c0 100644 --- a/library/src/main/java/com/john/waveview/Wave.java +++ b/library/src/main/java/com/john/waveview/Wave.java @@ -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; @@ -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 */ diff --git a/library/src/main/java/com/john/waveview/WaveView.java b/library/src/main/java/com/john/waveview/WaveView.java index 62088d1..f4f3d94 100644 --- a/library/src/main/java/com/john/waveview/WaveView.java +++ b/library/src/main/java/com/john/waveview/WaveView.java @@ -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; @@ -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,true); mWaveHz = attributes.getInt(R.styleable.WaveView_wave_hz, MIDDLE); attributes.recycle(); @@ -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; diff --git a/library/src/main/res/values/attr.xml b/library/src/main/res/values/attr.xml index 4994d9b..ecb90f5 100644 --- a/library/src/main/res/values/attr.xml +++ b/library/src/main/res/values/attr.xml @@ -3,23 +3,30 @@ + + + + + + + From d47ffa710fd719b1d151f69799574c722863a45a Mon Sep 17 00:00:00 2001 From: kalai Date: Sun, 21 Feb 2021 20:31:37 +0800 Subject: [PATCH 2/2] refactor: Default fill_to_brim set to false --- library/src/main/java/com/john/waveview/WaveView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/main/java/com/john/waveview/WaveView.java b/library/src/main/java/com/john/waveview/WaveView.java index f4f3d94..f7b4898 100644 --- a/library/src/main/java/com/john/waveview/WaveView.java +++ b/library/src/main/java/com/john/waveview/WaveView.java @@ -44,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); - mIsFilledTillBrim = attributes.getBoolean(R.styleable.WaveView_fill_to_brim,true); + mIsFilledTillBrim = attributes.getBoolean(R.styleable.WaveView_fill_to_brim,false); mWaveHz = attributes.getInt(R.styleable.WaveView_wave_hz, MIDDLE); attributes.recycle();