├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── eu
│ │ └── gsottbauer
│ │ └── equalizerviewsample
│ │ └── MainActivity.java
│ └── res
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── equalizerview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── eu
│ │ └── gsottbauer
│ │ └── equalizerview
│ │ └── EqualizerView.java
│ └── res
│ └── values
│ ├── attrs.xml
│ └── strings.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 | settings.xml
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # IntelliJ IDEA
30 | .idea/
31 | */.idea/
32 | *.iml
33 | */gen-gen-external-apklibs/
34 | */gen-external-apklibs/
35 |
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | Simple Equalizer Library for Android
4 | ==================================
5 |
6 | This Android library project is developed to you use an animated equalizer for your music related apps. Original version from [@claucookie](https://github.com/claucookie/mini-equalizer-library-android).
7 |
8 | [](https://android-arsenal.com/details/1/3715)
9 |
10 | Requirements
11 | --------
12 | Android 4.0 or higher.
13 |
14 | Installation
15 | --------
16 | Step 1: Add this in your `build.gradle` (Project) at the end of repositories
17 | ```groovy
18 | allprojects {
19 | ...
20 | repositories {
21 | maven { url "https://jitpack.io" }
22 | }
23 | }
24 | ```
25 | Step 2: Add this in your `build.gradle` (Module)
26 | ```groovy
27 | dependencies {
28 | implementation "com.github.gsotti:EqualizerView:v0.2"
29 | }
30 | ```
31 | Layout
32 | --------
33 | ````xml
34 |
45 | ````
46 |
47 | Attributes
48 | --------
49 | |Attribute|Description|Type|Default|
50 | |--|--|--|--|
51 | |barColor|Color of the bars|Color|Black|
52 | |barAnimationDuration|The animation follows a pattern and the number of loops is infinite. To set the duration of each loop, use this attribute|Integer (Miliseconds)|
53 | |barCount|Number of the bars|Integer|
54 | |barWidth|Width of the bars|Dimension|
55 | |marginLeft|Margin left between each bar|Dimension|
56 | |marginRight|Margin right between each bar|Dimension|
57 | |runInBatterySaveMode|Play animation if even battery saver is on|Boolean|
58 |
59 |
60 |
61 | Controlling the animation
62 | --------
63 |
64 | ````java
65 | EqualizerView equalizer = findViewById(R.id.equalizer);
66 | equalizer.animateBars(); // To start the animation
67 | equalizer.stopBars(); // To stop the animation
68 | ````
69 |
70 | Contribution
71 | --------
72 | Every idea, fork and suggestion is very welcome.
73 |
74 | Author
75 | --------
76 | Stefan Gsottbauer ([@gsotti](https://github.com/gsotti))
77 |
78 | License
79 | --------
80 | [MIT](https://opensource.org/licenses/MIT)
81 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "eu.gsottbauer.equalizerview"
9 | minSdkVersion 16
10 | targetSdkVersion 23
11 | versionCode 2
12 | versionName "0.2"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | compile project(':equalizerview')
27 | }
28 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Gsottbauer/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/java/eu/gsottbauer/equalizerviewsample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package eu.gsottbauer.equalizerviewsample;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.TypedValue;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.SeekBar;
9 | import android.widget.TextView;
10 |
11 | import eu.gsottbauer.equalizerview.EqualizerView;
12 |
13 | public class MainActivity extends AppCompatActivity {
14 |
15 | private EqualizerView mEqualizerView;
16 | private Button mPlayPauseButton;
17 | private SeekBar mBarCountSeekBar;
18 | private TextView mBarCountTextView;
19 | private SeekBar mAnimationDurationSeekBar;
20 | private TextView mAnimationDurationTextView;
21 | private SeekBar mBarWidthSeekBar;
22 | private TextView mBarWidthTextView;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_main);
28 |
29 | mEqualizerView = (EqualizerView) findViewById(R.id.equalizer);
30 | mPlayPauseButton = (Button) findViewById(R.id.play_button);
31 | mBarCountTextView = (TextView) findViewById(R.id.bar_count);
32 | mAnimationDurationTextView = (TextView) findViewById(R.id.animation_duration);
33 | mBarWidthTextView = (TextView) findViewById(R.id.bar_width_textview);
34 |
35 | mBarCountSeekBar = (SeekBar) findViewById(R.id.bar_count_seekbar);
36 | mAnimationDurationSeekBar = (SeekBar) findViewById(R.id.animation_duration_seekbar);
37 | mBarWidthSeekBar= (SeekBar) findViewById(R.id.bar_width_seekbar);
38 |
39 | mPlayPauseButton.setOnClickListener(mPlayButtonOnClickListener);
40 | mBarCountSeekBar.setOnSeekBarChangeListener(mBarCountSeekBarChangeListener);
41 | mAnimationDurationSeekBar.setOnSeekBarChangeListener(mAnimationDurationSeekBarChangeListener);
42 | mBarWidthSeekBar.setOnSeekBarChangeListener(mBarWidthSeekBarChangeListener);
43 |
44 | mBarCountTextView.setText("40 Bars used");
45 | mAnimationDurationTextView.setText("2000 ms");
46 | mBarWidthTextView.setText("2 dp");
47 |
48 | /*
49 | * Set Bar Color
50 | * mEqualizerView.setBarColor("#ff00ff");
51 | * mEqualizerView.setBarColor(ContextCompat.getColor(this,R.color.colorAccent));
52 | *
53 | * Set Bar Count
54 | * mEqualizerView.setBarCount(10);
55 | *
56 | * Set Animation Duration
57 | * mEqualizerView.setAnimationDuration(1000);
58 | *
59 | * Set Animation Value Count
60 | * mEqualizerView.setObjectAnimationValueCount(10);
61 | *
62 | * Set MarginLeft/Right
63 | * mEqualizerView.setMarginLeft(10);
64 | * mEqualizerView.setMarginRight(10);
65 | *
66 | * Set Bar Width
67 | * mEqualizerView.setBarWidth(5);
68 | *
69 | */
70 | }
71 |
72 | private SeekBar.OnSeekBarChangeListener mBarCountSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
73 | @Override
74 | public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
75 | mEqualizerView.stopBars();
76 | mPlayPauseButton.setText(getString(R.string.start));
77 | mEqualizerView.setBarCount(i + 1);
78 | mBarCountTextView.setText((i + 1) + " bars used");
79 | }
80 |
81 | @Override
82 | public void onStartTrackingTouch(SeekBar seekBar) {
83 |
84 | }
85 |
86 | @Override
87 | public void onStopTrackingTouch(SeekBar seekBar) {
88 |
89 | }
90 | };
91 |
92 | private SeekBar.OnSeekBarChangeListener mAnimationDurationSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
93 | @Override
94 | public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
95 | mEqualizerView.stopBars();
96 | mPlayPauseButton.setText(getString(R.string.start));
97 | mEqualizerView.setAnimationDuration((i + 1) * 100);
98 | mAnimationDurationTextView.setText(((i + 1) * 100) + " ms");
99 | }
100 |
101 | @Override
102 | public void onStartTrackingTouch(SeekBar seekBar) {
103 |
104 | }
105 |
106 | @Override
107 | public void onStopTrackingTouch(SeekBar seekBar) {
108 |
109 | }
110 | };
111 |
112 |
113 | private SeekBar.OnSeekBarChangeListener mBarWidthSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
114 | @Override
115 | public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
116 | mEqualizerView.stopBars();
117 | mPlayPauseButton.setText(getString(R.string.start));
118 |
119 | int width = (i <= 0) ? -1 : (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, i, getResources().getDisplayMetrics());
120 |
121 | mEqualizerView.setBarWidth(width);
122 | mBarWidthTextView.setText(((i)) + " dp");
123 | }
124 |
125 | @Override
126 | public void onStartTrackingTouch(SeekBar seekBar) {
127 |
128 | }
129 |
130 | @Override
131 | public void onStopTrackingTouch(SeekBar seekBar) {
132 |
133 | }
134 | };
135 |
136 |
137 |
138 |
139 | private View.OnClickListener mPlayButtonOnClickListener = new View.OnClickListener() {
140 | @Override
141 | public void onClick(View view) {
142 | if (mEqualizerView.isAnimating()) {
143 | mEqualizerView.stopBars();
144 | mPlayPauseButton.setText(getString(R.string.start));
145 | } else {
146 | mEqualizerView.animateBars();
147 | mPlayPauseButton.setText(getString(R.string.stop));
148 | }
149 | }
150 | };
151 | }
152 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
22 |
23 |
33 |
34 |
35 |
43 |
44 |
53 |
54 |
64 |
65 |
75 |
76 |
77 |
87 |
88 |
99 |
100 |
101 |
111 |
112 |
122 |
123 |
133 |
134 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gsotti/EqualizerView/33f61cbcccca3bb268f6f2f0ac48e73e911593a4/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gsotti/EqualizerView/33f61cbcccca3bb268f6f2f0ac48e73e911593a4/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gsotti/EqualizerView/33f61cbcccca3bb268f6f2f0ac48e73e911593a4/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gsotti/EqualizerView/33f61cbcccca3bb268f6f2f0ac48e73e911593a4/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gsotti/EqualizerView/33f61cbcccca3bb268f6f2f0ac48e73e911593a4/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | EqualizerView
3 | Start
4 | Stop
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.2'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/equalizerview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/equalizerview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 16
9 | targetSdkVersion 23
10 | versionCode 4
11 | versionName "0.4"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.4.0'
25 | }
26 |
27 |
28 | ext {
29 | bintrayRepo = 'maven'
30 | bintrayName = 'equalizerview'
31 |
32 | publishedGroupId = 'eu.gsottbauer'
33 | libraryName = 'EqualizerView'
34 | artifact = 'equalizerview'
35 |
36 | libraryDescription = 'Simple Equalizer View'
37 |
38 | siteUrl = 'https://github.com/gsotti/EqualizerView'
39 | gitUrl = 'https://github.com/gsotti/EqualizerView.git'
40 |
41 | libraryVersion = '0.3'
42 |
43 | developerId = 'gsotti'
44 | developerName = 'Stefan Gsottbauer'
45 | developerEmail = 'stefan@gsottbauer.eu'
46 |
47 | licenseName = 'The MIT License (MIT)'
48 | licenseUrl = 'https://opensource.org/licenses/MIT'
49 | allLicenses = ["MIT License"]
50 | }
51 |
52 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
53 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
--------------------------------------------------------------------------------
/equalizerview/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Gsottbauer/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/equalizerview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/equalizerview/src/main/java/eu/gsottbauer/equalizerview/EqualizerView.java:
--------------------------------------------------------------------------------
1 | package eu.gsottbauer.equalizerview;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorSet;
5 | import android.animation.ObjectAnimator;
6 | import android.animation.ValueAnimator;
7 | import android.content.Context;
8 | import android.content.res.TypedArray;
9 | import android.graphics.Color;
10 | import android.os.Build;
11 | import android.os.PowerManager;
12 | import android.util.AttributeSet;
13 | import android.view.Gravity;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.view.ViewTreeObserver;
17 | import android.view.animation.LinearInterpolator;
18 | import android.widget.LinearLayout;
19 |
20 | import java.util.ArrayList;
21 | import java.util.Random;
22 |
23 | /**
24 | * Created by claucookie on 01/02/15.
25 | * Modified by gsotti 06/01/2016
26 | */
27 | public class EqualizerView extends LinearLayout {
28 |
29 |
30 | public static final int DEFAULT_DURATION = 3000;
31 | public static final int DEFAULT_BAR_COUNT = 20;
32 | public static final int DEFAULT_ANIMATION_COUNT = 30;
33 | public static final int DEFAULT_COLOR = Color.DKGRAY;
34 | public static final int DEFAULT_WIDTH = ViewGroup.LayoutParams.MATCH_PARENT;
35 | public static final int DEFAULT_MARGIN_LEFT = 1;
36 | public static final int DEFAULT_MARGIN_RIGHT = 1;
37 | public static final boolean DEFAULT_RUN_IN_BATTERY_SAVE_MODE = false;
38 |
39 | ArrayList mBars = new ArrayList<>();
40 | ArrayList mAnimators = new ArrayList<>();
41 |
42 | AnimatorSet mPlayingSet;
43 | AnimatorSet mStopSet;
44 | Boolean isAnimating = false;
45 |
46 | int mViewHeight;
47 |
48 | int mForegroundColor = DEFAULT_COLOR;
49 | int mAnimationDuration = DEFAULT_DURATION;
50 | int mBarCount = DEFAULT_BAR_COUNT;
51 | int mBarWidth = DEFAULT_WIDTH;
52 | int mMarginLeft = DEFAULT_MARGIN_LEFT;
53 | int mMarginRight = DEFAULT_MARGIN_RIGHT;
54 | boolean mRunInBatterySafeMode = DEFAULT_RUN_IN_BATTERY_SAVE_MODE;
55 |
56 | public EqualizerView(Context context) {
57 | super(context);
58 | initView();
59 | }
60 |
61 | public EqualizerView(Context context, AttributeSet attrs) {
62 | super(context, attrs);
63 | getAttrs(context, attrs);
64 | initView();
65 | }
66 |
67 | public EqualizerView(Context context, AttributeSet attrs, int defStyle) {
68 | super(context, attrs, defStyle);
69 | getAttrs(context, attrs);
70 | initView();
71 | }
72 |
73 | private void getAttrs(Context context, AttributeSet attrs) {
74 |
75 | TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.EqualizerView, 0, 0);
76 |
77 | try {
78 |
79 | mRunInBatterySafeMode = a.getBoolean(R.styleable.EqualizerView_runInBatterySaveMode, DEFAULT_RUN_IN_BATTERY_SAVE_MODE);
80 | mForegroundColor = a.getInt(R.styleable.EqualizerView_barColor, DEFAULT_COLOR);
81 | mAnimationDuration = a.getInt(R.styleable.EqualizerView_animationDuration, DEFAULT_DURATION);
82 | mBarCount = a.getInt(R.styleable.EqualizerView_barCount, DEFAULT_BAR_COUNT);
83 | mBarWidth = (int) a.getDimension(R.styleable.EqualizerView_barWidth, DEFAULT_WIDTH);
84 | mMarginLeft = (int) a.getDimension(R.styleable.EqualizerView_marginLeft, DEFAULT_MARGIN_LEFT);
85 | mMarginRight = (int) a.getDimension(R.styleable.EqualizerView_marginRight, DEFAULT_MARGIN_RIGHT);
86 |
87 | } finally {
88 | a.recycle();
89 | }
90 | }
91 |
92 | private void initView() {
93 |
94 | setOrientation(LinearLayout.HORIZONTAL);
95 | setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
96 |
97 | for (int i = 0; i < mBarCount; i++) {
98 |
99 | View view = new View(getContext());
100 |
101 | LinearLayout.LayoutParams params = new LayoutParams(mBarWidth, ViewGroup.LayoutParams.MATCH_PARENT);
102 | params.weight = (mBarWidth <= -1) ? 1 : 0;
103 | params.setMargins(mMarginLeft, 0, mMarginRight, 0);
104 | view.setLayoutParams(params);
105 |
106 | view.setBackgroundColor(mForegroundColor);
107 | addView(view);
108 |
109 | setPivots(view);
110 | mBars.add(view);
111 | }
112 |
113 | getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
114 | @Override
115 | public void onGlobalLayout() {
116 | if (getHeight() > 0) {
117 | mViewHeight = getHeight();
118 |
119 | if (Build.VERSION.SDK_INT >= 16) {
120 | getViewTreeObserver().removeOnGlobalLayoutListener(this);
121 | }
122 | }
123 | }
124 | });
125 | }
126 |
127 | private void resetView() {
128 | removeAllViews();
129 | mBars.clear();
130 | mAnimators.clear();
131 | mPlayingSet = null;
132 | mStopSet = null;
133 | }
134 |
135 |
136 | private void setPivots(final View view) {
137 | view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
138 | @Override
139 | public void onGlobalLayout() {
140 | if (view.getHeight() > 0) {
141 | view.setPivotY(view.getHeight());
142 |
143 | if (Build.VERSION.SDK_INT >= 16) {
144 | view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
145 | }
146 | }
147 | }
148 | });
149 | }
150 |
151 | public void animateBars() {
152 |
153 | isAnimating = true;
154 |
155 | if (isInBatterySaveMode()) {
156 |
157 | if (mRunInBatterySafeMode) {
158 | new Thread(mAnimationThread).start();
159 | }
160 |
161 | } else {
162 |
163 | if (mPlayingSet == null) {
164 |
165 | for (int i = 0; i < mBars.size(); i++) {
166 |
167 | Random rand = new Random();
168 | float[] values = new float[DEFAULT_ANIMATION_COUNT];
169 |
170 | for (int j = 0; j < DEFAULT_ANIMATION_COUNT; j++) {
171 | values[j] = rand.nextFloat();
172 | }
173 |
174 | ObjectAnimator scaleYbar = ObjectAnimator.ofFloat(mBars.get(i), "scaleY", values);
175 | scaleYbar.setRepeatCount(ValueAnimator.INFINITE);
176 | scaleYbar.setRepeatMode(ObjectAnimator.REVERSE);
177 | mAnimators.add(scaleYbar);
178 | }
179 |
180 | mPlayingSet = new AnimatorSet();
181 | mPlayingSet.playTogether(mAnimators);
182 | mPlayingSet.setDuration(mAnimationDuration);
183 | mPlayingSet.setInterpolator(new LinearInterpolator());
184 | mPlayingSet.start();
185 |
186 | } else if (Build.VERSION.SDK_INT < 19) {
187 | if (!mPlayingSet.isStarted()) {
188 | mPlayingSet.start();
189 | }
190 | } else {
191 | if (mPlayingSet.isPaused()) {
192 | mPlayingSet.resume();
193 | }
194 | }
195 | }
196 | }
197 |
198 | public void stopBars() {
199 |
200 | isAnimating = false;
201 |
202 | if (!isInBatterySaveMode()) {
203 |
204 | if (mPlayingSet != null && mPlayingSet.isRunning() && mPlayingSet.isStarted()) {
205 | if (Build.VERSION.SDK_INT < 19) {
206 | mPlayingSet.end();
207 | } else {
208 | mPlayingSet.pause();
209 | }
210 | }
211 |
212 | if (mStopSet == null) {
213 | mAnimators.clear();
214 |
215 | for (int i = 0; i < mBars.size(); i++) {
216 | mAnimators.add(ObjectAnimator.ofFloat(mBars.get(i), "scaleY", 0.1f));
217 | }
218 |
219 | mStopSet = new AnimatorSet();
220 | mStopSet.playTogether(mAnimators);
221 | mStopSet.setDuration(200);
222 | mStopSet.start();
223 | } else if (!mStopSet.isStarted()) {
224 | mStopSet.start();
225 | }
226 | } else {
227 | if (mRunInBatterySafeMode) {
228 | resetView();
229 | initView();
230 | }
231 | }
232 | }
233 |
234 |
235 | private Runnable mAnimationThread = new Runnable() {
236 | @Override
237 | public void run() {
238 |
239 | final Random rand = new Random();
240 |
241 | while (isAnimating) {
242 |
243 | for (int i = 0; i < mBars.size(); i++) {
244 |
245 | final View bar_tmp = mBars.get(i);
246 |
247 | bar_tmp.post(new Runnable() {
248 | @Override
249 | public void run() {
250 |
251 | float value = rand.nextFloat() * mViewHeight;
252 |
253 | LinearLayout.LayoutParams params = (LayoutParams) bar_tmp.getLayoutParams();
254 | params.height = (int) value;
255 | bar_tmp.setLayoutParams(params);
256 | bar_tmp.invalidate();
257 | }
258 | });
259 | }
260 |
261 | try {
262 | Thread.sleep(80);
263 | } catch (InterruptedException e) {
264 | e.printStackTrace();
265 | }
266 | }
267 | }
268 | };
269 |
270 |
271 | private boolean isInBatterySaveMode() {
272 | PowerManager powerManager = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
273 |
274 | if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
275 | powerManager.isPowerSaveMode()) {
276 | return true;
277 | }
278 |
279 | return false;
280 | }
281 |
282 |
283 | /**
284 | * setBarColor
285 | *
286 | * @param mForegroundColor foreground color as hex string
287 | */
288 | public void setBarColor(String mForegroundColor) {
289 | this.mForegroundColor = Color.parseColor(mForegroundColor);
290 | resetView();
291 | initView();
292 | }
293 |
294 | /**
295 | * setBarColor
296 | *
297 | * @param mForegroundColor foreground color as integer
298 | */
299 | public void setBarColor(int mForegroundColor) {
300 | this.mForegroundColor = mForegroundColor;
301 | resetView();
302 | initView();
303 | }
304 |
305 | /**
306 | * setBarCount
307 | *
308 | * @param mBarCount bar count
309 | */
310 | public void setBarCount(int mBarCount) {
311 | this.mBarCount = mBarCount;
312 | resetView();
313 | initView();
314 | }
315 |
316 | /**
317 | * setAnimationDuration
318 | *
319 | * @param mAnimationDuration duration in milliseconds
320 | */
321 | public void setAnimationDuration(int mAnimationDuration) {
322 | this.mAnimationDuration = mAnimationDuration;
323 | resetView();
324 | initView();
325 | }
326 |
327 | /**
328 | * setBarWidth
329 | *
330 | * @param mBarWidth bar width in pixel
331 | */
332 | public void setBarWidth(int mBarWidth) {
333 | this.mBarWidth = mBarWidth;
334 | resetView();
335 | initView();
336 | }
337 |
338 | /**
339 | * setMarginRight
340 | *
341 | * @param mMarginRight margin right in pixel
342 | */
343 | public void setMarginRight(int mMarginRight) {
344 | this.mMarginRight = mMarginRight;
345 | resetView();
346 | initView();
347 | }
348 |
349 | /**
350 | * setMarginLeft
351 | *
352 | * @param mMarginLeft margin left in pixel
353 | */
354 | public void setMarginLeft(int mMarginLeft) {
355 | this.mMarginLeft = mMarginLeft;
356 | resetView();
357 | initView();
358 | }
359 |
360 |
361 | public void setRunInBatterySafeMode(boolean mRunInBatterySafeMode) {
362 | this.mRunInBatterySafeMode = mRunInBatterySafeMode;
363 | }
364 |
365 | public Boolean isAnimating() {
366 | return isAnimating;
367 | }
368 |
369 |
370 | }
--------------------------------------------------------------------------------
/equalizerview/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/equalizerview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | EqualizerView
3 |
4 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gsotti/EqualizerView/33f61cbcccca3bb268f6f2f0ac48e73e911593a4/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':equalizerview'
2 |
--------------------------------------------------------------------------------