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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.uiuios.aios.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.bean.WiFiInfo;
|
||||
import com.uiuios.aios.dialog.WifiDialog;
|
||||
import com.uiuios.aios.utils.WiFiUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AvailableWiFiAdapter extends RecyclerView.Adapter<AvailableWiFiAdapter.Holder> {
|
||||
|
||||
private Context mContext;
|
||||
private List<WiFiInfo> mResultList;
|
||||
|
||||
public void setResultList(List<WiFiInfo> list) {
|
||||
this.mResultList = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
mContext = parent.getContext();
|
||||
return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_wifi_available, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull Holder holder, int position) {
|
||||
WiFiInfo wiFiInfo = mResultList.get(position);
|
||||
holder.tv_name.setText(wiFiInfo.getSSID());
|
||||
if (wiFiInfo.isSaved()) {
|
||||
if (wiFiInfo.isAvailable()) {
|
||||
holder.iv_icon.setImageDrawable(mContext.getDrawable(R.drawable.icon_wifi_saved));
|
||||
} else {
|
||||
holder.iv_icon.setImageDrawable(mContext.getDrawable(R.drawable.icon_wifi_unavailable));
|
||||
}
|
||||
} else {
|
||||
holder.iv_icon.setImageDrawable(mContext.getDrawable(R.drawable.icon_wifi_available));
|
||||
}
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// if (wiFiInfo.isSaved()) {
|
||||
//
|
||||
// } else {
|
||||
showPassword(wiFiInfo.getSSID());
|
||||
// }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showPassword(String ssid) {
|
||||
WifiDialog passwordDialog = new WifiDialog(mContext);
|
||||
passwordDialog.setTitle(String.format(mContext.getString(R.string.connect_wifi_ssid), ssid));
|
||||
passwordDialog.setOnClickBottomListener(new WifiDialog.OnClickBottomListener() {
|
||||
@Override
|
||||
public void onPositiveClick() {
|
||||
WiFiUtils.addWiFiNetwork(ssid, passwordDialog.getPassword());
|
||||
passwordDialog.dismiss();
|
||||
}
|
||||
});
|
||||
passwordDialog.show();
|
||||
passwordDialog.getWindow().setGravity(Gravity.CENTER);
|
||||
passwordDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||
passwordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mResultList == null ? 0 : mResultList.size();
|
||||
}
|
||||
|
||||
class Holder extends RecyclerView.ViewHolder {
|
||||
ImageView iv_icon;
|
||||
TextView tv_name;
|
||||
ConstraintLayout root;
|
||||
|
||||
public Holder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
iv_icon = itemView.findViewById(R.id.iv_icon);
|
||||
tv_name = itemView.findViewById(R.id.tv_name);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.uiuios.aios.adapter;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.CallLog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -24,7 +25,7 @@ public class CallRecordAdapter extends RecyclerView.Adapter<CallRecordAdapter.Ho
|
||||
|
||||
private Context mContext;
|
||||
private List<RecordsInfo> mRecordsInfoList;
|
||||
private SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("HH:mm");
|
||||
private SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
public void setRecordsInfoList(List<RecordsInfo> recordsInfoList) {
|
||||
this.mRecordsInfoList = recordsInfoList;
|
||||
@@ -43,6 +44,18 @@ public class CallRecordAdapter extends RecyclerView.Adapter<CallRecordAdapter.Ho
|
||||
RecordsInfo recordsInfo = mRecordsInfoList.get(position);
|
||||
String phone = recordsInfo.getNumber();
|
||||
holder.tv_phone.setText(phone);
|
||||
switch (recordsInfo.getType()) {
|
||||
default:
|
||||
case CallLog.Calls.INCOMING_TYPE:
|
||||
holder.tv_state.setImageDrawable(mContext.getDrawable(R.drawable.icon_incoming));
|
||||
break;
|
||||
case CallLog.Calls.OUTGOING_TYPE:
|
||||
holder.tv_state.setImageDrawable(mContext.getDrawable(R.drawable.icon_outgoing));
|
||||
break;
|
||||
case CallLog.Calls.MISSED_TYPE:
|
||||
holder.tv_state.setImageDrawable(mContext.getDrawable(R.drawable.icon_missed));
|
||||
break;
|
||||
}
|
||||
holder.tv_time.setText(mSimpleDateFormat.format(new Date(recordsInfo.getDate())));
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -53,6 +66,15 @@ public class CallRecordAdapter extends RecyclerView.Adapter<CallRecordAdapter.Ho
|
||||
mContext.startActivity(dialIntent);
|
||||
}
|
||||
});
|
||||
holder.iv_remove.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String queryString = "NUMBER=" + recordsInfo.getNumber();
|
||||
mContext.getContentResolver().delete(CallLog.Calls.CONTENT_URI, queryString, null);
|
||||
mRecordsInfoList.remove(position);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,6 +85,8 @@ public class CallRecordAdapter extends RecyclerView.Adapter<CallRecordAdapter.Ho
|
||||
class Holder extends RecyclerView.ViewHolder {
|
||||
ConstraintLayout root;
|
||||
ImageView iv_avatar;
|
||||
ImageView iv_remove;
|
||||
ImageView tv_state;
|
||||
TextView tv_phone;
|
||||
TextView tv_time;
|
||||
|
||||
@@ -70,6 +94,8 @@ public class CallRecordAdapter extends RecyclerView.Adapter<CallRecordAdapter.Ho
|
||||
super(itemView);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
iv_avatar = itemView.findViewById(R.id.iv_avatar);
|
||||
iv_remove = itemView.findViewById(R.id.iv_remove);
|
||||
tv_state = itemView.findViewById(R.id.tv_state);
|
||||
tv_phone = itemView.findViewById(R.id.tv_phone);
|
||||
tv_time = itemView.findViewById(R.id.tv_time);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class GoodsListAdapter extends RecyclerView.Adapter<GoodsListAdapter.Good
|
||||
holder.tv_name.setText(goodsInfo.getGoods_name());
|
||||
holder.tv_desc.setText(goodsInfo.getGoods_desc());
|
||||
holder.tv_price.setText("全网低价¥" + goodsInfo.getOriginal_price());
|
||||
holder.tv_buying_price.setText("秒杀价格¥" + goodsInfo.getBuying_price());
|
||||
holder.tv_buying_price.setText("秒杀¥" + goodsInfo.getBuying_price());
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -19,7 +18,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.utils.FFmpegUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -80,17 +79,17 @@ public class NotificationAdapter extends RecyclerView.Adapter<NotificationAdapte
|
||||
} else {
|
||||
FFmpegUtils.loadVideoScreenshot(file, new Observer<Bitmap>() {
|
||||
@Override
|
||||
public void onSubscribe(@io.reactivex.rxjava3.annotations.NonNull Disposable d) {
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@io.reactivex.rxjava3.annotations.NonNull Bitmap bitmap) {
|
||||
public void onNext(@NonNull Bitmap bitmap) {
|
||||
Glide.with(holder.iv_cover).load(bitmap).into(holder.iv_cover);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.rxjava3.annotations.NonNull Throwable e) {
|
||||
public void onError(@NonNull Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@@ -132,17 +131,17 @@ public class NotificationAdapter extends RecyclerView.Adapter<NotificationAdapte
|
||||
mMediaPlayer.prepareAsync();
|
||||
FFmpegUtils.getDurationInMilliseconds(voice, new Observer<Integer>() {
|
||||
@Override
|
||||
public void onSubscribe(@io.reactivex.rxjava3.annotations.NonNull Disposable d) {
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@io.reactivex.rxjava3.annotations.NonNull Integer integer) {
|
||||
public void onNext(@NonNull Integer integer) {
|
||||
holder.tv_voice.setText(integer + "秒");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.rxjava3.annotations.NonNull Throwable e) {
|
||||
public void onError(@NonNull Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
155
app/src/main/java/com/uiuios/aios/adapter/SavedWiFiAdapter.java
Normal file
155
app/src/main/java/com/uiuios/aios/adapter/SavedWiFiAdapter.java
Normal file
@@ -0,0 +1,155 @@
|
||||
package com.uiuios.aios.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.bean.WiFiInfo;
|
||||
import com.uiuios.aios.dialog.DeleWifiDialog;
|
||||
import com.uiuios.aios.dialog.WifiDialog;
|
||||
import com.uiuios.aios.utils.WiFiUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SavedWiFiAdapter extends RecyclerView.Adapter<SavedWiFiAdapter.Holder> {
|
||||
|
||||
private Context mContext;
|
||||
private List<WiFiInfo> mResultList;
|
||||
|
||||
public void setResultList(List<WiFiInfo> list) {
|
||||
this.mResultList = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
mContext = parent.getContext();
|
||||
return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_wifi_info, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull Holder holder, int position) {
|
||||
WiFiInfo wiFiInfo = mResultList.get(position);
|
||||
holder.tv_name.setText(wiFiInfo.getSSID());
|
||||
if (wiFiInfo.isConnected()) {
|
||||
holder.tv_connected.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.tv_connected.setVisibility(View.GONE);
|
||||
}
|
||||
if (wiFiInfo.isSaved()) {
|
||||
if (wiFiInfo.isAvailable()) {
|
||||
holder.iv_icon.setImageDrawable(mContext.getDrawable(R.drawable.icon_wifi_saved));
|
||||
holder.tv_level.setText("信号:" + getWifiLevelText(wiFiInfo.getLevel()) + "(" + wiFiInfo.getLevel() + "dBm)");
|
||||
holder.tv_level.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.iv_icon.setImageDrawable(mContext.getDrawable(R.drawable.icon_wifi_unavailable));
|
||||
holder.tv_level.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
holder.iv_icon.setImageDrawable(mContext.getDrawable(R.drawable.icon_wifi_available));
|
||||
holder.tv_level.setText("信号:" + getWifiLevelText(wiFiInfo.getLevel()) + "(" + wiFiInfo.getLevel() + "dBm)");
|
||||
holder.tv_level.setVisibility(View.VISIBLE);
|
||||
}
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// if (wiFiInfo.isSaved()) {
|
||||
//
|
||||
// } else {
|
||||
showPassword(wiFiInfo.getSSID());
|
||||
// }
|
||||
}
|
||||
});
|
||||
holder.root.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
showRemoveDialog(wiFiInfo.getSSID(), position);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showRemoveDialog(String ssid, int position) {
|
||||
DeleWifiDialog deleWifiDialog = new DeleWifiDialog(mContext);
|
||||
deleWifiDialog.setTitle("提醒");
|
||||
deleWifiDialog.setMessage(ssid);
|
||||
deleWifiDialog.setOnClickBottomListener(new DeleWifiDialog.OnClickBottomListener() {
|
||||
@Override
|
||||
public void onPositiveClick() {
|
||||
WiFiUtils.removeWiFiNetwork(ssid);
|
||||
deleWifiDialog.dismiss();
|
||||
mResultList.remove(position);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
deleWifiDialog.show();
|
||||
deleWifiDialog.getWindow().setGravity(Gravity.CENTER);
|
||||
deleWifiDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||
deleWifiDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
}
|
||||
|
||||
private static final int MIN_RSSI = -100;
|
||||
|
||||
private static final int MAX_RSSI = -55;
|
||||
|
||||
private String getWifiLevelText(int db) {
|
||||
if (db < MIN_RSSI) {
|
||||
return "微弱";
|
||||
} else if (db < -88) {
|
||||
return "一般";
|
||||
} else if (db < -77) {
|
||||
return "良好";
|
||||
} else if (db < MAX_RSSI) {
|
||||
return "极佳";
|
||||
}
|
||||
return "一般";
|
||||
}
|
||||
|
||||
private void showPassword(String ssid) {
|
||||
WifiDialog passwordDialog = new WifiDialog(mContext);
|
||||
passwordDialog.setTitle(String.format(mContext.getString(R.string.connect_wifi_ssid), ssid));
|
||||
passwordDialog.setOnClickBottomListener(new WifiDialog.OnClickBottomListener() {
|
||||
@Override
|
||||
public void onPositiveClick() {
|
||||
WiFiUtils.addWiFiNetwork(ssid, passwordDialog.getPassword());
|
||||
passwordDialog.dismiss();
|
||||
}
|
||||
});
|
||||
passwordDialog.show();
|
||||
passwordDialog.getWindow().setGravity(Gravity.CENTER);
|
||||
passwordDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||
passwordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mResultList == null ? 0 : mResultList.size();
|
||||
}
|
||||
|
||||
class Holder extends RecyclerView.ViewHolder {
|
||||
ImageView iv_icon;
|
||||
TextView tv_name, tv_level, tv_connected;
|
||||
ConstraintLayout root;
|
||||
|
||||
public Holder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
iv_icon = itemView.findViewById(R.id.iv_icon);
|
||||
tv_name = itemView.findViewById(R.id.tv_name);
|
||||
tv_level = itemView.findViewById(R.id.tv_level);
|
||||
tv_connected = itemView.findViewById(R.id.tv_connected);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.uiuios.aios.adapter;
|
||||
package com.uiuios.aios.alarm;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.MediaPlayer;
|
||||
@@ -9,7 +10,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -21,7 +21,7 @@ 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.bean.AlarmClockData;
|
||||
import com.uiuios.aios.activity.alarm.AlarmClockEditActivity;
|
||||
import com.uiuios.aios.utils.FFmpegUtils;
|
||||
import com.uiuios.aios.utils.ScreenUtils;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
@@ -42,12 +42,21 @@ public class AlarmAdapter extends RecyclerView.Adapter<AlarmAdapter.holder> {
|
||||
|
||||
private FragmentActivity mContext;
|
||||
private List<AlarmClockData> mAlarmClockData;
|
||||
private OnLongClickListener mOnLongClickListener;
|
||||
|
||||
public void setAlarmClockData(List<AlarmClockData> alarmClockData) {
|
||||
this.mAlarmClockData = alarmClockData;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setOnLongClickListener(OnLongClickListener onLongClickListener) {
|
||||
this.mOnLongClickListener = onLongClickListener;
|
||||
}
|
||||
|
||||
public interface OnLongClickListener {
|
||||
void onLongClick(AlarmClockData alarmClockData);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
@@ -59,7 +68,7 @@ public class AlarmAdapter extends RecyclerView.Adapter<AlarmAdapter.holder> {
|
||||
public void onBindViewHolder(@NonNull holder holder, int position) {
|
||||
AlarmClockData alarmClockData = mAlarmClockData.get(position);
|
||||
switch (alarmClockData.getType()) {
|
||||
case 1:
|
||||
case AlarmUtils.ONCE:
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
Date date = sdf.parse(alarmClockData.getTime());
|
||||
@@ -69,19 +78,23 @@ public class AlarmAdapter extends RecyclerView.Adapter<AlarmAdapter.holder> {
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
holder.tv_remind_type.setText("单次");
|
||||
holder.tv_remind_type.setText("一次");
|
||||
holder.tv_remind_type.setBackgroundResource(R.drawable.tv_times_bg_once);
|
||||
break;
|
||||
case 2:
|
||||
case AlarmUtils.LOOP:
|
||||
holder.tv_time.setText(alarmClockData.getTime());
|
||||
holder.tv_remind_type.setText("循环");
|
||||
holder.tv_remind_type.setText("每天");
|
||||
holder.tv_remind_type.setBackgroundResource(R.drawable.tv_times_bg_loop);
|
||||
break;
|
||||
case 3:
|
||||
case AlarmUtils.WORKING_DAY:
|
||||
holder.tv_time.setText(alarmClockData.getTime());
|
||||
holder.tv_remind_type.setText("周一至周五");
|
||||
holder.tv_remind_type.setBackgroundResource(R.drawable.tv_times_bg_work);
|
||||
break;
|
||||
case 4:
|
||||
case AlarmUtils.OFF_DAY:
|
||||
holder.tv_time.setText(alarmClockData.getTime());
|
||||
holder.tv_remind_type.setText("周六至周日");
|
||||
holder.tv_remind_type.setBackgroundResource(R.drawable.tv_times_bg_offday);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
@@ -115,17 +128,17 @@ public class AlarmAdapter extends RecyclerView.Adapter<AlarmAdapter.holder> {
|
||||
mMediaPlayer.prepareAsync();
|
||||
FFmpegUtils.getDurationInMilliseconds(voice, new Observer<Integer>() {
|
||||
@Override
|
||||
public void onSubscribe(@io.reactivex.rxjava3.annotations.NonNull Disposable d) {
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@io.reactivex.rxjava3.annotations.NonNull Integer integer) {
|
||||
public void onNext(@NonNull Integer integer) {
|
||||
holder.tv_voice.setText(integer + "秒");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.rxjava3.annotations.NonNull Throwable e) {
|
||||
public void onError(@NonNull Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@@ -141,48 +154,49 @@ public class AlarmAdapter extends RecyclerView.Adapter<AlarmAdapter.holder> {
|
||||
}
|
||||
});
|
||||
}
|
||||
String url = alarmClockData.getFile();
|
||||
String fileName = url.substring(url.lastIndexOf("/") + 1, url.length());
|
||||
String realPath = Utils.getDownLoadPath(mContext) + fileName;
|
||||
File file = new File(realPath);
|
||||
if (file.exists()) {
|
||||
holder.iv_finish.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
holder.iv_finish.setVisibility(View.GONE);
|
||||
}
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
String fileUrl = alarmClockData.getFile();
|
||||
if (TextUtils.isEmpty(fileUrl)) {
|
||||
holder.cl_vp.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.cl_vp.setVisibility(View.VISIBLE);
|
||||
if (isImgUrl(url)) {
|
||||
holder.iv_cover.setVisibility(View.VISIBLE);
|
||||
if (isImgUrl(fileUrl)) {
|
||||
holder.imageView.setVisibility(View.VISIBLE);
|
||||
holder.jz_video.setVisibility(View.GONE);
|
||||
if (!mContext.isDestroyed()) {
|
||||
RequestOptions options = new RequestOptions().transform(new RoundedCorners(ScreenUtils.dip2px(mContext, 16F)));
|
||||
Glide.with(mContext).load(url).apply(options).into(holder.iv_cover);
|
||||
Glide.with(mContext).load(fileUrl).apply(options).into(holder.imageView);
|
||||
}
|
||||
} else {
|
||||
holder.iv_cover.setVisibility(View.GONE);
|
||||
holder.imageView.setVisibility(View.GONE);
|
||||
holder.jz_video.setVisibility(View.VISIBLE);
|
||||
holder.jz_video.setUp(url, "");
|
||||
String fileName = Utils.getFileNamefromURL(fileUrl);
|
||||
File file = new File(Utils.getDownLoadPath(mContext) + fileName);
|
||||
String path;
|
||||
if (file.exists() && !file.isDirectory()) {
|
||||
path = file.getAbsolutePath();
|
||||
} else {
|
||||
path = fileUrl;
|
||||
}
|
||||
holder.jz_video.setUp(path, "");
|
||||
holder.jz_video.startButton.setImageDrawable(mContext.getDrawable(R.drawable.play));
|
||||
FFmpegUtils.loadVideoScreenshot(url, new Observer<Bitmap>() {
|
||||
FFmpegUtils.loadVideoScreenshot(path, new Observer<Bitmap>() {
|
||||
@Override
|
||||
public void onSubscribe(@io.reactivex.rxjava3.annotations.NonNull Disposable d) {
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@io.reactivex.rxjava3.annotations.NonNull Bitmap bitmap) {
|
||||
public void onNext(@NonNull Bitmap bitmap) {
|
||||
if (!mContext.isDestroyed()) {
|
||||
RequestOptions options = new RequestOptions().transform(new RoundedCorners(ScreenUtils.dip2px(mContext, 16F)));
|
||||
Glide.with(mContext).load(bitmap).apply(options).into(holder.jz_video.posterImageView);
|
||||
// Glide.with(mContext).load(bitmap).into(holder.imageView);
|
||||
}
|
||||
holder.jz_video.startButton.setImageDrawable(mContext.getDrawable(R.drawable.play));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.rxjava3.annotations.NonNull Throwable e) {
|
||||
public void onError(@NonNull Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@@ -194,7 +208,21 @@ public class AlarmAdapter extends RecyclerView.Adapter<AlarmAdapter.holder> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
holder.root.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
mOnLongClickListener.onLongClick(alarmClockData);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(mContext, AlarmClockEditActivity.class);
|
||||
intent.putExtra("id", alarmClockData.getId());
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -214,10 +242,9 @@ public class AlarmAdapter extends RecyclerView.Adapter<AlarmAdapter.holder> {
|
||||
|
||||
class holder extends RecyclerView.ViewHolder {
|
||||
TextView tv_time, tv_remind_type, tv_title, tv_voice;
|
||||
ConstraintLayout cl_voice, cl_vp;
|
||||
ConstraintLayout cl_voice, cl_vp, root;
|
||||
JzvdStdRound jz_video;
|
||||
ImageView iv_cover, iv_finish;
|
||||
Switch switch1;
|
||||
ImageView imageView;
|
||||
|
||||
public holder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
@@ -226,11 +253,11 @@ public class AlarmAdapter extends RecyclerView.Adapter<AlarmAdapter.holder> {
|
||||
tv_title = itemView.findViewById(R.id.tv_title);
|
||||
tv_voice = itemView.findViewById(R.id.tv_voice);
|
||||
cl_voice = itemView.findViewById(R.id.cl_voice);
|
||||
switch1 = itemView.findViewById(R.id.switch1);
|
||||
cl_vp = itemView.findViewById(R.id.cl_vp);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
jz_video = itemView.findViewById(R.id.jz_video);
|
||||
iv_cover = itemView.findViewById(R.id.iv_cover);
|
||||
iv_finish = itemView.findViewById(R.id.iv_finish);
|
||||
imageView = itemView.findViewById(R.id.imageView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.uiuios.aios.bean;
|
||||
package com.uiuios.aios.alarm;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -8,13 +8,13 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AlarmClockData implements Serializable {
|
||||
private static final long serialVersionUID = -5856502480745183157L;
|
||||
@@ -26,10 +26,14 @@ public class AlarmClockData implements Serializable {
|
||||
String voice;//语音文件地址
|
||||
String voice_md5;
|
||||
String file;//图片或视频文件地址
|
||||
String file_md5;
|
||||
int remind_type;
|
||||
int is_onoff;//0关闭 1开启
|
||||
|
||||
boolean finished = false;
|
||||
boolean is_local = false;
|
||||
boolean edited = false;
|
||||
boolean deleted = false;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
@@ -87,6 +91,14 @@ public class AlarmClockData implements Serializable {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public String getFile_md5() {
|
||||
return file_md5;
|
||||
}
|
||||
|
||||
public void setFile_md5(String file_md5) {
|
||||
this.file_md5 = file_md5;
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
@@ -111,6 +123,30 @@ public class AlarmClockData implements Serializable {
|
||||
this.is_onoff = is_onoff;
|
||||
}
|
||||
|
||||
public boolean isIs_local() {
|
||||
return is_local;
|
||||
}
|
||||
|
||||
public void setIs_local(boolean is_local) {
|
||||
this.is_local = is_local;
|
||||
}
|
||||
|
||||
public boolean isEdited() {
|
||||
return edited;
|
||||
}
|
||||
|
||||
public void setEdited(boolean edited) {
|
||||
this.edited = edited;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
public long getTimeStamp() {
|
||||
if (TextUtils.isEmpty(time)) {
|
||||
return 0L;
|
||||
@@ -151,11 +187,12 @@ public class AlarmClockData implements Serializable {
|
||||
if (!(obj instanceof AlarmClockData)) return false;
|
||||
if (id != ((AlarmClockData) obj).id) return false;
|
||||
if (type != ((AlarmClockData) obj).type) return false;
|
||||
if (!time.equals(((AlarmClockData) obj).time)) return false;
|
||||
if (!title.equals(((AlarmClockData) obj).title)) return false;
|
||||
if (!voice.equals(((AlarmClockData) obj).voice)) return false;
|
||||
if (!voice_md5.equals(((AlarmClockData) obj).voice_md5)) return false;
|
||||
if (!file.equals(((AlarmClockData) obj).file)) return false;
|
||||
if (!Objects.equals(time, ((AlarmClockData) obj).time)) return false;
|
||||
if (!Objects.equals(title, ((AlarmClockData) obj).title)) return false;
|
||||
if (!Objects.equals(voice, ((AlarmClockData) obj).voice)) return false;
|
||||
if (!Objects.equals(voice_md5, ((AlarmClockData) obj).voice_md5)) return false;
|
||||
if (!Objects.equals(file, ((AlarmClockData) obj).file)) return false;
|
||||
if (!Objects.equals(file_md5, ((AlarmClockData) obj).file_md5)) return false;
|
||||
if (remind_type != ((AlarmClockData) obj).remind_type) return false;
|
||||
if (is_onoff != ((AlarmClockData) obj).is_onoff) return false;
|
||||
|
||||
@@ -3,15 +3,15 @@ package com.uiuios.aios.alarm;
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.os.Environment;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class AlarmOpenHelper extends SQLiteOpenHelper {
|
||||
|
||||
public static final int DATABASE_VERSION = 1;
|
||||
public static final int DATABASE_VERSION = 2;
|
||||
public static final String DATABASE_NAME = "AlarmDatabase.db";
|
||||
public static final String DATABASE_FILE_NAME = Environment.getExternalStorageDirectory().getPath() + File.separator + DATABASE_NAME;
|
||||
// public static final String DATABASE_FILE_NAME = Environment.getExternalStorageDirectory().getPath() + File.separator + DATABASE_NAME;
|
||||
public static final String DATABASE_FILE_NAME = File.separator + DATABASE_NAME;
|
||||
|
||||
public static final String TABLE_ALARM = " AlarmTable";
|
||||
|
||||
@@ -22,9 +22,15 @@ public class AlarmOpenHelper extends SQLiteOpenHelper {
|
||||
public static final String KEY_VOICE = "voice";
|
||||
public static final String KEY_VOICE_MD5 = "voice_md5";
|
||||
public static final String KEY_FILE = "file";
|
||||
public static final String KEY_FILE_MD5 = "file_md5";
|
||||
public static final String KEY_REMIND_TYPE = "remind_type";
|
||||
public static final String KEY_IS_ONOFF = "is_onoff";
|
||||
|
||||
public static final String KEY_FINISHED = "finished";
|
||||
public static final String KEY_IS_LOCAL = "is_local";
|
||||
public static final String KEY_EDITED = "edited";
|
||||
public static final String KEY_DELETED = "deleted";
|
||||
|
||||
|
||||
String CREATE_ALARM_TABLE = "CREATE TABLE IF NOT EXISTS" + TABLE_ALARM +
|
||||
"("
|
||||
@@ -35,9 +41,14 @@ public class AlarmOpenHelper extends SQLiteOpenHelper {
|
||||
+ KEY_VOICE + " TEXT,"
|
||||
+ KEY_VOICE_MD5 + " TEXT,"
|
||||
+ KEY_FILE + " TEXT,"
|
||||
+ KEY_FILE_MD5 + " TEXT,"
|
||||
+ KEY_REMIND_TYPE + " INTEGER,"
|
||||
+ KEY_IS_ONOFF + " INTEGER,"
|
||||
+ KEY_FINISHED + " BOOLEAN DEFAULT 0"
|
||||
|
||||
+ KEY_FINISHED + " BOOLEAN DEFAULT 0,"
|
||||
+ KEY_IS_LOCAL + " BOOLEAN DEFAULT 0,"
|
||||
+ KEY_EDITED + " BOOLEAN DEFAULT 0,"
|
||||
+ KEY_DELETED + " BOOLEAN DEFAULT 0"
|
||||
+ ")";
|
||||
|
||||
public AlarmOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
|
||||
@@ -51,10 +62,16 @@ public class AlarmOpenHelper extends SQLiteOpenHelper {
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
if (oldVersion >= newVersion) {
|
||||
return;
|
||||
switch (oldVersion + 1) {
|
||||
case 1:
|
||||
db.execSQL(CREATE_ALARM_TABLE); // 执行修改表,添加字段的逻辑。
|
||||
case 2:
|
||||
String sql = "ALTER TABLE " + TABLE_ALARM + " ADD COLUMN " + KEY_EDITED + " BOOLEAN DEFAULT 0";
|
||||
db.execSQL(sql);
|
||||
String sql2 = "ALTER TABLE " + TABLE_ALARM + " ADD COLUMN " + KEY_DELETED + " BOOLEAN DEFAULT 0";
|
||||
db.execSQL(sql2);
|
||||
String sql3 = "ALTER TABLE " + TABLE_ALARM + " ADD COLUMN " + KEY_FILE_MD5 + " TEXT";
|
||||
db.execSQL(sql3);
|
||||
}
|
||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_ALARM);
|
||||
onCreate(db);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@ import android.util.Log;
|
||||
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.blankj.utilcode.util.FileUtils;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.service.main.MainService;
|
||||
import com.uiuios.aios.utils.FileUtil;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
@@ -35,23 +33,33 @@ import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class AlarmUtils {
|
||||
private static final String TAG = AlarmUtils.class.getSimpleName();
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static AlarmUtils sInstance;
|
||||
private static String TAG = AlarmUtils.class.getSimpleName();
|
||||
private Context mContext;
|
||||
private AlarmManager alarmManager;
|
||||
private SQLiteDatabase db;
|
||||
private AlarmManager mAlarmManager;
|
||||
private SQLiteDatabase mDatabase;
|
||||
private AlarmOpenHelper mAlarmOpenHelper;
|
||||
private HashSet<PendingIntent> pendingIntents;
|
||||
|
||||
public static final int ONE_DAY_TIME = 1000 * 60 * 60 * 24;
|
||||
|
||||
/*一次性*/
|
||||
public static final int ONCE = 1;
|
||||
/*每天*/
|
||||
public static final int LOOP = 2;
|
||||
/*周一到周五*/
|
||||
public static final int WORKING_DAY = 3;
|
||||
/*休息日*/
|
||||
public static final int OFF_DAY = 4;
|
||||
|
||||
private AlarmUtils(Context context) {
|
||||
this.mContext = context;
|
||||
// this.mAlarmOpenHelper = new AlarmOpenHelper(context, AlarmOpenHelper.DATABASE_NAME, null, AlarmOpenHelper.DATABASE_VERSION);
|
||||
this.mAlarmOpenHelper = new AlarmOpenHelper(context, AlarmOpenHelper.DATABASE_FILE_NAME, null, AlarmOpenHelper.DATABASE_VERSION);
|
||||
this.db = mAlarmOpenHelper.getWritableDatabase();
|
||||
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
this.mAlarmOpenHelper = new AlarmOpenHelper(context, mContext.getExternalCacheDir() + AlarmOpenHelper.DATABASE_FILE_NAME, null, AlarmOpenHelper.DATABASE_VERSION);
|
||||
this.mDatabase = mAlarmOpenHelper.getWritableDatabase();
|
||||
this.mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
@@ -65,15 +73,35 @@ public class AlarmUtils {
|
||||
|
||||
public static AlarmUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init AmapManager first");
|
||||
throw new IllegalStateException("You must be init AlarmUtils first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private void open() {
|
||||
if (db == null || !db.isOpen()) {
|
||||
db = mAlarmOpenHelper.getWritableDatabase();
|
||||
}
|
||||
private void openDatabase() {
|
||||
// if (mDatabase == null || !mDatabase.isOpen()) {
|
||||
// mDatabase = mAlarmOpenHelper.getWritableDatabase();
|
||||
// }
|
||||
}
|
||||
|
||||
private ContentValues getValuesFromAlarmClock(AlarmClockData alarmClockData) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(AlarmOpenHelper.KEY_ID, alarmClockData.getId());
|
||||
values.put(AlarmOpenHelper.KEY_TYPE, alarmClockData.getType());
|
||||
values.put(AlarmOpenHelper.KEY_TIME, alarmClockData.getTime());
|
||||
values.put(AlarmOpenHelper.KEY_TITLE, alarmClockData.getTitle());
|
||||
values.put(AlarmOpenHelper.KEY_VOICE, alarmClockData.getVoice());
|
||||
values.put(AlarmOpenHelper.KEY_VOICE_MD5, alarmClockData.getVoice_md5());
|
||||
values.put(AlarmOpenHelper.KEY_FILE, alarmClockData.getFile());
|
||||
values.put(AlarmOpenHelper.KEY_FILE_MD5, alarmClockData.getFile_md5());
|
||||
values.put(AlarmOpenHelper.KEY_REMIND_TYPE, alarmClockData.getRemind_type());
|
||||
values.put(AlarmOpenHelper.KEY_IS_ONOFF, alarmClockData.getIs_onoff());
|
||||
|
||||
values.put(AlarmOpenHelper.KEY_FINISHED, alarmClockData.isFinished());
|
||||
values.put(AlarmOpenHelper.KEY_IS_LOCAL, alarmClockData.isIs_local());
|
||||
values.put(AlarmOpenHelper.KEY_EDITED, alarmClockData.isEdited());
|
||||
values.put(AlarmOpenHelper.KEY_DELETED, alarmClockData.isDeleted());
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,27 +111,19 @@ public class AlarmUtils {
|
||||
* @return
|
||||
*/
|
||||
public boolean addAlarmClock(AlarmClockData alarmClockData) {
|
||||
open();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(AlarmOpenHelper.KEY_ID, alarmClockData.getId());
|
||||
values.put(AlarmOpenHelper.KEY_TYPE, alarmClockData.getType());
|
||||
values.put(AlarmOpenHelper.KEY_TIME, alarmClockData.getTime());
|
||||
values.put(AlarmOpenHelper.KEY_TITLE, alarmClockData.getTitle());
|
||||
values.put(AlarmOpenHelper.KEY_VOICE, alarmClockData.getVoice());
|
||||
values.put(AlarmOpenHelper.KEY_VOICE_MD5, alarmClockData.getVoice_md5());
|
||||
values.put(AlarmOpenHelper.KEY_FILE, alarmClockData.getFile());
|
||||
values.put(AlarmOpenHelper.KEY_REMIND_TYPE, alarmClockData.getRemind_type());
|
||||
values.put(AlarmOpenHelper.KEY_IS_ONOFF, alarmClockData.getIs_onoff());
|
||||
openDatabase();
|
||||
ContentValues values = getValuesFromAlarmClock(alarmClockData);
|
||||
long id = 0;
|
||||
db.beginTransaction();
|
||||
mDatabase.beginTransaction();
|
||||
try {
|
||||
id = db.insert(AlarmOpenHelper.TABLE_ALARM, null, values);
|
||||
id = mDatabase.insertWithOnConflict(AlarmOpenHelper.TABLE_ALARM, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
mDatabase.setTransactionSuccessful();
|
||||
} catch (Exception e) {
|
||||
db.setTransactionSuccessful();
|
||||
Log.e(TAG, "addAlarmClock: " + e.getMessage());
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
mDatabase.endTransaction();
|
||||
}
|
||||
db.close();
|
||||
setAlarm(alarmClockData);
|
||||
return id > 0;
|
||||
}
|
||||
|
||||
@@ -115,28 +135,53 @@ public class AlarmUtils {
|
||||
* @return
|
||||
*/
|
||||
public boolean updateAlarmClock(AlarmClockData alarmClockData) {
|
||||
open();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(AlarmOpenHelper.KEY_ID, alarmClockData.getId());
|
||||
values.put(AlarmOpenHelper.KEY_TYPE, alarmClockData.getType());
|
||||
values.put(AlarmOpenHelper.KEY_TIME, alarmClockData.getTime());
|
||||
values.put(AlarmOpenHelper.KEY_TITLE, alarmClockData.getTitle());
|
||||
values.put(AlarmOpenHelper.KEY_VOICE, alarmClockData.getVoice());
|
||||
values.put(AlarmOpenHelper.KEY_VOICE_MD5, alarmClockData.getVoice_md5());
|
||||
values.put(AlarmOpenHelper.KEY_FILE, alarmClockData.getFile());
|
||||
values.put(AlarmOpenHelper.KEY_REMIND_TYPE, alarmClockData.getRemind_type());
|
||||
values.put(AlarmOpenHelper.KEY_IS_ONOFF, alarmClockData.getIs_onoff());
|
||||
openDatabase();
|
||||
AlarmClockData old = getDatabaseSingleAlarm(alarmClockData);
|
||||
if (old != null) {
|
||||
PendingIntent pendingIntent = getPendingIntent(old);
|
||||
if (pendingIntent != null) {
|
||||
mAlarmManager.cancel(pendingIntent);
|
||||
}
|
||||
}
|
||||
ContentValues values = getValuesFromAlarmClock(alarmClockData);
|
||||
long id = 0;
|
||||
db.beginTransaction();
|
||||
mDatabase.beginTransaction();
|
||||
try {
|
||||
id = db.insertWithOnConflict(AlarmOpenHelper.TABLE_ALARM, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
db.setTransactionSuccessful();
|
||||
id = mDatabase.insertWithOnConflict(AlarmOpenHelper.TABLE_ALARM, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
mDatabase.setTransactionSuccessful();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "updateAlarmClock: " + e.getMessage());
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
mDatabase.endTransaction();
|
||||
}
|
||||
db.close();
|
||||
setAlarm(alarmClockData);
|
||||
return id > 0;
|
||||
}
|
||||
|
||||
public boolean updateAlarmClock(AlarmClockData alarmClockData, int newId) {
|
||||
openDatabase();
|
||||
int oldId = alarmClockData.getId();
|
||||
AlarmClockData old = getDatabaseSingleAlarm(alarmClockData);
|
||||
if (old != null) {
|
||||
// deleteAlarmClock(oldId);
|
||||
PendingIntent pendingIntent = getPendingIntent(old);
|
||||
if (pendingIntent != null) {
|
||||
mAlarmManager.cancel(pendingIntent);
|
||||
}
|
||||
}
|
||||
alarmClockData.setId(newId);
|
||||
ContentValues values = getValuesFromAlarmClock(alarmClockData);
|
||||
long id = 0;
|
||||
mDatabase.beginTransaction();
|
||||
try {
|
||||
id = mDatabase.update(AlarmOpenHelper.TABLE_ALARM, values, "id=" + oldId, null);
|
||||
mDatabase.setTransactionSuccessful();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "updateAlarmClock: " + e.getMessage());
|
||||
} finally {
|
||||
mDatabase.endTransaction();
|
||||
}
|
||||
setAlarm(alarmClockData);
|
||||
return id > 0;
|
||||
}
|
||||
|
||||
@@ -145,35 +190,24 @@ public class AlarmUtils {
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
public void insertListValues(List<AlarmClockData> list) {
|
||||
open();
|
||||
public void insertAlarmClockList(List<AlarmClockData> list) {
|
||||
openDatabase();
|
||||
List<ContentValues> contentValuesList = new ArrayList<>();
|
||||
for (AlarmClockData alarmClockData : list) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(AlarmOpenHelper.KEY_ID, alarmClockData.getId());
|
||||
values.put(AlarmOpenHelper.KEY_TYPE, alarmClockData.getType());
|
||||
values.put(AlarmOpenHelper.KEY_TIME, alarmClockData.getTime());
|
||||
values.put(AlarmOpenHelper.KEY_TITLE, alarmClockData.getTitle());
|
||||
values.put(AlarmOpenHelper.KEY_VOICE, alarmClockData.getVoice());
|
||||
values.put(AlarmOpenHelper.KEY_VOICE_MD5, alarmClockData.getVoice_md5());
|
||||
values.put(AlarmOpenHelper.KEY_FILE, alarmClockData.getFile());
|
||||
values.put(AlarmOpenHelper.KEY_REMIND_TYPE, alarmClockData.getRemind_type());
|
||||
values.put(AlarmOpenHelper.KEY_IS_ONOFF, alarmClockData.getIs_onoff());
|
||||
values.put(AlarmOpenHelper.KEY_FINISHED, alarmClockData.isFinished());
|
||||
ContentValues values = getValuesFromAlarmClock(alarmClockData);
|
||||
contentValuesList.add(values);
|
||||
}
|
||||
db.beginTransaction();
|
||||
mDatabase.beginTransaction();
|
||||
try {
|
||||
for (ContentValues v : contentValuesList) {
|
||||
db.insertWithOnConflict(AlarmOpenHelper.TABLE_ALARM, null, v, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
mDatabase.insertWithOnConflict(AlarmOpenHelper.TABLE_ALARM, null, v, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
}
|
||||
db.setTransactionSuccessful();
|
||||
mDatabase.setTransactionSuccessful();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "insertListValues: " + e.getMessage());
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
mDatabase.endTransaction();
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,36 +218,42 @@ public class AlarmUtils {
|
||||
*/
|
||||
public boolean deleteAlarmClock(AlarmClockData alarmClockData) {
|
||||
if (alarmClockData == null) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
PendingIntent pendingIntent = getPendingIntent(alarmClockData);
|
||||
if (pendingIntent != null) {
|
||||
mAlarmManager.cancel(pendingIntent);
|
||||
}
|
||||
return deleteAlarmClock(alarmClockData.getId());
|
||||
}
|
||||
|
||||
public boolean deleteAlarmClock(int RowID) {
|
||||
open();
|
||||
openDatabase();
|
||||
long id = 0;
|
||||
db.beginTransaction();
|
||||
mDatabase.beginTransaction();
|
||||
try {
|
||||
id = db.delete(AlarmOpenHelper.TABLE_ALARM, "id =" + RowID, null);
|
||||
db.setTransactionSuccessful();
|
||||
id = mDatabase.delete(AlarmOpenHelper.TABLE_ALARM, " id =" + RowID, null);
|
||||
mDatabase.setTransactionSuccessful();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "deleteAlarmClock: " + e.getMessage());
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
mDatabase.endTransaction();
|
||||
}
|
||||
db.close();
|
||||
return id > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除所有闹钟
|
||||
*/
|
||||
public void deleteAllAlarmClock() {
|
||||
HashSet<PendingIntent> pendingIntents = getOldPendingIntents();
|
||||
HashSet<PendingIntent> pendingIntents = getOldPendingIntentsSet();
|
||||
Iterator<PendingIntent> pendingIntentIterator = pendingIntents.iterator();
|
||||
while (pendingIntentIterator.hasNext()) {
|
||||
PendingIntent pendingIntent = pendingIntentIterator.next();
|
||||
alarmManager.cancel(pendingIntent);
|
||||
mAlarmManager.cancel(pendingIntent);
|
||||
pendingIntentIterator.remove();
|
||||
}
|
||||
List<AlarmClockData> alarmClockData = getAllAlarms();
|
||||
List<AlarmClockData> alarmClockData = getDatabaseAlarms();
|
||||
for (AlarmClockData data : alarmClockData) {
|
||||
deleteAlarmClock(data.getId());
|
||||
}
|
||||
@@ -224,12 +264,11 @@ public class AlarmUtils {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<AlarmClockData> getAllAlarms() {
|
||||
open();
|
||||
public List<AlarmClockData> getDatabaseAlarms() {
|
||||
openDatabase();
|
||||
List<AlarmClockData> list = new ArrayList<>();
|
||||
String selectQuery = "SELECT * FROM " + AlarmOpenHelper.TABLE_ALARM;
|
||||
open();
|
||||
Cursor cursor = db.rawQuery(selectQuery, null);
|
||||
Cursor cursor = mDatabase.rawQuery(selectQuery, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
AlarmClockData alarmClockData = new AlarmClockData();
|
||||
@@ -240,23 +279,139 @@ public class AlarmUtils {
|
||||
alarmClockData.setVoice(cursor.getString(4));
|
||||
alarmClockData.setVoice_md5(cursor.getString(5));
|
||||
alarmClockData.setFile(cursor.getString(6));
|
||||
alarmClockData.setRemind_type(cursor.getInt(7));
|
||||
alarmClockData.setIs_onoff(cursor.getInt(8));
|
||||
if (cursor.getInt(9) == 1) {
|
||||
alarmClockData.setFinished(true);
|
||||
} else {
|
||||
alarmClockData.setFinished(false);
|
||||
}
|
||||
alarmClockData.setFile_md5(cursor.getString(7));
|
||||
alarmClockData.setRemind_type(cursor.getInt(8));
|
||||
alarmClockData.setIs_onoff(cursor.getInt(9));
|
||||
alarmClockData.setFinished(cursor.getInt(10) == 1);
|
||||
alarmClockData.setIs_local(cursor.getInt(11) == 1);
|
||||
alarmClockData.setEdited(cursor.getInt(12) == 1);
|
||||
alarmClockData.setDeleted(cursor.getInt(13) == 1);
|
||||
list.add(alarmClockData);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 获取单个闹钟
|
||||
*/
|
||||
public AlarmClockData getDatabaseSingleAlarm(AlarmClockData data) {
|
||||
openDatabase();
|
||||
List<AlarmClockData> list = new ArrayList<>();
|
||||
String selectQuery = "SELECT * FROM " + AlarmOpenHelper.TABLE_ALARM + " where id =" + data.getId();
|
||||
Cursor cursor = mDatabase.rawQuery(selectQuery, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
AlarmClockData alarmClockData = new AlarmClockData();
|
||||
alarmClockData.setId(Integer.parseInt(cursor.getString(0)));
|
||||
alarmClockData.setType(cursor.getInt(1));
|
||||
alarmClockData.setTime(cursor.getString(2));
|
||||
alarmClockData.setTitle(cursor.getString(3));
|
||||
alarmClockData.setVoice(cursor.getString(4));
|
||||
alarmClockData.setVoice_md5(cursor.getString(5));
|
||||
alarmClockData.setFile(cursor.getString(6));
|
||||
alarmClockData.setFile_md5(cursor.getString(7));
|
||||
alarmClockData.setRemind_type(cursor.getInt(8));
|
||||
alarmClockData.setIs_onoff(cursor.getInt(9));
|
||||
alarmClockData.setFinished(cursor.getInt(10) == 1);
|
||||
alarmClockData.setIs_local(cursor.getInt(11) == 1);
|
||||
alarmClockData.setEdited(cursor.getInt(12) == 1);
|
||||
alarmClockData.setDeleted(cursor.getInt(13) == 1);
|
||||
list.add(alarmClockData);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
return list.size() == 0 ? null : list.get(0);
|
||||
}
|
||||
|
||||
public AlarmClockData getDatabaseSingleAlarm(int id) {
|
||||
openDatabase();
|
||||
List<AlarmClockData> list = new ArrayList<>();
|
||||
String selectQuery = "SELECT * FROM " + AlarmOpenHelper.TABLE_ALARM + " where id =" + id;
|
||||
Cursor cursor = mDatabase.rawQuery(selectQuery, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
AlarmClockData alarmClockData = new AlarmClockData();
|
||||
alarmClockData.setId(Integer.parseInt(cursor.getString(0)));
|
||||
alarmClockData.setType(cursor.getInt(1));
|
||||
alarmClockData.setTime(cursor.getString(2));
|
||||
alarmClockData.setTitle(cursor.getString(3));
|
||||
alarmClockData.setVoice(cursor.getString(4));
|
||||
alarmClockData.setVoice_md5(cursor.getString(5));
|
||||
alarmClockData.setFile(cursor.getString(6));
|
||||
alarmClockData.setFile_md5(cursor.getString(7));
|
||||
alarmClockData.setRemind_type(cursor.getInt(8));
|
||||
alarmClockData.setIs_onoff(cursor.getInt(9));
|
||||
alarmClockData.setFinished(cursor.getInt(10) == 1);
|
||||
alarmClockData.setIs_local(cursor.getInt(11) == 1);
|
||||
alarmClockData.setEdited(cursor.getInt(12) == 1);
|
||||
alarmClockData.setDeleted(cursor.getInt(13) == 1);
|
||||
list.add(alarmClockData);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
return list.size() == 0 ? null : list.get(0);
|
||||
}
|
||||
|
||||
public List<AlarmClockData> getDeletedAlarm() {
|
||||
openDatabase();
|
||||
List<AlarmClockData> list = new ArrayList<>();
|
||||
String selectQuery = "SELECT * FROM " + AlarmOpenHelper.TABLE_ALARM + " where deleted = 1";
|
||||
Cursor cursor = mDatabase.rawQuery(selectQuery, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
AlarmClockData alarmClockData = new AlarmClockData();
|
||||
alarmClockData.setId(Integer.parseInt(cursor.getString(0)));
|
||||
alarmClockData.setType(cursor.getInt(1));
|
||||
alarmClockData.setTime(cursor.getString(2));
|
||||
alarmClockData.setTitle(cursor.getString(3));
|
||||
alarmClockData.setVoice(cursor.getString(4));
|
||||
alarmClockData.setVoice_md5(cursor.getString(5));
|
||||
alarmClockData.setFile(cursor.getString(6));
|
||||
alarmClockData.setFile_md5(cursor.getString(7));
|
||||
alarmClockData.setRemind_type(cursor.getInt(8));
|
||||
alarmClockData.setIs_onoff(cursor.getInt(9));
|
||||
alarmClockData.setFinished(cursor.getInt(10) == 1);
|
||||
alarmClockData.setIs_local(cursor.getInt(11) == 1);
|
||||
alarmClockData.setEdited(cursor.getInt(12) == 1);
|
||||
alarmClockData.setDeleted(cursor.getInt(13) == 1);
|
||||
list.add(alarmClockData);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<AlarmClockData> getLocalAddAlarm() {
|
||||
openDatabase();
|
||||
List<AlarmClockData> list = new ArrayList<>();
|
||||
String selectQuery = "SELECT * FROM " + AlarmOpenHelper.TABLE_ALARM + " where is_local = 1";
|
||||
Cursor cursor = mDatabase.rawQuery(selectQuery, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
AlarmClockData alarmClockData = new AlarmClockData();
|
||||
alarmClockData.setId(Integer.parseInt(cursor.getString(0)));
|
||||
alarmClockData.setType(cursor.getInt(1));
|
||||
alarmClockData.setTime(cursor.getString(2));
|
||||
alarmClockData.setTitle(cursor.getString(3));
|
||||
alarmClockData.setVoice(cursor.getString(4));
|
||||
alarmClockData.setVoice_md5(cursor.getString(5));
|
||||
alarmClockData.setFile(cursor.getString(6));
|
||||
alarmClockData.setFile_md5(cursor.getString(7));
|
||||
alarmClockData.setRemind_type(cursor.getInt(8));
|
||||
alarmClockData.setIs_onoff(cursor.getInt(9));
|
||||
alarmClockData.setFinished(cursor.getInt(10) == 1);
|
||||
alarmClockData.setIs_local(cursor.getInt(11) == 1);
|
||||
alarmClockData.setEdited(cursor.getInt(12) == 1);
|
||||
alarmClockData.setDeleted(cursor.getInt(13) == 1);
|
||||
list.add(alarmClockData);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
return list;
|
||||
}
|
||||
|
||||
private HashSet<PendingIntent> pendingIntents;
|
||||
|
||||
/**
|
||||
* 设置闹钟列表
|
||||
@@ -265,58 +420,54 @@ public class AlarmUtils {
|
||||
*/
|
||||
public void setAlarmClockData(List<AlarmClockData> data) {
|
||||
if (pendingIntents == null) {
|
||||
pendingIntents = getOldPendingIntents();
|
||||
pendingIntents = getOldPendingIntentsSet();
|
||||
}
|
||||
Iterator<PendingIntent> pendingIntentIterator = pendingIntents.iterator();
|
||||
while (pendingIntentIterator.hasNext()) {
|
||||
PendingIntent pendingIntent = pendingIntentIterator.next();
|
||||
alarmManager.cancel(pendingIntent);
|
||||
mAlarmManager.cancel(pendingIntent);
|
||||
pendingIntentIterator.remove();
|
||||
}
|
||||
// for (PendingIntent pendingIntent : pendingIntents) {
|
||||
//
|
||||
// }
|
||||
List<AlarmClockData> newData = mergeData(data);
|
||||
for (AlarmClockData clockData : newData) {
|
||||
setAlarm(clockData);
|
||||
checkResource(clockData.getFile());
|
||||
}
|
||||
insertListValues(newData);
|
||||
insertAlarmClockList(newData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url 下载资源
|
||||
*/
|
||||
private void checkResource(String url) {
|
||||
if (TextUtils.isEmpty(url))
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
return;
|
||||
}
|
||||
String fileName = url.substring(url.lastIndexOf("/") + 1, url.length());
|
||||
if (FileUtil.isVideoFile(fileName)) {
|
||||
String realPath = Utils.getDownLoadPath(mContext) + fileName;
|
||||
File file = new File(realPath);
|
||||
if (!file.exists()) {
|
||||
Aria.download(this)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(Utils.getDownLoadPath(mContext) + fileName)
|
||||
// .ignoreFilePathOccupy()
|
||||
.create(); //启动下载}
|
||||
}
|
||||
}else if (FileUtil.isPictureFile(fileName)){
|
||||
Glide.with(mContext).load(url);
|
||||
String realPath = Utils.getDownLoadPath(mContext) + fileName;
|
||||
File file = new File(realPath);
|
||||
if (!file.exists()) {
|
||||
Aria.download(this)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(Utils.getDownLoadPath(mContext) + fileName)
|
||||
.create(); //启动下载}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并闹钟列表,删除不存在闹钟
|
||||
*
|
||||
* @param alarmClockDataList
|
||||
* @return
|
||||
* @param newAlarmClockDataList
|
||||
* @return 新增的闹钟
|
||||
*/
|
||||
private List<AlarmClockData> mergeData(List<AlarmClockData> alarmClockDataList) {
|
||||
private List<AlarmClockData> mergeData(List<AlarmClockData> newAlarmClockDataList) {
|
||||
HashMap<Integer, AlarmClockData> alarmClockDataMap = new HashMap<>();
|
||||
if (alarmClockDataList != null) {
|
||||
for (AlarmClockData alarmClockData : alarmClockDataList) {
|
||||
if (newAlarmClockDataList != null) {
|
||||
for (AlarmClockData alarmClockData : newAlarmClockDataList) {
|
||||
alarmClockDataMap.put(alarmClockData.getId(), alarmClockData);
|
||||
}
|
||||
}
|
||||
HashMap<Integer, AlarmClockData> oldData = getOldData();
|
||||
HashMap<Integer, AlarmClockData> oldData = getOldDataMap();
|
||||
List<AlarmClockData> deleteData = new ArrayList<>();
|
||||
for (Map.Entry<Integer, AlarmClockData> entry : oldData.entrySet()) {
|
||||
if (alarmClockDataMap.get(entry.getKey()) == null) {
|
||||
@@ -324,14 +475,18 @@ public class AlarmUtils {
|
||||
}
|
||||
}
|
||||
for (AlarmClockData alarmClockData : deleteData) {
|
||||
if (alarmClockData.isIs_local() || alarmClockData.deleted) {
|
||||
Log.e(TAG, "mergeData: skip " + alarmClockData.getId());
|
||||
continue;
|
||||
}
|
||||
deleteAlarmClock(alarmClockData);
|
||||
}
|
||||
|
||||
List<AlarmClockData> newData = new ArrayList<>();
|
||||
if (alarmClockDataList == null) {
|
||||
if (newAlarmClockDataList == null) {
|
||||
return newData;
|
||||
}
|
||||
for (AlarmClockData alarm : alarmClockDataList) {
|
||||
for (AlarmClockData alarm : newAlarmClockDataList) {
|
||||
AlarmClockData oldAlarm = oldData.get(alarm.getId());
|
||||
if (oldAlarm == null) {
|
||||
newData.add(alarm);
|
||||
@@ -353,53 +508,48 @@ public class AlarmUtils {
|
||||
* @return
|
||||
*/
|
||||
public boolean updateAlarmFinished(AlarmClockData alarmClockData) {
|
||||
open();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(AlarmOpenHelper.KEY_ID, alarmClockData.getId());
|
||||
values.put(AlarmOpenHelper.KEY_TYPE, alarmClockData.getType());
|
||||
values.put(AlarmOpenHelper.KEY_TIME, alarmClockData.getTime());
|
||||
values.put(AlarmOpenHelper.KEY_TITLE, alarmClockData.getTitle());
|
||||
values.put(AlarmOpenHelper.KEY_VOICE, alarmClockData.getVoice());
|
||||
values.put(AlarmOpenHelper.KEY_VOICE_MD5, alarmClockData.getVoice_md5());
|
||||
values.put(AlarmOpenHelper.KEY_FILE, alarmClockData.getFile());
|
||||
values.put(AlarmOpenHelper.KEY_REMIND_TYPE, alarmClockData.getRemind_type());
|
||||
values.put(AlarmOpenHelper.KEY_IS_ONOFF, alarmClockData.getIs_onoff());
|
||||
values.put(AlarmOpenHelper.KEY_FINISHED, alarmClockData.isFinished());
|
||||
openDatabase();
|
||||
ContentValues values = getValuesFromAlarmClock(alarmClockData);
|
||||
long id = 0;
|
||||
db.beginTransaction();
|
||||
mDatabase.beginTransaction();
|
||||
try {
|
||||
id = db.update(AlarmOpenHelper.TABLE_ALARM, values, AlarmOpenHelper.KEY_ID + "=?", new String[]{String.valueOf(alarmClockData.getId())});
|
||||
db.setTransactionSuccessful();
|
||||
id = mDatabase.update(AlarmOpenHelper.TABLE_ALARM, values, AlarmOpenHelper.KEY_ID + "=?", new String[]{String.valueOf(alarmClockData.getId())});
|
||||
mDatabase.setTransactionSuccessful();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "updateAlarmFinished: " + e.getMessage());
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
mDatabase.endTransaction();
|
||||
}
|
||||
db.close();
|
||||
return id > 0;
|
||||
}
|
||||
|
||||
public HashMap<Integer, AlarmClockData> getOldData() {
|
||||
List<AlarmClockData> alarmClockData = getAllAlarms();
|
||||
if (alarmClockData == null || alarmClockData.size() == 0) {
|
||||
return new HashMap<>();
|
||||
} else {
|
||||
HashMap<Integer, AlarmClockData> hashMap = new HashMap<>();
|
||||
public List<AlarmClockData> getOldData() {
|
||||
List<AlarmClockData> alarmClockData = new ArrayList<>();
|
||||
List<AlarmClockData> dataBaseAlarms = getDatabaseAlarms();
|
||||
if (dataBaseAlarms != null && dataBaseAlarms.size() != 0) {
|
||||
alarmClockData.addAll(dataBaseAlarms);
|
||||
}
|
||||
return alarmClockData;
|
||||
}
|
||||
|
||||
public HashMap<Integer, AlarmClockData> getOldDataMap() {
|
||||
List<AlarmClockData> alarmClockData = getOldData();
|
||||
HashMap<Integer, AlarmClockData> hashMap = new HashMap<>();
|
||||
if (alarmClockData.size() != 0) {
|
||||
for (AlarmClockData clockData : alarmClockData) {
|
||||
hashMap.put(clockData.getId(), clockData);
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取最近一次的闹钟
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public AlarmClockData getRecentAlarmClock() {
|
||||
List<AlarmClockData> alarmClockData = getAllAlarms();
|
||||
List<AlarmClockData> alarmClockData = getDatabaseAlarms();
|
||||
if (alarmClockData == null || alarmClockData.size() == 0) {
|
||||
return null;
|
||||
} else {
|
||||
@@ -417,15 +567,21 @@ public class AlarmUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private HashSet<PendingIntent> getOldPendingIntents() {
|
||||
private HashSet<PendingIntent> getOldPendingIntentsSet() {
|
||||
HashSet<PendingIntent> pendingIntents = new HashSet<>();
|
||||
HashMap<Integer, AlarmClockData> data = getOldData();
|
||||
HashMap<Integer, AlarmClockData> data = getOldDataMap();
|
||||
for (AlarmClockData alarmClockData : data.values()) {
|
||||
pendingIntents.add(getPendingIntent(alarmClockData));
|
||||
}
|
||||
return pendingIntents;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已设置闹钟的PendingIntent
|
||||
*
|
||||
* @param alarmClock
|
||||
* @return
|
||||
*/
|
||||
private PendingIntent getPendingIntent(AlarmClockData alarmClock) {
|
||||
Intent intent = new Intent(MainService.ALARMWAKEUP);
|
||||
intent.putExtra("title", alarmClock.getTitle());
|
||||
@@ -475,14 +631,6 @@ public class AlarmUtils {
|
||||
return zeroTime;
|
||||
}
|
||||
|
||||
/*一次性*/
|
||||
public static final int ONCE = 1;
|
||||
/*每天*/
|
||||
public static final int LOOP = 2;
|
||||
/*周一到周五*/
|
||||
public static final int WORKING_DAY = 3;
|
||||
/*休息日*/
|
||||
public static final int OFF_DAY = 4;
|
||||
|
||||
/**
|
||||
* 设置闹钟
|
||||
@@ -490,6 +638,9 @@ public class AlarmUtils {
|
||||
* @param alarm
|
||||
*/
|
||||
public void setAlarm(AlarmClockData alarm) {
|
||||
if (pendingIntents == null) {
|
||||
pendingIntents = getOldPendingIntentsSet();
|
||||
}
|
||||
int id = alarm.getId();
|
||||
int type = alarm.getType();
|
||||
String timeString = alarm.getTime();
|
||||
@@ -498,10 +649,17 @@ public class AlarmUtils {
|
||||
long timeStamp = getTimestamp(timeString);
|
||||
Log.e(TAG, "setAlarm: " + timeStamp);
|
||||
boolean finished = alarm.isFinished();
|
||||
String url = alarm.getVoice();
|
||||
String md5 = alarm.getVoice_md5();
|
||||
if (!TextUtils.isEmpty(url)) {
|
||||
ariaDownload(url, md5);
|
||||
String voiceUrl = alarm.getVoice();
|
||||
String voiceMd5 = alarm.getVoice_md5();
|
||||
if (!TextUtils.isEmpty(voiceUrl)) {
|
||||
if (!FileUtil.isLocalPath(voiceUrl))
|
||||
ariaDownload(voiceUrl, voiceMd5);
|
||||
}
|
||||
String fileUrl = alarm.getFile();
|
||||
String fileMd5 = alarm.getFile_md5();
|
||||
if (!TextUtils.isEmpty(fileUrl)) {
|
||||
if (!FileUtil.isLocalPath(fileUrl))
|
||||
ariaDownload(fileUrl, fileMd5);
|
||||
}
|
||||
switch (type) {
|
||||
case ONCE:
|
||||
@@ -540,7 +698,7 @@ public class AlarmUtils {
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
mAlarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setOnceAlarm: " + "id: " + requestCode + " title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
@@ -559,7 +717,7 @@ public class AlarmUtils {
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setDayLoopAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
// setLoopAlarm(action, extra, requestCode, AlarmManager.INTERVAL_DAY, timestamp);
|
||||
}
|
||||
@@ -585,7 +743,7 @@ public class AlarmUtils {
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
alarmManager.setWindow(AlarmManager.RTC_WAKEUP, timestamp, intervalMillis, startPendingIntent);
|
||||
mAlarmManager.setWindow(AlarmManager.RTC_WAKEUP, timestamp, intervalMillis, startPendingIntent);
|
||||
Log.e(TAG, "setLoopAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
@@ -609,7 +767,7 @@ public class AlarmUtils {
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setWorkDayAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
@@ -634,7 +792,7 @@ public class AlarmUtils {
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setOffDayAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
@@ -646,7 +804,7 @@ public class AlarmUtils {
|
||||
String fileMD5 = FileUtils.getFileMD5ToString(file);
|
||||
Log.e("ariaDownload", "fileOnlineMD5=" + md5);
|
||||
Log.e("ariaDownload", "fileMD5=" + fileMD5);
|
||||
if (!md5.equals(fileMD5)) {
|
||||
if (!md5.equalsIgnoreCase(fileMD5)) {
|
||||
Aria.download(this)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(Utils.getDownLoadPath(mContext) + fileName)
|
||||
@@ -666,5 +824,23 @@ public class AlarmUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public void ariaDownload(String url) {
|
||||
if (FileUtil.isLocalPath(url)) {
|
||||
return;
|
||||
}
|
||||
String fileName = Utils.getFileNamefromURL(url);
|
||||
File file = new File(Utils.getDownLoadPath(mContext) + fileName);
|
||||
if (file.exists() && !file.isDirectory()) {
|
||||
String fileMD5 = FileUtils.getFileMD5ToString(file);
|
||||
Log.e("ariaDownload", "fileMD5=" + fileMD5);
|
||||
Log.e("ariaDownload", "fileName = " + fileName + " exists");
|
||||
} else {
|
||||
Aria.download(this)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(Utils.getDownLoadPath(mContext) + fileName)
|
||||
.create(); //启动下载}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.uiuios.aios.service.main.MainService;
|
||||
import com.uiuios.aios.utils.AppUsedTimeUtils;
|
||||
import com.uiuios.aios.utils.JGYUtils;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
import com.uiuios.aios.utils.WiFiUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -52,6 +53,7 @@ public class BaseApplication extends Application {
|
||||
Aria.init(this);
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||
Aria.get(this).getDownloadConfig().setConvertSpeed(true);
|
||||
WiFiUtils.init(this);
|
||||
AppUsedTimeUtils.init(this);
|
||||
AlarmUtils.init(this);
|
||||
HeConfig.init("HE2210211540591362", "fe42a7bb59b14eefb27eea4fb2c40e99");
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.uiuios.aios.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.ContentView;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
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 io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
|
||||
public abstract class BaseLifecycleActivity extends AppCompatActivity implements LifecycleProvider<ActivityEvent> {
|
||||
public final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
|
||||
|
||||
public BaseLifecycleActivity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@ContentView
|
||||
public BaseLifecycleActivity(@LayoutRes int contentLayoutId) {
|
||||
super(contentLayoutId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final Observable<ActivityEvent> lifecycle() {
|
||||
return lifecycleSubject.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull ActivityEvent event) {
|
||||
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindToLifecycle() {
|
||||
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
setContentView(this.getLayoutId());
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置布局
|
||||
*/
|
||||
public abstract int getLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
public abstract void initView();
|
||||
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
public abstract void initData();
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.uiuios.aios.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.ContentView;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
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 io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
public abstract class BaseLightLifecycleActivity extends AppCompatActivity implements LifecycleProvider<ActivityEvent> {
|
||||
public final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
|
||||
|
||||
public BaseLightLifecycleActivity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@ContentView
|
||||
public BaseLightLifecycleActivity(@LayoutRes int contentLayoutId) {
|
||||
super(contentLayoutId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final Observable<ActivityEvent> lifecycle() {
|
||||
return lifecycleSubject.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull ActivityEvent event) {
|
||||
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@CheckResult
|
||||
public final <T> LifecycleTransformer<T> bindToLifecycle() {
|
||||
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
setContentView(this.getLayoutId());
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置布局
|
||||
*/
|
||||
public abstract int getLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
public abstract void initView();
|
||||
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
public abstract void initData();
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
16
app/src/main/java/com/uiuios/aios/bean/AlarmClockId.java
Normal file
16
app/src/main/java/com/uiuios/aios/bean/AlarmClockId.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.uiuios.aios.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class AlarmClockId implements Serializable {
|
||||
private static final long serialVersionUID = 4423679466957746841L;
|
||||
int id;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
62
app/src/main/java/com/uiuios/aios/bean/WiFiInfo.java
Normal file
62
app/src/main/java/com/uiuios/aios/bean/WiFiInfo.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.uiuios.aios.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class WiFiInfo implements Serializable {
|
||||
private static final long serialVersionUID = 2429102475725706816L;
|
||||
|
||||
String SSID;
|
||||
String BSSID;
|
||||
int level;
|
||||
boolean connected;
|
||||
boolean isSaved;
|
||||
boolean isAvailable;
|
||||
|
||||
public String getSSID() {
|
||||
return SSID;
|
||||
}
|
||||
|
||||
public void setSSID(String SSID) {
|
||||
this.SSID = SSID;
|
||||
}
|
||||
|
||||
public String getBSSID() {
|
||||
return BSSID;
|
||||
}
|
||||
|
||||
public void setBSSID(String BSSID) {
|
||||
this.BSSID = BSSID;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
public void setConnected(boolean connected) {
|
||||
this.connected = connected;
|
||||
}
|
||||
|
||||
public boolean isSaved() {
|
||||
return isSaved;
|
||||
}
|
||||
|
||||
public void setSaved(boolean saved) {
|
||||
isSaved = saved;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return isAvailable;
|
||||
}
|
||||
|
||||
public void setAvailable(boolean available) {
|
||||
isAvailable = available;
|
||||
}
|
||||
}
|
||||
246
app/src/main/java/com/uiuios/aios/dialog/DeleWifiDialog.java
Normal file
246
app/src/main/java/com/uiuios/aios/dialog/DeleWifiDialog.java
Normal file
@@ -0,0 +1,246 @@
|
||||
package com.uiuios.aios.dialog;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
|
||||
|
||||
/**
|
||||
* description:自定义dialog
|
||||
*/
|
||||
|
||||
public class DeleWifiDialog extends AlertDialog {
|
||||
/**
|
||||
* 显示的图片
|
||||
*/
|
||||
private ImageView imageIv;
|
||||
|
||||
/**
|
||||
* 显示的标题
|
||||
*/
|
||||
private TextView titleTv;
|
||||
|
||||
/**
|
||||
* 显示的消息
|
||||
*/
|
||||
private TextView messageTv;
|
||||
|
||||
/**
|
||||
* 确认和取消按钮
|
||||
*/
|
||||
private TextView positiveBn;
|
||||
private TextView negtiveBn;
|
||||
/**
|
||||
* 按钮之间的分割线
|
||||
*/
|
||||
// private View columnLineView;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public DeleWifiDialog(Context context) {
|
||||
super(context, R.style.CustomDialog);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 都是内容数据
|
||||
*/
|
||||
private String message;
|
||||
private String title;
|
||||
private String positive;
|
||||
private int imageResId = -1;
|
||||
private boolean showPasswd = false;
|
||||
|
||||
/**
|
||||
* 底部是否只有一个按钮
|
||||
*/
|
||||
private boolean isSingle = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_delete_wifi);
|
||||
//按空白处不能取消动画
|
||||
setCanceledOnTouchOutside(false);
|
||||
//初始化界面控件
|
||||
initView();
|
||||
//初始化界面数据
|
||||
refreshView();
|
||||
//初始化界面控件的事件
|
||||
initEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面的确定和取消监听器
|
||||
*/
|
||||
private void initEvent() {
|
||||
//设置确定按钮被点击后,向外界提供监听
|
||||
positiveBn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onClickBottomListener != null) {
|
||||
onClickBottomListener.onPositiveClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
negtiveBn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面控件的显示数据
|
||||
*/
|
||||
private void refreshView() {
|
||||
//如果用户自定了title和message
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
titleTv.setText(title);
|
||||
titleTv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
titleTv.setVisibility(View.GONE);
|
||||
}
|
||||
if (!TextUtils.isEmpty(message)) {
|
||||
messageTv.setText(message);
|
||||
}
|
||||
//如果设置按钮的文字
|
||||
if (!TextUtils.isEmpty(positive)) {
|
||||
positiveBn.setText(positive);
|
||||
} else {
|
||||
positiveBn.setText("确定");
|
||||
}
|
||||
negtiveBn.setText("取消");
|
||||
|
||||
if (imageResId != -1) {
|
||||
imageIv.setImageResource(imageResId);
|
||||
imageIv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
imageIv.setVisibility(View.GONE);
|
||||
}
|
||||
/**
|
||||
* 只显示一个按钮的时候隐藏取消按钮,回掉只执行确定的事件
|
||||
*/
|
||||
// if (isSingle) {
|
||||
//// columnLineView.setVisibility(View.GONE);
|
||||
// negtiveBn.setVisibility(View.GONE);
|
||||
// } else {
|
||||
// negtiveBn.setVisibility(View.VISIBLE);
|
||||
//// columnLineView.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
refreshView();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面控件
|
||||
*/
|
||||
private void initView() {
|
||||
positiveBn = findViewById(R.id.positive);
|
||||
negtiveBn = findViewById(R.id.negtive);
|
||||
titleTv = findViewById(R.id.title);
|
||||
messageTv = findViewById(R.id.message);
|
||||
imageIv = findViewById(R.id.image);
|
||||
// columnLineView = findViewById(R.id.column_line);
|
||||
showKeyboard();
|
||||
}
|
||||
|
||||
public void showKeyboard() {
|
||||
if (messageTv != null) {
|
||||
//设置可获得焦点
|
||||
messageTv.setFocusable(true);
|
||||
messageTv.setFocusableInTouchMode(true);
|
||||
//请求获得焦点
|
||||
messageTv.requestFocus();
|
||||
//调用系统输入法
|
||||
InputMethodManager inputManager = (InputMethodManager) messageTv
|
||||
.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
inputManager.showSoftInput(messageTv, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置确定取消按钮的回调
|
||||
*/
|
||||
private OnClickBottomListener onClickBottomListener;
|
||||
|
||||
public void setOnClickBottomListener(OnClickBottomListener onClickBottomListener) {
|
||||
this.onClickBottomListener = onClickBottomListener;
|
||||
}
|
||||
|
||||
public interface OnClickBottomListener {
|
||||
/**
|
||||
* 点击确定按钮事件
|
||||
*/
|
||||
void onPositiveClick();
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public DeleWifiDialog setMessage(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public DeleWifiDialog setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPositive() {
|
||||
return positive;
|
||||
}
|
||||
|
||||
public DeleWifiDialog setPositive(String positive) {
|
||||
this.positive = positive;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getImageResId() {
|
||||
return imageResId;
|
||||
}
|
||||
|
||||
public boolean isSingle() {
|
||||
return isSingle;
|
||||
}
|
||||
|
||||
public DeleWifiDialog setSingle(boolean single) {
|
||||
isSingle = single;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeleWifiDialog setImageResId(int imageResId) {
|
||||
this.imageResId = imageResId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
String passwd = messageTv.getText().toString();
|
||||
return passwd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
}
|
||||
}
|
||||
251
app/src/main/java/com/uiuios/aios/dialog/DeleteDialog.java
Normal file
251
app/src/main/java/com/uiuios/aios/dialog/DeleteDialog.java
Normal file
@@ -0,0 +1,251 @@
|
||||
package com.uiuios.aios.dialog;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
|
||||
|
||||
/**
|
||||
* description:自定义dialog
|
||||
*/
|
||||
|
||||
public class DeleteDialog extends AlertDialog {
|
||||
/**
|
||||
* 显示的图片
|
||||
*/
|
||||
private ImageView imageIv;
|
||||
|
||||
/**
|
||||
* 显示的标题
|
||||
*/
|
||||
private TextView titleTv;
|
||||
|
||||
/**
|
||||
* 显示的消息
|
||||
*/
|
||||
private TextView messageTv;
|
||||
|
||||
/**
|
||||
* 确认和取消按钮
|
||||
*/
|
||||
private TextView positiveBn;
|
||||
private TextView negtiveBn;
|
||||
|
||||
/**
|
||||
* 按钮之间的分割线
|
||||
*/
|
||||
// private View columnLineView;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public DeleteDialog(Context context) {
|
||||
super(context, R.style.CustomDialog);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 都是内容数据
|
||||
*/
|
||||
private String message;
|
||||
private String title;
|
||||
private String positive, negtive;
|
||||
private int imageResId = -1;
|
||||
|
||||
/**
|
||||
* 底部是否只有一个按钮
|
||||
*/
|
||||
private boolean isSingle = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_delete);
|
||||
//按空白处不能取消动画
|
||||
setCanceledOnTouchOutside(false);
|
||||
//初始化界面控件
|
||||
initView();
|
||||
//初始化界面数据
|
||||
refreshView();
|
||||
//初始化界面控件的事件
|
||||
initEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面的确定和取消监听器
|
||||
*/
|
||||
private void initEvent() {
|
||||
//设置确定按钮被点击后,向外界提供监听
|
||||
positiveBn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onClickBottomListener != null) {
|
||||
onClickBottomListener.onPositiveClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
//设置取消按钮被点击后,向外界提供监听
|
||||
negtiveBn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onClickBottomListener != null) {
|
||||
onClickBottomListener.onNegtiveClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面控件的显示数据
|
||||
*/
|
||||
private void refreshView() {
|
||||
//如果用户自定了title和message
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
titleTv.setText(title);
|
||||
titleTv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
titleTv.setVisibility(View.GONE);
|
||||
}
|
||||
if (!TextUtils.isEmpty(message)) {
|
||||
messageTv.setText(message);
|
||||
}
|
||||
//如果设置按钮的文字
|
||||
if (!TextUtils.isEmpty(positive)) {
|
||||
positiveBn.setText(positive);
|
||||
} else {
|
||||
positiveBn.setText("确定");
|
||||
}
|
||||
if (!TextUtils.isEmpty(negtive)) {
|
||||
negtiveBn.setText(negtive);
|
||||
} else {
|
||||
negtiveBn.setText("取消");
|
||||
}
|
||||
|
||||
if (imageResId != -1) {
|
||||
imageIv.setImageResource(imageResId);
|
||||
imageIv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
imageIv.setVisibility(View.GONE);
|
||||
}
|
||||
/**
|
||||
* 只显示一个按钮的时候隐藏取消按钮,回掉只执行确定的事件
|
||||
*/
|
||||
// if (isSingle) {
|
||||
//// columnLineView.setVisibility(View.GONE);
|
||||
// negtiveBn.setVisibility(View.GONE);
|
||||
// } else {
|
||||
// negtiveBn.setVisibility(View.VISIBLE);
|
||||
//// columnLineView.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
refreshView();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面控件
|
||||
*/
|
||||
private void initView() {
|
||||
negtiveBn = findViewById(R.id.negtive);
|
||||
positiveBn = findViewById(R.id.positive);
|
||||
titleTv = findViewById(R.id.title);
|
||||
messageTv = findViewById(R.id.message);
|
||||
imageIv = findViewById(R.id.image);
|
||||
// columnLineView = findViewById(R.id.column_line);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置确定取消按钮的回调
|
||||
*/
|
||||
private OnClickBottomListener onClickBottomListener;
|
||||
|
||||
public void setOnClickBottomListener(OnClickBottomListener onClickBottomListener) {
|
||||
this.onClickBottomListener = onClickBottomListener;
|
||||
}
|
||||
|
||||
public interface OnClickBottomListener {
|
||||
/**
|
||||
* 点击确定按钮事件
|
||||
*/
|
||||
void onPositiveClick();
|
||||
|
||||
/**
|
||||
* 点击取消按钮事件
|
||||
*/
|
||||
void onNegtiveClick();
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public DeleteDialog setMessage(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public DeleteDialog setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPositive() {
|
||||
return positive;
|
||||
}
|
||||
|
||||
public DeleteDialog setPositive(String positive) {
|
||||
this.positive = positive;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getNegtive() {
|
||||
return negtive;
|
||||
}
|
||||
|
||||
public DeleteDialog setNegtive(String negtive) {
|
||||
this.negtive = negtive;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeleteDialog setNegtiveText(String negtive) {
|
||||
negtiveBn.setText(negtive);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getImageResId() {
|
||||
return imageResId;
|
||||
}
|
||||
|
||||
public boolean isSingle() {
|
||||
return isSingle;
|
||||
}
|
||||
|
||||
public DeleteDialog setSingle(boolean single) {
|
||||
isSingle = single;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeleteDialog setImageResId(int imageResId) {
|
||||
this.imageResId = imageResId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
}
|
||||
}
|
||||
265
app/src/main/java/com/uiuios/aios/dialog/WifiDialog.java
Normal file
265
app/src/main/java/com/uiuios/aios/dialog/WifiDialog.java
Normal file
@@ -0,0 +1,265 @@
|
||||
package com.uiuios.aios.dialog;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.HideReturnsTransformationMethod;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
|
||||
|
||||
/**
|
||||
* description:自定义dialog
|
||||
*/
|
||||
|
||||
public class WifiDialog extends AlertDialog {
|
||||
/**
|
||||
* 显示的图片
|
||||
*/
|
||||
private ImageView imageIv;
|
||||
private ImageView iv_show;
|
||||
private ImageView iv_close;
|
||||
|
||||
/**
|
||||
* 显示的标题
|
||||
*/
|
||||
private TextView titleTv;
|
||||
|
||||
/**
|
||||
* 显示的消息
|
||||
*/
|
||||
private EditText messageTv;
|
||||
|
||||
/**
|
||||
* 确认和取消按钮
|
||||
*/
|
||||
private TextView positiveBn;
|
||||
|
||||
/**
|
||||
* 按钮之间的分割线
|
||||
*/
|
||||
// private View columnLineView;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public WifiDialog(Context context) {
|
||||
super(context, R.style.CustomDialog);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 都是内容数据
|
||||
*/
|
||||
private String message;
|
||||
private String title;
|
||||
private String positive;
|
||||
private int imageResId = -1;
|
||||
private boolean showPasswd = false;
|
||||
|
||||
/**
|
||||
* 底部是否只有一个按钮
|
||||
*/
|
||||
private boolean isSingle = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_wifi);
|
||||
//按空白处不能取消动画
|
||||
setCanceledOnTouchOutside(false);
|
||||
//初始化界面控件
|
||||
initView();
|
||||
//初始化界面数据
|
||||
refreshView();
|
||||
//初始化界面控件的事件
|
||||
initEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面的确定和取消监听器
|
||||
*/
|
||||
private void initEvent() {
|
||||
//设置确定按钮被点击后,向外界提供监听
|
||||
positiveBn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onClickBottomListener != null) {
|
||||
onClickBottomListener.onPositiveClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
iv_show.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (showPasswd) {
|
||||
iv_show.setImageDrawable(mContext.getDrawable(R.drawable.icon_passwd_show));
|
||||
messageTv.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
||||
} else {
|
||||
iv_show.setImageDrawable(mContext.getDrawable(R.drawable.icon_passwd_hide));
|
||||
messageTv.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
|
||||
}
|
||||
showPasswd = !showPasswd;
|
||||
}
|
||||
});
|
||||
iv_close.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面控件的显示数据
|
||||
*/
|
||||
private void refreshView() {
|
||||
//如果用户自定了title和message
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
titleTv.setText(title);
|
||||
titleTv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
titleTv.setVisibility(View.GONE);
|
||||
}
|
||||
if (!TextUtils.isEmpty(message)) {
|
||||
messageTv.setText(message);
|
||||
}
|
||||
//如果设置按钮的文字
|
||||
if (!TextUtils.isEmpty(positive)) {
|
||||
positiveBn.setText(positive);
|
||||
} else {
|
||||
positiveBn.setText("确定");
|
||||
}
|
||||
|
||||
if (imageResId != -1) {
|
||||
imageIv.setImageResource(imageResId);
|
||||
imageIv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
imageIv.setVisibility(View.GONE);
|
||||
}
|
||||
/**
|
||||
* 只显示一个按钮的时候隐藏取消按钮,回掉只执行确定的事件
|
||||
*/
|
||||
// if (isSingle) {
|
||||
//// columnLineView.setVisibility(View.GONE);
|
||||
// negtiveBn.setVisibility(View.GONE);
|
||||
// } else {
|
||||
// negtiveBn.setVisibility(View.VISIBLE);
|
||||
//// columnLineView.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
refreshView();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化界面控件
|
||||
*/
|
||||
private void initView() {
|
||||
positiveBn = findViewById(R.id.positive);
|
||||
titleTv = findViewById(R.id.title);
|
||||
messageTv = findViewById(R.id.message);
|
||||
imageIv = findViewById(R.id.image);
|
||||
iv_show = findViewById(R.id.iv_show);
|
||||
iv_close = findViewById(R.id.iv_close);
|
||||
|
||||
// columnLineView = findViewById(R.id.column_line);
|
||||
showKeyboard();
|
||||
}
|
||||
|
||||
public void showKeyboard() {
|
||||
if (messageTv != null) {
|
||||
//设置可获得焦点
|
||||
messageTv.setFocusable(true);
|
||||
messageTv.setFocusableInTouchMode(true);
|
||||
//请求获得焦点
|
||||
messageTv.requestFocus();
|
||||
//调用系统输入法
|
||||
InputMethodManager inputManager = (InputMethodManager) messageTv
|
||||
.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
inputManager.showSoftInput(messageTv, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置确定取消按钮的回调
|
||||
*/
|
||||
private OnClickBottomListener onClickBottomListener;
|
||||
|
||||
public void setOnClickBottomListener(OnClickBottomListener onClickBottomListener) {
|
||||
this.onClickBottomListener = onClickBottomListener;
|
||||
}
|
||||
|
||||
public interface OnClickBottomListener {
|
||||
/**
|
||||
* 点击确定按钮事件
|
||||
*/
|
||||
void onPositiveClick();
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public WifiDialog setMessage(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public WifiDialog setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPositive() {
|
||||
return positive;
|
||||
}
|
||||
|
||||
public WifiDialog setPositive(String positive) {
|
||||
this.positive = positive;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getImageResId() {
|
||||
return imageResId;
|
||||
}
|
||||
|
||||
public boolean isSingle() {
|
||||
return isSingle;
|
||||
}
|
||||
|
||||
public WifiDialog setSingle(boolean single) {
|
||||
isSingle = single;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WifiDialog setImageResId(int imageResId) {
|
||||
this.imageResId = imageResId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
String passwd = messageTv.getText().toString();
|
||||
return passwd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,12 @@ import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.FragmentEvent;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.DailyAppActivity;
|
||||
import com.uiuios.aios.activity.code.FamilySpaceActivity;
|
||||
import com.uiuios.aios.base.BaseFragment;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.DesktopIcon;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.dialog.CustomDialog;
|
||||
import com.uiuios.aios.dialog.DailyAppDialog;
|
||||
import com.uiuios.aios.manager.AppStatusManager;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.service.NotificationService;
|
||||
@@ -169,6 +169,7 @@ public class AppListFragment extends BaseFragment {
|
||||
iv.setImageDrawable(desktopIcon.getIcon());
|
||||
} else {
|
||||
iv.setImageDrawable(getActivity().getResources().getDrawable(resID));
|
||||
desktopIcon.setIcon(mContext.getResources().getDrawable(resID));
|
||||
}
|
||||
} else {
|
||||
iv.setImageBitmap(BitmapUtils.getIconBitmap(rootView.getContext(), desktopIcon.getIcon()));
|
||||
@@ -253,9 +254,10 @@ public class AppListFragment extends BaseFragment {
|
||||
switch (pkg) {
|
||||
case "aios.exit":
|
||||
case "com.uiuios.sn":
|
||||
case "aios.daily.app":
|
||||
break;
|
||||
default:
|
||||
showHinDialog(pkg, desktopIcon.getLable());
|
||||
showHideDialog(desktopIcon);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -266,23 +268,25 @@ public class AppListFragment extends BaseFragment {
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, FragmentEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@io.reactivex.rxjava3.annotations.NonNull Disposable d) {
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("updateAppDisableStatus", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@io.reactivex.rxjava3.annotations.NonNull BaseResponse baseResponse) {
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("updateAppDisableStatus", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
ApkUtils.disableApp(mContext, pkg);
|
||||
// ApkUtils.disableApp(mContext, pkg);
|
||||
AppStatusManager.getInstance().addHidedApp(pkg);
|
||||
} else {
|
||||
ToastUtil.show("隐藏失败,检查网络连接");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.rxjava3.annotations.NonNull Throwable e) {
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("updateAppDisableStatus", "onError: ");
|
||||
ToastUtil.show("隐藏失败,检查网络连接");
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@@ -293,23 +297,26 @@ public class AppListFragment extends BaseFragment {
|
||||
});
|
||||
}
|
||||
|
||||
private void showHinDialog(String pkg, String label) {
|
||||
CustomDialog customDialog = new CustomDialog(mContext);
|
||||
customDialog.setTitle("隐藏应用");
|
||||
customDialog.setMessage("是否要隐藏:" + label);
|
||||
customDialog.setOnClickBottomListener(new CustomDialog.OnClickBottomListener() {
|
||||
private void showHideDialog(DesktopIcon desktopIcon) {
|
||||
String label = desktopIcon.getLable();
|
||||
String pkg = desktopIcon.getPackageName();
|
||||
DailyAppDialog dailyAppDialog = new DailyAppDialog(mContext);
|
||||
dailyAppDialog.setTitle("移到日常应用");
|
||||
dailyAppDialog.setMessage(label);
|
||||
dailyAppDialog.setIconImage(desktopIcon.getIcon());
|
||||
dailyAppDialog.setOnClickBottomListener(new DailyAppDialog.OnClickBottomListener() {
|
||||
@Override
|
||||
public void onPositiveClick() {
|
||||
updateAppDisableStatus(pkg, label);
|
||||
customDialog.dismiss();
|
||||
dailyAppDialog.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegtiveClick() {
|
||||
customDialog.dismiss();
|
||||
dailyAppDialog.dismiss();
|
||||
}
|
||||
});
|
||||
customDialog.show();
|
||||
dailyAppDialog.show();
|
||||
}
|
||||
|
||||
private void SendRunningApp(Context context) {
|
||||
|
||||
@@ -56,11 +56,12 @@ import com.uiuios.aios.activity.alarm.AlarmClockActivity;
|
||||
import com.uiuios.aios.activity.code.FamilySpaceActivity;
|
||||
import com.uiuios.aios.activity.contact.ContactActivity;
|
||||
import com.uiuios.aios.activity.weather.WeatherActivity;
|
||||
import com.uiuios.aios.activity.wifi.WiFiManagerActivity;
|
||||
import com.uiuios.aios.adapter.NotificationAdapter;
|
||||
import com.uiuios.aios.adapter.SOSNnmberAdapter;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.base.BaseFragment;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.bean.AlarmItem;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
import com.uiuios.aios.bean.HealthCode;
|
||||
@@ -567,8 +568,10 @@ public class CustomFragment extends BaseFragment implements CustomContact.Custom
|
||||
cl_wifi.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
|
||||
startActivity(intent);
|
||||
// Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
|
||||
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// startActivity(intent);
|
||||
startActivity(new Intent(mContext, WiFiManagerActivity.class));
|
||||
}
|
||||
});
|
||||
cl_activation.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -603,7 +606,6 @@ public class CustomFragment extends BaseFragment implements CustomContact.Custom
|
||||
} else {
|
||||
// tv_name.setText("未设置");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void showPassword() {
|
||||
@@ -832,24 +834,25 @@ public class CustomFragment extends BaseFragment implements CustomContact.Custom
|
||||
}
|
||||
|
||||
private void getAlarm() {
|
||||
NetInterfaceManager.getInstance().getAlarmClock(new NetInterfaceManager.AlarmClockCallback() {
|
||||
@Override
|
||||
public void setAlarmClock(List<AlarmClockData> alarmClockList) {
|
||||
startActivity(new Intent(mContext, AlarmClockActivity.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmClockEmpty() {
|
||||
showNoData("温馨提示", "请在小程序上设置爱心闹钟");
|
||||
rv_noti.setVisibility(View.GONE);
|
||||
iv_note_nodata.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
});
|
||||
startActivity(new Intent(mContext, AlarmClockActivity.class));
|
||||
// NetInterfaceManager.getInstance().getAlarmClock(new NetInterfaceManager.AlarmClockCallback() {
|
||||
// @Override
|
||||
// public void setAlarmClock(List<AlarmClockData> alarmClockList) {
|
||||
// startActivity(new Intent(mContext, AlarmClockActivity.class));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setAlarmClockEmpty() {
|
||||
// showNoData("温馨提示", "请在小程序上设置爱心闹钟");
|
||||
// rv_noti.setVisibility(View.GONE);
|
||||
// iv_note_nodata.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError() {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
private void getAlarmCache() {
|
||||
|
||||
144
app/src/main/java/com/uiuios/aios/gson/GsonUtils.java
Normal file
144
app/src/main/java/com/uiuios/aios/gson/GsonUtils.java
Normal file
@@ -0,0 +1,144 @@
|
||||
package com.uiuios.aios.gson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class GsonUtils {
|
||||
//https://blog.csdn.net/zte1055889498/article/details/122400299
|
||||
|
||||
public static JsonObject getJsonObject(String jsonString) {
|
||||
JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
private static final Gson gson;
|
||||
|
||||
static {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
builder.registerTypeAdapterFactory(new NullStringToEmptyAdapterFactory());
|
||||
builder.registerTypeAdapter(Integer.class, new IntegerDefault0Adapter());
|
||||
builder.registerTypeAdapter(int.class, new IntegerDefault0Adapter());
|
||||
builder.disableHtmlEscaping();
|
||||
builder.enableComplexMapKeySerialization();
|
||||
// builder.excludeFieldsWithoutExposeAnnotation();
|
||||
builder.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
gson = builder.create();
|
||||
}
|
||||
|
||||
public static Type makeJavaType(Type rawType, Type... typeArguments) {
|
||||
return TypeToken.getParameterized(rawType, typeArguments).getType();
|
||||
}
|
||||
|
||||
public static String toString(Object value) {
|
||||
if (Objects.isNull(value)) {
|
||||
return null;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return (String) value;
|
||||
}
|
||||
return toJSONString(value);
|
||||
}
|
||||
|
||||
public static String toJSONString(Object value) {
|
||||
return gson.toJson(value);
|
||||
}
|
||||
|
||||
public static String toPrettyString(Object value) {
|
||||
return gson.newBuilder().setPrettyPrinting().create().toJson(value);
|
||||
}
|
||||
|
||||
public static JsonElement fromJavaObject(Object value) {
|
||||
JsonElement result = null;
|
||||
if (Objects.nonNull(value) && (value instanceof String)) {
|
||||
result = parseObject((String) value);
|
||||
} else {
|
||||
result = gson.toJsonTree(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static JsonElement parseObject(String content) {
|
||||
return JsonParser.parseString(content);
|
||||
}
|
||||
|
||||
public static JsonElement getJsonElement(JsonObject node, String name) {
|
||||
return node.get(name);
|
||||
}
|
||||
|
||||
public static JsonElement getJsonElement(JsonArray node, int index) {
|
||||
return node.get(index);
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(JsonElement node, Class<T> clazz) {
|
||||
return gson.fromJson(node, clazz);
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(JsonElement node, Type type) {
|
||||
return gson.fromJson(node, type);
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(JsonElement node, TypeToken<?> typeToken) {
|
||||
return toJavaObject(node, typeToken.getType());
|
||||
}
|
||||
|
||||
public static <E> List<E> toJavaList(JsonElement node, Class<E> clazz) {
|
||||
return toJavaObject(node, makeJavaType(List.class, clazz));
|
||||
}
|
||||
|
||||
public static List<Object> toJavaList(JsonElement node) {
|
||||
return toJavaObject(node, new TypeToken<List<Object>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public static <V> Map<String, V> toJavaMap(JsonElement node, Class<V> clazz) {
|
||||
return toJavaObject(node, makeJavaType(Map.class, String.class, clazz));
|
||||
}
|
||||
|
||||
public static Map<String, Object> toJavaMap(JsonElement node) {
|
||||
return toJavaObject(node, new TypeToken<Map<String, Object>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(String content, Class<T> clazz) {
|
||||
JsonObject jsonObject = getJsonObject(content);
|
||||
String jsonString = jsonObject.toString();
|
||||
return gson.fromJson(jsonString, clazz);
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(String content, Type type) {
|
||||
return gson.fromJson(content, type);
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(String content, TypeToken<?> typeToken) {
|
||||
return toJavaObject(content, typeToken.getType());
|
||||
}
|
||||
|
||||
public static <E> List<E> toJavaList(String content, Class<E> clazz) {
|
||||
return toJavaObject(content, makeJavaType(List.class, clazz));
|
||||
}
|
||||
|
||||
public static List<Object> toJavaList(String content) {
|
||||
return toJavaObject(content, new TypeToken<List<Object>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public static <V> Map<String, V> toJavaMap(String content, Class<V> clazz) {
|
||||
return toJavaObject(content, makeJavaType(Map.class, String.class, clazz));
|
||||
}
|
||||
|
||||
public static Map<String, Object> toJavaMap(String content) {
|
||||
return toJavaObject(content, new TypeToken<Map<String, Object>>() {
|
||||
}.getType());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.uiuios.aios.gson;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class IntegerDefault0Adapter implements JsonSerializer<Integer>, JsonDeserializer<Integer> {
|
||||
@Override
|
||||
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
try {
|
||||
if (json.getAsString().equals("")) {
|
||||
return 0;
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
try {
|
||||
return json.getAsInt();
|
||||
} catch (NumberFormatException e) {
|
||||
throw new JsonSyntaxException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.uiuios.aios.gson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.TypeAdapterFactory;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class NullStringToEmptyAdapterFactory<T> implements TypeAdapterFactory {
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||
|
||||
Class<T> rawType = (Class<T>) type.getRawType();
|
||||
if (rawType != String.class) {
|
||||
return null;
|
||||
}
|
||||
return (TypeAdapter<T>) new StringAdapter();
|
||||
}
|
||||
|
||||
public static class StringAdapter extends TypeAdapter<String> {
|
||||
@Override
|
||||
public String read(JsonReader reader) throws IOException {
|
||||
if (reader.peek() == JsonToken.NULL) {
|
||||
reader.nextNull();
|
||||
return "";
|
||||
}
|
||||
return reader.nextString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter writer, String value) throws IOException {
|
||||
if (value == null) {
|
||||
writer.nullValue();
|
||||
return;
|
||||
}
|
||||
writer.value(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class AppStatusManager {
|
||||
int i = IconUtils.appClassNameList.indexOf(pkg);
|
||||
if (i != -1) {
|
||||
String val = IconUtils.appIconList.get(i);
|
||||
int resID = mContext.getResources().getIdentifier(val, "drawable", "com.uiui.aios");
|
||||
int resID = mContext.getResources().getIdentifier(val, "drawable", "com.uiuios.aios");
|
||||
if (resID != 0) {
|
||||
appSelectBean.setIcon(mContext.getResources().getDrawable(resID));
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle4.android.FragmentEvent;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.bean.ActivityBean;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.bean.AlarmClockId;
|
||||
import com.uiuios.aios.bean.ArticleInfo;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
@@ -26,10 +27,15 @@ import com.uiuios.aios.bean.UserAvatarInfo;
|
||||
import com.uiuios.aios.bean.UserId;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.disklrucache.CacheHelper;
|
||||
import com.uiuios.aios.gson.GsonUtils;
|
||||
import com.uiuios.aios.manager.ConnectManager;
|
||||
import com.uiuios.aios.manager.ConnectMode;
|
||||
import com.uiuios.aios.network.api.ActivityListApi;
|
||||
import com.uiuios.aios.network.api.AlarmClockAddApi;
|
||||
import com.uiuios.aios.network.api.AlarmClockApi;
|
||||
import com.uiuios.aios.network.api.AlarmClockDeleteApi;
|
||||
import com.uiuios.aios.network.api.AlarmClockEditApi;
|
||||
import com.uiuios.aios.network.api.AlarmClockQueryApi;
|
||||
import com.uiuios.aios.network.api.AppUsageRecordApi;
|
||||
import com.uiuios.aios.network.api.ArticleListApi;
|
||||
import com.uiuios.aios.network.api.DemandListApi;
|
||||
@@ -50,7 +56,6 @@ import com.uiuios.aios.network.api.UpdateAppIconApi;
|
||||
import com.uiuios.aios.network.api.UpdateDesktopApi;
|
||||
import com.uiuios.aios.network.api.UserInfoControl;
|
||||
import com.uiuios.aios.network.interceptor.RepeatRequestInterceptor;
|
||||
import com.uiuios.aios.utils.GsonUtils;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -182,14 +187,6 @@ public class NetInterfaceManager {
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse<List<AlarmClockData>>> getAlarmClockObservable() {
|
||||
return mRetrofit
|
||||
.create(AlarmClockApi.class)
|
||||
.getAlarmClockApiApi(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse> getRunningAppObservable(String json) {
|
||||
return mRetrofit.create(RunNewApp.class)
|
||||
.sendRunningInfo(Utils.getSerial(), json)
|
||||
@@ -274,6 +271,46 @@ public class NetInterfaceManager {
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
/*
|
||||
*闹钟相关
|
||||
*/
|
||||
|
||||
public Observable<BaseResponse<List<AlarmClockData>>> getAlarmClockObservable() {
|
||||
return mRetrofit
|
||||
.create(AlarmClockApi.class)
|
||||
.getAlarmClockApiApi(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse<AlarmClockId>> getAlarmClockAddObservable(Map<String, String> params, MultipartBody.Part body) {
|
||||
return mRetrofit.create(AlarmClockAddApi.class)
|
||||
.addAlarmClock(params, body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse> getAlarmClockEditObservable(Map<String, String> params, MultipartBody.Part body) {
|
||||
return mRetrofit.create(AlarmClockEditApi.class)
|
||||
.editAlarmClock(params, body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse<AlarmClockData>> getAlarmClockByIdObservable(int id) {
|
||||
return mRetrofit.create(AlarmClockQueryApi.class)
|
||||
.getAlarmClockById(Utils.getSerial(), id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse> deleteAlarmClockObservable(int id) {
|
||||
return mRetrofit.create(AlarmClockDeleteApi.class)
|
||||
.alarmClockDelete(Utils.getSerial(), id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public interface onCompleteCallback {
|
||||
void onComplete();
|
||||
}
|
||||
@@ -321,7 +358,7 @@ public class NetInterfaceManager {
|
||||
Log.e("getUserID", "onNext: " + userIdBaseResponse);
|
||||
if (userIdBaseResponse.code == 200) {
|
||||
UserId userId = userIdBaseResponse.data;
|
||||
mCacheHelper.put(UrlAddress.GET_USER_ID, GsonUtils.toJsonString(userId));
|
||||
mCacheHelper.put(UrlAddress.GET_USER_ID, GsonUtils.toJSONString(userId));
|
||||
mMMKV.encode("USER_ID", userId.getUser_id());
|
||||
} else {
|
||||
mCacheHelper.put(UrlAddress.GET_USER_ID, -1);
|
||||
@@ -421,7 +458,7 @@ public class NetInterfaceManager {
|
||||
mCacheHelper.put(UrlAddress.GET_ACTIVITY_LIST, "");
|
||||
if (callback != null) callback.noData();
|
||||
} else {
|
||||
mCacheHelper.put(UrlAddress.GET_ACTIVITY_LIST, GsonUtils.toJsonString(activityBeans));
|
||||
mCacheHelper.put(UrlAddress.GET_ACTIVITY_LIST, GsonUtils.toJSONString(activityBeans));
|
||||
if (callback != null) callback.setActivitiesList(activityBeans);
|
||||
}
|
||||
} else {
|
||||
@@ -532,7 +569,7 @@ public class NetInterfaceManager {
|
||||
mCacheHelper.put(UrlAddress.GET_DEMAND_LIST, "");
|
||||
if (callback != null) callback.noData();
|
||||
} else {
|
||||
mCacheHelper.put(UrlAddress.GET_DEMAND_LIST, GsonUtils.toJsonString(demandBeans));
|
||||
mCacheHelper.put(UrlAddress.GET_DEMAND_LIST, GsonUtils.toJSONString(demandBeans));
|
||||
if (callback != null) callback.setDemandList(demandBeans);
|
||||
}
|
||||
} else {
|
||||
@@ -650,7 +687,7 @@ public class NetInterfaceManager {
|
||||
Log.e("getHealthCode", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<HealthCode> healthCodeList = listBaseResponse.data;
|
||||
mCacheHelper.put(UrlAddress.GET_HEALTH_CODE, GsonUtils.toJsonString(healthCodeList));
|
||||
mCacheHelper.put(UrlAddress.GET_HEALTH_CODE, GsonUtils.toJSONString(healthCodeList));
|
||||
callback.setHealthCode(healthCodeList);
|
||||
} else {
|
||||
mCacheHelper.put(UrlAddress.GET_HEALTH_CODE, "");
|
||||
@@ -703,23 +740,23 @@ public class NetInterfaceManager {
|
||||
// }
|
||||
}
|
||||
|
||||
public void getAlarmClockCache(BehaviorSubject<ActivityEvent> lifecycle, AlarmClockCallback callback) {
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_ALARM_CLOCK);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
getAlarmClock(lifecycle, callback);
|
||||
} else {
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<AlarmClockData>>() {
|
||||
}.getType();
|
||||
List<AlarmClockData> list = gson.fromJson(jsonString, type);
|
||||
if (list == null || list.size() == 0) {
|
||||
callback.setAlarmClockEmpty();
|
||||
} else {
|
||||
callback.setAlarmClock(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
// public void getAlarmClockCache(BehaviorSubject<ActivityEvent> lifecycle, AlarmClockCallback callback) {
|
||||
// String jsonString = mCacheHelper.getAsString(UrlAddress.GET_ALARM_CLOCK);
|
||||
// //为 "" 是已经请求成功的
|
||||
// if (jsonString == null) {
|
||||
// getAlarmClock(lifecycle, callback);
|
||||
// } else {
|
||||
// Gson gson = new Gson();
|
||||
// Type type = new TypeToken<List<AlarmClockData>>() {
|
||||
// }.getType();
|
||||
// List<AlarmClockData> list = gson.fromJson(jsonString, type);
|
||||
// if (list == null || list.size() == 0) {
|
||||
// callback.setAlarmClockEmpty();
|
||||
// } else {
|
||||
// callback.setAlarmClock(list);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public void getAlarmClock(BehaviorSubject<ActivityEvent> lifecycle, AlarmClockCallback callback) {
|
||||
getAlarmClockObservable()
|
||||
@@ -751,34 +788,34 @@ public class NetInterfaceManager {
|
||||
List<AlarmClockData> alarmClockData = listBaseResponse.data;
|
||||
if (alarmClockData != null && alarmClockData.size() != 0) {
|
||||
AlarmUtils.getInstance().setAlarmClockData(alarmClockData);
|
||||
if (callback != null) callback.setAlarmClock(alarmClockData);
|
||||
mMMKV.encode(UrlAddress.GET_ALARM_CLOCK, GsonUtils.toJSONString(alarmClockData));
|
||||
|
||||
// if (callback != null) {
|
||||
// callback.setAlarmClock(alarmClockData);
|
||||
// }
|
||||
} else {
|
||||
AlarmUtils.getInstance().deleteAllAlarmClock();
|
||||
AlarmUtils.getInstance().setAlarmClockData(null);
|
||||
if (callback != null) callback.setAlarmClockEmpty();
|
||||
mMMKV.encode(UrlAddress.GET_ALARM_CLOCK, "");
|
||||
|
||||
// if (callback != null) {
|
||||
// callback.setAlarmClockEmpty();
|
||||
// }
|
||||
}
|
||||
mCacheHelper.put(UrlAddress.GET_ALARM_CLOCK, GsonUtils.toJsonString(alarmClockData));
|
||||
} else {
|
||||
AlarmUtils.getInstance().deleteAllAlarmClock();
|
||||
AlarmUtils.getInstance().setAlarmClockData(null);
|
||||
mCacheHelper.put(UrlAddress.GET_ALARM_CLOCK, "");
|
||||
if (callback != null) callback.setAlarmClockEmpty();
|
||||
mMMKV.encode(UrlAddress.GET_ALARM_CLOCK, "");
|
||||
|
||||
// if (callback != null) {
|
||||
// callback.setAlarmClockEmpty();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAlarmClockObserver", "onError: " + e.getMessage());
|
||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_ALARM_CLOCK);
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<AlarmClockData>>() {
|
||||
}.getType();
|
||||
List<AlarmClockData> list = gson.fromJson(jsonString, type);
|
||||
if (list == null || list.size() == 0) {
|
||||
if (callback != null) callback.setAlarmClockEmpty();
|
||||
} else {
|
||||
if (callback != null) callback.setAlarmClock(list);
|
||||
}
|
||||
if (callback != null) callback.onError();
|
||||
onComplete();
|
||||
}
|
||||
@@ -786,6 +823,13 @@ public class NetInterfaceManager {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAlarmClockObserver", "onComplete: ");
|
||||
List<AlarmClockData> list = AlarmUtils.getInstance().getOldData();
|
||||
if (list == null || list.size() == 0) {
|
||||
if (callback != null) callback.setAlarmClockEmpty();
|
||||
} else {
|
||||
List<AlarmClockData> filter = list.stream().filter(alarmClockData -> !alarmClockData.isDeleted()).collect(Collectors.toList());
|
||||
if (callback != null) callback.setAlarmClock(filter);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -896,7 +940,7 @@ public class NetInterfaceManager {
|
||||
if (callback != null) callback.setEmpty();
|
||||
} else {
|
||||
List<Contact> emergencyContact = setting_sos.stream().filter(contact -> contact.getIs_urgent() == 1).collect(Collectors.toList());
|
||||
mCacheHelper.put(UrlAddress.GET_SETTINGS, GsonUtils.toJsonString(setting_sos));
|
||||
mCacheHelper.put(UrlAddress.GET_SETTINGS, GsonUtils.toJSONString(setting_sos));
|
||||
if (callback != null) {
|
||||
callback.setContact(setting_sos);
|
||||
callback.setEmergencyContact(emergencyContact);
|
||||
@@ -998,7 +1042,7 @@ public class NetInterfaceManager {
|
||||
mCacheHelper.put(UrlAddress.GET_MAIL_LIST, "");
|
||||
if (callback != null) callback.setEmpty();
|
||||
} else {
|
||||
mCacheHelper.put(UrlAddress.GET_MAIL_LIST, GsonUtils.toJsonString(contactList));
|
||||
mCacheHelper.put(UrlAddress.GET_MAIL_LIST, GsonUtils.toJSONString(contactList));
|
||||
List<Contact> emergencyContact = contactList.stream().filter(contact -> contact.getIs_urgent() == 1).collect(Collectors.toList());
|
||||
if (callback != null) {
|
||||
callback.setContact(contactList);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.AlarmClockId;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import okhttp3.MultipartBody;
|
||||
import retrofit2.http.Multipart;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Part;
|
||||
import retrofit2.http.QueryMap;
|
||||
|
||||
public interface AlarmClockAddApi {
|
||||
@Multipart
|
||||
@POST(UrlAddress.ALARM_CLOCK_ADD)
|
||||
Observable<BaseResponse<AlarmClockId>> addAlarmClock(
|
||||
@QueryMap Map<String, String> params,
|
||||
@Part MultipartBody.Part body
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface AlarmClockDeleteApi {
|
||||
@FormUrlEncoded
|
||||
@POST(UrlAddress.ALARM_CLOCK_DELETE)
|
||||
Observable<BaseResponse> alarmClockDelete(
|
||||
@Field("sn") String sn,
|
||||
@Field("id") int id
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import okhttp3.MultipartBody;
|
||||
import retrofit2.http.Multipart;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Part;
|
||||
import retrofit2.http.QueryMap;
|
||||
|
||||
public interface AlarmClockEditApi {
|
||||
@Multipart
|
||||
@POST(UrlAddress.ALARM_CLOCK_EDIT)
|
||||
Observable<BaseResponse> editAlarmClock(
|
||||
@QueryMap Map<String, String> params,
|
||||
@Part MultipartBody.Part body
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.uiuios.aios.network.api;
|
||||
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface AlarmClockQueryApi {
|
||||
@GET(UrlAddress.ALARM_CLOCK_BY_ID)
|
||||
Observable<BaseResponse<AlarmClockData>> getAlarmClockById(
|
||||
@Query("sn") String sn,
|
||||
@Query("id") int id
|
||||
);
|
||||
}
|
||||
@@ -2,17 +2,21 @@ package com.uiuios.aios.service.main;
|
||||
|
||||
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;
|
||||
|
||||
public class MainSContact {
|
||||
public interface Presenter extends BasePresenter<MainSView> {
|
||||
void addAlarmClock();
|
||||
void deleteAlarmClock();
|
||||
//设置所有信息
|
||||
void getAlarmClock();
|
||||
}
|
||||
|
||||
public interface MainSView extends BaseView {
|
||||
void addAlarmClockFinish();
|
||||
void deleteAlarmClockFinish();
|
||||
//获取所有信息
|
||||
void setAlarmClock(List<AlarmClockData> dataList);
|
||||
}
|
||||
|
||||
@@ -4,14 +4,30 @@ import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.bean.AlarmClockId;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
@@ -52,6 +68,207 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
private int addFinishStatu;
|
||||
|
||||
@Override
|
||||
public void addAlarmClock() {
|
||||
List<AlarmClockData> localAddAlarm = AlarmUtils.getInstance().getLocalAddAlarm();
|
||||
if (localAddAlarm.size() == 0) {
|
||||
Log.e(TAG, "addAlarmClock: localAddAlarm is empty");
|
||||
mView.addAlarmClockFinish();
|
||||
} else {
|
||||
addFinishStatu = 0;
|
||||
for (AlarmClockData alarmClockData : localAddAlarm) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("sn", Utils.getSerial());
|
||||
params.put("time", alarmClockData.getTime());
|
||||
params.put("type", String.valueOf(alarmClockData.getType()));
|
||||
params.put("title", alarmClockData.getTitle());
|
||||
params.put("remind_type", "0");
|
||||
params.put("is_onoff", "1");
|
||||
|
||||
File picFile = new File(alarmClockData.getFile());
|
||||
MediaType mediaType = MediaType.Companion.parse("image/png");
|
||||
RequestBody requestBody = RequestBody.Companion.create(picFile, mediaType);
|
||||
MultipartBody.Part body = MultipartBody.Part.createFormData("file", picFile.getName(), requestBody);
|
||||
|
||||
NetInterfaceManager.getInstance().getAlarmClockAddObservable(params, body)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<AlarmClockId>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("addAlarmClock", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<AlarmClockId> alarmClockIdBaseResponse) {
|
||||
Log.e("addAlarmClock", "onNext: " + alarmClockIdBaseResponse);
|
||||
if (alarmClockIdBaseResponse.code == 200) {
|
||||
alarmClockData.setIs_local(false);
|
||||
AlarmUtils.getInstance().updateAlarmClock(alarmClockData, alarmClockIdBaseResponse.data.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("addAlarmClock", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
addFinishStatu += 1;
|
||||
Log.e("addAlarmClock", "onComplete: " + addFinishStatu);
|
||||
if (addFinishStatu == localAddAlarm.size()) {
|
||||
mView.addAlarmClockFinish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Observable.concat(getAddObservableList(localAddAlarm))
|
||||
// .compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
// .subscribe(new Observer<BaseResponse<AlarmClockId>>() {
|
||||
// @Override
|
||||
// public void onSubscribe(@NonNull Disposable d) {
|
||||
// Log.e("addAlarmClock", "onSubscribe: ");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNext(@NonNull BaseResponse<AlarmClockId> baseResponse) {
|
||||
// Log.e("addAlarmClock", "onSubscribe: " + baseResponse);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(@NonNull Throwable e) {
|
||||
// Log.e("addAlarmClock", "onError: " + e.getMessage());
|
||||
// onComplete();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onComplete() {
|
||||
// Log.e("addAlarmClock", "onSubscribe: ");
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建被观察者集合
|
||||
*
|
||||
* @param alarmClockDataList
|
||||
* @return
|
||||
*/
|
||||
private List<Observable<BaseResponse<AlarmClockId>>> getAddObservableList(List<AlarmClockData> alarmClockDataList) {
|
||||
List<Observable<BaseResponse<AlarmClockId>>> events = new ArrayList<>();
|
||||
for (AlarmClockData alarmClockData : alarmClockDataList) {
|
||||
events.add(getAddObservable(alarmClockData));
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
private Observable<BaseResponse<AlarmClockId>> getAddObservable(AlarmClockData alarmClockData) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("sn", Utils.getSerial());
|
||||
params.put("time", alarmClockData.getTime());
|
||||
params.put("type", String.valueOf(alarmClockData.getType()));
|
||||
params.put("title", alarmClockData.getTitle());
|
||||
params.put("remind_type", "0");
|
||||
params.put("is_onoff", "1");
|
||||
|
||||
File picFile = new File(alarmClockData.getFile());
|
||||
MediaType mediaType = MediaType.Companion.parse("image/png");
|
||||
RequestBody requestBody = RequestBody.Companion.create(picFile, mediaType);
|
||||
MultipartBody.Part body = MultipartBody.Part.createFormData("file", picFile.getName(), requestBody);
|
||||
|
||||
return NetInterfaceManager.getInstance().getAlarmClockAddObservable(params, body);
|
||||
}
|
||||
|
||||
private int deleteFinishStatu;
|
||||
|
||||
@Override
|
||||
public void deleteAlarmClock() {
|
||||
List<AlarmClockData> deletedAlarm = AlarmUtils.getInstance().getDeletedAlarm();
|
||||
if (deletedAlarm.size() == 0) {
|
||||
Log.e(TAG, "deleteAlarmClock: deletedAlarm is empty");
|
||||
mView.deleteAlarmClockFinish();
|
||||
} else {
|
||||
deleteFinishStatu = 0;
|
||||
for (AlarmClockData alarmClockData : deletedAlarm) {
|
||||
NetInterfaceManager.getInstance().deleteAlarmClockObservable(alarmClockData.getId())
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("deleteAlarmClock", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("deleteAlarmClock", "onNext: " + baseResponse);
|
||||
AlarmUtils.getInstance().deleteAlarmClock(alarmClockData.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("deleteAlarmClock", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
deleteFinishStatu += 1;
|
||||
Log.e("deleteAlarmClock", "onComplete: " + deleteFinishStatu);
|
||||
if (deleteFinishStatu == deletedAlarm.size()) {
|
||||
mView.deleteAlarmClockFinish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Observable.concat(getDeletedObservableList(deletedAlarm))
|
||||
// .compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
// .subscribe(new Observer<BaseResponse>() {
|
||||
// @Override
|
||||
// public void onSubscribe(@NonNull Disposable d) {
|
||||
// Log.e("deleteAlarmClock", "onSubscribe: ");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
// Log.e("deleteAlarmClock", "onSubscribe: " + baseResponse);
|
||||
// AlarmUtils.getInstance().deleteAlarmClock(deletedAlarm.get());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(@NonNull Throwable e) {
|
||||
// Log.e("deleteAlarmClock", "onError: " + e.getMessage());
|
||||
// onComplete();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onComplete() {
|
||||
// Log.e("deleteAlarmClock", "onSubscribe: ");
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建被观察者集合
|
||||
*
|
||||
* @param alarmClockDataList
|
||||
* @return
|
||||
*/
|
||||
private List<Observable<BaseResponse>> getDeletedObservableList(List<AlarmClockData> alarmClockDataList) {
|
||||
List<Observable<BaseResponse>> events = new ArrayList<>();
|
||||
for (AlarmClockData alarmClockData : alarmClockDataList) {
|
||||
events.add(getDeletedObservable(alarmClockData));
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
private Observable<BaseResponse> getDeletedObservable(AlarmClockData alarmClockData) {
|
||||
return NetInterfaceManager.getInstance().deleteAlarmClockObservable(alarmClockData.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAlarmClock() {
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.uiuios.aios.BuildConfig;
|
||||
import com.uiuios.aios.activity.NoticeActivity;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.base.BaseService;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.ApkUtils;
|
||||
@@ -51,7 +51,7 @@ import okhttp3.RequestBody;
|
||||
public class MainService extends BaseService implements MainSContact.MainSView, NetworkUtils.OnNetworkStatusChangedListener {
|
||||
private static final String TAG = MainService.class.getSimpleName();
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public static MainSPresenter mPresenter;
|
||||
public MainSPresenter mPresenter;
|
||||
|
||||
public MainService() {
|
||||
|
||||
@@ -64,7 +64,9 @@ public class MainService extends BaseService implements MainSContact.MainSView,
|
||||
|
||||
@Override
|
||||
public void onConnected(NetworkUtils.NetworkType networkType) {
|
||||
|
||||
if (isScreenOn()) {
|
||||
mPresenter.addAlarmClock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,7 +89,7 @@ public class MainService extends BaseService implements MainSContact.MainSView,
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
NetworkUtils.registerNetworkStatusChangedListener(this);
|
||||
mPresenter.getAlarmClock();
|
||||
mPresenter.addAlarmClock();
|
||||
registerAlarmReceiver();
|
||||
registerTimeReceiver();
|
||||
registerLockScreenReceiver();
|
||||
@@ -115,11 +117,27 @@ public class MainService extends BaseService implements MainSContact.MainSView,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAlarmClockFinish() {
|
||||
mPresenter.deleteAlarmClock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAlarmClockFinish() {
|
||||
mPresenter.getAlarmClock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmClock(List<AlarmClockData> dataList) {
|
||||
|
||||
}
|
||||
|
||||
public boolean isScreenOn() {
|
||||
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
//true为打开,false为关闭
|
||||
return powerManager.isInteractive();
|
||||
}
|
||||
|
||||
public static final String ALARMWAKEUP = "ALARM_WAKEUP";
|
||||
|
||||
private void registerAlarmReceiver() {
|
||||
@@ -157,7 +175,7 @@ public class MainService extends BaseService implements MainSContact.MainSView,
|
||||
}
|
||||
|
||||
public void setNextAlarm(int code) {
|
||||
HashMap<Integer, AlarmClockData> clockDataHashMap = AlarmUtils.getInstance().getOldData();
|
||||
HashMap<Integer, AlarmClockData> clockDataHashMap = AlarmUtils.getInstance().getOldDataMap();
|
||||
AlarmClockData alarmClockData = clockDataHashMap.get(code);
|
||||
Log.e(TAG, "setNextAlarm: " + alarmClockData);
|
||||
if (alarmClockData != null) {
|
||||
@@ -415,7 +433,7 @@ public class MainService extends BaseService implements MainSContact.MainSView,
|
||||
@Download.onTaskRunning
|
||||
protected void running(DownloadTask task) {
|
||||
Log.e("aria", "正在下载:" + task.getPercent() + ":" + task.getExtendField());
|
||||
ToastUtil.show("正在下载:" + task.getPercent() + "%" + "\t" + Formatter.formatFileSize(MainService.this, task.getSpeed()) + "/s");
|
||||
// ToastUtil.show("正在下载:" + task.getPercent() + "%" + "\t" + Formatter.formatFileSize(MainService.this, task.getSpeed()) + "/s");
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
|
||||
@@ -20,6 +20,7 @@ import androidx.annotation.RequiresApi;
|
||||
import com.uiuios.aios.BuildConfig;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.bean.DesktopIcon;
|
||||
import com.uiuios.aios.manager.AppStatusManager;
|
||||
import com.uiuios.aios.receiver.InstallResultReceiver;
|
||||
|
||||
import java.io.File;
|
||||
@@ -182,6 +183,10 @@ public class ApkUtils {
|
||||
Log.e(TAG, "queryFilterAppInfo: disable = " + pkg);
|
||||
continue;
|
||||
}
|
||||
if (AppStatusManager.getInstance().getHidedAppSet().contains(pkg)) {
|
||||
Log.e(TAG, "queryFilterAppInfo: hided = " + pkg);
|
||||
continue;
|
||||
}
|
||||
if (isSystemApp(context, pkg))//通过flag排除系统应用,会将电话、短信也排除掉
|
||||
{
|
||||
if (showPackageName.contains(pkg)) {
|
||||
@@ -194,9 +199,9 @@ public class ApkUtils {
|
||||
// resolveInfos.add(resolveInfo);
|
||||
// }
|
||||
// } else {
|
||||
if (allowPackages.contains(pkg) && !excludePackageName.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
}
|
||||
if (allowPackages.contains(pkg) && !excludePackageName.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.uiuios.aios.utils;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class FileUtil {
|
||||
@@ -14,6 +15,10 @@ public class FileUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isLocalPath(String path) {
|
||||
return path.startsWith(File.separator);
|
||||
}
|
||||
|
||||
private static HashSet<String> videoFormat = new HashSet<String>() {{
|
||||
this.add(".mp4");
|
||||
this.add(".avi");
|
||||
|
||||
@@ -11,6 +11,8 @@ import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Glide 加载 简单判空封装 防止异步加载数据时调用Glide 抛出异常
|
||||
* Created by Li_Xavier on 2017/6/20 0020.
|
||||
@@ -51,6 +53,22 @@ public class GlideLoadUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public void glideLoad(Context context, String url, ImageView imageView) {
|
||||
if (context != null) {
|
||||
Glide.with(context).load(url).centerCrop().into(imageView);
|
||||
} else {
|
||||
Log.i(TAG, "Picture loading failed,context is null");
|
||||
}
|
||||
}
|
||||
|
||||
public void glideLoad(Context context, File file, ImageView imageView) {
|
||||
if (context != null) {
|
||||
Glide.with(context).load(file).centerCrop().into(imageView);
|
||||
} else {
|
||||
Log.i(TAG, "Picture loading failed,context is null");
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
public void glideLoad(Activity activity, String url, ImageView imageView, int default_image) {
|
||||
if (!activity.isDestroyed()) {
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.uiuios.aios.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
|
||||
public class GsonUtils {
|
||||
public static JsonObject getJsonObject(String jsonString) {
|
||||
JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
// TODO: 2022/3/31 暂时没有实现
|
||||
public static <T> T getJsonFromType(String jsonString, Class clazz) {
|
||||
Gson gson = new Gson();
|
||||
T t = (T) gson.fromJson(jsonString, clazz);
|
||||
return t;
|
||||
}
|
||||
|
||||
public static String toJsonString(Object o) {
|
||||
return new Gson().toJson(o);
|
||||
}
|
||||
}
|
||||
21
app/src/main/java/com/uiuios/aios/utils/ScreenUtil.java
Normal file
21
app/src/main/java/com/uiuios/aios/utils/ScreenUtil.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.uiuios.aios.utils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class ScreenUtil {
|
||||
/**
|
||||
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
|
||||
*/
|
||||
public static int dip2px(Context context, float dpValue) {
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (int) (dpValue * scale + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手机的分辨率从 px(像素) 的单位 转成为 dp
|
||||
*/
|
||||
public static int px2dip(Context context, float pxValue) {
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (int) (pxValue / scale + 0.5f);
|
||||
}
|
||||
}
|
||||
@@ -26,4 +26,12 @@ public class TimeUtils {
|
||||
Date date = new Date(millSec);
|
||||
return sdf.format(date);
|
||||
}
|
||||
|
||||
public static String secToTime(int totalSecs) {
|
||||
int hours = totalSecs / 3600;
|
||||
int minutes = (totalSecs % 3600) / 60;
|
||||
int seconds = totalSecs % 60;
|
||||
String timeString = String.format("%02d:%02d:%02d", hours, minutes, seconds);
|
||||
return timeString;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
@@ -41,13 +42,13 @@ public class ToastUtil {
|
||||
ToastUtils.make()
|
||||
// .setBgColor(ColorUtils.getColor(R.color.toast_color))
|
||||
.setTextColor(Color.DKGRAY)
|
||||
// .setGravity(Gravity.CENTER, 0, 0)
|
||||
.setGravity(Gravity.CENTER, 0, 0)
|
||||
.setNotUseSystemToast()
|
||||
.show(msg);
|
||||
}
|
||||
|
||||
public static void betaShow(final String msg) {
|
||||
if ( BuildConfig.DEBUG) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
ToastUtils.make()
|
||||
// .setBgColor(ColorUtils.getColor(R.color.toast_color))
|
||||
.setTextColor(Color.RED)
|
||||
|
||||
225
app/src/main/java/com/uiuios/aios/utils/WiFiUtils.java
Normal file
225
app/src/main/java/com/uiuios/aios/utils/WiFiUtils.java
Normal file
@@ -0,0 +1,225 @@
|
||||
package com.uiuios.aios.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : fanhuitong
|
||||
* e-mail :
|
||||
* @date : 2021/10/25 10:20
|
||||
* desc :
|
||||
* version: 1.0
|
||||
*/
|
||||
public class WiFiUtils {
|
||||
private static WiFiUtils sInstance;
|
||||
private static WifiManager mWifiManager;
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private Context mContext;
|
||||
private static String TAG = WiFiUtils.class.getSimpleName();
|
||||
|
||||
public WiFiUtils(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
if (sInstance == null) {
|
||||
Log.e(TAG, "init: ");
|
||||
sInstance = new WiFiUtils(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static WiFiUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init WiFiUtils first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* wifi是否打开
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isWifiEnable() {
|
||||
boolean isEnable = false;
|
||||
if (mWifiManager != null) {
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
isEnable = true;
|
||||
}
|
||||
}
|
||||
return isEnable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开WiFi
|
||||
*/
|
||||
public void openWifi() {
|
||||
if (mWifiManager != null && !isWifiEnable()) {
|
||||
mWifiManager.setWifiEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭WiFi
|
||||
*/
|
||||
public void closeWifi() {
|
||||
if (mWifiManager != null && isWifiEnable()) {
|
||||
mWifiManager.setWifiEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取WiFi列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<ScanResult> getWifiList() {
|
||||
List<ScanResult> resultList = new ArrayList<>();
|
||||
if (mWifiManager != null && isWifiEnable()) {
|
||||
resultList.addAll(mWifiManager.getScanResults());
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 有密码连接
|
||||
*
|
||||
* @param ssid
|
||||
* @param pws
|
||||
*/
|
||||
public static void connectWifiPws(String ssid, String pws) {
|
||||
// mWifiManager.disableNetwork(mWifiManager.getConnectionInfo().getNetworkId());
|
||||
mWifiManager.disconnect();
|
||||
int netId = mWifiManager.addNetwork(getWifiConfig(ssid, pws, true));
|
||||
mWifiManager.enableNetwork(netId, true);
|
||||
mWifiManager.reconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* 无密码连接
|
||||
*
|
||||
* @param ssid
|
||||
*/
|
||||
public void connectWifiNoPws(String ssid) {
|
||||
// mWifiManager.disableNetwork(mWifiManager.getConnectionInfo().getNetworkId());
|
||||
int netId = mWifiManager.addNetwork(getWifiConfig(ssid, "", false));
|
||||
mWifiManager.enableNetwork(netId, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* wifi设置
|
||||
*
|
||||
* @param ssid
|
||||
* @param pws
|
||||
* @param isHasPws
|
||||
*/
|
||||
private static WifiConfiguration getWifiConfig(String ssid, String pws, boolean isHasPws) {
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.allowedAuthAlgorithms.clear();
|
||||
config.allowedGroupCiphers.clear();
|
||||
config.allowedKeyManagement.clear();
|
||||
config.allowedPairwiseCiphers.clear();
|
||||
config.allowedProtocols.clear();
|
||||
config.SSID = "\"" + ssid + "\"";
|
||||
|
||||
WifiConfiguration tempConfig = isExist(ssid);
|
||||
if (tempConfig != null) {
|
||||
mWifiManager.removeNetwork(tempConfig.networkId);
|
||||
}
|
||||
if (isHasPws) {
|
||||
config.preSharedKey = "\"" + pws + "\"";
|
||||
config.hiddenSSID = true;
|
||||
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
|
||||
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
|
||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
|
||||
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
|
||||
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
|
||||
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
|
||||
config.status = WifiConfiguration.Status.ENABLED;
|
||||
} else {
|
||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到配置好的网络连接
|
||||
*
|
||||
* @param ssid
|
||||
* @return
|
||||
*/
|
||||
private static WifiConfiguration isExist(String ssid) {
|
||||
List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
|
||||
for (WifiConfiguration config : configs) {
|
||||
if (config.SSID.equals("\"" + ssid + "\"")) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addWiFiNetwork(String ssid, String passwd) {
|
||||
int netId;
|
||||
if (TextUtils.isEmpty(passwd)) {
|
||||
netId = mWifiManager.addNetwork(getWifiConfig(ssid, "", false));
|
||||
} else {
|
||||
netId = mWifiManager.addNetwork(getWifiConfig(ssid, passwd, true));
|
||||
}
|
||||
mWifiManager.enableNetwork(netId, true);
|
||||
}
|
||||
|
||||
public static void removeWiFiNetwork(String ssid) {
|
||||
WifiConfiguration tempConfig = isExist(ssid);
|
||||
int networkId = tempConfig.networkId;
|
||||
mWifiManager.removeNetwork(networkId);
|
||||
mWifiManager.saveConfiguration();
|
||||
}
|
||||
|
||||
synchronized private static boolean wifiSaved(String ssid) {
|
||||
// 获取已保存wifi配置链表
|
||||
List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
|
||||
boolean saved = false;
|
||||
for (WifiConfiguration configuration : configs) {
|
||||
if (ssid.equals(configuration.SSID)) {
|
||||
saved = true;
|
||||
}
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
//断判某个wifi是否是连接成功的那个wifi
|
||||
public boolean isConnectedWifi(Context context, String myssid) {
|
||||
WifiManager mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
if (isWifiConnect(context)) {
|
||||
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
||||
String ssid = wifiInfo.getSSID();
|
||||
return ssid != null && ssid.contains(myssid);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//判断wifi是否连接
|
||||
public static boolean isWifiConnect(Context context) {
|
||||
ConnectivityManager connManager = (ConnectivityManager) context
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
@SuppressLint("MissingPermission")
|
||||
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
return mWifi.getState() == NetworkInfo.State.CONNECTED;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user