version:1.1
fix: add:应用使用数据统计
This commit is contained in:
@@ -5,13 +5,20 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -22,45 +29,73 @@ import android.widget.TextView;
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.amap.api.location.AMapLocationClient;
|
||||
import com.amap.api.location.AMapLocationListener;
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.king.view.circleprogressview.CircleProgressView;
|
||||
import com.qweather.sdk.bean.base.Code;
|
||||
import com.qweather.sdk.bean.base.Lang;
|
||||
import com.qweather.sdk.bean.base.Unit;
|
||||
import com.qweather.sdk.bean.weather.WeatherNowBean;
|
||||
import com.qweather.sdk.view.QWeather;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiui.os.BuildConfig;
|
||||
import com.uiui.os.R;
|
||||
import com.uiui.os.adapter.AlarmClockAdapter;
|
||||
import com.uiui.os.adapter.NotificationAdapter;
|
||||
import com.uiui.os.bean.AlarmClockData;
|
||||
import com.uiui.os.bean.AlarmItem;
|
||||
import com.uiui.os.utils.AmapManager;
|
||||
import com.uiui.os.utils.ApkUtils;
|
||||
import com.uiui.os.utils.APKUtils;
|
||||
import com.uiui.os.utils.AppUtil;
|
||||
import com.uiui.os.utils.Utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link CustomFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class CustomFragment extends Fragment {
|
||||
public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkStatusChangedListener {
|
||||
@BindView(R.id.tv_add)
|
||||
TextView tv_add;
|
||||
@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.cl_alarm)
|
||||
ConstraintLayout cl_alarm;
|
||||
@BindView(R.id.iv_charging)
|
||||
ImageView iv_charging;
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.rv_clock)
|
||||
RecyclerView rv_clock;
|
||||
@BindView(R.id.wifi_ssid)
|
||||
TextView wifi_ssid;
|
||||
@BindView(R.id.cl_wifi)
|
||||
ConstraintLayout cl_wifi;
|
||||
|
||||
private String TAG = CustomFragment.class.getSimpleName();
|
||||
|
||||
private TextView tv_time,tv_add, tv_type, tv_status;
|
||||
private ImageView iv_pic;
|
||||
private TextView tv_temp;
|
||||
private TextView tv_battery;
|
||||
private TextView tv_location;
|
||||
private CircleProgressView cpv;
|
||||
private ConstraintLayout cl_alarm;
|
||||
private ImageView iv_charging;
|
||||
private int[] mShaderColors = new int[]{0xFFfa3db5, 0xFFF8867E, 0xFFF79F6B, 0xFFF79F6B, 0xFFF79F6B, 0xFFF8867E, 0xFFfa3db5};
|
||||
|
||||
private View rootView;
|
||||
private List<AlarmItem> alarmItemList;
|
||||
private NotificationAdapter notificationAdapter;
|
||||
private AlarmClockAdapter alarmClockAdapter;
|
||||
private MMKV mmkv;
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
@@ -71,9 +106,6 @@ public class CustomFragment extends Fragment {
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
private View rootView;
|
||||
private AlarmItem alarmItem;
|
||||
|
||||
public CustomFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
@@ -96,18 +128,20 @@ public class CustomFragment extends Fragment {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void setAlarmItem(AlarmItem item) {
|
||||
this.alarmItem = item;
|
||||
public void setAlarmItem(List<AlarmItem> alarmItem) {
|
||||
this.alarmItemList = alarmItem;
|
||||
setAlarm();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
NetworkUtils.registerNetworkStatusChangedListener(this);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
mmkv = MMKV.defaultMMKV();
|
||||
registerBatteryReceiver();
|
||||
getActivity().registerReceiver(mbatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
}
|
||||
@@ -128,6 +162,39 @@ public class CustomFragment extends Fragment {
|
||||
|
||||
BatteryReceiver batteryReceiver;
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
wifi_ssid.setText("WiFi未连接");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(NetworkUtils.NetworkType networkType) {
|
||||
if (networkType == NetworkUtils.NetworkType.NETWORK_WIFI) {
|
||||
wifi_ssid.setText(getConnectWifiSsid());
|
||||
} else {
|
||||
wifi_ssid.setText("WiFi未连接");
|
||||
}
|
||||
}
|
||||
|
||||
private String getConnectWifiSsid() {
|
||||
WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
|
||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
Log.d("wifiInfo", wifiInfo.toString());
|
||||
Log.d("SSID", wifiInfo.getSSID());
|
||||
return wifiInfo.getSSID();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查wifi是否处开连接状态
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isWifiConnect() {
|
||||
ConnectivityManager connManager = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo mWifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
return mWifiInfo.isConnected();
|
||||
}
|
||||
|
||||
private class BatteryReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
@@ -139,7 +206,7 @@ public class CustomFragment extends Fragment {
|
||||
// 最大电量
|
||||
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
|
||||
int elec = (level * 100) / scale;
|
||||
Log.e(TAG, "electricity:=" + elec + "%");
|
||||
Log.i(TAG, "electricity:=" + elec + "%");
|
||||
tv_battery.setText(elec + "%");
|
||||
} else if (Intent.ACTION_POWER_CONNECTED.equals(action)
|
||||
|| Intent.ACTION_POWER_DISCONNECTED.equals(action)
|
||||
@@ -155,14 +222,14 @@ public class CustomFragment extends Fragment {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Log.e(TAG, "onReceive: " + action);
|
||||
Log.i(TAG, "onReceive: " + action);
|
||||
if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
|
||||
int status = intent.getIntExtra("status", BatteryManager.BATTERY_STATUS_UNKNOWN);
|
||||
if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
|
||||
if (rootView != null) {
|
||||
iv_charging.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
if (rootView != null) {
|
||||
iv_charging.setVisibility(View.GONE);
|
||||
}
|
||||
@@ -176,67 +243,63 @@ public class CustomFragment extends Fragment {
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
rootView = inflater.inflate(R.layout.fragment_custom, container, false);
|
||||
ButterKnife.bind(this, rootView);
|
||||
initView();
|
||||
initData();
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
tv_time = rootView.findViewById(R.id.tv_time);
|
||||
tv_add = rootView.findViewById(R.id.tv_add);
|
||||
tv_type = rootView.findViewById(R.id.tv_type);
|
||||
tv_status = rootView.findViewById(R.id.tv_status);
|
||||
|
||||
iv_pic = rootView.findViewById(R.id.iv_pic);
|
||||
tv_temp = rootView.findViewById(R.id.tv_temp);
|
||||
tv_location = rootView.findViewById(R.id.tv_location);
|
||||
tv_battery = rootView.findViewById(R.id.tv_battery);
|
||||
Log.e(TAG, "initView: " + Utils.getBatteryLevel(getActivity()));
|
||||
tv_battery.setText(Utils.getBatteryLevel(getActivity()) + "%");
|
||||
cpv = rootView.findViewById(R.id.cpv);
|
||||
cpv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
killBackgroundApp();
|
||||
}
|
||||
});
|
||||
cl_alarm = rootView.findViewById(R.id.cl_alarm);
|
||||
cl_alarm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ApkUtils.openPackage(getActivity(), "com.alarmclock.uiui");
|
||||
APKUtils.openPackage(getActivity(), "com.alarmclock.uiui");
|
||||
}
|
||||
});
|
||||
iv_charging = rootView.findViewById(R.id.iv_charging);
|
||||
notificationAdapter = new NotificationAdapter();
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(notificationAdapter);
|
||||
if (isWifiConnect()) {
|
||||
wifi_ssid.setText(getConnectWifiSsid());
|
||||
} else {
|
||||
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);
|
||||
setAlarm();
|
||||
refreshMemory();
|
||||
}
|
||||
|
||||
private void setAlarm() {
|
||||
if (rootView == null) return;
|
||||
if (alarmItem == null) {
|
||||
tv_time.setText("暂无闹钟");
|
||||
tv_time.setVisibility(View.GONE);
|
||||
if (alarmItemList == null) {
|
||||
tv_add.setVisibility(View.VISIBLE);
|
||||
tv_type.setVisibility(View.GONE);
|
||||
tv_status.setVisibility(View.GONE);
|
||||
rv_clock.setVisibility(View.GONE);
|
||||
} else {
|
||||
tv_time.setText(alarmItem.mTime);
|
||||
tv_time.setVisibility(View.VISIBLE);
|
||||
tv_add.setVisibility(View.GONE);
|
||||
tv_type.setText(alarmItem.mRepeatType);
|
||||
tv_type.setVisibility(View.VISIBLE);
|
||||
tv_status.setVisibility(View.VISIBLE);
|
||||
if (alarmItem.mActive) {
|
||||
tv_status.setText("打开");
|
||||
} else {
|
||||
tv_status.setText("关闭");
|
||||
}
|
||||
rv_clock.setVisibility(View.VISIBLE);
|
||||
alarmClockAdapter.setAlarmItemList(alarmItemList);
|
||||
}
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
initAmap();
|
||||
getAlarmClock();
|
||||
}
|
||||
|
||||
private void initAmap() {
|
||||
@@ -258,6 +321,17 @@ public class CustomFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
private void getAlarmClock() {
|
||||
String jsonString = mmkv.decodeString("AlarmClock", "");
|
||||
if (!TextUtils.isEmpty(jsonString)) {
|
||||
Type type = new TypeToken<List<AlarmClockData>>() {
|
||||
}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<AlarmClockData> data = gson.fromJson(jsonString, type);
|
||||
notificationAdapter.setDataList(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void getweather(double longitude, double latitude) {
|
||||
/**
|
||||
* 实况天气数据
|
||||
@@ -276,7 +350,7 @@ public class CustomFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onSuccess(WeatherNowBean weatherBean) {
|
||||
Log.e(TAG, "getWeather onSuccess: " + new Gson().toJson(weatherBean));
|
||||
// Log.e(TAG, "getWeather onSuccess: " + new Gson().toJson(weatherBean));
|
||||
//先判断返回的status是否正确,当status正确时获取数据,若status不正确,可查看status对应的Code值找到原因
|
||||
if (Code.OK == weatherBean.getCode()) {
|
||||
WeatherNowBean.NowBaseBean now = weatherBean.getNow();
|
||||
@@ -295,7 +369,7 @@ public class CustomFragment extends Fragment {
|
||||
|
||||
|
||||
private void killBackgroundApp() {
|
||||
List<String> pkgList = ApkUtils.queryFilterAppList(getActivity());
|
||||
List<String> pkgList = APKUtils.queryFilterAppList(getActivity());
|
||||
for (String pkg : pkgList) {
|
||||
if (pkg.equalsIgnoreCase(BuildConfig.APPLICATION_ID)) continue;
|
||||
killBackgroundProcesses(pkg);
|
||||
@@ -333,6 +407,7 @@ public class CustomFragment extends Fragment {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
NetworkUtils.unregisterNetworkStatusChangedListener(this);
|
||||
if (batteryReceiver != null) {
|
||||
getActivity().unregisterReceiver(batteryReceiver);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user