226 lines
8.2 KiB
Java
226 lines
8.2 KiB
Java
package com.uiui.aios.activity;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.media.AudioManager;
|
|
import android.media.MediaPlayer;
|
|
import android.os.Bundle;
|
|
import android.os.PowerManager;
|
|
import android.os.Vibrator;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import com.blankj.utilcode.util.FileUtils;
|
|
import com.bumptech.glide.Glide;
|
|
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
|
import com.bumptech.glide.request.RequestOptions;
|
|
import com.uiui.aios.R;
|
|
import com.uiui.aios.bean.AlarmClockData;
|
|
import com.uiui.aios.bean.BaseResponse;
|
|
import com.uiui.aios.network.NetInterfaceManager;
|
|
import com.uiui.aios.alarm.AlarmUtils;
|
|
import com.uiui.aios.utils.FileUtil;
|
|
import com.uiui.aios.utils.ScreenUtils;
|
|
import com.uiui.aios.utils.Utils;
|
|
import com.uiui.aios.utils.WakeUpUtils;
|
|
import com.uiui.aios.view.JzvdStdAssert;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.ButterKnife;
|
|
import cn.jzvd.JZDataSource;
|
|
import cn.jzvd.Jzvd;
|
|
import io.reactivex.rxjava3.annotations.NonNull;
|
|
import io.reactivex.rxjava3.core.Observer;
|
|
import io.reactivex.rxjava3.disposables.Disposable;
|
|
|
|
public class NoticeActivity extends AppCompatActivity {
|
|
private String TAG = NoticeActivity.class.getSimpleName();
|
|
|
|
@BindView(R.id.tv_title)
|
|
TextView tv_title;
|
|
@BindView(R.id.bt_ok)
|
|
Button bt_ok;
|
|
@BindView(R.id.cl_voice)
|
|
ConstraintLayout cl_voice;
|
|
@BindView(R.id.cl_vp)
|
|
ConstraintLayout cl_vp;
|
|
@BindView(R.id.jz_video)
|
|
JzvdStdAssert jz_video;
|
|
@BindView(R.id.imageView)
|
|
ImageView imageView;
|
|
|
|
private AlarmClockData alarmClockData;
|
|
private int code;
|
|
private MediaPlayer mediaPlayer;
|
|
private PowerManager pm;
|
|
private PowerManager.WakeLock wakeLock;
|
|
private AudioManager audioManager;
|
|
|
|
private Vibrator vibrator;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_notice);
|
|
ButterKnife.bind(this);
|
|
Intent intent = getIntent();
|
|
code = intent.getIntExtra("id", -1);
|
|
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
wakeLock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "WakeAndLock");
|
|
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
|
if (code == -1) {
|
|
finish();
|
|
} else {
|
|
wakeLock.acquire(60 * 1000L);
|
|
long[] pattern = {1000, 5000, 1000, 5000};
|
|
vibrator.vibrate(pattern, 0);
|
|
WakeUpUtils.wakeUpAndUnlockScreen(this);
|
|
HashMap<Integer, AlarmClockData> oldData = AlarmUtils.getInstance().getOldData();
|
|
alarmClockData = oldData.get(code);
|
|
if (alarmClockData == null) {
|
|
finish();
|
|
}
|
|
Log.e(TAG, "onCreate: " + alarmClockData);
|
|
showData(alarmClockData);
|
|
}
|
|
|
|
}
|
|
|
|
private void showData(AlarmClockData alarmClockData) {
|
|
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
|
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
|
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, AudioManager.FLAG_PLAY_SOUND);
|
|
tv_title.setText(alarmClockData.getTitle());
|
|
bt_ok.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
HashMap<Integer, AlarmClockData> oldData = AlarmUtils.getInstance().getOldData();
|
|
AlarmClockData alarm = oldData.get(code);
|
|
if (alarm != null) {
|
|
alarm.setFinished(true);
|
|
AlarmUtils.getInstance().updateAlarmFinished(alarm);
|
|
}
|
|
NetInterfaceManager.getInstance()
|
|
.getUpdateAlarmObservable(alarmClockData.getId())
|
|
.subscribe(new Observer<BaseResponse>() {
|
|
@Override
|
|
public void onSubscribe(@NonNull Disposable d) {
|
|
Log.e("showData", "onSubscribe: ");
|
|
}
|
|
|
|
@Override
|
|
public void onNext(@NonNull BaseResponse baseResponse) {
|
|
Log.e("showData", "onNext: " + baseResponse);
|
|
}
|
|
|
|
@Override
|
|
public void onError(@NonNull Throwable e) {
|
|
Log.e("showData", "onError: " + e.getMessage());
|
|
onComplete();
|
|
}
|
|
|
|
@Override
|
|
public void onComplete() {
|
|
Log.e("showData", "onComplete: ");
|
|
finish();
|
|
}
|
|
});
|
|
|
|
}
|
|
});
|
|
String voiceUrl = alarmClockData.getVoice();
|
|
String voicemd5 = alarmClockData.getVoice_md5();
|
|
String filePath = alarmClockData.getFile();
|
|
|
|
if (!TextUtils.isEmpty(voiceUrl)) {
|
|
cl_voice.setVisibility(View.VISIBLE);
|
|
String fileName = Utils.getFileNamefromURL(voiceUrl);
|
|
File file = new File(Utils.getDownLoadPath(NoticeActivity.this) + fileName);
|
|
String fileMD5 = FileUtils.getFileMD5ToString(file);
|
|
// if (!md5.equals(fileMD5)) {
|
|
// // TODO: 2021/12/16
|
|
// } else {
|
|
mediaPlayer = new MediaPlayer();
|
|
try {
|
|
// 切歌之前先重置,释放掉之前的资源
|
|
mediaPlayer.reset();
|
|
FileInputStream fis = new FileInputStream(file);
|
|
mediaPlayer.setDataSource(fis.getFD());
|
|
// 设置播放源
|
|
// mediaPlayer.setDataSource(file.getAbsolutePath());
|
|
// 开始播放前的准备工作,加载多媒体资源,获取相关信息
|
|
mediaPlayer.prepare();
|
|
// 开始播放
|
|
mediaPlayer.start();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
Log.e(TAG, "showData: " + e.getMessage());
|
|
}
|
|
// }
|
|
} else {
|
|
cl_voice.setVisibility(View.GONE);
|
|
}
|
|
if (!TextUtils.isEmpty(filePath)) {
|
|
cl_vp.setVisibility(View.VISIBLE);
|
|
String fileType = FileUtil.getFileType(filePath);
|
|
Log.e(TAG, "showData: " + fileType);
|
|
if (FileUtil.isPictureFile(fileType)) {
|
|
jz_video.setVisibility(View.GONE);
|
|
imageView.setVisibility(View.VISIBLE);
|
|
RequestOptions options = new RequestOptions().transform(new RoundedCorners(ScreenUtils.dip2px(this, 16F)));
|
|
Glide.with(NoticeActivity.this).load(filePath).apply(options).into(imageView);
|
|
} else if (FileUtil.isVideoFile(fileType)) {
|
|
jz_video.setVisibility(View.VISIBLE);
|
|
imageView.setVisibility(View.GONE);
|
|
JZDataSource jzDataSource = new JZDataSource(filePath, "");
|
|
jzDataSource.looping = true;
|
|
jz_video.setUp(jzDataSource, Jzvd.SCREEN_NORMAL);
|
|
jz_video.startVideo();
|
|
}
|
|
} else {
|
|
cl_vp.setVisibility(View.GONE);
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
if (mediaPlayer != null) {
|
|
if (mediaPlayer.isPlaying()) {
|
|
mediaPlayer.stop();
|
|
}
|
|
mediaPlayer.release();
|
|
mediaPlayer = null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onBackPressed() {
|
|
if (Jzvd.backPress()) {
|
|
return;
|
|
}
|
|
super.onBackPressed();
|
|
}
|
|
|
|
@Override
|
|
protected void onPause() {
|
|
super.onPause();
|
|
Jzvd.releaseAllVideos();
|
|
}
|
|
}
|