Initial commit
This commit is contained in:
97
sources/com/google/zxing/client/android/BeepManager.java
Normal file
97
sources/com/google/zxing/client/android/BeepManager.java
Normal file
@@ -0,0 +1,97 @@
|
||||
package com.google.zxing.client.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class BeepManager implements MediaPlayer.OnErrorListener, Closeable {
|
||||
private static final String e = BeepManager.class.getSimpleName();
|
||||
private final Activity a;
|
||||
private MediaPlayer b = null;
|
||||
private boolean c;
|
||||
private boolean d;
|
||||
|
||||
public BeepManager(Activity activity) {
|
||||
this.a = activity;
|
||||
b();
|
||||
}
|
||||
|
||||
public synchronized void a() {
|
||||
if (this.c && this.b != null) {
|
||||
this.b.start();
|
||||
}
|
||||
if (this.d) {
|
||||
((Vibrator) this.a.getSystemService("vibrator")).vibrate(200L);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void b() {
|
||||
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.a);
|
||||
this.c = a(defaultSharedPreferences, this.a);
|
||||
this.d = defaultSharedPreferences.getBoolean("preferences_vibrate", false);
|
||||
if (this.c && this.b == null) {
|
||||
this.a.setVolumeControlStream(3);
|
||||
this.b = a(this.a);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // java.io.Closeable, java.lang.AutoCloseable
|
||||
public synchronized void close() {
|
||||
if (this.b != null) {
|
||||
this.b.release();
|
||||
this.b = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.media.MediaPlayer.OnErrorListener
|
||||
public synchronized boolean onError(MediaPlayer mediaPlayer, int i, int i2) {
|
||||
if (i == 100) {
|
||||
this.a.finish();
|
||||
} else {
|
||||
close();
|
||||
b();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean a(SharedPreferences sharedPreferences, Context context) {
|
||||
boolean z = sharedPreferences.getBoolean("preferences_play_beep", true);
|
||||
if (!z || ((AudioManager) context.getSystemService("audio")).getRingerMode() == 2) {
|
||||
return z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private MediaPlayer a(Context context) {
|
||||
MediaPlayer mediaPlayer = new MediaPlayer();
|
||||
try {
|
||||
AssetFileDescriptor openRawResourceFd = context.getResources().openRawResourceFd(R$raw.beep);
|
||||
try {
|
||||
mediaPlayer.setDataSource(openRawResourceFd.getFileDescriptor(), openRawResourceFd.getStartOffset(), openRawResourceFd.getLength());
|
||||
mediaPlayer.setOnErrorListener(this);
|
||||
mediaPlayer.setAudioStreamType(3);
|
||||
mediaPlayer.setLooping(false);
|
||||
mediaPlayer.setVolume(0.1f, 0.1f);
|
||||
mediaPlayer.prepare();
|
||||
if (openRawResourceFd != null) {
|
||||
openRawResourceFd.close();
|
||||
}
|
||||
return mediaPlayer;
|
||||
} finally {
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
Log.w(e, e2);
|
||||
mediaPlayer.release();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user