version:3.7
fix: update:修改主页
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.AddAppAdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.DesktopIcon;
|
||||
import com.uiuios.aios.manager.AppManager;
|
||||
import com.uiuios.aios.view.RecyclerViewSpacesItemDecoration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class AddIconActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.tv_appsize)
|
||||
TextView tv_appsize;
|
||||
|
||||
private AddAppAdapter mAddAppAdapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_add_icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 6));
|
||||
HashMap<String, Integer> stringIntegerHashMap = new HashMap<>();
|
||||
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getRealMetrics(dm);
|
||||
float density = dm.density; // 屏幕密度(0.75 / 1.0 / 1.5)
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.TOP_DECORATION, (int) (density * 1));//top间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.BOTTOM_DECORATION, (int) (density * 1));//底部间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.LEFT_DECORATION, (int) (density * 20));//左间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.RIGHT_DECORATION, (int) (density * 20));//右间距
|
||||
recyclerView.addItemDecoration(new RecyclerViewSpacesItemDecoration(stringIntegerHashMap));
|
||||
mAddAppAdapter = new AddAppAdapter();
|
||||
recyclerView.setAdapter(mAddAppAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
ArrayList<DesktopIcon> desktopIcons = AppManager.getInstance().getAllAppList();
|
||||
mAddAppAdapter.setDesktopIcons(desktopIcons);
|
||||
Set<String> appList = AppManager.getInstance().getAddPackages();
|
||||
mAddAppAdapter.setPackageSet(appList);
|
||||
tv_appsize.setText(String.format(getString(R.string.app_size), desktopIcons.size()));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.Settings;
|
||||
@@ -38,7 +39,9 @@ import com.uiuios.aios.bean.DesktopIcon;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.fragment.AppListFragment;
|
||||
import com.uiuios.aios.base.BaseFragmentPagerAdapter;
|
||||
import com.uiuios.aios.fragment.ControlFragment;
|
||||
import com.uiuios.aios.fragment.custom.CustomFragment;
|
||||
import com.uiuios.aios.fragment.home.HomeFragment;
|
||||
import com.uiuios.aios.fragment.second.SecondFragment;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
import com.uiuios.aios.service.NotificationService;
|
||||
@@ -74,12 +77,14 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
private BaseFragmentPagerAdapter mBaseFragmentPagerAdapter;
|
||||
|
||||
private List<Fragment> mFragments;
|
||||
private CustomFragment mCustomFragment;
|
||||
private SecondFragment mSecondFragment;
|
||||
private ControlFragment mControlFragment;
|
||||
private HomeFragment mHomeFragment;
|
||||
// private CustomFragment mCustomFragment;
|
||||
// private SecondFragment mSecondFragment;
|
||||
|
||||
private boolean is_twoscreen = false;
|
||||
private int appListIndex = 1;
|
||||
private int defaultCurrent = 0;
|
||||
private int appListIndex = 2;
|
||||
private int defaultCurrent = 1;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
@@ -113,8 +118,12 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
// mSecondFragment = new SecondFragment();
|
||||
// mFragments.add(mSecondFragment);
|
||||
// }
|
||||
mCustomFragment = new CustomFragment();
|
||||
mFragments.add(mCustomFragment);
|
||||
// mCustomFragment = new CustomFragment();
|
||||
// mFragments.add(mCustomFragment);
|
||||
mControlFragment =new ControlFragment();
|
||||
mFragments.add(mControlFragment);
|
||||
mHomeFragment =new HomeFragment();
|
||||
mFragments.add(mHomeFragment);
|
||||
|
||||
mMainPresenter.getSystemSettings();
|
||||
// mMainPresenter.getAdminSnSetting();
|
||||
@@ -216,13 +225,13 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
String json = mIAlarmAidlInterface.getAlarm();
|
||||
Log.e(TAG, "onServiceConnected: " + json);
|
||||
if ("暂无闹钟".equalsIgnoreCase(json) || TextUtils.isEmpty(json)) {
|
||||
mCustomFragment.setAlarmItem(null);
|
||||
// mCustomFragment.setAlarmItem(null);
|
||||
return;
|
||||
}
|
||||
Type type = new TypeToken<List<AlarmItem>>() {
|
||||
}.getType();
|
||||
List<AlarmItem> alarmItem = new Gson().fromJson(json, type);
|
||||
mCustomFragment.setAlarmItem(alarmItem);
|
||||
// mCustomFragment.setAlarmItem(alarmItem);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -458,6 +467,16 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
// super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
// super.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
private void registmNewAppReceiver() {
|
||||
mNewAppReceiver = new NewAppReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
@@ -503,7 +522,7 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
Log.e(TAG, "onReceive: " + intent.getAction());
|
||||
String setting_sos = intent.getStringExtra("setting_sos");
|
||||
if (TextUtils.isEmpty(setting_sos)) return;
|
||||
mCustomFragment.setSosNumber();
|
||||
// mCustomFragment.setSosNumber();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
116
app/src/main/java/com/uiuios/aios/adapter/AddAppAdapter.java
Normal file
116
app/src/main/java/com/uiuios/aios/adapter/AddAppAdapter.java
Normal file
@@ -0,0 +1,116 @@
|
||||
package com.uiuios.aios.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
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 androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.bean.DesktopIcon;
|
||||
import com.uiuios.aios.manager.AppManager;
|
||||
import com.uiuios.aios.utils.BitmapUtils;
|
||||
import com.uiuios.aios.utils.IconUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class AddAppAdapter extends RecyclerView.Adapter<AddAppAdapter.AppHolder> {
|
||||
private static final String TAG = AddAppAdapter.class.getSimpleName();
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private List<DesktopIcon> desktopIcons;
|
||||
|
||||
private Set<String> packageSet;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public AppHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
mContext = parent.getContext();
|
||||
return new AppHolder(LayoutInflater.from(mContext).inflate(R.layout.item_add_app, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull AppHolder holder, int position) {
|
||||
DesktopIcon desktopIcon = desktopIcons.get(position);
|
||||
String lable = desktopIcon.getLable();
|
||||
holder.tv_appname.setText(lable);
|
||||
holder.iv_icon.setImageDrawable(desktopIcon.getIcon());
|
||||
String pkg = desktopIcon.getPackageName();
|
||||
|
||||
if (packageSet != null) {
|
||||
if (packageSet.contains(pkg)) {
|
||||
holder.iv_select.setImageDrawable(mContext.getDrawable(R.drawable.icon_selected));
|
||||
} else {
|
||||
holder.iv_select.setImageDrawable(mContext.getDrawable(R.drawable.icon_unselected));
|
||||
}
|
||||
}
|
||||
|
||||
Log.e(TAG, "getView: " + pkg);
|
||||
int i = IconUtils.appClassNameList.indexOf(pkg);
|
||||
if (i != -1) {
|
||||
String val = IconUtils.appIconList.get(i);
|
||||
int resID = mContext.getResources().getIdentifier(val, "drawable", "com.uiui.zyos");
|
||||
if (resID == 0) {
|
||||
Log.e(TAG, "getView: not found src : " + pkg);
|
||||
holder.iv_icon.setImageBitmap(BitmapUtils.getIconBitmap(mContext, desktopIcon.getIcon()));
|
||||
} else {
|
||||
holder.iv_icon.setImageDrawable(mContext.getResources().getDrawable(resID));
|
||||
}
|
||||
} else {
|
||||
if (AppManager.ADD_NAME.equals(pkg)) {
|
||||
holder.iv_icon.setImageDrawable(desktopIcon.getIcon());
|
||||
} else {
|
||||
holder.iv_icon.setImageBitmap(BitmapUtils.getIconBitmap(mContext, desktopIcon.getIcon()));
|
||||
}
|
||||
}
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (packageSet.contains(pkg)) {
|
||||
packageSet.remove(pkg);
|
||||
AppManager.getInstance().removeAddPakcage(pkg);
|
||||
} else {
|
||||
packageSet.add(pkg);
|
||||
AppManager.getInstance().addAddPakcage(pkg);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return desktopIcons == null ? 0 : desktopIcons.size();
|
||||
}
|
||||
|
||||
public void setDesktopIcons(List<DesktopIcon> desktopIcons) {
|
||||
this.desktopIcons = desktopIcons;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setPackageSet(Set<String> packageSet) {
|
||||
this.packageSet = packageSet;
|
||||
}
|
||||
|
||||
class AppHolder extends RecyclerView.ViewHolder {
|
||||
ConstraintLayout root;
|
||||
TextView tv_appname;
|
||||
ImageView iv_icon, iv_select;
|
||||
|
||||
public AppHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
tv_appname = itemView.findViewById(R.id.tv_appname);
|
||||
iv_icon = itemView.findViewById(R.id.iv_icon);
|
||||
iv_select = itemView.findViewById(R.id.iv_select);
|
||||
}
|
||||
}
|
||||
}
|
||||
120
app/src/main/java/com/uiuios/aios/adapter/HomeAppAdapter.java
Normal file
120
app/src/main/java/com/uiuios/aios/adapter/HomeAppAdapter.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package com.uiuios.aios.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
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 androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.AddIconActivity;
|
||||
import com.uiuios.aios.bean.DesktopIcon;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.manager.AppManager;
|
||||
import com.uiuios.aios.utils.ApkUtils;
|
||||
import com.uiuios.aios.utils.BitmapUtils;
|
||||
import com.uiuios.aios.utils.IconUtils;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HomeAppAdapter extends RecyclerView.Adapter<HomeAppAdapter.AppHolder> {
|
||||
private static final String TAG = HomeAppAdapter.class.getSimpleName();
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private List<DesktopIcon> desktopIcons;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public AppHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
mContext = parent.getContext();
|
||||
return new AppHolder(LayoutInflater.from(mContext).inflate(R.layout.item_home_app, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull AppHolder holder, int position) {
|
||||
DesktopIcon desktopIcon = desktopIcons.get(position);
|
||||
String lable = desktopIcon.getLable();
|
||||
holder.tv_appname.setText(lable);
|
||||
holder.iv_icon.setImageDrawable(desktopIcon.getIcon());
|
||||
String pkg = desktopIcon.getPackageName();
|
||||
Log.e(TAG, "getView: " + pkg);
|
||||
int i = IconUtils.appClassNameList.indexOf(pkg);
|
||||
if (i != -1) {
|
||||
String val = IconUtils.appIconList.get(i);
|
||||
int resID = mContext.getResources().getIdentifier(val, "drawable", "com.uiui.zyos");
|
||||
if (resID == 0) {
|
||||
Log.e(TAG, "getView: not found src : " + pkg);
|
||||
holder.iv_icon.setImageBitmap(BitmapUtils.getIconBitmap(mContext, desktopIcon.getIcon()));
|
||||
} else {
|
||||
holder.iv_icon.setImageDrawable(mContext.getResources().getDrawable(resID));
|
||||
}
|
||||
} else {
|
||||
// if (AppManager.ADD_NAME.equals(pkg)) {
|
||||
// holder.iv_icon.setImageDrawable(desktopIcon.getIcon());
|
||||
// } else if (AppManager.UPDATE_NAME.equals(pkg)) {
|
||||
// holder.iv_icon.setImageDrawable(desktopIcon.getIcon());
|
||||
// } else {
|
||||
holder.iv_icon.setImageDrawable(desktopIcon.getIcon());
|
||||
// }
|
||||
}
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (AppManager.ADD_NAME.equals(pkg)) {
|
||||
mContext.startActivity(new Intent(mContext, AddIconActivity.class));
|
||||
// } else if (AppManager.UPDATE_NAME.equals(pkg)) {
|
||||
// Intent intent = new Intent();
|
||||
// ComponentName componentName = new ComponentName("com.uiui.zy", "com.uiui.zy.activity.update.UpdateActivity");
|
||||
// intent.setComponent(componentName);
|
||||
// mContext.startActivity(intent);
|
||||
} else {
|
||||
int setting_other_appInstaller = Settings.Global.getInt(mContext.getContentResolver(), CommonConfig.SETTING_OTHER_APPINSTALLER_KEY, 1);
|
||||
if (setting_other_appInstaller == 0
|
||||
&& !ApkUtils.isSystemApp(mContext, desktopIcon.getPackageName()
|
||||
)) {
|
||||
ToastUtil.show("已禁止应用打开");
|
||||
} else {
|
||||
ApkUtils.openPackage(mContext, desktopIcon.getPackageName(), desktopIcon.getClassName());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return desktopIcons == null ? 0 : desktopIcons.size();
|
||||
}
|
||||
|
||||
public List<DesktopIcon> getDesktopIcons() {
|
||||
return desktopIcons;
|
||||
}
|
||||
|
||||
public void setDesktopIcons(List<DesktopIcon> desktopIcons) {
|
||||
this.desktopIcons = desktopIcons;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
class AppHolder extends RecyclerView.ViewHolder {
|
||||
ConstraintLayout root;
|
||||
TextView tv_appname;
|
||||
ImageView iv_icon;
|
||||
|
||||
public AppHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
tv_appname = itemView.findViewById(R.id.tv_appname);
|
||||
iv_icon = itemView.findViewById(R.id.iv_icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import com.tencent.bugly.crashreport.CrashReport;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiuios.aios.BuildConfig;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.manager.AppManager;
|
||||
import com.uiuios.aios.manager.AppStatusManager;
|
||||
import com.uiuios.aios.manager.ConnectManager;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
@@ -46,6 +47,8 @@ public class BaseApplication extends Application {
|
||||
Aria.init(this);
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||
Aria.get(this).getDownloadConfig().setConvertSpeed(true);
|
||||
|
||||
AppManager.init(this);
|
||||
WiFiUtils.init(this);
|
||||
AppUsedTimeUtils.init(this);
|
||||
AlarmUtils.init(this);
|
||||
|
||||
886
app/src/main/java/com/uiuios/aios/fragment/ControlFragment.java
Normal file
886
app/src/main/java/com/uiuios/aios/fragment/ControlFragment.java
Normal file
@@ -0,0 +1,886 @@
|
||||
package com.uiuios.aios.fragment;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.hardware.camera2.CameraAccessException;
|
||||
import android.hardware.camera2.CameraCharacteristics;
|
||||
import android.hardware.camera2.CameraManager;
|
||||
import android.media.AudioManager;
|
||||
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.Build;
|
||||
import android.os.Bundle;
|
||||
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.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.ControlActivity;
|
||||
import com.uiuios.aios.base.BaseFragment;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.disklrucache.CacheHelper;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
import com.uiuios.aios.utils.BrightnessUtils;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.view.RulerSeekBar;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link ControlFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class ControlFragment extends BaseFragment {
|
||||
private static final String TAG = ControlFragment.class.getSimpleName();
|
||||
|
||||
|
||||
@BindView(R.id.seekBar)
|
||||
RulerSeekBar seekBar;
|
||||
@BindView(R.id.seekbar_brightness)
|
||||
SeekBar seekbar_brightness;
|
||||
@BindView(R.id.seekbar_sound)
|
||||
SeekBar seekbar_sound;
|
||||
|
||||
@BindView(R.id.tv_sound)
|
||||
TextView tv_sound;
|
||||
@BindView(R.id.tv_brightness)
|
||||
TextView tv_brightness;
|
||||
@BindView(R.id.tv_location)
|
||||
TextView tv_location;
|
||||
@BindView(R.id.cl_wifi)
|
||||
ConstraintLayout cl_wifi;
|
||||
@BindView(R.id.cl_bt)
|
||||
ConstraintLayout cl_bt;
|
||||
@BindView(R.id.cl_battery)
|
||||
ConstraintLayout cl_battery;
|
||||
@BindView(R.id.cl_flashlight)
|
||||
ConstraintLayout cl_flashlight;
|
||||
@BindView(R.id.cl_location)
|
||||
ConstraintLayout cl_location;
|
||||
|
||||
|
||||
private View rootView;
|
||||
private Context mContext;
|
||||
private ContentResolver mCRv;
|
||||
private CacheHelper mCacheHelper;
|
||||
|
||||
// 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 ControlFragment() {
|
||||
// Required empty public constructor
|
||||
Log.e(TAG, "ControlFragment: 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 ControlFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static ControlFragment newInstance(String param1, String param2) {
|
||||
ControlFragment fragment = new ControlFragment();
|
||||
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 void fetchData() {
|
||||
Log.e(TAG, "fetchData: ");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
Log.e(TAG, "onConfigurationChanged: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
long time = System.currentTimeMillis();
|
||||
Log.e(TAG, "onCreateView: rootView = " + rootView);
|
||||
if (null != rootView) {
|
||||
ViewGroup parent = (ViewGroup) rootView.getParent();
|
||||
if (null != parent) {
|
||||
parent.removeView(rootView);
|
||||
}
|
||||
} else { // 如ongoing果rootView为空 ,就实例化该视图
|
||||
rootView = inflater.inflate(R.layout.fragment_control, container, false);
|
||||
mContext = rootView.getContext();
|
||||
mCRv = mContext.getContentResolver();
|
||||
mCacheHelper = new CacheHelper(mContext);
|
||||
ButterKnife.bind(this, rootView);
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
Log.e(TAG, "onCreateView: tiem = " + (System.currentTimeMillis() - time));
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
mCRv = mContext.getContentResolver();
|
||||
getWifi();
|
||||
registerReceivers();
|
||||
getBluetooth();
|
||||
registerBluetoothReceiver();
|
||||
getBattery();
|
||||
registerBatteryReceiver();
|
||||
getFlashlight();
|
||||
getFontSize();
|
||||
getLocation();
|
||||
getBrightness();
|
||||
getSound();
|
||||
cl_flashlight.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
try {
|
||||
startActivity(new Intent(Settings.ACTION_SETTINGS));
|
||||
} catch (Exception e) {
|
||||
ToastUtil.show("打开失败");
|
||||
Log.e(TAG, "onClick: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
cl_battery.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(Settings.ACTION_BATTERY_SAVER_SETTINGS));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
|
||||
}
|
||||
|
||||
private void getWifi() {
|
||||
cl_wifi.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
|
||||
// startActivity(new Intent(ControlActivity.this, WiFiManagerActivity.class));
|
||||
}
|
||||
});
|
||||
// if (isWifiEnabled()) {
|
||||
//// tv_wifi_ssid.setText(getConnectWifiSsid());
|
||||
// cl_wifi.setBackground(mContext.getDrawable(R.drawable.control_background_item));
|
||||
// } else {
|
||||
//// tv_wifi_ssid.setText("未连接");
|
||||
// cl_wifi.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
// }
|
||||
}
|
||||
|
||||
public boolean isWifiEnabled() {
|
||||
WifiManager wifiMgr = (WifiManager)mContext. getSystemService(Context.WIFI_SERVICE);
|
||||
if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
|
||||
ConnectivityManager connManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo wifiInfo = connManager
|
||||
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
return wifiInfo.isConnected();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private WifiReceiver mWifiReceiver;
|
||||
|
||||
private void registerReceivers() {
|
||||
registerWiFiReceiver();
|
||||
}
|
||||
|
||||
private void registerWiFiReceiver() {
|
||||
if (mWifiReceiver == null) {
|
||||
mWifiReceiver = new WifiReceiver();
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
||||
filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
|
||||
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
mContext. registerReceiver(mWifiReceiver, filter);
|
||||
}
|
||||
|
||||
public class WifiReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "wifiReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
case WifiManager.RSSI_CHANGED_ACTION:
|
||||
Log.e(TAG, "wifi信号强度变化");
|
||||
break;
|
||||
//wifi连接上与否
|
||||
case WifiManager.NETWORK_STATE_CHANGED_ACTION:
|
||||
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||
if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
|
||||
Log.e(TAG, "wifi断开");
|
||||
// tv_wifi_ssid.setText("未连接");
|
||||
// cl_wifi.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
} else if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
|
||||
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
//获取当前wifi名称
|
||||
String newSSID = wifiInfo.getSSID();
|
||||
// tv_wifi_ssid.setText(getConnectWifiSsid());
|
||||
// cl_wifi.setBackground(mContext.getDrawable(R.drawable.control_background_item));
|
||||
}
|
||||
break;
|
||||
//wifi打开与否
|
||||
case WifiManager.WIFI_STATE_CHANGED_ACTION:
|
||||
int wifistate = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED);
|
||||
if (wifistate == WifiManager.WIFI_STATE_DISABLED) {
|
||||
Log.e(TAG, "系统关闭wifi");
|
||||
// tv_wifi_ssid.setText("关");
|
||||
// cl_wifi.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
} else if (wifistate == WifiManager.WIFI_STATE_ENABLED) {
|
||||
Log.e(TAG, "系统开启wifi");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前连接WIFI的SSID
|
||||
*/
|
||||
public String getSSID() {
|
||||
WifiManager wm = (WifiManager)mContext. getSystemService(Context.WIFI_SERVICE);
|
||||
if (wm != null) {
|
||||
WifiInfo winfo = wm.getConnectionInfo();
|
||||
if (winfo != null) {
|
||||
String s = winfo.getSSID();
|
||||
if (s.length() > 2 && s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') {
|
||||
return s.substring(1, s.length() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getConnectWifiSsid() {
|
||||
// WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
// WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
//// //去掉带引号的字符串方法一
|
||||
//// String wifiInfo1 = wifiInfo.getSSID();
|
||||
//// if (wifiInfo1.contains("\"")) {
|
||||
//// wifiInfo1 = wifiInfo1.substring(1, wifiInfo1.length() - 1);
|
||||
//// }
|
||||
////去掉带引号的字符串方法二
|
||||
// String wifiSSID = wifiInfo.getSSID();
|
||||
// String wifiInfo1 = wifiSSID.replaceAll("\"", "");
|
||||
return RemoteManager.getInstance().getConnectWifiSsid();
|
||||
}
|
||||
|
||||
private BluetoothAdapter bluetoothAdapter;
|
||||
|
||||
private void getBluetooth() {
|
||||
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (bluetoothAdapter.isEnabled()) {
|
||||
// if (isConnected()) {
|
||||
// cl_bt.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
// tv_bt_ssid.setText(getBluetoothDeviceName());
|
||||
// } else {
|
||||
// cl_bt.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
// tv_bt_ssid.setText("未连接");
|
||||
// }
|
||||
} else {
|
||||
// cl_bt.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
// tv_bt_ssid.setText("已关闭");
|
||||
}
|
||||
getConnectedDevicesV1();
|
||||
cl_bt.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// public boolean isConnected() {
|
||||
// Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices();
|
||||
// List<BluetoothDevice> deviceList = bondedDevices.stream().filter(new Predicate<BluetoothDevice>() {
|
||||
// @Override
|
||||
// public boolean test(BluetoothDevice bluetoothDevice) {
|
||||
// return bluetoothDevice.isConnected();
|
||||
// }
|
||||
// }).collect(Collectors.toList());
|
||||
// return deviceList.size() > 0;
|
||||
// }
|
||||
|
||||
// public String getBluetoothDeviceName() {
|
||||
// Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices();
|
||||
// List<BluetoothDevice> deviceList = bondedDevices.stream().filter(new Predicate<BluetoothDevice>() {
|
||||
// @Override
|
||||
// public boolean test(BluetoothDevice bluetoothDevice) {
|
||||
// return bluetoothDevice.isConnected();
|
||||
// }
|
||||
// }).collect(Collectors.toList());
|
||||
// if (deviceList.size() == 0) {
|
||||
// return "未连接";
|
||||
// } else {
|
||||
// return deviceList.get(0).getName();
|
||||
// }
|
||||
// }
|
||||
|
||||
//TODO 根据mac地址判断是否已连接(这里参数可以直接用BluetoothDevice对象)
|
||||
//但这么写其实更通用。
|
||||
public boolean isConnected(String macAddress) {
|
||||
if (!BluetoothAdapter.checkBluetoothAddress(macAddress)) {
|
||||
return false;
|
||||
}
|
||||
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(macAddress);
|
||||
|
||||
Method isConnectedMethod = null;
|
||||
boolean isConnected;
|
||||
try {
|
||||
isConnectedMethod = BluetoothDevice.class.getDeclaredMethod("isConnected", (Class[]) null);
|
||||
isConnectedMethod.setAccessible(true);
|
||||
isConnected = (boolean) isConnectedMethod.invoke(device, (Object[]) null);
|
||||
} catch (NoSuchMethodException e) {
|
||||
isConnected = false;
|
||||
} catch (IllegalAccessException e) {
|
||||
isConnected = false;
|
||||
} catch (InvocationTargetException e) {
|
||||
isConnected = false;
|
||||
}
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统中已连接的蓝牙设备
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<BluetoothDevice> getConnectedDevicesV1() {
|
||||
Class<BluetoothAdapter> bluetoothAdapterClass = BluetoothAdapter.class;//得到BluetoothAdapter的Class对象
|
||||
Set<BluetoothDevice> deviceSet = new HashSet<>();
|
||||
//是否存在连接的蓝牙设备
|
||||
try {
|
||||
Method method = bluetoothAdapterClass.getDeclaredMethod("getMostRecentlyConnectedDevices", (Class[]) null);
|
||||
//打开权限
|
||||
method.setAccessible(true);
|
||||
List<BluetoothDevice> list = (List<BluetoothDevice>) method.invoke(BluetoothAdapter.getDefaultAdapter(), (Object[]) null);
|
||||
Log.e("zbh", "最近连接过的设备:");
|
||||
for (BluetoothDevice dev : list
|
||||
) {
|
||||
String Type = "";
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
switch (dev.getType()) {
|
||||
case BluetoothDevice.DEVICE_TYPE_CLASSIC:
|
||||
Type = "经典";
|
||||
break;
|
||||
case BluetoothDevice.DEVICE_TYPE_LE:
|
||||
Type = "BLE";
|
||||
break;
|
||||
case BluetoothDevice.DEVICE_TYPE_DUAL:
|
||||
Type = "双模";
|
||||
break;
|
||||
default:
|
||||
Type = "未知";
|
||||
break;
|
||||
}
|
||||
}
|
||||
String connect = "设备未连接";
|
||||
if (isConnected(dev.getAddress())) {
|
||||
deviceSet.add(dev);
|
||||
connect = "设备已连接";
|
||||
}
|
||||
Log.e("zbh", connect + ", address = " + dev.getAddress() + "(" + Type + "), name --> " + dev.getName());
|
||||
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return deviceSet;
|
||||
}
|
||||
|
||||
private BluetoothMonitorReceiver bleListenerReceiver;
|
||||
|
||||
private void registerBluetoothReceiver() {
|
||||
bleListenerReceiver = new BluetoothMonitorReceiver();
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
// 监视蓝牙关闭和打开的状态
|
||||
intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
// 监视蓝牙设备与APP连接的状态
|
||||
intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
|
||||
intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
|
||||
// 注册广播
|
||||
mContext. registerReceiver(this.bleListenerReceiver, intentFilter);
|
||||
}
|
||||
|
||||
public class BluetoothMonitorReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Log.e("BluetoothMonitorReceiver", "onReceive: " + action);
|
||||
if (!TextUtils.isEmpty(action)) {
|
||||
switch (action) {
|
||||
case BluetoothAdapter.ACTION_STATE_CHANGED:
|
||||
int blueState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
|
||||
switch (blueState) {
|
||||
case BluetoothAdapter.STATE_TURNING_ON:
|
||||
// tv_bt_ssid.setText("正在打开");
|
||||
// cl_bt.setBackground(mContext.getDrawable(R.drawable.control_background_item));
|
||||
break;
|
||||
case BluetoothAdapter.STATE_ON:
|
||||
// tv_bt_ssid.setText("已打开");
|
||||
// cl_bt.setBackground(mContext.getDrawable(R.drawable.control_background_item));
|
||||
break;
|
||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
||||
// tv_bt_ssid.setText("正在关闭");
|
||||
// cl_bt.setBackground(mContext.getDrawable(R.drawable.control_background_item));
|
||||
break;
|
||||
case BluetoothAdapter.STATE_OFF:
|
||||
// tv_bt_ssid.setText("已关闭");
|
||||
// cl_bt.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
break;
|
||||
case BluetoothDevice.ACTION_ACL_CONNECTED:
|
||||
// tv_bt_ssid.setText(getBluetoothDeviceName());
|
||||
// cl_bt.setBackground(mContext.getDrawable(R.drawable.control_background_item));
|
||||
break;
|
||||
case BluetoothDevice.ACTION_ACL_DISCONNECTED:
|
||||
// tv_bt_ssid.setText("未连接");
|
||||
// cl_bt.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getBattery() {
|
||||
// tv_electricity.setText(getBatteryCapacity() + "%");
|
||||
if (isBatteryCharging()) {
|
||||
// cl_battery.setBackground(mContext.getDrawable(R.drawable.control_background_item));
|
||||
} else {
|
||||
// cl_battery.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动获取当前电池是否在充电 , 即数据线是否插在手机上
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isBatteryCharging() {
|
||||
boolean isBatteryCharging = false;
|
||||
// 主动发送包含是否正在充电状态的广播 , 该广播会持续发送
|
||||
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||
// 注册广播接受者
|
||||
Intent intent = mContext.registerReceiver(null, intentFilter);
|
||||
// 获取充电状态
|
||||
int batteryChargeState = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
|
||||
// 判定是否是 AC 交流电充电
|
||||
boolean isAc = batteryChargeState == BatteryManager.BATTERY_PLUGGED_AC;
|
||||
// 判断是否是 USB 充电
|
||||
boolean isUsb = batteryChargeState == BatteryManager.BATTERY_PLUGGED_USB;
|
||||
// 判断是否是 无线充电
|
||||
boolean isWireless = batteryChargeState == BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
||||
// 如何上述任意一种为 true , 说明当前正在充电
|
||||
isBatteryCharging = isAc || isUsb || isWireless;
|
||||
return isBatteryCharging;
|
||||
}
|
||||
|
||||
|
||||
public int getBatteryCapacity() {
|
||||
try {
|
||||
BatteryManager batteryManager = (BatteryManager)mContext. getSystemService(Context.BATTERY_SERVICE);
|
||||
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
|
||||
} catch (Exception e) {
|
||||
Log.e("getBattery", "getBattery" + e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private BatteryReceiver mBatteryReceiver;
|
||||
|
||||
private void registerBatteryReceiver() {
|
||||
if (mBatteryReceiver == null) {
|
||||
mBatteryReceiver = new BatteryReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_POWER_CONNECTED);
|
||||
filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
|
||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||
// filter.addAction(Intent.ACTION_BATTERY_LEVEL_CHANGED);
|
||||
filter.addAction(Intent.ACTION_BATTERY_LOW);
|
||||
filter.addAction(Intent.ACTION_BATTERY_OKAY);
|
||||
mContext. registerReceiver(mBatteryReceiver, filter);
|
||||
}
|
||||
}
|
||||
|
||||
public class BatteryReceiver extends BroadcastReceiver {
|
||||
public static final String TAG = "BatteryReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// 获取广播事件
|
||||
String action = intent.getAction();
|
||||
if (TextUtils.isEmpty(action)) return;
|
||||
Log.e(TAG, "onReceive: " + action);
|
||||
switch (action) {
|
||||
case Intent.ACTION_POWER_CONNECTED:
|
||||
// cl_battery.setBackground(mContext.getDrawable(R.drawable.control_background_item));
|
||||
break;
|
||||
case Intent.ACTION_POWER_DISCONNECTED:
|
||||
// cl_battery.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
break;
|
||||
// case Intent.ACTION_BATTERY_LEVEL_CHANGED:
|
||||
// tv_electricity.setText(getBatteryCapacity() + "%");
|
||||
// break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean flashing = false;
|
||||
private CameraManager cameraManager;
|
||||
|
||||
// private void getFlashlight() {
|
||||
// if (isFlashlightAvailable()) {
|
||||
// tv_flashlight_switch.setText("关");
|
||||
// cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
// } else {
|
||||
// tv_flashlight_switch.setText("不可用");
|
||||
// cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
// return;
|
||||
// }
|
||||
//// if (isFlashlightEnabled()) {
|
||||
//// tv_flashlight_switch.setText("开");
|
||||
//// cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
//// } else {
|
||||
//// tv_flashlight_switch.setText("关");
|
||||
//// cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
//// }
|
||||
//
|
||||
// cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
|
||||
//
|
||||
// cl_flashlight.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// if (flashing) {
|
||||
// try {
|
||||
// String CameraId = cameraManager.getCameraIdList()[0];
|
||||
// cameraManager.setTorchMode(CameraId, false);
|
||||
// } catch (CameraAccessException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// flashing = false;
|
||||
// tv_flashlight_switch.setText("关");
|
||||
// cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
// } else {
|
||||
// try {
|
||||
// String CameraId = cameraManager.getCameraIdList()[0];
|
||||
// cameraManager.setTorchMode(CameraId, true);
|
||||
// } catch (CameraAccessException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// tv_flashlight_switch.setText("开");
|
||||
// cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
// flashing = true;
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
BroadcastReceiver mTimeUpdateReceiver;
|
||||
|
||||
class TimeUpdateReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent == null) return;
|
||||
String action = intent.getAction();
|
||||
if (action == null || action.isEmpty()) return;
|
||||
|
||||
if (action.equals(Intent.ACTION_TIME_TICK)) {
|
||||
//系统每1分钟发送一次广播
|
||||
updateTimeUi();
|
||||
} else if (action.equals(Intent.ACTION_TIME_CHANGED)) {
|
||||
//系统手动更改时间发送广播
|
||||
updateTimeUi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTimeUi() {
|
||||
// long time = System.currentTimeMillis();
|
||||
// SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
|
||||
// String timeText = timeFormat.format(time);
|
||||
// tv_flashlight.setText(timeText);
|
||||
// SimpleDateFormat format = new SimpleDateFormat("MM月dd日");
|
||||
// String dataText = format.format(time);
|
||||
// tv_flashlight_switch.setText(dataText);
|
||||
}
|
||||
|
||||
private void getFlashlight() {
|
||||
if (mTimeUpdateReceiver == null) {
|
||||
mTimeUpdateReceiver = new TimeUpdateReceiver();
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_TIME_TICK);
|
||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
mContext. registerReceiver(mTimeUpdateReceiver, filter);
|
||||
updateTimeUi();
|
||||
// if (isFlashlightAvailable()) {
|
||||
// tv_flashlight_switch.setText("关");
|
||||
// cl_flashlight.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
// } else {
|
||||
// tv_flashlight_switch.setText("不可用");
|
||||
// cl_flashlight.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
// return;
|
||||
// }
|
||||
//// if (isFlashlightEnabled()) {
|
||||
//// tv_flashlight_switch.setText("开");
|
||||
//// cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
//// } else {
|
||||
//// tv_flashlight_switch.setText("关");
|
||||
//// cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
//// }
|
||||
//
|
||||
// cameraManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
|
||||
//
|
||||
// cl_flashlight.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// if (flashing) {
|
||||
// try {
|
||||
// String CameraId = cameraManager.getCameraIdList()[0];
|
||||
// cameraManager.setTorchMode(CameraId, false);
|
||||
// } catch (CameraAccessException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// flashing = false;
|
||||
// tv_flashlight_switch.setText("关");
|
||||
// cl_flashlight.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
// } else {
|
||||
// try {
|
||||
// String CameraId = cameraManager.getCameraIdList()[0];
|
||||
// cameraManager.setTorchMode(CameraId, true);
|
||||
// } catch (CameraAccessException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// tv_flashlight_switch.setText("开");
|
||||
// cl_flashlight.setBackground(mContext.getDrawable(R.drawable.control_background_item));
|
||||
// flashing = true;
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
private boolean isFlashlightAvailable() {
|
||||
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
|
||||
}
|
||||
|
||||
private static String getCameraId(Context context) throws CameraAccessException {
|
||||
final CameraManager cameraManager = context.getSystemService(CameraManager.class);
|
||||
final String[] ids = cameraManager.getCameraIdList();
|
||||
for (String id : ids) {
|
||||
CameraCharacteristics c = cameraManager.getCameraCharacteristics(id);
|
||||
Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
|
||||
Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING);
|
||||
if (flashAvailable != null && flashAvailable
|
||||
&& lensFacing != null && lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// private boolean isFlashlightEnabled() {
|
||||
// return Settings.Secure.getInt(crv, Settings.Secure.FLASHLIGHT_ENABLED, 0) == 1;
|
||||
// }
|
||||
|
||||
private void getFontSize() {
|
||||
float fontScale = Settings.System.getFloat(mCRv, Settings.System.FONT_SCALE, 0.0f);
|
||||
Log.e(TAG, "getHardware: fontScale = " + fontScale);
|
||||
List<String> mEntries = Arrays.asList(getResources().getStringArray(R.array.entries_font_size));
|
||||
List<String> strEntryValues = Arrays.asList(getResources().getStringArray(R.array.entryvalues_font_size));
|
||||
seekBar.setMax(mEntries.size() - 1);
|
||||
String font_size;
|
||||
int index = strEntryValues.indexOf(String.valueOf(fontScale));
|
||||
if (index == -1) {
|
||||
font_size = "默认";
|
||||
} else {
|
||||
font_size = mEntries.get(index);
|
||||
}
|
||||
// tv_font_size.setText(font_size);
|
||||
seekBar.setProgress(index);
|
||||
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||
Settings.System.putFloat(mCRv, Settings.System.FONT_SCALE, Float.parseFloat(strEntryValues.get(i)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getLocation() {
|
||||
String addr = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE).decodeString(CommonConfig.MAP_ADDRESS_KEY);
|
||||
|
||||
if (TextUtils.isEmpty(addr) || "nullnull".equals(addr) || "null".equals(addr)) {
|
||||
tv_location.setText("未能获取到位置信息");
|
||||
} else {
|
||||
tv_location.setText(addr);
|
||||
}
|
||||
cl_location.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
RemoteManager.getInstance().getLocation();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getBrightness() {
|
||||
seekbar_brightness.setMax(255);
|
||||
//亮度
|
||||
int brightness = Settings.System.getInt(mCRv, Settings.System.SCREEN_BRIGHTNESS, 1);
|
||||
seekbar_brightness.setProgress(brightness);
|
||||
Log.e(TAG, "getHardware: brightness = " + brightness);
|
||||
int gamma = BrightnessUtils.convertLinearToGamma(brightness, 1, 255);
|
||||
Log.e(TAG, "getHardware: gamma = " + gamma);
|
||||
long percentage = Math.round((((double) gamma / 65535) * 100f));
|
||||
// tv_brightness.setText(percentage + "%");
|
||||
Log.e(TAG, "getHardware: percentage = " + percentage);
|
||||
seekbar_brightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||
Log.e(TAG, "onProgressChanged: i = " + i);
|
||||
RemoteManager.getInstance().putSystemInt(Settings.System.SCREEN_BRIGHTNESS, i);
|
||||
int gamma = BrightnessUtils.convertLinearToGamma(i, 1, 255);
|
||||
Log.e(TAG, "onProgressChanged: gamma = " + gamma);
|
||||
long percentage = Math.round((((double) gamma / 65535) * 100f));
|
||||
Log.e(TAG, "onProgressChanged: percentage = " + percentage);
|
||||
// tv_brightness.setText(percentage + "%");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
private void getSound() {
|
||||
mAudioManager = (AudioManager)mContext. getSystemService(Context.AUDIO_SERVICE);
|
||||
//最大音量
|
||||
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
seekbar_sound.setMax(maxVolume);
|
||||
Log.e(TAG, "getHardware: maxVolume = " + maxVolume);
|
||||
//音量
|
||||
int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
seekbar_sound.setProgress(streamVolume);
|
||||
Log.e(TAG, "getHardware: streamVolume = " + streamVolume);
|
||||
int currentVolume = (int) (((double) streamVolume / (double) maxVolume) * 100f);
|
||||
Log.e(TAG, "getHardware: currentVolume = " + currentVolume);
|
||||
tv_sound.setText(currentVolume + "%");
|
||||
seekbar_sound.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||
int volume = (int) (((double) i / (double) maxVolume) * 100f);
|
||||
tv_sound.setText(volume + "%");
|
||||
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, i, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mWifiReceiver != null)mContext. unregisterReceiver(mWifiReceiver);
|
||||
if (mTimeUpdateReceiver != null) mContext.unregisterReceiver(mTimeUpdateReceiver);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.uiuios.aios.fragment.home;
|
||||
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
import com.uiuios.aios.bean.DesktopIcon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class HomeContact {
|
||||
public interface Presenter extends BasePresenter<PrecisionView> {
|
||||
void getInstalledApp();
|
||||
}
|
||||
|
||||
public interface PrecisionView extends BaseView {
|
||||
void setInstalledApp( ArrayList<DesktopIcon> desktopIcons);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,632 @@
|
||||
package com.uiuios.aios.fragment.home;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
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.WeatherDailyBean;
|
||||
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.uiuios.aios.BuildConfig;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.EmergencyActivity;
|
||||
import com.uiuios.aios.activity.alarm.AlarmClockActivity;
|
||||
import com.uiuios.aios.activity.contact.ContactActivity;
|
||||
import com.uiuios.aios.activity.weather.WeatherActivity;
|
||||
import com.uiuios.aios.activity.weather.WeatherPresenter;
|
||||
import com.uiuios.aios.adapter.HomeAppAdapter;
|
||||
import com.uiuios.aios.adapter.NotificationAdapter;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.base.BaseFragment;
|
||||
import com.uiuios.aios.bean.AlarmItem;
|
||||
import com.uiuios.aios.bean.Contact;
|
||||
import com.uiuios.aios.bean.DesktopIcon;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.dialog.SingleDialog;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.push.PushManager;
|
||||
import com.uiuios.aios.utils.ApkUtils;
|
||||
import com.uiuios.aios.utils.AppUtil;
|
||||
import com.uiuios.aios.view.RecyclerViewSpacesItemDecoration;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link HomeFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class HomeFragment extends BaseFragment implements HomeContact.PrecisionView {
|
||||
private static final String TAG = HomeFragment.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.cl_weather)
|
||||
ConstraintLayout cl_weather;
|
||||
@BindView(R.id.cl_app)
|
||||
ConstraintLayout cl_app;
|
||||
@BindView(R.id.cl_space)
|
||||
ConstraintLayout cl_space;
|
||||
@BindView(R.id.cl_health)
|
||||
ConstraintLayout cl_health;
|
||||
@BindView(R.id.cl_alarmclock)
|
||||
ConstraintLayout cl_alarmclock;
|
||||
@BindView(R.id.cl_clear)
|
||||
ConstraintLayout cl_clear;
|
||||
@BindView(R.id.cl_sos)
|
||||
ConstraintLayout cl_sos;
|
||||
@BindView(R.id.cl_contact)
|
||||
ConstraintLayout cl_contact;
|
||||
@BindView(R.id.cl_appstore)
|
||||
ConstraintLayout cl_appstore;
|
||||
|
||||
@BindView(R.id.tv_time)
|
||||
TextView tv_time;
|
||||
@BindView(R.id.tv_location)
|
||||
TextView tv_location;
|
||||
@BindView(R.id.tv_data)
|
||||
TextView tv_data;
|
||||
@BindView(R.id.iv_pic)
|
||||
ImageView iv_pic;
|
||||
@BindView(R.id.tv_temp)
|
||||
TextView tv_temp;
|
||||
@BindView(R.id.tv_weather)
|
||||
TextView tv_weather;
|
||||
@BindView(R.id.cpv)
|
||||
CircleProgressView cpv;
|
||||
@BindView(R.id.rv_noti)
|
||||
RecyclerView rv_noti;
|
||||
@BindView(R.id.iv_note_nodata)
|
||||
ImageView iv_note_nodata;
|
||||
@BindView(R.id.rv_app)
|
||||
RecyclerView rv_app;
|
||||
@BindView(R.id.iv_nodata)
|
||||
ImageView iv_nodata;
|
||||
|
||||
private View rootView;
|
||||
private FragmentActivity mContext;
|
||||
private HomePresenter mHomePresenter;
|
||||
private HomeAppAdapter mHomeAppAdapter;
|
||||
private List<AlarmItem> alarmItemList;
|
||||
private NotificationAdapter notificationAdapter;
|
||||
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private int[] mShaderColors = new int[]{0xFF05d192, 0xFF05d192, 0xFF05d192, 0xFF05d192, 0xFF05d192, 0xFF05d192, 0xFF05d192};
|
||||
private int[] mShaderColorsRed = new int[]{0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000};
|
||||
|
||||
// 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 HomeFragment() {
|
||||
// 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 HomeFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static HomeFragment newInstance(String param1, String param2) {
|
||||
HomeFragment fragment = new HomeFragment();
|
||||
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 void fetchData() {
|
||||
getAlarmClock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
Log.e(TAG, "onCreateView: ");
|
||||
if (null != rootView) {
|
||||
ViewGroup parent = (ViewGroup) rootView.getParent();
|
||||
if (null != parent) {
|
||||
parent.removeView(rootView);
|
||||
}
|
||||
} else { // 如ongoing果rootView为空 ,就实例化该视图
|
||||
rootView = inflater.inflate(R.layout.fragment_home, container, false);
|
||||
mContext = (FragmentActivity) rootView.getContext();
|
||||
mHomePresenter = new HomePresenter(mContext);
|
||||
mHomePresenter.attachView(this);
|
||||
mHomePresenter.setLifecycle(lifecycleSubject);
|
||||
ButterKnife.bind(this, rootView);
|
||||
initView();
|
||||
|
||||
}
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
initAmap();
|
||||
setTiem();
|
||||
refreshMemory();
|
||||
|
||||
registerTimeReceiver();
|
||||
registerAlarmClockReceiver();
|
||||
|
||||
notificationAdapter = new NotificationAdapter();
|
||||
notificationAdapter.setOnClickListener(new NotificationAdapter.OnClickListener() {
|
||||
@Override
|
||||
public void onClick() {
|
||||
getAlarm();
|
||||
}
|
||||
});
|
||||
rv_noti.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getAlarm();
|
||||
}
|
||||
});
|
||||
rv_noti.setLayoutManager(new LinearLayoutManager(mContext));
|
||||
rv_noti.setAdapter(notificationAdapter);
|
||||
|
||||
rv_app.setLayoutManager(new GridLayoutManager(mContext, 3));
|
||||
HashMap<String, Integer> stringIntegerHashMap = new HashMap<>();
|
||||
WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getRealMetrics(dm);
|
||||
float density = dm.density; // 屏幕密度(0.75 / 1.0 / 1.5)
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.TOP_DECORATION, (int) (density * 4));//top间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.BOTTOM_DECORATION, (int) (density * 40));//底部间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.LEFT_DECORATION, (int) (density * 4));//左间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.RIGHT_DECORATION, (int) (density * 4));//右间距
|
||||
rv_app.addItemDecoration(new RecyclerViewSpacesItemDecoration(stringIntegerHashMap));
|
||||
mHomeAppAdapter = new HomeAppAdapter();
|
||||
rv_app.setAdapter(mHomeAppAdapter);
|
||||
|
||||
cl_weather.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(mContext, WeatherActivity.class));
|
||||
}
|
||||
});
|
||||
cl_app.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
cl_space.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ApkUtils.openPackage(mContext, "com.uiui.videoplayer", "com.uiui.videoplayer.activity.main.MainActivity");
|
||||
}
|
||||
});
|
||||
|
||||
cl_health.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
cl_alarmclock.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
cl_clear.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
killBackgroundApp();
|
||||
}
|
||||
});
|
||||
cl_sos.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
checkSosNumber();
|
||||
}
|
||||
});
|
||||
cl_contact.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(mContext, ContactActivity.class));
|
||||
}
|
||||
});
|
||||
cl_appstore.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ApkUtils.openPackage(mContext, "com.uiui.videoplayer", "com.uiui.videoplayer.activity.main.MainActivity");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Log.e(TAG, "onResume: " );
|
||||
mHomePresenter.getInstalledApp();
|
||||
}
|
||||
|
||||
//监听时间和日期变化
|
||||
public void registerTimeReceiver() {
|
||||
mTimeChangedReceiver = new TimeChangedReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(Intent.ACTION_DATE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIME_TICK);
|
||||
mContext.registerReceiver(mTimeChangedReceiver, filter);
|
||||
}
|
||||
|
||||
private TimeChangedReceiver mTimeChangedReceiver;
|
||||
|
||||
@Override
|
||||
public void setInstalledApp(ArrayList<DesktopIcon> desktopIcons) {
|
||||
Log.e(TAG, "setInstalledApp: " + desktopIcons);
|
||||
if (desktopIcons == null || desktopIcons.size() == 0) {
|
||||
iv_nodata.setVisibility(View.VISIBLE);
|
||||
rv_app.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
iv_nodata.setVisibility(View.GONE);
|
||||
rv_app.setVisibility(View.VISIBLE);
|
||||
mHomeAppAdapter.setDesktopIcons(desktopIcons);
|
||||
}
|
||||
}
|
||||
|
||||
private class TimeChangedReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Intent.ACTION_DATE_CHANGED.equals(intent.getAction())) {
|
||||
Log.e(TAG, "TimeChangedReceiver:" + "data changed");
|
||||
} else if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) {
|
||||
Log.e(TAG, "TimeChangedReceiver:" + "time changed");
|
||||
} else if (Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
|
||||
Log.e(TAG, "TimeChangedReceiver:" + "timezone changed");
|
||||
} else if (Intent.ACTION_TIME_TICK.equals(intent.getAction())) {
|
||||
Log.e(TAG, "TimeChangedReceiver:" + "time tick");
|
||||
}
|
||||
setTiem();
|
||||
}
|
||||
}
|
||||
|
||||
private void registerAlarmClockReceiver() {
|
||||
if (null == mAlarmClockReceiver) {
|
||||
mAlarmClockReceiver = new AlarmClockReceiver();
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(PushManager.SET_ALARMCLOCK);
|
||||
mContext.registerReceiver(mAlarmClockReceiver, filter);
|
||||
}
|
||||
|
||||
private AlarmClockReceiver mAlarmClockReceiver;
|
||||
|
||||
private class AlarmClockReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Log.e(TAG, "onReceive: " + action);
|
||||
if (PushManager.SET_ALARMCLOCK.equals(action)) {
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getAlarmClock();
|
||||
}
|
||||
}, 3456);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getAlarm() {
|
||||
startActivity(new Intent(mContext, AlarmClockActivity.class));
|
||||
}
|
||||
|
||||
private void checkSosNumber() {
|
||||
NetInterfaceManager.getInstance().getContactList(new NetInterfaceManager.ContactCallback() {
|
||||
@Override
|
||||
public void setContact(List<Contact> contactList) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEmergencyContact(List<Contact> emergencyContact) {
|
||||
if (emergencyContact == null || emergencyContact.size() == 0) {
|
||||
showNoData("温馨提示", "请在小程序上面设置紧急联系人");
|
||||
} else {
|
||||
Intent intent = new Intent(mContext, EmergencyActivity.class);
|
||||
// intent.putExtra("setting_sos", phone);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEmpty() {
|
||||
showNoData("温馨提示", "请在小程序上面设置紧急联系人");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showNoData(String title, String msg) {
|
||||
SingleDialog dialog = new SingleDialog(mContext);
|
||||
dialog.setTitle(title)
|
||||
.setMessage(msg)
|
||||
.setPositive("确定")
|
||||
.setOnClickBottomListener(new SingleDialog.OnClickBottomListener() {
|
||||
@Override
|
||||
public void onPositiveClick() {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
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) {
|
||||
RemoteManager.getInstance().killBackgroundProcesses(packageName);
|
||||
}
|
||||
|
||||
private void refreshMemory() {
|
||||
long avail = AppUtil.getAvailMemory(mContext);
|
||||
long total = AppUtil.getTotalMemory(mContext);
|
||||
int x = (int) (((total - avail) / (double) total) * 100);
|
||||
if (x > 80) {
|
||||
cpv.setProgressColor(mShaderColorsRed);
|
||||
} else {
|
||||
cpv.setProgressColor(mShaderColors);
|
||||
}
|
||||
cpv.showAnimation(0, x, 1000);
|
||||
float x2 = (((total - avail) / (float) total));
|
||||
}
|
||||
|
||||
private void setTiem() {
|
||||
long time = System.currentTimeMillis();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
||||
Date date = new Date(time);
|
||||
tv_time.setText(sdf.format(date));
|
||||
SimpleDateFormat sdf2 = new SimpleDateFormat("MM月-dd日");
|
||||
Date date2 = new Date(time);
|
||||
tv_data.setText(sdf2.format(date2) + "\t" + getWeek());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 根据日期取得星期几
|
||||
*/
|
||||
public static String getWeek() {
|
||||
Date date = new Date();
|
||||
String[] weeks = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(date);
|
||||
int weekIndex = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
if (weekIndex < 0) {
|
||||
weekIndex = 0;
|
||||
}
|
||||
return weeks[weekIndex];
|
||||
}
|
||||
|
||||
private void initAmap() {
|
||||
String city = RemoteManager.getInstance().getCity();
|
||||
tv_location.setText(city);
|
||||
getweather(RemoteManager.getInstance().getLongitude(), RemoteManager.getInstance().getLatitude());
|
||||
}
|
||||
|
||||
|
||||
private boolean isnight() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = calendar.get(Calendar.MINUTE);
|
||||
int second = calendar.get(Calendar.SECOND);
|
||||
return hour >= 16 && minute >= 30;
|
||||
}
|
||||
|
||||
private String nowString;
|
||||
|
||||
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(mContext, 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", mContext.getPackageName());
|
||||
// iv_pic.setImageDrawable(mContext.getDrawable(resId));
|
||||
nowString = now.getText();
|
||||
tv_temp.setText(now.getTemp() + "℃");
|
||||
tv_weather.setText(now.getText());
|
||||
String iconDay = weatherBean.getNow().getIcon();
|
||||
Log.e("getweather", "onSuccess: iconDay = " + iconDay);
|
||||
switch (iconDay) {
|
||||
case "100":
|
||||
case "150":
|
||||
case "102":
|
||||
case "152":
|
||||
if (isnight()) {
|
||||
// cl_weather.setBackground(ContextCompat.getDrawable(mContext, R.drawable.background_weather_sun));
|
||||
} else {
|
||||
// cl_weather.setBackground(ContextCompat.getDrawable(mContext, R.drawable.background_weather_sun_night));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// cl_weather.setBackground(ContextCompat.getDrawable(mContext, R.drawable.background_weather_rain));
|
||||
}
|
||||
} else {
|
||||
//在此查看返回数据失败的原因
|
||||
Code code = weatherBean.getCode();
|
||||
Log.d("getWeatherNow", "failed code: " + code);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
QWeather.getWeather24Hourly(mContext, 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", mContext.getPackageName());
|
||||
Log.e(TAG, "onSuccess: " + resId);
|
||||
if (resId == 0) {
|
||||
iv_pic.setImageDrawable(mContext.getDrawable(R.drawable.he100));
|
||||
} else {
|
||||
iv_pic.setImageDrawable(mContext.getDrawable(resId));
|
||||
}
|
||||
tv_temp.setText(now.getTemp() + "℃");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//在此查看返回数据失败的原因
|
||||
Code code = weatherHourlyBean.getCode();
|
||||
Log.e("getWeather24Hourly", "failed code: " + code);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
QWeather.getWeather7D(mContext, location, new QWeather.OnResultWeatherDailyListener() {
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
Log.e("getWeather", "onError: " + throwable.getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WeatherDailyBean weatherDailyBean) {
|
||||
String jsonString = new Gson().toJson(weatherDailyBean);
|
||||
Log.d("getWeather", "onSuccess: " + jsonString);
|
||||
mMMKV.encode(WeatherPresenter.WEATHER_DAILY_KEY, jsonString);
|
||||
List<WeatherDailyBean.DailyBean> dailyBeans = weatherDailyBean.getDaily();
|
||||
if (dailyBeans != null && dailyBeans.size() != 0) {
|
||||
WeatherDailyBean.DailyBean dailyBean = weatherDailyBean.getDaily().get(0);
|
||||
tv_weather.setText(nowString + "\t" + dailyBean.getTempMin() + "℃ - " + dailyBean.getTempMax() + "℃");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getAlarmClock() {
|
||||
NetInterfaceManager.getInstance().getAlarmClock(new NetInterfaceManager.AlarmClockCallback() {
|
||||
@Override
|
||||
public void setAlarmClock(List<AlarmClockData> alarmClockList) {
|
||||
AlarmClockData alarmClockData = AlarmUtils.getInstance().getRecentAlarmClock();
|
||||
List<AlarmClockData> data = new ArrayList<>();
|
||||
if (alarmClockData != null) {
|
||||
data.add(alarmClockData);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmClockEmpty() {
|
||||
rv_noti.setVisibility(View.GONE);
|
||||
iv_note_nodata.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.uiuios.aios.fragment.home;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.trello.rxlifecycle4.android.FragmentEvent;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.bean.DesktopIcon;
|
||||
import com.uiuios.aios.manager.AppManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
public class HomePresenter implements HomeContact.Presenter {
|
||||
private static final String TAG = HomePresenter.class.getSimpleName();
|
||||
private Context mContext;
|
||||
private HomeContact.PrecisionView mView;
|
||||
|
||||
public HomePresenter(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
private BehaviorSubject<FragmentEvent> lifecycle;
|
||||
|
||||
void setLifecycle(BehaviorSubject<FragmentEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<FragmentEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(@NonNull HomeContact.PrecisionView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getInstalledApp() {
|
||||
ArrayList<DesktopIcon> desktopIcons = AppManager.getInstance().getAddDesktopIcon();
|
||||
// DesktopIcon updateDesktopIcon = new DesktopIcon();
|
||||
// updateDesktopIcon.setLable("应用更新");
|
||||
// updateDesktopIcon.setPackageName(AppManager.UPDATE_NAME);
|
||||
// updateDesktopIcon.setIcon(mContext.getDrawable(R.drawable.icon_update));
|
||||
// desktopIcons.add(desktopIcons.size(), updateDesktopIcon);
|
||||
|
||||
DesktopIcon desktopIcon = new DesktopIcon();
|
||||
desktopIcon.setLable("添加应用");
|
||||
desktopIcon.setPackageName(AppManager.ADD_NAME);
|
||||
desktopIcon.setIcon(mContext.getDrawable(R.drawable.home_icon_add));
|
||||
desktopIcons.add(desktopIcons.size(), desktopIcon);
|
||||
|
||||
mView.setInstalledApp(desktopIcons);
|
||||
}
|
||||
}
|
||||
295
app/src/main/java/com/uiuios/aios/manager/AppManager.java
Normal file
295
app/src/main/java/com/uiuios/aios/manager/AppManager.java
Normal file
@@ -0,0 +1,295 @@
|
||||
package com.uiuios.aios.manager;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiuios.aios.bean.DesktopIcon;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.utils.ApkUtils;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AppManager {
|
||||
private static final String TAG = AppManager.class.getSimpleName();
|
||||
|
||||
public static final String ADD_NAME = "com.zyos.add";
|
||||
public static final String UPDATE_NAME = "com.zyos.update";
|
||||
private static final String SHOW_PACKAGE_KEY = "SHOW_PACKAGE_KEY";
|
||||
private static final String ADD_PACKAGE_KEY = "ADD_PACKAGE_KEY";
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static AppManager sInstance;
|
||||
private Context mContext;
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
private Set<String> showPackages;
|
||||
private Set<String> addPackages;
|
||||
|
||||
public static void init(Context context) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("context is NULL");
|
||||
}
|
||||
if (sInstance == null) {
|
||||
Log.e(TAG, "init: ");
|
||||
sInstance = new AppManager(context);
|
||||
}
|
||||
}
|
||||
|
||||
public AppManager(Context context) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("Context is NULL");
|
||||
}
|
||||
this.mContext = context;
|
||||
this.showPackages = mMMKV.decodeStringSet(SHOW_PACKAGE_KEY, new HashSet<>());
|
||||
this.addPackages = mMMKV.decodeStringSet(ADD_PACKAGE_KEY, new HashSet<>());
|
||||
this.showPackages.removeIf(TextUtils::isEmpty);
|
||||
}
|
||||
|
||||
public static AppManager getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init AppManager first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void addPakcage(String packageName) {
|
||||
this.showPackages.add(packageName);
|
||||
mMMKV.encode(SHOW_PACKAGE_KEY, showPackages);
|
||||
}
|
||||
|
||||
public void removePakcage(String packageName) {
|
||||
this.showPackages.remove(packageName);
|
||||
mMMKV.encode(SHOW_PACKAGE_KEY, showPackages);
|
||||
}
|
||||
|
||||
public Set<String> getFilterAppset() {
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
// 查询所有已经安装的应用程序
|
||||
List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
|
||||
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
|
||||
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
|
||||
// 通过getPackageManager()的queryIntentActivities方法遍历,得到所有能打开的app的packageName
|
||||
List<ResolveInfo> resolveinfoList = pm.queryIntentActivities(resolveIntent, 0);
|
||||
Set<String> allowPackages = resolveinfoList.stream().map(resolveInfo -> resolveInfo.activityInfo.packageName).collect(Collectors.toSet());
|
||||
|
||||
// List<String> adminApp = RemoteManager.getInstance().getAdminApp();
|
||||
// Log.i(TAG, "queryFilterAppInfo: adminapp = " + adminApp);
|
||||
for (ResolveInfo resolveInfo : resolveinfoList) {
|
||||
String pkg = resolveInfo.activityInfo.packageName;
|
||||
if (ApkUtils.appIsDisable(mContext, pkg)) {
|
||||
Log.e(TAG, "queryFilterAppInfo: disable = " + pkg);
|
||||
continue;
|
||||
}
|
||||
if (showPackages.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
} else {
|
||||
//通过flag排除系统应用,会将电话、短信也排除掉
|
||||
if (ApkUtils.isSystemApp(mContext, pkg)) {
|
||||
if (ApkUtils.showPackageName.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
}
|
||||
} else {
|
||||
if (allowPackages.contains(pkg) && !ApkUtils.excludePackageName.contains(pkg)) {
|
||||
// if (adminApp.contains(pkg)) {
|
||||
// resolveInfos.add(resolveInfo);
|
||||
// } else if (ApkUtils.showPackageName.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Settings.Global.getInt(mContext.getContentResolver(), "is_activity", 0) == 0) {
|
||||
resolveInfos.removeIf(resolveInfo -> "com.uiui.city".equals(resolveInfo.activityInfo.packageName));
|
||||
}
|
||||
Set<String> desktopIcons = resolveInfos.stream().map(resolveInfo -> resolveInfo.activityInfo.packageName).collect(Collectors.toSet());
|
||||
return desktopIcons;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<DesktopIcon> getFilterAppList() {
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
// 查询所有已经安装的应用程序
|
||||
List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
|
||||
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
|
||||
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
|
||||
// 通过getPackageManager()的queryIntentActivities方法遍历,得到所有能打开的app的packageName
|
||||
List<ResolveInfo> resolveinfoList = pm.queryIntentActivities(resolveIntent, 0);
|
||||
Set<String> allowPackages = resolveinfoList.stream().map(resolveInfo -> resolveInfo.activityInfo.packageName).collect(Collectors.toSet());
|
||||
|
||||
|
||||
// List<String> adminApp = RemoteManager.getInstance().getAdminApp();
|
||||
// Log.i(TAG, "queryFilterAppInfo: adminapp = " + adminApp);
|
||||
for (ResolveInfo resolveInfo : resolveinfoList) {
|
||||
String pkg = resolveInfo.activityInfo.packageName;
|
||||
if (ApkUtils.appIsDisable(mContext, pkg)) {
|
||||
Log.e(TAG, "queryFilterAppInfo: disable = " + pkg);
|
||||
continue;
|
||||
}
|
||||
if (showPackages.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
} else {
|
||||
//通过flag排除系统应用,会将电话、短信也排除掉
|
||||
if (ApkUtils.isSystemApp(mContext, pkg)) {
|
||||
if (ApkUtils.showPackageName.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
}
|
||||
} else {
|
||||
if (allowPackages.contains(pkg) && !ApkUtils.excludePackageName.contains(pkg)) {
|
||||
// if (adminApp.contains(pkg)) {
|
||||
// resolveInfos.add(resolveInfo);
|
||||
// } else if (ApkUtils.showPackageName.contains(pkg)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Settings.Global.getInt(mContext.getContentResolver(), "is_activity", 0) == 0) {
|
||||
resolveInfos.removeIf(resolveInfo -> "com.uiui.city".equals(resolveInfo.activityInfo.packageName));
|
||||
}
|
||||
resolveInfos.sort(new Comparator<ResolveInfo>() {
|
||||
@Override
|
||||
public int compare(ResolveInfo o1, ResolveInfo o2) {
|
||||
return Collator.getInstance(Locale.CHINESE).compare(o1.loadLabel(pm).toString(), o2.loadLabel(pm).toString());
|
||||
}
|
||||
});
|
||||
resolveInfos.sort(new Comparator<ResolveInfo>() {
|
||||
@Override
|
||||
public int compare(ResolveInfo o1, ResolveInfo o2) {
|
||||
try {
|
||||
if ((pm.getApplicationInfo(o1.activityInfo.packageName, 0).flags & ApplicationInfo.FLAG_SYSTEM) <= (pm.getApplicationInfo(o2.activityInfo.packageName, 0).flags & ApplicationInfo.FLAG_SYSTEM)) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
ArrayList<DesktopIcon> desktopIcons = new ArrayList<>();
|
||||
for (ResolveInfo applicationInfo : resolveInfos) {
|
||||
if (!ApkUtils.excludeClassName.contains(applicationInfo.activityInfo.name)) {
|
||||
desktopIcons.add(DesktopIcon.creatDesktopIcon(mContext, applicationInfo));
|
||||
}
|
||||
}
|
||||
return desktopIcons;
|
||||
}
|
||||
|
||||
public ArrayList<DesktopIcon> getAllAppList() {
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
// 查询所有已经安装的应用程序
|
||||
List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
|
||||
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
|
||||
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
|
||||
// 通过getPackageManager()的queryIntentActivities方法遍历,得到所有能打开的app的packageName
|
||||
List<ResolveInfo> resolveinfoList = pm.queryIntentActivities(resolveIntent, 0);
|
||||
Set<String> allowPackages = resolveinfoList.stream().map(resolveInfo -> resolveInfo.activityInfo.packageName).collect(Collectors.toSet());
|
||||
|
||||
|
||||
// List<String> adminApp = RemoteManager.getInstance().getAdminApp();
|
||||
// Log.i(TAG, "queryFilterAppInfo: adminapp = " + adminApp);
|
||||
for (ResolveInfo resolveInfo : resolveinfoList) {
|
||||
String pkg = resolveInfo.activityInfo.packageName;
|
||||
if (ApkUtils.appIsDisable(mContext, pkg)) {
|
||||
Log.e(TAG, "queryFilterAppInfo: disable = " + pkg);
|
||||
continue;
|
||||
}
|
||||
if (ApkUtils.excludePackageName.contains(pkg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
resolveInfos.add(resolveInfo);
|
||||
}
|
||||
if (Settings.Global.getInt(mContext.getContentResolver(), "is_activity", 0) == 0) {
|
||||
resolveInfos.removeIf(resolveInfo -> "com.uiui.city".equals(resolveInfo.activityInfo.packageName));
|
||||
}
|
||||
resolveInfos.sort(new Comparator<ResolveInfo>() {
|
||||
@Override
|
||||
public int compare(ResolveInfo o1, ResolveInfo o2) {
|
||||
return Collator.getInstance(Locale.CHINESE).compare(o1.loadLabel(pm).toString(), o2.loadLabel(pm).toString());
|
||||
}
|
||||
});
|
||||
// resolveInfos.sort(new Comparator<ResolveInfo>() {
|
||||
// @Override
|
||||
// public int compare(ResolveInfo o1, ResolveInfo o2) {
|
||||
// try {
|
||||
// if ((pm.getApplicationInfo(o1.activityInfo.packageName, 0).flags & ApplicationInfo.FLAG_SYSTEM) <= (pm.getApplicationInfo(o2.activityInfo.packageName, 0).flags & ApplicationInfo.FLAG_SYSTEM)) {
|
||||
// return 1;
|
||||
// } else {
|
||||
// return -1;
|
||||
// }
|
||||
// } catch (PackageManager.NameNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
ArrayList<DesktopIcon> desktopIcons = new ArrayList<>();
|
||||
for (ResolveInfo applicationInfo : resolveInfos) {
|
||||
desktopIcons.add(DesktopIcon.creatDesktopIcon(mContext, applicationInfo));
|
||||
}
|
||||
return desktopIcons;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<DesktopIcon> getAddDesktopIcon() {
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
// 查询所有已经安装的应用程序
|
||||
List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
|
||||
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
|
||||
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
|
||||
// 通过getPackageManager()的queryIntentActivities方法遍历,得到所有能打开的app的packageName
|
||||
List<ResolveInfo> resolveinfoList = pm.queryIntentActivities(resolveIntent, 0);
|
||||
for (ResolveInfo resolveInfo : resolveinfoList) {
|
||||
if (addPackages.contains(resolveInfo.activityInfo.packageName)) {
|
||||
resolveInfos.add(resolveInfo);
|
||||
}
|
||||
}
|
||||
ArrayList<DesktopIcon> desktopIcons = new ArrayList<>();
|
||||
for (ResolveInfo applicationInfo : resolveInfos) {
|
||||
desktopIcons.add(DesktopIcon.creatDesktopIcon(mContext, applicationInfo));
|
||||
}
|
||||
return desktopIcons;
|
||||
}
|
||||
|
||||
public void addAddPakcage(String packageName) {
|
||||
this.addPackages.add(packageName);
|
||||
mMMKV.encode(ADD_PACKAGE_KEY, addPackages);
|
||||
}
|
||||
|
||||
public void removeAddPakcage(String packageName) {
|
||||
this.addPackages.remove(packageName);
|
||||
mMMKV.encode(ADD_PACKAGE_KEY, addPackages);
|
||||
}
|
||||
|
||||
public Set<String> getAddPackages() {
|
||||
Set<String> stringSet = mMMKV.decodeStringSet(ADD_PACKAGE_KEY, new HashSet<>());
|
||||
return stringSet;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,6 @@ public class RemoteManager {
|
||||
|
||||
private static final String SN_KEY = "sn_serial_key";
|
||||
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static RemoteManager sInstance;
|
||||
private Context mContext;
|
||||
|
||||
@@ -44,7 +44,7 @@ import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
|
||||
public class ApkUtils {
|
||||
private static HashSet<String> excludePackageName = new HashSet<String>() {{
|
||||
public static HashSet<String> excludePackageName = new HashSet<String>() {{
|
||||
this.add(BuildConfig.APPLICATION_ID);
|
||||
this.add("org.chromium.browser");
|
||||
this.add("com.sprd.sprdnote");
|
||||
@@ -67,11 +67,11 @@ public class ApkUtils {
|
||||
this.add("com.teclast.zybrowser");
|
||||
}};
|
||||
|
||||
private static HashSet<String> excludeClassName = new HashSet<String>() {{
|
||||
public static HashSet<String> excludeClassName = new HashSet<String>() {{
|
||||
this.add("com.android.dialer.app.calllog.CallLogActivity");
|
||||
}};
|
||||
|
||||
private static HashSet<String> showPackageName = new HashSet<String>() {{
|
||||
public static HashSet<String> showPackageName = new HashSet<String>() {{
|
||||
this.add("com.uiuios.sn");
|
||||
this.add("com.uiuios.browser");
|
||||
// this.add("com.uiuios.appstore");
|
||||
@@ -271,7 +271,7 @@ public class ApkUtils {
|
||||
return (applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0;
|
||||
}
|
||||
|
||||
private static boolean appIsDisable(Context context, String pkg) {
|
||||
public static boolean appIsDisable(Context context, String pkg) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
return pm.getApplicationEnabledSetting(pkg) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
|
||||
}
|
||||
@@ -361,8 +361,13 @@ public class ApkUtils {
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
if (context != null) {
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "openPackage: " + e.getMessage());
|
||||
ToastUtil.show("应用未安装");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user