Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import android.os.Process;

public class Main {
    public static void doKillOrContinueDialog(Context context, String title, String message,
            OnClickListener positiveListener, OnClickListener negativeListener) {
        if (positiveListener == null) {
            positiveListener = createDoNothingListener();
        }
        if (negativeListener == null) {
            negativeListener = createKillListener();
        }

        new AlertDialog.Builder(context).setTitle(title).setMessage(message)
                .setPositiveButton("Continue", positiveListener).setNegativeButton("Kill", negativeListener)
                .setCancelable(false).create().show();
    }

    public static OnClickListener createDoNothingListener() {
        return new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // Do nothing
            }
        };
    }

    public static OnClickListener createKillListener() {
        return new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Process.killProcess(Process.myPid());
            }
        };
    }
}