version:1.5
fix: update:增加天气预报详情,增加系统应用模块
This commit is contained in:
@@ -6,6 +6,7 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
@@ -28,7 +29,6 @@ import android.widget.ImageView;
|
||||
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;
|
||||
@@ -37,19 +37,20 @@ 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.WeatherHourlyBean;
|
||||
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.activity.APPListActivity;
|
||||
import com.uiui.os.activity.EmergencyActivity;
|
||||
import com.uiui.os.activity.weather.WeatherActivity;
|
||||
import com.uiui.os.adapter.AlarmClockAdapter;
|
||||
import com.uiui.os.adapter.NotificationAdapter;
|
||||
import com.uiui.os.adapter.SOSNnmberAdapter;
|
||||
import com.uiui.os.bean.AlarmClockData;
|
||||
import com.uiui.os.bean.AlarmItem;
|
||||
import com.uiui.os.bean.BaseResponse;
|
||||
import com.uiui.os.network.NetInterfaceManager;
|
||||
import com.uiui.os.utils.AmapManager;
|
||||
import com.uiui.os.utils.APKUtils;
|
||||
import com.uiui.os.utils.AppUtil;
|
||||
@@ -63,9 +64,6 @@ import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
|
||||
/**
|
||||
@@ -74,6 +72,18 @@ import io.reactivex.rxjava3.disposables.Disposable;
|
||||
* 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_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)
|
||||
TextView tv_add;
|
||||
@BindView(R.id.tv_battery)
|
||||
@@ -86,24 +96,18 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
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_noti)
|
||||
RecyclerView rv_noti;
|
||||
@BindView(R.id.rv_clock)
|
||||
RecyclerView rv_clock;
|
||||
@BindView(R.id.wifi_ssid)
|
||||
TextView wifi_ssid;
|
||||
@BindView(R.id.cl_wifi)
|
||||
ConstraintLayout cl_wifi;
|
||||
@BindView(R.id.iv_sos)
|
||||
ImageView iv_sos;
|
||||
@BindView(R.id.rv_sos)
|
||||
RecyclerView rv_sos;
|
||||
@BindView(R.id.cl_sos)
|
||||
ConstraintLayout cl_soso;
|
||||
@BindView(R.id.iv_note_nodata)
|
||||
ImageView iv_note_nodata;
|
||||
|
||||
@@ -116,7 +120,7 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
private AlarmClockAdapter alarmClockAdapter;
|
||||
private SOSNnmberAdapter sosNnmberAdapter;
|
||||
private MMKV mmkv;
|
||||
private Context context;
|
||||
private Context mContext;
|
||||
private ContentResolver mCRv;
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
@@ -265,8 +269,8 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
rootView = inflater.inflate(R.layout.fragment_custom, container, false);
|
||||
context = rootView.getContext();
|
||||
mCRv = context.getContentResolver();
|
||||
mContext = rootView.getContext();
|
||||
mCRv = mContext.getContentResolver();
|
||||
ButterKnife.bind(this, rootView);
|
||||
initView();
|
||||
initData();
|
||||
@@ -289,8 +293,8 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
}
|
||||
});
|
||||
notificationAdapter = new NotificationAdapter();
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(notificationAdapter);
|
||||
rv_noti.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
rv_noti.setAdapter(notificationAdapter);
|
||||
if (isWifiConnect()) {
|
||||
wifi_ssid.setText(getConnectWifiSsid());
|
||||
} else {
|
||||
@@ -317,6 +321,29 @@ 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
setAlarm();
|
||||
refreshMemory();
|
||||
}
|
||||
@@ -359,17 +386,13 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
}
|
||||
|
||||
private void initAmap() {
|
||||
AMapLocationClient aMapLocationClient = AmapManager.getInstance().getLocationClient();
|
||||
aMapLocationClient.stopLocation();
|
||||
aMapLocationClient.startLocation();
|
||||
aMapLocationClient.setLocationListener(new AMapLocationListener() {
|
||||
AmapManager.getInstance().startLocation(new AMapLocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(AMapLocation aMapLocation) {
|
||||
Log.e(TAG, "onLocationChanged: " + aMapLocation);
|
||||
if (aMapLocation.getErrorCode() == 0) {
|
||||
String city = aMapLocation.getCity();
|
||||
getweather(aMapLocation.getLongitude(), aMapLocation.getLatitude());
|
||||
tv_location.setText(city);
|
||||
getweather(aMapLocation.getLongitude(), aMapLocation.getLatitude());
|
||||
} else {
|
||||
|
||||
}
|
||||
@@ -386,15 +409,16 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
List<AlarmClockData> data = gson.fromJson(jsonString, type);
|
||||
List<AlarmClockData> showData = data.subList(0, 1);
|
||||
notificationAdapter.setDataList(data);
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
rv_noti.setVisibility(View.VISIBLE);
|
||||
iv_note_nodata.setVisibility(View.GONE);
|
||||
} else {
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
rv_noti.setVisibility(View.GONE);
|
||||
iv_note_nodata.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void getweather(double longitude, double latitude) {
|
||||
String location = longitude + "," + latitude;
|
||||
/**
|
||||
* 实况天气数据
|
||||
* @param location 所查询的地区,可通过该地区名称、ID、IP和经纬度进行查询经纬度格式:经度,纬度
|
||||
@@ -404,26 +428,52 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
* @param listener 网络访问结果回调
|
||||
*/
|
||||
|
||||
QWeather.getWeatherNow(getActivity(), "" + longitude + "," + latitude, Lang.ZH_HANS, Unit.METRIC, new QWeather.OnResultWeatherNowListener() {
|
||||
QWeather.getWeatherNow(getActivity(), location, Lang.ZH_HANS, Unit.METRIC, new QWeather.OnResultWeatherNowListener() {
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(TAG, "getWeather onError: " + e);
|
||||
Log.e("getWeatherNow", "onError: " + e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WeatherNowBean weatherBean) {
|
||||
// Log.e(TAG, "getWeather onSuccess: " + new Gson().toJson(weatherBean));
|
||||
Log.e("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();
|
||||
// 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.e(TAG, "failed code: " + code);
|
||||
Log.e("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.e("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();
|
||||
int resId = getResources().getIdentifier(imageName, "drawable", getActivity().getPackageName());
|
||||
iv_pic.setImageDrawable(getActivity().getDrawable(resId));
|
||||
tv_temp.setText(now.getTemp() + "℃");
|
||||
}
|
||||
} else {
|
||||
//在此查看返回数据失败的原因
|
||||
Code code = weatherHourlyBean.getCode();
|
||||
Log.e("getWeather24Hourly", "failed code: " + code);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -431,7 +481,7 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
|
||||
|
||||
private void killBackgroundApp() {
|
||||
List<String> pkgList = APKUtils.queryFilterAppList(context);
|
||||
List<String> pkgList = APKUtils.queryFilterAppList(mContext);
|
||||
for (String pkg : pkgList) {
|
||||
if (pkg.equalsIgnoreCase(BuildConfig.APPLICATION_ID)) continue;
|
||||
killBackgroundProcesses(pkg);
|
||||
@@ -442,7 +492,7 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
ActivityManager activityManager;
|
||||
try {
|
||||
activityManager = (ActivityManager)
|
||||
context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
activityManager.killBackgroundProcesses(packageName);
|
||||
Method forceStopPackage = activityManager.getClass()
|
||||
.getDeclaredMethod("forceStopPackage", String.class);
|
||||
@@ -457,8 +507,8 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt
|
||||
}
|
||||
|
||||
private void refreshMemory() {
|
||||
long avail = AppUtil.getAvailMemory(context);
|
||||
long total = AppUtil.getTotalMemory(context);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user