Skip to content

Commit

Permalink
add "stop this app" shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
diontools committed Oct 19, 2024
1 parent f1f312a commit 8b764ae
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/app/src/debug/res/xml/shortcuts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@
android:targetClass="io.github.diontools.donotspeak.MainActivity"
/>
</shortcut>
<shortcut
android:shortcutId="shutdown"
android:icon="@drawable/ic_noisy"
android:shortcutShortLabel="@string/shortcut_stop_this_app"
android:shortcutLongLabel="@string/shortcut_stop_this_app"
>
<intent
android:action="SHUTDOWN"
android:targetPackage="io.github.diontools.donotspeak.debug"
android:targetClass="io.github.diontools.donotspeak.MainActivity"
/>
</shortcut>
</shortcuts>
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ public int onStartCommand(Intent intent, int flags, int startId) {
break;
}
case ACTION_SHUTDOWN: {
if (logger != null) logger.Log(TAG, "shutdown");
Toast.makeText(this.getApplicationContext(), "Shutdown", Toast.LENGTH_SHORT).show();
this.stopSelf();
IsLive = false;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ static void stopUntilScreenOff(Context context) {
}

static void shutdown(Context context) {
Compat.startForegroundService(
context,
// use startService for shutdown
context.startService(
new Intent(context, DNSService.class)
.setAction(DNSService.ACTION_SHUTDOWN)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ protected void onCreate(Bundle savedInstanceState) {
} else if (Objects.equals(action, DNSService.ACTION_SWITCH)) {
IntentUtility.switching(this);
this.exit();
} else if (Objects.equals(action, DNSService.ACTION_SHUTDOWN)) {
this.requestStopApp();
} else {
PermissionUtility.requestBluetoothPermissionIfRequired(this, result -> {
switch (result) {
Expand Down
1 change: 1 addition & 0 deletions src/app/src/main/res/values-ja/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="start_toast_text">ミュートしています</string>
<string name="stop_toast_text">%1$s まで有効</string>
<string name="stop_until_screen_off">画面消灯まで有効</string>
<string name="shortcut_stop_this_app">アプリ停止</string>
<string name="notification_channel_name">ステータス</string>
<string name="notification_action_untilScreenOff">画面消灯まで有効化</string>
<string name="notification_subtext_enabled">タップしてメニューを表示</string>
Expand Down
1 change: 1 addition & 0 deletions src/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<string name="shortcut_enableSpeakerUntilScreenOff">Enable Speaker</string>
<string name="shortcut_showMenu">Show Menu</string>
<string name="shortcut_switch">Switch</string>
<string name="shortcut_stop_this_app">Stop this app</string>
<string name="tile_label">Disabling Speaker</string>
<string name="tile_stop_text">Speak until %1$s</string>
<string name="tile_stop_until_screen_off">Speak until screen off</string>
Expand Down
12 changes: 12 additions & 0 deletions src/app/src/main/res/xml/shortcuts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@
android:targetClass="io.github.diontools.donotspeak.MainActivity"
/>
</shortcut>
<shortcut
android:shortcutId="shutdown"
android:icon="@drawable/ic_noisy"
android:shortcutShortLabel="Stop app"
android:shortcutLongLabel="Stop app"
>
<intent
android:action="SHUTDOWN"
android:targetPackage="io.github.diontools.donotspeak"
android:targetClass="io.github.diontools.donotspeak.MainActivity"
/>
</shortcut>
</shortcuts>

0 comments on commit 8b764ae

Please sign in to comment.