+# ohos-audio-visualizer
-[](https://travis-ci.org/GautamChibde/android-audio-visualizer) [](https://codebeat.co/projects/github-com-gautamchibde-android-audio-visualizer-master) [  ](https://bintray.com/gautamchibde/Audio-Visualizer/audiovisualizer/_latestVersion) [](https://android-arsenal.com/api?level=14)
-# Demo
+#### 项目介绍
+- 项目名称:ohos-audio-visualizer
+- 所属系列:openharmony的第三方组件适配移植
+- 功能:实现音频可视化
+- 项目移植状态:主功能完成
+- 调用差异:无
+- 开发版本:sdk5,DevEco Studio2.1 beta4(实时更新以当前最新版本为准)
+- 基线版本:Release v2.2.0
-     
+#### 效果演示
+
-# Importing the Library
+#### 安装教程
-Add to build.gradle:
-```groovy
-dependencies {
- compile 'com.chibde:audiovisualizer:2.2.0'
+1.在项目根目录下的build.gradle文件中,
+ ```gradle
+allprojects {
+ repositories {
+ maven {
+ url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
+ }
+ }
}
+ ```
+2.在entry模块的build.gradle文件中,
+ ```gradle
+ dependencies {
+ implementation('com.gitee.chinasoft_ohos:ohos-audio-visualizer:0.0.1-SNAPSHOT')
+ ......
+ }
+ ```
+
+在sdk5,DevEco Studio2.1 beta4下项目可直接运行
+如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件,
+并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
+
+#### 使用说明
+
+```示例XML
+
```
-Library is available in jcenter repository
-
-# How to use
-
- Refer to the [sample](https://github.com/GautamChibde/android-audio-visualizer/tree/master/sample) project on how to use visualizer or refer to [WIKI](https://github.com/GautamChibde/android-audio-visualizer/wiki) docs.
-
- ## Visualizers
-* [LineVisualizer](https://github.com/GautamChibde/android-audio-visualizer/wiki/Line-Visualizer)
-* [BarVisualizer](https://github.com/GautamChibde/android-audio-visualizer/wiki/Bar-Visualizer)
-* [CircleVisualizer](https://github.com/GautamChibde/android-audio-visualizer/wiki/Circle-Visualizer)
-* [Circle Bar Visualizer](https://github.com/GautamChibde/android-audio-visualizer/wiki/Circle-Bar-Visualizer)
-* [Line Bar Visualizer](https://github.com/GautamChibde/android-audio-visualizer/wiki/Line-Bar-Visualizer)
-* [Square Bar Visualizer](https://github.com/GautamChibde/android-audio-visualizer/wiki/SquareBar-Visualizer)
-
-License
-=======
-Copyright 2017 Gautam Chibde
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
+
+```java
+CircleVisualizer circleVisualizer = (CircleVisualizer) findComponentById(ResourceTable.Id_visualizer);
+circleVisualizer.setColor(Color.BLUE.getValue());
+// Customize the size of the circle. by defalut multipliers is 1.
+circleVisualizer.setRadiusMultiplier(3f);
+// set the line with for the visualizer between 1-10 default 1.
+circleVisualizer.setStrokeWidth(1);
+circleVisualizer.setPlayer(playSoundUtil.getAudioRenderer().getRendererSessionId(), getBundleName());
+```
+#### 测试信息
+
+CodeCheck代码测试无异常
+
+CloudTest代码测试无异常
+
+火绒安全病毒安全检测通过
+
+当前版本demo功能与原组件基本无差异
+
+
+#### 版本迭代
+
+- 0.0.1-SNAPSHOT
+
+#### 版权和许可信息
+
+ Copyright 2017 Gautam Chibde
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/audiovisualizer/audiovisualizer.iml b/audiovisualizer/audiovisualizer.iml
new file mode 100644
index 0000000000000000000000000000000000000000..4d1a1dcbc90c59fcd30dfd3ea3bfab658968a15c
--- /dev/null
+++ b/audiovisualizer/audiovisualizer.iml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/audiovisualizer/build.gradle b/audiovisualizer/build.gradle
index 34e87939c400db24f7ba7690beec6c28a555d13c..312bc1c336a2b750048a182991e5872344e45dbf 100644
--- a/audiovisualizer/build.gradle
+++ b/audiovisualizer/build.gradle
@@ -1,54 +1,13 @@
-apply plugin: 'com.android.library'
-//apply plugin: 'com.jfrog.bintray'
-//apply plugin: 'maven-publish'
-//
-//ext {
-// bintrayRepo = 'Audio-Visualizer' // your repo name
-// bintrayName = 'audiovisualizer' // has to be same as your library module name
-// publishedGroupId = 'com.chibde' // your module package name
-// libraryName = 'audiovisualizer'
-// artifact = 'audiovisualizer' // has to be same as your library module name
-// libraryDescription = 'Audio visualisation for android MediaPlayer'
-// siteUrl = 'https://github.com/GautamChibde/android-audio-visualizer'
-// gitUrl = 'https://github.com/GautamChibde/android-audio-visualizer.git'
-// libraryVersion = '2.2.0'
-// developerId = 'gautamchibde'
-// developerName = 'Gautam Chibde'
-// developerEmail = 'gautamchibde@gmail.com'
-// licenseName = 'The Apache Software License, Version 2.0'
-// licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
-// allLicenses = ["Apache-2.0"]
-//}
-
-android {
- compileSdkVersion 30
- buildToolsVersion '30.0.3'
-
+apply plugin: 'com.huawei.ohos.library'
+ohos {
+ compileSdkVersion 5
defaultConfig {
- minSdkVersion 14
- targetSdkVersion 30
- versionCode 1
- versionName "1.0"
-
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
-
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
+ compatibleSdkVersion 5
}
+
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
- androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1', {
- exclude group: 'com.android.support', module: 'support-annotations'
- })
- implementation 'androidx.appcompat:appcompat:1.0.0'
- testImplementation 'junit:junit:4.12'
+ testCompile 'junit:junit:4.12'
}
-
-//apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/installv.gradle'
-//apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/bintrayv.gradle'
diff --git a/audiovisualizer/proguard-rules.pro b/audiovisualizer/proguard-rules.pro
deleted file mode 100644
index c8f0183af73b528949011c6924cd9ea30ea22bee..0000000000000000000000000000000000000000
--- a/audiovisualizer/proguard-rules.pro
+++ /dev/null
@@ -1,25 +0,0 @@
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in /home/gautam/Sdk/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the proguardFiles
-# directive in build.gradle.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
-
-# Uncomment this to preserve the line number information for
-# debugging stack traces.
-#-keepattributes SourceFile,LineNumberTable
-
-# If you keep the line number information, uncomment this to
-# hide the original source file name.
-#-renamesourcefileattribute SourceFile
diff --git a/audiovisualizer/src/androidTest/java/com/chibde/ExampleInstrumentedTest.java b/audiovisualizer/src/androidTest/java/com/chibde/ExampleInstrumentedTest.java
deleted file mode 100644
index 41beab76c1a2109f2d79b5b8ebccb45c7be278d1..0000000000000000000000000000000000000000
--- a/audiovisualizer/src/androidTest/java/com/chibde/ExampleInstrumentedTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.chibde;
-
-import android.content.Context;
-import androidx.test.InstrumentationRegistry;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import static junit.framework.Assert.assertEquals;
-
-/**
- * Instrumentation test, which will execute on an Android device.
- *
- * @see Testing documentation
- */
-@RunWith(AndroidJUnit4.class)
-public class ExampleInstrumentedTest {
- @Test
- public void useAppContext() throws Exception {
- // Context of the app under test.
- Context appContext = InstrumentationRegistry.getTargetContext();
-
- assertEquals("com.chibde.audiovisulaizer.test", appContext.getPackageName());
- }
-}
diff --git a/audiovisualizer/src/main/AndroidManifest.xml b/audiovisualizer/src/main/AndroidManifest.xml
deleted file mode 100644
index 2227ccdb30bb1edfb1a2dbf68fac98736c14f11f..0000000000000000000000000000000000000000
--- a/audiovisualizer/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
diff --git a/audiovisualizer/src/main/config.json b/audiovisualizer/src/main/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..fe967a47daea9851888b383eb692ef561bd79d61
--- /dev/null
+++ b/audiovisualizer/src/main/config.json
@@ -0,0 +1,27 @@
+{
+ "app": {
+ "bundleName": "com.chibde.visualizer",
+ "vendor": "chibde",
+ "version": {
+ "code": 1,
+ "name": "1.0"
+ },
+ "apiVersion": {
+ "compatible": 5,
+ "target": 5,
+ "releaseType": "Release"
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "com.chibde.visualizer",
+ "deviceType": [
+ "phone"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "audiovisualizer",
+ "moduleType": "har"
+ }
+ }
+}
\ No newline at end of file
diff --git a/audiovisualizer/src/main/java/com/chibde/BaseVisualizer.java b/audiovisualizer/src/main/java/com/chibde/BaseVisualizer.java
index b359aac7db4fc051237bd1df10ad4191ccf0cd6d..05b33507d2284fd66613d344268c44ba9732dbfd 100644
--- a/audiovisualizer/src/main/java/com/chibde/BaseVisualizer.java
+++ b/audiovisualizer/src/main/java/com/chibde/BaseVisualizer.java
@@ -1,41 +1,41 @@
/*
-* Copyright (C) 2017 Gautam Chibde
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright (C) 2017 Gautam Chibde
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.chibde;
-import android.content.Context;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.media.MediaPlayer;
-import android.media.audiofx.Visualizer;
-import android.util.AttributeSet;
-import android.view.View;
-import androidx.annotation.Nullable;
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.Component;
+import ohos.agp.render.Paint;
+import ohos.agp.utils.Color;
+import ohos.app.Context;
+import ohos.media.audio.*;
+
+
+import java.util.Arrays;
/**
* Base class that contains common implementation for all
* visualizers.
* Created by gautam chibde on 28/10/17.
*/
-
-abstract public class BaseVisualizer extends View {
+abstract public class BaseVisualizer extends Component {
protected byte[] bytes;
protected Paint paint;
- protected Visualizer visualizer;
- protected int color = Color.BLUE;
+ protected int color;
+ private AudioWaver audioWaver;
public BaseVisualizer(Context context) {
super(context);
@@ -43,19 +43,20 @@ abstract public class BaseVisualizer extends View {
init();
}
- public BaseVisualizer(Context context, @Nullable AttributeSet attrs) {
+ public BaseVisualizer(Context context, AttrSet attrs) {
super(context, attrs);
init(attrs);
init();
}
- public BaseVisualizer(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+
+ public BaseVisualizer(Context context, AttrSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
init();
}
- private void init(AttributeSet attributeSet) {
+ private void init(AttrSet attributeSet) {
paint = new Paint();
}
@@ -66,53 +67,50 @@ abstract public class BaseVisualizer extends View {
*/
public void setColor(int color) {
this.color = color;
- this.paint.setColor(this.color);
- }
-
- /**
- * @deprecated will be removed in next version use {@link BaseVisualizer#setPlayer(int)} instead
- * @param mediaPlayer MediaPlayer
- */
- @Deprecated
- public void setPlayer(MediaPlayer mediaPlayer) {
- setPlayer(mediaPlayer.getAudioSessionId());
+ this.paint.setColor(new Color(color));
}
- public void setPlayer(int audioSessionId) {
- visualizer = new Visualizer(audioSessionId);
- visualizer.setEnabled(false);
- visualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
+ public void setPlayer(int sessionid, String name) {
- visualizer.setDataCaptureListener(new Visualizer.OnDataCaptureListener() {
+ audioWaver = new AudioWaver(sessionid, name);
+ audioWaver.setActivated(false);
+ audioWaver.setDataSize(AudioWaver.getMaxDataSize());
+ audioWaver.setWaveDataObserver(new AudioWaver.WaveDataObserver() {
@Override
- public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes,
- int samplingRate) {
+ public void onWaveData(byte[] bytes, int i) {
+
BaseVisualizer.this.bytes = bytes;
- invalidate();
+ //刷新
+ getContext().getUITaskDispatcher().asyncDispatch(new Runnable() {
+ @Override
+ public void run() {
+ invalidate();
+ }
+ });
}
+ }, AudioWaver.getMinInterval());
+ audioWaver.setActivated(true);
- @Override
- public void onFftDataCapture(Visualizer visualizer, byte[] bytes,
- int samplingRate) {
- }
- }, Visualizer.getMaxCaptureRate() / 2, true, false);
- visualizer.setEnabled(true);
}
+ @Override
public void release() {
+ super.release();
//will be null if setPlayer hasn't yet been called
- if (visualizer == null)
+ if (audioWaver == null)
return;
-
- visualizer.release();
+ audioWaver.release();
bytes = null;
invalidate();
}
- public Visualizer getVisualizer() {
- return visualizer;
+
+ public AudioWaver getVisualizer() {
+ return audioWaver;
}
protected abstract void init();
+
+
}
diff --git a/audiovisualizer/src/main/java/com/chibde/visualizer/BarVisualizer.java b/audiovisualizer/src/main/java/com/chibde/visualizer/BarVisualizer.java
index df6a4a0cb1f6daaf9b767b260449bbb1b5fb0df4..a5e605aa153236e9ff3dac32ef4b1a715c488a30 100644
--- a/audiovisualizer/src/main/java/com/chibde/visualizer/BarVisualizer.java
+++ b/audiovisualizer/src/main/java/com/chibde/visualizer/BarVisualizer.java
@@ -15,46 +15,41 @@
*/
package com.chibde.visualizer;
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import androidx.annotation.Nullable;
-import android.util.AttributeSet;
import com.chibde.BaseVisualizer;
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.Component;
+import ohos.agp.render.Canvas;
+import ohos.agp.render.Paint;
+import ohos.agp.utils.Point;
+import ohos.app.Context;
/**
- * Custom view that creates a Bar visualizer effect for
- * the android {@link android.media.MediaPlayer}
+ * Custom component that creates a Bar visualizer effect for
*
* Created by gautam chibde on 28/10/17.
*/
-public class BarVisualizer extends BaseVisualizer {
-
+public class BarVisualizer extends BaseVisualizer implements Component.DrawTask {
private float density = 50;
private int gap;
public BarVisualizer(Context context) {
super(context);
+ addDrawTask(this);
}
- public BarVisualizer(Context context,
- @Nullable AttributeSet attrs) {
+ public BarVisualizer(Context context, AttrSet attrs) {
super(context, attrs);
+ addDrawTask(this);
}
- public BarVisualizer(Context context,
- @Nullable AttributeSet attrs,
- int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- }
@Override
protected void init() {
this.density = 50;
this.gap = 4;
- paint.setStyle(Paint.Style.FILL);
+ paint.setStyle(Paint.Style.FILL_STYLE);
}
/**
@@ -72,22 +67,24 @@ public class BarVisualizer extends BaseVisualizer {
this.density = 10;
}
}
-
@Override
- protected void onDraw(Canvas canvas) {
+ public void onDraw(Component component, Canvas canvas) {
if (bytes != null) {
float barWidth = getWidth() / density;
float div = bytes.length / density;
paint.setStrokeWidth(barWidth - gap);
-
for (int i = 0; i < density; i++) {
int bytePosition = (int) Math.ceil(i * div);
int top = getHeight() +
((byte) (Math.abs(bytes[bytePosition]) + 128)) * getHeight() / 128;
float barX = (i * barWidth) + (barWidth / 2);
canvas.drawLine(barX, getHeight(), barX, top, paint);
+
+ Point points =new Point(barX,getHeight());
+ Point pointss =new Point(barX,top);
+ canvas.drawLine(points,pointss,paint);
}
- super.onDraw(canvas);
+ //super.onDraw(component,canvas);
}
}
}
diff --git a/audiovisualizer/src/main/java/com/chibde/visualizer/BlazingColorVisualizer.java b/audiovisualizer/src/main/java/com/chibde/visualizer/BlazingColorVisualizer.java
index ef94722e6c485e433780d5f01fc8872d8ebd161c..3355e67d5286b4484cf8edc4757dcce923b8a72c 100644
--- a/audiovisualizer/src/main/java/com/chibde/visualizer/BlazingColorVisualizer.java
+++ b/audiovisualizer/src/main/java/com/chibde/visualizer/BlazingColorVisualizer.java
@@ -1,75 +1,79 @@
/*
-* Copyright (C) 2017 Gautam Chibde
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright (C) 2017 Gautam Chibde
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.chibde.visualizer;
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.LinearGradient;
-import android.graphics.Shader;
-import androidx.annotation.Nullable;
-import android.util.AttributeSet;
-
import com.chibde.BaseVisualizer;
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.Component;
+import ohos.agp.render.Canvas;
+import ohos.agp.render.LinearShader;
+import ohos.agp.render.Paint;
+import ohos.agp.render.Shader;
+import ohos.agp.utils.Color;
+import ohos.agp.utils.Point;
+import ohos.app.Context;
/**
* TODO
- *
- * Created by gautam chibde on 29/10/17.
+ * Created by gautam chibd e on 29/10/17.
*/
-class BlazingColorVisualizer extends BaseVisualizer {
+class BlazingColorVisualizer extends BaseVisualizer implements Component.DrawTask {
private Shader shader;
+ // private ShapeElement shapeElement;
public BlazingColorVisualizer(Context context) {
super(context);
+ addDrawTask(this);
}
public BlazingColorVisualizer(Context context,
- @Nullable AttributeSet attrs) {
+ AttrSet attrs) {
super(context, attrs);
+ addDrawTask(this);
}
public BlazingColorVisualizer(Context context,
- @Nullable AttributeSet attrs,
+ AttrSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
+ addDrawTask(this);
}
@Override
protected void init() {
- shader = new LinearGradient(0,
- 0,
- 0,
- getHeight(),
- Color.BLUE,
- Color.GREEN,
- Shader.TileMode.MIRROR /*or REPEAT*/);
+ Point[] point = new Point[]{new Point(0, 0)};
+ float[] point1 = {0, getHeight()};
+
+ Color[] colors = {Color.BLUE, Color.GREEN};
+ shader = new LinearShader(point, point1, colors, Shader.TileMode.MIRROR_TILEMODE);
}
+
@Override
- protected void onDraw(Canvas canvas) {
+ public void onDraw(Component component, Canvas canvas) {
if (bytes != null) {
- paint.setShader(shader);
+ paint.setShader(shader, Paint.ShaderType.LINEAR_SHADER);
for (int i = 0, k = 0; i < (bytes.length - 1) && k < bytes.length; i++, k++) {
int top = getHeight() +
((byte) (Math.abs(bytes[k]) + 128)) * getHeight() / 128;
- canvas.drawLine(i, getHeight(), i, top, paint);
+ Point points = new Point(i, getHeight());
+ Point pointss = new Point(i, top);
+ canvas.drawLine(points, pointss, paint);
}
- super.onDraw(canvas);
}
}
}
diff --git a/audiovisualizer/src/main/java/com/chibde/visualizer/CircleBarVisualizer.java b/audiovisualizer/src/main/java/com/chibde/visualizer/CircleBarVisualizer.java
index c10b93d465b51fcd1e59c5518a25dfd5978d2c1e..50db97a9e354d21049360084613e9d9c5a6e936c 100644
--- a/audiovisualizer/src/main/java/com/chibde/visualizer/CircleBarVisualizer.java
+++ b/audiovisualizer/src/main/java/com/chibde/visualizer/CircleBarVisualizer.java
@@ -15,61 +15,62 @@
*/
package com.chibde.visualizer;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import androidx.annotation.Nullable;
-import android.util.AttributeSet;
-
import com.chibde.BaseVisualizer;
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.Component;
+import ohos.agp.render.Canvas;
+import ohos.agp.render.Paint;
+import ohos.agp.utils.Color;
+import ohos.app.Context;
/**
- * Custom view that creates a Circle and Bar visualizer effect for
- * the android {@link android.media.MediaPlayer}
+ * Custom component that creates a Circle and Bar visualizer effect for
*
* Created by gautam chibde on 20/11/17.
*/
-public class CircleBarVisualizer extends BaseVisualizer {
+public class CircleBarVisualizer extends BaseVisualizer implements Component.DrawTask {
private float[] points;
private Paint circlePaint;
private int radius;
public CircleBarVisualizer(Context context) {
super(context);
+ addDrawTask(this::onDraw);
}
public CircleBarVisualizer(Context context,
- @Nullable AttributeSet attrs) {
+ AttrSet attrs) {
super(context, attrs);
+ addDrawTask(this::onDraw);
}
public CircleBarVisualizer(Context context,
- @Nullable AttributeSet attrs,
+ AttrSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
+ addDrawTask(this::onDraw);
}
@Override
protected void init() {
- paint.setStyle(Paint.Style.STROKE);
+ paint.setStyle(Paint.Style.STROKE_STYLE);
circlePaint = new Paint();
radius = -1;
}
@Override
- protected void onDraw(Canvas canvas) {
+ public void onDraw(Component component, Canvas canvas) {
if (radius == -1) {
radius = getHeight() < getWidth() ? getHeight() : getWidth();
radius = (int) (radius * 0.65 / 2);
double circumference = 2 * Math.PI * radius;
paint.setStrokeWidth((float) (circumference / 120));
- circlePaint.setStyle(Paint.Style.STROKE);
+ circlePaint.setStyle(Paint.Style.STROKE_STYLE);
circlePaint.setStrokeWidth(4);
}
- circlePaint.setColor(color);
- canvas.drawCircle(getWidth() / 2f, getHeight() / 2f, radius, circlePaint);
+ circlePaint.setColor(new Color(color));
+ canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius, circlePaint);
if (bytes != null) {
if (points == null || points.length < bytes.length * 4) {
points = new float[bytes.length * 4];
@@ -99,6 +100,6 @@ public class CircleBarVisualizer extends BaseVisualizer {
canvas.drawLines(points, paint);
}
- super.onDraw(canvas);
+
}
}
diff --git a/audiovisualizer/src/main/java/com/chibde/visualizer/CircleBarVisualizerSmooth.java b/audiovisualizer/src/main/java/com/chibde/visualizer/CircleBarVisualizerSmooth.java
index cbb112751c02dea7416a8b576ea229e97ee1bbb1..b261cee6a087dcb6b67c062fc76543b0dee124d0 100644
--- a/audiovisualizer/src/main/java/com/chibde/visualizer/CircleBarVisualizerSmooth.java
+++ b/audiovisualizer/src/main/java/com/chibde/visualizer/CircleBarVisualizerSmooth.java
@@ -15,30 +15,23 @@
*/
package com.chibde.visualizer;
-
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-
-
-import android.util.AttributeSet;
-
-import androidx.annotation.Nullable;
-
import com.chibde.BaseVisualizer;
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.Component;
+import ohos.agp.render.Canvas;
+import ohos.agp.render.Paint;
+import ohos.app.Context;
import java.util.HashMap;
import java.util.Map;
/**
- * Custom view that creates a Circle and Bar visualizer effect for the android
- * {@link android.media.MediaPlayer}
+ * Custom component that creates a Circle and Bar visualizer effect for the ohos
*
* Created by gautam chibde on 20/11/17. Smooth effect added by Ali heidari
*/
-public class CircleBarVisualizerSmooth extends BaseVisualizer {
+public class CircleBarVisualizerSmooth extends BaseVisualizer implements Component.DrawTask {
private final static float _StepsCount = 2;
private final static int _BarCount = 120;
private final static float _AngleStep = 360f / _BarCount;
@@ -48,15 +41,15 @@ public class CircleBarVisualizerSmooth extends BaseVisualizer {
// Stores radius and step-counter which every invoking of "onDraw" requires them
private Map configs = null;
-
public CircleBarVisualizerSmooth(Context context,
- @Nullable AttributeSet attrs) {
+ AttrSet attrs) {
super(context, attrs);
+ addDrawTask(this);
}
@Override
protected void init() {
- paint.setStyle(Paint.Style.STROKE);
+ paint.setStyle(Paint.Style.STROKE_STYLE);
}
/*
@@ -173,7 +166,7 @@ public class CircleBarVisualizerSmooth extends BaseVisualizer {
// Because we have 120 bars, so the buffer should be filtered and only 120 bytes
// from the buffer will have chosen to be shown.
// Get length of bar
- int t = getBarLength(i, (bytes.length - bytes.length % 4f) / _BarCount);
+ int t = getBarLength(i, (bytes.length - bytes.length % 4) / _BarCount);
// Find the round by
int round = (int) (getConfig("stepCounter") % _StepsCount);
if (round == 0) {
@@ -210,7 +203,7 @@ public class CircleBarVisualizerSmooth extends BaseVisualizer {
points[indexM4 + 1] = (float) (this.getHeight() / 2 + getConfig("radius") * Math.sin(angle));
}
// Calculates points for current round
- calcRound(i, angle);
+
}
/*
@@ -222,8 +215,21 @@ public class CircleBarVisualizerSmooth extends BaseVisualizer {
* Differences / 3 Finally when OldEnd(s) matched to End(s) Need to set End with
* OldEnd value And the action will be repeated until visualizer is running.
*/
+
+
+ /*
+ * Reset configs
+ */
+ private void resetConfigs() {
+ // The stepCounter increases
+ setConfig("stepCounter", getConfig("stepCounter") + 1);
+ // Initialized, no longer need initializing
+ if (getConfig("needsInit") == 1)
+ setConfig("needsInit", 0);
+ }
+
@Override
- protected void onDraw(Canvas canvas) {
+ public void onDraw(Component component, Canvas canvas) {
// Check if bytes initiated before
if (bytes == null)
return;
@@ -243,26 +249,13 @@ public class CircleBarVisualizerSmooth extends BaseVisualizer {
double radianAngle = Math.toRadians(angle);
this.fillStartingPoints(i, radianAngle);
-
-
}
if (getConfig("needsInit") == 0)
canvas.drawLines(points, paint);
- super.onDraw(canvas);
+ //super.onDraw(canvas);
// Resets configurations variable for next calling of onDraw
this.resetConfigs();
}
-
- /*
- * Reset configs
- */
- private void resetConfigs() {
- // The stepCounter increases
- setConfig("stepCounter", getConfig("stepCounter") + 1);
- // Initialized, no longer need initializing
- if (getConfig("needsInit") == 1)
- setConfig("needsInit", 0);
- }
}
\ No newline at end of file
diff --git a/audiovisualizer/src/main/java/com/chibde/visualizer/CircleVisualizer.java b/audiovisualizer/src/main/java/com/chibde/visualizer/CircleVisualizer.java
index d65044062b66173669d236304268027fdbe939d1..46a534cd6b4d8bff6c5b0f50525afe6bb20a7a95 100644
--- a/audiovisualizer/src/main/java/com/chibde/visualizer/CircleVisualizer.java
+++ b/audiovisualizer/src/main/java/com/chibde/visualizer/CircleVisualizer.java
@@ -1,48 +1,49 @@
/*
-* Copyright (C) 2017 Gautam Chibde
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright (C) 2017 Gautam Chibde
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.chibde.visualizer;
-import android.content.Context;
-import android.graphics.Canvas;
-import androidx.annotation.Nullable;
-import android.util.AttributeSet;
-
import com.chibde.BaseVisualizer;
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.Component;
+import ohos.agp.render.Canvas;
+import ohos.app.Context;
/**
- * Custom view that creates a circle visualizer effect for
- * the android {@link android.media.MediaPlayer}
- *
+ * Custom component that creates a circle visualizer effect for
+ *
* Created by gautam on 13/11/17.
*/
-public class CircleVisualizer extends BaseVisualizer {
+public class CircleVisualizer extends BaseVisualizer implements Component.DrawTask {
private float[] points;
private float radiusMultiplier = 1;
private float strokeWidth = 0.005f;
public CircleVisualizer(Context context) {
super(context);
+ addDrawTask(this);
}
- public CircleVisualizer(Context context, @Nullable AttributeSet attrs) {
+ public CircleVisualizer(Context context, AttrSet attrs) {
super(context, attrs);
+ addDrawTask(this);
}
- public CircleVisualizer(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+ public CircleVisualizer(Context context, AttrSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
+ addDrawTask(this);
}
@Override
@@ -75,7 +76,7 @@ public class CircleVisualizer extends BaseVisualizer {
}
@Override
- protected void onDraw(Canvas canvas) {
+ public void onDraw(Component component, Canvas canvas) {
if (bytes != null) {
paint.setStrokeWidth(getHeight() * strokeWidth);
if (points == null || points.length < bytes.length * 4) {
@@ -105,6 +106,5 @@ public class CircleVisualizer extends BaseVisualizer {
}
canvas.drawLines(points, paint);
}
- super.onDraw(canvas);
}
}
diff --git a/audiovisualizer/src/main/java/com/chibde/visualizer/LineBarVisualizer.java b/audiovisualizer/src/main/java/com/chibde/visualizer/LineBarVisualizer.java
index 3b9feaeb167a5577decf8557e6727288eaf6fdd0..9d481de7cf48b91fd11596f904d18ff1b3d7c68f 100644
--- a/audiovisualizer/src/main/java/com/chibde/visualizer/LineBarVisualizer.java
+++ b/audiovisualizer/src/main/java/com/chibde/visualizer/LineBarVisualizer.java
@@ -14,38 +14,39 @@
* limitations under the License.
*/
package com.chibde.visualizer;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import androidx.annotation.Nullable;
-import android.util.AttributeSet;
-
import com.chibde.BaseVisualizer;
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.Component;
+import ohos.agp.render.Canvas;
+import ohos.agp.render.Paint;
+import ohos.agp.utils.Color;
+import ohos.agp.utils.Point;
+import ohos.app.Context;
/**
- * Custom view that creates a Line and Bar visualizer effect for
- * the android {@link android.media.MediaPlayer}
+ * Custom component that creates a Line and Bar visualizer effect for
*
* Created by gautam chibde on 22/11/17.
*/
-public class LineBarVisualizer extends BaseVisualizer {
+public class LineBarVisualizer extends BaseVisualizer implements Component.DrawTask {
private Paint middleLine;
private float density;
private int gap;
public LineBarVisualizer(Context context) {
super(context);
+ addDrawTask(this::onDraw);
}
- public LineBarVisualizer(Context context, @Nullable AttributeSet attrs) {
+ public LineBarVisualizer(Context context, AttrSet attrs) {
super(context, attrs);
+ addDrawTask(this::onDraw);
}
- public LineBarVisualizer(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+ public LineBarVisualizer(Context context, AttrSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
+ addDrawTask(this::onDraw);
}
@Override
@@ -79,15 +80,18 @@ public class LineBarVisualizer extends BaseVisualizer {
}
}
+
@Override
- protected void onDraw(Canvas canvas) {
+ public void onDraw(Component component, Canvas canvas) {
if (middleLine.getColor() != Color.BLUE) {
- middleLine.setColor(color);
+ middleLine.setColor(new Color());
}
if (bytes != null) {
float barWidth = getWidth() / density;
float div = bytes.length / density;
- canvas.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2, middleLine);
+ Point point=new Point(0,getHeight()/2);
+ Point point11=new Point(getWidth(),getHeight()/2);
+ canvas.drawLine(point,point11,middleLine);
paint.setStrokeWidth(barWidth - gap);
for (int i = 0; i < density; i++) {
@@ -101,10 +105,14 @@ public class LineBarVisualizer extends BaseVisualizer {
* (getHeight() / 2) / 128;
float barX = (i * barWidth) + (barWidth / 2);
- canvas.drawLine(barX, bottom, barX, getHeight() / 2, paint);
- canvas.drawLine(barX, top, barX, getHeight() / 2, paint);
+ Point points =new Point(barX,bottom);
+ Point pointss =new Point(barX,getHeight()/2);
+ canvas.drawLine(points,pointss, paint);
+ Point point1 =new Point(barX,top);
+ Point point2 =new Point(barX,getHeight()/2);
+ canvas.drawLine(point1,point2, paint);
}
- super.onDraw(canvas);
+ // super.onDraw(canvas);
}
}
}
diff --git a/audiovisualizer/src/main/java/com/chibde/visualizer/LineVisualizer.java b/audiovisualizer/src/main/java/com/chibde/visualizer/LineVisualizer.java
index e037c4a3dda4de86fe706f8503ea5f8382c994c0..476f0b6d96ae67a850877bd7b6e9e837d2a3150b 100644
--- a/audiovisualizer/src/main/java/com/chibde/visualizer/LineVisualizer.java
+++ b/audiovisualizer/src/main/java/com/chibde/visualizer/LineVisualizer.java
@@ -14,40 +14,40 @@
* limitations under the License.
*/
package com.chibde.visualizer;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Rect;
-import androidx.annotation.Nullable;
-import android.util.AttributeSet;
-
import com.chibde.BaseVisualizer;
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.Component;
+import ohos.agp.render.Canvas;
+import ohos.agp.utils.Rect;
+import ohos.app.Context;
/**
- * Custom view that creates a Bar visualizer effect for
- * the android {@link android.media.MediaPlayer}
+ * Custom component that creates a Bar visualizer effect fo
*
* Created by gautam chibde on 28/10/17.
*/
-public class LineVisualizer extends BaseVisualizer {
+public class LineVisualizer extends BaseVisualizer implements Component.DrawTask {
private float[] points;
private Rect rect = new Rect();
private float strokeWidth = 0.005f;
public LineVisualizer(Context context) {
super(context);
+ addDrawTask(this::onDraw);
}
public LineVisualizer(Context context,
- @Nullable AttributeSet attrs) {
+ AttrSet attrs) {
super(context, attrs);
+ addDrawTask(this::onDraw);
}
public LineVisualizer(Context context,
- @Nullable AttributeSet attrs,
+ AttrSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
+ addDrawTask(this::onDraw);
}
@Override
@@ -69,7 +69,7 @@ public class LineVisualizer extends BaseVisualizer {
}
@Override
- protected void onDraw(Canvas canvas) {
+ public void onDraw(Component component, Canvas canvas) {
if (bytes != null) {
if (points == null || points.length < bytes.length * 4) {
points = new float[bytes.length * 4];
@@ -78,15 +78,14 @@ public class LineVisualizer extends BaseVisualizer {
rect.set(0, 0, getWidth(), getHeight());
for (int i = 0; i < bytes.length - 1; i++) {
- points[i * 4] = rect.width() * i / (bytes.length - 1);
- points[i * 4 + 1] = rect.height() / 2
- + ((byte) (bytes[i] + 128)) * (rect.height() / 3) / 128;
- points[i * 4 + 2] = rect.width() * (i + 1) / (bytes.length - 1);
- points[i * 4 + 3] = rect.height() / 2
- + ((byte) (bytes[i + 1] + 128)) * (rect.height() / 3) / 128;
+ points[i * 4] = rect.getWidth() * i / (bytes.length - 1);
+ points[i * 4 + 1] = rect.getHeight() / 2
+ + ((byte) (bytes[i] + 128)) * (rect.getHeight() / 3) / 128;
+ points[i * 4 + 2] = rect.getWidth() * (i + 1) / (bytes.length - 1);
+ points[i * 4 + 3] = rect.getHeight() / 2
+ + ((byte) (bytes[i + 1] + 128)) * (rect.getHeight() / 3) / 128;
}
canvas.drawLines(points, paint);
}
- super.onDraw(canvas);
}
}
diff --git a/audiovisualizer/src/main/java/com/chibde/visualizer/MyApplication.java b/audiovisualizer/src/main/java/com/chibde/visualizer/MyApplication.java
new file mode 100644
index 0000000000000000000000000000000000000000..14ce34c22bf9e670a5993a06da99c0627378b3e0
--- /dev/null
+++ b/audiovisualizer/src/main/java/com/chibde/visualizer/MyApplication.java
@@ -0,0 +1,10 @@
+package com.chibde.visualizer;
+
+import ohos.aafwk.ability.AbilityPackage;
+
+public class MyApplication extends AbilityPackage {
+ @Override
+ public void onInitialize() {
+ super.onInitialize();
+ }
+}
diff --git a/audiovisualizer/src/main/java/com/chibde/visualizer/SquareBarVisualizer.java b/audiovisualizer/src/main/java/com/chibde/visualizer/SquareBarVisualizer.java
index 8409163461d42285dc43b0769ce1492e51a9a3ce..1bc0d91bba5d5dc3f0625c107d73ede2496aef61 100644
--- a/audiovisualizer/src/main/java/com/chibde/visualizer/SquareBarVisualizer.java
+++ b/audiovisualizer/src/main/java/com/chibde/visualizer/SquareBarVisualizer.java
@@ -15,47 +15,48 @@
*/
package com.chibde.visualizer;
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.util.AttributeSet;
-
-import androidx.annotation.Nullable;
-
import com.chibde.BaseVisualizer;
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.Component;
+import ohos.agp.render.Canvas;
+import ohos.agp.render.Paint;
+import ohos.agp.utils.Point;
+import ohos.app.Context;
/**
- * Custom view that creates a Bar visualizer effect for
- * the android {@link android.media.MediaPlayer}
+ * Custom component that creates a Bar visualizer effect for
*