【移动应用开发技术】Android中语音声波控件以及条形波控件怎么用_第1页
【移动应用开发技术】Android中语音声波控件以及条形波控件怎么用_第2页
【移动应用开发技术】Android中语音声波控件以及条形波控件怎么用_第3页
【移动应用开发技术】Android中语音声波控件以及条形波控件怎么用_第4页
【移动应用开发技术】Android中语音声波控件以及条形波控件怎么用_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【移动应用开发技术】Android中语音声波控件以及条形波控件怎么用

SoundWavesView/**

*

语音通话的声波控件

*

Created

by

Mr.LongFace

on

2017/9/16.

*/

public

class

SoundWavesView

extends

View

{

private

int

mMini;

//

最短值

private

int

mMax;

//

最大值

private

int

mLineWidth;

//

每条声波的宽度

private

int

mSoundNum

=

5;

//

声波的数量

private

int

mSpac;

//

每条声波的中点

private

int

mWidth

,

mHeight;

//

控件宽高

private

boolean

isRun

=

false;

private

Paint

mPaint;

private

RectF

mRectF;

private

List<SoundLine>

mSoundList

=

new

ArrayList<>();

private

Handler

mHandler

=

new

Handler();

private

Runnable

mInvalidateRun

=

new

Runnable()

{

@Override

public

void

run()

{

postInvalidate();

}

};

public

SoundWavesView(Context

context,

@Nullable

AttributeSet

attrs)

{

super(context,

attrs);

mPaint

=

new

Paint();

mPaint.setAntiAlias(true);

mPaint.setColor(getResources().getColor(R.color.color_red));

mPaint.setStyle(Paint.Style.FILL);

mRectF

=

new

RectF();

}

@Override

protected

void

onMeasure(int

widthMeasureSpec,

int

heightMeasureSpec)

{

super.onMeasure(widthMeasureSpec,

heightMeasureSpec);

if

(widthMeasureSpec

>

0

&&

heightMeasureSpec

>

0)

{

initParam();

}

}

private

void

initParam()

{

mWidth

=

getWidth();

mHeight

=

getHeight();

mMini

=

(int)

(mHeight

*

0.3f);

mMax

=

mHeight;

initLines();

}

@Override

protected

void

onDraw(Canvas

canvas)

{

super.onDraw(canvas);

for

(int

i

=

0;

i

<

mSoundNum;

i++)

{

SoundLine

sound

=

mSoundList.get(i);

mRectF.left

=

sound.left;

mRectF.right

=

sound.right;

mRectF.top

=

sound.top;

mRectF.bottom

=

sound.bottom;

canvas.drawRoundRect(mRectF

,

mLineWidth

/

2

,

mLineWidth

/

2

,

mPaint);

}

if

(isRun)

{

mHandler.postDelayed(mInvalidateRun,

10);

}

}

@Override

protected

void

onVisibilityChanged(@NonNull

View

changedView,

int

visibility)

{

super.onVisibilityChanged(changedView,

visibility);

if

(isRun)

{

if

(visibility

==

VISIBLE)

{

if

(mWidth

==

0)

{

initParam();

}

if

(mSoundList

!=

null

&&

mSoundList.size()

>

0)

{

for

(SoundLine

soundLine

:

mSoundList)

{

soundLine.start();

}

}

}else{

if

(mSoundList

!=

null

&&

mSoundList.size()

>

0)

{

for

(SoundLine

soundLine

:

mSoundList)

{

soundLine.stop();

}

}

}

}

}

public

void

start()

{

if

(!isRun)

{

isRun

=

true;

for

(SoundLine

sound

:

mSoundList)

{

sound.start();

}

postInvalidate();

}

}

public

void

stop(){

if

(isRun)

{

isRun

=

false;

for

(SoundLine

sound

:

mSoundList)

{

sound.stop();

}

}

}

private

void

initLines()

{

mLineWidth

=

(int)

(mWidth

/

mSoundNum

*

0.7f);

mSpac

=

mWidth

/

(mSoundNum

-

1);

mSoundList.clear();

chaos();

}

/**

*

生成凌乱的

*/

private

void

chaos()

{

for

(int

i

=

0;

i

<

mSoundNum;

i++)

{

int

left

=

i

*

mSpac

-

mLineWidth

/

2;

int

right

=

i

*

mSpac

+

mLineWidth

/

2;

SoundLine

s

=

new

SoundLine(left

,

right

,

0

,

mHeight);

s.setMode(SoundLine.SPEED_RAN);

s.setBorder(mMini

,

mMax);

mSoundList.add(s);

}

}

/**

*

生成波浪的

*/

private

void

wave(){

//

TODO

防止UI抽风

}

/**

*

生成有序的

*/

private

void

order(){

//

TODO

防止UI抽风

}

}SoundLine/**

*

语音音频波纹的单个音波属性

*

Created

by

Mr.LongFace

on

2017/9/16.

*/

public

class

SoundLine

implements

ValueAnimator.AnimatorUpdateListener{

//

随机

4挡

public

static

final

int

SPEED_LOW

=

500;

public

static

final

int

SPEED_MID

=

200;

public

static

final

int

SPEED_HEI

=

0;

public

static

final

int

SPEED_RAN

=

0;

private

Random

mRandom;

private

ValueAnimator

mAnim;

public

int

left

,

right

,

top

,

bottom;

private

int

min

,

max;

public

SoundLine(int

left

,

int

right

,

int

top

,

int

bottom){

this.left

=

left;

this.right

=

right;

this.top

=

top;

this.bottom

=

bottom;

mRandom

=

new

Random();

initAnim();

}

private

void

initAnim()

{

mAnim

=

ValueAnimator.ofFloat(0.0f

,

1.0f);

setMode(SPEED_MID);

mAnim.setRepeatCount(-1);

mAnim.setRepeatMode(ValueAnimator.REVERSE);

mAnim.addUpdateListener(this);

}

public

void

setMode(int

mode){

if

(mode

==

SPEED_RAN)

{

mode

=

mRandom.nextInt(400);

}

mAnim.setDuration(300

+

mode);

}

public

void

start(){

if

(mAnim.isRunning()){

mAnim.end();

}

mAnim.start();

}

@Override

public

void

onAnimationUpdate(ValueAnimator

valueAnimator)

{

float

f

=

(float)

valueAnimator

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论