version
fix: update:修改包名
This commit is contained in:
227
app/src/main/java/com/xwad/os/activity/NoticeActivity.java
Normal file
227
app/src/main/java/com/xwad/os/activity/NoticeActivity.java
Normal file
@@ -0,0 +1,227 @@
|
||||
package com.xwad.os.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.PowerManager;
|
||||
import android.os.Vibrator;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
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.xwad.os.R;
|
||||
import com.xwad.os.alarm.AlarmUtils;
|
||||
import com.xwad.os.base.BaseDataBindingActivity;
|
||||
import com.xwad.os.bean.AlarmClockData;
|
||||
import com.xwad.os.bean.BaseResponse;
|
||||
import com.xwad.os.databinding.ActivityNoticeBinding;
|
||||
import com.xwad.os.network.NetInterfaceManager;
|
||||
import com.xwad.os.utils.FileUtil;
|
||||
import com.xwad.os.utils.ScreenUtils;
|
||||
import com.xwad.os.utils.Utils;
|
||||
import com.xwad.os.utils.WakeUpUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
|
||||
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 BaseDataBindingActivity {
|
||||
private static final String TAG = "NoticeActivity";
|
||||
|
||||
private ActivityNoticeBinding mBinding;
|
||||
|
||||
private AlarmClockData mAlarmClockData;
|
||||
private int code;
|
||||
private MediaPlayer mMediaPlayer;
|
||||
private PowerManager mPowerManager;
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
private AudioManager audioManager;
|
||||
|
||||
private Vibrator mVibrator;
|
||||
|
||||
|
||||
@Override
|
||||
protected void initDataBinding() {
|
||||
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_notice);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
Intent intent = getIntent();
|
||||
code = intent.getIntExtra("id", -1);
|
||||
mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
mWakeLock = mPowerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "WakeAndLock");
|
||||
mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (code == -1) {
|
||||
finish();
|
||||
} else {
|
||||
mWakeLock.acquire(60 * 1000L);
|
||||
long[] pattern = {1000, 5000, 1000, 5000};
|
||||
mVibrator.vibrate(pattern, 0);
|
||||
WakeUpUtils.wakeUpAndUnlockScreen(this);
|
||||
HashMap<Integer, AlarmClockData> oldData = AlarmUtils.getInstance().getOldData();
|
||||
mAlarmClockData = oldData.get(code);
|
||||
if (mAlarmClockData == null) {
|
||||
finish();
|
||||
}
|
||||
Log.e(TAG, "onCreate: " + mAlarmClockData);
|
||||
showData(mAlarmClockData);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
mBinding.tvTitle.setText(alarmClockData.getTitle());
|
||||
mBinding.btOk.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)) {
|
||||
mBinding.clVoice.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 {
|
||||
mMediaPlayer = new MediaPlayer();
|
||||
try {
|
||||
// 切歌之前先重置,释放掉之前的资源
|
||||
mMediaPlayer.reset();
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
mMediaPlayer.setDataSource(fis.getFD());
|
||||
// 设置播放源
|
||||
// mediaPlayer.setDataSource(file.getAbsolutePath());
|
||||
// 开始播放前的准备工作,加载多媒体资源,获取相关信息
|
||||
mMediaPlayer.prepare();
|
||||
// 开始播放
|
||||
mMediaPlayer.start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "showData: " + e.getMessage());
|
||||
}
|
||||
// }
|
||||
} else {
|
||||
mBinding.clVoice.setVisibility(View.GONE);
|
||||
}
|
||||
if (!TextUtils.isEmpty(filePath)) {
|
||||
mBinding.clVp.setVisibility(View.VISIBLE);
|
||||
String fileType = FileUtil.getFileType(filePath);
|
||||
Log.e(TAG, "showData: " + fileType);
|
||||
if (FileUtil.isPictureFile(fileType)) {
|
||||
mBinding.jzVideo.setVisibility(View.GONE);
|
||||
mBinding.ivDictation.setVisibility(View.VISIBLE);
|
||||
RequestOptions options = new RequestOptions().transform(new RoundedCorners(ScreenUtils.dip2px(this, 16F)));
|
||||
Glide.with(NoticeActivity.this).load(filePath).apply(options).into(mBinding.ivDictation);
|
||||
} else if (FileUtil.isVideoFile(fileType)) {
|
||||
mBinding.jzVideo.setVisibility(View.VISIBLE);
|
||||
mBinding.ivDictation.setVisibility(View.GONE);
|
||||
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.length());
|
||||
String realPath = Utils.getDownLoadPath(NoticeActivity.this) + fileName;
|
||||
File file = new File(realPath);
|
||||
JZDataSource jzDataSource;
|
||||
if (!file.exists()) {
|
||||
jzDataSource = new JZDataSource(filePath, "");
|
||||
Log.e(TAG, "showData: not exists");
|
||||
} else {
|
||||
Log.e(TAG, "showData: exists " + file);
|
||||
URI uri = file.toURI();
|
||||
jzDataSource = new JZDataSource(uri.toString(), "");
|
||||
}
|
||||
jzDataSource.looping = true;
|
||||
mBinding.jzVideo.setUp(jzDataSource, Jzvd.SCREEN_NORMAL);
|
||||
mBinding.jzVideo.startPreloading();
|
||||
mBinding.jzVideo.startVideoAfterPreloading();
|
||||
mBinding.jzVideo.startVideo();
|
||||
}
|
||||
} else {
|
||||
mBinding.clVp.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mMediaPlayer != null) {
|
||||
if (mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.stop();
|
||||
}
|
||||
mMediaPlayer.release();
|
||||
mMediaPlayer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (Jzvd.backPress()) {
|
||||
return;
|
||||
}
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
Jzvd.releaseAllVideos();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user