Skip to content
This repository was archived by the owner on Mar 10, 2021. It is now read-only.
Draft
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 app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion '20.0.0'

defaultConfig {
minSdkVersion 8
minSdkVersion 11
targetSdkVersion 20
versionCode 1
versionName "1.0"
Expand All @@ -20,6 +20,6 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':library')
}
14 changes: 13 additions & 1 deletion app/src/main/java/com/waveview/demo/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.waveview.demo;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.widget.SeekBar;

Expand All @@ -14,17 +16,27 @@ public class MainActivity extends Activity {
private SeekBar seekBar;
private WaveView waveView;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

seekBar = (SeekBar) findViewById(R.id.seek_bar);
waveView = (WaveView) findViewById(R.id.wave_view);
/* final ArgbEvaluator evaluator = new ArgbEvaluator();
final int initColor = getResources().getColor(R.color.holo_red);
final int endColor = getResources().getColor(R.color.holo_green);*/

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {


seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
waveView.setProgress(progress);
/* int color = (Integer) evaluator.evaluate(progress/100f,initColor,endColor);
waveView.setAboveWaveColor(color);
waveView.setBlowWaveColor(color);
waveView.setWaveColor(color);*/
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/gradient_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="@color/dark_blue"
android:endColor="@color/light_blue"
android:type="linear" />
</shape>
</item>
</selector>
13 changes: 8 additions & 5 deletions app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
android:id="@+id/wave_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff702e8c"
wave:above_wave_color="@android:color/white"
wave:blow_wave_color="@android:color/white"
android:background="#FFFFFF"
wave:above_wave_color="@color/light_blue"
wave:blow_wave_color="@color/light_blue"
wave:above_wave_color_alpha="0.5"
wave:blow_wave_color_alpha="0.3"
wave:progress="80"
wave:wave_height="little"
wave:wave_height="large"
wave:wave_hz="normal"
wave:wave_length="middle" />
wave:wave_length="middle"
wave:background="@drawable/gradient_background"/>

<SeekBar
android:id="@+id/seek_bar"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/color.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="holo_purple">#ffaa66cc</color>
<color name="holo_green">#7CB342</color>
<color name="holo_red">#E53935</color>

<color name="light_blue">#DA00FFE1</color>
<color name="dark_blue">#007BFF</color>
</resources>
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'])
}
59 changes: 48 additions & 11 deletions library/src/main/java/com/john/waveview/Solid.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,78 @@
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import static com.john.waveview.WaveView.alphaPercentToInt;

/**
* Created by John on 2014/10/15.
*/
class Solid extends View {

private Paint aboveWavePaint;
private Paint blowWavePaint;
private final Paint mWavePaint = new Paint();
private int mWaveColor;
private float mWaveAlpha;
private Drawable mBackgroundDrawable;

private final Paint.Style STYLE = Paint.Style.FILL;

public Solid(Context context, AttributeSet attrs) {
this(context, attrs, 0);
public Solid(Context context, SolidAttributes solidAttributes) {
this(context,null, 0, solidAttributes);
}

public Solid(Context context, AttributeSet attrs, int defStyleAttr) {
/*For Android Studio Tools*/
private Solid(Context context){
super(context); }

private Solid(Context context, AttributeSet attrs, int defStyleAttr, SolidAttributes solidAttributes) {
super(context, attrs, defStyleAttr);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.weight = 1;
setLayoutParams(params);
initialize(solidAttributes);
setWaveColor();
}

public void setAboveWavePaint(Paint aboveWavePaint) {
this.aboveWavePaint = aboveWavePaint;
private void initialize(SolidAttributes solidAttributes) {
mBackgroundDrawable = solidAttributes.getBackgroundDrawable();

mWaveColor = solidAttributes.getWaveColor();
mWaveAlpha = solidAttributes.getWaveAlpha();
setWaveAlpha(mWaveAlpha);
mWavePaint.setStyle(STYLE);
if(mBackgroundDrawable!=null) {
this.setBackgroundDrawable(mBackgroundDrawable);
}
}

public void setBlowWavePaint(Paint blowWavePaint) {
this.blowWavePaint = blowWavePaint;
public void setWaveColor() {
mWavePaint.setColor(mWaveColor);
setWaveAlpha(mWaveAlpha);
}

public void setWaveAlpha(float alpha){ mWavePaint.setAlpha(alphaPercentToInt(alpha)); }

public float getWaveAlpha() { return mWavePaint.getAlpha(); }

public void setWaveColor(int color) { mWavePaint.setColor(color); }

public int getWaveColor() { return mWavePaint.getColor(); }

@Override
public Drawable getBackground() { return mBackgroundDrawable; }

public void setBackground(Drawable backgroundDrawable){ mBackgroundDrawable = backgroundDrawable; }

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRect(getLeft(), 0, getRight(), getBottom(), blowWavePaint);
canvas.drawRect(getLeft(), 0, getRight(), getBottom(), aboveWavePaint);
if(mBackgroundDrawable==null) {
canvas.drawRect(getLeft(), 0, getRight(), getBottom(), mWavePaint);
canvas.drawRect(getLeft(), 0, getRight(), getBottom(), mWavePaint);
}
}
}
25 changes: 25 additions & 0 deletions library/src/main/java/com/john/waveview/SolidAttributes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.john.waveview;


import android.graphics.drawable.Drawable;

/**
* Data class to store solid attributes*/
public class SolidAttributes {

private int mWaveColor;
private float mWaveAlpha;
private Drawable mBackgroundDrawable;

SolidAttributes(int waveColor, float waveAlpha, Drawable drawable){
mWaveColor = waveColor;
mWaveAlpha = waveAlpha;
mBackgroundDrawable = drawable;
}

public int getWaveColor() { return mWaveColor; }

public float getWaveAlpha() { return mWaveAlpha; }

public Drawable getBackgroundDrawable() { return mBackgroundDrawable; }
}
Loading