version:3.5
fix: update:优化退出,增加闹钟
This commit is contained in:
@@ -32,9 +32,12 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.wifi.WiFiManagerActivity;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
import com.uiuios.aios.utils.BrightnessUtils;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.view.RulerSeekBar;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -51,7 +54,7 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class ControlActivity extends AppCompatActivity {
|
||||
public class ControlActivity extends BaseActivity {
|
||||
private static final String TAG = ControlActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.iv_back)
|
||||
@@ -120,15 +123,14 @@ public class ControlActivity extends AppCompatActivity {
|
||||
"com.android.settings.flashlight.action.FLASHLIGHT_CHANGED";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_control);
|
||||
ButterKnife.bind(this);
|
||||
crv = getContentResolver();
|
||||
initView();
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_control;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
crv = getContentResolver();
|
||||
getWifi();
|
||||
registerReceivers();
|
||||
getBluetooth();
|
||||
@@ -140,13 +142,30 @@ public class ControlActivity extends AppCompatActivity {
|
||||
getLocation();
|
||||
getBrightness();
|
||||
getSound();
|
||||
cl_flashlight.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
try {
|
||||
startActivity(new Intent(Settings.ACTION_SETTINGS));
|
||||
} catch (Exception e) {
|
||||
ToastUtil.show("打开失败");
|
||||
Log.e(TAG, "onClick: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
private void getWifi() {
|
||||
cl_wifi.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));
|
||||
// startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
|
||||
startActivity(new Intent(ControlActivity.this, WiFiManagerActivity.class));
|
||||
}
|
||||
});
|
||||
if (isWifiEnabled()) {
|
||||
@@ -605,13 +624,13 @@ public class ControlActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void updateTimeUi() {
|
||||
long time = System.currentTimeMillis();
|
||||
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
|
||||
String timeText = timeFormat.format(time);
|
||||
tv_flashlight.setText(timeText);
|
||||
SimpleDateFormat format = new SimpleDateFormat("MM月dd日");
|
||||
String dataText = format.format(time);
|
||||
tv_flashlight_switch.setText(dataText);
|
||||
// long time = System.currentTimeMillis();
|
||||
// SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
|
||||
// String timeText = timeFormat.format(time);
|
||||
// tv_flashlight.setText(timeText);
|
||||
// SimpleDateFormat format = new SimpleDateFormat("MM月dd日");
|
||||
// String dataText = format.format(time);
|
||||
// tv_flashlight_switch.setText(dataText);
|
||||
}
|
||||
|
||||
private void getFlashlight() {
|
||||
@@ -728,8 +747,8 @@ public class ControlActivity extends AppCompatActivity {
|
||||
private void getLocation() {
|
||||
String addr = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE).decodeString(CommonConfig.MAP_ADDRESS_KEY);
|
||||
|
||||
if (TextUtils.isEmpty(addr)) {
|
||||
tv_location.setText("未知");
|
||||
if (TextUtils.isEmpty(addr) || "nullnull".equals(addr) || "null".equals(addr)) {
|
||||
tv_location.setText("未能获取到位置信息");
|
||||
} else {
|
||||
tv_location.setText(addr);
|
||||
}
|
||||
|
||||
@@ -7,232 +7,84 @@ 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 androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
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.uiuios.aios.R;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.FileUtil;
|
||||
import com.uiuios.aios.utils.ScreenUtils;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
import com.uiuios.aios.utils.WakeUpUtils;
|
||||
import com.uiuios.aios.view.JzvdStdAssert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
|
||||
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.iv_cover)
|
||||
ImageView imageView;
|
||||
@BindView(R.id.positive)
|
||||
TextView positive;
|
||||
|
||||
private AlarmClockData alarmClockData;
|
||||
private int code;
|
||||
private MediaPlayer mediaPlayer;
|
||||
private PowerManager pm;
|
||||
private PowerManager.WakeLock wakeLock;
|
||||
private AudioManager audioManager;
|
||||
private int mId;
|
||||
private MediaPlayer mMediaPlayer;
|
||||
private PowerManager mPowerManager;
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
private Vibrator vibrator;
|
||||
private Vibrator mVibrator;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_notice);
|
||||
Log.e(TAG, "onCreate: " );
|
||||
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) {
|
||||
mId = 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);
|
||||
mWakeLock.acquire(60 * 1000L);
|
||||
long[] pattern = {1000, 5000, 1000, 5000};
|
||||
mVibrator.vibrate(pattern, 0);
|
||||
WakeUpUtils.wakeUpAndUnlockScreen(this);
|
||||
|
||||
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, AudioManager.FLAG_PLAY_SOUND);
|
||||
|
||||
mMediaPlayer = MediaPlayer.create(this, R.raw.ni);
|
||||
// 开始播放
|
||||
mMediaPlayer.start();
|
||||
|
||||
positive.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent noticeIntent = new Intent(NoticeActivity.this, NoticeInfoActivity.class);
|
||||
noticeIntent.putExtra("id", mId);
|
||||
startActivity(noticeIntent);
|
||||
|
||||
finish();
|
||||
}
|
||||
Log.e(TAG, "onCreate: " + alarmClockData);
|
||||
jz_video.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showData(alarmClockData);
|
||||
}
|
||||
},1234);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void showData(AlarmClockData alarmClockData) {
|
||||
Log.e(TAG, "showData: " );
|
||||
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);
|
||||
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;
|
||||
jz_video.setUp(jzDataSource, Jzvd.SCREEN_NORMAL);
|
||||
jz_video.startPreloading();
|
||||
jz_video.startVideoAfterPreloading();
|
||||
jz_video.startVideo();
|
||||
|
||||
}
|
||||
} else {
|
||||
cl_vp.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Log.e(TAG, "onDestroy: " );
|
||||
super.onDestroy();
|
||||
if (mediaPlayer != null) {
|
||||
if (mediaPlayer.isPlaying()) {
|
||||
mediaPlayer.stop();
|
||||
if (mMediaPlayer != null) {
|
||||
if (mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.stop();
|
||||
}
|
||||
mediaPlayer.release();
|
||||
mediaPlayer = null;
|
||||
mMediaPlayer.release();
|
||||
mMediaPlayer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
Log.e(TAG, "onDestroy: " );
|
||||
if (Jzvd.backPress()) {
|
||||
return;
|
||||
}
|
||||
@@ -240,9 +92,7 @@ public class NoticeActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
Log.e(TAG, "onDestroy: " );
|
||||
super.onStop();
|
||||
Jzvd.releaseAllVideos();
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
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 androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
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.uiuios.aios.R;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.FileUtil;
|
||||
import com.uiuios.aios.utils.ScreenUtils;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
import com.uiuios.aios.utils.WakeUpUtils;
|
||||
import com.uiuios.aios.view.JzvdStdAssert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
|
||||
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 NoticeInfoActivity extends AppCompatActivity {
|
||||
private String TAG = NoticeInfoActivity.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 mAlarmClockData;
|
||||
private int mId;
|
||||
private MediaPlayer mMediaPlayer;
|
||||
private PowerManager mPowerManager;
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
private Vibrator mVibrator;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_notice_info);
|
||||
ButterKnife.bind(this);
|
||||
Intent intent = getIntent();
|
||||
mId = 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);
|
||||
|
||||
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, AudioManager.FLAG_PLAY_SOUND);
|
||||
|
||||
mMediaPlayer = new MediaPlayer();
|
||||
|
||||
if (mId == -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().getOldDataMap();
|
||||
mAlarmClockData = oldData.get(mId);
|
||||
if (mAlarmClockData == null) {
|
||||
finish();
|
||||
}
|
||||
Log.e(TAG, "onCreate: " + mAlarmClockData);
|
||||
showPic(mAlarmClockData);
|
||||
jz_video.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showData(mAlarmClockData);
|
||||
}
|
||||
}, 123);
|
||||
}
|
||||
}
|
||||
|
||||
private void showPic(AlarmClockData alarmClockData) {
|
||||
tv_title.setText(alarmClockData.getTitle());
|
||||
bt_ok.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
HashMap<Integer, AlarmClockData> oldData = AlarmUtils.getInstance().getOldDataMap();
|
||||
AlarmClockData alarm = oldData.get(mId);
|
||||
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();
|
||||
if (!TextUtils.isEmpty(voiceUrl)) {
|
||||
cl_voice.setVisibility(View.VISIBLE);
|
||||
String fileName = Utils.getFileNamefromURL(voiceUrl);
|
||||
File file = new File(Utils.getDownLoadPath(NoticeInfoActivity.this) + fileName);
|
||||
String fileMD5 = FileUtils.getFileMD5ToString(file);
|
||||
// if (!md5.equals(fileMD5)) {
|
||||
// // TODO: 2021/12/16
|
||||
// } else {
|
||||
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 {
|
||||
cl_voice.setVisibility(View.GONE);
|
||||
}
|
||||
String filePath = alarmClockData.getFile();
|
||||
RequestOptions options = new RequestOptions().transform(new RoundedCorners(ScreenUtils.dip2px(this, 16F)));
|
||||
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.length());
|
||||
String realPath = Utils.getDownLoadPath(NoticeInfoActivity.this) + fileName;
|
||||
File file = new File(realPath);
|
||||
if (file.exists()){
|
||||
Glide.with(NoticeInfoActivity.this).load(file).apply(options).error(R.drawable.icon_nodata).into(imageView);
|
||||
}else {
|
||||
Glide.with(NoticeInfoActivity.this).load(filePath).apply(options).error(R.drawable.icon_nodata).into(imageView);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void showData(AlarmClockData alarmClockData) {
|
||||
String filePath = alarmClockData.getFile();
|
||||
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)));
|
||||
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.length());
|
||||
String realPath = Utils.getDownLoadPath(NoticeInfoActivity.this) + fileName;
|
||||
File file = new File(realPath);
|
||||
if (file.exists()){
|
||||
Glide.with(NoticeInfoActivity.this).load(file).apply(options).error(R.drawable.icon_nodata).into(imageView);
|
||||
}else {
|
||||
Glide.with(NoticeInfoActivity.this).load(filePath).apply(options).error(R.drawable.icon_nodata).into(imageView);
|
||||
}
|
||||
} else if (FileUtil.isVideoFile(fileType)) {
|
||||
jz_video.setVisibility(View.VISIBLE);
|
||||
imageView.setVisibility(View.GONE);
|
||||
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.length());
|
||||
String realPath = Utils.getDownLoadPath(NoticeInfoActivity.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;
|
||||
jz_video.setUp(jzDataSource, Jzvd.SCREEN_NORMAL);
|
||||
jz_video.startPreloading();
|
||||
jz_video.startVideoAfterPreloading();
|
||||
jz_video.startVideo();
|
||||
}
|
||||
} else {
|
||||
cl_vp.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();
|
||||
}
|
||||
}
|
||||
@@ -8,31 +8,48 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.AlarmAdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmAdapter;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.base.BaseLightLifecycleActivity;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.dialog.DeleteDialog;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.push.PushManager;
|
||||
import com.uiuios.aios.push.tpush.MessageReceiver;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import cn.jzvd.Jzvd;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
public class AlarmClockActivity extends BaseActivity implements AlarmClockContact.ClockView {
|
||||
public class AlarmClockActivity extends BaseLightLifecycleActivity implements AlarmClockContact.ClockView {
|
||||
private static final String TAG = AlarmClockActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.rv_goods)
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
|
||||
@BindView(R.id.swipeRefreshLayout)
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
@BindView(R.id.fab)
|
||||
FloatingActionButton fab;
|
||||
@BindView(R.id.cl_nodata)
|
||||
ConstraintLayout cl_nodata;
|
||||
|
||||
private AlarmClockPresenter mPresenter;
|
||||
private AlarmAdapter mAlarmAdapter;
|
||||
@@ -44,12 +61,22 @@ public class AlarmClockActivity extends BaseActivity implements AlarmClockContac
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
UltimateBarX.statusBarOnly(this)
|
||||
.colorRes(R.color.default_blue)
|
||||
.fitWindow(true)
|
||||
.apply();
|
||||
ButterKnife.bind(this);
|
||||
mPresenter = new AlarmClockPresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
|
||||
mAlarmAdapter = new AlarmAdapter();
|
||||
mAlarmAdapter.setOnLongClickListener(new AlarmAdapter.OnLongClickListener() {
|
||||
@Override
|
||||
public void onLongClick(AlarmClockData alarmClockData) {
|
||||
showDialog(alarmClockData);
|
||||
}
|
||||
});
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(AlarmClockActivity.this));
|
||||
recyclerView.setAdapter(mAlarmAdapter);
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -58,27 +85,106 @@ public class AlarmClockActivity extends BaseActivity implements AlarmClockContac
|
||||
finish();
|
||||
}
|
||||
});
|
||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
mPresenter.getAlarmClock();
|
||||
}
|
||||
});
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(AlarmClockActivity.this, AlarmClockAddActivity.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showDialog(AlarmClockData alarmClockData) {
|
||||
DeleteDialog dialog = new DeleteDialog(this);
|
||||
dialog.setTitle("提醒")
|
||||
.setMessage("是否要删除本次闹钟")
|
||||
.setPositive("确定")
|
||||
.setNegtive("取消")
|
||||
.setOnClickBottomListener(new DeleteDialog.OnClickBottomListener() {
|
||||
@Override
|
||||
public void onPositiveClick() {
|
||||
deleteAlarm(alarmClockData);
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegtiveClick() {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void deleteAlarm(AlarmClockData alarmClockData) {
|
||||
if (alarmClockData.isIs_local()) {
|
||||
alarmClockData.setDeleted(true);
|
||||
AlarmUtils.getInstance().deleteAlarmClock(alarmClockData);
|
||||
} else {
|
||||
NetInterfaceManager.getInstance().deleteAlarmClockObservable(alarmClockData.getId())
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("deleteAlarm", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("deleteAlarm", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
AlarmUtils.getInstance().deleteAlarmClock(alarmClockData);
|
||||
ToastUtil.show("删除成功");
|
||||
} else {
|
||||
ToastUtil.show("删除失败:" + baseResponse.msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("deleteAlarm", "onError: " + e.getMessage());
|
||||
alarmClockData.setDeleted(true);
|
||||
AlarmUtils.getInstance().updateAlarmClock(alarmClockData);
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("deleteAlarm", "onComplete: ");
|
||||
mPresenter.getAlarmClock();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
registerAlarmClockReceiver();
|
||||
mPresenter.getAlarmClock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showAlarmClock(List<AlarmClockData> alarmClockData) {
|
||||
mAlarmAdapter.setAlarmClockData(alarmClockData);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
cl_nodata.setVisibility(View.GONE);
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmClockEmpty() {
|
||||
mAlarmAdapter.setAlarmClockData(null);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
cl_nodata.setVisibility(View.VISIBLE);
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
ToastUtil.show("服务器连接失败,检查网络连接");
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,6 +196,12 @@ public class AlarmClockActivity extends BaseActivity implements AlarmClockContac
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mPresenter.getAlarmClock();
|
||||
}
|
||||
|
||||
private void registerAlarmClockReceiver() {
|
||||
if (null == mAlarmClockReceiver) {
|
||||
mAlarmClockReceiver = new AlarmClockReceiver();
|
||||
|
||||
@@ -0,0 +1,495 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.bigkoo.pickerview.builder.TimePickerBuilder;
|
||||
import com.bigkoo.pickerview.listener.CustomListener;
|
||||
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
|
||||
import com.bigkoo.pickerview.view.TimePickerView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.luck.picture.lib.basic.PictureSelector;
|
||||
import com.luck.picture.lib.config.SelectMimeType;
|
||||
import com.luck.picture.lib.entity.LocalMedia;
|
||||
import com.luck.picture.lib.interfaces.OnResultCallbackListener;
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.base.GlideEngine;
|
||||
import com.uiuios.aios.bean.AlarmClockId;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.FFmpegUtils;
|
||||
import com.uiuios.aios.utils.FileUtil;
|
||||
import com.uiuios.aios.utils.ScreenUtil;
|
||||
import com.uiuios.aios.utils.TimeUtils;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.base.BaseLifecycleActivity;
|
||||
import com.uiuios.aios.base.GlideEngine;
|
||||
import com.uiuios.aios.bean.AlarmClockId;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.FileUtil;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
import com.xiasuhuei321.loadingdialog.view.LoadingDialog;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
private static final String TAG = AlarmClockAddActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.cl_content)
|
||||
ConstraintLayout cl_content;
|
||||
@BindView(R.id.ll_type)
|
||||
LinearLayout ll_type;
|
||||
@BindView(R.id.cl_type)
|
||||
ConstraintLayout cl_type;
|
||||
@BindView(R.id.tv_type)
|
||||
TextView tv_type;
|
||||
@BindView(R.id.cl_pic)
|
||||
ConstraintLayout cl_pic;
|
||||
@BindView(R.id.et_activation)
|
||||
EditText et_activation;
|
||||
@BindView(R.id.nv_pic)
|
||||
NiceImageView nv_pic;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
@BindView(R.id.bt_confirm)
|
||||
Button bt_confirm;
|
||||
@BindView(R.id.bt_cancel)
|
||||
Button bt_cancel;
|
||||
@BindView(R.id.tv_duration)
|
||||
TextView tv_duration;
|
||||
|
||||
@BindView(R.id.rb1)
|
||||
RadioButton rb1;
|
||||
@BindView(R.id.rb2)
|
||||
RadioButton rb2;
|
||||
@BindView(R.id.rb3)
|
||||
RadioButton rb3;
|
||||
@BindView(R.id.rb4)
|
||||
RadioButton rb4;
|
||||
|
||||
private PopupWindow mPopupWindow;
|
||||
|
||||
private TimePickerView pvTime;
|
||||
private String mPictrueFilePath;
|
||||
private Date mDate;
|
||||
/*类型 1一次性 2每天 3周一到周五 4周六周日*/
|
||||
private int mType = 1;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_add_alarm_clock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
UltimateBarX.statusBarOnly(this)
|
||||
.colorRes(R.color.default_blue)
|
||||
.fitWindow(true)
|
||||
.apply();
|
||||
|
||||
ButterKnife.bind(this);
|
||||
initTimePicker();
|
||||
|
||||
|
||||
rb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb1.setTextColor(colorStateList);
|
||||
mType = 1;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb1.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
rb2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb2.setTextColor(colorStateList);
|
||||
mType = 2;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb2.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
rb3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb3.setTextColor(colorStateList);
|
||||
mType = 3;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb3.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
rb4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb4.setTextColor(colorStateList);
|
||||
mType = 4;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb4.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rb1.setChecked(true);
|
||||
|
||||
cl_pic.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
openSelector();
|
||||
}
|
||||
});
|
||||
cl_type.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// showTimeFilterWindow();
|
||||
}
|
||||
});
|
||||
nv_pic.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
openSelector();
|
||||
}
|
||||
});
|
||||
bt_confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkContent();
|
||||
}
|
||||
});
|
||||
bt_cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
private void showTimeFilterWindow() {
|
||||
if (mPopupWindow == null) {
|
||||
View view = getLayoutInflater().inflate(R.layout.window_menu, null);
|
||||
TextView tvMenuOne = view.findViewById(R.id.tv_menuOne);
|
||||
TextView tvMenuTwo = view.findViewById(R.id.tv_menuTwo);
|
||||
TextView tvMenuThree = view.findViewById(R.id.tv_menuThree);
|
||||
TextView tvMenuFour = view.findViewById(R.id.tv_menuFour);
|
||||
mPopupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
|
||||
mPopupWindow.setOutsideTouchable(true);
|
||||
tvMenuOne.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 1;
|
||||
tv_type.setText("只响一次");
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
tvMenuTwo.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 2;
|
||||
tv_type.setText("每天");
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
tvMenuThree.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 3;
|
||||
tv_type.setText("周一至周五");
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
tvMenuFour.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 4;
|
||||
tv_type.setText("周六至周日");
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (mPopupWindow.isShowing()) {
|
||||
mPopupWindow.dismiss();
|
||||
} else {
|
||||
Log.e(TAG, "showTimeFilterWindow: right " + tv_type.getRight());
|
||||
Log.e(TAG, "showTimeFilterWindow: top " + tv_type.getTop());
|
||||
Log.e(TAG, "showTimeFilterWindow: right " + cl_type.getRight());
|
||||
Log.e(TAG, "showTimeFilterWindow: top " + cl_type.getTop());
|
||||
mPopupWindow.showAtLocation(cl_type, Gravity.END, 20, 0);
|
||||
}
|
||||
}
|
||||
|
||||
LoadingDialog mLoadingDialog;
|
||||
|
||||
private void checkContent() {
|
||||
|
||||
pvTime.returnData();
|
||||
if (TextUtils.isEmpty(et_activation.getText())) {
|
||||
ToastUtil.show("请输入标题");
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(mPictrueFilePath)) {
|
||||
ToastUtil.show("请选择图片");
|
||||
return;
|
||||
}
|
||||
String timeStamp = getTime(mDate);
|
||||
Log.e(TAG, "checkContent: " + timeStamp);
|
||||
Log.e(TAG, "checkContent: " + mPictrueFilePath);
|
||||
// Uri uri = Uri.parse(pictrueFilePath);
|
||||
// File picFile = FileUtil.uriToFile(uri, AlarmClockAddActivity.this);
|
||||
File picFile = new File(mPictrueFilePath);
|
||||
MediaType mediaType = MediaType.Companion.parse("image/png");
|
||||
RequestBody requestBody = RequestBody.Companion.create(picFile, mediaType);
|
||||
MultipartBody.Part body = MultipartBody.Part.createFormData("file", picFile.getName(), requestBody);
|
||||
AlarmClockData alarmClockData = new AlarmClockData();
|
||||
alarmClockData.setFile(mPictrueFilePath);
|
||||
alarmClockData.setType(mType);
|
||||
alarmClockData.setTime(timeStamp);
|
||||
alarmClockData.setTitle(et_activation.getText().toString());
|
||||
alarmClockData.setRemind_type(0);
|
||||
alarmClockData.setIs_onoff(1);
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("sn", Utils.getSerial());
|
||||
params.put("time", timeStamp);
|
||||
params.put("type", String.valueOf(mType));
|
||||
params.put("title", et_activation.getText().toString());
|
||||
params.put("remind_type", "0");
|
||||
params.put("is_onoff", "1");
|
||||
|
||||
mLoadingDialog = new LoadingDialog(this);
|
||||
mLoadingDialog.setLoadingText("正在上传")
|
||||
.setSuccessText("添加成功")
|
||||
.setFailedText("添加失败")
|
||||
.setInterceptBack(true)
|
||||
.setLoadSpeed(LoadingDialog.Speed.SPEED_ONE)
|
||||
.closeSuccessAnim()
|
||||
.show();
|
||||
|
||||
NetInterfaceManager.getInstance().getAlarmClockAddObservable(params, body)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<AlarmClockId>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("checkContent", "onSubscribe: ");
|
||||
bt_confirm.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<AlarmClockId> baseResponse) {
|
||||
Log.e("checkContent", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
ToastUtil.show("添加成功");
|
||||
// int id = baseResponse.data.getId();
|
||||
// alarmClockData.setId(id);
|
||||
// AlarmUtils.getInstance().addAlarmClock(alarmClockData);
|
||||
mLoadingDialog.loadSuccess();
|
||||
mLoadingDialog.close();
|
||||
finish();
|
||||
} else {
|
||||
ToastUtil.show("添加失败:" + baseResponse.msg);
|
||||
bt_confirm.setEnabled(true);
|
||||
mLoadingDialog.loadFailed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("checkContent", "onError: " + e.getMessage());
|
||||
ToastUtil.show("已保存到本地");
|
||||
ToastUtil.show("添加成功");
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
int fakeId = random.nextInt(Integer.MAX_VALUE);
|
||||
Log.e(TAG, "onError: fakeId = " + fakeId);
|
||||
alarmClockData.setId(fakeId);
|
||||
alarmClockData.setIs_local(true);
|
||||
Log.e(TAG, "onError: addAlarmClock = " + AlarmUtils.getInstance().addAlarmClock(alarmClockData));
|
||||
|
||||
onComplete();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("checkContent", "onComplete: ");
|
||||
mLoadingDialog.close();
|
||||
bt_confirm.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void openSelector() {
|
||||
PictureSelector.create(AlarmClockAddActivity.this)
|
||||
.openGallery(SelectMimeType.ofAll())
|
||||
.setSelectionMode(1)
|
||||
.setImageEngine(GlideEngine.createGlideEngine())
|
||||
.forResult(new OnResultCallbackListener<LocalMedia>() {
|
||||
@Override
|
||||
public void onResult(ArrayList<LocalMedia> result) {
|
||||
mPictrueFilePath = result.get(0).getRealPath();
|
||||
File file = new File(mPictrueFilePath);
|
||||
if (file.exists()) {
|
||||
RequestOptions options = new RequestOptions().transform(new RoundedCorners(ScreenUtil.dip2px(AlarmClockAddActivity.this, 8F)));
|
||||
Glide.with(nv_pic).load(file).apply(options).into(nv_pic);
|
||||
nv_pic.setVisibility(View.VISIBLE);
|
||||
cl_pic.setVisibility(View.GONE);
|
||||
if (FileUtil.isVideoFile(mPictrueFilePath)) {
|
||||
FFmpegUtils.getDurationInMilliseconds(mPictrueFilePath, new Observer<Integer>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("openSelector", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull Integer integer) {
|
||||
Log.e("openSelector", "onNext: " + integer);
|
||||
tv_duration.setText(TimeUtils.secToTime(integer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("openSelector", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("openSelector", "onComplete: ");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
tv_duration.setText("");
|
||||
}
|
||||
} else {
|
||||
mPictrueFilePath = "";
|
||||
nv_pic.setVisibility(View.GONE);
|
||||
cl_pic.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
Log.e(TAG, "onCancel: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initTimePicker() {
|
||||
//控制时间范围(如果不设置范围,则使用默认时间1900-2100年,此段代码可注释)
|
||||
//因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11
|
||||
Calendar selectedDate = Calendar.getInstance();
|
||||
|
||||
Calendar startDate = Calendar.getInstance();
|
||||
startDate.set(2013, 0, 23);
|
||||
|
||||
Calendar endDate = Calendar.getInstance();
|
||||
endDate.set(2019, 11, 28);
|
||||
|
||||
//时间选择器
|
||||
pvTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
|
||||
@Override
|
||||
public void onTimeSelect(Date date, View v) {//选中事件回调
|
||||
// 这里回调过来的v,就是show()方法里面所添加的 View 参数,如果show的时候没有添加参数,v则为null
|
||||
/*btn_Time.setText(getTime(date));*/
|
||||
mDate = date;
|
||||
Log.e(TAG, "onTimeSelect: " + getTime(date));
|
||||
}
|
||||
})
|
||||
.setLayoutRes(R.layout.pickerview_custom_time, new CustomListener() {
|
||||
@Override
|
||||
public void customLayout(View v) {
|
||||
|
||||
}
|
||||
})
|
||||
.setType(new boolean[]{false, false, false, true, true, false})
|
||||
.setLabel("", "", "", "时", "分", "") //设置空字符串以隐藏单位提示 hide label
|
||||
.setDividerColor(Color.GRAY)
|
||||
.setContentTextSize(30)
|
||||
.setDate(selectedDate)
|
||||
.setRangDate(startDate, selectedDate)
|
||||
.setDecorView(cl_content)//非dialog模式下,设置ViewGroup, pickerView将会添加到这个ViewGroup中
|
||||
.setOutSideColor(0x00000000)
|
||||
.setOutSideCancelable(false)
|
||||
.build();
|
||||
pvTime.setKeyBackCancelable(false);//系统返回键监听屏蔽掉
|
||||
pvTime.show(cl_content, false);//弹出时间选择器,传递参数过去,回调的时候则可以绑定此view
|
||||
|
||||
}
|
||||
|
||||
private String getTime(Date date) {
|
||||
SimpleDateFormat format;
|
||||
if (mType == 1) {
|
||||
format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
} else {
|
||||
format = new SimpleDateFormat("HH:mm");
|
||||
}
|
||||
return format.format(date);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.uiuios.aios.activity.alarm;
|
||||
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -0,0 +1,675 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.bigkoo.pickerview.builder.TimePickerBuilder;
|
||||
import com.bigkoo.pickerview.listener.CustomListener;
|
||||
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
|
||||
import com.bigkoo.pickerview.view.TimePickerView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.luck.picture.lib.basic.PictureSelector;
|
||||
import com.luck.picture.lib.config.SelectMimeType;
|
||||
import com.luck.picture.lib.entity.LocalMedia;
|
||||
import com.luck.picture.lib.interfaces.OnResultCallbackListener;
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
import com.trello.rxlifecycle4.LifecycleProvider;
|
||||
import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.base.GlideEngine;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.FFmpegUtils;
|
||||
import com.uiuios.aios.utils.FileUtil;
|
||||
import com.uiuios.aios.utils.GlideLoadUtils;
|
||||
import com.uiuios.aios.utils.ScreenUtil;
|
||||
import com.uiuios.aios.utils.TimeUtils;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
import com.xiasuhuei321.loadingdialog.view.LoadingDialog;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class AlarmClockEditActivity extends AppCompatActivity implements LifecycleProvider<ActivityEvent> {
|
||||
|
||||
private static final String TAG = AlarmClockEditActivity.class.getSimpleName();
|
||||
private final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
|
||||
|
||||
|
||||
@BindView(R.id.cl_content)
|
||||
ConstraintLayout cl_content;
|
||||
@BindView(R.id.ll_type)
|
||||
LinearLayout ll_type;
|
||||
@BindView(R.id.cl_type)
|
||||
ConstraintLayout cl_type;
|
||||
@BindView(R.id.tv_type)
|
||||
TextView tv_type;
|
||||
@BindView(R.id.cl_pic)
|
||||
ConstraintLayout cl_pic;
|
||||
@BindView(R.id.et_activation)
|
||||
EditText et_activation;
|
||||
@BindView(R.id.nv_pic)
|
||||
NiceImageView nv_pic;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
@BindView(R.id.bt_confirm)
|
||||
Button bt_confirm;
|
||||
@BindView(R.id.bt_cancel)
|
||||
Button bt_cancel;
|
||||
@BindView(R.id.tv_title)
|
||||
TextView tv_title;
|
||||
@BindView(R.id.tv_duration)
|
||||
TextView tv_duration;
|
||||
|
||||
@BindView(R.id.rb1)
|
||||
RadioButton rb1;
|
||||
@BindView(R.id.rb2)
|
||||
RadioButton rb2;
|
||||
@BindView(R.id.rb3)
|
||||
RadioButton rb3;
|
||||
@BindView(R.id.rb4)
|
||||
RadioButton rb4;
|
||||
|
||||
private PopupWindow mMenuPopupWindow;
|
||||
|
||||
private TimePickerView pvTime;
|
||||
private String mPictrueFilePath;
|
||||
|
||||
private Date mDate;
|
||||
/*类型 1一次性 2每天 3周一到周五 4周六周日*/
|
||||
private int mType = 1;
|
||||
private int mId;
|
||||
private AlarmClockData mAlarmClockData;
|
||||
|
||||
@Override
|
||||
@androidx.annotation.NonNull
|
||||
@CheckResult
|
||||
public final Observable<ActivityEvent> lifecycle() {
|
||||
return lifecycleSubject.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@androidx.annotation.NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindUntilEvent(@androidx.annotation.NonNull ActivityEvent event) {
|
||||
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@androidx.annotation.NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindToLifecycle() {
|
||||
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
lifecycleSubject.onNext(ActivityEvent.START);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
lifecycleSubject.onNext(ActivityEvent.RESUME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onPause() {
|
||||
lifecycleSubject.onNext(ActivityEvent.PAUSE);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onStop() {
|
||||
lifecycleSubject.onNext(ActivityEvent.STOP);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onDestroy() {
|
||||
lifecycleSubject.onNext(ActivityEvent.DESTROY);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_add_alarm_clock);
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
UltimateBarX.statusBarOnly(this)
|
||||
.colorRes(R.color.default_blue)
|
||||
.fitWindow(true)
|
||||
.apply();
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
ButterKnife.bind(this);
|
||||
tv_title.setText("编辑闹钟");
|
||||
initTimePicker();
|
||||
|
||||
cl_pic.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
openSelector();
|
||||
}
|
||||
});
|
||||
cl_type.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// showTimeFilterWindow();
|
||||
}
|
||||
});
|
||||
nv_pic.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
openSelector();
|
||||
}
|
||||
});
|
||||
bt_confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkContent();
|
||||
}
|
||||
});
|
||||
bt_cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
rb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb1.setTextColor(colorStateList);
|
||||
mType = 1;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb1.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
rb2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb2.setTextColor(colorStateList);
|
||||
mType = 2;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb2.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
rb3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb3.setTextColor(colorStateList);
|
||||
mType = 3;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb3.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
rb4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb4.setTextColor(colorStateList);
|
||||
mType = 4;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb4.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
Intent intent = getIntent();
|
||||
if (intent == null) {
|
||||
ToastUtil.show("获取闹钟信息失败");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
mId = intent.getIntExtra("id", -1);
|
||||
if (mId == -1) {
|
||||
ToastUtil.show("获取闹钟信息失败");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
NetInterfaceManager.getInstance().getAlarmClockByIdObservable(mId)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<AlarmClockData>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getAlarmClockById", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<AlarmClockData> alarmClockDatabaseResponse) {
|
||||
Log.e("getAlarmClockById", "onNext: " + alarmClockDatabaseResponse);
|
||||
if (alarmClockDatabaseResponse.code == 200) {
|
||||
AlarmClockData alarmClockData = alarmClockDatabaseResponse.data;
|
||||
mAlarmClockData = alarmClockData;
|
||||
setAlarmClockInfo(alarmClockData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAlarmClockById", "onError: " + e.getMessage());
|
||||
HashMap<Integer, AlarmClockData> oldData = AlarmUtils.getInstance().getOldDataMap();
|
||||
mAlarmClockData = oldData.get(mId);
|
||||
setAlarmClockInfo(mAlarmClockData);
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAlarmClockById", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setAlarmClockInfo(AlarmClockData alarmClockData) {
|
||||
if (alarmClockData == null) {
|
||||
ToastUtil.show("闹钟信息为空");
|
||||
return;
|
||||
}
|
||||
Log.e(TAG, "setAlarmClockInfo: " + alarmClockData);
|
||||
mType = alarmClockData.getType();
|
||||
switch (mType) {
|
||||
default:
|
||||
case AlarmUtils.ONCE:
|
||||
rb1.setChecked(true);
|
||||
tv_type.setText("只响一次");
|
||||
break;
|
||||
case AlarmUtils.LOOP:
|
||||
rb2.setChecked(true);
|
||||
tv_type.setText("每天");
|
||||
break;
|
||||
case AlarmUtils.WORKING_DAY:
|
||||
rb3.setChecked(true);
|
||||
tv_type.setText("周一至周五");
|
||||
break;
|
||||
case AlarmUtils.OFF_DAY:
|
||||
rb4.setChecked(true);
|
||||
tv_type.setText("周六至周日");
|
||||
break;
|
||||
}
|
||||
String time = alarmClockData.getTime();
|
||||
Calendar date = getTime(time);
|
||||
Calendar now = Calendar.getInstance();
|
||||
date.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1, now.get(Calendar.DAY_OF_MONTH));
|
||||
Log.e(TAG, "setAlarmClockInfo: " + date.getTimeInMillis());
|
||||
pvTime.setDate(date);
|
||||
String title = alarmClockData.getTitle();
|
||||
et_activation.setText(title);
|
||||
String fileUrl = alarmClockData.getFile();
|
||||
mPictrueFilePath = fileUrl;
|
||||
String fileName = Utils.getFileNamefromURL(fileUrl);
|
||||
File file = new File(Utils.getDownLoadPath(AlarmClockEditActivity.this) + fileName);
|
||||
if (TextUtils.isEmpty(fileUrl)) {
|
||||
cl_pic.setVisibility(View.VISIBLE);
|
||||
nv_pic.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (file.exists() && !file.isDirectory()) {
|
||||
GlideLoadUtils.getInstance().glideLoad(this, file, nv_pic);
|
||||
} else {
|
||||
GlideLoadUtils.getInstance().glideLoad(this, fileUrl, nv_pic);
|
||||
}
|
||||
cl_pic.setVisibility(View.GONE);
|
||||
nv_pic.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
LoadingDialog mLoadingDialog;
|
||||
|
||||
private void checkContent() {
|
||||
pvTime.returnData();
|
||||
if (TextUtils.isEmpty(et_activation.getText())) {
|
||||
ToastUtil.show("请输入标题");
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(mPictrueFilePath)) {
|
||||
ToastUtil.show("请重新选择图片");
|
||||
return;
|
||||
}
|
||||
String timeStamp = getTime(mDate);
|
||||
Log.e(TAG, "checkContent: " + timeStamp);
|
||||
Log.e(TAG, "checkContent: " + mPictrueFilePath);
|
||||
// Uri uri = Uri.parse(pictrueFilePath);
|
||||
// File picFile = FileUtil.uriToFile(uri, AlarmClockAddActivity.this);
|
||||
MultipartBody.Part body;
|
||||
if (FileUtil.isLocalPath(mPictrueFilePath)) {
|
||||
File picFile = new File(mPictrueFilePath);
|
||||
MediaType mediaType = MediaType.Companion.parse("image/png");
|
||||
RequestBody requestBody = RequestBody.Companion.create(picFile, mediaType);
|
||||
body = MultipartBody.Part.createFormData("file", picFile.getName(), requestBody);
|
||||
} else {
|
||||
String fileName = Utils.getFileNamefromURL(mPictrueFilePath);
|
||||
File picFile = new File(Utils.getDownLoadPath(this) + fileName);
|
||||
MediaType mediaType = MediaType.Companion.parse("image/png");
|
||||
RequestBody requestBody = RequestBody.Companion.create(picFile, mediaType);
|
||||
body = MultipartBody.Part.createFormData("file", picFile.getName(), requestBody);
|
||||
}
|
||||
|
||||
mAlarmClockData.setId(mId);
|
||||
mAlarmClockData.setType(mType);
|
||||
mAlarmClockData.setTime(timeStamp);
|
||||
mAlarmClockData.setTitle(et_activation.getText().toString());
|
||||
mAlarmClockData.setFile(mPictrueFilePath);
|
||||
mAlarmClockData.setRemind_type(0);
|
||||
mAlarmClockData.setIs_onoff(1);
|
||||
mAlarmClockData.setFinished(false);
|
||||
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("sn", Utils.getSerial());
|
||||
params.put("id", String.valueOf(mId));
|
||||
params.put("type", String.valueOf(mType));
|
||||
params.put("time", timeStamp);
|
||||
params.put("title", et_activation.getText().toString());
|
||||
params.put("remind_type", "0");
|
||||
params.put("is_onoff", "1");
|
||||
|
||||
mLoadingDialog = new LoadingDialog(this);
|
||||
mLoadingDialog.setLoadingText("正在上传")
|
||||
.setSuccessText("编辑成功")
|
||||
.setFailedText("编辑失败")
|
||||
.setInterceptBack(true)
|
||||
.setLoadSpeed(LoadingDialog.Speed.SPEED_ONE)
|
||||
.closeSuccessAnim()
|
||||
.show();
|
||||
|
||||
NetInterfaceManager.getInstance().getAlarmClockEditObservable(params, body)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("checkContent", "onSubscribe: ");
|
||||
ToastUtil.show("正在上传");
|
||||
bt_confirm.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("checkContent", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
ToastUtil.show("编辑成功");
|
||||
mLoadingDialog.loadSuccess();
|
||||
mLoadingDialog.close();
|
||||
mAlarmClockData.setEdited(false);
|
||||
AlarmUtils.getInstance().updateAlarmClock(mAlarmClockData);
|
||||
finish();
|
||||
} else {
|
||||
ToastUtil.show("编辑失败:" + baseResponse.msg);
|
||||
mLoadingDialog.loadFailed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("checkContent", "onError: " + e.getMessage());
|
||||
mAlarmClockData.setEdited(true);
|
||||
AlarmUtils.getInstance().updateAlarmClock(mAlarmClockData);
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("checkContent", "onComplete: ");
|
||||
bt_confirm.setEnabled(true);
|
||||
finish();
|
||||
mLoadingDialog.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void showTimeFilterWindow() {
|
||||
if (mMenuPopupWindow == null) {
|
||||
View view = getLayoutInflater().inflate(R.layout.window_menu, null);
|
||||
TextView tvMenuOne = view.findViewById(R.id.tv_menuOne);
|
||||
TextView tvMenuTwo = view.findViewById(R.id.tv_menuTwo);
|
||||
TextView tvMenuThree = view.findViewById(R.id.tv_menuThree);
|
||||
TextView tvMenuFour = view.findViewById(R.id.tv_menuFour);
|
||||
mMenuPopupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
|
||||
mMenuPopupWindow.setOutsideTouchable(true);
|
||||
tvMenuOne.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 1;
|
||||
tv_type.setText("只响一次");
|
||||
mMenuPopupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
tvMenuTwo.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 2;
|
||||
tv_type.setText("每天");
|
||||
mMenuPopupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
tvMenuThree.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 3;
|
||||
tv_type.setText("周一至周五");
|
||||
mMenuPopupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
tvMenuFour.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 4;
|
||||
tv_type.setText("周六至周日");
|
||||
mMenuPopupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (mMenuPopupWindow.isShowing()) {
|
||||
mMenuPopupWindow.dismiss();
|
||||
} else {
|
||||
Log.e(TAG, "showTimeFilterWindow: right " + tv_type.getRight());
|
||||
Log.e(TAG, "showTimeFilterWindow: top " + tv_type.getTop());
|
||||
Log.e(TAG, "showTimeFilterWindow: right " + cl_type.getRight());
|
||||
Log.e(TAG, "showTimeFilterWindow: top " + cl_type.getTop());
|
||||
mMenuPopupWindow.showAtLocation(cl_type, Gravity.END, 20, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void openSelector() {
|
||||
PictureSelector.create(AlarmClockEditActivity.this)
|
||||
.openGallery(SelectMimeType.ofAll())
|
||||
.setSelectionMode(1)
|
||||
.setImageEngine(GlideEngine.createGlideEngine())
|
||||
.forResult(new OnResultCallbackListener<LocalMedia>() {
|
||||
@Override
|
||||
public void onResult(ArrayList<LocalMedia> result) {
|
||||
mPictrueFilePath = result.get(0).getRealPath();
|
||||
File file = new File(mPictrueFilePath);
|
||||
if (file.exists()) {
|
||||
RequestOptions options = new RequestOptions().transform(new RoundedCorners(ScreenUtil.dip2px(AlarmClockEditActivity.this, 8F)));
|
||||
Glide.with(nv_pic).load(file).apply(options).into(nv_pic);
|
||||
nv_pic.setVisibility(View.VISIBLE);
|
||||
cl_pic.setVisibility(View.GONE);
|
||||
if (FileUtil.isVideoFile(mPictrueFilePath)) {
|
||||
FFmpegUtils.getDurationInMilliseconds(mPictrueFilePath, new Observer<Integer>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("openSelector", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull Integer integer) {
|
||||
Log.e("openSelector", "onNext: " + integer);
|
||||
tv_duration.setText(TimeUtils.secToTime(integer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("openSelector", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("openSelector", "onComplete: ");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
tv_duration.setText("");
|
||||
}
|
||||
} else {
|
||||
mPictrueFilePath = "";
|
||||
nv_pic.setVisibility(View.GONE);
|
||||
cl_pic.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
Log.e(TAG, "onCancel: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initTimePicker() {
|
||||
//控制时间范围(如果不设置范围,则使用默认时间1900-2100年,此段代码可注释)
|
||||
//因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11
|
||||
Calendar selectedDate = Calendar.getInstance();
|
||||
|
||||
Calendar startDate = Calendar.getInstance();
|
||||
startDate.set(2013, 0, 23);
|
||||
|
||||
Calendar endDate = Calendar.getInstance();
|
||||
endDate.set(2019, 11, 28);
|
||||
|
||||
//时间选择器
|
||||
pvTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
|
||||
@Override
|
||||
public void onTimeSelect(Date date, View v) {//选中事件回调
|
||||
// 这里回调过来的v,就是show()方法里面所添加的 View 参数,如果show的时候没有添加参数,v则为null
|
||||
/*btn_Time.setText(getTime(date));*/
|
||||
mDate = date;
|
||||
Log.e(TAG, "onTimeSelect: " + getTime(date));
|
||||
}
|
||||
})
|
||||
.setLayoutRes(R.layout.pickerview_custom_time, new CustomListener() {
|
||||
@Override
|
||||
public void customLayout(View v) {
|
||||
|
||||
}
|
||||
})
|
||||
.setType(new boolean[]{false, false, false, true, true, false})
|
||||
.setLabel("", "", "", "时", "分", "") //设置空字符串以隐藏单位提示 hide label
|
||||
.setDividerColor(Color.GRAY)
|
||||
.setContentTextSize(30)
|
||||
.setDate(selectedDate)
|
||||
.setRangDate(startDate, selectedDate)
|
||||
.setDecorView(cl_content)//非dialog模式下,设置ViewGroup, pickerView将会添加到这个ViewGroup中
|
||||
.setOutSideColor(0x00000000)
|
||||
.setOutSideCancelable(false)
|
||||
.build();
|
||||
pvTime.setKeyBackCancelable(false);//系统返回键监听屏蔽掉
|
||||
pvTime.show(cl_content, false);//弹出时间选择器,传递参数过去,回调的时候则可以绑定此view
|
||||
|
||||
}
|
||||
|
||||
private String getTime(Date date) {
|
||||
SimpleDateFormat format;
|
||||
if (mType == 1) {
|
||||
format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
} else {
|
||||
format = new SimpleDateFormat("HH:mm");
|
||||
}
|
||||
return format.format(date);
|
||||
}
|
||||
|
||||
private Calendar getTime(String timeString) {
|
||||
SimpleDateFormat sdf;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
if (mType == 1) {
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
} else {
|
||||
sdf = new SimpleDateFormat("HH:mm");
|
||||
}
|
||||
try {
|
||||
Date date = sdf.parse(timeString);
|
||||
calendar.setTime(date);
|
||||
return calendar;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "getTime: " + e.getMessage());
|
||||
calendar.setTime(new Date());
|
||||
return calendar;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,9 +11,9 @@ import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.gson.GsonUtils;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
import com.uiuios.aios.utils.GsonUtils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
@@ -68,7 +68,7 @@ public class ContactPresenter implements ContactContact.Presenter {
|
||||
public void onNext(@NonNull BaseResponse<List<Contact>> listBaseResponse) {
|
||||
Log.e("getContactList", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
mMMKV.putString(UrlAddress.GET_MAIL_LIST, GsonUtils.toJsonString(listBaseResponse.data));
|
||||
mMMKV.putString(UrlAddress.GET_MAIL_LIST, GsonUtils.toJSONString(listBaseResponse.data));
|
||||
mView.setContact(listBaseResponse.data);
|
||||
} else {
|
||||
mMMKV.putString(UrlAddress.GET_MAIL_LIST, "");
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.dialer.DialerActivity;
|
||||
import com.uiuios.aios.adapter.CallRecordAdapter;
|
||||
import com.uiuios.aios.bean.RecordsInfo;
|
||||
import com.uiuios.aios.dialog.DeleteDialog;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -75,15 +76,37 @@ public class RecordsActivity extends AppCompatActivity {
|
||||
iv_clear.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
for (RecordsInfo recordsInfo : dataList) {
|
||||
String queryString = "NUMBER=" + recordsInfo.getNumber();
|
||||
getContentResolver().delete(CallLog.Calls.CONTENT_URI, queryString, null);
|
||||
}
|
||||
getData();
|
||||
showDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showDialog() {
|
||||
DeleteDialog dialog = new DeleteDialog(this);
|
||||
dialog.setTitle("提醒")
|
||||
.setMessage("清空全部通话记录")
|
||||
.setPositive("确定")
|
||||
.setNegtive("取消")
|
||||
// .setSingle(true)
|
||||
.setOnClickBottomListener(new DeleteDialog.OnClickBottomListener() {
|
||||
@Override
|
||||
public void onPositiveClick() {
|
||||
for (RecordsInfo recordsInfo : dataList) {
|
||||
String queryString = "NUMBER=" + recordsInfo.getNumber();
|
||||
getContentResolver().delete(CallLog.Calls.CONTENT_URI, queryString, null);
|
||||
}
|
||||
getData();
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegtiveClick() {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.uiuios.aios.activity.wifi;
|
||||
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
import com.uiuios.aios.bean.WiFiInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WiFiContact {
|
||||
public interface Presenter extends BasePresenter<WiFiView> {
|
||||
void getWiFiList();
|
||||
}
|
||||
|
||||
public interface WiFiView extends BaseView {
|
||||
void setSavedWiFiList(List<WiFiInfo> wiFiList);
|
||||
void setAvailableWiFiList(List<WiFiInfo> wiFiList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package com.uiuios.aios.activity.wifi;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.AvailableWiFiAdapter;
|
||||
import com.uiuios.aios.adapter.SavedWiFiAdapter;
|
||||
import com.uiuios.aios.base.BaseLightActivity;
|
||||
import com.uiuios.aios.bean.WiFiInfo;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.view.HorizontalItemDecoration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class WiFiManagerActivity extends BaseLightActivity implements WiFiContact.WiFiView {
|
||||
|
||||
|
||||
@BindView(R.id.iv_close)
|
||||
ImageView iv_close;
|
||||
@BindView(R.id.rv_saved)
|
||||
RecyclerView rv_saved;
|
||||
@BindView(R.id.rv_available)
|
||||
RecyclerView rv_available;
|
||||
@BindView(R.id.tv_refresh)
|
||||
TextView tv_refresh;
|
||||
@BindView(R.id.tv_refresh2)
|
||||
TextView tv_refresh2;
|
||||
|
||||
private WiFiPresenter mPresenter;
|
||||
private SavedWiFiAdapter mSavedWiFiAdapter;
|
||||
private AvailableWiFiAdapter mAvailableWiFiAdapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_wifi_manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mPresenter = new WiFiPresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
|
||||
iv_close.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
tv_refresh.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mPresenter.getWiFiList();
|
||||
}
|
||||
});
|
||||
tv_refresh2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mPresenter.getWiFiList();
|
||||
}
|
||||
});
|
||||
|
||||
mSavedWiFiAdapter = new SavedWiFiAdapter();
|
||||
mAvailableWiFiAdapter = new AvailableWiFiAdapter();
|
||||
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
||||
rv_saved.setLayoutManager(linearLayoutManager);
|
||||
rv_saved.addItemDecoration(new HorizontalItemDecoration(30, this));
|
||||
rv_saved.setAdapter(mSavedWiFiAdapter);
|
||||
|
||||
LinearLayoutManager linearLayoutManager2 = new LinearLayoutManager(this);
|
||||
linearLayoutManager2.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
rv_available.setLayoutManager(linearLayoutManager2);
|
||||
rv_available.setAdapter(mAvailableWiFiAdapter);
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
||||
filter.addAction("android.net.wifi.CONFIGURED_NETWORKS_CHANGE");
|
||||
filter.addAction("android.net.wifi.LINK_CONFIGURATION_CHANGED");
|
||||
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
|
||||
registerReceiver(broadcastReceiver, filter);
|
||||
|
||||
|
||||
mPresenter.getWiFiList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(broadcastReceiver);
|
||||
}
|
||||
|
||||
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action != null) {
|
||||
switch (action) {
|
||||
case ConnectivityManager.CONNECTIVITY_ACTION:
|
||||
case WifiManager.SCAN_RESULTS_AVAILABLE_ACTION:
|
||||
case "android.net.wifi.CONFIGURED_NETWORKS_CHANGE":
|
||||
case "android.net.wifi.LINK_CONFIGURATION_CHANGED":
|
||||
case WifiManager.NETWORK_STATE_CHANGED_ACTION:
|
||||
case WifiManager.SUPPLICANT_STATE_CHANGED_ACTION:
|
||||
default:
|
||||
mPresenter.getWiFiList();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void setSavedWiFiList(List<WiFiInfo> wiFiList) {
|
||||
ToastUtil.show("刷新成功");
|
||||
mSavedWiFiAdapter.setResultList(wiFiList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAvailableWiFiList(List<WiFiInfo> wiFiList) {
|
||||
mAvailableWiFiAdapter.setResultList(wiFiList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.uiuios.aios.activity.wifi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.bean.WiFiInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
import static android.text.TextUtils.isEmpty;
|
||||
|
||||
public class WiFiPresenter implements WiFiContact.Presenter {
|
||||
|
||||
private WiFiContact.WiFiView mView;
|
||||
private Context mContext;
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
public void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
WiFiPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(@NonNull WiFiContact.WiFiView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getWiFiList() {
|
||||
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
||||
List<WifiConfiguration> wifiConfigurations = wifiManager.getConfiguredNetworks();
|
||||
Map<String, WifiConfiguration> savedWifiConfiguration = new HashMap<>();
|
||||
for (WifiConfiguration wifiConfiguration : wifiConfigurations) {
|
||||
savedWifiConfiguration.put(wifiConfiguration.SSID.replaceAll("\"", ""), wifiConfiguration);
|
||||
}
|
||||
List<ScanResult> scanResults = wifiManager.getScanResults();
|
||||
List<ScanResult> filterList = scanResults.stream().filter(scanResult -> !isEmpty(scanResult.SSID)).collect(Collectors.toList());
|
||||
Map<String, WiFiInfo> scanResultMap = new HashMap<>();
|
||||
List<WiFiInfo> savedList = new ArrayList<>();
|
||||
List<WiFiInfo> availableList = new ArrayList<>();
|
||||
|
||||
for (ScanResult scanResult : filterList) {
|
||||
WiFiInfo wiFiInfo = new WiFiInfo();
|
||||
wiFiInfo.setSSID(scanResult.SSID);
|
||||
wiFiInfo.setBSSID(scanResult.BSSID);
|
||||
wiFiInfo.setLevel(scanResult.level);
|
||||
// if (savedWifiConfiguration.get(scanResult.SSID) != null) {
|
||||
// //跳过已保存的
|
||||
// continue;
|
||||
// }
|
||||
wiFiInfo.setAvailable(true);
|
||||
wiFiInfo.setSaved(false);
|
||||
scanResultMap.put(scanResult.SSID, wiFiInfo);
|
||||
availableList.add(wiFiInfo);
|
||||
}
|
||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
for (Map.Entry<String, WifiConfiguration> wifiConfiguration : savedWifiConfiguration.entrySet()) {
|
||||
WiFiInfo wiFiInfo = new WiFiInfo();
|
||||
if (wifiInfo != null) {
|
||||
if (wifiConfiguration.getValue().SSID.equals(wifiInfo.getSSID())) {
|
||||
wiFiInfo.setConnected(true);
|
||||
}
|
||||
}
|
||||
String ssid = wifiConfiguration.getValue().SSID.replaceAll("\"", "");
|
||||
WiFiInfo wiFiInfo1 = scanResultMap.get(ssid);
|
||||
if (wiFiInfo1 != null) {
|
||||
|
||||
wiFiInfo.setSSID(wiFiInfo1.getSSID());
|
||||
wiFiInfo.setBSSID(wiFiInfo1.getBSSID());
|
||||
wiFiInfo.setLevel(wiFiInfo1.getLevel());
|
||||
wiFiInfo.setAvailable(true);
|
||||
} else {
|
||||
wiFiInfo.setSSID(wifiConfiguration.getValue().SSID.replaceAll("\"", ""));
|
||||
wiFiInfo.setBSSID(wifiConfiguration.getValue().BSSID);
|
||||
wiFiInfo.setAvailable(false);
|
||||
}
|
||||
wiFiInfo.setSaved(true);
|
||||
savedList.add(wiFiInfo);
|
||||
availableList.removeIf(new Predicate<WiFiInfo>() {
|
||||
@Override
|
||||
public boolean test(WiFiInfo wiFiInfo) {
|
||||
return wiFiInfo.getSSID().equals(ssid);
|
||||
}
|
||||
});
|
||||
}
|
||||
mView.setSavedWiFiList(savedList.stream().sorted(new Comparator<WiFiInfo>() {
|
||||
@Override
|
||||
public int compare(WiFiInfo o1, WiFiInfo o2) {
|
||||
if (o1.isAvailable()) {
|
||||
return -1;
|
||||
} else if (o2.isAvailable()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}).collect(Collectors.toList()));
|
||||
mView.setAvailableWiFiList(availableList);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user