Example usage for android.app AlertDialog.Builder show

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

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:com.synvata.modules.DriverLicenseEditActivity.java

private void chooseDriverType() {
    final JSONArray list = AppSettings.driver_type_list;
    if (list == null) {
        return;/* w w w .  ja v  a 2 s . co m*/
    }
    String types = ((EditText) findViewById(R.id.edt_driverlicense_car_type)).getText().toString();

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    MultiChoiceID.clear();
    builder.setIcon(R.drawable.index_looks);
    builder.setTitle("Please choose");

    final String[] items = new String[list.length()];
    boolean[] checkedItems = new boolean[list.length()];
    try {
        for (int i = 0; i < list.length(); i++) {
            JSONObject item = list.getJSONObject(i);
            String code = item.getString("code");
            String name = item.getString("name");
            String years = item.getString("years");
            items[i] = String.format("%s--%s(%s)", code, name, years);
            if (types.contains(code)) {
                checkedItems[i] = true;
                MultiChoiceID.add(i);
            } else {
                checkedItems[i] = false;
            }
        }
    } catch (Exception e) {
        log(e);
    }

    builder.setMultiChoiceItems(items, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            if (isChecked) {
                if (!MultiChoiceID.contains(which))
                    MultiChoiceID.add(which);
            } else {
                if (MultiChoiceID.contains(which))
                    MultiChoiceID.remove(which);
            }

        }
    });
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

            //            String str = "";
            //                int size = MultiChoiceID.size();
            //                for (int i = 0 ;i < size; i++) {
            //                   str+= items[MultiChoiceID.get(i)] + ", ";
            //                }
            //                showDialog(str);
            changeDriverType();
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    builder.show();
}

From source file:com.mobantica.DriverItRide.activities.ActivityProfile.java

private void selectImage() {
    final CharSequence[] options = { getResources().getString(R.string.take_photo),
            getResources().getString(R.string.select_from_gallery), getResources().getString(R.string.cancel) };
    android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);

    builder.setTitle(getResources().getString(R.string.add_photo));

    builder.setItems(options, new DialogInterface.OnClickListener() {
        @Override/* w  w w. j a v a2 s  .co  m*/
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals(getResources().getString(R.string.take_photo))) {
                Boolean isSDPresent = android.os.Environment.getExternalStorageState()
                        .equals(android.os.Environment.MEDIA_MOUNTED);
                if (isSDPresent) {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
                    startActivityForResult(intent, 1);
                    //Log.d(TAG, "onClick: " + fileUri);
                    ChnagedUri = fileUri;
                } else {
                    myToast(ActivityProfile.this,
                            getResources().getString(R.string.insert_an_sd_card_before_using_the_camera));
                }
            } else if (options[item].equals(getResources().getString(R.string.select_from_gallery))) {
                Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, 2);
            } else if (options[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }

    });

    builder.show();
}

From source file:fi.mikuz.boarder.gui.internet.InternetMenu.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.internet_menu);
    setTitle("Internet Menu");
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mWaitDialog = new TimeoutProgressDialog(this, "Waiting for response", TAG, true);

    mInternetDownload = (Button) findViewById(R.id.internet_download);
    mInternetRegisterSettings = (Button) findViewById(R.id.internet_register_settings);
    mInternetLoginLogout = (Button) findViewById(R.id.internet_login_logout);
    mInternetUploads = (Button) findViewById(R.id.internet_uploads);
    mInternetFavorites = (Button) findViewById(R.id.internet_favorites);
    mAccountMessage = (TextView) findViewById(R.id.account_message_text);

    mDbHelper = new LoginDbAdapter(this);
    mDbHelper.open();//from  w  ww  .j a  va  2s .co m

    mGlobalVariableDbHelper = new GlobalVariablesDbAdapter(this);
    mGlobalVariableDbHelper.open();
    int dbTosVersion = 0;
    try {
        Cursor variableCursor = mGlobalVariableDbHelper.fetchVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY);
        startManagingCursor(variableCursor);
        dbTosVersion = variableCursor.getInt(variableCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA));
    } catch (SQLException e) {
        mGlobalVariableDbHelper.createIntVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY, 0);
        Log.d(TAG, "Couldn't get tosVersion", e);

    } catch (CursorIndexOutOfBoundsException e) {
        mGlobalVariableDbHelper.createIntVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY, 0);
        Log.d(TAG, "Couldn't get tosVersion", e);
    }

    if (dbTosVersion < mTosVersion) {
        AlertDialog.Builder builder = new AlertDialog.Builder(InternetMenu.this);
        builder.setTitle("Terms of service");
        builder.setMessage("Excited to get your hands on those sweet boards? - Good.\n\n"
                + "There are some terms you must agree to and follow to get things rolling smoothly;\n\n"
                + "You may only communicate in English in the Boarder Internet service.\n\n"
                + "An uploaded board may contain any languages. However, if the board is not 'in English' that must be visibly stated in the description.\n\n"
                + "You agree to always follow applicable laws when using Boarder.\n\n"
                + "Pornographic and other adult only material is not allowed.\n\n"
                + "You must be at least 13 years old to register to the Boarder Internet service.\n\n"
                + "You may never transmit anything or communicate a way that can be deemed offensive.\n\n"
                + "Don't make cheap copies of another users boards.\n\n"
                + "We can use material(s) publicly shared by you as promotional material.\n\n"
                + "We will suspend your Boarder releated accounts and/or remove your material from the Boarder service if you behave badly.");

        builder.setPositiveButton("Agree", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                mGlobalVariableDbHelper.updateIntVariable(GlobalVariablesDbAdapter.TOS_VERSION_KEY,
                        mTosVersion);
            }
        });

        builder.setNegativeButton("Disagree", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                InternetMenu.this.finish();
            }
        });

        builder.setCancelable(false);
        builder.show();
    }

    if (mLoginInfo == null) {
        try {
            String userId;
            String sessionToken;

            Cursor loginCursor = mDbHelper.fetchLogin(USER_ID_KEY);
            startManagingCursor(loginCursor);
            userId = loginCursor.getString(loginCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA));

            loginCursor = mDbHelper.fetchLogin(SESSION_TOKEN_KEY);
            startManagingCursor(loginCursor);
            sessionToken = loginCursor.getString(loginCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA));

            mLoginInfo = new HashMap<String, String>();
            mLoginInfo.put(USER_ID_KEY, userId);
            mLoginInfo.put(SESSION_TOKEN_KEY, sessionToken);
            sendDonationInfo();

            mSessionValidityChecked = false;
            checkSessionValidity();

        } catch (CursorIndexOutOfBoundsException e) {
            Log.d(TAG, "Couldn't get database session info", e);
            mSessionValidityChecked = true;
        }
    }

    getVersionInfo(); // Keep under login stuff

    mInternetDownload.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(InternetMenu.this, DownloadBoardList.class);
            i.putExtra(LOGIN_KEY, mLoginInfo);
            startActivity(i);
        }
    });

    mInternetRegisterSettings.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mInternetRegisterSettings.getText().toString().equals(SETTINGS_TEXT)) {
                Intent i = new Intent(InternetMenu.this, Settings.class);
                i.putExtra(LOGIN_KEY, mLoginInfo);
                startActivityForResult(i, LOGIN_RETURN);
            } else {
                Intent i = new Intent(InternetMenu.this, Register.class);
                startActivity(i);
            }
        }
    });

    mInternetLoginLogout.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            startLogin();
        }
    });

    mInternetUploads.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(InternetMenu.this, Uploads.class);
            i.putExtra(LOGIN_KEY, mLoginInfo);
            startActivityForResult(i, LOGIN_RETURN);
        }
    });

    mInternetFavorites.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(InternetMenu.this, Favorites.class);
            i.putExtra(LOGIN_KEY, mLoginInfo);
            startActivityForResult(i, LOGIN_RETURN);
        }
    });

}

From source file:cgeo.geocaching.cgeocaches.java

private void removeList(final boolean askForConfirmation) {
    // if there are no caches on this list, don't bother the user with questions.
    // there is no harm in deleting the list, he could recreate it easily
    if (CollectionUtils.isEmpty(cacheList)) {
        removeListInternal();//from  www.j  a  va 2s  .co  m
        return;
    }

    if (!askForConfirmation) {
        removeListInternal();
        return;
    }

    // ask him, if there are caches on the list
    final AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle(R.string.list_dialog_remove_title);
    alert.setMessage(R.string.list_dialog_remove_description);
    alert.setPositiveButton(R.string.list_dialog_remove, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            removeListInternal();
        }
    });
    alert.setNegativeButton(res.getString(R.string.list_dialog_cancel), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();
        }
    });

    alert.show();
}

From source file:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java

@Override
public void onBackPressed() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 0) {
        TabGroup currentTabGroup = (TabGroup) fragmentManager.findFragmentByTag(
                fragmentManager.getBackStackEntryAt(fragmentManager.getBackStackEntryCount() - 1).getName());
        if (currentTabGroup != null) {
            renderer.invalidateListViews(currentTabGroup);
            renderer.setCurrentTabGroup(currentTabGroup);
            getActionBar().setTitle(currentTabGroup.getLabel());
        }/*from   w  w w  . ja  v  a  2s.  c  om*/
        super.onBackPressed();
    } else {
        if (syncStarted) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Stop Syncing");
            builder.setMessage(
                    "Syncing is still in progress. Do you want to exit the activity and stop the sync?");
            builder.setPositiveButton("Yes", new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    syncStarted = false;
                    stopSync();
                    ShowModuleActivity.super.onBackPressed();
                }
            });
            builder.setNegativeButton("No", new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing
                }
            });
            builder.show();
        } else {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Exit Module");
            builder.setMessage("Do you want to exit module?");
            builder.setPositiveButton("Yes", new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ShowModuleActivity.super.onBackPressed();
                }
            });
            builder.setNegativeButton("No", new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing
                }
            });
            builder.show();
        }
    }
}

From source file:fi.mikuz.boarder.gui.internet.Settings.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.internet_settings);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    @SuppressWarnings("unchecked")
    HashMap<String, String> lastSession = (HashMap<String, String>) getIntent()
            .getSerializableExtra(InternetMenu.LOGIN_KEY);

    try {/*from w w w .j  a  v a  2s  .c om*/
        mUserId = lastSession.get(InternetMenu.USER_ID_KEY);
        mSessionToken = lastSession.get(InternetMenu.SESSION_TOKEN_KEY);
    } catch (NullPointerException e) {
        Toast.makeText(Settings.this, "Please login", Toast.LENGTH_LONG).show();
        Settings.this.finish();
    }

    Button changePassword = (Button) findViewById(R.id.change_password);

    changePassword.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LayoutInflater inflater = (LayoutInflater) Settings.this.getSystemService(LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.internet_settings_alert_change_password,
                    (ViewGroup) findViewById(R.id.alert_settings_root));

            final EditText oldPasswordInput = (EditText) layout.findViewById(R.id.oldPasswordInput);
            final EditText newPassword1Input = (EditText) layout.findViewById(R.id.newPassword1Input);
            final EditText newPassword2Input = (EditText) layout.findViewById(R.id.newPassword2Input);
            Button submitButton = (Button) layout.findViewById(R.id.submitButton);

            AlertDialog.Builder builder = new AlertDialog.Builder(Settings.this);
            builder.setView(layout);
            builder.setTitle("Change password");

            submitButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    String oldPasswordText = oldPasswordInput.getText().toString();
                    String newPassword1Text = newPassword1Input.getText().toString();
                    String newPassword2Text = newPassword2Input.getText().toString();

                    if (!newPassword1Text.equals(newPassword2Text)) {
                        Toast.makeText(Settings.this, "New passwords don't match", Toast.LENGTH_LONG).show();
                    } else if (newPassword1Text.length() < 6) {
                        Toast.makeText(Settings.this, "Password length must be at least 6 characters",
                                Toast.LENGTH_LONG).show();
                    } else {
                        try {
                            mWaitDialog = new TimeoutProgressDialog(Settings.this, "Waiting for response", TAG,
                                    false);
                            HashMap<String, String> sendList = new HashMap<String, String>();
                            sendList.put(InternetMenu.PASSWORD_KEY, Security.passwordHash(newPassword1Text));
                            sendList.put(InternetMenu.OLD_PASSWORD_KEY, Security.passwordHash(oldPasswordText));
                            sendList.put(InternetMenu.USER_ID_KEY, mUserId);
                            sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
                            new ConnectionManager(Settings.this, InternetMenu.mChangePasswordURL, sendList);
                        } catch (NoSuchAlgorithmException e) {
                            mWaitDialog.dismiss();
                            String msg = "Couldn't make md5 hash";
                            Toast.makeText(Settings.this, msg, Toast.LENGTH_LONG).show();
                            Log.e(TAG, msg, e);
                        }
                    }
                }
            });

            builder.show();
        }
    });

    Button changeEmail = (Button) findViewById(R.id.change_email);

    changeEmail.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LayoutInflater inflater = (LayoutInflater) Settings.this.getSystemService(LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.internet_settings_alert_change_email,
                    (ViewGroup) findViewById(R.id.alert_settings_root));

            final EditText passwordInput = (EditText) layout.findViewById(R.id.passwordInput);
            final EditText newEmailInput = (EditText) layout.findViewById(R.id.newEmailInput);
            Button submitButton = (Button) layout.findViewById(R.id.submitButton);

            AlertDialog.Builder builder = new AlertDialog.Builder(Settings.this);
            builder.setView(layout);
            builder.setTitle("Change email");

            submitButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    String passwordText = passwordInput.getText().toString();
                    String newEmailText = newEmailInput.getText().toString();

                    try {
                        mWaitDialog = new TimeoutProgressDialog(Settings.this, "Waiting for response", TAG,
                                false);
                        HashMap<String, String> sendList = new HashMap<String, String>();
                        sendList.put(InternetMenu.PASSWORD_KEY, Security.passwordHash(passwordText));
                        sendList.put(InternetMenu.EMAIL_KEY, newEmailText);
                        sendList.put(InternetMenu.USER_ID_KEY, mUserId);
                        sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
                        new ConnectionManager(Settings.this, InternetMenu.mChangeEmailURL, sendList);
                    } catch (NoSuchAlgorithmException e) {
                        mWaitDialog.dismiss();
                        String msg = "Couldn't make md5 hash";
                        Toast.makeText(Settings.this, msg, Toast.LENGTH_LONG).show();
                        Log.e(TAG, msg, e);
                    }
                }
            });

            builder.show();
        }
    });

}

From source file:ac.robinson.bettertogether.ConnectionSetupActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int[] grantResults) {
    switch (requestCode) {
    case CAMERA_PERMISSION_RESULT:
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            restartCaptureManager();/*from   www.j  a v a 2  s  . co  m*/
        } else {
            AlertDialog.Builder builder = new AlertDialog.Builder(ConnectionSetupActivity.this);
            builder.setTitle(R.string.title_camera_access);
            builder.setMessage(R.string.hint_enable_camera_access);
            builder.setPositiveButton(R.string.hint_edit_permissions, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent();
                    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    intent.setData(
                            Uri.fromParts("package", ConnectionSetupActivity.this.getPackageName(), null));
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        // we've tried everything by this point!
                        Log.d(TAG,
                                "Camera permission denied and request failed - will not be able to scan codes");
                        Toast.makeText(ConnectionSetupActivity.this, R.string.error_accessing_camera,
                                Toast.LENGTH_LONG).show();
                    }
                    restartCaptureManager();
                }
            });
            builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(ConnectionSetupActivity.this, R.string.error_accessing_location,
                            Toast.LENGTH_LONG).show();
                    restartCaptureManager(); // reset capture UI and try again
                }
            });
            builder.show();
        }
        break;

    case COARSE_LOCATION_PERMISSION_RESULT:
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            createClient();
        } else {
            AlertDialog.Builder builder = new AlertDialog.Builder(ConnectionSetupActivity.this);
            builder.setTitle(R.string.title_coarse_location_access);
            builder.setMessage(R.string.hint_enable_coarse_location_access);
            builder.setPositiveButton(R.string.hint_edit_permissions, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent();
                    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    intent.setData(
                            Uri.fromParts("package", ConnectionSetupActivity.this.getPackageName(), null));
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        // we've tried everything by this point!
                        Log.d(TAG,
                                "Coarse location permission denied and request failed - will not be able to connect");
                        Toast.makeText(ConnectionSetupActivity.this, R.string.error_accessing_location,
                                Toast.LENGTH_LONG).show();
                    }
                    restartCaptureManager();
                }
            });
            builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(ConnectionSetupActivity.this, R.string.error_accessing_location,
                            Toast.LENGTH_LONG).show();
                    restartCaptureManager(); // reset capture UI and try again
                }
            });
            builder.show();
        }
        break;

    default:
        if (mCaptureManager != null && requestCode == CaptureManager.getCameraPermissionReqCode()) {
            // ignored - CaptureManager's default is to exit on permission denial, so we handle permissions ourselves
            // mCaptureManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
        break;
    }
}

From source file:com.t2.compassionMeditation.Graphs1Activity.java

/**
 * Validates sensors, makes sure that bluetooth is on and each sensor has a parameter associated with it
 *///from w  ww.  jav  a2s .c  om
void validateBioSensors() {

    // First make sure that bluetooth is enabled
    if (!mBluetoothEnabled) {
        AlertDialog.Builder alert1 = new AlertDialog.Builder(this);

        alert1.setMessage("Bluetooth is not enabled on your device. Press OK to go to the wireless system"
                + "settings to turn it on");

        alert1.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                mInstance.startActivityForResult(
                        new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS), BLUETOOTH_SETTINGS_ID);
            }
        });
        alert1.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        });
        alert1.show();
    }
    String badSensorName = null;

    // Now make sure that every device has a parameter associated with it
    for (BioSensor sensor : mBioSensors) {
        if (sensor.mEnabled) {
            String param = SharedPref.getParamForDevice(mInstance, sensor.mBTAddress);
            //Log.d(TAG, "sensor: " + sensor.mBTName + ", parameter: " + param);
            if (param == null) {
                badSensorName = sensor.mBTName;
                break;
            }
        }
    } // end for (BioSensor sensor: mBioSensors)

    if (badSensorName != null) {
        AlertDialog.Builder alert1 = new AlertDialog.Builder(this);

        alert1.setMessage("Sensor " + badSensorName + " is enabled but "
                + " does not have a parameter associated with it." + "Press Ok to associate one");

        alert1.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                Intent intent2 = new Intent(mInstance, DeviceManagerActivity.class);
                mInstance.startActivity(intent2);
            }
        });
        alert1.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        });
        alert1.show();

    }
}

From source file:com.google.sample.beaconservice.ManageBeaconFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false);

    advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type);
    advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id);
    status = (TextView) rootView.findViewById(R.id.status);
    placeId = (TextView) rootView.findViewById(R.id.placeId);
    placeId.setOnClickListener(new View.OnClickListener() {
        @Override//from  w  w  w.ja  v a  2s .  c  o m
        public void onClick(View v) {
            editLatLngAction();
        }
    });
    latLng = (TextView) rootView.findViewById(R.id.latLng);
    latLng.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editLatLngAction();
        }
    });
    mapView = (ImageView) rootView.findViewById(R.id.mapView);
    mapView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editLatLngAction();
        }
    });

    expectedStability = (TextView) rootView.findViewById(R.id.expectedStability);
    expectedStability.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability");
            final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
                    R.array.stability_enums, android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            final Spinner spinner = new Spinner(getActivity());
            spinner.setAdapter(adapter);
            // Set the position of the spinner to the current value.
            if (beacon.expectedStability != null
                    && !beacon.expectedStability.equals(Beacon.STABILITY_UNSPECIFIED)) {
                for (int i = 0; i < spinner.getCount(); i++) {
                    if (beacon.expectedStability.equals(spinner.getItemAtPosition(i))) {
                        spinner.setSelection(i);
                    }
                }
            }
            builder.setView(spinner);
            builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    beacon.expectedStability = (String) spinner.getSelectedItem();
                    updateBeacon();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    description = (TextView) rootView.findViewById(R.id.description);
    description.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description");
            final EditText editText = new EditText(getActivity());
            editText.setText(description.getText());
            builder.setView(editText);
            builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    beacon.description = editText.getText().toString();
                    updateBeacon();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    actionButton = (Button) rootView.findViewById(R.id.actionButton);

    decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton);
    decommissionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon")
                    .setMessage("Are you sure you want to decommission this beacon? This operation is "
                            + "irreversible and the beacon cannot be registered again")
                    .setPositiveButton("Decommission", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            Callback decommissionCallback = new Callback() {
                                @Override
                                public void onFailure(Request request, IOException e) {
                                    logErrorAndToast("Failed request: " + request, e);
                                }

                                @Override
                                public void onResponse(Response response) throws IOException {
                                    if (response.isSuccessful()) {
                                        beacon.status = Beacon.STATUS_DECOMMISSIONED;
                                        updateBeacon();
                                    } else {
                                        String body = response.body().string();
                                        logErrorAndToast("Unsuccessful decommissionBeacon request: " + body);
                                    }
                                }
                            };
                            client.decommissionBeacon(decommissionCallback, beacon.getBeaconName());
                        }
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).show();
        }
    });

    attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider);
    attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel);
    attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout);

    // Fetch the namespace for the developer console project ID. We redraw the UI once that
    // request completes.
    // TODO: cache this.
    Callback listNamespacesCallback = new Callback() {
        @Override
        public void onFailure(Request request, IOException e) {
            logErrorAndToast("Failed request: " + request, e);
        }

        @Override
        public void onResponse(Response response) throws IOException {
            String body = response.body().string();
            if (response.isSuccessful()) {
                try {
                    JSONObject json = new JSONObject(body);
                    JSONArray namespaces = json.getJSONArray("namespaces");
                    // At present there can be only one namespace.
                    String tmp = namespaces.getJSONObject(0).getString("namespaceName");
                    if (tmp.startsWith("namespaces/")) {
                        namespace = tmp.substring("namespaces/".length());
                    } else {
                        namespace = tmp;
                    }
                    redraw();
                } catch (JSONException e) {
                    Log.e(TAG, "JSONException", e);
                }
            } else {
                logErrorAndToast("Unsuccessful listNamespaces request: " + body);
            }
        }
    };
    client.listNamespaces(listNamespacesCallback);
    return rootView;
}

From source file:adventure_fragments.Running.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);/*  w w  w .j av  a  2 s.co m*/
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemRunning(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsRunning();
                adapt = new CustomAdapter4(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_run);
                listItem.setAdapter(adapt);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}