version:1.9
fix: update:修改包名,添加推送
This commit is contained in:
210
app/src/main/java/com/uiui/aios/fragment/AppListFragment.java
Normal file
210
app/src/main/java/com/uiui/aios/fragment/AppListFragment.java
Normal file
@@ -0,0 +1,210 @@
|
||||
package com.uiui.aios.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.uiui.aios.R;
|
||||
import com.uiui.aios.bean.BaseResponse;
|
||||
import com.uiui.aios.bean.DesktopIcon;
|
||||
import com.uiui.aios.network.NetInterfaceManager;
|
||||
import com.uiui.aios.utils.ApkUtils;
|
||||
import com.uiui.aios.utils.BitmapUtils;
|
||||
import com.uiui.aios.utils.IconUtils;
|
||||
import com.uiui.aios.utils.AppUsedTimeUtils;
|
||||
import com.uiui.aios.view.MyGridLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link AppListFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class AppListFragment extends Fragment {
|
||||
// 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;
|
||||
|
||||
private ArrayList<DesktopIcon> mDesktopIcons;
|
||||
private MyGridLayout gridLayout;
|
||||
private String TAG = AppListFragment.class.getSimpleName();
|
||||
|
||||
public AppListFragment() {
|
||||
// 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 AppListFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static AppListFragment newInstance(String param1, String param2) {
|
||||
AppListFragment fragment = new AppListFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
mDesktopIcons = savedInstanceState.getParcelableArrayList("applicationInfos");
|
||||
}
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
||||
private View rootView;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
rootView = inflater.inflate(R.layout.fragment_applist, container, false);
|
||||
initView();
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
if (mDesktopIcons.size() != 12) {
|
||||
mDesktopIcons.addAll(new ArrayList<>(Arrays.asList(new DesktopIcon[12 - mDesktopIcons.size()])));
|
||||
}
|
||||
gridLayout = rootView.findViewById(R.id.list);
|
||||
if (getActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
gridLayout.set(4, 3);
|
||||
} else {
|
||||
gridLayout.set(3, 4);
|
||||
}
|
||||
|
||||
gridLayout.setGridAdapter(new MyGridLayout.GridAdatper() {
|
||||
@Override
|
||||
public View getView(int index) {
|
||||
PackageManager pm = rootView.getContext().getPackageManager();
|
||||
View view = getLayoutInflater().inflate(R.layout.item_actions,
|
||||
null);
|
||||
ImageView iv = view.findViewById(R.id.iv);
|
||||
TextView tv = view.findViewById(R.id.tv);
|
||||
LinearLayout linearLayout = view.findViewById(R.id.btn_booktag);
|
||||
DesktopIcon desktopIcon = mDesktopIcons.get(index);
|
||||
|
||||
if (desktopIcon != null) {
|
||||
Log.e(TAG, "getView: " + desktopIcon.getPackageName());
|
||||
int i = IconUtils.appClassNameList.indexOf(desktopIcon.getPackageName());
|
||||
if (i != -1) {
|
||||
String val = IconUtils.appIconList.get(i);
|
||||
int resID = getActivity().getResources().getIdentifier(val, "drawable", "com.uiui.aios");
|
||||
if (resID == 0) {
|
||||
Log.e(TAG, "getView: not found src : " + desktopIcon.getPackageName());
|
||||
iv.setImageDrawable(desktopIcon.getIcon());
|
||||
} else {
|
||||
iv.setImageDrawable(getActivity().getResources().getDrawable(resID));
|
||||
}
|
||||
} else {
|
||||
iv.setImageBitmap(BitmapUtils.getIconBitmap(rootView.getContext(), desktopIcon.getIcon()));
|
||||
}
|
||||
tv.setText(desktopIcon.getLable());
|
||||
// linearLayout.setEnabled(true);
|
||||
} else {
|
||||
// linearLayout.setEnabled(false);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
// return applicationInfos == null ? 0 : applicationInfos.size();
|
||||
return mDesktopIcons.size();
|
||||
}
|
||||
});
|
||||
gridLayout.setApplicationInfos(mDesktopIcons);
|
||||
gridLayout.setOnItemClickListener(new MyGridLayout.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(View v, int index) {
|
||||
DesktopIcon desktopIcon = mDesktopIcons.get(index);
|
||||
if (desktopIcon != null) {
|
||||
ApkUtils.openPackage(v.getContext(), desktopIcon.getPackageName());
|
||||
AppUsedTimeUtils.getInstance().setAppPackageName(desktopIcon.getPackageName());
|
||||
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
|
||||
SendRunningApp(getActivity());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void SendRunningApp(Context context) {
|
||||
String packageName = AppUsedTimeUtils.getInstance().getAppPackageName();
|
||||
long time = AppUsedTimeUtils.getInstance().getStartTime();
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("app_package", packageName);
|
||||
jsonObject.addProperty("version_name", ApkUtils.getAPPVersionName(context, packageName));
|
||||
jsonObject.addProperty("start_time", time / 1000);
|
||||
String jsonString = jsonObject.toString();
|
||||
Log.e(TAG, "SendRunningApp: " + jsonString);
|
||||
NetInterfaceManager.getInstance()
|
||||
.getRunningAppObservable(jsonString)
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("SendRunningApp", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("SendRunningApp", "onSubscribe: " + baseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("SendRunningApp", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("SendRunningApp", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setAppList(ArrayList<DesktopIcon> appList) {
|
||||
this.mDesktopIcons = appList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
outState.putParcelableArrayList("applicationInfos", mDesktopIcons);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
package com.uiui.aios.fragment;
|
||||
|
||||
import android.util.SparseArray;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 加载显示Fragment的ViewPagerAdapter基类
|
||||
* 提供可以刷新的方法
|
||||
*
|
||||
* @author Fly
|
||||
* @e-mail 1285760616@qq.com
|
||||
* @time 2018/3/22
|
||||
*/
|
||||
public class BaseFragmentPagerAdapter extends FragmentPagerAdapter {
|
||||
private List<Fragment> mFragmentList;
|
||||
private FragmentManager mFragmentManager;
|
||||
/**下面两个值用来保存Fragment的位置信息,用以判断该位置是否需要更新*/
|
||||
private SparseArray<String> mFragmentPositionMap;
|
||||
private SparseArray<String> mFragmentPositionMapAfterUpdate;
|
||||
|
||||
public BaseFragmentPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
|
||||
super(fm);
|
||||
mFragmentList = fragments;
|
||||
mFragmentManager = fm;
|
||||
mFragmentList = fragments;
|
||||
mFragmentPositionMap = new SparseArray<>();
|
||||
mFragmentPositionMapAfterUpdate = new SparseArray<>();
|
||||
setFragmentPositionMap();
|
||||
setFragmentPositionMapForUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新之前的位置信息,用<hashCode, position>的键值对结构来保存
|
||||
*/
|
||||
private void setFragmentPositionMap() {
|
||||
mFragmentPositionMap.clear();
|
||||
for (int i = 0; i < mFragmentList.size(); i++) {
|
||||
mFragmentPositionMap.put(Long.valueOf(getItemId(i)).intValue(), String.valueOf(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新之后的位置信息,用<hashCode, position>的键值对结构来保存
|
||||
*/
|
||||
private void setFragmentPositionMapForUpdate() {
|
||||
mFragmentPositionMapAfterUpdate.clear();
|
||||
for (int i = 0; i < mFragmentList.size(); i++) {
|
||||
mFragmentPositionMapAfterUpdate.put(Long.valueOf(getItemId(i)).intValue(), String.valueOf(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在此方法中找到需要更新的位置返回POSITION_NONE,否则返回POSITION_UNCHANGED即可
|
||||
*/
|
||||
@Override
|
||||
public int getItemPosition(Object object) {
|
||||
int hashCode = object.hashCode();
|
||||
//查找object在更新后的列表中的位置
|
||||
String position = mFragmentPositionMapAfterUpdate.get(hashCode);
|
||||
//更新后的列表中不存在该object的位置了
|
||||
if (position == null) {
|
||||
return POSITION_NONE;
|
||||
} else {
|
||||
//如果更新后的列表中存在该object的位置, 查找该object之前的位置并判断位置是否发生了变化
|
||||
int size = mFragmentPositionMap.size();
|
||||
for (int i = 0; i < size ; i++) {
|
||||
int key = mFragmentPositionMap.keyAt(i);
|
||||
if (key == hashCode) {
|
||||
String index = mFragmentPositionMap.get(key);
|
||||
if (position.equals(index)) {
|
||||
//位置没变依然返回POSITION_UNCHANGED
|
||||
return POSITION_UNCHANGED;
|
||||
} else {
|
||||
//位置变了
|
||||
return POSITION_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return POSITION_UNCHANGED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定的Fragment替换/更新为新的Fragment
|
||||
* @param oldFragment 旧Fragment
|
||||
* @param newFragment 新Fragment
|
||||
*/
|
||||
public void replaceFragment(Fragment oldFragment, Fragment newFragment) {
|
||||
int position = mFragmentList.indexOf(oldFragment);
|
||||
if (position == -1) {
|
||||
return;
|
||||
}
|
||||
//从Transaction移除旧的Fragment
|
||||
removeFragmentInternal(oldFragment);
|
||||
//替换List中对应的Fragment
|
||||
mFragmentList.set(position, newFragment);
|
||||
//刷新Adapter
|
||||
notifyItemChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定位置的Fragment替换/更新为新的Fragment,同{@link #replaceFragment(Fragment oldFragment, Fragment newFragment)}
|
||||
* @param position 旧Fragment的位置
|
||||
* @param newFragment 新Fragment
|
||||
*/
|
||||
public void replaceFragment(int position, Fragment newFragment) {
|
||||
Fragment oldFragment = mFragmentList.get(position);
|
||||
removeFragmentInternal(oldFragment);
|
||||
mFragmentList.set(position, newFragment);
|
||||
notifyItemChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除指定的Fragment
|
||||
* @param fragment 目标Fragment
|
||||
*/
|
||||
public void removeFragment(Fragment fragment) {
|
||||
//先从List中移除
|
||||
mFragmentList.remove(fragment);
|
||||
//然后从Transaction移除
|
||||
removeFragmentInternal(fragment);
|
||||
//最后刷新Adapter
|
||||
notifyItemChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除指定位置的Fragment,同 {@link #removeFragment(Fragment fragment)}
|
||||
* @param position
|
||||
*/
|
||||
public void removeFragment(int position) {
|
||||
Fragment fragment = mFragmentList.get(position);
|
||||
//然后从List中移除
|
||||
mFragmentList.remove(fragment);
|
||||
//先从Transaction移除
|
||||
removeFragmentInternal(fragment);
|
||||
//最后刷新Adapter
|
||||
notifyItemChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加Fragment
|
||||
* @param fragment 目标Fragment
|
||||
*/
|
||||
public void addFragment(Fragment fragment) {
|
||||
mFragmentList.add(fragment);
|
||||
notifyItemChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* 在指定位置插入一个Fragment
|
||||
* @param position 插入位置
|
||||
* @param fragment 目标Fragment
|
||||
*/
|
||||
public void insertFragment(int position, Fragment fragment) {
|
||||
mFragmentList.add(position, fragment);
|
||||
notifyItemChanged();
|
||||
}
|
||||
|
||||
private void notifyItemChanged() {
|
||||
//刷新之前重新收集位置信息
|
||||
setFragmentPositionMapForUpdate();
|
||||
notifyDataSetChanged();
|
||||
setFragmentPositionMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Transaction移除Fragment
|
||||
* @param fragment 目标Fragment
|
||||
*/
|
||||
private void removeFragmentInternal(Fragment fragment) {
|
||||
FragmentTransaction transaction = mFragmentManager.beginTransaction();
|
||||
transaction.remove(fragment);
|
||||
transaction.commitNow();
|
||||
}
|
||||
|
||||
/**
|
||||
* 此方法不用position做返回值即可破解fragment tag异常的错误
|
||||
*/
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
// 获取当前数据的hashCode,其实这里不用hashCode用自定义的可以关联当前Item对象的唯一值也可以,只要不是直接返回position
|
||||
return mFragmentList.get(position).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
return mFragmentList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mFragmentList.size();
|
||||
}
|
||||
|
||||
public List<Fragment> getFragments() {
|
||||
return mFragmentList;
|
||||
}
|
||||
}
|
||||
550
app/src/main/java/com/uiui/aios/fragment/CustomFragment.java
Normal file
550
app/src/main/java/com/uiui/aios/fragment/CustomFragment.java
Normal file
@@ -0,0 +1,550 @@
|
||||
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.content.pm.ResolveInfo;
|
||||
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.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.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.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;
|
||||
import com.uiui.aios.adapter.SOSNnmberAdapter;
|
||||
import com.uiui.aios.bean.AlarmClockData;
|
||||
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.Utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
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_wifi)
|
||||
ConstraintLayout cl_wifi;
|
||||
@BindView(R.id.qr_code)
|
||||
ConstraintLayout qr_code;
|
||||
@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)
|
||||
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;
|
||||
|
||||
|
||||
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");
|
||||
// }
|
||||
// });
|
||||
notificationAdapter = new NotificationAdapter();
|
||||
rv_noti.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
rv_noti.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);
|
||||
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_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() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(getActivity(), CodeActivity.class));
|
||||
}
|
||||
});
|
||||
// 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)) {
|
||||
Type type = new TypeToken<List<AlarmClockData>>() {
|
||||
}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<AlarmClockData> data = gson.fromJson(jsonString, type);
|
||||
List<AlarmClockData> showData = data.subList(0, 1);
|
||||
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;
|
||||
/**
|
||||
* 实况天气数据
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
}
|
||||
331
app/src/main/java/com/uiui/aios/fragment/SecondFragment.java
Normal file
331
app/src/main/java/com/uiui/aios/fragment/SecondFragment.java
Normal file
@@ -0,0 +1,331 @@
|
||||
package com.uiui.aios.fragment;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.FragmentEvent;
|
||||
import com.uiui.aios.R;
|
||||
import com.uiui.aios.base.BaseFragment;
|
||||
import com.uiui.aios.bean.ActivityBean;
|
||||
import com.uiui.aios.bean.ArticleInfo;
|
||||
import com.uiui.aios.bean.BaseResponse;
|
||||
import com.uiui.aios.bean.DemandBean;
|
||||
import com.uiui.aios.bean.GoodsInfo;
|
||||
import com.uiui.aios.network.NetInterfaceManager;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link SecondFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class SecondFragment extends BaseFragment {
|
||||
private static final String TAG = SecondFragment.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.iv_img)
|
||||
ImageView iv_img;
|
||||
@BindView(R.id.tv_goods_name)
|
||||
TextView tv_goods_name;
|
||||
@BindView(R.id.tv_goods_desc)
|
||||
TextView tv_goods_desc;
|
||||
@BindView(R.id.tv_buying_price)
|
||||
TextView tv_buying_price;
|
||||
@BindView(R.id.progressBar)
|
||||
ProgressBar progressBar;
|
||||
@BindView(R.id.tv_snapup)
|
||||
TextView tv_snapup;
|
||||
|
||||
@BindView(R.id.iv_aimg)
|
||||
ImageView iv_aimg;
|
||||
@BindView(R.id.tv_title)
|
||||
TextView tv_title;
|
||||
@BindView(R.id.tv_content)
|
||||
TextView tv_content;
|
||||
|
||||
@BindView(R.id.iv_avatar_a)
|
||||
ImageView iv_avatar_a;
|
||||
@BindView(R.id.tv_title_a)
|
||||
TextView tv_title_a;
|
||||
|
||||
@BindView(R.id.iv_avatar_d)
|
||||
ImageView iv_avatar_d;
|
||||
@BindView(R.id.tv_title_d)
|
||||
TextView tv_title_d;
|
||||
@BindView(R.id.tv_price)
|
||||
TextView tv_price;
|
||||
|
||||
@BindView(R.id.cl_activity)
|
||||
ConstraintLayout cl_activity;
|
||||
|
||||
@BindView(R.id.cl_demand)
|
||||
ConstraintLayout cl_demand;
|
||||
|
||||
private View rootView;
|
||||
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 SecondFragment() {
|
||||
// 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 SecondFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static SecondFragment newInstance(String param1, String param2) {
|
||||
SecondFragment fragment = new SecondFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
rootView = inflater.inflate(R.layout.fragment_second, container, false);
|
||||
mContext = rootView.getContext();
|
||||
mCRv = mContext.getContentResolver();
|
||||
ButterKnife.bind(this, rootView);
|
||||
initView();
|
||||
initData();
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
getGoods();
|
||||
getArticle();
|
||||
getActivityList();
|
||||
getDemandList();
|
||||
}
|
||||
|
||||
private void getDemandList() {
|
||||
NetInterfaceManager.getInstance().getDemandListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, FragmentEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<DemandBean>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getDemandList", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<DemandBean>> listBaseResponse) {
|
||||
Log.e("getDemandList", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<DemandBean> demandBeans = listBaseResponse.data;
|
||||
if (demandBeans != null && demandBeans.size() != 0) {
|
||||
DemandBean demandBean = demandBeans.get(0);
|
||||
setDemand(demandBean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getDemandList", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getDemandList", "onComplete: ");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void setDemand(DemandBean demandBean) {
|
||||
Glide.with(iv_avatar_d).load(demandBean.getAvatar()).into(iv_avatar_d);
|
||||
tv_title_d.setText(demandBean.getTitle());
|
||||
tv_price.setText(String.valueOf(demandBean.getPrice()));
|
||||
}
|
||||
|
||||
private void getActivityList() {
|
||||
NetInterfaceManager.getInstance().getActivityListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, FragmentEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<ActivityBean>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getActivityList", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<ActivityBean>> listBaseResponse) {
|
||||
Log.e("getActivityList", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<ActivityBean> activityBeans = listBaseResponse.data;
|
||||
if (activityBeans != null && activityBeans.size() != 0) {
|
||||
ActivityBean activityBean = activityBeans.get(0);
|
||||
setActivity(activityBean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getActivityList", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getActivityList", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setActivity(ActivityBean activity) {
|
||||
Glide.with(iv_avatar_a).load(activity.getAvatar()).into(iv_avatar_a);
|
||||
tv_title_a.setText(activity.getTitle());
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
cl_activity.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
openApp();
|
||||
}
|
||||
});
|
||||
cl_demand.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
openApp();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void openApp(){
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
/*知道要跳转应用的包命与目标Activity*/
|
||||
ComponentName componentName = new ComponentName("com.uiui.city", "com.uiui.city.activity.MainActivity");
|
||||
intent.setComponent(componentName);
|
||||
intent.putExtra("", "");//这里Intent传值
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void getGoods() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getGoodsListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, FragmentEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<GoodsInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getGoods", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<GoodsInfo>> listBaseResponse) {
|
||||
Log.e("getGoods", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<GoodsInfo> goodsInfoList = listBaseResponse.data;
|
||||
if (goodsInfoList != null && goodsInfoList.size() != 0) {
|
||||
GoodsInfo goodsInfo = goodsInfoList.get(0);
|
||||
setGoodsInfo(goodsInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getGoods", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getGoods", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setGoodsInfo(GoodsInfo goodsInfo) {
|
||||
Glide.with(iv_img).load(goodsInfo.getImg()).into(iv_img);
|
||||
tv_goods_name.setText(goodsInfo.getGoods_name());
|
||||
tv_goods_desc.setText(goodsInfo.getGoods_desc());
|
||||
tv_buying_price.setText(String.valueOf(goodsInfo.getBuying_price()));
|
||||
}
|
||||
|
||||
private void getArticle() {
|
||||
NetInterfaceManager.getInstance().getArticleListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, FragmentEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<ArticleInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getArticle", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<ArticleInfo>> listBaseResponse) {
|
||||
Log.e("getArticle", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<ArticleInfo> articleInfos = listBaseResponse.data;
|
||||
if (articleInfos != null && articleInfos.size() != 0) {
|
||||
ArticleInfo articleInfo = articleInfos.get(0);
|
||||
setArticleInfo(articleInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getArticle", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getArticle", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setArticleInfo(ArticleInfo articleInfo) {
|
||||
Glide.with(iv_aimg).load(articleInfo.getImg()).into(iv_aimg);
|
||||
tv_title.setText(articleInfo.getTitle());
|
||||
tv_content.setText(articleInfo.getContent());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user