mirror of
https://gitea.winboll.cc/ZhanGSKen/MyWinBoLL.git
synced 2026-08-14 05:27:10 +08:00
组合框架应用操作流程响应
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Thu Jul 02 07:36:18 GMT 2026
|
||||
#Thu Jul 02 16:21:25 HKT 2026
|
||||
stageCount=0
|
||||
libraryProject=
|
||||
baseVersion=15.20
|
||||
publishVersion=15.20.0
|
||||
buildCount=22
|
||||
buildCount=28
|
||||
baseBetaVersion=15.20.1
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
<!-- 在后台使用位置信息 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
|
||||
|
||||
<!-- 前台服务 -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package cc.winboll.studio.bytheway;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import cc.winboll.studio.bytheway.activities.SettingsActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@@ -40,6 +42,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
DevelopUtils.inflateMenu(this, menu);
|
||||
}
|
||||
getMenuInflater().inflate(cc.winboll.studio.libaes.R.menu.toolbar_drawerbase, menu);
|
||||
getMenuInflater().inflate(R.menu.activity_main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -48,6 +51,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (AESThemeUtil.onWinBoLLThemeItemSelected(this, item)) {
|
||||
recreate();
|
||||
}
|
||||
if (item.getItemId() == R.id.action_settings) {
|
||||
startActivity(new Intent(this, SettingsActivity.class));
|
||||
return true;
|
||||
}
|
||||
if (DevelopUtils.onDevelopItemSelected(this, item)) {
|
||||
LogUtils.d(TAG, String.format("onOptionsItemSelected item.getItemId() %d ", item.getItemId()));
|
||||
} else {
|
||||
|
||||
@@ -2,22 +2,31 @@ package cc.winboll.studio.bytheway.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
import cc.winboll.studio.bytheway.R;
|
||||
import cc.winboll.studio.bytheway.services.GpsReceiveService;
|
||||
|
||||
/**
|
||||
* @Author 豆包&BigPickle&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/07/02 15:38
|
||||
* @Describe 应用设置窗口
|
||||
*/
|
||||
public class SettingsActivity extends Activity {
|
||||
|
||||
|
||||
public static final String TAG = "SettingsActivity";
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_settings);
|
||||
|
||||
|
||||
Switch swGpsService = findViewById(R.id.sw_gps_service);
|
||||
swGpsService.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
GpsReceiveService.startGpsService(SettingsActivity.this);
|
||||
} else {
|
||||
GpsReceiveService.stopGpsService(SettingsActivity.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
package cc.winboll.studio.bytheway.services;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.widget.Toast;
|
||||
import cc.winboll.studio.bytheway.helpers.GpsDbManager;
|
||||
import cc.winboll.studio.bytheway.models.GpsBean;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
@@ -16,9 +21,11 @@ import cc.winboll.studio.libappbase.LogUtils;
|
||||
* @Describe 动态注册定位广播,接收GPS数据并持久化存入SQLite数据库。单例独占模式,自带重复启动拦截,对外静态统一启停接口
|
||||
*/
|
||||
public class GpsReceiveService extends Service {
|
||||
|
||||
|
||||
public static final String TAG = "GpsReceiveService";
|
||||
|
||||
private static final int NOTIFICATION_ID = 1001;
|
||||
private static final String CHANNEL_ID = "gps_service_channel";
|
||||
|
||||
private static boolean serviceRunning = false;
|
||||
private GpsDbManager dbManager;
|
||||
private BroadcastReceiver gpsBroadcastReceiver;
|
||||
@@ -55,7 +62,27 @@ public class GpsReceiveService extends Service {
|
||||
serviceRunning = true;
|
||||
dbManager = new GpsDbManager(getApplicationContext());
|
||||
registerGpsBroadcast();
|
||||
startForeground(NOTIFICATION_ID, createNotification());
|
||||
LogUtils.i("GpsReceiveService", "GPS接收服务创建完成");
|
||||
Toast.makeText(this, "GPS定位服务已开启", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private Notification createNotification() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(
|
||||
CHANNEL_ID,
|
||||
"GPS定位服务",
|
||||
NotificationManager.IMPORTANCE_LOW
|
||||
);
|
||||
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
manager.createNotificationChannel(channel);
|
||||
}
|
||||
return new Notification.Builder(this, CHANNEL_ID)
|
||||
.setContentTitle("ByTheWay")
|
||||
.setContentText("GPS定位服务运行中")
|
||||
.setSmallIcon(android.R.drawable.ic_menu_mylocation)
|
||||
.setOngoing(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,13 +138,15 @@ public class GpsReceiveService extends Service {
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
stopForeground(true);
|
||||
serviceRunning = false;
|
||||
//反注册广播,防止内存泄漏
|
||||
if (gpsBroadcastReceiver != null) {
|
||||
unregisterReceiver(gpsBroadcastReceiver);
|
||||
}
|
||||
LogUtils.i("GpsReceiveService", "GPS接收服务已销毁,广播已解绑");
|
||||
Toast.makeText(this, "GPS定位服务已关闭", Toast.LENGTH_SHORT).show();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
<?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:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp">
|
||||
|
||||
<Switch
|
||||
android:id="@+id/sw_gps_service"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="GPS定位服务" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:icon="@android:drawable/ic_menu_preferences"
|
||||
android:title="@string/action_settings"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
||||
@@ -1,4 +1,4 @@
|
||||
<resources>
|
||||
<string name="app_name">ByTheWay</string>
|
||||
|
||||
<string name="action_settings">设置</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user