Example usage for android.app AlertDialog.Builder setIcon

List of usage examples for android.app AlertDialog.Builder setIcon

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setIcon.

Prototype

public void setIcon(Drawable icon) 

Source Link

Usage

From source file:jmri.enginedriver.throttle.java

public void promptForSteal(final String addr, final int whichThrottle) {
    if (stealPromptActive)
        return;//from   www. jav a2  s .c  om
    stealPromptActive = true;
    final AlertDialog.Builder b = new AlertDialog.Builder(this);
    b.setIcon(android.R.drawable.ic_dialog_alert);
    b.setTitle(R.string.steal_title);
    b.setMessage(getString(R.string.steal_text, addr));
    b.setCancelable(true);
    b.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { //if yes pressed, tell ta to proceed with steal
        public void onClick(DialogInterface dialog, int id) {
            mainapp.sendMsg(mainapp.comm_msg_handler, message_type.STEAL, addr, whichThrottle);
            stealPromptActive = false;
        }
    });
    b.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { //if no pressed do nothing
        public void onClick(DialogInterface dialog, int id) {
            stealPromptActive = false;
        }
    });
    AlertDialog alert = b.create();
    alert.show();
}

From source file:jmri.enginedriver.throttle.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (webView != null) {
        setImmersiveModeOn(webView);//from w ww. j a va 2 s. co m
    }

    // Handle all of the possible menu actions.
    Intent in;
    switch (item.getItemId()) {
    case R.id.turnouts_mnu:
        in = new Intent().setClass(this, turnouts.class);
        navigatingAway = true;
        startActivity(in);
        connection_activity.overridePendingTransition(this, R.anim.push_right_in, R.anim.push_right_out);
        break;
    case R.id.routes_mnu:
        in = new Intent().setClass(this, routes.class);
        navigatingAway = true;
        startActivity(in);
        connection_activity.overridePendingTransition(this, R.anim.push_left_in, R.anim.push_left_out);
        break;
    case R.id.web_mnu:
        in = new Intent().setClass(this, web_activity.class);
        in.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        navigatingAway = true;
        mainapp.webMenuSelected = true;
        startActivity(in);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;
    case R.id.exit_mnu:
        navigatingAway = true;
        mainapp.checkExit(this);
        break;
    case R.id.power_control_mnu:
        in = new Intent().setClass(this, power_control.class);
        navigatingAway = true;
        startActivity(in);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;
    case R.id.preferences_mnu:
        in = new Intent().setClass(this, preferences.class);
        navigatingAway = true;
        startActivityForResult(in, ACTIVITY_PREFS); // reinitialize function buttons and labels on return
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;
    case R.id.settings_mnu:
        in = new Intent().setClass(this, function_settings.class);
        navigatingAway = true;
        startActivity(in);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;
    case R.id.about_mnu:
        in = new Intent().setClass(this, about_page.class);
        navigatingAway = true;
        startActivity(in);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;
    case R.id.logviewer_menu:
        Intent logviewer = new Intent().setClass(this, LogViewerActivity.class);
        navigatingAway = true;
        startActivity(logviewer);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;
    case R.id.EmerStop:
        mainapp.sendEStopMsg();
        speedUpdate(0); // update all three throttles
        applySpeedRelatedOptions(); // update all three throttles
        if (IS_ESU_MCII) {
            Log.d("Engine_Driver", "ESU_MCII: Move knob request for EStop");
            setEsuThrottleKnobPosition(whichVolume, 0);
        }

        break;
    case R.id.power_layout_button:
        if (!mainapp.isPowerControlAllowed()) {
            AlertDialog.Builder b = new AlertDialog.Builder(this);
            b.setIcon(android.R.drawable.ic_dialog_alert);
            b.setTitle(getApplicationContext().getResources().getString(R.string.powerWillNotWorkTitle));
            b.setMessage(getApplicationContext().getResources().getString(R.string.powerWillNotWork));
            b.setCancelable(true);
            b.setNegativeButton("OK", null);
            AlertDialog alert = b.create();
            alert.show();
            mainapp.displayPowerStateMenuButton(TMenu);
        } else {
            mainapp.powerStateMenuButton();
        }
        break;

    case R.id.EditConsist0_menu:
        Intent consistEdit = new Intent().setClass(this, ConsistEdit.class);

        consistEdit.putExtra("whichThrottle", '0');
        navigatingAway = true;
        startActivityForResult(consistEdit, ACTIVITY_CONSIST);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;
    case R.id.EditConsist1_menu:
        Intent consistEdit2 = new Intent().setClass(this, ConsistEdit.class);
        consistEdit2.putExtra("whichThrottle", '1');
        navigatingAway = true;
        startActivityForResult(consistEdit2, ACTIVITY_CONSIST);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;

    case R.id.EditConsist2_menu:
        Intent consistEdit3 = new Intent().setClass(this, ConsistEdit.class);
        consistEdit3.putExtra("whichThrottle", '2');
        navigatingAway = true;
        startActivityForResult(consistEdit3, ACTIVITY_CONSIST);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;

    case R.id.EditLightsConsist0_menu:
        Intent consistLightsEdit = new Intent().setClass(this, ConsistLightsEdit.class);
        consistLightsEdit.putExtra("whichThrottle", '0');
        navigatingAway = true;
        startActivityForResult(consistLightsEdit, ACTIVITY_CONSIST_LIGHTS);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;

    case R.id.EditLightsConsist1_menu:
        Intent consistLightsEdit2 = new Intent().setClass(this, ConsistLightsEdit.class);
        consistLightsEdit2.putExtra("whichThrottle", '1');
        navigatingAway = true;
        startActivityForResult(consistLightsEdit2, ACTIVITY_CONSIST_LIGHTS);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;
    case R.id.EditLightsConsist2_menu:
        Intent consistLightsEdit3 = new Intent().setClass(this, ConsistLightsEdit.class);
        consistLightsEdit3.putExtra("whichThrottle", '2');
        navigatingAway = true;
        startActivityForResult(consistLightsEdit3, ACTIVITY_CONSIST_LIGHTS);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;

    case R.id.gamepad_test_mnu1:
        in = new Intent().setClass(this, gamepad_test.class);
        in.putExtra("whichGamepadNo", "0");
        navigatingAway = true;
        startActivityForResult(in, ACTIVITY_GAMEPAD_TEST);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;

    case R.id.gamepad_test_mnu2:
        in = new Intent().setClass(this, gamepad_test.class);
        in.putExtra("whichGamepadNo", "1");
        navigatingAway = true;
        startActivityForResult(in, ACTIVITY_GAMEPAD_TEST);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;

    case R.id.gamepad_test_mnu3:
        in = new Intent().setClass(this, gamepad_test.class);
        in.putExtra("whichGamepadNo", "2");
        navigatingAway = true;
        startActivityForResult(in, ACTIVITY_GAMEPAD_TEST);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        break;

    case R.id.timer_mnu:
        showTimerPasswordDialog();
        break;

    case R.id.flashlight_button:
        mainapp.toggleFlashlight(this, TMenu);
        break;

    case R.id.EsuMc2Knob_button:
        toggleEsuMc2Knob(this, TMenu);
        break;
    }
    return super.onOptionsItemSelected(item);
}