sos报告部件重构
This commit is contained in:
parent
7b05d613e4
commit
6378433424
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Feb 16 12:53:20 GMT 2025
|
#Mon Feb 17 03:10:13 GMT 2025
|
||||||
stageCount=2
|
stageCount=2
|
||||||
libraryProject=libappbase
|
libraryProject=libappbase
|
||||||
baseVersion=1.5
|
baseVersion=1.5
|
||||||
publishVersion=1.5.1
|
publishVersion=1.5.1
|
||||||
buildCount=168
|
buildCount=184
|
||||||
baseBetaVersion=1.5.2
|
baseBetaVersion=1.5.2
|
||||||
|
@ -17,6 +17,7 @@ import cc.winboll.studio.libappbase.SOS;
|
|||||||
import cc.winboll.studio.libappbase.SimpleOperateSignalCenterService;
|
import cc.winboll.studio.libappbase.SimpleOperateSignalCenterService;
|
||||||
import cc.winboll.studio.libappbase.widgets.APPSOSReportWidget;
|
import cc.winboll.studio.libappbase.widgets.APPSOSReportWidget;
|
||||||
import com.hjq.toast.ToastUtils;
|
import com.hjq.toast.ToastUtils;
|
||||||
|
import cc.winboll.studio.libappbase.bean.APPSOSBean;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
public void onSOS(View view) {
|
public void onSOS(View view) {
|
||||||
Intent intent = new Intent(this, TestService.class);
|
Intent intent = new Intent(this, TestService.class);
|
||||||
stopService(intent);
|
stopService(intent);
|
||||||
SOS.sosWinBollService(this, TestService.class);
|
SOS.sosWinBollService(this, new APPSOSBean(getPackageName(), TestService.class.getName()));
|
||||||
|
|
||||||
// Intent intentTimeWidget = new Intent(this, TimeWidget.class);
|
// Intent intentTimeWidget = new Intent(this, TimeWidget.class);
|
||||||
// intentTimeWidget.setAction(TimeWidget.UPDATE_TIME_ACTION);
|
// intentTimeWidget.setAction(TimeWidget.UPDATE_TIME_ACTION);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Feb 16 12:53:20 GMT 2025
|
#Mon Feb 17 03:10:13 GMT 2025
|
||||||
stageCount=2
|
stageCount=2
|
||||||
libraryProject=libappbase
|
libraryProject=libappbase
|
||||||
baseVersion=1.5
|
baseVersion=1.5
|
||||||
publishVersion=1.5.1
|
publishVersion=1.5.1
|
||||||
buildCount=168
|
buildCount=184
|
||||||
baseBetaVersion=1.5.2
|
baseBetaVersion=1.5.2
|
||||||
|
@ -11,15 +11,17 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
|
||||||
public class AppUtils {
|
public class AppUtils {
|
||||||
|
|
||||||
public static final String TAG = "AppUtils";
|
public static final String TAG = "AppUtils";
|
||||||
|
|
||||||
public static String getAppNameByPackageName(Context context, String packageName) {
|
public static String getAppNameByPackageName(Context context, String packageName) {
|
||||||
PackageManager packageManager = context.getPackageManager();
|
PackageManager packageManager = context.getPackageManager();
|
||||||
try {
|
try {
|
||||||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
|
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
|
||||||
return (String) packageManager.getApplicationLabel(applicationInfo);
|
return (String) packageManager.getApplicationLabel(applicationInfo);
|
||||||
} catch (NameNotFoundException e) {
|
} catch (NameNotFoundException e) {
|
||||||
e.printStackTrace();
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
return null;
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,18 +7,17 @@ package cc.winboll.studio.libappbase;
|
|||||||
*/
|
*/
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import cc.winboll.studio.libappbase.bean.APPSOSBean;
|
||||||
|
|
||||||
public class SOS {
|
public class SOS {
|
||||||
|
|
||||||
public static final String TAG = "SOS";
|
public static final String TAG = "SOS";
|
||||||
public static final String ACTION_SOS = "cc.winboll.studio.libappbase.WinBoll.ACTION_SOS";
|
public static final String ACTION_SOS = "cc.winboll.studio.libappbase.WinBoll.ACTION_SOS";
|
||||||
|
|
||||||
public static void sosWinBollService(Context context, Class<?> clazz) {
|
public static void sosWinBollService(Context context, APPSOSBean bean) {
|
||||||
Intent intent = new Intent(ACTION_SOS);
|
Intent intent = new Intent(ACTION_SOS);
|
||||||
intent.putExtra("sos", "SOS");
|
intent.putExtra("SOS", "Service");
|
||||||
intent.putExtra("sosPackage", context.getPackageName());
|
intent.putExtra("APPSOSBean", bean.toString());
|
||||||
intent.putExtra("sosCalssType", "Service");
|
|
||||||
intent.putExtra("sosClassName", clazz.getName());
|
|
||||||
String szToPackage = "";
|
String szToPackage = "";
|
||||||
if (GlobalApplication.isDebuging()) {
|
if (GlobalApplication.isDebuging()) {
|
||||||
szToPackage = "cc.winboll.studio.appbase.beta";
|
szToPackage = "cc.winboll.studio.appbase.beta";
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
package cc.winboll.studio.libappbase.bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
|
* @Date 2025/02/17 00:29:29
|
||||||
|
* @Describe APPSOSReportBean
|
||||||
|
*/
|
||||||
|
import android.util.JsonReader;
|
||||||
|
import android.util.JsonWriter;
|
||||||
|
import cc.winboll.studio.libappbase.BaseBean;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class APPSOSBean extends BaseBean {
|
||||||
|
|
||||||
|
public static final String TAG = "APPSOSBean";
|
||||||
|
|
||||||
|
protected String sosPackage;
|
||||||
|
protected String sosClassName;
|
||||||
|
|
||||||
|
public APPSOSBean() {
|
||||||
|
this.sosPackage = "";
|
||||||
|
this.sosClassName = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public APPSOSBean(String sosPackage, String sosClassName) {
|
||||||
|
this.sosPackage = sosPackage;
|
||||||
|
this.sosClassName = sosClassName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSosPackage(String sosPackage) {
|
||||||
|
this.sosPackage = sosPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSosPackage() {
|
||||||
|
return sosPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSosClassName(String sosClassName) {
|
||||||
|
this.sosClassName = sosClassName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSosClassName() {
|
||||||
|
return sosClassName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return APPSOSBean.class.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||||
|
super.writeThisToJsonWriter(jsonWriter);
|
||||||
|
jsonWriter.name("sosPackage").value(getSosPackage());
|
||||||
|
jsonWriter.name("sosClassName").value(getSosClassName());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
||||||
|
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
|
||||||
|
if (name.equals("sosPackage")) {
|
||||||
|
setSosPackage(jsonReader.nextString());
|
||||||
|
} else if (name.equals("sosClassName")) {
|
||||||
|
setSosClassName(jsonReader.nextString());
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||||
|
jsonReader.beginObject();
|
||||||
|
while (jsonReader.hasNext()) {
|
||||||
|
String name = jsonReader.nextName();
|
||||||
|
if (!initObjectsFromJsonReader(jsonReader, name)) {
|
||||||
|
jsonReader.skipValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 结束 JSON 对象
|
||||||
|
jsonReader.endObject();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package cc.winboll.studio.libappbase.bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
|
* @Date 2025/02/17 10:05:09
|
||||||
|
* @Describe APPSOSReportBean
|
||||||
|
*/
|
||||||
|
import android.util.JsonReader;
|
||||||
|
import android.util.JsonWriter;
|
||||||
|
import cc.winboll.studio.libappbase.BaseBean;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class APPSOSReportBean extends BaseBean {
|
||||||
|
|
||||||
|
public static final String TAG = "APPSOSReportBean";
|
||||||
|
|
||||||
|
protected String sosReport;
|
||||||
|
|
||||||
|
public APPSOSReportBean() {
|
||||||
|
this.sosReport = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public APPSOSReportBean(String sosReport) {
|
||||||
|
this.sosReport = sosReport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSosReport(String sosReport) {
|
||||||
|
this.sosReport = sosReport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSosReport() {
|
||||||
|
return sosReport;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return APPSOSReportBean.class.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||||
|
super.writeThisToJsonWriter(jsonWriter);
|
||||||
|
jsonWriter.name("sosReport").value(getSosReport());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
||||||
|
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
|
||||||
|
if (name.equals("sosReport")) {
|
||||||
|
setSosReport(jsonReader.nextString());
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||||
|
jsonReader.beginObject();
|
||||||
|
while (jsonReader.hasNext()) {
|
||||||
|
String name = jsonReader.nextName();
|
||||||
|
if (!initObjectsFromJsonReader(jsonReader, name)) {
|
||||||
|
jsonReader.skipValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 结束 JSON 对象
|
||||||
|
jsonReader.endObject();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,11 @@ import cc.winboll.studio.libappbase.LogUtils;
|
|||||||
import cc.winboll.studio.libappbase.WinBoll;
|
import cc.winboll.studio.libappbase.WinBoll;
|
||||||
import cc.winboll.studio.libappbase.AppUtils;
|
import cc.winboll.studio.libappbase.AppUtils;
|
||||||
import cc.winboll.studio.libappbase.widgets.APPSOSReportWidget;
|
import cc.winboll.studio.libappbase.widgets.APPSOSReportWidget;
|
||||||
|
import cc.winboll.studio.libappbase.bean.APPSOSBean;
|
||||||
|
import java.io.IOException;
|
||||||
|
import cc.winboll.studio.libappbase.bean.APPSOSReportBean;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen@AliYun.Com
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
@ -25,30 +30,44 @@ public class WinBollReceiver extends BroadcastReceiver {
|
|||||||
if (action.equals(WinBoll.ACTION_SOS)) {
|
if (action.equals(WinBoll.ACTION_SOS)) {
|
||||||
LogUtils.d(TAG, String.format("context.getPackageName() %s", context.getPackageName()));
|
LogUtils.d(TAG, String.format("context.getPackageName() %s", context.getPackageName()));
|
||||||
LogUtils.d(TAG, String.format("action %s", action));
|
LogUtils.d(TAG, String.format("action %s", action));
|
||||||
String sos = intent.getStringExtra("sos");
|
String SOS = intent.getStringExtra("SOS");
|
||||||
LogUtils.d(TAG, String.format("sos %s", sos));
|
LogUtils.d(TAG, String.format("SOS %s", SOS));
|
||||||
if (sos != null && sos.equals("SOS")) {
|
if (SOS != null && SOS.equals("Service")) {
|
||||||
String sosCalssType = intent.getStringExtra("sosCalssType");
|
String szAPPSOSBean = intent.getStringExtra("APPSOSBean");
|
||||||
LogUtils.d(TAG, String.format("sosCalssType %s", sosCalssType));
|
LogUtils.d(TAG, String.format("szAPPSOSBean %s", szAPPSOSBean));
|
||||||
if (sosCalssType != null && sosCalssType.equals("Service")) {
|
if (szAPPSOSBean != null) {
|
||||||
String sosPackage = intent.getStringExtra("sosPackage");
|
try {
|
||||||
LogUtils.d(TAG, String.format("sosPackage %s", sosPackage));
|
APPSOSBean bean = APPSOSBean.parseStringToBean(szAPPSOSBean, APPSOSBean.class);
|
||||||
|
if (bean != null) {
|
||||||
|
String sosPackage = bean.getSosPackage();
|
||||||
|
LogUtils.d(TAG, String.format("sosPackage %s", sosPackage));
|
||||||
|
String sosClassName = bean.getSosClassName();
|
||||||
|
LogUtils.d(TAG, String.format("sosClassName %s", sosClassName));
|
||||||
|
|
||||||
String sosClassName = intent.getStringExtra("sosClassName");
|
Intent intentService = new Intent();
|
||||||
LogUtils.d(TAG, String.format("sosClassName %s", sosClassName));
|
intentService.setComponent(new ComponentName(sosPackage, sosClassName));
|
||||||
|
context.startService(intentService);
|
||||||
|
|
||||||
Intent intentService = new Intent();
|
String appName = AppUtils.getAppNameByPackageName(context, sosPackage);
|
||||||
intentService.setComponent(new ComponentName(sosPackage, sosClassName));
|
LogUtils.d(TAG, String.format("appName %s", appName));
|
||||||
context.startService(intentService);
|
APPSOSReportBean appSOSReportBean = new APPSOSReportBean(appName);
|
||||||
LogUtils.d(TAG, String.format("context.startService(intentService);"));
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
String currentTime = sdf.format(new Date());
|
||||||
String appName = AppUtils.getAppNameByPackageName(context, sosPackage);
|
StringBuilder sbLine = new StringBuilder();
|
||||||
LogUtils.d(TAG, String.format("appName %s", appName));
|
sbLine.append("[");
|
||||||
Intent intentAPPSOSReportWidget = new Intent(context, APPSOSReportWidget.class);
|
sbLine.append(currentTime);
|
||||||
intentAPPSOSReportWidget.setAction(APPSOSReportWidget.ACTION_ADD_SOS_REPORT);
|
sbLine.append("] Power to ");
|
||||||
intentAPPSOSReportWidget.putExtra("appName", appName);
|
sbLine.append(appName);
|
||||||
context.sendBroadcast(intentAPPSOSReportWidget);
|
appSOSReportBean.setSosReport(sbLine.toString());
|
||||||
|
|
||||||
|
Intent intentAPPSOSReportWidget = new Intent(context, APPSOSReportWidget.class);
|
||||||
|
intentAPPSOSReportWidget.setAction(APPSOSReportWidget.ACTION_ADD_SOS_REPORT);
|
||||||
|
intentAPPSOSReportWidget.putExtra("APPSOSReportBean", appSOSReportBean.toString());
|
||||||
|
context.sendBroadcast(intentAPPSOSReportWidget);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ import cc.winboll.studio.libappbase.R;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import cc.winboll.studio.libappbase.bean.APPSOSReportBean;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class APPSOSReportWidget extends AppWidgetProvider {
|
public class APPSOSReportWidget extends AppWidgetProvider {
|
||||||
|
|
||||||
@ -24,43 +26,76 @@ public class APPSOSReportWidget extends AppWidgetProvider {
|
|||||||
public static final String ACTION_ADD_SOS_REPORT = "cc.winboll.studio.libappbase.widgets.APPSOSReportWidget.ACTION_ADD_SOS_REPORT";
|
public static final String ACTION_ADD_SOS_REPORT = "cc.winboll.studio.libappbase.widgets.APPSOSReportWidget.ACTION_ADD_SOS_REPORT";
|
||||||
public static final String ACTION_RELOAD_SOS_REPORT = "cc.winboll.studio.libappbase.widgets.APPSOSReportWidget.ACTION_RELOAD_SOS_REPORT";
|
public static final String ACTION_RELOAD_SOS_REPORT = "cc.winboll.studio.libappbase.widgets.APPSOSReportWidget.ACTION_RELOAD_SOS_REPORT";
|
||||||
|
|
||||||
volatile static ArrayList<String> _Message;
|
volatile static ArrayList<APPSOSReportBean> _APPSOSReportBeanList;
|
||||||
final static int _MAX_PAGES = 10;
|
final static int _MAX_PAGES = 10;
|
||||||
final static int _OnePageLinesCount = 5;
|
final static int _OnePageLinesCount = 5;
|
||||||
volatile static int _CurrentPageIndex = 0;
|
volatile static int _CurrentPageIndex = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||||
|
initAPPSOSReportBeanList(context);
|
||||||
for (int appWidgetId : appWidgetIds) {
|
for (int appWidgetId : appWidgetIds) {
|
||||||
updateAppWidget(context, appWidgetManager, appWidgetId, "");
|
updateAppWidget(context, appWidgetManager, appWidgetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
super.onReceive(context, intent);
|
super.onReceive(context, intent);
|
||||||
|
initAPPSOSReportBeanList(context);
|
||||||
if (intent.getAction().equals(ACTION_ADD_SOS_REPORT)) {
|
if (intent.getAction().equals(ACTION_ADD_SOS_REPORT)) {
|
||||||
LogUtils.d(TAG, "ACTION_ADD_SOS_REPORT");
|
LogUtils.d(TAG, "ACTION_ADD_SOS_REPORT");
|
||||||
String sosAppName = intent.getStringExtra("appName");
|
String szAPPSOSReportBean = intent.getStringExtra("APPSOSReportBean");
|
||||||
LogUtils.d(TAG, String.format("sosAppName %s", sosAppName));
|
LogUtils.d(TAG, String.format("szAPPSOSBean %s", szAPPSOSReportBean));
|
||||||
|
try {
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
APPSOSReportBean bean = APPSOSReportBean.parseStringToBean(szAPPSOSReportBean, APPSOSReportBean.class);
|
||||||
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, APPSOSReportWidget.class));
|
if (bean != null) {
|
||||||
for (int appWidgetId : appWidgetIds) {
|
addAPPSOSReportBean(context, bean);
|
||||||
updateAppWidget(context, appWidgetManager, appWidgetId, sosAppName);
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
|
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, APPSOSReportWidget.class));
|
||||||
|
for (int appWidgetId : appWidgetIds) {
|
||||||
|
updateAppWidget(context, appWidgetManager, appWidgetId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
}
|
}
|
||||||
} else if (intent.getAction().equals(ACTION_RELOAD_SOS_REPORT)) {
|
} else if (intent.getAction().equals(ACTION_RELOAD_SOS_REPORT)) {
|
||||||
LogUtils.d(TAG, "ACTION_RELOAD_SOS_REPORT");
|
LogUtils.d(TAG, "ACTION_RELOAD_SOS_REPORT");
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, APPSOSReportWidget.class));
|
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, APPSOSReportWidget.class));
|
||||||
for (int appWidgetId : appWidgetIds) {
|
for (int appWidgetId : appWidgetIds) {
|
||||||
updateAppWidget(context, appWidgetManager, appWidgetId, "");
|
updateAppWidget(context, appWidgetManager, appWidgetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, String sosAppName) {
|
//
|
||||||
|
// 加入新报告信息
|
||||||
|
//
|
||||||
|
void addAPPSOSReportBean(Context context, APPSOSReportBean bean) {
|
||||||
|
initAPPSOSReportBeanList(context);
|
||||||
|
_APPSOSReportBeanList.add(0, bean);
|
||||||
|
// 控制记录总数
|
||||||
|
while (_APPSOSReportBeanList.size() > _MAX_PAGES * _OnePageLinesCount) {
|
||||||
|
_APPSOSReportBeanList.remove(_APPSOSReportBeanList.size() - 1);
|
||||||
|
}
|
||||||
|
APPSOSReportBean.saveBeanList(context, _APPSOSReportBeanList, APPSOSReportBean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
void initAPPSOSReportBeanList(Context context) {
|
||||||
|
if (_APPSOSReportBeanList == null) {
|
||||||
|
_APPSOSReportBeanList = new ArrayList<APPSOSReportBean>();
|
||||||
|
APPSOSReportBean.loadBeanList(context, _APPSOSReportBeanList, APPSOSReportBean.class);
|
||||||
|
}
|
||||||
|
if (_APPSOSReportBeanList == null) {
|
||||||
|
_APPSOSReportBeanList = new ArrayList<APPSOSReportBean>();
|
||||||
|
APPSOSReportBean.saveBeanList(context, _APPSOSReportBeanList, APPSOSReportBean.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
|
||||||
LogUtils.d(TAG, "updateAppWidget(...)");
|
LogUtils.d(TAG, "updateAppWidget(...)");
|
||||||
|
|
||||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
|
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
|
||||||
@ -74,24 +109,6 @@ public class APPSOSReportWidget extends AppWidgetProvider {
|
|||||||
PendingIntent pendingIntentNext = PendingIntent.getBroadcast(context, 0, intentNext, PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent pendingIntentNext = PendingIntent.getBroadcast(context, 0, intentNext, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
views.setOnClickPendingIntent(R.id.widget_button_next, pendingIntentNext);
|
views.setOnClickPendingIntent(R.id.widget_button_next, pendingIntentNext);
|
||||||
|
|
||||||
// 加入新消息
|
|
||||||
if (sosAppName != null && !sosAppName.equals("")) {
|
|
||||||
if (_Message == null) {
|
|
||||||
_Message = new ArrayList<String>();
|
|
||||||
}
|
|
||||||
// 获取当前时间并设置到TextView
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
|
||||||
String currentTime = sdf.format(new Date());
|
|
||||||
StringBuilder sbLine = new StringBuilder();
|
|
||||||
sbLine.append("[");
|
|
||||||
sbLine.append(currentTime);
|
|
||||||
sbLine.append("] Power to ");
|
|
||||||
sbLine.append(sosAppName);
|
|
||||||
_Message.add(0, sbLine.toString());
|
|
||||||
while (_Message.size() > _MAX_PAGES * _OnePageLinesCount) { // 控制显示在6行
|
|
||||||
_Message.remove(_Message.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
views.setTextViewText(R.id.infoTextView, getPageInfo());
|
views.setTextViewText(R.id.infoTextView, getPageInfo());
|
||||||
views.setTextViewText(R.id.sosReportTextView, getMessage());
|
views.setTextViewText(R.id.sosReportTextView, getMessage());
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||||
@ -99,11 +116,11 @@ public class APPSOSReportWidget extends AppWidgetProvider {
|
|||||||
|
|
||||||
public static String getMessage() {
|
public static String getMessage() {
|
||||||
ArrayList<String> msgTemp = new ArrayList<String>();
|
ArrayList<String> msgTemp = new ArrayList<String>();
|
||||||
if (_Message != null) {
|
if (_APPSOSReportBeanList != null) {
|
||||||
int start = _OnePageLinesCount * _CurrentPageIndex;
|
int start = _OnePageLinesCount * _CurrentPageIndex;
|
||||||
start = _Message.size() > start ? start : _Message.size() - 1;
|
start = _APPSOSReportBeanList.size() > start ? start : _APPSOSReportBeanList.size() - 1;
|
||||||
for (int i = start, j = 0; i < _Message.size() && j < _OnePageLinesCount; i++, j++) {
|
for (int i = start, j = 0; i < _APPSOSReportBeanList.size() && j < _OnePageLinesCount; i++, j++) {
|
||||||
msgTemp.add(_Message.get(i));
|
msgTemp.add(_APPSOSReportBeanList.get(i).getSosReport());
|
||||||
}
|
}
|
||||||
String message = String.join("\n", msgTemp);
|
String message = String.join("\n", msgTemp);
|
||||||
return message;
|
return message;
|
||||||
@ -112,7 +129,7 @@ public class APPSOSReportWidget extends AppWidgetProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void prePage(Context context) {
|
public static void prePage(Context context) {
|
||||||
if (_Message != null) {
|
if (_APPSOSReportBeanList != null) {
|
||||||
if (_CurrentPageIndex > 0) {
|
if (_CurrentPageIndex > 0) {
|
||||||
_CurrentPageIndex = _CurrentPageIndex - 1;
|
_CurrentPageIndex = _CurrentPageIndex - 1;
|
||||||
}
|
}
|
||||||
@ -123,8 +140,8 @@ public class APPSOSReportWidget extends AppWidgetProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void nextPage(Context context) {
|
public static void nextPage(Context context) {
|
||||||
if (_Message != null) {
|
if (_APPSOSReportBeanList != null) {
|
||||||
if ((_CurrentPageIndex + 1) * _OnePageLinesCount < _Message.size()) {
|
if ((_CurrentPageIndex + 1) * _OnePageLinesCount < _APPSOSReportBeanList.size()) {
|
||||||
_CurrentPageIndex = _CurrentPageIndex + 1;
|
_CurrentPageIndex = _CurrentPageIndex + 1;
|
||||||
}
|
}
|
||||||
Intent intentAPPSOSReportWidget = new Intent(context, APPSOSReportWidget.class);
|
Intent intentAPPSOSReportWidget = new Intent(context, APPSOSReportWidget.class);
|
||||||
@ -134,11 +151,11 @@ public class APPSOSReportWidget extends AppWidgetProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String getPageInfo() {
|
String getPageInfo() {
|
||||||
if (_Message == null) {
|
if (_APPSOSReportBeanList == null) {
|
||||||
return "0/0";
|
return "0/0";
|
||||||
}
|
}
|
||||||
int leftCount = _Message.size() % _OnePageLinesCount;
|
int leftCount = _APPSOSReportBeanList.size() % _OnePageLinesCount;
|
||||||
int currentPageCount = _Message.size() / _OnePageLinesCount + (leftCount == 0 ?0: 1);
|
int currentPageCount = _APPSOSReportBeanList.size() / _OnePageLinesCount + (leftCount == 0 ?0: 1);
|
||||||
return String.format("%d/%d", _CurrentPageIndex + 1, currentPageCount);
|
return String.format("%d/%d", _CurrentPageIndex + 1, currentPageCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user