<category android:name="android.intent.category.MONKEY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
+ </activity>
+ <activity
+ android:name=".NotificationActivity"
+ android:launchMode="singleTop">
+
+
+
</activity>
</application>
--- /dev/null
+package com.ic.launcher;
+
+import android.os.Bundle;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+
+import com.ic.launcher.presenter.NotificationPresenter;
+
+public class NotificationActivity extends AppCompatActivity {
+
+ private NotificationPresenter notificationPresenter;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_notification);
+ notificationPresenter = NotificationPresenter.getsInstance(this);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ if (notificationPresenter != null) {
+ notificationPresenter.onClean();
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ //更新数据
+ notificationPresenter.updateData();
+ }
+}
--- /dev/null
+package com.ic.launcher.data;
+
+public class NotificationItem {
+ private int id;
+ private String title;
+ private long date;
+ private String category;
+ private String type;
+ private int order;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public long getDate() {
+ return date;
+ }
+
+ public void setDate(long date) {
+ this.date = date;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public int getOrder() {
+ return order;
+ }
+
+ public void setOrder(int order) {
+ this.order = order;
+ }
+
+ @Override
+ public String toString() {
+ return "NotificationItem{" +
+ "id=" + id +
+ ", title='" + title + '\'' +
+ ", date=" + date +
+ ", category='" + category + '\'' +
+ ", type='" + type + '\'' +
+ ", order=" + order +
+ '}';
+ }
+}
public class BasePresenter {
- protected void onClean() {
+ public void onClean() {
}
}
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
-import android.os.Handler;
-import android.os.HandlerThread;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import static com.ic.launcher.utils.Constants.NOTIFICATIONS;
+
public class MainPagePresenter extends BasePresenter {
public static final String PATH = "settings";
public MutableLiveData<String> envTempValue = new MutableLiveData<>();
private final Context mContext;
- private final Handler handler;
private MainPagePresenter(Context context) {
this.mContext = context;
//监听数据变化
executor = Executors.newSingleThreadExecutor();
-
- HandlerThread handlerThread = new HandlerThread("ic:launcher.main.page");
- //开启任务执行
- handlerThread.start();
- handler = new Handler(handlerThread.getLooper());
- //handler.post(updateTimeTask);
- //监听网路广播
- registerTimeDateReceiver();
- updateTime(null);
- observerContent(context);
- updateTemperature();
- updateOxygen();
- updateEnvTemp();
- updateHeartRate();
+ executor.execute(() -> {
+ //监听网路广播
+ registerTimeDateReceiver();
+ updateTime(null);
+ updateTemperature();
+ updateOxygen();
+ updateEnvTemp();
+ updateHeartRate();
+ observerContent(context);
+ });
}
private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
}
@Override
- protected void onClean() {
+ public void onClean() {
super.onClean();
mContext.unregisterReceiver(mIntentReceiver);
}
updateEnvTemp();
}
});
+ //监听警告地方
+ context.getContentResolver().registerContentObserver(Uri.parse(NOTIFICATIONS),
+ true, new ContentObserver(null) {
+ @Override
+ public void onChange(boolean selfChange) {
+ //打开通知列表
+
+ }
+ });
}
private void getValueByKey(String key) {
--- /dev/null
+package com.ic.launcher.presenter;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+
+import androidx.lifecycle.MutableLiveData;
+
+import com.ic.iclooger.ICLogger;
+import com.ic.launcher.data.NotificationItem;
+import com.ic.launcher.utils.Constants;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class NotificationPresenter extends BasePresenter {
+ private final Context mContext;
+ private final ExecutorService executorService;
+ private final ContentResolver contentResolver;
+
+ private NotificationPresenter(Context context) {
+ this.mContext = context;
+ executorService = Executors.newSingleThreadExecutor();
+ contentResolver = mContext.getContentResolver();
+ }
+
+ private static NotificationPresenter sInstance = null;
+
+ public static NotificationPresenter getsInstance(Context context) {
+ if (sInstance == null) {
+ sInstance = new NotificationPresenter(context);
+ }
+ return sInstance;
+ }
+
+ @Override
+ public void onClean() {
+ super.onClean();
+ sInstance = null;
+ executorService.shutdown();
+ }
+
+ //关心的数据
+ public MutableLiveData<List<NotificationItem>> notificationListValue = new MutableLiveData<>();
+
+ /**
+ * 更新通知列表
+ */
+ public void updateData() {
+ executorService.execute(() -> {
+ //获取通知列表
+ Cursor query = contentResolver.query(Uri.parse(Constants.NOTIFICATIONS),
+ null, null, null, null);
+ if (query != null) {
+ List<NotificationItem> notificationItems = new ArrayList<>();
+ while (query.moveToNext()) {
+ //创建Item
+ NotificationItem notificationItem = new NotificationItem();
+ //读取数据
+ int id = query.getInt(0);
+ notificationItem.setId(id);
+ String title = query.getString(1);
+ notificationItem.setTitle(title);
+ String type = query.getString(2);
+ notificationItem.setType(type);
+ String category = query.getString(3);
+ notificationItem.setCategory(category);
+ int order = query.getInt(4);
+ notificationItem.setOrder(order);
+ long date = query.getLong(5);
+ notificationItem.setDate(date);
+ ICLogger.d("notificationItem == > " + notificationItem.toString());
+ //设置数据
+ notificationItems.add(notificationItem);
+ }
+ notificationListValue.postValue(notificationItems);
+ query.close();
+ }
+ });
+ }
+}
public static final String AUTHORITY_ALARM = "com.ic.provider.alarm";
public static final String ALARMS = "content://" + AUTHORITY_ALARM + "/" + PATH_ALARM;
+
+ public static final String PATH_NOTIFICATION = "notification";
+ public static final String AUTHORITY_NOTIFICATION = "com.ic.notification";
+ public static final String NOTIFICATIONS = "content://" + AUTHORITY_NOTIFICATION + "/" + PATH_NOTIFICATION;
+
}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout
+ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file