version:1.9
fix: update:修改包名,添加推送
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package com.uiui.aios.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
||||
import com.uiui.aios.R;
|
||||
import com.uiui.aios.adapter.APPListAdapter;
|
||||
import com.uiui.aios.base.BaseActivity;
|
||||
import com.uiui.aios.bean.AppListInfo;
|
||||
import com.uiui.aios.utils.ApkUtils;
|
||||
import com.uiui.aios.utils.BitmapUtils;
|
||||
import com.uiui.aios.view.RecyclerViewSpacesItemDecoration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class APPListActivity extends BaseActivity {
|
||||
private ImageView back;
|
||||
private RecyclerView mRecyclerView;
|
||||
private APPListAdapter adapter;
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_applist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
back = findViewById(R.id.iv_back);
|
||||
back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
mRecyclerView = findViewById(R.id.recyclerview);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
List<ApplicationInfo> applicationInfoList = ApkUtils.getSystemApp(APPListActivity.this);
|
||||
PackageManager pm = getPackageManager();
|
||||
if (null != applicationInfoList) {
|
||||
List<AppListInfo> appinfoList = new ArrayList<>();
|
||||
for (ApplicationInfo applicationInfo : applicationInfoList) {
|
||||
AppListInfo info = new AppListInfo(
|
||||
applicationInfo.loadLabel(pm).toString(),
|
||||
applicationInfo.packageName,
|
||||
BitmapUtils.getIconBitmap(APPListActivity.this, applicationInfo.loadIcon(pm))
|
||||
);
|
||||
appinfoList.add(info);
|
||||
}
|
||||
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)
|
||||
int orientation = 0;
|
||||
orientation = getResources().getConfiguration().orientation;
|
||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.TOP_DECORATION, (int) (density * 16));//top间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.BOTTOM_DECORATION, (int) (density * 32));//top间距
|
||||
} else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.TOP_DECORATION, (int) (density * 50));//top间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.BOTTOM_DECORATION, (int) (density * 100));//top间距
|
||||
}
|
||||
// stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.TOP_DECORATION, (int) (density * 40));//top间距
|
||||
// stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.BOTTOM_DECORATION, (int) (density * 20));//底部间距
|
||||
// stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.LEFT_DECORATION, (int) (density * 20));//左间距
|
||||
// stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.RIGHT_DECORATION, (int) (density * 20));//右间距
|
||||
adapter = new APPListAdapter(APPListActivity.this);
|
||||
mRecyclerView.setLayoutManager(new GridLayoutManager(APPListActivity.this, 3));
|
||||
// rv_list.addItemDecoration(new RecyclerItemDecoration(10, 10, 4));
|
||||
mRecyclerView.addItemDecoration(new RecyclerViewSpacesItemDecoration(stringIntegerHashMap));
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
adapter.setAppListInfos(appinfoList);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
121
app/src/main/java/com/uiui/aios/activity/CodeActivity.java
Normal file
121
app/src/main/java/com/uiui/aios/activity/CodeActivity.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package com.uiui.aios.activity;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiui.aios.R;
|
||||
import com.uiui.aios.adapter.HealthCodeAdapter;
|
||||
import com.uiui.aios.base.BaseActivity;
|
||||
import com.uiui.aios.bean.BaseResponse;
|
||||
import com.uiui.aios.bean.HealthCode;
|
||||
import com.uiui.aios.network.NetInterfaceManager;
|
||||
import com.uiui.aios.utils.Utils;
|
||||
import com.uiui.aios.view.ScaleCircleNavigator;
|
||||
|
||||
import net.lucode.hackware.magicindicator.MagicIndicator;
|
||||
import net.lucode.hackware.magicindicator.ViewPagerHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
|
||||
public class CodeActivity extends BaseActivity {
|
||||
@BindView(R.id.viewPager)
|
||||
ViewPager mViewPager;
|
||||
@BindView(R.id.magicIndicator)
|
||||
MagicIndicator mMagicIndicator;
|
||||
|
||||
private HealthCodeAdapter mHealthCodeAdapter;
|
||||
private ScaleCircleNavigator scaleCircleNavigator;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mHealthCodeAdapter = new HealthCodeAdapter();
|
||||
mViewPager.setAdapter(mHealthCodeAdapter);
|
||||
scaleCircleNavigator = new ScaleCircleNavigator(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
getHealthCode();
|
||||
}
|
||||
|
||||
private void setImageViews(List<HealthCode> healthCodes) {
|
||||
mMagicIndicator.setNavigator(scaleCircleNavigator);
|
||||
scaleCircleNavigator.setCircleCount(healthCodes.size());
|
||||
scaleCircleNavigator.setNormalCircleColor(Color.DKGRAY);
|
||||
scaleCircleNavigator.setSelectedCircleColor(Color.LTGRAY);
|
||||
scaleCircleNavigator.setCircleClickListener(new ScaleCircleNavigator.OnCircleClickListener() {
|
||||
@Override
|
||||
public void onClick(int index) {
|
||||
|
||||
}
|
||||
});
|
||||
ViewPagerHelper.bind(mMagicIndicator, mViewPager);
|
||||
List<ImageView> imageViews = new ArrayList<>();
|
||||
for (HealthCode healthCode : healthCodes) {
|
||||
ImageView image = new ImageView(this);
|
||||
image.setAdjustViewBounds(true);
|
||||
image.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
Glide.with(this).load(healthCode.getImg()).into(image);
|
||||
imageViews.add(image);
|
||||
}
|
||||
mHealthCodeAdapter.setImageViews(imageViews);
|
||||
mHealthCodeAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
private void getHealthCode() {
|
||||
NetInterfaceManager.getInstance().getHealthCodeApi()
|
||||
.getArticleDetails(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<HealthCode>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getHealthCode", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<HealthCode>> listBaseResponse) {
|
||||
Log.e("getHealthCode", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<HealthCode> healthCodeList = listBaseResponse.data;
|
||||
setImageViews(healthCodeList);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getHealthCode", "onError: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getHealthCode", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
227
app/src/main/java/com/uiui/aios/activity/EmergencyActivity.java
Normal file
227
app/src/main/java/com/uiui/aios/activity/EmergencyActivity.java
Normal file
@@ -0,0 +1,227 @@
|
||||
package com.uiui.aios.activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.uiui.aios.R;
|
||||
import com.uiui.aios.bean.BaseResponse;
|
||||
import com.uiui.aios.network.NetInterfaceManager;
|
||||
import com.uiui.aios.receiver.BootReceiver;
|
||||
import com.uiui.aios.utils.ToastUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
|
||||
public class EmergencyActivity extends AppCompatActivity {
|
||||
@BindView(R.id.tv_countdown)
|
||||
TextView tv_countdown;
|
||||
@BindView(R.id.iv_finish)
|
||||
ImageView iv_finish;
|
||||
private Disposable subscribe;
|
||||
private String TAG = EmergencyActivity.class.getSimpleName();
|
||||
private boolean needDial = false;
|
||||
private boolean isCalling = false;
|
||||
private List<String> phoneListSet;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Log.e(TAG, "onCreate: ");
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_emergency);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
//发送紧急广播
|
||||
Intent bootIntent = new Intent(BootReceiver.SOS);
|
||||
bootIntent.setComponent(new ComponentName("com.uiui.sn", "com.uiui.sn.receiver.BootReceiver"));
|
||||
sendBroadcast(bootIntent);
|
||||
|
||||
Intent intent = getIntent();
|
||||
// String setting_sos = intent.getStringExtra("setting_sos");
|
||||
// if (TextUtils.isEmpty(setting_sos)) {
|
||||
// finish();
|
||||
// return;
|
||||
// }
|
||||
|
||||
String setting_sos = Settings.System.getString(getContentResolver(), "setting_sos");
|
||||
if (TextUtils.isEmpty(setting_sos)) return;
|
||||
phoneListSet = new ArrayList<>(Arrays.asList(setting_sos.split(",")));
|
||||
Log.e(TAG, "onCreate: " + phoneListSet);
|
||||
|
||||
final Long time = 3L;
|
||||
subscribe = Observable.interval(1, TimeUnit.SECONDS)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(aLong -> {
|
||||
Log.e("TAG", "倒计时:" + aLong);
|
||||
if (aLong < time && !subscribe.isDisposed()) {
|
||||
tv_countdown.setText("倒计时(" + (time - aLong - 1) + ")秒");
|
||||
Log.e(TAG, "accept: " + (time - aLong - 1));
|
||||
} else {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getSOSRecordObservable()
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("SOSRecordApi", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("SOSRecordApi", "onNext: " + baseResponse);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("SOSRecordApi", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("SOSRecordApi", "onComplete: ");
|
||||
}
|
||||
});
|
||||
needDial = true;
|
||||
Intent intent1 = new Intent(Intent.ACTION_CALL);
|
||||
Uri data = Uri.parse("tel:" + phoneListSet.get(0));
|
||||
intent1.setData(data);
|
||||
startActivity(intent1);
|
||||
isCalling = true;
|
||||
phoneListSet.remove(0);
|
||||
// finish();
|
||||
subscribe.dispose();
|
||||
}
|
||||
});
|
||||
iv_finish.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
// TelephonyManager telM = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
|
||||
// telM.listen(new PhoneStateListener() {
|
||||
// /**
|
||||
// * 当有精确通话状态时回调
|
||||
// * Callback invoked when precise device call state changes
|
||||
// * @hide 隐藏api, 给系统app使用的
|
||||
// */
|
||||
// public void onPreciseCallStateChanged(PreciseCallState callState) {
|
||||
// //当有精确通话状态时回调
|
||||
// Log.e(TAG, "onPreciseCallStateChanged: " + callState);
|
||||
// }
|
||||
// }, PhoneStateListener.LISTEN_PRECISE_CALL_STATE); //需要权限android.permission.READ_PRECISE_PHONE_STATE
|
||||
//
|
||||
// StatusBarManager mStatusBarManager = (StatusBarManager) getApplicationContext().getSystemService(Context.STATUS_BAR_SERVICE);
|
||||
//// mStatusBarManager.disable(StatusBarManager.DISABLE_HOME);//隐藏home键
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
Log.e(TAG, "onResume: ");
|
||||
Log.e(TAG, "onResume: " + phoneListSet);
|
||||
if (needDial) {
|
||||
if (phoneListSet == null || phoneListSet.size() == 0) return;
|
||||
Handler.getMain().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent intent1 = new Intent(Intent.ACTION_CALL);
|
||||
Uri data = Uri.parse("tel:" + phoneListSet.get(0));
|
||||
intent1.setData(data);
|
||||
startActivity(intent1);
|
||||
isCalling = true;
|
||||
phoneListSet.remove(0);
|
||||
}
|
||||
}, 2000);
|
||||
} else {
|
||||
if (phoneListSet == null) {
|
||||
ToastUtil.show("没有设置紧急联系人");
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.e(TAG, "onDestroy: ");
|
||||
if (subscribe != null) {
|
||||
subscribe.dispose();
|
||||
subscribe = null;
|
||||
}
|
||||
}
|
||||
|
||||
// class MobileCallReceiver extends BroadcastReceiver {
|
||||
// @Override
|
||||
// public void onReceive(Context context, Intent intent) {
|
||||
// if (intent.getAction() == null) {
|
||||
// return;
|
||||
// }
|
||||
//// switch (intent.getAction()) {
|
||||
//// case CustomAction.PRECISE_CALL_STATE:
|
||||
//// int callState = intent.getIntExtra("foreground_state", -2);
|
||||
//// switch (callState) {
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_IDLE:
|
||||
//// Log.d(TAG, "IDLE");
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_DIALING:
|
||||
//// Log.d(TAG, "DIALING");
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_ALERTING:
|
||||
//// Log.d(TAG, "ALERTING isHandFree=" + isHandFree);
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_ACTIVE:
|
||||
//// Log.d(TAG, "ACTIVE");
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_INCOMING:
|
||||
//// Log.d(TAG, "INCOMING来电");
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_DISCONNECTING:
|
||||
//// Log.d(TAG, "DISCONNECTING");
|
||||
//// break;
|
||||
//// case PreciseCallState.PRECISE_CALL_STATE_DISCONNECTED:
|
||||
//// Log.d(TAG, "DISCONNECTED");
|
||||
//// break;
|
||||
//// }
|
||||
//// break;
|
||||
//// case TelephonyManager.ACTION_PHONE_STATE_CHANGED:
|
||||
//// break;
|
||||
//// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 精确的九大通话状态
|
||||
// public class PreciseCallState {
|
||||
// public static final int PRECISE_CALL_STATE_IDLE = 0; //通话空闲
|
||||
// public static final int PRECISE_CALL_STATE_ACTIVE = 1; //正在通话(活动中)
|
||||
// public static final int PRECISE_CALL_STATE_HOLDING = 2; //通话挂起(例如我和多个人通话,其中一个通话在活动,而其它通话就会进入挂起状态)
|
||||
// public static final int PRECISE_CALL_STATE_DIALING = 3; //拨号开始
|
||||
// public static final int PRECISE_CALL_STATE_ALERTING = 4; //正在呼出(提醒对方接电话)
|
||||
// public static final int PRECISE_CALL_STATE_INCOMING = 5; //对方来电
|
||||
// public static final int PRECISE_CALL_STATE_WAITING = 6; //第三方来电等待(例如我正在和某人通话,而其他人打入时就会就进入等待状态)
|
||||
// public static final int PRECISE_CALL_STATE_DISCONNECTED = 7; //挂断完成
|
||||
// public static final int PRECISE_CALL_STATE_DISCONNECTING = 8; //正在挂断
|
||||
// }
|
||||
}
|
||||
200
app/src/main/java/com/uiui/aios/activity/NoticeActivity.java
Normal file
200
app/src/main/java/com/uiui/aios/activity/NoticeActivity.java
Normal file
@@ -0,0 +1,200 @@
|
||||
package com.uiui.aios.activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.blankj.utilcode.util.FileUtils;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.uiui.aios.R;
|
||||
import com.uiui.aios.bean.AlarmClockData;
|
||||
import com.uiui.aios.bean.BaseResponse;
|
||||
import com.uiui.aios.network.NetInterfaceManager;
|
||||
import com.uiui.aios.utils.AlarmUtils;
|
||||
import com.uiui.aios.utils.FileUtil;
|
||||
import com.uiui.aios.utils.Utils;
|
||||
import com.uiui.aios.view.JzvdStdAssert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import cn.jzvd.Jzvd;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
public class NoticeActivity extends AppCompatActivity {
|
||||
@BindView(R.id.tv_title)
|
||||
TextView tv_title;
|
||||
@BindView(R.id.bt_ok)
|
||||
Button bt_ok;
|
||||
@BindView(R.id.cl_voice)
|
||||
ConstraintLayout cl_voice;
|
||||
@BindView(R.id.cl_vp)
|
||||
ConstraintLayout cl_vp;
|
||||
@BindView(R.id.jz_video)
|
||||
JzvdStdAssert jz_video;
|
||||
@BindView(R.id.imageView)
|
||||
ImageView imageView;
|
||||
|
||||
private AlarmClockData alarmClockData;
|
||||
int code;
|
||||
private MediaPlayer mediaPlayer;
|
||||
|
||||
private String TAG = NoticeActivity.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_notice);
|
||||
ButterKnife.bind(this);
|
||||
Intent intent = getIntent();
|
||||
code = intent.getIntExtra("id", -1);
|
||||
if (code == -1) {
|
||||
finish();
|
||||
} else {
|
||||
HashMap<Integer, AlarmClockData> oldData = AlarmUtils.getInstance().getOldData();
|
||||
alarmClockData = oldData.get(code);
|
||||
if (alarmClockData == null) {
|
||||
finish();
|
||||
}
|
||||
showData(alarmClockData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void showData(AlarmClockData alarmClockData) {
|
||||
tv_title.setText(alarmClockData.getTitle());
|
||||
bt_ok.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
HashMap<Integer, AlarmClockData> oldData = AlarmUtils.getInstance().getOldData();
|
||||
List<AlarmClockData> data = new ArrayList<>();
|
||||
for (AlarmClockData alarm : oldData.values()) {
|
||||
if (alarm.getId() == code) {
|
||||
alarm.setFinished(true);
|
||||
}
|
||||
data.add(alarm);
|
||||
}
|
||||
AlarmUtils.getInstance().setAlarmString(data);
|
||||
NetInterfaceManager.getInstance()
|
||||
.getUpdateAlarmObservable(alarmClockData.getId())
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("showData", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("showData", "onNext: " + baseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("showData", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("showData", "onComplete: ");
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
String voiceUrl = alarmClockData.getVoice();
|
||||
String voicemd5 = alarmClockData.getVoice_md5();
|
||||
String filePath = alarmClockData.getFile();
|
||||
|
||||
if (!TextUtils.isEmpty(voiceUrl)) {
|
||||
cl_voice.setVisibility(View.VISIBLE);
|
||||
String fileName = Utils.getFileNamefromURL(voiceUrl);
|
||||
File file = new File(Utils.getDownLoadPath(NoticeActivity.this) + fileName);
|
||||
String fileMD5 = FileUtils.getFileMD5ToString(file);
|
||||
// if (!md5.equals(fileMD5)) {
|
||||
// // TODO: 2021/12/16
|
||||
// } else {
|
||||
mediaPlayer = new MediaPlayer();
|
||||
try {
|
||||
// 切歌之前先重置,释放掉之前的资源
|
||||
mediaPlayer.reset();
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
mediaPlayer.setDataSource(fis.getFD());
|
||||
// 设置播放源
|
||||
// mediaPlayer.setDataSource(file.getAbsolutePath());
|
||||
// 开始播放前的准备工作,加载多媒体资源,获取相关信息
|
||||
mediaPlayer.prepare();
|
||||
// 开始播放
|
||||
mediaPlayer.start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "showData: " + e.getMessage());
|
||||
}
|
||||
// }
|
||||
} else {
|
||||
cl_voice.setVisibility(View.GONE);
|
||||
}
|
||||
if (!TextUtils.isEmpty(filePath)) {
|
||||
cl_vp.setVisibility(View.VISIBLE);
|
||||
String fileType = FileUtil.getFileType(filePath);
|
||||
Log.e(TAG, "showData: " + fileType);
|
||||
if (FileUtil.isPictureFile(fileType)) {
|
||||
jz_video.setVisibility(View.GONE);
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
Glide.with(NoticeActivity.this).load(filePath).into(imageView);
|
||||
} else if (FileUtil.isVideoFile(fileType)) {
|
||||
jz_video.setVisibility(View.VISIBLE);
|
||||
imageView.setVisibility(View.GONE);
|
||||
jz_video.setUp(filePath, "");
|
||||
jz_video.startVideo();
|
||||
}
|
||||
} else {
|
||||
cl_vp.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mediaPlayer != null) {
|
||||
if (mediaPlayer.isPlaying()) {
|
||||
mediaPlayer.stop();
|
||||
}
|
||||
mediaPlayer.release();
|
||||
mediaPlayer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (Jzvd.backPress()) {
|
||||
return;
|
||||
}
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
Jzvd.releaseAllVideos();
|
||||
}
|
||||
}
|
||||
349
app/src/main/java/com/uiui/aios/activity/main/MainActivity.java
Normal file
349
app/src/main/java/com/uiui/aios/activity/main/MainActivity.java
Normal file
@@ -0,0 +1,349 @@
|
||||
package com.uiui.aios.activity.main;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.alarmclock.uiui.IAlarmAidlInterface;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.uiui.aios.BuildConfig;
|
||||
import com.uiui.aios.R;
|
||||
import com.uiui.aios.base.BaseActivity;
|
||||
import com.uiui.aios.bean.AlarmItem;
|
||||
import com.uiui.aios.bean.DesktopIcon;
|
||||
import com.uiui.aios.fragment.AppListFragment;
|
||||
import com.uiui.aios.fragment.BaseFragmentPagerAdapter;
|
||||
import com.uiui.aios.fragment.CustomFragment;
|
||||
import com.uiui.aios.fragment.SecondFragment;
|
||||
import com.uiui.aios.utils.ApkUtils;
|
||||
import com.uiui.aios.utils.AppUsedTimeUtils;
|
||||
import com.uiui.aios.view.ScaleCircleNavigator;
|
||||
|
||||
import net.lucode.hackware.magicindicator.MagicIndicator;
|
||||
import net.lucode.hackware.magicindicator.ViewPagerHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
private static String TAG = MainActivity.class.getSimpleName();
|
||||
private MainPresenter mMainPresenter;
|
||||
|
||||
@BindView(R.id.viewPager)
|
||||
ViewPager mViewPager;
|
||||
@BindView(R.id.magicIndicator)
|
||||
MagicIndicator mMagicIndicator;
|
||||
|
||||
private FragmentManager mFragmentManager;
|
||||
private FragmentTransaction mFragmentTransaction;
|
||||
private BaseFragmentPagerAdapter mBaseFragmentPagerAdapter;
|
||||
private List<Fragment> mFragments;
|
||||
private CustomFragment mCustomFragment;
|
||||
private SecondFragment mSecondFragment;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mMainPresenter = new MainPresenter(this);
|
||||
mMainPresenter.attachView(this);
|
||||
mMainPresenter.setLifecycle(lifecycleSubject);
|
||||
|
||||
mFragmentManager = getSupportFragmentManager();
|
||||
mFragmentTransaction = mFragmentManager.beginTransaction();
|
||||
mFragments = new ArrayList<>();
|
||||
mBaseFragmentPagerAdapter = new BaseFragmentPagerAdapter(mFragmentManager, mFragments);
|
||||
// fragmentTransaction.add(R.id.viewPager, appListFragment);
|
||||
// fragmentTransaction.commit();
|
||||
mSecondFragment = new SecondFragment();
|
||||
mFragments.add(mSecondFragment);
|
||||
mCustomFragment = new CustomFragment();
|
||||
mFragments.add(mCustomFragment);
|
||||
|
||||
mMainPresenter.getDesktopLayout();
|
||||
ArrayList<DesktopIcon> desktopIcons = ApkUtils.queryFilterAppInfo(this);
|
||||
|
||||
int x = 0;
|
||||
for (int i = 0; i <= desktopIcons.size(); i++) {
|
||||
if (i != 0 && i % APP_LIST_SIZE == 0) {
|
||||
AppListFragment appListFragment = new AppListFragment();
|
||||
appListFragment.setAppList(new ArrayList<>(desktopIcons.subList(x, i)));
|
||||
mFragments.add(appListFragment);
|
||||
x = i;
|
||||
} else if (i == desktopIcons.size()) {
|
||||
AppListFragment appListFragment = new AppListFragment();
|
||||
mFragments.add(appListFragment);
|
||||
appListFragment.setAppList(new ArrayList<>(desktopIcons.subList(x, i)));
|
||||
}
|
||||
}
|
||||
|
||||
ScaleCircleNavigator scaleCircleNavigator = new ScaleCircleNavigator(this);
|
||||
scaleCircleNavigator.setCircleCount(mFragments.size());
|
||||
scaleCircleNavigator.setNormalCircleColor(Color.DKGRAY);
|
||||
scaleCircleNavigator.setSelectedCircleColor(Color.LTGRAY);
|
||||
scaleCircleNavigator.setCircleClickListener(new ScaleCircleNavigator.OnCircleClickListener() {
|
||||
@Override
|
||||
public void onClick(int index) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
mViewPager.setAdapter(mBaseFragmentPagerAdapter);
|
||||
mMagicIndicator.setNavigator(scaleCircleNavigator);
|
||||
ViewPagerHelper.bind(mMagicIndicator, mViewPager);
|
||||
if (mFragments.size() > 1) {
|
||||
mViewPager.setCurrentItem(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
registmNewAppReceiver();
|
||||
registerSOSNumberReceiver();
|
||||
mAlarmServiceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
Log.e(TAG, "onServiceConnected: ");
|
||||
mIAlarmAidlInterface = IAlarmAidlInterface.Stub.asInterface(service);
|
||||
getAlarmData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
Log.e(TAG, "onServiceDisconnected: ");
|
||||
mIAlarmAidlInterface = null;
|
||||
}
|
||||
};
|
||||
bindAlarmService();
|
||||
}
|
||||
|
||||
private ServiceConnection mAlarmServiceConnection;
|
||||
private IAlarmAidlInterface mIAlarmAidlInterface;
|
||||
|
||||
private void bindAlarmService() {
|
||||
if (mIAlarmAidlInterface == null) {
|
||||
//这是连接aidl服务的代码
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("com.alarmclock.uiui.IAlarmAidlInterface");
|
||||
intent.setPackage("com.alarmclock.uiui");
|
||||
intent.setComponent(new ComponentName("com.alarmclock.uiui", "com.alarmclock.uiui.AIDLAlarmService"));
|
||||
bindService(intent, mAlarmServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void getAlarmData() {
|
||||
if (mIAlarmAidlInterface == null) {
|
||||
bindAlarmService();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String json = mIAlarmAidlInterface.getAlarm();
|
||||
Log.e(TAG, "onServiceConnected: " + json);
|
||||
if ("暂无闹钟".equalsIgnoreCase(json) || TextUtils.isEmpty(json)) {
|
||||
mCustomFragment.setAlarmItem(null);
|
||||
return;
|
||||
}
|
||||
Type type = new TypeToken<List<AlarmItem>>() {
|
||||
}.getType();
|
||||
List<AlarmItem> alarmItem = new Gson().fromJson(json, type);
|
||||
mCustomFragment.setAlarmItem(alarmItem);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private final static int APP_LIST_SIZE = 3 * 4;
|
||||
|
||||
private void addData() {
|
||||
List<Fragment> fragmentList = new ArrayList<>();
|
||||
ArrayList<DesktopIcon> applicationInfoList = ApkUtils.queryFilterAppInfo(this);
|
||||
int x = 0;
|
||||
for (int i = 0; i <= applicationInfoList.size(); i++) {
|
||||
if (i != 0 && i % APP_LIST_SIZE == 0) {
|
||||
AppListFragment appListFragment = new AppListFragment();
|
||||
appListFragment.setAppList(new ArrayList<>(applicationInfoList.subList(x, i)));
|
||||
fragmentList.add(appListFragment);
|
||||
x = i;
|
||||
} else if (i == applicationInfoList.size()) {
|
||||
AppListFragment appListFragment = new AppListFragment();
|
||||
fragmentList.add(appListFragment);
|
||||
appListFragment.setAppList(new ArrayList<>(applicationInfoList.subList(x, i)));
|
||||
}
|
||||
}
|
||||
//从第三个开始改
|
||||
for (int i = 2; i <= fragmentList.size(); i++) {
|
||||
if (mFragments.get(i) != null) {
|
||||
mBaseFragmentPagerAdapter.replaceFragment(i, fragmentList.get(i - 2));
|
||||
mFragments.remove(i);
|
||||
mFragments.add(i, fragmentList.get(i - 2));
|
||||
} else {
|
||||
mBaseFragmentPagerAdapter.addFragment(fragmentList.get(i - 2));
|
||||
mFragments.add(fragmentList.get(i - 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
return false;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
Log.e(TAG, "onNewIntent: " + intent.getAction());
|
||||
String action = intent.getAction();
|
||||
if (TextUtils.isEmpty(action)) {
|
||||
return;
|
||||
}
|
||||
switch (action) {
|
||||
default:
|
||||
break;
|
||||
case Intent.ACTION_MAIN:
|
||||
mViewPager.setCurrentItem(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
AppUsedTimeUtils.getInstance().setAppPackageName(BuildConfig.APPLICATION_ID);
|
||||
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
|
||||
getAlarmData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mMainPresenter.sendRunningInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
super.onRestart();
|
||||
mMainPresenter.sendAPPUsage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
AppUsedTimeUtils.getInstance().setEndTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mMainPresenter.detachView();
|
||||
if (mNewAppReceiver != null) {
|
||||
unregisterReceiver(mNewAppReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
private void registmNewAppReceiver() {
|
||||
mNewAppReceiver = new NewAppReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
||||
filter.addDataScheme("package");
|
||||
registerReceiver(mNewAppReceiver, filter);
|
||||
}
|
||||
|
||||
private NewAppReceiver mNewAppReceiver;
|
||||
|
||||
class NewAppReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Log.e(TAG, "onReceive: " + action);
|
||||
if (Intent.ACTION_PACKAGE_ADDED.equals(action)
|
||||
|| Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
|
||||
addData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SOSNumberReceiver sosNumberReceiver;
|
||||
|
||||
private void registerSOSNumberReceiver() {
|
||||
if (sosNumberReceiver == null) {
|
||||
sosNumberReceiver = new SOSNumberReceiver();
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction("setting_sos");
|
||||
registerReceiver(sosNumberReceiver, filter);
|
||||
}
|
||||
|
||||
class SOSNumberReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.e(TAG, "onReceive: " + intent.getAction());
|
||||
String setting_sos = intent.getStringExtra("setting_sos");
|
||||
if (TextUtils.isEmpty(setting_sos)) return;
|
||||
mCustomFragment.setSosNumber();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDesktopLayoutFinish() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDesktopLayoutFinish() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendAPPUsageFinish() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRunningInfoFinish() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.uiui.aios.activity.main;
|
||||
|
||||
import com.uiui.aios.base.BasePresenter;
|
||||
import com.uiui.aios.base.BaseView;
|
||||
|
||||
public class MainContact {
|
||||
public interface Presenter extends BasePresenter<MainContact.MainView> {
|
||||
/*获取桌面布局*/
|
||||
void getDesktopLayout();
|
||||
/*更新桌面布局*/
|
||||
void updateDesktopLayout();
|
||||
/*上传正在运行的APP*/
|
||||
void sendAPPUsage();
|
||||
/*上传后台运行的APP*/
|
||||
void sendRunningInfo();
|
||||
}
|
||||
|
||||
public interface MainView extends BaseView {
|
||||
void getDesktopLayoutFinish();
|
||||
void updateDesktopLayoutFinish();
|
||||
void sendAPPUsageFinish();
|
||||
void sendRunningInfoFinish();
|
||||
}
|
||||
}
|
||||
169
app/src/main/java/com/uiui/aios/activity/main/MainPresenter.java
Normal file
169
app/src/main/java/com/uiui/aios/activity/main/MainPresenter.java
Normal file
@@ -0,0 +1,169 @@
|
||||
package com.uiui.aios.activity.main;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiui.aios.BuildConfig;
|
||||
import com.uiui.aios.bean.BaseResponse;
|
||||
import com.uiui.aios.bean.NetDesktopIcon;
|
||||
import com.uiui.aios.network.NetInterfaceManager;
|
||||
import com.uiui.aios.utils.ApkUtils;
|
||||
import com.uiui.aios.utils.AppUsedTimeUtils;
|
||||
import com.uiui.aios.utils.Utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
public class MainPresenter implements MainContact.Presenter {
|
||||
private static final String TAG = MainPresenter.class.getSimpleName();
|
||||
private MainContact.MainView mView;
|
||||
private Context mContext;
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
MainPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
Log.e(TAG, "MainPresenter: " + context.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(MainContact.MainView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDesktopLayout() {
|
||||
NetInterfaceManager.getInstance().getDesktopLayoutObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<NetDesktopIcon>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getDesktopLayout", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<NetDesktopIcon>> listBaseResponse) {
|
||||
Log.e("getDesktopLayout", "onNext: " + listBaseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getDesktopLayout", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getDesktopLayout", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDesktopLayout() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendAPPUsage() {
|
||||
AppUsedTimeUtils.getInstance().setEndTime(System.currentTimeMillis());
|
||||
String packagename = AppUsedTimeUtils.getInstance().getAppPackageName();
|
||||
Log.e(TAG, "onRestart packagename == " + packagename);
|
||||
if (!TextUtils.isEmpty(packagename)) {
|
||||
Log.e(TAG, "onRestart: " + ApkUtils.getAppNameByPackage(mContext, packagename));
|
||||
Log.e(TAG, "onRestart: " + packagename);
|
||||
NetInterfaceManager.getInstance().getAppUsageRecordControl()
|
||||
.sendappUsageRecord(Utils.getSerial(),
|
||||
ApkUtils.getAppNameByPackage(mContext, packagename),
|
||||
packagename,
|
||||
AppUsedTimeUtils.getInstance().getStartTime() / 1000,
|
||||
AppUsedTimeUtils.getInstance().getEndTime() / 1000)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("sendAPPUsage", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("sendAPPUsage", "onNext: " + baseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("sendAPPUsage", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("sendAPPUsage", "onComplete: ");
|
||||
mView.sendAPPUsageFinish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Log.e("onRestart", "app = null" + packagename);
|
||||
mView.sendAPPUsageFinish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRunningInfo() {
|
||||
AppUsedTimeUtils.getInstance().setAppPackageName(BuildConfig.APPLICATION_ID);
|
||||
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
|
||||
long time = AppUsedTimeUtils.getInstance().getStartTime();
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("app_package", BuildConfig.APPLICATION_ID);
|
||||
jsonObject.addProperty("version_name", ApkUtils.getAPPVersionName(mContext, BuildConfig.APPLICATION_ID));
|
||||
jsonObject.addProperty("start_time", time / 1000);
|
||||
String jsonString = jsonObject.toString();
|
||||
Log.e(TAG, "sendRunningInfo: " + jsonString);
|
||||
NetInterfaceManager.getInstance()
|
||||
.getRunningAppObservable(jsonString)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("sendRunningInfo", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("sendRunningInfo", "onNext: " + baseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("sendRunningInfo", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("sendRunningInfo", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.uiui.aios.activity.weather;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.qweather.sdk.bean.weather.WeatherDailyBean;
|
||||
import com.uiui.aios.R;
|
||||
import com.uiui.aios.adapter.WeatherDayApdapter;
|
||||
import com.uiui.aios.base.BaseActivity;
|
||||
import com.uiui.aios.view.HorizontalItemDecoration;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class WeatherActivity extends BaseActivity implements WeatherContact.WeatherView {
|
||||
@BindView(R.id.rv_weather)
|
||||
RecyclerView rv_weather;
|
||||
@BindView(R.id.tv_location)
|
||||
TextView tv_location;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
|
||||
private WeatherPresenter mPresenter;
|
||||
private WeatherDayApdapter mWeatherDayApdapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_weather;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mPresenter = new WeatherPresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
||||
Resources resources = getResources();
|
||||
rv_weather.setLayoutManager(linearLayoutManager);
|
||||
rv_weather.addItemDecoration(new HorizontalItemDecoration(30, this));//10表示10dp
|
||||
// rv_weather.setLayoutManager(new GridLayoutManager(this, 3));
|
||||
// rv_weather.addItemDecoration(new RecyclerItemDecoration(ScreenUtils.dp2px(resources, 10), ScreenUtils.dp2px(resources, 10), 3));
|
||||
mWeatherDayApdapter = new WeatherDayApdapter();
|
||||
rv_weather.setAdapter(mWeatherDayApdapter);
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
mPresenter.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocation(String location) {
|
||||
tv_location.setText(location);
|
||||
mPresenter.getWeatherCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeatherCache(WeatherDailyBean weatherCache) {
|
||||
if (weatherCache != null) {
|
||||
mWeatherDayApdapter.setDailyBeans(weatherCache.getDaily());
|
||||
}
|
||||
mPresenter.getWeather();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeather(WeatherDailyBean weather) {
|
||||
if (weather != null) {
|
||||
mWeatherDayApdapter.setDailyBeans(weather.getDaily());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mPresenter.detachView();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.uiui.aios.activity.weather;
|
||||
|
||||
import com.qweather.sdk.bean.weather.WeatherDailyBean;
|
||||
import com.uiui.aios.base.BasePresenter;
|
||||
import com.uiui.aios.base.BaseView;
|
||||
|
||||
public class WeatherContact {
|
||||
public interface Presenter extends BasePresenter<WeatherView> {
|
||||
//获取定位缓存
|
||||
void getLocation();
|
||||
//获取天气缓存
|
||||
void getWeatherCache();
|
||||
//获取天气
|
||||
void getWeather();
|
||||
}
|
||||
|
||||
public interface WeatherView extends BaseView {
|
||||
//设置定位缓存
|
||||
void setLocation(String location);
|
||||
//设置天气缓存
|
||||
void setWeatherCache(WeatherDailyBean weatherCache);
|
||||
//设置天气
|
||||
void setWeather(WeatherDailyBean weather);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.uiui.aios.activity.weather;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.qweather.sdk.bean.weather.WeatherDailyBean;
|
||||
import com.qweather.sdk.view.QWeather;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiui.aios.utils.AmapManager;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
/**
|
||||
* MainActivity和MainService 的 Presenter
|
||||
*
|
||||
* @author jgy02
|
||||
*/
|
||||
public class WeatherPresenter implements WeatherContact.Presenter {
|
||||
private static final String TAG = WeatherPresenter.class.getSimpleName();
|
||||
private static final String WEATHER_DAILY_KEY = "WEATHER_DAILY_JSON_STRING";
|
||||
private WeatherContact.WeatherView mView;
|
||||
private Context mContext;
|
||||
private MMKV mMMKV = MMKV.defaultMMKV();
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
public void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
public WeatherPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
Log.e(TAG, "WeatherPresenter: " + context.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(@NonNull WeatherContact.WeatherView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getLocation() {
|
||||
AMapLocation aMapLocation = AmapManager.getInstance().getNowAMapLocation();
|
||||
String location = "未知";
|
||||
if (aMapLocation != null) {
|
||||
location = aMapLocation.getCity() + "\t" + aMapLocation.getDistrict();
|
||||
}
|
||||
mView.setLocation(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getWeatherCache() {
|
||||
// TODO: 2022/1/21 读取json,反序列化,排序
|
||||
String jsonString = mMMKV.decodeString(WEATHER_DAILY_KEY, "");
|
||||
Type type = new TypeToken<WeatherDailyBean>() {
|
||||
}.getType();
|
||||
WeatherDailyBean weatherDailyBean = new Gson().fromJson(jsonString, type);
|
||||
mView.setWeatherCache(weatherDailyBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getWeather() {
|
||||
QWeather.getWeather7D(mContext, AmapManager.getInstance().getLocation(), new QWeather.OnResultWeatherDailyListener() {
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
Log.e("getWeather", "onError: " + throwable.getMessage());
|
||||
mView.setWeather(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WeatherDailyBean weatherDailyBean) {
|
||||
String jsonString = new Gson().toJson(weatherDailyBean);
|
||||
Log.d("getWeather", "onSuccess: " + jsonString);
|
||||
mMMKV.encode(WEATHER_DAILY_KEY, jsonString);
|
||||
mView.setWeather(weatherDailyBean);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user