version:2.0
fix: update:通知变化时更新
This commit is contained in:
@@ -17,6 +17,7 @@ import com.uiui.aios.R;
|
||||
import com.uiui.aios.adapter.APPListAdapter;
|
||||
import com.uiui.aios.base.BaseActivity;
|
||||
import com.uiui.aios.bean.AppListInfo;
|
||||
import com.uiui.aios.service.NotificationService;
|
||||
import com.uiui.aios.utils.ApkUtils;
|
||||
import com.uiui.aios.utils.BitmapUtils;
|
||||
import com.uiui.aios.view.RecyclerViewSpacesItemDecoration;
|
||||
@@ -87,6 +88,12 @@ public class APPListActivity extends BaseActivity {
|
||||
mRecyclerView.addItemDecoration(new RecyclerViewSpacesItemDecoration(stringIntegerHashMap));
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
adapter.setAppListInfos(appinfoList);
|
||||
NotificationService.setListener(new NotificationService.NotificationListener() {
|
||||
@Override
|
||||
public void onListenerUpdate() {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ import com.tencent.mmkv.MMKV;
|
||||
import com.uiui.aios.BuildConfig;
|
||||
import com.uiui.aios.R;
|
||||
import com.uiui.aios.activity.APPListActivity;
|
||||
import com.uiui.aios.activity.CodeActivity;
|
||||
import com.uiui.aios.activity.EmergencyActivity;
|
||||
import com.uiui.aios.activity.weather.WeatherActivity;
|
||||
import com.uiui.aios.adapter.NotificationAdapter;
|
||||
@@ -54,6 +53,7 @@ import com.uiui.aios.bean.AlarmItem;
|
||||
import com.uiui.aios.utils.AmapManager;
|
||||
import com.uiui.aios.utils.ApkUtils;
|
||||
import com.uiui.aios.utils.AppUtil;
|
||||
import com.uiui.aios.utils.SchemeUtils;
|
||||
import com.uiui.aios.utils.Utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -75,38 +75,34 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
// @BindView(R.id.cl_alarm)
|
||||
// ConstraintLayout cl_alarm;
|
||||
|
||||
@BindView(R.id.cl_wifi)
|
||||
ConstraintLayout cl_wifi;
|
||||
@BindView(R.id.qr_code)
|
||||
ConstraintLayout qr_code;
|
||||
// @BindView(R.id.cl_wifi)
|
||||
// ConstraintLayout cl_wifi;
|
||||
@BindView(R.id.cl_sos)
|
||||
ConstraintLayout cl_soso;
|
||||
@BindView(R.id.cl_allapp)
|
||||
ConstraintLayout cl_allapp;
|
||||
@BindView(R.id.cl_weather)
|
||||
ConstraintLayout cl_weather;
|
||||
@BindView(R.id.cl_battery)
|
||||
ConstraintLayout cl_battery;
|
||||
// @BindView(R.id.tv_add)
|
||||
// @BindView(R.id.cl_battery)
|
||||
// ConstraintLayout cl_battery;
|
||||
// @BindView(R.id.tv_add)
|
||||
// TextView tv_add;
|
||||
@BindView(R.id.tv_battery)
|
||||
TextView tv_battery;
|
||||
// @BindView(R.id.tv_battery)
|
||||
// TextView tv_battery;
|
||||
@BindView(R.id.tv_location)
|
||||
TextView tv_location;
|
||||
@BindView(R.id.iv_pic)
|
||||
ImageView iv_pic;
|
||||
@BindView(R.id.tv_temp)
|
||||
TextView tv_temp;
|
||||
@BindView(R.id.cpv)
|
||||
CircleProgressView cpv;
|
||||
@BindView(R.id.iv_charging)
|
||||
ImageView iv_charging;
|
||||
// @BindView(R.id.cpv)
|
||||
// CircleProgressView cpv;
|
||||
// @BindView(R.id.iv_charging)
|
||||
// ImageView iv_charging;
|
||||
@BindView(R.id.rv_noti)
|
||||
RecyclerView rv_noti;
|
||||
// @BindView(R.id.rv_clock)
|
||||
// @BindView(R.id.rv_clock)
|
||||
// RecyclerView rv_clock;
|
||||
@BindView(R.id.wifi_ssid)
|
||||
TextView wifi_ssid;
|
||||
// @BindView(R.id.wifi_ssid)
|
||||
// TextView wifi_ssid;
|
||||
@BindView(R.id.iv_sos)
|
||||
ImageView iv_sos;
|
||||
@BindView(R.id.rv_sos)
|
||||
@@ -114,6 +110,14 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
@BindView(R.id.iv_note_nodata)
|
||||
ImageView iv_note_nodata;
|
||||
|
||||
@BindView(R.id.cl_health)
|
||||
ConstraintLayout mClHealth;
|
||||
@BindView(R.id.cl_tongue)
|
||||
ConstraintLayout mClTongue;
|
||||
@BindView(R.id.cl_face)
|
||||
ConstraintLayout mClFace;
|
||||
@BindView(R.id.cl_hand)
|
||||
ConstraintLayout mClHand;
|
||||
|
||||
private String TAG = CustomFragment.class.getSimpleName();
|
||||
// private int[] mShaderColors = new int[]{0xFFfa3db5, 0xFFF8867E, 0xFFF79F6B, 0xFFF79F6B, 0xFFF79F6B, 0xFFF8867E, 0xFFfa3db5};
|
||||
@@ -121,7 +125,7 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
private View rootView;
|
||||
private List<AlarmItem> alarmItemList;
|
||||
private NotificationAdapter notificationAdapter;
|
||||
// private AlarmClockAdapter alarmClockAdapter;
|
||||
// private AlarmClockAdapter alarmClockAdapter;
|
||||
private SOSNnmberAdapter sosNnmberAdapter;
|
||||
private MMKV mmkv;
|
||||
private Context mContext;
|
||||
@@ -177,18 +181,17 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
wifi_ssid.setText("WiFi未连接");
|
||||
// wifi_ssid.setText("WiFi未连接");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(NetworkUtils.NetworkType networkType) {
|
||||
if (networkType == NetworkUtils.NetworkType.NETWORK_WIFI) {
|
||||
wifi_ssid.setText(getConnectWifiSsid());
|
||||
// wifi_ssid.setText(getConnectWifiSsid());
|
||||
} else {
|
||||
wifi_ssid.setText("WiFi未连接");
|
||||
// wifi_ssid.setText("WiFi未连接");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +242,7 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
|
||||
int elec = (level * 100) / scale;
|
||||
Log.i(TAG, "electricity:=" + elec + "%");
|
||||
tv_battery.setText(elec + "%");
|
||||
// tv_battery.setText(elec + "%");
|
||||
} else if (Intent.ACTION_POWER_CONNECTED.equals(action)
|
||||
|| Intent.ACTION_POWER_DISCONNECTED.equals(action)
|
||||
|| Intent.ACTION_BATTERY_LOW.equals(action)
|
||||
@@ -285,13 +288,13 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
|
||||
private void initView() {
|
||||
Log.e(TAG, "initView: " + Utils.getBatteryLevel(getActivity()));
|
||||
tv_battery.setText(Utils.getBatteryLevel(getActivity()) + "%");
|
||||
cpv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
killBackgroundApp();
|
||||
}
|
||||
});
|
||||
// tv_battery.setText(Utils.getBatteryLevel(getActivity()) + "%");
|
||||
// cpv.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// killBackgroundApp();
|
||||
// }
|
||||
// });
|
||||
// cl_alarm.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
@@ -302,16 +305,10 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
rv_noti.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
rv_noti.setAdapter(notificationAdapter);
|
||||
if (isWifiConnect()) {
|
||||
wifi_ssid.setText(getConnectWifiSsid());
|
||||
// wifi_ssid.setText(getConnectWifiSsid());
|
||||
} else {
|
||||
wifi_ssid.setText("WiFi未连接");
|
||||
// wifi_ssid.setText("WiFi未连接");
|
||||
}
|
||||
cl_wifi.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); //直接进入手机中的wifi网络设置界面
|
||||
}
|
||||
});
|
||||
// alarmClockAdapter = new AlarmClockAdapter();
|
||||
// rv_clock.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
// rv_clock.setAdapter(alarmClockAdapter);
|
||||
@@ -327,35 +324,54 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
getActivity().startActivity(intent);
|
||||
}
|
||||
});
|
||||
cl_allapp.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getActivity().startActivity(new Intent(getActivity(), APPListActivity.class));
|
||||
}
|
||||
});
|
||||
cl_weather.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(getActivity(), WeatherActivity.class));
|
||||
}
|
||||
});
|
||||
cl_battery.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
|
||||
ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity(powerUsageIntent, 0);
|
||||
// check that the Battery app exists on this device
|
||||
if (resolveInfo != null) {
|
||||
startActivity(powerUsageIntent);
|
||||
}
|
||||
}
|
||||
});
|
||||
qr_code.setOnClickListener(new View.OnClickListener() {
|
||||
// cl_battery.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
|
||||
// ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity(powerUsageIntent, 0);
|
||||
//// check that the Battery app exists on this device
|
||||
// if (resolveInfo != null) {
|
||||
// startActivity(powerUsageIntent);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
mClHealth.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(getActivity(), CodeActivity.class));
|
||||
// startActivity(new Intent(getActivity(), CodeActivity.class));
|
||||
// SchemeUtils.openScheme(getActivity(), SchemeUtils.SCHEME_TONGUE);
|
||||
}
|
||||
});
|
||||
mClTongue.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// startActivity(new Intent(getActivity(), CodeActivity.class));
|
||||
// startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); //直接进入手机中的wifi网络设置界面
|
||||
SchemeUtils.openScheme(getActivity(), SchemeUtils.SCHEME_TONGUE);
|
||||
}
|
||||
});
|
||||
mClFace.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// startActivity(new Intent(getActivity(), CodeActivity.class));
|
||||
SchemeUtils.openScheme(getActivity(), SchemeUtils.SCHEME_FACE);
|
||||
}
|
||||
});
|
||||
mClHand.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// startActivity(new Intent(getActivity(), CodeActivity.class));
|
||||
// getActivity().startActivity(new Intent(getActivity(), APPListActivity.class));
|
||||
SchemeUtils.openScheme(getActivity(), SchemeUtils.SCHEME_HAND);
|
||||
}
|
||||
});
|
||||
|
||||
// setAlarm();
|
||||
refreshMemory();
|
||||
}
|
||||
@@ -479,7 +495,7 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
WeatherHourlyBean.HourlyBean now = hourly.get(0);
|
||||
String imageName = "he" + now.getIcon();
|
||||
Log.e(TAG, "onSuccess: " + imageName);
|
||||
if (isAdded()){
|
||||
if (isAdded()) {
|
||||
int resId = getResources().getIdentifier(imageName, "drawable", getActivity().getPackageName());
|
||||
Log.e(TAG, "onSuccess: " + resId);
|
||||
if (resId == 0) {
|
||||
@@ -530,8 +546,8 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
long avail = AppUtil.getAvailMemory(mContext);
|
||||
long total = AppUtil.getTotalMemory(mContext);
|
||||
int x = (int) (((total - avail) / (double) total) * 100);
|
||||
cpv.setProgressColor(mShaderColors);
|
||||
cpv.showAnimation(0, x, 1000);
|
||||
// cpv.setProgressColor(mShaderColors);
|
||||
// cpv.showAnimation(0, x, 1000);
|
||||
float x2 = (((total - avail) / (float) total));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author TT
|
||||
@@ -15,14 +17,14 @@ public class NotificationService extends NotificationListenerService {
|
||||
private static final String TAG = NotificationService.class.getSimpleName();
|
||||
|
||||
private static HashMap<String, List<StatusBarNotification>> notificationMap = new HashMap<String, List<StatusBarNotification>>();
|
||||
private static NotificationListener mListener;
|
||||
private static Set<NotificationListener> mListener = new HashSet<NotificationListener>();
|
||||
|
||||
private void updateNotification() {
|
||||
notificationMap.clear();
|
||||
StatusBarNotification[] statusBarNotifications = getActiveNotifications();
|
||||
for (StatusBarNotification sbn : statusBarNotifications) {
|
||||
String pkg = sbn.getPackageName();
|
||||
Log.e(TAG, "onListenerConnected: " + pkg);
|
||||
Log.e(TAG, "onListenerUpdate: " + pkg);
|
||||
if (notificationMap.get(pkg) == null) {
|
||||
notificationMap.put(pkg, new ArrayList<>());
|
||||
notificationMap.get(pkg).add(sbn);
|
||||
@@ -30,7 +32,7 @@ public class NotificationService extends NotificationListenerService {
|
||||
notificationMap.get(pkg).add(sbn);
|
||||
}
|
||||
}
|
||||
Log.e(TAG, "onListenerConnected: " + notificationMap);
|
||||
Log.e(TAG, "onListenerUpdate: " + notificationMap);
|
||||
}
|
||||
|
||||
public static int getNotificationLength(String pkg) {
|
||||
@@ -42,15 +44,11 @@ public class NotificationService extends NotificationListenerService {
|
||||
}
|
||||
|
||||
public static void setListener(NotificationListener listener) {
|
||||
mListener = listener;
|
||||
mListener.add(listener);
|
||||
}
|
||||
|
||||
public interface NotificationListener {
|
||||
void onListenerConnected();
|
||||
|
||||
void onNotificationPosted(StatusBarNotification sbn);
|
||||
|
||||
void onNotificationRemoved(StatusBarNotification sbn);
|
||||
void onListenerUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,10 +59,11 @@ public class NotificationService extends NotificationListenerService {
|
||||
@Override
|
||||
public void onListenerConnected() {
|
||||
super.onListenerConnected();
|
||||
Log.e(TAG, "onListenerConnected: " + getActiveNotifications().length);
|
||||
Log.e(TAG, "onListenerUpdate: " + getActiveNotifications().length);
|
||||
updateNotification();
|
||||
if (mListener != null)
|
||||
mListener.onListenerConnected();
|
||||
for (NotificationListener listener : mListener) {
|
||||
listener.onListenerUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,8 +71,9 @@ public class NotificationService extends NotificationListenerService {
|
||||
super.onNotificationPosted(sbn);
|
||||
Log.e(TAG, "onNotificationPosted: " + getActiveNotifications().length);
|
||||
updateNotification();
|
||||
if (mListener != null)
|
||||
mListener.onNotificationPosted(sbn);
|
||||
for (NotificationListener listener : mListener) {
|
||||
listener.onListenerUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,8 +81,9 @@ public class NotificationService extends NotificationListenerService {
|
||||
super.onNotificationRemoved(sbn);
|
||||
Log.e(TAG, "onNotificationRemoved: " + getActiveNotifications().length);
|
||||
updateNotification();
|
||||
if (mListener != null)
|
||||
mListener.onNotificationRemoved(sbn);
|
||||
for (NotificationListener listener : mListener) {
|
||||
listener.onListenerUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
|
||||
public class AppUtil {
|
||||
|
||||
private static String TAG = AppUtil.class.getSimpleName();
|
||||
|
||||
/**
|
||||
@@ -88,4 +87,5 @@ public class AppUtil {
|
||||
// Byte转位KB或MB
|
||||
return memory * 1024;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
30
app/src/main/java/com/uiui/aios/utils/SchemeUtils.java
Normal file
30
app/src/main/java/com/uiui/aios/utils/SchemeUtils.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.uiui.aios.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
public class SchemeUtils {
|
||||
private static String TAG = SchemeUtils.class.getSimpleName();
|
||||
|
||||
public static final String SCHEME_TONGUE = "uiuihealth://tongue";
|
||||
public static final String SCHEME_FACE = "uiuihealth://face";
|
||||
public static final String SCHEME_HAND = "uiuihealth://hand";
|
||||
|
||||
public static void openScheme(Activity context, String uri) {
|
||||
if (TextUtils.isEmpty(uri)) {
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "openScheme: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user