翰林优商.apk(点击下载) / XlxVoiceCustomVoiceImage.java
package com.xlx.speech.voicereadsdk.ui.widget;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.TypedArray;
import android.media.AudioManager;
import android.media.AudioRecordingConfiguration;
import android.media.MediaPlayer;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.xlx.speech.m0.j;
import com.xlx.speech.m0.w;
import com.xlx.speech.voicereadsdk.R;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class XlxVoiceCustomVoiceImage extends FrameLayout {
public ImageView a;
public ImageView b;
public ImageView c;
public ImageView d;
public RippleView e;
public FrameLayout f;
public boolean g;
public Context h;
public List<b> i;
public boolean j;
public boolean k;
public b l;
public class a implements View.OnTouchListener {
public a() {
}
public boolean onTouch(View view, MotionEvent motionEvent) {
boolean z;
ImageView imageView;
XlxVoiceCustomVoiceImage xlxVoiceCustomVoiceImage;
b bVar;
int action = motionEvent.getAction();
int i = 0;
if (action != 0) {
if (action == 1 || action == 3) {
XlxVoiceCustomVoiceImage xlxVoiceCustomVoiceImage2 = XlxVoiceCustomVoiceImage.this;
if (xlxVoiceCustomVoiceImage2.l != null && xlxVoiceCustomVoiceImage2.g) {
Log.i("MyLogger", "stopRecord");
XlxVoiceCustomVoiceImage.this.d();
}
XlxVoiceCustomVoiceImage.this.requestDisallowInterceptTouchEvent(false);
}
} else if (w.a("android.permission.RECORD_AUDIO") || (bVar = (xlxVoiceCustomVoiceImage = XlxVoiceCustomVoiceImage.this).l) == null || xlxVoiceCustomVoiceImage.k) {
XlxVoiceCustomVoiceImage xlxVoiceCustomVoiceImage3 = XlxVoiceCustomVoiceImage.this;
if (xlxVoiceCustomVoiceImage3.l != null) {
Context context = xlxVoiceCustomVoiceImage3.getContext();
if (Build.VERSION.SDK_INT >= 24) {
Iterator<AudioRecordingConfiguration> it = ((AudioManager) context.getSystemService("audio")).getActiveRecordingConfigurations().iterator();
while (true) {
if (it.hasNext()) {
if (it.next().getClientAudioSource() == 1) {
z = true;
break;
}
} else {
break;
}
}
}
z = false;
Log.e("MyLogger", z ? "麦克风被占用" : "麦克风未被占用");
xlxVoiceCustomVoiceImage3.l.a();
for (b bVar2 : xlxVoiceCustomVoiceImage3.i) {
bVar2.a();
}
xlxVoiceCustomVoiceImage3.g = true;
xlxVoiceCustomVoiceImage3.e.d = false;
if (!xlxVoiceCustomVoiceImage3.k) {
MediaPlayer mediaPlayer = new MediaPlayer();
try {
AssetFileDescriptor openFd = xlxVoiceCustomVoiceImage3.getResources().getAssets().openFd("start_record_voice.mp3");
mediaPlayer.setDataSource(openFd.getFileDescriptor(), openFd.getStartOffset(), openFd.getLength());
mediaPlayer.prepare();
mediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
}
if (!xlxVoiceCustomVoiceImage3.k) {
imageView = xlxVoiceCustomVoiceImage3.d;
} else {
imageView = xlxVoiceCustomVoiceImage3.d;
i = 4;
}
imageView.setVisibility(i);
j.a().loadGifImage(xlxVoiceCustomVoiceImage3.h, R.drawable.xlx_voice_detail_voice_decoration_animation_dialog, xlxVoiceCustomVoiceImage3.d);
}
XlxVoiceCustomVoiceImage.this.requestDisallowInterceptTouchEvent(true);
} else {
bVar.c();
for (b bVar3 : XlxVoiceCustomVoiceImage.this.i) {
bVar3.c();
}
}
return true;
}
}
public interface b {
void a();
void b();
void c();
void d();
}
public XlxVoiceCustomVoiceImage(Context context) {
this(context, null);
}
public XlxVoiceCustomVoiceImage(Context context, AttributeSet attributeSet) {
this(context, attributeSet, 0);
}
public XlxVoiceCustomVoiceImage(Context context, AttributeSet attributeSet, int i2) {
super(context, attributeSet, i2);
this.i = new ArrayList();
this.j = false;
this.k = false;
this.h = context;
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.XlxVoiceCustomVoiceImage);
this.j = obtainStyledAttributes.getBoolean(R.styleable.XlxVoiceCustomVoiceImage_xlx_voice_big_view, this.j);
this.k = obtainStyledAttributes.getBoolean(R.styleable.XlxVoiceCustomVoiceImage_xlx_voice_open_package_model, this.k);
obtainStyledAttributes.recycle();
a(context);
}
public void a() {
setEnabled(true);
c();
}
public final void a(Context context) {
ImageView imageView;
int i2;
View inflate = LayoutInflater.from(context).inflate(this.j ? R.layout.xlx_voice_weight_big_voice_btn_layout : R.layout.xlx_voice_weight_voice_btn_layout, (ViewGroup) this, false);
this.a = (ImageView) inflate.findViewById(R.id.xlx_voice_detail_voice_btn_animation);
this.d = (ImageView) inflate.findViewById(R.id.xlx_voice_detail_voice_decoration_animation);
this.f = (FrameLayout) inflate.findViewById(R.id.xlx_voice_detail_voice_btn_layout);
this.e = (RippleView) inflate.findViewById(R.id.xlx_voice_detail_voice_ripple);
this.b = (ImageView) inflate.findViewById(R.id.xlx_voice_detail_voice_btn);
this.c = (ImageView) inflate.findViewById(R.id.xlx_voice_iv_voice_parse);
addView(inflate);
this.i.clear();
this.b.setClickable(true);
if (this.k) {
imageView = this.b;
i2 = R.drawable.xlx_voice_voice_open_package;
} else {
imageView = this.b;
i2 = R.drawable.xlx_voice_voice_read;
}
imageView.setImageResource(i2);
this.b.setOnTouchListener(new a());
}
public void b() {
c();
this.b.setImageResource(R.drawable.xlx_voice_voice_read_complete);
}
public void c() {
b bVar = this.l;
if (bVar != null) {
bVar.b();
}
for (b bVar2 : this.i) {
bVar2.b();
}
this.g = false;
this.a.setVisibility(8);
this.c.setVisibility(4);
this.d.setVisibility(8);
RippleView rippleView = this.e;
rippleView.d = true;
rippleView.invalidate();
}
public void d() {
this.d.setVisibility(4);
this.g = false;
this.a.setVisibility(4);
this.c.setVisibility(0);
j.a().loadGifImage(this.h, R.drawable.xlx_voice_detail_voice_btn_image_animation_dialog, this.c);
b bVar = this.l;
if (bVar != null) {
bVar.d();
}
for (b bVar2 : this.i) {
bVar2.d();
}
setEnabled(false);
}
public View getVoiceImageLayout() {
return this.f;
}
public void setEnabled(boolean z) {
super.setEnabled(z);
this.b.setEnabled(z);
}
public void setOpenPackageModel(boolean z) {
this.k = z;
}
public void setRecordListener(b bVar) {
this.l = bVar;
}
}