完成应用退出的菜单按钮逻辑
This commit is contained in:
		@@ -1,8 +1,8 @@
 | 
			
		||||
#Created by .winboll/winboll_app_build.gradle
 | 
			
		||||
#Fri Mar 28 15:50:23 HKT 2025
 | 
			
		||||
#Fri Mar 28 10:09:25 GMT 2025
 | 
			
		||||
stageCount=3
 | 
			
		||||
libraryProject=libappbase
 | 
			
		||||
baseVersion=15.1
 | 
			
		||||
publishVersion=15.1.2
 | 
			
		||||
buildCount=0
 | 
			
		||||
buildCount=4
 | 
			
		||||
baseBetaVersion=15.1.3
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,7 @@ import cc.winboll.studio.libappbase.sos.SOS;
 | 
			
		||||
import cc.winboll.studio.libappbase.utils.ToastUtils;
 | 
			
		||||
import cc.winboll.studio.libappbase.widgets.StatusWidget;
 | 
			
		||||
import cc.winboll.studio.libappbase.winboll.IWinBollActivity;
 | 
			
		||||
import cc.winboll.studio.libappbase.dialogs.YesNoAlertDialog;
 | 
			
		||||
 | 
			
		||||
public class MainActivity extends WinBollActivityBase implements IWinBollActivity {
 | 
			
		||||
 | 
			
		||||
@@ -68,12 +69,6 @@ public class MainActivity extends WinBollActivityBase implements IWinBollActivit
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onOptionsItemSelected(MenuItem item) {
 | 
			
		||||
        if (item.getItemId() == cc.winboll.studio.appbase.R.id.item_log) {
 | 
			
		||||
            GlobalApplication.getWinBollActivityManager().startLogActivity(this);
 | 
			
		||||
            return true;
 | 
			
		||||
        } else if(item.getItemId() == cc.winboll.studio.appbase.R.id.item_minimal) {
 | 
			
		||||
            moveTaskToBack(true);
 | 
			
		||||
        }
 | 
			
		||||
        // 在switch语句中处理每个ID,并在处理完后返回true,未处理的情况返回false。
 | 
			
		||||
        return super.onOptionsItemSelected(item);
 | 
			
		||||
    }
 | 
			
		||||
@@ -143,6 +138,8 @@ public class MainActivity extends WinBollActivityBase implements IWinBollActivit
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    public void onStopTestDemoService(View view) {
 | 
			
		||||
        Intent intent = new Intent(this, TestDemoService.class);
 | 
			
		||||
        intent.setAction(TestDemoService.ACTION_DISABLE);
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,11 @@ import android.app.Activity;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.os.PersistableBundle;
 | 
			
		||||
import android.support.v7.app.AppCompatActivity;
 | 
			
		||||
import android.view.MenuItem;
 | 
			
		||||
import cc.winboll.studio.appbase.App;
 | 
			
		||||
import cc.winboll.studio.appbase.R;
 | 
			
		||||
import cc.winboll.studio.libappbase.GlobalApplication;
 | 
			
		||||
import cc.winboll.studio.libappbase.dialogs.YesNoAlertDialog;
 | 
			
		||||
import cc.winboll.studio.libappbase.winboll.IWinBollActivity;
 | 
			
		||||
import cc.winboll.studio.libappbase.winboll.WinBollActivityManager;
 | 
			
		||||
 | 
			
		||||
@@ -43,6 +47,32 @@ public class WinBollActivityBase extends AppCompatActivity implements IWinBollAc
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onOptionsItemSelected(MenuItem item) {
 | 
			
		||||
        if (item.getItemId() == cc.winboll.studio.appbase.R.id.item_log) {
 | 
			
		||||
            GlobalApplication.getWinBollActivityManager().startLogActivity(this);
 | 
			
		||||
            return true;
 | 
			
		||||
        } else if(item.getItemId() == cc.winboll.studio.appbase.R.id.item_minimal) {
 | 
			
		||||
            //moveTaskToBack(true);
 | 
			
		||||
            exit();
 | 
			
		||||
        }
 | 
			
		||||
        // 在switch语句中处理每个ID,并在处理完后返回true,未处理的情况返回false。
 | 
			
		||||
        return super.onOptionsItemSelected(item);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void exit() {
 | 
			
		||||
        YesNoAlertDialog.show(this, "Exit " + getString(R.string.app_name), "Close all activity and exit?", new YesNoAlertDialog.OnDialogResultListener(){
 | 
			
		||||
 | 
			
		||||
                @Override
 | 
			
		||||
                public void onYes() {
 | 
			
		||||
                    App.getWinBollActivityManager().finishAll();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                @Override
 | 
			
		||||
                public void onNo() {
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onDestroy() {
 | 
			
		||||
 
 | 
			
		||||
@@ -76,8 +76,6 @@ public class New2Activity extends WinBollActivityBase implements IWinBollActivit
 | 
			
		||||
        if (item.getItemId() == cc.winboll.studio.appbase.R.id.item_log) {
 | 
			
		||||
            GlobalApplication.getWinBollActivityManager().startLogActivity(this);
 | 
			
		||||
            return true;
 | 
			
		||||
        } else if(item.getItemId() == cc.winboll.studio.appbase.R.id.item_minimal) {
 | 
			
		||||
            moveTaskToBack(true);
 | 
			
		||||
        }
 | 
			
		||||
        // 在switch语句中处理每个ID,并在处理完后返回true,未处理的情况返回false。
 | 
			
		||||
        return super.onOptionsItemSelected(item);
 | 
			
		||||
 
 | 
			
		||||
@@ -74,8 +74,6 @@ public class NewActivity extends WinBollActivityBase implements IWinBollActivity
 | 
			
		||||
        if (item.getItemId() == cc.winboll.studio.appbase.R.id.item_log) {
 | 
			
		||||
            GlobalApplication.getWinBollActivityManager().startLogActivity(this);
 | 
			
		||||
            return true;
 | 
			
		||||
        } else if(item.getItemId() == cc.winboll.studio.appbase.R.id.item_minimal) {
 | 
			
		||||
            moveTaskToBack(true);
 | 
			
		||||
        }
 | 
			
		||||
        // 在switch语句中处理每个ID,并在处理完后返回true,未处理的情况返回false。
 | 
			
		||||
        return super.onOptionsItemSelected(item);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
#Created by .winboll/winboll_app_build.gradle
 | 
			
		||||
#Fri Mar 28 15:50:14 HKT 2025
 | 
			
		||||
#Fri Mar 28 10:09:25 GMT 2025
 | 
			
		||||
stageCount=3
 | 
			
		||||
libraryProject=libappbase
 | 
			
		||||
baseVersion=15.1
 | 
			
		||||
publishVersion=15.1.2
 | 
			
		||||
buildCount=0
 | 
			
		||||
buildCount=4
 | 
			
		||||
baseBetaVersion=15.1.3
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,60 @@
 | 
			
		||||
package cc.winboll.studio.libappbase.dialogs;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author ZhanGSKen@AliYun.Com
 | 
			
		||||
 * @Date 2025/03/28 17:40:47
 | 
			
		||||
 * @Date 2024/08/12 14:46:25
 | 
			
		||||
 * @Describe 询问用户确定与否的选择框
 | 
			
		||||
 */
 | 
			
		||||
import android.app.AlertDialog;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.content.DialogInterface;
 | 
			
		||||
 | 
			
		||||
public class YesNoAlertDialog {
 | 
			
		||||
 | 
			
		||||
    public static final String TAG = "YesNoAlertDialog";
 | 
			
		||||
 | 
			
		||||
    public static void show(Context context, String szTitle, String szMessage, final OnDialogResultListener listener) {
 | 
			
		||||
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
 | 
			
		||||
            context);
 | 
			
		||||
 | 
			
		||||
        // set title
 | 
			
		||||
        alertDialogBuilder.setTitle(szTitle);
 | 
			
		||||
 | 
			
		||||
        // set dialog message
 | 
			
		||||
        alertDialogBuilder
 | 
			
		||||
            .setMessage(szMessage)
 | 
			
		||||
            .setCancelable(true)
 | 
			
		||||
            .setOnCancelListener(new DialogInterface.OnCancelListener(){
 | 
			
		||||
                @Override
 | 
			
		||||
                public void onCancel(DialogInterface dialog) {
 | 
			
		||||
                    listener.onNo();
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
            .setPositiveButton("YES", new DialogInterface.OnClickListener() {
 | 
			
		||||
                public void onClick(DialogInterface dialog, int id) {
 | 
			
		||||
                    // if this button is clicked, close
 | 
			
		||||
                    // current activity
 | 
			
		||||
                    listener.onYes();
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
            .setNegativeButton("NO", new DialogInterface.OnClickListener() {
 | 
			
		||||
                public void onClick(DialogInterface dialog, int id) {
 | 
			
		||||
                    // if this button is clicked, just close
 | 
			
		||||
                    // the dialog box and do nothing
 | 
			
		||||
                    dialog.cancel();
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
        // create alert dialog
 | 
			
		||||
        AlertDialog alertDialog = alertDialogBuilder.create();
 | 
			
		||||
 | 
			
		||||
        // show it
 | 
			
		||||
        alertDialog.show();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public interface OnDialogResultListener {
 | 
			
		||||
        abstract void onYes();
 | 
			
		||||
        abstract void onNo();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user