version:1.1
fix: update:迁移到UIUISOS
This commit is contained in:
100
app/src/main/java/com/uiuios/aios/activity/APPListActivity.java
Normal file
100
app/src/main/java/com/uiuios/aios/activity/APPListActivity.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.APPListAdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.AppListInfo;
|
||||
import com.uiuios.aios.service.NotificationService;
|
||||
import com.uiuios.aios.utils.ApkUtils;
|
||||
import com.uiuios.aios.utils.BitmapUtils;
|
||||
import com.uiuios.aios.view.RecyclerViewSpacesItemDecoration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class APPListActivity extends BaseActivity {
|
||||
private ImageView back;
|
||||
private RecyclerView mRecyclerView;
|
||||
private APPListAdapter adapter;
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_applist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
back = findViewById(R.id.iv_back);
|
||||
back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
mRecyclerView = findViewById(R.id.recyclerview);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
List<ApplicationInfo> applicationInfoList = ApkUtils.getSystemApp(APPListActivity.this);
|
||||
PackageManager pm = getPackageManager();
|
||||
if (null != applicationInfoList) {
|
||||
List<AppListInfo> appinfoList = new ArrayList<>();
|
||||
for (ApplicationInfo applicationInfo : applicationInfoList) {
|
||||
AppListInfo info = new AppListInfo(
|
||||
applicationInfo.loadLabel(pm).toString(),
|
||||
applicationInfo.packageName,
|
||||
BitmapUtils.getIconBitmap(APPListActivity.this, applicationInfo.loadIcon(pm))
|
||||
);
|
||||
appinfoList.add(info);
|
||||
}
|
||||
HashMap<String, Integer> stringIntegerHashMap = new HashMap<>();
|
||||
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getRealMetrics(dm);
|
||||
float density = dm.density; // 屏幕密度(0.75 / 1.0 / 1.5)
|
||||
int orientation = 0;
|
||||
orientation = getResources().getConfiguration().orientation;
|
||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.TOP_DECORATION, (int) (density * 16));//top间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.BOTTOM_DECORATION, (int) (density * 32));//top间距
|
||||
} else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.TOP_DECORATION, (int) (density * 50));//top间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.BOTTOM_DECORATION, (int) (density * 100));//top间距
|
||||
}
|
||||
// stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.TOP_DECORATION, (int) (density * 40));//top间距
|
||||
// stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.BOTTOM_DECORATION, (int) (density * 20));//底部间距
|
||||
// stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.LEFT_DECORATION, (int) (density * 20));//左间距
|
||||
// stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.RIGHT_DECORATION, (int) (density * 20));//右间距
|
||||
adapter = new APPListAdapter(APPListActivity.this);
|
||||
mRecyclerView.setLayoutManager(new GridLayoutManager(APPListActivity.this, 3));
|
||||
// rv_list.addItemDecoration(new RecyclerItemDecoration(10, 10, 4));
|
||||
mRecyclerView.addItemDecoration(new RecyclerViewSpacesItemDecoration(stringIntegerHashMap));
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
adapter.setAppListInfos(appinfoList);
|
||||
NotificationService.setListener(new NotificationService.NotificationListener() {
|
||||
@Override
|
||||
public void onListenerUpdate() {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
import com.uiuios.aios.disklrucache.CacheHelper;
|
||||
import com.uiuios.aios.manager.AmapManager;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.network.URLAddress;
|
||||
import com.uiuios.aios.receiver.BootReceiver;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
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;
|
||||
|
||||
public class EmergencyActivity extends AppCompatActivity {
|
||||
@BindView(R.id.tv_countdown)
|
||||
TextView tv_countdown;
|
||||
@BindView(R.id.iv_finish)
|
||||
ImageView iv_finish;
|
||||
private Disposable subscribe;
|
||||
private String TAG = EmergencyActivity.class.getSimpleName();
|
||||
private boolean needDial = false;
|
||||
private boolean isCalling = false;
|
||||
private List<Contact> phoneListSet;
|
||||
private CacheHelper mCacheHelper;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Log.e(TAG, "onCreate: ");
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_emergency);
|
||||
mCacheHelper = new CacheHelper(this);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
//发送紧急广播
|
||||
Intent bootIntent = new Intent(BootReceiver.SOS);
|
||||
bootIntent.setComponent(new ComponentName("com.uiuios.sn", "com.uiuios.sn.receiver.BootReceiver"));
|
||||
sendBroadcast(bootIntent);
|
||||
|
||||
Intent intent = getIntent();
|
||||
// String contactList = intent.getStringExtra("contactList");
|
||||
// if (TextUtils.isEmpty(contactList)) {
|
||||
// finish();
|
||||
// return;
|
||||
// }
|
||||
|
||||
String jsonString = mCacheHelper.getAsString(URLAddress.GET_MAIL_LIST);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
return;
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<Contact>>() {
|
||||
}.getType();
|
||||
List<Contact> contactList = gson.fromJson(jsonString, type);
|
||||
if (contactList == null || contactList.size() == 0) {
|
||||
return;
|
||||
}
|
||||
phoneListSet = contactList.stream().filter(contact -> contact.getIs_urgent() == 1).collect(Collectors.toList());
|
||||
Log.e(TAG, "onCreate: " + phoneListSet);
|
||||
|
||||
final Long time = 3L;
|
||||
subscribe = Observable.interval(1, TimeUnit.SECONDS)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(aLong -> {
|
||||
Log.e("TAG", "倒计时:" + aLong);
|
||||
if (aLong < time && !subscribe.isDisposed()) {
|
||||
tv_countdown.setText("倒计时(" + (time - aLong - 1) + ")秒");
|
||||
Log.e(TAG, "accept: " + (time - aLong - 1));
|
||||
} else {
|
||||
MMKV mmkv = MMKV.defaultMMKV();
|
||||
String longitude = mmkv.decodeString(AmapManager.LONGITUDE_KEY, "未知");
|
||||
String latitude = mmkv.decodeString(AmapManager.LATITUDE_KEY, "未知");
|
||||
String address = mmkv.decodeString(AmapManager.ADDRESS_KEY, "未知");
|
||||
NetInterfaceManager.getInstance()
|
||||
.getSOSRecordObservable(longitude, latitude, address)
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("SOSRecordApi", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("SOSRecordApi", "onNext: " + baseResponse);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("SOSRecordApi", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("SOSRecordApi", "onComplete: ");
|
||||
}
|
||||
});
|
||||
needDial = true;
|
||||
Intent intent1 = new Intent(Intent.ACTION_CALL);
|
||||
Uri data = Uri.parse("tel:" + phoneListSet.get(0).getMobile());
|
||||
intent1.setData(data);
|
||||
startActivity(intent1);
|
||||
isCalling = true;
|
||||
phoneListSet.remove(0);
|
||||
// finish();
|
||||
subscribe.dispose();
|
||||
}
|
||||
});
|
||||
iv_finish.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
// TelephonyManager telM = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
|
||||
// telM.listen(new PhoneStateListener() {
|
||||
// /**
|
||||
// * 当有精确通话状态时回调
|
||||
// * Callback invoked when precise device call state changes
|
||||
// * @hide 隐藏api, 给系统app使用的
|
||||
// */
|
||||
// public void onPreciseCallStateChanged(PreciseCallState callState) {
|
||||
// //当有精确通话状态时回调
|
||||
// Log.e(TAG, "onPreciseCallStateChanged: " + callState);
|
||||
// }
|
||||
// }, PhoneStateListener.LISTEN_PRECISE_CALL_STATE); //需要权限android.permission.READ_PRECISE_PHONE_STATE
|
||||
//
|
||||
// StatusBarManager mStatusBarManager = (StatusBarManager) getApplicationContext().getSystemService(Context.STATUS_BAR_SERVICE);
|
||||
//// mStatusBarManager.disable(StatusBarManager.DISABLE_HOME);//隐藏home键
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
Log.e(TAG, "onResume: ");
|
||||
Log.e(TAG, "onResume: " + phoneListSet);
|
||||
if (needDial) {
|
||||
if (phoneListSet == null || phoneListSet.size() == 0) return;
|
||||
Handler.getMain().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent intent1 = new Intent(Intent.ACTION_CALL);
|
||||
String phone = phoneListSet.get(0).getMobile();
|
||||
Uri data = Uri.parse("tel:" + phone);
|
||||
intent1.setData(data);
|
||||
startActivity(intent1);
|
||||
isCalling = true;
|
||||
phoneListSet.remove(0);
|
||||
}
|
||||
}, 2000);
|
||||
} else {
|
||||
if (phoneListSet == null) {
|
||||
ToastUtil.show("没有设置紧急联系人");
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.e(TAG, "onDestroy: ");
|
||||
if (subscribe != null) {
|
||||
subscribe.dispose();
|
||||
subscribe = null;
|
||||
}
|
||||
}
|
||||
|
||||
// class MobileCallReceiver extends BroadcastReceiver {
|
||||
// @Override
|
||||
// public void onReceive(Context context, Intent intent) {
|
||||
// if (intent.getAction() == null) {
|
||||
// return;
|
||||
// }
|
||||
//// switch (intent.getAction()) {
|
||||
//// case CustomAction.PRECISE_CALL_STATE:
|
||||
//// int callState = intent.getIntExtra("foreground_state", -2);
|
||||
//// switch (callState) {
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_IDLE:
|
||||
//// Log.d(TAG, "IDLE");
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_DIALING:
|
||||
//// Log.d(TAG, "DIALING");
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_ALERTING:
|
||||
//// Log.d(TAG, "ALERTING isHandFree=" + isHandFree);
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_ACTIVE:
|
||||
//// Log.d(TAG, "ACTIVE");
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_INCOMING:
|
||||
//// Log.d(TAG, "INCOMING来电");
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_DISCONNECTING:
|
||||
//// Log.d(TAG, "DISCONNECTING");
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_DISCONNECTED:
|
||||
//// Log.d(TAG, "DISCONNECTED");
|
||||
//// break;
|
||||
//// }
|
||||
//// break;
|
||||
//// case TelephonyManager.ACTION_PHONE_STATE_CHANGED:
|
||||
//// break;
|
||||
//// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 精确的九大通话状态
|
||||
// public class PreciseCallState {
|
||||
// public static final int PRECISE_CALL_STATE_IDLE = 0; //通话空闲
|
||||
// public static final int PRECISE_CALL_STATE_ACTIVE = 1; //正在通话(活动中)
|
||||
// public static final int PRECISE_CALL_STATE_HOLDING = 2; //通话挂起(例如我和多个人通话,其中一个通话在活动,而其它通话就会进入挂起状态)
|
||||
// public static final int PRECISE_CALL_STATE_DIALING = 3; //拨号开始
|
||||
// public static final int PRECISE_CALL_STATE_ALERTING = 4; //正在呼出(提醒对方接电话)
|
||||
// public static final int PRECISE_CALL_STATE_INCOMING = 5; //对方来电
|
||||
// public static final int PRECISE_CALL_STATE_WAITING = 6; //第三方来电等待(例如我正在和某人通话,而其他人打入时就会就进入等待状态)
|
||||
// public static final int PRECISE_CALL_STATE_DISCONNECTED = 7; //挂断完成
|
||||
// public static final int PRECISE_CALL_STATE_DISCONNECTING = 8; //正在挂断
|
||||
// }
|
||||
}
|
||||
237
app/src/main/java/com/uiuios/aios/activity/NoticeActivity.java
Normal file
237
app/src/main/java/com/uiuios/aios/activity/NoticeActivity.java
Normal file
@@ -0,0 +1,237 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.os.Vibrator;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.blankj.utilcode.util.FileUtils;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.FileUtil;
|
||||
import com.uiuios.aios.utils.ScreenUtils;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
import com.uiuios.aios.utils.WakeUpUtils;
|
||||
import com.uiuios.aios.view.JzvdStdAssert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import cn.jzvd.JZDataSource;
|
||||
import cn.jzvd.Jzvd;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
public class NoticeActivity extends AppCompatActivity {
|
||||
private String TAG = NoticeActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.tv_title)
|
||||
TextView tv_title;
|
||||
@BindView(R.id.bt_ok)
|
||||
Button bt_ok;
|
||||
@BindView(R.id.cl_voice)
|
||||
ConstraintLayout cl_voice;
|
||||
@BindView(R.id.cl_vp)
|
||||
ConstraintLayout cl_vp;
|
||||
@BindView(R.id.jz_video)
|
||||
JzvdStdAssert jz_video;
|
||||
@BindView(R.id.imageView)
|
||||
ImageView imageView;
|
||||
|
||||
private AlarmClockData alarmClockData;
|
||||
private int code;
|
||||
private MediaPlayer mediaPlayer;
|
||||
private PowerManager pm;
|
||||
private PowerManager.WakeLock wakeLock;
|
||||
private AudioManager audioManager;
|
||||
|
||||
private Vibrator vibrator;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_notice);
|
||||
ButterKnife.bind(this);
|
||||
Intent intent = getIntent();
|
||||
code = intent.getIntExtra("id", -1);
|
||||
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
wakeLock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "WakeAndLock");
|
||||
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (code == -1) {
|
||||
finish();
|
||||
} else {
|
||||
wakeLock.acquire(60 * 1000L);
|
||||
long[] pattern = {1000, 5000, 1000, 5000};
|
||||
vibrator.vibrate(pattern, 0);
|
||||
WakeUpUtils.wakeUpAndUnlockScreen(this);
|
||||
HashMap<Integer, AlarmClockData> oldData = AlarmUtils.getInstance().getOldData();
|
||||
alarmClockData = oldData.get(code);
|
||||
if (alarmClockData == null) {
|
||||
finish();
|
||||
}
|
||||
Log.e(TAG, "onCreate: " + alarmClockData);
|
||||
showData(alarmClockData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void showData(AlarmClockData alarmClockData) {
|
||||
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, AudioManager.FLAG_PLAY_SOUND);
|
||||
tv_title.setText(alarmClockData.getTitle());
|
||||
bt_ok.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
HashMap<Integer, AlarmClockData> oldData = AlarmUtils.getInstance().getOldData();
|
||||
AlarmClockData alarm = oldData.get(code);
|
||||
if (alarm != null) {
|
||||
alarm.setFinished(true);
|
||||
AlarmUtils.getInstance().updateAlarmFinished(alarm);
|
||||
}
|
||||
NetInterfaceManager.getInstance()
|
||||
.getUpdateAlarmObservable(alarmClockData.getId())
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("showData", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("showData", "onNext: " + baseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("showData", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("showData", "onComplete: ");
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
String voiceUrl = alarmClockData.getVoice();
|
||||
String voicemd5 = alarmClockData.getVoice_md5();
|
||||
String filePath = alarmClockData.getFile();
|
||||
|
||||
if (!TextUtils.isEmpty(voiceUrl)) {
|
||||
cl_voice.setVisibility(View.VISIBLE);
|
||||
String fileName = Utils.getFileNamefromURL(voiceUrl);
|
||||
File file = new File(Utils.getDownLoadPath(NoticeActivity.this) + fileName);
|
||||
String fileMD5 = FileUtils.getFileMD5ToString(file);
|
||||
// if (!md5.equals(fileMD5)) {
|
||||
// // TODO: 2021/12/16
|
||||
// } else {
|
||||
mediaPlayer = new MediaPlayer();
|
||||
try {
|
||||
// 切歌之前先重置,释放掉之前的资源
|
||||
mediaPlayer.reset();
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
mediaPlayer.setDataSource(fis.getFD());
|
||||
// 设置播放源
|
||||
// mediaPlayer.setDataSource(file.getAbsolutePath());
|
||||
// 开始播放前的准备工作,加载多媒体资源,获取相关信息
|
||||
mediaPlayer.prepare();
|
||||
// 开始播放
|
||||
mediaPlayer.start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "showData: " + e.getMessage());
|
||||
}
|
||||
// }
|
||||
} else {
|
||||
cl_voice.setVisibility(View.GONE);
|
||||
}
|
||||
if (!TextUtils.isEmpty(filePath)) {
|
||||
cl_vp.setVisibility(View.VISIBLE);
|
||||
String fileType = FileUtil.getFileType(filePath);
|
||||
Log.e(TAG, "showData: " + fileType);
|
||||
if (FileUtil.isPictureFile(fileType)) {
|
||||
jz_video.setVisibility(View.GONE);
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
RequestOptions options = new RequestOptions().transform(new RoundedCorners(ScreenUtils.dip2px(this, 16F)));
|
||||
Glide.with(NoticeActivity.this).load(filePath).apply(options).into(imageView);
|
||||
} else if (FileUtil.isVideoFile(fileType)) {
|
||||
jz_video.setVisibility(View.VISIBLE);
|
||||
imageView.setVisibility(View.GONE);
|
||||
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.length());
|
||||
String realPath = Utils.getDownLoadPath(NoticeActivity.this) + fileName;
|
||||
File file = new File(realPath);
|
||||
JZDataSource jzDataSource;
|
||||
if (!file.exists()) {
|
||||
jzDataSource = new JZDataSource(filePath, "");
|
||||
Log.e(TAG, "showData: not exists");
|
||||
} else {
|
||||
Log.e(TAG, "showData: exists " + file);
|
||||
URI uri = file.toURI();
|
||||
jzDataSource = new JZDataSource(uri.toString(), "");
|
||||
}
|
||||
jzDataSource.looping = true;
|
||||
jz_video.setUp(jzDataSource, Jzvd.SCREEN_NORMAL);
|
||||
jz_video.startPreloading();
|
||||
jz_video.startVideoAfterPreloading();
|
||||
jz_video.startVideo();
|
||||
}
|
||||
} else {
|
||||
cl_vp.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mediaPlayer != null) {
|
||||
if (mediaPlayer.isPlaying()) {
|
||||
mediaPlayer.stop();
|
||||
}
|
||||
mediaPlayer.release();
|
||||
mediaPlayer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (Jzvd.backPress()) {
|
||||
return;
|
||||
}
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
Jzvd.releaseAllVideos();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.AlarmAdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.tpush.MessageReceiver;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import cn.jzvd.Jzvd;
|
||||
|
||||
public class AlarmClockActivity extends BaseActivity implements AlarmClockContact.ClockView {
|
||||
private static final String TAG = AlarmClockActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
|
||||
|
||||
private AlarmClockPresenter mPresenter;
|
||||
private AlarmAdapter mAlarmAdapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_alarm_clock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mPresenter = new AlarmClockPresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
|
||||
mAlarmAdapter = new AlarmAdapter();
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(AlarmClockActivity.this));
|
||||
recyclerView.setAdapter(mAlarmAdapter);
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
registerAlarmClockReceiver();
|
||||
mPresenter.getAlarmClock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showAlarmClock(List<AlarmClockData> alarmClockData) {
|
||||
mAlarmAdapter.setAlarmClockData(alarmClockData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmClockEmpty() {
|
||||
mAlarmAdapter.setAlarmClockData(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
ToastUtil.show("服务器连接失败,检查网络连接");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
Jzvd.releaseAllVideos();
|
||||
if (mAlarmClockReceiver != null) {
|
||||
unregisterReceiver(mAlarmClockReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerAlarmClockReceiver() {
|
||||
if (null == mAlarmClockReceiver) {
|
||||
mAlarmClockReceiver = new AlarmClockReceiver();
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(MessageReceiver.SET_ALARMCLOCK);
|
||||
registerReceiver(mAlarmClockReceiver, filter);
|
||||
}
|
||||
|
||||
private AlarmClockReceiver mAlarmClockReceiver;
|
||||
|
||||
private class AlarmClockReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Log.e(TAG, "onReceive: " + action);
|
||||
if (MessageReceiver.SET_ALARMCLOCK.equals(action)) {
|
||||
mPresenter.getAlarmClock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AlarmClockContact {
|
||||
public interface Presenter extends BasePresenter<ClockView> {
|
||||
void getAlarmClock();
|
||||
}
|
||||
|
||||
public interface ClockView extends BaseView {
|
||||
void showAlarmClock(List<AlarmClockData> alarmClockData);
|
||||
void setAlarmClockEmpty();
|
||||
void onError();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.bean.AlarmClockData;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
public class AlarmClockPresenter implements AlarmClockContact.Presenter {
|
||||
|
||||
private AlarmClockContact.ClockView mView;
|
||||
private Context mContext;
|
||||
|
||||
AlarmClockPresenter(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 AlarmClockContact.ClockView 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) {
|
||||
mView.showAlarmClock(alarmClockList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmClockEmpty() {
|
||||
mView.setAlarmClockEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
mView.onError();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.uiuios.aios.activity.code;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.HealthCodeAdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.HealthCode;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.view.ScaleCircleNavigator;
|
||||
|
||||
import net.lucode.hackware.magicindicator.MagicIndicator;
|
||||
import net.lucode.hackware.magicindicator.ViewPagerHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class HealthCodeActivity extends BaseActivity implements HealthCodeContact.CodeView {
|
||||
@BindView(R.id.viewPager)
|
||||
ViewPager mViewPager;
|
||||
@BindView(R.id.magicIndicator)
|
||||
MagicIndicator mMagicIndicator;
|
||||
@BindView(R.id.iv_nodata)
|
||||
ImageView iv_nodata;
|
||||
|
||||
private HealthCodePresenter mPresenter;
|
||||
private HealthCodeAdapter mHealthCodeAdapter;
|
||||
private ScaleCircleNavigator scaleCircleNavigator;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mPresenter = new HealthCodePresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
mHealthCodeAdapter = new HealthCodeAdapter();
|
||||
mViewPager.setAdapter(mHealthCodeAdapter);
|
||||
scaleCircleNavigator = new ScaleCircleNavigator(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
mPresenter.getHealthCode();
|
||||
}
|
||||
|
||||
private void setImageViews(List<HealthCode> healthCodes) {
|
||||
mMagicIndicator.setNavigator(scaleCircleNavigator);
|
||||
scaleCircleNavigator.setCircleCount(healthCodes.size());
|
||||
scaleCircleNavigator.setNormalCircleColor(Color.DKGRAY);
|
||||
scaleCircleNavigator.setSelectedCircleColor(Color.LTGRAY);
|
||||
scaleCircleNavigator.setCircleClickListener(new ScaleCircleNavigator.OnCircleClickListener() {
|
||||
@Override
|
||||
public void onClick(int index) {
|
||||
|
||||
}
|
||||
});
|
||||
ViewPagerHelper.bind(mMagicIndicator, mViewPager);
|
||||
List<ImageView> imageViews = new ArrayList<>();
|
||||
for (HealthCode healthCode : healthCodes) {
|
||||
ImageView image = new ImageView(this);
|
||||
image.setAdjustViewBounds(true);
|
||||
image.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
Glide.with(this).load(healthCode.getImg()).into(image);
|
||||
imageViews.add(image);
|
||||
}
|
||||
mHealthCodeAdapter.setImageViews(imageViews);
|
||||
mHealthCodeAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHealthCode(List<HealthCode> codeList) {
|
||||
setImageViews(codeList);
|
||||
mViewPager.setVisibility(View.VISIBLE);
|
||||
mMagicIndicator.setVisibility(View.VISIBLE);
|
||||
iv_nodata.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHealthCodeNodata() {
|
||||
mViewPager.setVisibility(View.GONE);
|
||||
mMagicIndicator.setVisibility(View.GONE);
|
||||
iv_nodata.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
ToastUtil.show("连接服务器失败,请检查网络连接");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.uiuios.aios.activity.code;
|
||||
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
import com.uiuios.aios.bean.HealthCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HealthCodeContact {
|
||||
public interface Presenter extends BasePresenter<CodeView> {
|
||||
void getHealthCode();
|
||||
}
|
||||
|
||||
public interface CodeView extends BaseView {
|
||||
void setHealthCode(List<HealthCode> codeList);
|
||||
void setHealthCodeNodata();
|
||||
void onError();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.uiuios.aios.activity.code;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.bean.HealthCode;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
public class HealthCodePresenter implements HealthCodeContact.Presenter {
|
||||
private static final String TAG = HealthCodePresenter.class.getSimpleName();
|
||||
private HealthCodeContact.CodeView mView;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
HealthCodePresenter(Context context) {
|
||||
this.mContext = context;
|
||||
Log.e(TAG, "MainPresenter: " + context.getClass());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void attachView(@NonNull HealthCodeContact.CodeView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getHealthCode() {
|
||||
NetInterfaceManager.getInstance().getHealthCode(true, getLifecycle(), new NetInterfaceManager.HealthCodeCallback() {
|
||||
@Override
|
||||
public void setHealthCode(List<HealthCode> healthCode) {
|
||||
mView.setHealthCode(healthCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noData() {
|
||||
mView.setHealthCodeNodata();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
mView.onError();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.uiuios.aios.activity.contact;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.ContactAdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class ContactActivity extends BaseActivity implements ContactContact.ContactView {
|
||||
@BindView(R.id.rv_contact)
|
||||
RecyclerView rv_contact;
|
||||
@BindView(R.id.tv_people)
|
||||
TextView tv_people;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
|
||||
@OnClick({R.id.iv_back})
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.iv_back:
|
||||
finish();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
private ContactPresenter mContactPresenter;
|
||||
private ContactAdapter mContactAdapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_contact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mContactPresenter = new ContactPresenter(this);
|
||||
mContactPresenter.attachView(this);
|
||||
mContactPresenter.setLifecycle(lifecycleSubject);
|
||||
mContactAdapter = new ContactAdapter();
|
||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
rv_contact.setLayoutManager(new GridLayoutManager(this, 3));
|
||||
} else {
|
||||
rv_contact.setLayoutManager(new GridLayoutManager(this, 2));
|
||||
}
|
||||
rv_contact.setAdapter(mContactAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
mContactPresenter.getContact();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mContactPresenter.detachView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContact(List<Contact> contactList) {
|
||||
if (contactList != null) {
|
||||
mContactAdapter.setContactList(contactList);
|
||||
tv_people.setText(contactList.size() + "人");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.uiuios.aios.activity.contact;
|
||||
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ContactContact {
|
||||
public interface Presenter extends BasePresenter<ContactView> {
|
||||
void getContact();
|
||||
}
|
||||
|
||||
public interface ContactView extends BaseView {
|
||||
void setContact(List<Contact> contactList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.uiuios.aios.activity.contact;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
|
||||
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 ContactPresenter implements ContactContact.Presenter {
|
||||
private Context mContext;
|
||||
private ContactContact.ContactView mView;
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
ContactPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(@NonNull ContactContact.ContactView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getContact() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getContactListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<Contact>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getContactList", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<Contact>> listBaseResponse) {
|
||||
Log.e("getContactList", "onNext: " + listBaseResponse);
|
||||
mView.setContact(listBaseResponse.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getContactList", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getContactList", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
package com.uiuios.aios.activity.main;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.alarmclock.uiui.IAlarmAidlInterface;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.uiuios.aios.BuildConfig;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.AlarmItem;
|
||||
import com.uiuios.aios.bean.DesktopIcon;
|
||||
import com.uiuios.aios.fragment.AppListFragment;
|
||||
import com.uiuios.aios.fragment.BaseFragmentPagerAdapter;
|
||||
import com.uiuios.aios.fragment.CustomFragment;
|
||||
import com.uiuios.aios.fragment.SecondFragment;
|
||||
import com.uiuios.aios.service.NotificationService;
|
||||
import com.uiuios.aios.utils.ApkUtils;
|
||||
import com.uiuios.aios.utils.AppUsedTimeUtils;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.view.ScaleCircleNavigator;
|
||||
|
||||
import net.lucode.hackware.magicindicator.MagicIndicator;
|
||||
import net.lucode.hackware.magicindicator.ViewPagerHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
private static String TAG = MainActivity.class.getSimpleName();
|
||||
private MainPresenter mMainPresenter;
|
||||
|
||||
@BindView(R.id.viewPager)
|
||||
ViewPager mViewPager;
|
||||
@BindView(R.id.magicIndicator)
|
||||
MagicIndicator mMagicIndicator;
|
||||
|
||||
private FragmentManager mFragmentManager;
|
||||
private FragmentTransaction mFragmentTransaction;
|
||||
private ScaleCircleNavigator scaleCircleNavigator;
|
||||
private BaseFragmentPagerAdapter mBaseFragmentPagerAdapter;
|
||||
private List<Fragment> mFragments;
|
||||
private CustomFragment mCustomFragment;
|
||||
private SecondFragment mSecondFragment;
|
||||
private boolean is_twoscreen = false;
|
||||
private int appListIndex = 1;
|
||||
private int defaultCurrent = 0;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
toggleNotificationListenerService(this);
|
||||
mMainPresenter = new MainPresenter(this);
|
||||
mMainPresenter.attachView(this);
|
||||
mMainPresenter.setLifecycle(lifecycleSubject);
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
// SystemClock.setCurrentTimeMillis(1662123600000L);//09-02
|
||||
// SystemClock.setCurrentTimeMillis(1662210000000L);//09-03
|
||||
}
|
||||
|
||||
mFragmentManager = getSupportFragmentManager();
|
||||
mFragmentTransaction = mFragmentManager.beginTransaction();
|
||||
mFragments = new ArrayList<>();
|
||||
mBaseFragmentPagerAdapter = new BaseFragmentPagerAdapter(mFragmentManager, mFragments);
|
||||
// fragmentTransaction.add(R.id.viewPager, appListFragment);
|
||||
// fragmentTransaction.commit();
|
||||
|
||||
is_twoscreen = Settings.Global.getInt(getContentResolver(), "is_twoscreen", 1) == 1;
|
||||
if (is_twoscreen) {
|
||||
appListIndex = 2;
|
||||
defaultCurrent = 1;
|
||||
mSecondFragment = new SecondFragment();
|
||||
mFragments.add(mSecondFragment);
|
||||
}
|
||||
mCustomFragment = new CustomFragment();
|
||||
mFragments.add(mCustomFragment);
|
||||
|
||||
mMainPresenter.getSystemSettings();
|
||||
|
||||
ArrayList<DesktopIcon> desktopIcons = ApkUtils.queryFilterAppInfo(this);
|
||||
int x = 0;
|
||||
for (int i = 0; i <= desktopIcons.size(); i++) {
|
||||
if (i != 0 && i % APP_LIST_SIZE == 0) {
|
||||
AppListFragment appListFragment = new AppListFragment();
|
||||
appListFragment.setAppList(new ArrayList<>(desktopIcons.subList(x, i)));
|
||||
mFragments.add(appListFragment);
|
||||
x = i;
|
||||
} else if (i == desktopIcons.size()) {
|
||||
AppListFragment appListFragment = new AppListFragment();
|
||||
mFragments.add(appListFragment);
|
||||
appListFragment.setAppList(new ArrayList<>(desktopIcons.subList(x, i)));
|
||||
}
|
||||
}
|
||||
|
||||
scaleCircleNavigator = new ScaleCircleNavigator(this);
|
||||
scaleCircleNavigator.setCircleCount(mFragments.size());
|
||||
scaleCircleNavigator.setNormalCircleColor(Color.DKGRAY);
|
||||
scaleCircleNavigator.setSelectedCircleColor(Color.LTGRAY);
|
||||
scaleCircleNavigator.setCircleClickListener(new ScaleCircleNavigator.OnCircleClickListener() {
|
||||
@Override
|
||||
public void onClick(int index) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
mViewPager.setAdapter(mBaseFragmentPagerAdapter);
|
||||
mViewPager.setOffscreenPageLimit(2);
|
||||
mMagicIndicator.setNavigator(scaleCircleNavigator);
|
||||
ViewPagerHelper.bind(mMagicIndicator, mViewPager);
|
||||
if (mFragments.size() > 1) {
|
||||
mViewPager.setCurrentItem(defaultCurrent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
registmNewAppReceiver();
|
||||
registerSOSNumberReceiver();
|
||||
mAlarmServiceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
Log.e(TAG, "onServiceConnected: ");
|
||||
mIAlarmAidlInterface = IAlarmAidlInterface.Stub.asInterface(service);
|
||||
getAlarmData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
Log.e(TAG, "onServiceDisconnected: ");
|
||||
mIAlarmAidlInterface = null;
|
||||
}
|
||||
};
|
||||
bindAlarmService();
|
||||
}
|
||||
|
||||
private ServiceConnection mAlarmServiceConnection;
|
||||
private IAlarmAidlInterface mIAlarmAidlInterface;
|
||||
|
||||
private void bindAlarmService() {
|
||||
if (mIAlarmAidlInterface == null) {
|
||||
//这是连接aidl服务的代码
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("com.alarmclock.uiui.IAlarmAidlInterface");
|
||||
intent.setPackage("com.alarmclock.uiui");
|
||||
intent.setComponent(new ComponentName("com.alarmclock.uiui", "com.alarmclock.uiui.AIDLAlarmService"));
|
||||
bindService(intent, mAlarmServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void toggleNotificationListenerService(Context context) {
|
||||
Log.e(TAG, "toggleNotificationListenerService");
|
||||
PackageManager pm = context.getPackageManager();
|
||||
pm.setComponentEnabledSetting(new ComponentName(context, NotificationService.class),
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||
|
||||
pm.setComponentEnabledSetting(new ComponentName(context, NotificationService.class),
|
||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
private void getAlarmData() {
|
||||
if (mIAlarmAidlInterface == null) {
|
||||
bindAlarmService();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String json = mIAlarmAidlInterface.getAlarm();
|
||||
Log.e(TAG, "onServiceConnected: " + json);
|
||||
if ("暂无闹钟".equalsIgnoreCase(json) || TextUtils.isEmpty(json)) {
|
||||
mCustomFragment.setAlarmItem(null);
|
||||
return;
|
||||
}
|
||||
Type type = new TypeToken<List<AlarmItem>>() {
|
||||
}.getType();
|
||||
List<AlarmItem> alarmItem = new Gson().fromJson(json, type);
|
||||
mCustomFragment.setAlarmItem(alarmItem);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private final static int APP_LIST_SIZE = 3 * 4;
|
||||
|
||||
private void addData() {
|
||||
Log.e(TAG, "addData: ");
|
||||
List<Fragment> fragmentList = new ArrayList<>();
|
||||
ArrayList<DesktopIcon> applicationInfoList = ApkUtils.queryFilterAppInfo(this);
|
||||
int x = 0;
|
||||
for (int i = 0; i <= applicationInfoList.size(); i++) {
|
||||
if (i != 0 && i % APP_LIST_SIZE == 0) {
|
||||
AppListFragment appListFragment = new AppListFragment();
|
||||
appListFragment.setAppList(new ArrayList<>(applicationInfoList.subList(x, i)));
|
||||
fragmentList.add(appListFragment);
|
||||
x = i;
|
||||
} else if (i == applicationInfoList.size()) {
|
||||
AppListFragment appListFragment = new AppListFragment();
|
||||
fragmentList.add(appListFragment);
|
||||
appListFragment.setAppList(new ArrayList<>(applicationInfoList.subList(x, i)));
|
||||
}
|
||||
}
|
||||
//从第三个开始改
|
||||
for (int i = 0; i < fragmentList.size(); i++) {
|
||||
if (i + appListIndex < mFragments.size()) {
|
||||
mBaseFragmentPagerAdapter.replaceFragment(i + appListIndex, fragmentList.get(i));
|
||||
// mFragments.remove(i + 2);
|
||||
// mFragments.add(i + 2, fragmentList.get(i));
|
||||
} else {
|
||||
// mFragments.add(fragmentList.get(i));
|
||||
// mBaseFragmentPagerAdapter.getFragments();
|
||||
mBaseFragmentPagerAdapter.addFragment(fragmentList.get(i));
|
||||
}
|
||||
}
|
||||
for (int i = mFragments.size(); i > fragmentList.size() + appListIndex; i--) {
|
||||
mFragments.remove(i - 1);
|
||||
}
|
||||
scaleCircleNavigator.setCircleCount(mFragments.size());
|
||||
scaleCircleNavigator.notifyDataSetChanged();
|
||||
mBaseFragmentPagerAdapter.notifyItemChanged();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
return false;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
Log.e(TAG, "onNewIntent: " + intent.getAction());
|
||||
String action = intent.getAction();
|
||||
if (TextUtils.isEmpty(action)) {
|
||||
return;
|
||||
}
|
||||
switch (action) {
|
||||
default:
|
||||
break;
|
||||
case Intent.ACTION_MAIN:
|
||||
mViewPager.setCurrentItem(defaultCurrent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
AppUsedTimeUtils.getInstance().setAppPackageName(BuildConfig.APPLICATION_ID);
|
||||
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
|
||||
getAlarmData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
Log.e(TAG, "onResume: ");
|
||||
if (!isNotificationListenersEnabled()) {
|
||||
ToastUtil.show("请授予\"" + getString(R.string.app_name) + "\"使用通知权");
|
||||
gotoNotificationAccessSetting(this);
|
||||
}
|
||||
addData();
|
||||
mMainPresenter.sendRunningInfo();
|
||||
mMainPresenter.getAdminSnSetting();
|
||||
}
|
||||
|
||||
private static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners";
|
||||
|
||||
private boolean isNotificationListenersEnabled() {
|
||||
String pkgName = getPackageName();
|
||||
final String flat = Settings.Secure.getString(getContentResolver(), ENABLED_NOTIFICATION_LISTENERS);
|
||||
if (!TextUtils.isEmpty(flat)) {
|
||||
final String[] names = flat.split(":");
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
final ComponentName cn = ComponentName.unflattenFromString(names[i]);
|
||||
if (cn != null) {
|
||||
if (TextUtils.equals(pkgName, cn.getPackageName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean gotoNotificationAccessSetting(Context context) {
|
||||
try {
|
||||
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
|
||||
} catch (ActivityNotFoundException e) {//普通情况下找不到的时候需要再特殊处理找一次
|
||||
try {
|
||||
Intent intent = new Intent();
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.Settings$NotificationAccessSettingsActivity");
|
||||
intent.setComponent(cn);
|
||||
intent.putExtra(":settings:show_fragment", "NotificationAccessSettings");
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
ToastUtil.show("对不起,您的手机暂不支持");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
super.onRestart();
|
||||
mMainPresenter.sendAPPUsage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
AppUsedTimeUtils.getInstance().setEndTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mMainPresenter.detachView();
|
||||
if (mNewAppReceiver != null) {
|
||||
unregisterReceiver(mNewAppReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
private void registmNewAppReceiver() {
|
||||
mNewAppReceiver = new NewAppReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
||||
filter.addDataScheme("package");
|
||||
registerReceiver(mNewAppReceiver, filter);
|
||||
}
|
||||
|
||||
private NewAppReceiver mNewAppReceiver;
|
||||
|
||||
class NewAppReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Log.e(TAG, "onReceive: " + action);
|
||||
if (Intent.ACTION_PACKAGE_ADDED.equals(action)
|
||||
|| Intent.ACTION_PACKAGE_REMOVED.equals(action)
|
||||
|| Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
|
||||
addData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SOSNumberReceiver sosNumberReceiver;
|
||||
|
||||
private void registerSOSNumberReceiver() {
|
||||
if (sosNumberReceiver == null) {
|
||||
sosNumberReceiver = new SOSNumberReceiver();
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction("setting_sos");
|
||||
registerReceiver(sosNumberReceiver, filter);
|
||||
}
|
||||
|
||||
class SOSNumberReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.e(TAG, "onReceive: " + intent.getAction());
|
||||
String setting_sos = intent.getStringExtra("setting_sos");
|
||||
if (TextUtils.isEmpty(setting_sos)) return;
|
||||
mCustomFragment.setSosNumber();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemSettings() {
|
||||
mMainPresenter.getDesktopLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDesktopLayoutFinish() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDesktopLayoutFinish() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendAPPUsageFinish() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRunningInfoFinish() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdminSnSetting() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.uiuios.aios.activity.main;
|
||||
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
|
||||
public class MainContact {
|
||||
public interface Presenter extends BasePresenter<MainView> {
|
||||
/*获取系统设置*/
|
||||
void getSystemSettings();
|
||||
/*获取桌面布局*/
|
||||
void getDesktopLayout();
|
||||
/*更新桌面布局*/
|
||||
void updateDesktopLayout();
|
||||
/*上传正在运行的APP*/
|
||||
void sendAPPUsage();
|
||||
/*上传后台运行的APP*/
|
||||
void sendRunningInfo();
|
||||
/*获取负二屏开关*/
|
||||
void getAdminSnSetting();
|
||||
}
|
||||
|
||||
public interface MainView extends BaseView {
|
||||
void setSystemSettings();
|
||||
void getDesktopLayoutFinish();
|
||||
void updateDesktopLayoutFinish();
|
||||
void sendAPPUsageFinish();
|
||||
void sendRunningInfoFinish();
|
||||
void setAdminSnSetting();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
package com.uiuios.aios.activity.main;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.BuildConfig;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
import com.uiuios.aios.bean.NetDesktopIcon;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.ApkUtils;
|
||||
import com.uiuios.aios.utils.AppUsedTimeUtils;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
|
||||
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 MainPresenter implements MainContact.Presenter {
|
||||
private static final String TAG = MainPresenter.class.getSimpleName();
|
||||
private MainContact.MainView mView;
|
||||
private Context mContext;
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
MainPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
Log.e(TAG, "MainPresenter: " + context.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(MainContact.MainView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSystemSettings() {
|
||||
NetInterfaceManager.getInstance().getSystemSettings(true, getLifecycle(), new NetInterfaceManager.ContactCallback() {
|
||||
@Override
|
||||
public void setContact(List<Contact> contactList) {
|
||||
Intent intent = new Intent("setting_sos");
|
||||
mContext.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEmergencyContact(List<Contact> emergencyContact) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEmpty() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
mView.setSystemSettings();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDesktopLayout() {
|
||||
NetInterfaceManager.getInstance().getDesktopLayoutObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<NetDesktopIcon>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getDesktopLayout", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<NetDesktopIcon>> listBaseResponse) {
|
||||
Log.e("getDesktopLayout", "onNext: " + listBaseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getDesktopLayout", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getDesktopLayout", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDesktopLayout() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendAPPUsage() {
|
||||
AppUsedTimeUtils.getInstance().setEndTime(System.currentTimeMillis());
|
||||
String packagename = AppUsedTimeUtils.getInstance().getAppPackageName();
|
||||
Log.e(TAG, "onRestart packagename == " + packagename);
|
||||
if (!TextUtils.isEmpty(packagename)) {
|
||||
Log.e(TAG, "onRestart: " + ApkUtils.getAppNameByPackage(mContext, packagename));
|
||||
Log.e(TAG, "onRestart: " + packagename);
|
||||
NetInterfaceManager.getInstance().getAppUsageRecordControl()
|
||||
.sendappUsageRecord(Utils.getSerial(),
|
||||
ApkUtils.getAppNameByPackage(mContext, packagename),
|
||||
packagename,
|
||||
AppUsedTimeUtils.getInstance().getStartTime() / 1000,
|
||||
AppUsedTimeUtils.getInstance().getEndTime() / 1000)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("sendAPPUsage", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("sendAPPUsage", "onNext: " + baseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("sendAPPUsage", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("sendAPPUsage", "onComplete: ");
|
||||
mView.sendAPPUsageFinish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Log.e("onRestart", "app = null" + packagename);
|
||||
mView.sendAPPUsageFinish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRunningInfo() {
|
||||
AppUsedTimeUtils.getInstance().setAppPackageName(BuildConfig.APPLICATION_ID);
|
||||
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
|
||||
long time = AppUsedTimeUtils.getInstance().getStartTime();
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("app_package", BuildConfig.APPLICATION_ID);
|
||||
jsonObject.addProperty("version_name", ApkUtils.getAPPVersionName(mContext, BuildConfig.APPLICATION_ID));
|
||||
jsonObject.addProperty("start_time", time / 1000);
|
||||
String jsonString = jsonObject.toString();
|
||||
Log.e(TAG, "sendRunningInfo: " + jsonString);
|
||||
NetInterfaceManager.getInstance()
|
||||
.getRunningAppObservable(jsonString)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("sendRunningInfo", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("sendRunningInfo", "onNext: " + baseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("sendRunningInfo", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("sendRunningInfo", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAdminSnSetting() {
|
||||
NetInterfaceManager.getInstance().getAdminSnSetting(true, lifecycle, new NetInterfaceManager.onCompleteCallback() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.uiuios.aios.activity.weather;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.qweather.sdk.bean.weather.WeatherDailyBean;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.WeatherDayApdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.view.HorizontalItemDecoration;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class WeatherActivity extends BaseActivity implements WeatherContact.WeatherView {
|
||||
@BindView(R.id.rv_weather)
|
||||
RecyclerView rv_weather;
|
||||
@BindView(R.id.tv_location)
|
||||
TextView tv_location;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
|
||||
private WeatherPresenter mPresenter;
|
||||
private WeatherDayApdapter mWeatherDayApdapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_weather;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mPresenter = new WeatherPresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
Resources resources = getResources();
|
||||
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
||||
rv_weather.addItemDecoration(new HorizontalItemDecoration(30, this));//10表示10dp
|
||||
} else {
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
}
|
||||
rv_weather.setLayoutManager(linearLayoutManager);
|
||||
// rv_weather.setLayoutManager(new GridLayoutManager(this, 3));
|
||||
// rv_weather.addItemDecoration(new RecyclerItemDecoration(ScreenUtils.dp2px(resources, 10), ScreenUtils.dp2px(resources, 10), 3));
|
||||
mWeatherDayApdapter = new WeatherDayApdapter();
|
||||
rv_weather.setAdapter(mWeatherDayApdapter);
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
mPresenter.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocation(String location) {
|
||||
tv_location.setText(location);
|
||||
mPresenter.getWeatherCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeatherCache(WeatherDailyBean weatherCache) {
|
||||
if (weatherCache != null) {
|
||||
mWeatherDayApdapter.setDailyBeans(weatherCache.getDaily());
|
||||
}
|
||||
mPresenter.getWeather();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeather(WeatherDailyBean weather) {
|
||||
if (weather != null) {
|
||||
mWeatherDayApdapter.setDailyBeans(weather.getDaily());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mPresenter.detachView();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.uiuios.aios.activity.weather;
|
||||
|
||||
import com.qweather.sdk.bean.weather.WeatherDailyBean;
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
|
||||
public class WeatherContact {
|
||||
public interface Presenter extends BasePresenter<WeatherView> {
|
||||
//获取定位缓存
|
||||
void getLocation();
|
||||
//获取天气缓存
|
||||
void getWeatherCache();
|
||||
//获取天气
|
||||
void getWeather();
|
||||
}
|
||||
|
||||
public interface WeatherView extends BaseView {
|
||||
//设置定位缓存
|
||||
void setLocation(String location);
|
||||
//设置天气缓存
|
||||
void setWeatherCache(WeatherDailyBean weatherCache);
|
||||
//设置天气
|
||||
void setWeather(WeatherDailyBean weather);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.uiuios.aios.activity.weather;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.qweather.sdk.bean.weather.WeatherDailyBean;
|
||||
import com.qweather.sdk.view.QWeather;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.manager.AmapManager;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
/**
|
||||
* MainActivity和MainService 的 Presenter
|
||||
*
|
||||
* @author jgy02
|
||||
*/
|
||||
public class WeatherPresenter implements WeatherContact.Presenter {
|
||||
private static final String TAG = WeatherPresenter.class.getSimpleName();
|
||||
private static final String WEATHER_DAILY_KEY = "WEATHER_DAILY_JSON_STRING";
|
||||
private WeatherContact.WeatherView mView;
|
||||
private Context mContext;
|
||||
private MMKV mMMKV = MMKV.defaultMMKV();
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
public void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
public WeatherPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
Log.e(TAG, "WeatherPresenter: " + context.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(@NonNull WeatherContact.WeatherView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getLocation() {
|
||||
AMapLocation aMapLocation = AmapManager.getInstance().getNowAMapLocation();
|
||||
String location = "未知";
|
||||
if (aMapLocation != null) {
|
||||
location = aMapLocation.getCity() + "\t" + aMapLocation.getDistrict();
|
||||
}
|
||||
mView.setLocation(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getWeatherCache() {
|
||||
// TODO: 2022/1/21 读取json,反序列化,排序
|
||||
String jsonString = mMMKV.decodeString(WEATHER_DAILY_KEY, "");
|
||||
Type type = new TypeToken<WeatherDailyBean>() {
|
||||
}.getType();
|
||||
WeatherDailyBean weatherDailyBean = new Gson().fromJson(jsonString, type);
|
||||
mView.setWeatherCache(weatherDailyBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getWeather() {
|
||||
QWeather.getWeather7D(mContext, AmapManager.getInstance().getLocation(), new QWeather.OnResultWeatherDailyListener() {
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
Log.e("getWeather", "onError: " + throwable.getMessage());
|
||||
if (mView != null) {
|
||||
mView.setWeather(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WeatherDailyBean weatherDailyBean) {
|
||||
String jsonString = new Gson().toJson(weatherDailyBean);
|
||||
Log.d("getWeather", "onSuccess: " + jsonString);
|
||||
mMMKV.encode(WEATHER_DAILY_KEY, jsonString);
|
||||
if (mView != null) {
|
||||
mView.setWeather(weatherDailyBean);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user