From 7fd0ed4f249445884201a9cabd1017cc7b97bdef Mon Sep 17 00:00:00 2001 From: Manmade290 Date: Sat, 23 Apr 2022 19:06:30 +0800 Subject: [PATCH 1/2] add exit option --- .../lastlauncher/dialogs/ExitDialog.java | 68 +++++++++++++++++++ .../dialogs/GlobalSettingsDialog.java | 13 ++++ app/src/main/res/layout/dialog_exit.xml | 29 ++++++++ .../res/layout/dialog_global_settings.xml | 19 ++++++ 4 files changed, 129 insertions(+) create mode 100644 app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/ExitDialog.java create mode 100644 app/src/main/res/layout/dialog_exit.xml diff --git a/app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/ExitDialog.java b/app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/ExitDialog.java new file mode 100644 index 00000000..8446753c --- /dev/null +++ b/app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/ExitDialog.java @@ -0,0 +1,68 @@ +/* + * Last Launcher + * Copyright (C) 2022 LIU Tong + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package io.github.subhamtyagi.lastlauncher.dialogs; + +import android.app.Dialog; +import android.content.Context; +import android.os.Bundle; +import android.view.View; +import android.view.Window; +import android.widget.LinearLayout; + +import io.github.subhamtyagi.lastlauncher.LauncherActivity; +import io.github.subhamtyagi.lastlauncher.R; + +public class ExitDialog extends Dialog implements View.OnClickListener{ + + private final LauncherActivity context; + + ExitDialog(Context context, LauncherActivity launcherActivity) { + super(context); + this.context = launcherActivity; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); + setContentView(R.layout.dialog_exit); + LinearLayout ll = findViewById(R.id.exit_layout); + for (int i = 0; i < ll.getChildCount(); i++) { + ll.getChildAt(i).setOnClickListener(this); + } + } + + @Override + public void onClick(View view) { + if (view.getId() == R.id.t1) { + shutdown(); + } + if (view.getId() == R.id.t2) { + rollBack(); + } + } + + private void shutdown() { + System.exit(0); + } + + private void rollBack() { + cancel(); + } +} diff --git a/app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/GlobalSettingsDialog.java b/app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/GlobalSettingsDialog.java index d5af5435..06387084 100644 --- a/app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/GlobalSettingsDialog.java +++ b/app/src/main/java/io/github/subhamtyagi/lastlauncher/dialogs/GlobalSettingsDialog.java @@ -89,6 +89,7 @@ protected void onCreate(Bundle savedInstanceState) { findViewById(R.id.settings_color_size).setOnClickListener(this); findViewById(R.id.settings_sort_app_by).setOnClickListener(this); findViewById(R.id.settings_restart_launcher).setOnClickListener(this); + findViewById(R.id.settings_exit).setOnClickListener(this); //TODO: remove this var TextView colorSniffer = findViewById(R.id.settings_color_sniffer); @@ -165,6 +166,10 @@ public void onClick(View view) { case R.id.settings_restart_launcher: launcherActivity.recreate(); break; + // same as upper code, when click it show exit confirm dialog + case R.id.settings_exit: + showExitDialog(); + break; } } @@ -308,6 +313,14 @@ private void showThemeDialog() { new ThemeSelectorDialog(getContext(), launcherActivity).show(); } + /** + * show the exit confirm dialog + */ + private void showExitDialog() { + cancel(); + new ExitDialog(getContext(), launcherActivity).show(); + } + private void defaultSettings() { if (!BuildConfig.DEBUG) { DbUtils.clearDB(); diff --git a/app/src/main/res/layout/dialog_exit.xml b/app/src/main/res/layout/dialog_exit.xml new file mode 100644 index 00000000..800a0fce --- /dev/null +++ b/app/src/main/res/layout/dialog_exit.xml @@ -0,0 +1,29 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_global_settings.xml b/app/src/main/res/layout/dialog_global_settings.xml index 92c95bb2..a1008eb0 100644 --- a/app/src/main/res/layout/dialog_global_settings.xml +++ b/app/src/main/res/layout/dialog_global_settings.xml @@ -272,6 +272,25 @@ android:text="@string/restart_launcher" android:textSize="20sp" /> + + + + \ No newline at end of file From e5a28f6f2d93263d12bf37260c9cb5687210032e Mon Sep 17 00:00:00 2001 From: Manmade290 Date: Sun, 22 May 2022 17:48:16 +0800 Subject: [PATCH 2/2] fix the bug in theme selection --- app/src/main/res/values/styles.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 6729bf15..14baaf76 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -45,7 +45,6 @@ 40dp 5dp 5dp - #FFFFFFFF #FF000000 @style/PopupMenu