Example usage for android.content DialogInterface.OnClickListener DialogInterface.OnClickListener

List of usage examples for android.content DialogInterface.OnClickListener DialogInterface.OnClickListener

Introduction

In this page you can find the example usage for android.content DialogInterface.OnClickListener DialogInterface.OnClickListener.

Prototype

DialogInterface.OnClickListener

Source Link

Usage

From source file:mobile.client.iot.pzalejko.iothome.MainActivity.java

private void askForNewTemperatureAlert() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.alert_dialog_title_text));

    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_NUMBER);
    builder.setView(input);/* w ww .j av  a 2  s.  c  o m*/

    builder.setPositiveButton(getString(R.string.alert_dialog_update_button_text),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    tempAlertValueText.setText(R.string.empty_text_marker);

                    Double alertValue = Double.parseDouble(input.getText().toString());
                    TemperatureAlertEntity entity = new TemperatureAlertEntity(alertValue);

                    // send a request which will set a new temperature alert value.
                    Event event = new Event(entity, EventSource.LOCAL, EventType.UPDATE_TEMPERATURE_ALERT);
                    Intent outIntent = new Intent(MqttEvent.EVENT_OUT);
                    outIntent.putExtra(MqttEvent.PAYLOAD, event);
                    broadcaster.sendBroadcast(outIntent);
                }
            });
    builder.setNegativeButton(getString(R.string.alert_dialog_cancel_button_text),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

    builder.show();
}

From source file:com.example.SmartBoard.MyActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.clear:
        AlertDialog.Builder clearAlert = new AlertDialog.Builder(this);
        clearAlert.setTitle("Clear");
        clearAlert.setMessage("Are you sure you wanna clear everything on the screen?");
        clearAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //save drawing

                clearScreen();// w  ww  .ja  va 2  s  .c om

            }
        });
        clearAlert.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        clearAlert.show();

        return true;
    case R.id.deleteObject:
        mode = "Object Delete Mode";
        notifyMode("Object Delete Mode");
        drawer.removeObjectMode(true);
        return true;
    case R.id.blue:
        drawer.changeColor(Color.BLUE);
        return true;
    case R.id.black:
        drawer.changeColor(Color.BLACK);
        return true;
    case R.id.red:
        drawer.changeColor(Color.RED);
        return true;
    case R.id.green:
        drawer.changeColor(Color.parseColor("#228B22"));
        return true;
    case R.id.save:
        AlertDialog.Builder saveAlert = new AlertDialog.Builder(this);
        saveAlert.setTitle("Save");
        saveAlert.setMessage("Save work to device Gallery?");
        saveAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //save drawing
                drawer.setDrawingCacheEnabled(true);
                String imgSaved = MediaStore.Images.Media.insertImage(getContentResolver(),
                        drawer.getDrawingCache(), UUID.randomUUID().toString() + ".png",
                        "room ID:" + Login.roomId);
                if (imgSaved != null) {
                    Toast savedToast = Toast.makeText(getApplicationContext(), "Drawing saved to Gallery!",
                            Toast.LENGTH_SHORT);
                    savedToast.show();
                } else {
                    Toast unsavedToast = Toast.makeText(getApplicationContext(),
                            "Oops! Image could not be saved.", Toast.LENGTH_SHORT);
                    unsavedToast.show();
                }

                drawer.destroyDrawingCache();

            }
        });
        saveAlert.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //do nothing
            }
        });
        saveAlert.show();
        return true;
    case R.id.print:
        drawer.setDrawingCacheEnabled(true);
        doPhotoPrint(drawer.getDrawingCache());
        drawer.destroyDrawingCache();
        return true;

    case R.id.small:
        mode = "Pencil Mode";
        notifyMode("Pencil Mode");
        drawer.changeBrushSize(2);
        return true;
    case R.id.medium:
        mode = "Pencil Mode";
        notifyMode("Pencil Mode");
        drawer.changeBrushSize(5);
        return true;
    case R.id.large:
        mode = "Pencil Mode";
        notifyMode("Pencil Mode");
        drawer.changeBrushSize(10);
        return true;

    case R.id.smallE:
        mode = "Erase Mode";
        notifyMode("Erase Mode");
        drawer.changeEraseSize(30);
        return true;
    case R.id.mediumE:
        mode = "Erase Mode";
        notifyMode("Erase Mode");
        drawer.changeEraseSize(40);
        return true;
    case R.id.largeE:
        mode = "Erase Mode";
        notifyMode("Erase Mode");
        drawer.changeEraseSize(50);
        return true;
    case R.id.circle:
        mode = "Circle Mode";
        drawer.circleMode(true);
        notifyMode("Circle Object Mode");
        return true;
    case R.id.rectangle:
        mode = "Rectangle Object Mode";
        drawer.rectMode(true);
        notifyMode("Rectangle Object Mode");
        return true;
    case R.id.line:
        mode = "Line Object Mode";
        drawer.lineMode(true);
        notifyMode("Line Object Mode");
        return true;
    case R.id.drag:
        mode = "Drag Mode";
        drawer.dragMode(true);
        notifyMode("Drag Mode");
        return true;
    case R.id.text:
        mode = "Text Mode";
        notifyMode("Text Mode");
        DrawingView.placed = false;
        Intent intent2 = new Intent(this, TextBoxAlert.class);
        startActivityForResult(intent2, TEXT_BOX_INPUT);
        return true;
    case R.id.blackDropper:
        mode = "Color Dropper";
        drawer.colorDropperMode(true, Color.BLACK);
        return true;
    case R.id.blueDroppper:
        mode = "Color Dropper";
        drawer.colorDropperMode(true, Color.BLUE);
        return true;
    case R.id.redDropper:
        mode = "Color Dropper";
        drawer.colorDropperMode(true, Color.RED);
        return true;
    case R.id.greenDropper:
        mode = "Color Dropper";
        drawer.colorDropperMode(true, Color.parseColor("#228B22"));
        return true;
    case R.id.smallText:
        mode = "Touch to Resize";
        notifyMode(mode);
        drawer.textSizeMode(true, 10);
        return true;
    case R.id.mediumText:
        mode = "Touch to Resize";
        notifyMode(mode);
        drawer.textSizeMode(true, 15);
        return true;
    case R.id.largeText:
        mode = "Touch to Resize";
        notifyMode(mode);
        drawer.textSizeMode(true, 20);
        return true;
    case R.id.exit:
        finish();
        return true;
    case R.id.chat:
        if (StatusListener.connectFlag) {
            Intent intent = new Intent(this, Chat.class);
            startActivity(intent);
        } else {
            Toast.makeText(this, "No active connection. Check your internet connection and enter room",
                    Toast.LENGTH_SHORT).show();
            finish();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);

    }
}

From source file:th.in.ffc.MainActivity.java

@Override
public void onBackPressed() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("exit?");
    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

        @Override//from   w  ww .java2s.  c o  m
        public void onClick(DialogInterface dialog, int which) {

            p = new ProgressDialog(MainActivity.this);
            p.setMessage(getString(R.string.please_wait));
            p.setCancelable(false);
            p.show();

            registerReceiver(mEncrypterReceiver, mEncryptFilter);
            mRegis = true;

            Intent service = new Intent(MainActivity.this, CryptographerService.class);
            service.setAction(Action.ENCRYPT);
            startService(service);
        }
    });

    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builder.create().show();
}

From source file:com.ibm.iot.android.iotstarter.fragments.LogPagerFragment.java

/**************************************************************************
 * Functions to handle the iot_menu bar/*from  w  w  w.  j  a  v a 2 s . c om*/
 **************************************************************************/

private void openProfiles() {
    Log.d(TAG, ".openProfiles() entered");
    int currentAPIVersion = Build.VERSION.SDK_INT;
    if (currentAPIVersion < Build.VERSION_CODES.HONEYCOMB) {
        new AlertDialog.Builder(getActivity()).setTitle("Profiles Unavailable")
                .setMessage("Android 3.0 or greater required for profiles.").setPositiveButton(
                        getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                            }
                        })
                .show();
    } else {
        Intent profilesIntent = new Intent(getActivity().getApplicationContext(), ProfilesActivity.class);
        startActivity(profilesIntent);
    }
}

From source file:ca.xecure.easychip.MainActivity.java

private void show_payment_confirmation() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    double money = ((double) amount) / 100;
    int slashslash = callback_url.indexOf("//") + 2;
    String domain = callback_url.substring(slashslash, callback_url.indexOf('/', slashslash));

    builder.setTitle("Payment Confirmation")
            .setMessage("Are you sure to pay " + String.format("($%.2f) ", money) + "to " + domain + "?")
            .setCancelable(false).setPositiveButton("Yeah, I want to", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    String value_message;
                    try {
                        value_message = createValueMessage(amount, payee_id, annotation);
                    } catch (Exception ex) {
                        Log.e(LOG_TAG, ex.getMessage());
                        return;
                    }//from  w  w  w  .  java 2s . c om

                    HashMap<String, String> post_data = new HashMap<String, String>();
                    post_data.put("channel_id", channel_id);
                    post_data.put("value_message", value_message);

                    try {
                        http_post(callback_url, post_data);
                    } catch (IOException ex) {
                        Log.e(LOG_TAG, ex.getMessage());
                    }
                }
            }).setNegativeButton("No, I don't", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:net.alchemiestick.katana.winehqappdb.SearchView.java

private Dialog about_dialog() {
    String msg = "Copyright May 25th 2012 by Rene Kjellerup (aka Katana Steel) and Alchemiestick.\n\n";
    msg += "WineHQ Appdb Search is released under GPLv3 or later. It uses images from WINE project under LGPLv2 or later ";
    msg += "see license:\nhttp://www.gnu.org/licenses/\nfor more infomation about the licenses.\n\n";
    msg += "Souce code for the program can be obtained at\nhttps://github.com/Katana-Steel/winehqappdb\nand choose ";
    msg += "the apropriate release tag for the the version you are running.";
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("About").setMessage(msg).setCancelable(true).setNeutralButton("Ok",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();/*w  w  w .j  a v a  2 s.  c  o m*/
                }
            });
    return builder.create();
}

From source file:app.hacked.ChatFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.chat_fragment, null);
    Message = (EditText) view.findViewById(R.id.chatText);

    ((ImageButton) view.findViewById(R.id.sendButton)).setOnClickListener(new View.OnClickListener() {
        @Override/*from   ww  w .j a  v  a  2  s  .c o m*/
        public void onClick(View view) {
            if (!canPost) {
                //Toast.makeText(getActivity(), "You need to agree to the Hacked.io Terms of Attendance before posting", Toast.LENGTH_SHORT).show();
                //return;
                if (settings.getBoolean("agreetoChat", false)) {
                    canPost = true;
                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    // Add the buttons
                    builder.setPositiveButton("I agree", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            SharedPreferences.Editor editor = PreferenceManager
                                    .getDefaultSharedPreferences(getActivity()).edit();
                            editor.putBoolean("agreetoChat", true);
                            editor.commit();
                            dialog.dismiss();
                            canPost = true;
                        }
                    });
                    builder.setNegativeButton("Nope", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            SharedPreferences.Editor editor = PreferenceManager
                                    .getDefaultSharedPreferences(getActivity()).edit();
                            editor.putBoolean("agreetoChat", false);
                            editor.commit();
                            dialog.dismiss();
                            canPost = false;
                        }
                    });

                    builder.setMessage(getString(R.string.ChatTandC));

                    // Create the AlertDialog
                    AlertDialog dialog = builder.create();
                    dialog.setCancelable(false);
                    dialog.show();
                }
                return;
            }

            progressBar.setVisibility(View.VISIBLE);
            Message.setEnabled(false);

            final String msg = Message.getText().toString();
            JSONObject post = new JSONObject();
            try {
                try {
                    post.put("name", accounts[0].name);
                } catch (Exception e) {
                    e.printStackTrace();
                    post.put("name", "Anon");
                }
                post.put("msg", msg);
                post.put("auth", API.md5(API.BETTER_THAN_NOTHING_STUFF_TO_PREVENT_INJECTION_ATTEMPTS + msg));
            } catch (Exception e) {
                e.printStackTrace();
                Toast.makeText(getActivity(),
                        "An Error Was encountered parsing the entered details: " + e.getMessage(),
                        Toast.LENGTH_SHORT).show();
                return;
            }

            JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST,
                    "http://hackedioapp.networksaremadeofstring.co.uk/addchatmsg.php", post,
                    new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {
                            Log.e("response", response.toString());
                            try {
                                if (response.has("success") && response.getBoolean("success")) {
                                    //Toast.makeText(getActivity(), "Project added successfully!", Toast.LENGTH_SHORT).show();
                                    //adapter.ChatMessages.add(new ChatMessage(accounts[0].name,msg));
                                    //adapter.notifyDataSetChanged();
                                    Message.setText("");
                                    progressBar.setVisibility(View.INVISIBLE);
                                    Message.setEnabled(true);
                                } else {
                                    Toast.makeText(getActivity(), "An Error Was encountered",
                                            Toast.LENGTH_SHORT).show();
                                    Message.setEnabled(true);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }, new Response.ErrorListener() {

                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // TODO Auto-generated method stub
                            Toast.makeText(getActivity(), "An Error Was encountered: " + error.getMessage(),
                                    Toast.LENGTH_SHORT).show();
                        }
                    });

            queue.add(jsObjRequest);
        }
    });

    progressBar = view.findViewById(R.id.progressBar);

    return view;
}

From source file:org.jitsi.service.osgi.OSGiActivity.java

/**
 * Checks if the crash has occurred since the Jitsi was last started.
 * If it's true asks the user about eventual logs report.
 *///from w w w . j  a v a2  s . c  om
private void checkForSendLogsDialog() {
    // Checks if Jitsi has previously crashed and asks the user user
    // about log reporting
    if (!ExceptionHandler.hasCrashed()) {
        return;
    }
    // Clears the crash status
    ExceptionHandler.resetCrashedStatus();
    // Asks the user
    AlertDialog.Builder question = new AlertDialog.Builder(this);
    question.setTitle(R.string.service_gui_WARNING)
            .setMessage(getString(R.string.service_gui_SEND_LOGS_QUESTION))
            .setPositiveButton(R.string.service_gui_YES, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    JitsiApplication.showSendLogsDialog();
                }
            }).setNegativeButton(R.string.service_gui_NO, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create().show();

}

From source file:se.leap.bitmaskclient.Dashboard.java

private void configErrorDialog() {
    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getContext());
    alertBuilder.setTitle(getResources().getString(R.string.setup_error_title));
    alertBuilder.setMessage(getResources().getString(R.string.setup_error_text)).setCancelable(false)
            .setPositiveButton(getResources().getString(R.string.setup_error_configure_button),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            startActivityForResult(new Intent(getContext(), ConfigurationWizard.class),
                                    CONFIGURE_LEAP);
                        }/* w w w .  j  ava2 s.c o  m*/
                    })
            .setNegativeButton(getResources().getString(R.string.setup_error_close_button),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            preferences.edit().remove(Provider.KEY).remove(Constants.PROVIDER_CONFIGURED)
                                    .apply();
                            finish();
                        }
                    })
            .show();
}

From source file:com.readystatesoftware.ghostlog.GhostLogSettingsFragment.java

private void processRootFail() {

    int failCount = mPrefs.getInt(getString(R.string.pref_root_fail_count), 0);
    if (failCount == 0) {
        // show dialog first time
        AlertDialog dlg = new AlertDialog.Builder(mContext).setTitle(R.string.no_root)
                .setMessage(R.string.no_root_dialog)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // ok, do nothing
                    }/*from w  w w.j a  v a  2 s.c o m*/
                }).setNeutralButton(getString(R.string.github), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.repo_url)));
                        startActivity(intent);
                    }
                }).create();
        dlg.show();
        mPrefs.edit().putInt(getString(R.string.pref_root_fail_count), failCount + 1).apply();
    } else if (failCount <= 3) {
        // show toast 3 more times
        Toast.makeText(mContext, R.string.toast_no_root, Toast.LENGTH_LONG).show();
        mPrefs.edit().putInt(getString(R.string.pref_root_fail_count), failCount + 1).apply();
    }

}