574 lines
22 KiB
Java
574 lines
22 KiB
Java
package com.uiui.aios.fragment;
|
||
|
||
import android.app.ActivityManager;
|
||
import android.content.BroadcastReceiver;
|
||
import android.content.ContentResolver;
|
||
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.provider.Settings;
|
||
import android.text.TextUtils;
|
||
import android.util.Log;
|
||
import android.view.LayoutInflater;
|
||
import android.view.View;
|
||
import android.view.ViewGroup;
|
||
import android.widget.ImageView;
|
||
import android.widget.TextView;
|
||
|
||
import com.amap.api.location.AMapLocation;
|
||
import com.amap.api.location.AMapLocationListener;
|
||
import com.blankj.utilcode.util.NetworkUtils;
|
||
import com.google.gson.Gson;
|
||
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.WeatherHourlyBean;
|
||
import com.qweather.sdk.bean.weather.WeatherNowBean;
|
||
import com.qweather.sdk.view.QWeather;
|
||
import com.tencent.mmkv.MMKV;
|
||
import com.uiui.aios.BuildConfig;
|
||
import com.uiui.aios.R;
|
||
import com.uiui.aios.activity.code.HealthCodeActivity;
|
||
import com.uiui.aios.activity.EmergencyActivity;
|
||
import com.uiui.aios.activity.alarm.AlarmClockActivity;
|
||
import com.uiui.aios.activity.weather.WeatherActivity;
|
||
import com.uiui.aios.adapter.NotificationAdapter;
|
||
import com.uiui.aios.adapter.SOSNnmberAdapter;
|
||
import com.uiui.aios.bean.AlarmClockData;
|
||
import com.uiui.aios.bean.AlarmItem;
|
||
import com.uiui.aios.manager.AmapManager;
|
||
import com.uiui.aios.utils.AlarmUtils;
|
||
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;
|
||
import java.util.ArrayList;
|
||
import java.util.Arrays;
|
||
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 implements NetworkUtils.OnNetworkStatusChangedListener {
|
||
// @BindView(R.id.cl_alarm)
|
||
// ConstraintLayout cl_alarm;
|
||
|
||
@BindView(R.id.cl_note)
|
||
ConstraintLayout cl_note;
|
||
@BindView(R.id.cl_sos)
|
||
ConstraintLayout cl_soso;
|
||
@BindView(R.id.cl_weather)
|
||
ConstraintLayout cl_weather;
|
||
// @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_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.rv_noti)
|
||
RecyclerView rv_noti;
|
||
// @BindView(R.id.rv_clock)
|
||
// RecyclerView rv_clock;
|
||
// @BindView(R.id.wifi_ssid)
|
||
// TextView wifi_ssid;
|
||
@BindView(R.id.iv_sos)
|
||
ImageView iv_sos;
|
||
@BindView(R.id.rv_sos)
|
||
RecyclerView rv_sos;
|
||
@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};
|
||
private int[] mShaderColors = new int[]{0xFF3984f6, 0xFF3984f6, 0xFF3984f6, 0xFF3984f6, 0xFF3984f6, 0xFF3984f6, 0xFF3984f6};
|
||
private View rootView;
|
||
private List<AlarmItem> alarmItemList;
|
||
private NotificationAdapter notificationAdapter;
|
||
// private AlarmClockAdapter alarmClockAdapter;
|
||
private SOSNnmberAdapter sosNnmberAdapter;
|
||
private MMKV mmkv;
|
||
private Context mContext;
|
||
private ContentResolver mCRv;
|
||
|
||
// TODO: Rename parameter arguments, choose names that match
|
||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||
private static final String ARG_PARAM1 = "param1";
|
||
private static final String ARG_PARAM2 = "param2";
|
||
|
||
// TODO: Rename and change types of parameters
|
||
private String mParam1;
|
||
private String mParam2;
|
||
|
||
public CustomFragment() {
|
||
// Required empty public constructor
|
||
}
|
||
|
||
/**
|
||
* Use this factory method to create a new instance of
|
||
* this fragment using the provided parameters.
|
||
*
|
||
* @param param1 Parameter 1.
|
||
* @param param2 Parameter 2.
|
||
* @return A new instance of fragment CustomFragment.
|
||
*/
|
||
// TODO: Rename and change types and number of parameters
|
||
public static CustomFragment newInstance(String param1, String param2) {
|
||
CustomFragment fragment = new CustomFragment();
|
||
Bundle args = new Bundle();
|
||
args.putString(ARG_PARAM1, param1);
|
||
args.putString(ARG_PARAM2, param2);
|
||
fragment.setArguments(args);
|
||
return fragment;
|
||
}
|
||
|
||
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));
|
||
}
|
||
|
||
|
||
@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 void registerBatteryReceiver() {
|
||
if (null == batteryReceiver) {
|
||
batteryReceiver = new BatteryReceiver();
|
||
}
|
||
IntentFilter filter = new IntentFilter();
|
||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||
filter.addAction(Intent.ACTION_BATTERY_LOW);
|
||
filter.addAction(Intent.ACTION_BATTERY_OKAY);
|
||
filter.addAction(Intent.ACTION_POWER_CONNECTED);
|
||
filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
|
||
getActivity().registerReceiver(batteryReceiver, filter);
|
||
}
|
||
|
||
BatteryReceiver batteryReceiver;
|
||
|
||
private class BatteryReceiver extends BroadcastReceiver {
|
||
|
||
@Override
|
||
public void onReceive(Context context, Intent intent) {
|
||
String action = intent.getAction();
|
||
if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
|
||
// 当前电量
|
||
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
|
||
// 最大电量
|
||
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
|
||
int elec = (level * 100) / scale;
|
||
Log.i(TAG, "electricity:=" + 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)
|
||
|| Intent.ACTION_BATTERY_OKAY.equals(action)
|
||
) {
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
private BroadcastReceiver mbatteryReceiver = new BroadcastReceiver() {
|
||
@Override
|
||
public void onReceive(Context context, Intent intent) {
|
||
String action = intent.getAction();
|
||
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 {
|
||
if (rootView != null) {
|
||
// iv_charging.setVisibility(View.GONE);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
};
|
||
|
||
@Override
|
||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||
Bundle savedInstanceState) {
|
||
// Inflate the layout for this fragment
|
||
rootView = inflater.inflate(R.layout.fragment_custom, container, false);
|
||
mContext = rootView.getContext();
|
||
mCRv = mContext.getContentResolver();
|
||
ButterKnife.bind(this, rootView);
|
||
initView();
|
||
initData();
|
||
return rootView;
|
||
}
|
||
|
||
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();
|
||
// }
|
||
// });
|
||
// cl_alarm.setOnClickListener(new View.OnClickListener() {
|
||
// @Override
|
||
// public void onClick(View v) {
|
||
// ApkUtils.openPackage(getActivity(), "com.alarmclock.uiui");
|
||
// }
|
||
// });
|
||
cl_note.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
startActivity(new Intent(mContext, AlarmClockActivity.class));
|
||
}
|
||
});
|
||
notificationAdapter = new NotificationAdapter();
|
||
rv_noti.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
startActivity(new Intent(mContext, AlarmClockActivity.class));
|
||
}
|
||
});
|
||
rv_noti.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||
rv_noti.setAdapter(notificationAdapter);
|
||
if (isWifiConnect()) {
|
||
// wifi_ssid.setText(getConnectWifiSsid());
|
||
} else {
|
||
// wifi_ssid.setText("WiFi未连接");
|
||
}
|
||
// alarmClockAdapter = new AlarmClockAdapter();
|
||
// rv_clock.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||
// rv_clock.setAdapter(alarmClockAdapter);
|
||
sosNnmberAdapter = new SOSNnmberAdapter();
|
||
rv_sos.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||
rv_sos.setAdapter(sosNnmberAdapter);
|
||
cl_soso.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
Intent intent = new Intent(getActivity(), EmergencyActivity.class);
|
||
// intent.putExtra("setting_sos", phone);
|
||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||
getActivity().startActivity(intent);
|
||
}
|
||
});
|
||
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);
|
||
// }
|
||
// }
|
||
// });
|
||
mClHealth.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
startActivity(new Intent(getActivity(), HealthCodeActivity.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();
|
||
}
|
||
|
||
@Override
|
||
public void onResume() {
|
||
super.onResume();
|
||
// setAlarm();
|
||
setSosNumber();
|
||
}
|
||
|
||
public void setSosNumber() {
|
||
String setting_sos = Settings.System.getString(mCRv, "setting_sos");
|
||
if (TextUtils.isEmpty(setting_sos)) {
|
||
// rv_sos.setVisibility(View.GONE);
|
||
// iv_sos.setVisibility(View.VISIBLE);
|
||
} else {
|
||
// rv_sos.setVisibility(View.VISIBLE);
|
||
// iv_sos.setVisibility(View.GONE);
|
||
List<String> phoneList = new ArrayList<>(Arrays.asList(setting_sos.split(",")));
|
||
sosNnmberAdapter.setPhoneNumberList(phoneList);
|
||
}
|
||
}
|
||
|
||
private void setAlarm() {
|
||
if (rootView == null) return;
|
||
if (alarmItemList == null) {
|
||
// tv_add.setVisibility(View.VISIBLE);
|
||
// rv_clock.setVisibility(View.GONE);
|
||
} else {
|
||
// tv_add.setVisibility(View.GONE);
|
||
// rv_clock.setVisibility(View.VISIBLE);
|
||
// alarmClockAdapter.setAlarmItemList(alarmItemList);
|
||
}
|
||
}
|
||
|
||
private void initData() {
|
||
initAmap();
|
||
getAlarmClock();
|
||
}
|
||
|
||
private void initAmap() {
|
||
AmapManager.getInstance().startLocation(new AMapLocationListener() {
|
||
@Override
|
||
public void onLocationChanged(AMapLocation aMapLocation) {
|
||
if (aMapLocation.getErrorCode() == 0) {
|
||
String city = aMapLocation.getCity();
|
||
tv_location.setText(city);
|
||
getweather(aMapLocation.getLongitude(), aMapLocation.getLatitude());
|
||
} else {
|
||
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
private void getAlarmClock() {
|
||
String jsonString = mmkv.decodeString("AlarmClock", "");
|
||
if (!TextUtils.isEmpty(jsonString)) {
|
||
List<AlarmClockData> data = new ArrayList<>();
|
||
data.add(AlarmUtils.getInstance().getRecentAlarmClock());
|
||
notificationAdapter.setDataList(data);
|
||
rv_noti.setVisibility(View.VISIBLE);
|
||
iv_note_nodata.setVisibility(View.GONE);
|
||
} else {
|
||
rv_noti.setVisibility(View.GONE);
|
||
iv_note_nodata.setVisibility(View.VISIBLE);
|
||
}
|
||
}
|
||
|
||
private void getweather(double longitude, double latitude) {
|
||
String location = longitude + "," + latitude;
|
||
Log.e(TAG, "getweather: " + location);
|
||
/**
|
||
* 实况天气数据
|
||
* @param location 所查询的地区,可通过该地区名称、ID、IP和经纬度进行查询经纬度格式:经度,纬度
|
||
* (英文,分隔,十进制格式,北纬东经为正,南纬西经为负)
|
||
* @param lang (选填)多语言,可以不使用该参数,默认为简体中文
|
||
* @param unit (选填)单位选择,公制(m)或英制(i),默认为公制单位
|
||
* @param listener 网络访问结果回调
|
||
*/
|
||
QWeather.getWeatherNow(getActivity(), location, Lang.ZH_HANS, Unit.METRIC, new QWeather.OnResultWeatherNowListener() {
|
||
@Override
|
||
public void onError(Throwable e) {
|
||
Log.e("getWeatherNow", "onError: " + e);
|
||
}
|
||
|
||
@Override
|
||
public void onSuccess(WeatherNowBean weatherBean) {
|
||
Log.d("getWeatherNow", "onSuccess: " + new Gson().toJson(weatherBean));
|
||
//先判断返回的status是否正确,当status正确时获取数据,若status不正确,可查看status对应的Code值找到原因
|
||
if (Code.OK == weatherBean.getCode()) {
|
||
WeatherNowBean.NowBaseBean now = weatherBean.getNow();
|
||
// String imageName = "he" + now.getIcon();
|
||
// int resId = getResources().getIdentifier(imageName, "drawable", getActivity().getPackageName());
|
||
// iv_pic.setImageDrawable(getActivity().getDrawable(resId));
|
||
tv_temp.setText(now.getTemp() + "℃");
|
||
} else {
|
||
//在此查看返回数据失败的原因
|
||
Code code = weatherBean.getCode();
|
||
Log.d("getWeatherNow", "failed code: " + code);
|
||
}
|
||
}
|
||
});
|
||
|
||
QWeather.getWeather24Hourly(getActivity(), location, new QWeather.OnResultWeatherHourlyListener() {
|
||
@Override
|
||
public void onError(Throwable throwable) {
|
||
Log.e("getWeather24Hourly", "onError: " + throwable);
|
||
}
|
||
|
||
@Override
|
||
public void onSuccess(WeatherHourlyBean weatherHourlyBean) {
|
||
Log.d("getWeather24Hourly", "onSuccess: " + new Gson().toJson(weatherHourlyBean));
|
||
if (Code.OK == weatherHourlyBean.getCode()) {
|
||
List<WeatherHourlyBean.HourlyBean> hourly = weatherHourlyBean.getHourly();
|
||
if (hourly != null && hourly.size() != 0) {
|
||
WeatherHourlyBean.HourlyBean now = hourly.get(0);
|
||
String imageName = "he" + now.getIcon();
|
||
Log.e(TAG, "onSuccess: " + imageName);
|
||
if (isAdded()) {
|
||
int resId = getResources().getIdentifier(imageName, "drawable", getActivity().getPackageName());
|
||
Log.e(TAG, "onSuccess: " + resId);
|
||
if (resId == 0) {
|
||
iv_pic.setImageDrawable(getActivity().getDrawable(R.drawable.he100));
|
||
} else {
|
||
iv_pic.setImageDrawable(getActivity().getDrawable(resId));
|
||
}
|
||
tv_temp.setText(now.getTemp() + "℃");
|
||
}
|
||
}
|
||
} else {
|
||
//在此查看返回数据失败的原因
|
||
Code code = weatherHourlyBean.getCode();
|
||
Log.e("getWeather24Hourly", "failed code: " + code);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
private void killBackgroundApp() {
|
||
List<String> pkgList = ApkUtils.queryFilterAppList(mContext);
|
||
for (String pkg : pkgList) {
|
||
if (pkg.equalsIgnoreCase(BuildConfig.APPLICATION_ID)) continue;
|
||
killBackgroundProcesses(pkg);
|
||
}
|
||
refreshMemory();
|
||
}
|
||
|
||
private void killBackgroundProcesses(String packageName) {
|
||
ActivityManager activityManager;
|
||
try {
|
||
activityManager = (ActivityManager)
|
||
mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
||
activityManager.killBackgroundProcesses(packageName);
|
||
Method forceStopPackage = activityManager.getClass()
|
||
.getDeclaredMethod("forceStopPackage", String.class);
|
||
// Log.e(TAG, "killBackgroundProcesses: " + packageName);
|
||
forceStopPackage.setAccessible(true);
|
||
forceStopPackage.invoke(activityManager, packageName);
|
||
} catch (Exception e) {
|
||
Log.e(TAG, "killBackgroundProcesses: " + e.getMessage());
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
|
||
private void refreshMemory() {
|
||
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);
|
||
float x2 = (((total - avail) / (float) total));
|
||
}
|
||
|
||
|
||
@Override
|
||
public void onDestroy() {
|
||
super.onDestroy();
|
||
NetworkUtils.unregisterNetworkStatusChangedListener(this);
|
||
if (batteryReceiver != null) {
|
||
getActivity().unregisterReceiver(batteryReceiver);
|
||
}
|
||
if (mbatteryReceiver != null) {
|
||
getActivity().unregisterReceiver(mbatteryReceiver);
|
||
}
|
||
}
|
||
}
|