package com.ic.launcher;
+import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
String format = simpleDateFormat.format(date);
timeTv.setText(format);
itemView.setTag(category);
+ String type = notificationItem.getType();
+ itemView.setOnClickListener(item -> {
+ handleItemClick(category, notificationItem);
+ });
//处理头像
- int iconRes = getIconRes(notificationItem.getType());
+ int iconRes = getIconRes(type);
leftIconIv.setImageResource(iconRes);
if (integer == null) {
itemCategoryCount.put(category, 1);
}
}
+ private void handleItemClick(String category, NotificationItem notificationItem) {
+ //判断类型
+ //删除该类型的所有通知
+ Intent intent = new Intent();
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ switch (category) {
+ case CATEGORY_SMS:
+ //跳转到短信详情界面
+ intent.setAction("com.ic.sms.action.DETAIL");
+ intent.putExtra("detailNum", notificationItem.getTitle());
+ break;
+ case CATEGORY_TEMPERATURE:
+ case CATEGORY_BLOOD:
+ //跳转到记录里的体征警告界面
+ intent.setAction("com.ic.action.WARNING_MSG");
+ break;
+ case CATEGORY_PHONE:
+ //跳转到通话记录界面
+ intent.setAction("com.ic.action.PHONE_RECORD");
+ break;
+ }
+ startActivity(intent);
+// notificationPresenter.removeNotificationByCategory(category);
+ finish();
+ }
+
+
+ public static final String CATEGORY_TEMPERATURE = "com.ic.temperature";
+ public static final String CATEGORY_BLOOD = "com.ic.blood";
+ public static final String CATEGORY_SMS = "com.ic.mms";
+ public static final String CATEGORY_PHONE = "com.ic.phone";
+
+
public static final String TYPE_SMS = "sms";
public static final String TYPE_HEART_RATE = "heart_rate";
public static final String TYPE_BLOOD_PRESSURE = "blood_pressure";
import static com.ic.launcher.utils.Constants.NOTIFICATIONS;
+
public class MainPagePresenter extends BasePresenter {
public static final String PATH = "settings";
updateEnvTemp();
updateHeartRate();
observerContent(context);
- checkNotification();
+ //checkNotification();
+ updateTime(null);
+ //注册广播,监听灭屏和亮屏
+ listenerScreenState();
}
- private void checkNotification() {
- Cursor query = mContext.getContentResolver().query(Uri.parse(NOTIFICATIONS),
- null, null, null, null);
- if (query != null) {
- if (query.moveToNext()) {
- mContext.startActivity(new Intent(mContext, NotificationActivity.class));
- }
- query.close();
+ private final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ //灭屏
+ MainPagePresenter.getInstance(mContext).checkNotification();
}
+ };
+
+ private void listenerScreenState() {
+ IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(Intent.ACTION_SCREEN_ON);
+ //intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
+ mContext.registerReceiver(mScreenStateReceiver, intentFilter);
+ }
+
+ public void checkNotification() {
+ executor.execute(() -> {
+ Cursor query = mContext.getContentResolver().query(Uri.parse(NOTIFICATIONS),
+ null, null, null, null);
+ if (query != null) {
+ if (query.moveToNext()) {
+ mContext.startActivity(new Intent(mContext, NotificationActivity.class));
+ }
+ query.close();
+ }
+ });
}
private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onClean() {
super.onClean();
+ mContext.unregisterReceiver(mScreenStateReceiver);
mContext.unregisterReceiver(mIntentReceiver);
}
updateEnvTemp();
}
});
- //监听警告地方
- context.getContentResolver().registerContentObserver(Uri.parse(NOTIFICATIONS),
- true, new ContentObserver(null) {
- @Override
- public void onChange(boolean selfChange) {
- //打开通知列表
- mContext.startActivity(new Intent(mContext, NotificationActivity.class));
- }
- });
}
private void getValueByKey(String key) {