version:1.1.6
fix: update:修改图标大小,增加闹钟
This commit is contained in:
1 parent
3d15a60ac9
commit
e081884984
112 files changed
+16918
-163
No files matched your search
@@ -521,6 +521,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
||||
Log.e("AliyunPush", "init cloudchannel failed -- errorcode:" + errorCode + " -- errorMessage:" + errorMessage);
|
||||
}
|
||||
});
|
||||
NetInterfaceManager.getInstance().getAlarmClock();
|
||||
}
|
||||
|
||||
MainService.MainBinder mMainBinder;
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
import android.content.Intent;
|
||||
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 com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuipad.os.R;
|
||||
import com.uiuipad.os.network.NetInterfaceManager;
|
||||
import com.uiuipad.os.uiuiutils.ToastUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
public class AlarmActivity extends BaseActivity implements AlarmContact.AlarmView {
|
||||
private static final String TAG = AlarmActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.cl_exit)
|
||||
ConstraintLayout cl_exit;
|
||||
@BindView(R.id.cl_all)
|
||||
ConstraintLayout cl_all;
|
||||
@BindView(R.id.cl_medicine)
|
||||
ConstraintLayout cl_medicine;
|
||||
@BindView(R.id.cl_look)
|
||||
ConstraintLayout cl_look;
|
||||
@BindView(R.id.cl_reserve)
|
||||
ConstraintLayout cl_reserve;
|
||||
|
||||
@BindView(R.id.rv_data)
|
||||
RecyclerView rv_data;
|
||||
@BindView(R.id.cl_nodata)
|
||||
ConstraintLayout cl_nodata;
|
||||
|
||||
@BindView(R.id.imageView2)
|
||||
ImageView imageView2;
|
||||
@BindView(R.id.imageView4)
|
||||
ImageView imageView4;
|
||||
@BindView(R.id.imageView6)
|
||||
ImageView imageView6;
|
||||
@BindView(R.id.imageView8)
|
||||
ImageView imageView8;
|
||||
|
||||
@BindView(R.id.iv_add)
|
||||
ImageView iv_add;
|
||||
|
||||
private AlarmPresenter mPresenter;
|
||||
private AlarmAdapter mAlarmAdapter;
|
||||
|
||||
/**
|
||||
* 设置布局
|
||||
*/
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_alarm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mPresenter = new AlarmPresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
|
||||
mAlarmAdapter = new AlarmAdapter();
|
||||
mAlarmAdapter.setOnLongClickListener(new AlarmAdapter.OnLongClickListener() {
|
||||
@Override
|
||||
public void onLongClick(AlarmClockData alarmClockData) {
|
||||
// showDialog(alarmClockData);
|
||||
}
|
||||
});
|
||||
rv_data.setLayoutManager(new LinearLayoutManager(AlarmActivity.this));
|
||||
rv_data.setAdapter(mAlarmAdapter);
|
||||
switchItem(0);
|
||||
cl_exit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
cl_all.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switchItem(0);
|
||||
mPresenter.getAlarmClock(0);
|
||||
}
|
||||
});
|
||||
cl_medicine.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switchItem(1);
|
||||
mPresenter.getAlarmClock(1);
|
||||
}
|
||||
});
|
||||
cl_look.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switchItem(2);
|
||||
mPresenter.getAlarmClock(2);
|
||||
}
|
||||
});
|
||||
cl_reserve.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switchItem(3);
|
||||
mPresenter.getAlarmClock(3);
|
||||
}
|
||||
});
|
||||
|
||||
iv_add.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// startActivity(new Intent(AlarmActivity.this, AlarmClockAddActivity.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
@Override
|
||||
public void initData() {
|
||||
mPresenter.getAlarmClock(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mPresenter.getAlarmClock();
|
||||
}
|
||||
|
||||
private void switchItem(int position) {
|
||||
cl_all.setBackground(null);
|
||||
cl_medicine.setBackground(null);
|
||||
cl_look.setBackground(null);
|
||||
cl_reserve.setBackground(null);
|
||||
imageView2.setImageDrawable(null);
|
||||
imageView4.setImageDrawable(null);
|
||||
imageView6.setImageDrawable(null);
|
||||
imageView8.setImageDrawable(null);
|
||||
|
||||
switch (position) {
|
||||
case 0:
|
||||
default:
|
||||
cl_all.setBackground(getDrawable(R.drawable.alarm_pressed_background));
|
||||
imageView2.setImageDrawable(getDrawable(R.drawable.icon_touch));
|
||||
break;
|
||||
case 1:
|
||||
cl_medicine.setBackground(getDrawable(R.drawable.alarm_pressed_background));
|
||||
imageView4.setImageDrawable(getDrawable(R.drawable.icon_touch));
|
||||
break;
|
||||
case 2:
|
||||
cl_look.setBackground(getDrawable(R.drawable.alarm_pressed_background));
|
||||
imageView6.setImageDrawable(getDrawable(R.drawable.icon_touch));
|
||||
break;
|
||||
case 3:
|
||||
cl_reserve.setBackground(getDrawable(R.drawable.alarm_pressed_background));
|
||||
imageView8.setImageDrawable(getDrawable(R.drawable.icon_touch));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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(0);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public void setAlarmClock(List<AlarmClockData> alarmClockData) {
|
||||
if (alarmClockData == null || alarmClockData.size() == 0) {
|
||||
mAlarmAdapter.setAlarmClockData(null);
|
||||
// swipeRefreshLayout.setRefreshing(false);
|
||||
cl_nodata.setVisibility(View.VISIBLE);
|
||||
rv_data.setVisibility(View.GONE);
|
||||
ToastUtil.show("没有数据");
|
||||
} else {
|
||||
mAlarmAdapter.setAlarmClockData(alarmClockData);
|
||||
// swipeRefreshLayout.setRefreshing(false);
|
||||
cl_nodata.setVisibility(View.GONE);
|
||||
rv_data.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.MediaPlayer;
|
||||
import android.text.TextUtils;
|
||||
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;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.uiuipad.os.R;
|
||||
import com.uiuipad.os.uiuiutils.FFmpegUtils;
|
||||
import com.uiuipad.os.uiuiutils.ScreenUtils;
|
||||
import com.uiuipad.os.uiuiutils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
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) {
|
||||
mContext = (FragmentActivity) parent.getContext();
|
||||
return new AlarmAdapter.holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_alarm, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull holder holder, int position) {
|
||||
AlarmClockData alarmClockData = mAlarmClockData.get(position);
|
||||
switch (alarmClockData.getType()) {
|
||||
case AlarmUtils.ONCE:
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
Date date = sdf.parse(alarmClockData.getTime());
|
||||
SimpleDateFormat hours = new SimpleDateFormat("HH:mm");
|
||||
String time = hours.format(date);
|
||||
holder.tv_time.setText(time);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
holder.tv_remind_type.setText("一次");
|
||||
holder.tv_remind_type.setBackgroundResource(R.drawable.tv_times_bg_once);
|
||||
break;
|
||||
case AlarmUtils.LOOP:
|
||||
holder.tv_time.setText(alarmClockData.getTime());
|
||||
holder.tv_remind_type.setText("每天");
|
||||
holder.tv_remind_type.setBackgroundResource(R.drawable.tv_times_bg_loop);
|
||||
break;
|
||||
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 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:
|
||||
}
|
||||
String title = alarmClockData.getTitle();
|
||||
if (TextUtils.isEmpty(title)) {
|
||||
holder.tv_title.setText("无标题");
|
||||
} else {
|
||||
holder.tv_title.setText(title);
|
||||
}
|
||||
int is_onoff = alarmClockData.getIs_onoff();
|
||||
holder.toggleButton2.setDisable(true);
|
||||
if (is_onoff == 1) {
|
||||
holder.tv_status.setText("已开启");
|
||||
holder.toggleButton2.setToggleOn(false);
|
||||
} else {
|
||||
holder.tv_status.setText("已关闭");
|
||||
holder.toggleButton2.setToggleOff(false);
|
||||
}
|
||||
// int type = alarmClockData.getClazz();
|
||||
// switch (type){
|
||||
// case 1:
|
||||
// default:
|
||||
// holder.iv_type.setImageDrawable(mContext.getDrawable(R.drawable.icon_alarm_medicine));
|
||||
// break;
|
||||
// case 2:
|
||||
// holder.iv_type.setImageDrawable(mContext.getDrawable(R.drawable.icon_alarm_look));
|
||||
// break;
|
||||
// case 3:
|
||||
// holder.iv_type.setImageDrawable(mContext.getDrawable(R.drawable.icon_alarm_reserve));
|
||||
// break;
|
||||
// }
|
||||
String voice = alarmClockData.getVoice();
|
||||
if (TextUtils.isEmpty(voice)) {
|
||||
holder.cl_voice.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.cl_voice.setVisibility(View.VISIBLE);
|
||||
MediaPlayer mMediaPlayer = new MediaPlayer();
|
||||
mMediaPlayer.setAudioAttributes(
|
||||
new AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
|
||||
.build()
|
||||
);
|
||||
mMediaPlayer.setOnCompletionListener(mp -> Log.e("setOnCompletionListener", "onCompletion: "));
|
||||
mMediaPlayer.setOnPreparedListener(mp -> Log.e("setOnPreparedListener", "onPrepared: "));
|
||||
mMediaPlayer.setOnErrorListener((mp, what, extra) -> false);
|
||||
//设置音频文件到MediaPlayer对象中
|
||||
try {
|
||||
mMediaPlayer.setDataSource(voice);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//让MediaPlayer对象准备,用这个方法防止加载时耗时导致anr
|
||||
mMediaPlayer.prepareAsync();
|
||||
FFmpegUtils.getDurationInMilliseconds(voice, new Observer<Integer>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull Integer integer) {
|
||||
holder.tv_voice.setText(integer + "秒");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
holder.cl_voice.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mMediaPlayer.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
String fileUrl = alarmClockData.getFile();
|
||||
if (TextUtils.isEmpty(fileUrl)) {
|
||||
holder.cl_vp.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.cl_vp.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(fileUrl).apply(options).into(holder.imageView);
|
||||
}
|
||||
} else {
|
||||
holder.imageView.setVisibility(View.GONE);
|
||||
holder.jz_video.setVisibility(View.VISIBLE);
|
||||
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(path, new Observer<Bitmap>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
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(@NonNull Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private Pattern mCompile = Pattern.compile(".*?(gif|jpeg|png|jpg|bmp|webp)");
|
||||
|
||||
private boolean isImgUrl(String url) {
|
||||
if (TextUtils.isEmpty(url) || url.trim().length() == 0) {
|
||||
return false;
|
||||
}
|
||||
return mCompile.matcher(url).matches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mAlarmClockData == null ? 0 : mAlarmClockData.size();
|
||||
}
|
||||
|
||||
class holder extends RecyclerView.ViewHolder {
|
||||
TextView tv_time, tv_remind_type, tv_title, tv_voice, tv_status;
|
||||
ConstraintLayout cl_voice, cl_vp, root;
|
||||
JzvdStdRound jz_video;
|
||||
ImageView imageView,iv_type;
|
||||
ToggleButton toggleButton2;
|
||||
|
||||
public holder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
tv_time = itemView.findViewById(R.id.tv_time);
|
||||
tv_remind_type = itemView.findViewById(R.id.tv_remind_type);
|
||||
tv_title = itemView.findViewById(R.id.tv_title);
|
||||
tv_voice = itemView.findViewById(R.id.tv_voice);
|
||||
cl_voice = itemView.findViewById(R.id.cl_voice);
|
||||
cl_vp = itemView.findViewById(R.id.cl_vp);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
jz_video = itemView.findViewById(R.id.jz_video);
|
||||
imageView = itemView.findViewById(R.id.imageView);
|
||||
iv_type = itemView.findViewById(R.id.iv_type);
|
||||
tv_status = itemView.findViewById(R.id.tv_status);
|
||||
toggleButton2 = itemView.findViewById(R.id.toggleButton2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
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;
|
||||
|
||||
int id;
|
||||
int type;//类型 1一次 2循环 3周一到周五 4 周六周日
|
||||
String time;//"2021-11-15 18:33:23",//时间格式化字符串,循环类型是18:33:23
|
||||
String title;//标题
|
||||
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;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getVoice() {
|
||||
return voice;
|
||||
}
|
||||
|
||||
public void setVoice(String voice) {
|
||||
this.voice = voice;
|
||||
}
|
||||
|
||||
public String getVoice_md5() {
|
||||
return voice_md5;
|
||||
}
|
||||
|
||||
public void setVoice_md5(String voice_md5) {
|
||||
this.voice_md5 = voice_md5;
|
||||
}
|
||||
|
||||
public String getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(String file) {
|
||||
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;
|
||||
}
|
||||
|
||||
public void setFinished(boolean finished) {
|
||||
this.finished = finished;
|
||||
}
|
||||
|
||||
public int getRemind_type() {
|
||||
return remind_type;
|
||||
}
|
||||
|
||||
public void setRemind_type(int remind_type) {
|
||||
this.remind_type = remind_type;
|
||||
}
|
||||
|
||||
public int getIs_onoff() {
|
||||
return is_onoff;
|
||||
}
|
||||
|
||||
public void setIs_onoff(int is_onoff) {
|
||||
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;
|
||||
}
|
||||
if (time.length() == 5) {
|
||||
String[] timeSplit = time.split(":");
|
||||
int hour = Integer.parseInt(timeSplit[0]);
|
||||
int minute = Integer.parseInt(timeSplit[1]);
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH),
|
||||
c.get(Calendar.DAY_OF_MONTH), hour, minute, 0);
|
||||
long mTimeInfo = c.getTimeInMillis();
|
||||
Log.e("AlarmClockData", "getTimeStamp: " + mTimeInfo);
|
||||
long actualTime = mTimeInfo > System.currentTimeMillis() ? mTimeInfo : mTimeInfo + AlarmUtils.ONE_DAY_TIME;
|
||||
return actualTime;
|
||||
} else {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
try {
|
||||
Date date = simpleDateFormat.parse(time);
|
||||
long timestamp = date.getTime();
|
||||
return timestamp;
|
||||
} catch (ParseException e) {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (obj == null) return false;
|
||||
if (!(obj instanceof AlarmClockData)) return false;
|
||||
if (id != ((AlarmClockData) obj).id) return false;
|
||||
if (type != ((AlarmClockData) obj).type) 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;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AlarmContact {
|
||||
public interface Presenter extends BasePresenter<AlarmView> {
|
||||
void getAlarmClock();
|
||||
void getAlarmClock(int type);
|
||||
}
|
||||
|
||||
public interface AlarmView extends BaseView {
|
||||
void setAlarmClock(List<AlarmClockData> alarmClockData);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class AlarmOpenHelper extends SQLiteOpenHelper {
|
||||
|
||||
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 = File.separator + DATABASE_NAME;
|
||||
|
||||
public static final String TABLE_ALARM = " AlarmTable";
|
||||
|
||||
public static final String KEY_ID = "id";
|
||||
public static final String KEY_TYPE = "type";
|
||||
public static final String KEY_TIME = "time";
|
||||
public static final String KEY_TITLE = "title";
|
||||
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 +
|
||||
"("
|
||||
+ KEY_ID + " INTEGER PRIMARY KEY,"
|
||||
+ KEY_TYPE + " INTEGER,"
|
||||
+ KEY_TIME + " TEXT,"
|
||||
+ KEY_TITLE + " TEXT,"
|
||||
+ 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_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) {
|
||||
super(context, name, factory, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL(CREATE_ALARM_TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuipad.os.network.NetInterfaceManager;
|
||||
import com.uiuipad.os.network.bean.BaseResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
public class AlarmPresenter implements AlarmContact.Presenter {
|
||||
|
||||
private AlarmContact.AlarmView mView;
|
||||
private Context mContext;
|
||||
|
||||
AlarmPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(@NonNull AlarmContact.AlarmView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getAlarmClock() {
|
||||
NetInterfaceManager.getInstance().getAlarmClock(true, getLifecycle(), new NetInterfaceManager.AlarmClockCallback() {
|
||||
@Override
|
||||
public void setAlarmClock(List<AlarmClockData> alarmClockList) {
|
||||
if (alarmClockList.size() == 0) {
|
||||
setAlarmClockEmpty();
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmClockEmpty() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAlarmClock(int type) {
|
||||
NetInterfaceManager.getInstance().getAlarmClockObservable()
|
||||
.subscribe(new Observer<BaseResponse<List<AlarmClockData>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getAlarmClock", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<AlarmClockData>> listBaseResponse) {
|
||||
Log.e("getAlarmClock", "onNext: " + listBaseResponse);
|
||||
mView.setAlarmClock(listBaseResponse.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAlarmClock", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAlarmClock", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,843 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.blankj.utilcode.util.FileUtils;
|
||||
import com.uiuipad.os.service.MainService;
|
||||
import com.uiuipad.os.uiuiutils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
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 Context mContext;
|
||||
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, 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) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("context is NULL");
|
||||
}
|
||||
if (sInstance == null) {
|
||||
sInstance = new AlarmUtils(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static AlarmUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init AlarmUtils first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加数据
|
||||
*
|
||||
* @param alarmClockData
|
||||
* @return
|
||||
*/
|
||||
public boolean addAlarmClock(AlarmClockData alarmClockData) {
|
||||
openDatabase();
|
||||
ContentValues values = getValuesFromAlarmClock(alarmClockData);
|
||||
long id = 0;
|
||||
mDatabase.beginTransaction();
|
||||
try {
|
||||
id = mDatabase.insertWithOnConflict(AlarmOpenHelper.TABLE_ALARM, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
mDatabase.setTransactionSuccessful();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "addAlarmClock: " + e.getMessage());
|
||||
} finally {
|
||||
mDatabase.endTransaction();
|
||||
}
|
||||
setAlarm(alarmClockData);
|
||||
return id > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*
|
||||
* @param alarmClockData
|
||||
* @return
|
||||
*/
|
||||
public boolean updateAlarmClock(AlarmClockData alarmClockData) {
|
||||
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;
|
||||
mDatabase.beginTransaction();
|
||||
try {
|
||||
id = mDatabase.insertWithOnConflict(AlarmOpenHelper.TABLE_ALARM, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
mDatabase.setTransactionSuccessful();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "updateAlarmClock: " + e.getMessage());
|
||||
} finally {
|
||||
mDatabase.endTransaction();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入数据
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
public void insertAlarmClockList(List<AlarmClockData> list) {
|
||||
openDatabase();
|
||||
List<ContentValues> contentValuesList = new ArrayList<>();
|
||||
for (AlarmClockData alarmClockData : list) {
|
||||
ContentValues values = getValuesFromAlarmClock(alarmClockData);
|
||||
contentValuesList.add(values);
|
||||
}
|
||||
mDatabase.beginTransaction();
|
||||
try {
|
||||
for (ContentValues v : contentValuesList) {
|
||||
mDatabase.insertWithOnConflict(AlarmOpenHelper.TABLE_ALARM, null, v, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
}
|
||||
mDatabase.setTransactionSuccessful();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "insertListValues: " + e.getMessage());
|
||||
} finally {
|
||||
mDatabase.endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param alarmClockData
|
||||
* @return
|
||||
*/
|
||||
public boolean deleteAlarmClock(AlarmClockData alarmClockData) {
|
||||
if (alarmClockData == null) {
|
||||
return true;
|
||||
}
|
||||
PendingIntent pendingIntent = getPendingIntent(alarmClockData);
|
||||
if (pendingIntent != null) {
|
||||
mAlarmManager.cancel(pendingIntent);
|
||||
}
|
||||
return deleteAlarmClock(alarmClockData.getId());
|
||||
}
|
||||
|
||||
public boolean deleteAlarmClock(int RowID) {
|
||||
openDatabase();
|
||||
long id = 0;
|
||||
mDatabase.beginTransaction();
|
||||
try {
|
||||
id = mDatabase.delete(AlarmOpenHelper.TABLE_ALARM, " id =" + RowID, null);
|
||||
mDatabase.setTransactionSuccessful();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "deleteAlarmClock: " + e.getMessage());
|
||||
} finally {
|
||||
mDatabase.endTransaction();
|
||||
}
|
||||
return id > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除所有闹钟
|
||||
*/
|
||||
public void deleteAllAlarmClock() {
|
||||
HashSet<PendingIntent> pendingIntents = getOldPendingIntentsSet();
|
||||
Iterator<PendingIntent> pendingIntentIterator = pendingIntents.iterator();
|
||||
while (pendingIntentIterator.hasNext()) {
|
||||
PendingIntent pendingIntent = pendingIntentIterator.next();
|
||||
mAlarmManager.cancel(pendingIntent);
|
||||
pendingIntentIterator.remove();
|
||||
}
|
||||
List<AlarmClockData> alarmClockData = getDatabaseAlarms();
|
||||
for (AlarmClockData data : alarmClockData) {
|
||||
deleteAlarmClock(data.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有Alarm
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<AlarmClockData> getDatabaseAlarms() {
|
||||
openDatabase();
|
||||
List<AlarmClockData> list = new ArrayList<>();
|
||||
String selectQuery = "SELECT * FROM " + AlarmOpenHelper.TABLE_ALARM;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置闹钟列表
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public void setAlarmClockData(List<AlarmClockData> data) {
|
||||
if (pendingIntents == null) {
|
||||
pendingIntents = getOldPendingIntentsSet();
|
||||
}
|
||||
Iterator<PendingIntent> pendingIntentIterator = pendingIntents.iterator();
|
||||
while (pendingIntentIterator.hasNext()) {
|
||||
PendingIntent pendingIntent = pendingIntentIterator.next();
|
||||
mAlarmManager.cancel(pendingIntent);
|
||||
pendingIntentIterator.remove();
|
||||
}
|
||||
List<AlarmClockData> newData = mergeData(data);
|
||||
for (AlarmClockData clockData : newData) {
|
||||
setAlarm(clockData);
|
||||
checkResource(clockData.getFile());
|
||||
}
|
||||
insertAlarmClockList(newData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url 下载资源
|
||||
*/
|
||||
private void checkResource(String url) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
return;
|
||||
}
|
||||
String fileName = url.substring(url.lastIndexOf("/") + 1, url.length());
|
||||
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 newAlarmClockDataList
|
||||
* @return 新增的闹钟
|
||||
*/
|
||||
private List<AlarmClockData> mergeData(List<AlarmClockData> newAlarmClockDataList) {
|
||||
HashMap<Integer, AlarmClockData> alarmClockDataMap = new HashMap<>();
|
||||
if (newAlarmClockDataList != null) {
|
||||
for (AlarmClockData alarmClockData : newAlarmClockDataList) {
|
||||
alarmClockDataMap.put(alarmClockData.getId(), alarmClockData);
|
||||
}
|
||||
}
|
||||
HashMap<Integer, AlarmClockData> oldData = getOldDataMap();
|
||||
List<AlarmClockData> deleteData = new ArrayList<>();
|
||||
for (Map.Entry<Integer, AlarmClockData> entry : oldData.entrySet()) {
|
||||
if (alarmClockDataMap.get(entry.getKey()) == null) {
|
||||
deleteData.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
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 (newAlarmClockDataList == null) {
|
||||
return newData;
|
||||
}
|
||||
for (AlarmClockData alarm : newAlarmClockDataList) {
|
||||
AlarmClockData oldAlarm = oldData.get(alarm.getId());
|
||||
if (oldAlarm == null) {
|
||||
newData.add(alarm);
|
||||
} else {
|
||||
if (oldAlarm.equals(alarm)) {
|
||||
newData.add(oldAlarm);
|
||||
} else {
|
||||
newData.add(alarm);
|
||||
}
|
||||
}
|
||||
}
|
||||
return newData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新完成状态
|
||||
*
|
||||
* @param alarmClockData
|
||||
* @return
|
||||
*/
|
||||
public boolean updateAlarmFinished(AlarmClockData alarmClockData) {
|
||||
openDatabase();
|
||||
ContentValues values = getValuesFromAlarmClock(alarmClockData);
|
||||
long id = 0;
|
||||
mDatabase.beginTransaction();
|
||||
try {
|
||||
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 {
|
||||
mDatabase.endTransaction();
|
||||
}
|
||||
return id > 0;
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
public AlarmClockData getRecentAlarmClock() {
|
||||
List<AlarmClockData> alarmClockData = getDatabaseAlarms();
|
||||
if (alarmClockData == null || alarmClockData.size() == 0) {
|
||||
return null;
|
||||
} else {
|
||||
Collections.sort(alarmClockData, new Comparator<AlarmClockData>() {
|
||||
@Override
|
||||
public int compare(AlarmClockData o1, AlarmClockData o2) {
|
||||
if ((o1.getTimeStamp()) <= (o2.getTimeStamp())) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
});
|
||||
return alarmClockData.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
private HashSet<PendingIntent> getOldPendingIntentsSet() {
|
||||
HashSet<PendingIntent> pendingIntents = new HashSet<>();
|
||||
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());
|
||||
intent.putExtra("id", alarmClock.getId());
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, alarmClock.getId(), intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
return startPendingIntent;
|
||||
}
|
||||
|
||||
private long getTimestamp(String timeString) {
|
||||
if (TextUtils.isEmpty(timeString)) {
|
||||
return 0;
|
||||
}
|
||||
if (timeString.length() == 5) {
|
||||
String[] timeSplit = timeString.split(":");
|
||||
int hour = Integer.parseInt(timeSplit[0]);
|
||||
int minute = Integer.parseInt(timeSplit[1]);
|
||||
Calendar c = Calendar.getInstance();
|
||||
int year = c.get(Calendar.YEAR);
|
||||
int month = c.get(Calendar.MONTH);
|
||||
int day = c.get(Calendar.DAY_OF_MONTH);
|
||||
c.set(year, month, day, hour, minute, 0);
|
||||
long mTimeInfo = c.getTimeInMillis();
|
||||
Log.e(TAG, "getTimestamp: " + mTimeInfo);
|
||||
// long actualTime = mTimeInfo > System.currentTimeMillis() ? mTimeInfo : mTimeInfo + ONE_DAY_TIME;
|
||||
return mTimeInfo;
|
||||
} else {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
try {
|
||||
Date date = simpleDateFormat.parse(timeString);
|
||||
long timestamp = date.getTime();
|
||||
Log.e(TAG, "getTimestamp2: " + timestamp);
|
||||
return timestamp;
|
||||
} catch (ParseException e) {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long getZeroTiemstamp() {
|
||||
//设置时区
|
||||
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"));
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
long zeroTime = calendar.getTimeInMillis();
|
||||
Log.e(TAG, "getZeroTiemstamp: " + zeroTime);
|
||||
return zeroTime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置闹钟
|
||||
*
|
||||
* @param alarm
|
||||
*/
|
||||
public void setAlarm(AlarmClockData alarm) {
|
||||
if (pendingIntents == null) {
|
||||
pendingIntents = getOldPendingIntentsSet();
|
||||
}
|
||||
int id = alarm.getId();
|
||||
int type = alarm.getType();
|
||||
String timeString = alarm.getTime();
|
||||
String title = alarm.getTitle();
|
||||
Log.e(TAG, "setAlarm: " + title);
|
||||
long timeStamp = getTimestamp(timeString);
|
||||
Log.e(TAG, "setAlarm: " + timeStamp);
|
||||
boolean finished = alarm.isFinished();
|
||||
String voiceUrl = alarm.getVoice();
|
||||
String voiceMd5 = alarm.getVoice_md5();
|
||||
if (!TextUtils.isEmpty(voiceUrl)) {
|
||||
ariaDownload(voiceUrl, voiceMd5);
|
||||
}
|
||||
String fileUrl = alarm.getFile();
|
||||
String fileMd5 = alarm.getFile_md5();
|
||||
if (!TextUtils.isEmpty(fileUrl)) {
|
||||
ariaDownload(fileUrl, fileMd5);
|
||||
}
|
||||
switch (type) {
|
||||
case ONCE:
|
||||
if (!finished) {
|
||||
if (timeStamp < System.currentTimeMillis()) {
|
||||
Intent intent = new Intent(MainService.ALARMWAKEUP);
|
||||
intent.putExtra("title", title);
|
||||
intent.putExtra("id", id);
|
||||
mContext.sendBroadcast(intent);
|
||||
} else {
|
||||
setOnceAlarm(MainService.ALARMWAKEUP, title, id, timeStamp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LOOP:
|
||||
setDayLoopAlarm(MainService.ALARMWAKEUP, title, id, timeString);
|
||||
break;
|
||||
case WORKING_DAY:
|
||||
setWorkDayAlarm(MainService.ALARMWAKEUP, title, id, timeString);
|
||||
break;
|
||||
case OFF_DAY:
|
||||
setOffDayAlarm(MainService.ALARMWAKEUP, title, id, timeString);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param action
|
||||
* @param requestCode
|
||||
* @param timestamp 设置一次性闹钟
|
||||
*/
|
||||
public void setOnceAlarm(String action, String extra, int requestCode, long timestamp) {
|
||||
Intent intent = new Intent(action);
|
||||
intent.putExtra("title", extra);
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
mAlarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setOnceAlarm: " + "id: " + requestCode + " title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param action
|
||||
* @param requestCode
|
||||
* @param timeString 设置循环周期为一天的闹钟
|
||||
*/
|
||||
public void setDayLoopAlarm(String action, String extra, int requestCode, String timeString) {
|
||||
long timestamp = getTimestamp(timeString);
|
||||
if (System.currentTimeMillis() > timestamp) {
|
||||
timestamp += AlarmManager.INTERVAL_DAY;
|
||||
}
|
||||
Intent intent = new Intent(action);
|
||||
intent.putExtra("title", extra);
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setDayLoopAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
// setLoopAlarm(action, extra, requestCode, AlarmManager.INTERVAL_DAY, timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param action
|
||||
* @param requestCode
|
||||
* @param timestamp 设置循环周期为一小时的闹钟
|
||||
*/
|
||||
public void setHourLoopAlarm(String action, String extra, int requestCode, long timestamp) {
|
||||
setLoopAlarm(action, extra, requestCode, AlarmManager.INTERVAL_HOUR, timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param action
|
||||
* @param requestCode
|
||||
* @param intervalMillis
|
||||
* @param timestamp 循环闹钟
|
||||
*/
|
||||
public void setLoopAlarm(String action, String extra, int requestCode, long intervalMillis, long timestamp) {
|
||||
Intent intent = new Intent(action);
|
||||
intent.putExtra("title", extra);
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
mAlarmManager.setWindow(AlarmManager.RTC_WAKEUP, timestamp, intervalMillis, startPendingIntent);
|
||||
Log.e(TAG, "setLoopAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
public void setWorkDayAlarm(String action, String extra, int requestCode, String timeString) {
|
||||
long timestamp = getTimestamp(timeString);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int day_of_week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
switch (day_of_week) {
|
||||
case 6:
|
||||
case 7:
|
||||
timestamp += (8 - day_of_week) * AlarmManager.INTERVAL_DAY;
|
||||
break;
|
||||
default:
|
||||
if (System.currentTimeMillis() > timestamp) {
|
||||
timestamp += AlarmManager.INTERVAL_DAY;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Intent intent = new Intent(action);
|
||||
intent.putExtra("title", extra);
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setWorkDayAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
public void setOffDayAlarm(String action, String extra, int requestCode, String timeString) {
|
||||
long timestamp = getTimestamp(timeString);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int day_of_week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
switch (day_of_week) {
|
||||
case 6:
|
||||
if (System.currentTimeMillis() > timestamp) {
|
||||
timestamp += AlarmManager.INTERVAL_DAY;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
break;
|
||||
default:
|
||||
timestamp += (6 - day_of_week) * AlarmManager.INTERVAL_DAY;
|
||||
break;
|
||||
}
|
||||
Intent intent = new Intent(action);
|
||||
intent.putExtra("title", extra);
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setOffDayAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
|
||||
public void ariaDownload(String url, String md5) {
|
||||
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", "fileOnlineMD5=" + md5);
|
||||
Log.e("ariaDownload", "fileMD5=" + fileMD5);
|
||||
if (!md5.equalsIgnoreCase(fileMD5)) {
|
||||
Aria.download(this)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(Utils.getDownLoadPath(mContext) + fileName)
|
||||
// .ignoreFilePathOccupy()
|
||||
.setExtendField(md5)
|
||||
.create(); //启动下载}
|
||||
} else {
|
||||
Log.e("ariaDownload", "fileName = " + fileName + " exists");
|
||||
}
|
||||
} else {
|
||||
Aria.download(this)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(Utils.getDownLoadPath(mContext) + fileName)
|
||||
// .ignoreFilePathOccupy()
|
||||
.setExtendField(md5)
|
||||
.create(); //启动下载}
|
||||
}
|
||||
}
|
||||
|
||||
public void ariaDownload(String url) {
|
||||
if (Utils.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(); //启动下载}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
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 com.uiuipad.os.R;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity implements LifecycleProvider<ActivityEvent> {
|
||||
public final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
|
||||
|
||||
public BaseActivity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@ContentView
|
||||
public BaseActivity(@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);
|
||||
// StatusBarUtil.init(this);
|
||||
UltimateBarX.statusBar(this)
|
||||
.transparent()
|
||||
.colorRes(R.color.white)
|
||||
// .light(true)
|
||||
.apply();
|
||||
UltimateBarX.navigationBar(this)
|
||||
.transparent()
|
||||
.colorRes(R.color.white)
|
||||
// .light(true)
|
||||
.apply();
|
||||
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,10 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public interface BasePresenter<V extends BaseView> {
|
||||
|
||||
void attachView(@NonNull V view);
|
||||
|
||||
void detachView();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
public interface BaseView {
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
import cn.jzvd.JzvdStd;
|
||||
|
||||
|
||||
public class JzvdStdAssert extends JzvdStd {
|
||||
private onVideoCompletionListener onVideoCompletionListener;
|
||||
private ScreenOrientationChangeListener changeListener;
|
||||
private GotoFullScreenListener gotoFullScreenListener;
|
||||
|
||||
public JzvdStdAssert(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public JzvdStdAssert(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPrepared() {
|
||||
Log.e("onStateChanged", "onPrepared");
|
||||
state = STATE_PREPARED;
|
||||
if (!preloading) {
|
||||
mediaInterface.start();
|
||||
preloading = false;
|
||||
}
|
||||
onStatePlaying();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCompletion() {
|
||||
super.onCompletion();
|
||||
if (onVideoCompletionListener != null) {
|
||||
onVideoCompletionListener.onVideoComplet();
|
||||
}
|
||||
Log.e("onStateChanged", "onCompletion");
|
||||
}
|
||||
|
||||
public void setOnCompletionListener(onVideoCompletionListener listener) {
|
||||
this.onVideoCompletionListener = listener;
|
||||
}
|
||||
|
||||
public void setScreenOrientationChangeListener(ScreenOrientationChangeListener listener) {
|
||||
this.changeListener = listener;
|
||||
}
|
||||
|
||||
public void setGotoFullScreenListener(GotoFullScreenListener listener) {
|
||||
this.gotoFullScreenListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gotoNormalScreen() {
|
||||
super.gotoNormalScreen();
|
||||
changeListener.onOrientationChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gotoFullscreen() {
|
||||
super.gotoFullscreen();
|
||||
gotoFullScreenListener.onGotoFullScreen();
|
||||
}
|
||||
|
||||
//视频播放完成回调
|
||||
public interface onVideoCompletionListener {
|
||||
void onVideoComplet();
|
||||
}
|
||||
|
||||
//退出全屏回调
|
||||
public interface ScreenOrientationChangeListener {
|
||||
void onOrientationChange();
|
||||
}
|
||||
|
||||
//进入全屏回调
|
||||
public interface GotoFullScreenListener {
|
||||
void onGotoFullScreen();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PaintFlagsDrawFilter;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.RectF;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.uiuipad.os.R;
|
||||
|
||||
import cn.jzvd.JzvdStd;
|
||||
|
||||
public class JzvdStdRound extends JzvdStd {
|
||||
|
||||
private int radius;
|
||||
private int leftTopRadius;
|
||||
private int rightTopRadius;
|
||||
private int rightBottomRadius;
|
||||
private int leftBottomRadius;
|
||||
|
||||
public JzvdStdRound(Context context) {
|
||||
super(context);
|
||||
}
|
||||
public JzvdStdRound(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initAttrs(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.layout_jzstd_notitle;
|
||||
}
|
||||
|
||||
void initAttrs(Context context, AttributeSet attrs) {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.JzvdStdRound);
|
||||
radius = a.getDimensionPixelSize(R.styleable.JzvdStdRound_radius, 0);
|
||||
leftTopRadius = a.getDimensionPixelSize(R.styleable.JzvdStdRound_left_top_radius, 0);
|
||||
rightTopRadius = a.getDimensionPixelSize(R.styleable.JzvdStdRound_right_top_radius, 0);
|
||||
rightBottomRadius = a.getDimensionPixelSize(R.styleable.JzvdStdRound_right_bottom_radius, 0);
|
||||
leftBottomRadius = a.getDimensionPixelSize(R.styleable.JzvdStdRound_left_bottom_radius, 0);
|
||||
}
|
||||
|
||||
|
||||
public void setRadius(int radius){
|
||||
this.radius = radius;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setLeftTopRadius(int leftTopRadius) {
|
||||
this.leftTopRadius = leftTopRadius;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
public void setRightTopRadius(int rightTopRadius) {
|
||||
this.rightTopRadius = rightTopRadius;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
public void setRightBottomRadius(int rightBottomRadius) {
|
||||
this.rightBottomRadius = rightBottomRadius;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setLeftBottomRadius(int leftBottomRadius) {
|
||||
this.leftBottomRadius = leftBottomRadius;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
Path path = new Path();
|
||||
if (radius > 0) {
|
||||
path.addRoundRect(new RectF(0, 0, getMeasuredWidth(), getMeasuredHeight()),
|
||||
radius, radius, Path.Direction.CW);
|
||||
} else {
|
||||
path.addRoundRect(new RectF(0, 0, getMeasuredWidth(), getMeasuredHeight()),
|
||||
new float[]{leftTopRadius, leftTopRadius, rightTopRadius, rightTopRadius,
|
||||
rightBottomRadius, rightBottomRadius, leftBottomRadius, leftBottomRadius},
|
||||
Path.Direction.CW);
|
||||
canvas.setDrawFilter(new PaintFlagsDrawFilter(0,
|
||||
Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
|
||||
}
|
||||
canvas.clipPath(path);
|
||||
super.dispatchDraw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
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.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.uiuipad.os.R;
|
||||
import com.uiuipad.os.uiuiutils.WakeUpUtils;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import cn.jzvd.Jzvd;
|
||||
|
||||
public class NoticeActivity extends AppCompatActivity {
|
||||
private String TAG = NoticeActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.positive)
|
||||
TextView positive;
|
||||
|
||||
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);
|
||||
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);
|
||||
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.setLooping(true);
|
||||
// 开始播放
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
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.uiuipad.os.R;
|
||||
import com.uiuipad.os.network.NetInterfaceManager;
|
||||
import com.uiuipad.os.network.bean.BaseResponse;
|
||||
import com.uiuipad.os.uiuiutils.FileUtil;
|
||||
import com.uiuipad.os.uiuiutils.ScreenUtils;
|
||||
import com.uiuipad.os.uiuiutils.Utils;
|
||||
import com.uiuipad.os.uiuiutils.WakeUpUtils;
|
||||
|
||||
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()
|
||||
.getUpdateAlarmClockObservable(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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,347 @@
|
||||
package com.uiuipad.os.alarm;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
|
||||
import com.facebook.rebound.SimpleSpringListener;
|
||||
import com.facebook.rebound.Spring;
|
||||
import com.facebook.rebound.SpringConfig;
|
||||
import com.facebook.rebound.SpringSystem;
|
||||
import com.facebook.rebound.SpringUtil;
|
||||
import com.uiuipad.os.R;
|
||||
|
||||
public class ToggleButton extends View {
|
||||
private SpringSystem springSystem;
|
||||
private Spring spring;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private float radius;
|
||||
/**
|
||||
* 开启颜色
|
||||
*/
|
||||
private int onColor = Color.parseColor("#3D54D9");
|
||||
/**
|
||||
* 关闭颜色
|
||||
*/
|
||||
private int offBorderColor = Color.parseColor("#e7e4e4");
|
||||
/**
|
||||
* 灰色带颜色
|
||||
*/
|
||||
private int offColor = Color.parseColor("#ffffff");
|
||||
/**
|
||||
* 手柄颜色
|
||||
*/
|
||||
private int spotColor = Color.parseColor("#ffffff");
|
||||
/**
|
||||
* 边框颜色
|
||||
*/
|
||||
private int borderColor = offBorderColor;
|
||||
/**
|
||||
* 画笔
|
||||
*/
|
||||
private Paint paint;
|
||||
/**
|
||||
* 开关状态
|
||||
*/
|
||||
private boolean toggleOn = false;
|
||||
/**
|
||||
* 边框大小
|
||||
*/
|
||||
private int borderWidth = 2;
|
||||
/**
|
||||
* 垂直中心
|
||||
*/
|
||||
private float centerY;
|
||||
/**
|
||||
* 按钮的开始和结束位置
|
||||
*/
|
||||
private float startX, endX;
|
||||
/**
|
||||
* 手柄X位置的最小和最大值
|
||||
*/
|
||||
private float spotMinX, spotMaxX;
|
||||
/**
|
||||
* 手柄大小
|
||||
*/
|
||||
private int spotSize;
|
||||
/**
|
||||
* 手柄X位置
|
||||
*/
|
||||
private float spotX;
|
||||
/**
|
||||
* 关闭时内部灰色带高度
|
||||
*/
|
||||
private float offLineWidth;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private RectF rect = new RectF();
|
||||
/**
|
||||
* 默认使用动画
|
||||
*/
|
||||
private boolean defaultAnimate = true;
|
||||
/**
|
||||
* 是否默认处于打开状态
|
||||
*/
|
||||
private boolean isDefaultOn = false;
|
||||
/**
|
||||
* 禁止点击
|
||||
*/
|
||||
private boolean disable = false;
|
||||
|
||||
private OnToggleChanged listener;
|
||||
|
||||
public void setDisable(boolean dis) {
|
||||
this.disable = dis;
|
||||
}
|
||||
|
||||
private ToggleButton(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ToggleButton(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
setup(attrs);
|
||||
}
|
||||
|
||||
public ToggleButton(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setup(attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
spring.removeListener(springListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
spring.addListener(springListener);
|
||||
}
|
||||
|
||||
public void setup(AttributeSet attrs) {
|
||||
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setStrokeCap(Paint.Cap.ROUND);
|
||||
springSystem = SpringSystem.create();
|
||||
spring = springSystem.createSpring();
|
||||
spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(50, 7));
|
||||
this.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
if (disable) {
|
||||
|
||||
} else {
|
||||
toggle(defaultAnimate);
|
||||
}
|
||||
}
|
||||
});
|
||||
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ToggleButton);
|
||||
offBorderColor = typedArray.getColor(R.styleable.ToggleButton_tbOffBorderColor, offBorderColor);
|
||||
onColor = typedArray.getColor(R.styleable.ToggleButton_tbOnColor, onColor);
|
||||
spotColor = typedArray.getColor(R.styleable.ToggleButton_tbSpotColor, spotColor);
|
||||
offColor = typedArray.getColor(R.styleable.ToggleButton_tbOffColor, offColor);
|
||||
borderWidth = typedArray.getDimensionPixelSize(R.styleable.ToggleButton_tbBorderWidth, borderWidth);
|
||||
defaultAnimate = typedArray.getBoolean(R.styleable.ToggleButton_tbAnimate, defaultAnimate);
|
||||
isDefaultOn = typedArray.getBoolean(R.styleable.ToggleButton_tbAsDefaultOn, isDefaultOn);
|
||||
typedArray.recycle();
|
||||
borderColor = offBorderColor;
|
||||
if (isDefaultOn) {
|
||||
toggleOn();
|
||||
}
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
toggle(true);
|
||||
}
|
||||
|
||||
public void toggle(boolean animate) {
|
||||
toggleOn = !toggleOn;
|
||||
takeEffect(animate);
|
||||
if (listener != null) {
|
||||
listener.onToggle(toggleOn);
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleOn() {
|
||||
setToggleOn();
|
||||
if (listener != null) {
|
||||
listener.onToggle(toggleOn);
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleOff() {
|
||||
setToggleOff();
|
||||
if (listener != null) {
|
||||
listener.onToggle(toggleOn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置显示成打开样式,不会触发toggle事件
|
||||
*/
|
||||
public void setToggleOn() {
|
||||
setToggleOn(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param animate asd
|
||||
*/
|
||||
public void setToggleOn(boolean animate) {
|
||||
toggleOn = true;
|
||||
takeEffect(animate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置显示成关闭样式,不会触发toggle事件
|
||||
*/
|
||||
public void setToggleOff() {
|
||||
setToggleOff(true);
|
||||
}
|
||||
|
||||
public void setToggleOff(boolean animate) {
|
||||
toggleOn = false;
|
||||
takeEffect(animate);
|
||||
}
|
||||
|
||||
public int isToggleOn() {
|
||||
return toggleOn ? 1 : 0;
|
||||
}
|
||||
|
||||
private void takeEffect(boolean animate) {
|
||||
if (animate) {
|
||||
spring.setEndValue(toggleOn ? 1 : 0);
|
||||
} else {
|
||||
//这里没有调用spring,所以spring里的当前值没有变更,这里要设置一下,同步两边的当前值
|
||||
spring.setCurrentValue(toggleOn ? 1 : 0);
|
||||
calculateEffect(toggleOn ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
Resources r = Resources.getSystem();
|
||||
if (widthMode == MeasureSpec.UNSPECIFIED || widthMode == MeasureSpec.AT_MOST) {
|
||||
widthSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, r.getDisplayMetrics());
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
|
||||
}
|
||||
if (heightMode == MeasureSpec.UNSPECIFIED || heightSize == MeasureSpec.AT_MOST) {
|
||||
heightSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, r.getDisplayMetrics());
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right,
|
||||
int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
final int width = getWidth();
|
||||
final int height = getHeight();
|
||||
radius = Math.min(width, height) * 0.5f;
|
||||
centerY = radius;
|
||||
startX = radius;
|
||||
endX = width - radius;
|
||||
spotMinX = startX + borderWidth;
|
||||
spotMaxX = endX - borderWidth;
|
||||
spotSize = height - 4 * borderWidth;
|
||||
spotX = toggleOn ? spotMaxX : spotMinX;
|
||||
offLineWidth = 0;
|
||||
}
|
||||
|
||||
SimpleSpringListener springListener = new SimpleSpringListener() {
|
||||
@Override
|
||||
public void onSpringUpdate(Spring spring) {
|
||||
final double value = spring.getCurrentValue();
|
||||
calculateEffect(value);
|
||||
}
|
||||
};
|
||||
|
||||
private int clamp(int value, int low, int high) {
|
||||
return Math.min(Math.max(value, low), high);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
//
|
||||
super.draw(canvas);
|
||||
rect.set(0, 0, getWidth(), getHeight());
|
||||
paint.setColor(borderColor);
|
||||
canvas.drawRoundRect(rect, radius, radius, paint);
|
||||
if (offLineWidth > 0) {
|
||||
final float cy = offLineWidth * 0.5f;
|
||||
rect.set(spotX - cy, centerY - cy, endX + cy, centerY + cy);
|
||||
// paint.setColor(offColor);
|
||||
canvas.drawRoundRect(rect, cy, cy, paint);
|
||||
}
|
||||
rect.set(spotX - 1 - radius, centerY - radius, spotX + 1.1f + radius, centerY + radius);
|
||||
paint.setColor(borderColor);
|
||||
canvas.drawRoundRect(rect, radius, radius, paint);
|
||||
final float spotR = spotSize * 0.5f;
|
||||
rect.set(spotX - spotR, centerY - spotR, spotX + spotR, centerY + spotR);
|
||||
paint.setColor(spotColor);
|
||||
canvas.drawRoundRect(rect, spotR, spotR, paint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
private void calculateEffect(final double value) {
|
||||
final float mapToggleX = (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, spotMinX, spotMaxX);
|
||||
spotX = mapToggleX;
|
||||
float mapOffLineWidth = (float) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, 10, spotSize);
|
||||
offLineWidth = mapOffLineWidth;
|
||||
final int fb = Color.blue(onColor);
|
||||
final int fr = Color.red(onColor);
|
||||
final int fg = Color.green(onColor);
|
||||
final int tb = Color.blue(offBorderColor);
|
||||
final int tr = Color.red(offBorderColor);
|
||||
final int tg = Color.green(offBorderColor);
|
||||
int sb = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fb, tb);
|
||||
int sr = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fr, tr);
|
||||
int sg = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fg, tg);
|
||||
sb = clamp(sb, 0, 255);
|
||||
sr = clamp(sr, 0, 255);
|
||||
sg = clamp(sg, 0, 255);
|
||||
borderColor = Color.rgb(sr, sg, sb);
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @author ThinkPad
|
||||
*/
|
||||
public interface OnToggleChanged {
|
||||
/**
|
||||
* @param on = =
|
||||
*/
|
||||
public void onToggle(boolean on);
|
||||
}
|
||||
|
||||
public void setOnToggleChanged(OnToggleChanged onToggleChanged) {
|
||||
listener = onToggleChanged;
|
||||
}
|
||||
|
||||
public boolean isAnimate() {
|
||||
return defaultAnimate;
|
||||
}
|
||||
|
||||
public void setAnimate(boolean animate) {
|
||||
this.defaultAnimate = animate;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import android.app.Application;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tencent.bugly.crashreport.CrashReport;
|
||||
import com.uiuipad.os.alarm.AlarmUtils;
|
||||
import com.uiuipad.os.manager.AppUsedTimeUtils;
|
||||
import com.uiuipad.os.manager.ConnectManager;
|
||||
import com.uiuipad.os.manager.RunningAppManager;
|
||||
@@ -37,6 +38,7 @@ public class BaseApplication extends Application {
|
||||
AppUsedTimeUtils.init(this);
|
||||
RunningAppManager.init(this);
|
||||
TimeControlManager.init(this);
|
||||
AlarmUtils.init(this);
|
||||
|
||||
CrashReport.initCrashReport(getApplicationContext(), "55d55ba689", false);
|
||||
CrashReport.setDeviceId(this, Utils.getSerial(this));
|
||||
|
||||
@@ -451,7 +451,11 @@ public class CacheHelper {
|
||||
String cachePath;
|
||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|
||||
|| !Environment.isExternalStorageRemovable()) {
|
||||
cachePath = context.getExternalCacheDir().getPath();
|
||||
if (context.getExternalCacheDir() != null) {
|
||||
cachePath = context.getExternalCacheDir().getPath();
|
||||
} else {
|
||||
cachePath = context.getCacheDir().getPath();
|
||||
}
|
||||
} else {
|
||||
cachePath = context.getCacheDir().getPath();
|
||||
}
|
||||
|
||||
@@ -666,6 +666,11 @@ public class RunningAppManager {
|
||||
this.add("com.sprd.engineermode");
|
||||
this.add("com.teclast.update");
|
||||
this.add("com.incar.update");
|
||||
this.add("com.uiui.sn");
|
||||
this.add("com.uiui.videoplayer");
|
||||
this.add("com.uiui.appstore");
|
||||
this.add("com.uiui.browser");
|
||||
this.add("com.uiui.aios");
|
||||
}};
|
||||
|
||||
/**
|
||||
@@ -675,6 +680,7 @@ public class RunningAppManager {
|
||||
* @return
|
||||
*/
|
||||
public boolean inControlTime(String pkg) {
|
||||
//白名单默认可用
|
||||
if (allowPackage.contains(pkg)) {
|
||||
return false;
|
||||
}
|
||||
@@ -687,6 +693,7 @@ public class RunningAppManager {
|
||||
}
|
||||
boolean havaConfigure = TimeControlManager.getInstance().havaConfigure(pkg);
|
||||
TimeManageSn machineControl = TimeControlManager.getInstance().getGlobalMachineControl();
|
||||
//没有激活或者没有绑定可用
|
||||
if (machineControl == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -694,31 +701,12 @@ public class RunningAppManager {
|
||||
if (havaConfigure) {
|
||||
//有单独设置 不管是分类整机还是其他都是这个设置
|
||||
TimeManageApp appTimeControl = TimeControlManager.getInstance().getAppTimeControl(pkg);
|
||||
// if (appTimeControl.getIs_control() == 0) {
|
||||
// ToastUtil.show("应用已被禁用");
|
||||
// Log.e(TAG, "inControlTime: " + "应用已被禁用");
|
||||
// return true;
|
||||
// }
|
||||
//始终可用应用
|
||||
if (appTimeControl.getUse_type() == 0) {
|
||||
Log.e(TAG, "inControlTime: " + "应用始终可用");
|
||||
return false;
|
||||
}
|
||||
|
||||
Log.e(TAG, "inControlTime: globalRemainingTime = " + globalRemainingTime);
|
||||
if (appTimeControl.getUse_type() != 3) {
|
||||
if (globalRemainingTime <= 0) {
|
||||
// if (machineControl != null) {
|
||||
// if (machineControl.getIs_part() == 0 && machineControl.getIs_quota() == 0) {
|
||||
// Log.e(TAG, "inControlTime: is_part = 0 is_quota = 0");
|
||||
// //整机额度和时间段关闭不管控
|
||||
// return false;
|
||||
// }
|
||||
// } else {
|
||||
ToastUtil.show("今日可使用时间已用完");
|
||||
return true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
//打开时间段管控
|
||||
if (appTimeControl.getTime_part() != null && appTimeControl.getTime_part().size() != 0) {
|
||||
boolean inControlTime = inControlTime(machineControl, appTimeControl);
|
||||
@@ -729,15 +717,10 @@ public class RunningAppManager {
|
||||
Log.e(TAG, "inControlTime: " + "该应用" + partTime2String(appTimeControl));
|
||||
return true;
|
||||
} else {
|
||||
// if (appTimeControl.getIs_quota() == 0) {
|
||||
// //要求设置了管控时间段没有设置使用额度也可以使用
|
||||
// return false;
|
||||
// }
|
||||
if (getAppRemainingTime(pkg) <= 0) {
|
||||
//没有剩余时间
|
||||
ToastUtil.show("该应用今日可使用时间已用完");
|
||||
Log.e(TAG, "inControlTime: " + "该应用今日可使用时间已用完");
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -745,10 +728,6 @@ public class RunningAppManager {
|
||||
}
|
||||
} else {
|
||||
//关闭时间段管控关闭额度开关为不管控
|
||||
// if (appTimeControl.getIs_quota() == 0) {
|
||||
// Log.e(TAG, "inControlTime: " + "没有使用额度");
|
||||
// return false;
|
||||
// }
|
||||
if (getAppRemainingTime(pkg) <= 0) {
|
||||
//没有剩余时间
|
||||
ToastUtil.show("该应用今日可使用时间已用完");
|
||||
@@ -761,33 +740,6 @@ public class RunningAppManager {
|
||||
} else {
|
||||
//没有配置可以直接使用
|
||||
return false;
|
||||
// //根据整机
|
||||
// if (machineControl == null) {
|
||||
// return false;
|
||||
// }
|
||||
// if (globalRemainingTime <= 0) {
|
||||
//// if (machineControl.getIs_part() == 0 && machineControl.getIs_quota() == 0) {
|
||||
//// Log.e(TAG, "inControlTime: is_part = 0 is_quota = 0");
|
||||
//// //整机额度和时间段关闭不管控
|
||||
//// return false;
|
||||
//// }
|
||||
// }
|
||||
//// if (machineControl.is_quota == 1) {
|
||||
// if (isControl == 1) {
|
||||
// if (haveUseTime(machineControl.getWork_time(), machineControl.getRest_time(), machineControl.getToday_time())) {
|
||||
// return false;
|
||||
// } else {
|
||||
// boolean inControlTime = inControlTime(machineControl);
|
||||
// if (inControlTime) {
|
||||
// Log.i(TAG, "inControlTime: " + "应用在管控时间段不能打开" + machineControl.getTime_part().toString());
|
||||
// ToastUtil.show("该应用" + partTime2String(machineControl));
|
||||
// }
|
||||
// return inControlTime;
|
||||
// }
|
||||
// } else {
|
||||
// //关闭整机额度开关 始终可用
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -862,14 +814,6 @@ public class RunningAppManager {
|
||||
} else {
|
||||
remainTime.setTotalTime(appTimeControl.getRest_time());
|
||||
}
|
||||
// if (appTimeControl.getIs_control() == 0) {
|
||||
// remainTime.setDisableType(1);
|
||||
// remainTime.setContent("应用已被禁用");
|
||||
// return remainTime.toString();
|
||||
// }
|
||||
// if (appTimeControl.getUse_type() == 0) {
|
||||
// return "";
|
||||
// }
|
||||
//打开时间段管控
|
||||
if (appTimeControl.getTime_part() != null && appTimeControl.getTime_part().size() != 0) {
|
||||
boolean inControlTime = inControlTime(machineControl, appTimeControl);
|
||||
@@ -879,10 +823,6 @@ public class RunningAppManager {
|
||||
remainTime.setContent("该应用" + partTime2String(appTimeControl));
|
||||
return remainTime.getContent();
|
||||
} else {
|
||||
// if (appTimeControl.getIs_quota() == 0) {
|
||||
// //要求设置了管控时间段没有设置使用额度也可以使用
|
||||
// return "";
|
||||
// }
|
||||
if (getAppRemainingTime(pkg) <= 0) {
|
||||
//没有剩余时间
|
||||
if (inWeekDay()) {
|
||||
@@ -907,9 +847,6 @@ public class RunningAppManager {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if (appTimeControl.getIs_quota() == 0) {
|
||||
// return "";
|
||||
// }
|
||||
if (getAppRemainingTime(pkg) <= 0) {
|
||||
//没有剩余时间
|
||||
if (appTimeControl.getUse_type() == 1) {
|
||||
@@ -924,7 +861,7 @@ public class RunningAppManager {
|
||||
remainTime.setContent("该应用今日可使用时间已用完");
|
||||
return remainTime.getContent();
|
||||
}
|
||||
return "";
|
||||
return "该应用今日可使用时间已用完";
|
||||
}
|
||||
} else {
|
||||
//根据整机
|
||||
@@ -936,7 +873,6 @@ public class RunningAppManager {
|
||||
} else {
|
||||
remainTime.setTotalTime(machineControl.getRest_time());
|
||||
}
|
||||
// if (machineControl.is_quota == 1) {
|
||||
if (haveUseTime(machineControl.getWork_time(), machineControl.getRest_time(), machineControl.getToday_time())) {
|
||||
return "";
|
||||
} else {
|
||||
@@ -949,10 +885,6 @@ public class RunningAppManager {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
// } else {
|
||||
// //关闭整机额度开关 始终可用
|
||||
// return "";
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -314,12 +314,13 @@ public class LoaderTask implements Runnable {
|
||||
ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo> added = new ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo>();
|
||||
synchronized (this) {
|
||||
for (LauncherActivityInfo app : apps) {
|
||||
Log.e("verifyApplications", "AllAPP: " + app.getApplicationInfo().packageName);
|
||||
if (BuildConfig.APPLICATION_ID.equals(app.getApplicationInfo().packageName)
|
||||
|| "com.ygyb.yischool".equals(app.getApplicationInfo().packageName)
|
||||
Log.e("verifyApplications", "AllAPP: pkg = " + app.getApplicationInfo().packageName);
|
||||
Log.e("verifyApplications", "AllAPP: className = " + app.getComponentName().getClassName());
|
||||
if ("com.ygyb.yischool".equals(app.getApplicationInfo().packageName)
|
||||
|| "com.cube.setlauncherdef".equals(app.getApplicationInfo().packageName)
|
||||
|| "com.iflytek.speechcloud".equals(app.getApplicationInfo().packageName)
|
||||
|| "com.oirsdfg89.flg".equals(app.getApplicationInfo().packageName)
|
||||
|| "com.uiuipad.os.Launcher".equals(app.getComponentName().getClassName())
|
||||
)
|
||||
continue;
|
||||
if (is_control == 1) {
|
||||
|
||||
@@ -2,12 +2,22 @@ package com.uiuipad.os.network;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
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.trello.rxlifecycle4.android.FragmentEvent;
|
||||
import com.uiuipad.os.alarm.AlarmClockData;
|
||||
import com.uiuipad.os.alarm.AlarmUtils;
|
||||
import com.uiuipad.os.disklrucache.CacheHelper;
|
||||
import com.uiuipad.os.gson.GsonUtils;
|
||||
import com.uiuipad.os.network.api.TimeManageAppApi;
|
||||
import com.uiuipad.os.network.api.TimeManageSnApi;
|
||||
import com.uiuipad.os.network.api.UploadAppUseLogApi;
|
||||
import com.uiuipad.os.network.api.alarmclock.AlarmClockApi;
|
||||
import com.uiuipad.os.network.api.alarmclock.AlarmClockByIdApi;
|
||||
import com.uiuipad.os.network.api.alarmclock.UpdateAlarmClockApi;
|
||||
import com.uiuipad.os.network.bean.BaseResponse;
|
||||
import com.uiuipad.os.network.bean.TimeManageApp;
|
||||
import com.uiuipad.os.network.bean.TimeManageSn;
|
||||
@@ -18,10 +28,15 @@ import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
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.schedulers.Schedulers;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
@@ -130,4 +145,118 @@ public class NetInterfaceManager {
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse<List<AlarmClockData>>> getAlarmClockObservable() {
|
||||
return mRetrofit.create(AlarmClockApi.class)
|
||||
.getAlarmClock(Utils.getSerial(mContext))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse> getUpdateAlarmClockObservable(int id) {
|
||||
return mRetrofit.create(UpdateAlarmClockApi.class)
|
||||
.updateAlarmClock(Utils.getSerial(mContext),id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse> getAlarmClockByIdObservable(int id) {
|
||||
return mRetrofit.create(AlarmClockByIdApi.class)
|
||||
.alarmClockById(Utils.getSerial(mContext),id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface AlarmClockCallback {
|
||||
void setAlarmClock(List<AlarmClockData> alarmClockList);
|
||||
|
||||
void setAlarmClockEmpty();
|
||||
|
||||
void onError();
|
||||
}
|
||||
|
||||
|
||||
public void getAlarmClock(boolean refresh, BehaviorSubject<ActivityEvent> lifecycle, AlarmClockCallback callback) {
|
||||
getAlarmClock(lifecycle, callback);
|
||||
}
|
||||
|
||||
public void getAlarmClock(BehaviorSubject<ActivityEvent> lifecycle, AlarmClockCallback callback) {
|
||||
getAlarmClockObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(getAlarmClockObserver(callback));
|
||||
}
|
||||
|
||||
public void getAlarmClockFragment(BehaviorSubject<FragmentEvent> lifecycle, AlarmClockCallback callback) {
|
||||
getAlarmClockObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, FragmentEvent.DESTROY))
|
||||
.subscribe(getAlarmClockObserver(callback));
|
||||
}
|
||||
|
||||
public void getAlarmClock(AlarmClockCallback callback) {
|
||||
getAlarmClockObservable()
|
||||
.subscribe(getAlarmClockObserver(callback));
|
||||
}
|
||||
|
||||
public void getAlarmClock() {
|
||||
getAlarmClockObservable()
|
||||
.subscribe(getAlarmClockObserver(null));
|
||||
}
|
||||
|
||||
public Observer<BaseResponse<List<AlarmClockData>>> getAlarmClockObserver(AlarmClockCallback callback) {
|
||||
return new Observer<BaseResponse<List<AlarmClockData>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getAlarmClockObserver", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<AlarmClockData>> listBaseResponse) {
|
||||
Log.e("getAlarmClockObserver", "onNext: ");
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<AlarmClockData> alarmClockData = listBaseResponse.data;
|
||||
if (alarmClockData != null && alarmClockData.size() != 0) {
|
||||
AlarmUtils.getInstance().setAlarmClockData(alarmClockData);
|
||||
mMMKV.encode(UrlAddress.GET_ALARM_CLOCK, GsonUtils.toJSONString(alarmClockData));
|
||||
// if (callback != null) {
|
||||
// callback.setAlarmClock(alarmClockData);
|
||||
// }
|
||||
} else {
|
||||
AlarmUtils.getInstance().deleteAllAlarmClock();
|
||||
AlarmUtils.getInstance().setAlarmClockData(null);
|
||||
mMMKV.encode(UrlAddress.GET_ALARM_CLOCK, "");
|
||||
// if (callback != null) {
|
||||
// callback.setAlarmClockEmpty();
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
AlarmUtils.getInstance().deleteAllAlarmClock();
|
||||
AlarmUtils.getInstance().setAlarmClockData(null);
|
||||
mMMKV.encode(UrlAddress.GET_ALARM_CLOCK, "");
|
||||
// if (callback != null) {
|
||||
// callback.setAlarmClockEmpty();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAlarmClockObserver", "onError: " + e.getMessage());
|
||||
if (callback != null) callback.onError();
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,14 @@ public class UrlAddress {
|
||||
public static final String GET_TIME_MANAGE_SN = "equipment/timeManage/getTimeManageSn";
|
||||
/*获取应用时间管控*/
|
||||
public static final String GET_TIME_MANAGE_APP = "equipment/timeManage/getTimeManageApp";
|
||||
|
||||
/*
|
||||
* 闹钟
|
||||
* */
|
||||
/*获取闹钟*/
|
||||
public static final String GET_ALARM_CLOCK = "equipment/alarmClock/getAlarmClock";
|
||||
/*闹钟完成调用*/
|
||||
public static final String UPDATE_ALARM_CLOCK = "equipment/alarmClock/updateAlarmClock";
|
||||
/*编号查询闹钟*/
|
||||
public static final String ALARM_CLOCK_BY_ID = "equipment/alarmClock/alarmClockById";
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.uiuipad.os.network.api.alarmclock;
|
||||
|
||||
import com.uiuipad.os.alarm.AlarmClockData;
|
||||
import com.uiuipad.os.network.UrlAddress;
|
||||
import com.uiuipad.os.network.bean.BaseResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface AlarmClockApi {
|
||||
@GET(UrlAddress.GET_ALARM_CLOCK)
|
||||
Observable<BaseResponse<List<AlarmClockData>>> getAlarmClock(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.uiuipad.os.network.api.alarmclock;
|
||||
|
||||
import com.uiuipad.os.network.UrlAddress;
|
||||
import com.uiuipad.os.network.bean.BaseResponse;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface AlarmClockByIdApi {
|
||||
@GET(UrlAddress.ALARM_CLOCK_BY_ID)
|
||||
Observable<BaseResponse> alarmClockById(
|
||||
@Query("sn") String sn,
|
||||
@Query("id") int id
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.uiuipad.os.network.api.alarmclock;
|
||||
|
||||
import com.uiuipad.os.network.UrlAddress;
|
||||
import com.uiuipad.os.network.bean.BaseResponse;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface UpdateAlarmClockApi {
|
||||
@FormUrlEncoded
|
||||
@POST(UrlAddress.UPDATE_ALARM_CLOCK)
|
||||
Observable<BaseResponse> updateAlarmClock(
|
||||
@Field("sn") String sn,
|
||||
@Field("id") int id
|
||||
);
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.uiuipad.os.network.bean;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class NewestAppUpdateResult implements Serializable {
|
||||
private static final long serialVersionUID = -934484906663584753L;
|
||||
|
||||
long id ;
|
||||
String url;
|
||||
int version_code;
|
||||
String app_name;
|
||||
@SerializedName("package")
|
||||
String app_package;
|
||||
String app_md5;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getApp_name() {
|
||||
return app_name;
|
||||
}
|
||||
|
||||
public void setApp_name(String app_name) {
|
||||
this.app_name = app_name;
|
||||
}
|
||||
|
||||
public String getApp_package() {
|
||||
return app_package;
|
||||
}
|
||||
|
||||
public void setApp_package(String app_package) {
|
||||
this.app_package = app_package;
|
||||
}
|
||||
|
||||
public int getVersion_code() {
|
||||
return version_code;
|
||||
}
|
||||
|
||||
public void setVersion_code(int version_code) {
|
||||
this.version_code = version_code;
|
||||
}
|
||||
|
||||
public String getApp_md5() {
|
||||
return app_md5;
|
||||
}
|
||||
|
||||
public void setApp_md5(String app_md5) {
|
||||
this.app_md5 = app_md5;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,16 @@ import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.uiuipad.os.network.NetInterfaceManager;
|
||||
import com.uiuipad.os.service.MainService;
|
||||
import com.uiuipad.os.uiuiutils.ToastUtil;
|
||||
|
||||
public class PushManager {
|
||||
private static final String TAG = PushManager.class.getSimpleName();
|
||||
|
||||
public static final String SET_ALARMCLOCK = "zuoyeos.action.change.alarmclaock";
|
||||
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static PushManager sInstance;
|
||||
private Context mContext;
|
||||
@@ -34,11 +38,20 @@ public class PushManager {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
|
||||
/*设置闹钟*/
|
||||
private static final String SET_ALARM = "17";
|
||||
/*时间管控*/
|
||||
private static final String TIME_MANAGEMENT = "28";
|
||||
|
||||
public void setPushContent(String title, String extras) {
|
||||
switch (title) {
|
||||
case SET_ALARM:
|
||||
ToastUtil.betaShow("收到推送消息: 设置闹钟");
|
||||
NetInterfaceManager.getInstance().getAlarmClock();
|
||||
Intent intent = new Intent(SET_ALARMCLOCK);
|
||||
mContext.sendBroadcast(intent);
|
||||
break;
|
||||
case TIME_MANAGEMENT:
|
||||
ToastUtil.betaShow("收到管控:时间管控");
|
||||
mContext.sendBroadcast(new Intent(MainService.REFRESH_ACTION));
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
@@ -15,6 +16,9 @@ import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
|
||||
import com.uiuipad.os.alarm.AlarmClockData;
|
||||
import com.uiuipad.os.alarm.AlarmUtils;
|
||||
import com.uiuipad.os.alarm.NoticeActivity;
|
||||
import com.uiuipad.os.uiuiutils.ApkUtils;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
@@ -22,12 +26,17 @@ import com.arialyy.aria.core.task.DownloadTask;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
public class MainService extends Service implements MainSContact.MainView, LifecycleProvider<ActivityEvent> {
|
||||
private String TAG = MainService.class.getSimpleName();
|
||||
|
||||
public static final String ALARMWAKEUP = "KUXIN_ALARM_WAKEUP";
|
||||
|
||||
|
||||
public MainSPresenter mPresenter;
|
||||
|
||||
@@ -90,6 +99,7 @@ public class MainService extends Service implements MainSContact.MainView, Lifec
|
||||
private void registerReceivers() {
|
||||
registerTimeReceiver();
|
||||
registerRefreshReceiver();
|
||||
registerAlarmReceiver();
|
||||
}
|
||||
|
||||
private void unregisterReceivers() {
|
||||
@@ -99,6 +109,69 @@ public class MainService extends Service implements MainSContact.MainView, Lifec
|
||||
if (mRefreshReceiver != null) {
|
||||
unregisterReceiver(mRefreshReceiver);
|
||||
}
|
||||
if (alarmReceiver != null) {
|
||||
unregisterReceiver(alarmReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void registerAlarmReceiver() {
|
||||
if (alarmReceiver == null) {
|
||||
alarmReceiver = new AlarmReceiver();
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(ALARMWAKEUP);
|
||||
registerReceiver(alarmReceiver, filter);
|
||||
}
|
||||
|
||||
private AlarmReceiver alarmReceiver = new AlarmReceiver();
|
||||
|
||||
private class AlarmReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.e("AlarmReceiver", "onReceive: " + System.currentTimeMillis());
|
||||
String action = intent.getAction();
|
||||
if (TextUtils.isEmpty(action)) return;
|
||||
Log.e("AlarmReceiver", "onReceive: " + action);
|
||||
String title = intent.getStringExtra("title");
|
||||
int code = intent.getIntExtra("id", -1);
|
||||
Log.e("AlarmReceiver", "onReceive: title = " + title);
|
||||
setNextAlarm(code);
|
||||
if (ALARMWAKEUP.equals(action)) {
|
||||
Intent noticeIntent = new Intent();
|
||||
noticeIntent.putExtra("id", code);
|
||||
noticeIntent.setClass(MainService.this, NoticeActivity.class);
|
||||
noticeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(noticeIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setNextAlarm(int code) {
|
||||
HashMap<Integer, AlarmClockData> clockDataHashMap = AlarmUtils.getInstance().getOldDataMap();
|
||||
AlarmClockData alarmClockData = clockDataHashMap.get(code);
|
||||
Log.e(TAG, "setNextAlarm: " + alarmClockData);
|
||||
if (alarmClockData != null) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int day_of_week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
Log.e(TAG, "setNextAlarm: " + day_of_week);
|
||||
switch (alarmClockData.getType()) {
|
||||
case AlarmUtils.ONCE:
|
||||
break;
|
||||
case AlarmUtils.LOOP:
|
||||
AlarmUtils.getInstance().setDayLoopAlarm(MainService.ALARMWAKEUP, alarmClockData.getTitle(), alarmClockData.getId(), alarmClockData.getTime());
|
||||
break;
|
||||
case AlarmUtils.WORKING_DAY:
|
||||
if (day_of_week < 5 || day_of_week == 7) {
|
||||
AlarmUtils.getInstance().setWorkDayAlarm(MainService.ALARMWAKEUP, alarmClockData.getTitle(), alarmClockData.getId(), alarmClockData.getTime());
|
||||
}
|
||||
break;
|
||||
case AlarmUtils.OFF_DAY:
|
||||
AlarmUtils.getInstance().setOffDayAlarm(MainService.ALARMWAKEUP, alarmClockData.getTitle(), alarmClockData.getId(), alarmClockData.getTime());
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TimeChangedReceiver mTimeChangedReceiver;
|
||||
|
||||
@@ -113,8 +113,12 @@ public class ItemClickHandler {
|
||||
// if (is_forbid(v.getContext(), packageName)) {
|
||||
// return;
|
||||
// }
|
||||
Log.e("ItemClickHandler", "onClick: " + packageName);
|
||||
if (RunningAppManager.getInstance().inControlTime(packageName)){
|
||||
ToastUtil.show(RunningAppManager.getInstance().getDisableContent(packageName));
|
||||
String content = RunningAppManager.getInstance().getDisableContent(packageName);
|
||||
if (!TextUtils.isEmpty(content)){
|
||||
ToastUtil.show(content);
|
||||
}
|
||||
return;
|
||||
}
|
||||
//获取本地密码
|
||||
@@ -123,7 +127,6 @@ public class ItemClickHandler {
|
||||
Type type = new TypeToken<List<AppPasswdBean>>() {
|
||||
}.getType();
|
||||
List<AppPasswdBean> appPasswdBeans = new Gson().fromJson(ApplicationLock, type);
|
||||
Log.e("ItemClickHandler", "onClick: " + packageName);
|
||||
if (appPasswdBeans == null) {
|
||||
onClickAppShortcut(v, (WorkspaceItemInfo) tag, launcher, sourceContainer);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.uiuipad.os.uiuiutils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.ObservableEmitter;
|
||||
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import wseemann.media.FFmpegMediaMetadataRetriever;
|
||||
|
||||
public class FFmpegUtils {
|
||||
/**
|
||||
* 获取在线音频时间长度
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static void getDurationInMilliseconds(String url, Observer<Integer> observer) {
|
||||
Observable.create(new ObservableOnSubscribe<Integer>() {
|
||||
@Override
|
||||
public void subscribe(@NonNull ObservableEmitter<Integer> emitter) throws Throwable {
|
||||
long time = System.currentTimeMillis();
|
||||
FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
|
||||
mmr.setDataSource(url);
|
||||
int duration = Integer.parseInt(mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION));
|
||||
Log.e("AudioUtils", "getDurationInMilliseconds: " + (System.currentTimeMillis() - time));
|
||||
mmr.release();//释放资源
|
||||
emitter.onNext(duration / 1000);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(observer);
|
||||
}
|
||||
|
||||
public static void loadVideoScreenshot(String url, Observer<Bitmap> observer) {
|
||||
Observable.create(new ObservableOnSubscribe<Bitmap>() {
|
||||
@Override
|
||||
public void subscribe(@NonNull ObservableEmitter<Bitmap> emitter) throws Throwable {
|
||||
FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
|
||||
mmr.setDataSource(url);
|
||||
mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ALBUM);
|
||||
mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ARTIST);
|
||||
Bitmap b = mmr.getFrameAtTime(2000000, FFmpegMediaMetadataRetriever.OPTION_CLOSEST); // frame at 2 seconds
|
||||
byte[] artwork = mmr.getEmbeddedPicture();
|
||||
mmr.release();
|
||||
emitter.onNext(b);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(observer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.uiuipad.os.uiuiutils;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class FileUtil {
|
||||
public static String getFileType(String url) {
|
||||
if (url.indexOf("/") == -1) {
|
||||
return url.substring(url.indexOf("."), url.length());
|
||||
} else {
|
||||
String fileName = url.substring(url.lastIndexOf("/"));
|
||||
return fileName.substring(fileName.indexOf("."), fileName.length());
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
this.add(".nkv");
|
||||
this.add(".flv");
|
||||
}};
|
||||
private static HashSet<String> pictureFormat = new HashSet<String>() {{
|
||||
this.add(".png");
|
||||
this.add(".jpg");
|
||||
this.add(".jpeg");
|
||||
this.add(".bmp");
|
||||
}};
|
||||
|
||||
public static boolean isVideoFile(String fileName) {
|
||||
if (TextUtils.isEmpty(fileName)) {
|
||||
return false;
|
||||
} else {
|
||||
if (!fileName.startsWith(".")) {
|
||||
return videoFormat.contains(getFileType(fileName));
|
||||
} else {
|
||||
return videoFormat.contains(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPictureFile(String fileName) {
|
||||
if (TextUtils.isEmpty(fileName)) {
|
||||
return false;
|
||||
} else {
|
||||
if (!fileName.startsWith(".")) {
|
||||
return pictureFormat.contains(getFileType(fileName));
|
||||
} else {
|
||||
return pictureFormat.contains(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static File uriToFile(Uri uri, Context context) {
|
||||
String path = null;
|
||||
if ("file".equals(uri.getScheme())) {
|
||||
path = uri.getEncodedPath();
|
||||
if (path != null) {
|
||||
path = Uri.decode(path);
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
StringBuffer buff = new StringBuffer();
|
||||
buff.append("(").append(MediaStore.Images.ImageColumns.DATA).append("=").append("'" + path + "'").append(")");
|
||||
Cursor cur = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA}, buff.toString(), null, null);
|
||||
int index = 0;
|
||||
int dataIdx = 0;
|
||||
for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
||||
index = cur.getColumnIndex(MediaStore.Images.ImageColumns._ID);
|
||||
index = cur.getInt(index);
|
||||
dataIdx = cur.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
|
||||
path = cur.getString(dataIdx);
|
||||
}
|
||||
cur.close();
|
||||
if (index == 0) {
|
||||
} else {
|
||||
Uri u = Uri.parse("content://media/external/images/media/" + index);
|
||||
System.out.println("temp uri is :" + u);
|
||||
}
|
||||
}
|
||||
if (path != null) {
|
||||
return new File(path);
|
||||
}
|
||||
} else if ("content".equals(uri.getScheme())) {
|
||||
// 4.2.2以后
|
||||
String[] proj = {MediaStore.Images.Media.DATA};
|
||||
Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
||||
path = cursor.getString(columnIndex);
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
return new File(path);
|
||||
} else {
|
||||
//Log.i(TAG, "Uri Scheme:" + uri.getScheme());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.uiuipad.os.uiuiutils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
public class ScreenUtils {
|
||||
/**
|
||||
* 根据手机的分辨率从 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);
|
||||
}
|
||||
|
||||
public static int dp2px(Resources resources, float dp) {
|
||||
final float scale = resources.getDisplayMetrics().density;
|
||||
return (int) (dp * scale + 0.5f);
|
||||
}
|
||||
|
||||
public static int sp2px(Resources resources, float sp) {
|
||||
final float scale = resources.getDisplayMetrics().scaledDensity;
|
||||
return (int) (sp * scale);
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,18 @@ import android.content.pm.UserInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.RemoteException;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.uiuipad.os.BuildConfig;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -334,4 +338,34 @@ public class Utils {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static File getDiskCacheDir(Context context, String uniqueName) {
|
||||
String cachePath;
|
||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|
||||
|| !Environment.isExternalStorageRemovable()) {
|
||||
if (context.getExternalCacheDir() != null) {
|
||||
cachePath = context.getExternalCacheDir().getPath();
|
||||
} else {
|
||||
cachePath = context.getCacheDir().getPath();
|
||||
}
|
||||
} else {
|
||||
cachePath = context.getCacheDir().getPath();
|
||||
}
|
||||
return new File(cachePath + File.separator + uniqueName);
|
||||
}
|
||||
|
||||
public static String getDownLoadPath(Context context) {
|
||||
String path = ContextCompat.getExternalFilesDirs(context, Environment.DIRECTORY_DOWNLOADS)[0].getAbsolutePath();
|
||||
return path + File.separator;
|
||||
}
|
||||
|
||||
public static boolean isLocalPath(String path) {
|
||||
return path.startsWith(File.separator);
|
||||
}
|
||||
|
||||
public static String getFileNamefromURL(String url) {
|
||||
int position = url.lastIndexOf("/");
|
||||
return url.substring(position + 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.uiuipad.os.uiuiutils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
public class WakeUpUtils {
|
||||
|
||||
/**
|
||||
* 唤醒手机屏幕并解锁
|
||||
*/
|
||||
public static void wakeUpAndUnlock(Activity activity) {
|
||||
// 获取电源管理器对象
|
||||
PowerManager pm = (PowerManager) activity.getApplicationContext()
|
||||
.getSystemService(Context.POWER_SERVICE);
|
||||
boolean screenOn = pm.isScreenOn();
|
||||
Log.d("WakeScreen0", "screenOn: " + screenOn);
|
||||
if (!screenOn) {
|
||||
// 获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
|
||||
@SuppressLint("InvalidWakeLockTag") PowerManager.WakeLock wl = pm.newWakeLock(
|
||||
PowerManager.ACQUIRE_CAUSES_WAKEUP |
|
||||
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
|
||||
wl.acquire(10000); // 点亮屏幕
|
||||
wl.release(); // 释放
|
||||
}
|
||||
// 屏幕解锁
|
||||
KeyguardManager keyguardManager = (KeyguardManager) activity.getApplicationContext()
|
||||
.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("unLock");
|
||||
// 屏幕锁定
|
||||
// keyguardLock.reenableKeyguard();
|
||||
keyguardLock.disableKeyguard(); // 解锁
|
||||
unLockScreen(activity);
|
||||
}
|
||||
|
||||
private static void unLockScreen(Activity activity) {
|
||||
final Window win = activity.getWindow();
|
||||
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
||||
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
|
||||
|
||||
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
|
||||
}
|
||||
|
||||
/**
|
||||
* 唤醒手机屏幕并解锁
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
public static void wakeUpAndUnlockScreen(Activity activity) {
|
||||
|
||||
Window win = activity.getWindow();
|
||||
win.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
|
||||
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
||||
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
||||
|
||||
PowerManager pm = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
|
||||
@SuppressLint("InvalidWakeLockTag")
|
||||
PowerManager.WakeLock wakelock = pm.newWakeLock(
|
||||
PowerManager.FULL_WAKE_LOCK
|
||||
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "xx");
|
||||
wakelock.acquire();
|
||||
wakelock.release();
|
||||
|
||||
KeyguardManager keyguardManager = (KeyguardManager) activity.getApplicationContext()
|
||||
.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
|
||||
if (activity == null) return;
|
||||
keyguardManager.requestDismissKeyguard(activity, new KeyguardManager.KeyguardDismissCallback() {
|
||||
@Override
|
||||
public void onDismissError() {
|
||||
super.onDismissError();
|
||||
Log.d("xxx-->", "1 onDismissError");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissSucceeded() {
|
||||
super.onDismissSucceeded();
|
||||
Log.d("xxx-->", "1 onDismissSucceeded");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissCancelled() {
|
||||
super.onDismissCancelled();
|
||||
Log.d("xxx-->", "1 onDismissCancelled");
|
||||
}
|
||||
});
|
||||
|
||||
if (activity == null) return;
|
||||
keyguardManager.requestDismissKeyguard(activity, new KeyguardManager.KeyguardDismissCallback() {
|
||||
@Override
|
||||
public void onDismissError() {
|
||||
super.onDismissError();
|
||||
Log.d("xxx-->", "2 onDismissError");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissSucceeded() {
|
||||
super.onDismissSucceeded();
|
||||
Log.d("xxx-->", "2 onDismissSucceeded");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissCancelled() {
|
||||
super.onDismissCancelled();
|
||||
Log.d("xxx-->", "2 onDismissCancelled");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user