基本救援设施铺设完成
This commit is contained in:
parent
7a8d3329d4
commit
691f9bbd1c
@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Sat Feb 15 11:51:34 GMT 2025
|
||||
#Sat Feb 15 13:33:01 GMT 2025
|
||||
stageCount=2
|
||||
libraryProject=libappbase
|
||||
baseVersion=1.5
|
||||
publishVersion=1.5.1
|
||||
buildCount=123
|
||||
buildCount=147
|
||||
baseBetaVersion=1.5.2
|
||||
|
@ -60,30 +60,13 @@
|
||||
</intent-filter>
|
||||
|
||||
</receiver>
|
||||
<receiver android:name=".widgets.TimeWidget">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action android:name="com.example.android.UPDATE_TIME" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/appwidget_provider_info" />
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".TimeWidget">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action android:name="com.example.android.UPDATE_TIME" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/appwidget_provider_info" />
|
||||
</receiver>
|
||||
|
||||
|
||||
<meta-data
|
||||
android:name="android.max_aspect"
|
||||
android:value="4.0"/>
|
||||
|
||||
<service android:name="cc.winboll.studio.appbase.services.TestService"
|
||||
android:exported="true"/>
|
||||
|
||||
</application>
|
||||
|
||||
|
@ -9,11 +9,13 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import cc.winboll.studio.appbase.R;
|
||||
import cc.winboll.studio.appbase.services.MainService;
|
||||
import cc.winboll.studio.appbase.services.TestService;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.LogView;
|
||||
import cc.winboll.studio.libappbase.SOS;
|
||||
import cc.winboll.studio.libappbase.SimpleOperateSignalCenterService;
|
||||
import cc.winboll.studio.libappbase.widgets.TimeWidget;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
@ -77,7 +79,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
public void onSOS(View view) {
|
||||
SOS.sosToWinBoll(this);
|
||||
Intent intent = new Intent(this, TestService.class);
|
||||
stopService(intent);
|
||||
SOS.sosWinBollService(this, TestService.class);
|
||||
|
||||
// Intent intentTimeWidget = new Intent(this, TimeWidget.class);
|
||||
// intentTimeWidget.setAction(TimeWidget.UPDATE_TIME_ACTION);
|
||||
// intentTimeWidget.putExtra("appName", "TestName");
|
||||
// sendBroadcast(intentTimeWidget);
|
||||
//
|
||||
}
|
||||
|
||||
// public void sos() {
|
||||
@ -105,6 +115,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
// sendBroadcast(intent);
|
||||
// LogUtils.d(TAG, "onSOS2");
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
package cc.winboll.studio.appbase.services;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen@AliYun.Com
|
||||
* @Date 2025/02/15 20:48:36
|
||||
* @Describe TestService
|
||||
*/
|
||||
public class TestService extends Service {
|
||||
|
||||
public static final String TAG = "TestService";
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
LogUtils.d(TAG, "onCreate()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
LogUtils.d(TAG, "onStartCommand(...)");
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
LogUtils.d(TAG, "onDestroy()");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -4,13 +4,11 @@ package cc.winboll.studio.appbase.threads;
|
||||
* @Author ZhanGSKen@AliYun.Com
|
||||
* @Date 2025/02/14 03:46:44
|
||||
*/
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import cc.winboll.studio.appbase.handlers.MainServiceHandler;
|
||||
import cc.winboll.studio.appbase.widgets.TimeWidget;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.widgets.TimeWidget;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class MainServiceThread extends Thread {
|
||||
@ -44,15 +42,12 @@ public class MainServiceThread extends Thread {
|
||||
|
||||
while (!isExist()) {
|
||||
//ToastUtils.show("run()");
|
||||
//LogUtils.d(TAG, "run()");
|
||||
Intent intent = new Intent(mContext, TimeWidget.class);
|
||||
intent.setAction(TimeWidget.UPDATE_TIME_ACTION);
|
||||
//PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
mContext.sendBroadcast(intent);
|
||||
//AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
|
||||
//long interval = 1000;
|
||||
//alarmManager.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), interval, pendingIntent);
|
||||
|
||||
LogUtils.d(TAG, "run()");
|
||||
Intent intentTimeWidget = new Intent(mContext, TimeWidget.class);
|
||||
intentTimeWidget.setAction(TimeWidget.UPDATE_TIME_ACTION);
|
||||
intentTimeWidget.putExtra("appName", "TestName");
|
||||
mContext.sendBroadcast(intentTimeWidget);
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="#FFFFFFFF">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Button"
|
||||
android:id="@+id/widget_button"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:text="Text"
|
||||
android:id="@+id/timeTextView"
|
||||
android:layout_weight="1.0"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Sat Feb 15 11:51:34 GMT 2025
|
||||
#Sat Feb 15 13:33:01 GMT 2025
|
||||
stageCount=2
|
||||
libraryProject=libappbase
|
||||
baseVersion=1.5
|
||||
publishVersion=1.5.1
|
||||
buildCount=123
|
||||
buildCount=147
|
||||
baseBetaVersion=1.5.2
|
||||
|
@ -40,7 +40,18 @@
|
||||
</intent-filter>
|
||||
|
||||
</receiver>
|
||||
|
||||
|
||||
<receiver android:name=".widgets.TimeWidget"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action android:name="com.example.android.UPDATE_TIME" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/appwidget_provider_info" />
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@ -0,0 +1,26 @@
|
||||
package cc.winboll.studio.libappbase;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen@AliYun.Com
|
||||
* @Date 2025/02/15 20:05:03
|
||||
* @Describe AppUtils
|
||||
*/
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
|
||||
public class AppUtils {
|
||||
public static final String TAG = "AppUtils";
|
||||
public static String getAppNameByPackageName(Context context, String packageName) {
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
try {
|
||||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
|
||||
return (String) packageManager.getApplicationLabel(applicationInfo);
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,14 @@ import android.content.Intent;
|
||||
public class SOS {
|
||||
|
||||
public static final String TAG = "SOS";
|
||||
|
||||
public static void sosToWinBoll(Context context) {
|
||||
Intent intent = new Intent(WinBoll.ACTION_SOS);
|
||||
public static final String ACTION_SOS = "cc.winboll.studio.libappbase.WinBoll.ACTION_SOS";
|
||||
|
||||
public static void sosWinBollService(Context context, Class<?> clazz) {
|
||||
Intent intent = new Intent(ACTION_SOS);
|
||||
intent.putExtra("sos", "SOS");
|
||||
intent.putExtra("sosPackage", context.getPackageName());
|
||||
intent.putExtra("message", "SOS");
|
||||
intent.putExtra("sosCalssType", "Service");
|
||||
intent.putExtra("sosClassName", clazz.getName());
|
||||
String szToPackage = "";
|
||||
if (GlobalApplication.isDebuging()) {
|
||||
szToPackage = "cc.winboll.studio.appbase.beta";
|
||||
@ -24,7 +27,7 @@ public class SOS {
|
||||
}
|
||||
intent.setPackage(szToPackage);
|
||||
context.sendBroadcast(intent);
|
||||
|
||||
|
||||
LogUtils.d(TAG, String.format("SOS Send To WinBoll. (szToPackage : %s)", szToPackage));
|
||||
//ToastUtils.show("SOS Send To WinBoll");
|
||||
}
|
||||
|
@ -93,6 +93,10 @@ public class SimpleOperateSignalCenterService extends Service {
|
||||
super.onCreate();
|
||||
LogUtils.d(TAG, "onCreate");
|
||||
mSimpleOperateSignalCenterServiceBean = SimpleOperateSignalCenterServiceBean.loadBean(this, SimpleOperateSignalCenterServiceBean.class);
|
||||
if(mSimpleOperateSignalCenterServiceBean == null) {
|
||||
mSimpleOperateSignalCenterServiceBean = new SimpleOperateSignalCenterServiceBean();
|
||||
SimpleOperateSignalCenterServiceBean.saveBean(this, mSimpleOperateSignalCenterServiceBean);
|
||||
}
|
||||
runMainThread();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.WinBoll;
|
||||
import cc.winboll.studio.libappbase.AppUtils;
|
||||
import cc.winboll.studio.libappbase.widgets.TimeWidget;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen@AliYun.Com
|
||||
@ -39,6 +41,14 @@ public class WinBollReceiver extends BroadcastReceiver {
|
||||
intentService.setComponent(new ComponentName(sosPackage, sosClassName));
|
||||
context.startService(intentService);
|
||||
LogUtils.d(TAG, String.format("context.startService(intentService);"));
|
||||
|
||||
String appName = AppUtils.getAppNameByPackageName(context, sosPackage);
|
||||
LogUtils.d(TAG, String.format("appName %s", appName));
|
||||
Intent intentTimeWidget = new Intent(context, TimeWidget.class);
|
||||
intentTimeWidget.setAction(TimeWidget.UPDATE_TIME_ACTION);
|
||||
intentTimeWidget.putExtra("appName", appName);
|
||||
context.sendBroadcast(intentTimeWidget);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
package cc.winboll.studio.appbase.widgets;
|
||||
|
||||
package cc.winboll.studio.libappbase.widgets;
|
||||
/**
|
||||
* @Author ZhanGSKen@AliYun.Com
|
||||
* @Date 2025/02/15 14:41:25
|
||||
* @Describe TimeWidget
|
||||
*/
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
@ -13,12 +11,11 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.widget.RemoteViews;
|
||||
import cc.winboll.studio.appbase.R;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.R;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class TimeWidget extends AppWidgetProvider {
|
||||
|
||||
@ -31,7 +28,7 @@ public class TimeWidget extends AppWidgetProvider {
|
||||
@Override
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
for (int appWidgetId : appWidgetIds) {
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId);
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId, "");
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,47 +36,48 @@ public class TimeWidget extends AppWidgetProvider {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
super.onReceive(context, intent);
|
||||
if (intent.getAction().equals(UPDATE_TIME_ACTION)) {
|
||||
|
||||
String sosAppName = intent.getStringExtra("appName");
|
||||
LogUtils.d(TAG, String.format("sosAppName %s", sosAppName));
|
||||
|
||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, TimeWidget.class));
|
||||
for (int appWidgetId : appWidgetIds) {
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId);
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId, sosAppName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
|
||||
if (_Message == null) {
|
||||
_Message = new ArrayList<String>();
|
||||
}
|
||||
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, String sosAppName) {
|
||||
|
||||
LogUtils.d(TAG, "updateAppWidget(...)");
|
||||
|
||||
StringBuilder sbLine = new StringBuilder();
|
||||
// for (int appWidgetId : appWidgetIds) {
|
||||
// RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
|
||||
//
|
||||
|
||||
// appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||
// }
|
||||
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
|
||||
//设置按钮点击事件
|
||||
Intent intent = new Intent(context, WidgetButtonClickListener.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
views.setOnClickPendingIntent(R.id.widget_button, pendingIntent);
|
||||
|
||||
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("]");
|
||||
sbLine.append("] Power to ");
|
||||
sbLine.append(sosAppName);
|
||||
_Message.add(0, sbLine.toString());
|
||||
while(_Message.size() > 6) { // 控制显示在6行
|
||||
while (_Message.size() > 6) { // 控制显示在6行
|
||||
_Message.remove(_Message.size() - 1);
|
||||
}
|
||||
String message = String.join("\n", _Message);
|
||||
views.setTextViewText(R.id.timeTextView, message);
|
||||
if (_Message != null) {
|
||||
String message = String.join("\n", _Message);
|
||||
views.setTextViewText(R.id.timeTextView, message);
|
||||
}
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cc.winboll.studio.appbase.widgets;
|
||||
package cc.winboll.studio.libappbase.widgets;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen@AliYun.Com
|
||||
@ -12,10 +12,10 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.Toast;
|
||||
import cc.winboll.studio.appbase.R;
|
||||
import cc.winboll.studio.libappbase.R;
|
||||
|
||||
public class WidgetButtonClickListener extends BroadcastReceiver {
|
||||
|
||||
|
||||
public static final String TAG = "WidgetButtonClickListener";
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@ -31,4 +31,3 @@ public class WidgetButtonClickListener extends BroadcastReceiver {
|
||||
Toast.makeText(context, "按钮被点击", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
30
libappbase/src/main/res/layout/widget_layout.xml
Normal file
30
libappbase/src/main/res/layout/widget_layout.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="#FFFFFFFF">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Button"
|
||||
android:id="@+id/widget_button"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:id="@+id/timeTextView"
|
||||
android:layout_weight="1.0"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user