Example usage for android.app AlertDialog dismiss

List of usage examples for android.app AlertDialog dismiss

Introduction

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

Prototype

@Override
public void dismiss() 

Source Link

Document

Dismiss this dialog, removing it from the screen.

Usage

From source file:com.garrocho.MapActivity.java

@SuppressLint("NewApi")
@Override/*from w  w  w .j a va 2s .  c  o m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_map);
    if (savedInstanceState == null) {
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            musica = null;
        } else {
            musica = extras.getString("MUSICA");
        }
    } else {
        musica = (String) savedInstanceState.getSerializable("MUSICA");
    }

    mPrefs = new SimpleGeofenceStore(this);
    Intent intent = new Intent();
    intent.putStringArrayListExtra(String.valueOf(GeofenceUtils.LISTA_GEOFENCES_ADDED), null);

    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

    if (mMap != null) {

        mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

        mMap.setOnMapLongClickListener(new OnMapLongClickListener() {

            @Override
            public void onMapLongClick(final LatLng point) {
                CameraPosition INIT = new CameraPosition.Builder()
                        .target(new LatLng(point.latitude, point.longitude)).zoom(17.5F).build();
                mMap.animateCamera(CameraUpdateFactory.newCameraPosition(INIT));

                // TODO Auto-generated method stub
                String names[] = { "25", "50", "100", "200", "400" };
                final AlertDialog alertDialog = new AlertDialog.Builder(MapActivity.this,
                        android.R.style.Theme_Translucent).create();
                LayoutInflater inflater = getLayoutInflater();
                View convertView = (View) inflater.inflate(R.layout.custom, null);
                alertDialog.setView(convertView);
                alertDialog.setTitle("Selecione um Radius");
                ListView lv = (ListView) convertView.findViewById(R.id.listView1);
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(MapActivity.this,
                        android.R.layout.simple_list_item_1, names);
                lv.setAdapter(adapter);
                alertDialog.show();
                lv.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                        String item = ((TextView) arg1).getText().toString();

                        SimpleGeofence geofence = new SimpleGeofence(String.valueOf(mPrefs.getQtdeGeo() + 1),
                                point.latitude, point.longitude, Float.valueOf(item),
                                GEOFENCE_EXPIRATION_IN_MILLISECONDS, Geofence.GEOFENCE_TRANSITION_ENTER,
                                musica);

                        addMarkerForFence(geofence);
                        mPrefs.setGeofence(geofence.getId(), geofence);
                        lista.add(geofence.getId());
                        Intent intent = new Intent();
                        intent.putStringArrayListExtra(String.valueOf(GeofenceUtils.LISTA_GEOFENCES_ADDED),
                                lista);
                        MapActivity.this.setResult(Activity.RESULT_OK, intent);
                        alertDialog.dismiss();
                        Toast.makeText(MapActivity.this, "GeoFence Adicionada!", Toast.LENGTH_LONG).show();
                    }
                });
            }
        });

        desenharMakers();

        mMap.setMyLocationEnabled(true);

        Location location = mMap.getMyLocation();
        CameraPosition INIT = null;

        if (location == null) {
            locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
            location = getLastBestLocation();
        }

        INIT = new CameraPosition.Builder().target(new LatLng(location.getLatitude(), location.getLongitude()))
                .zoom(17.5F).build();

        if (INIT != null)
            mMap.animateCamera(CameraUpdateFactory.newCameraPosition(INIT));
    }
}

From source file:com.chaitu.lmscalendar.ui.UrlDialog.java

@Override
public void onStart() {
    super.onStart();
    final AlertDialog dlg = (AlertDialog) getDialog();
    if (dlg == null)
        return;//w  w  w. j  a  va 2  s.com

    View.OnClickListener onClickTask;
    onClickTask = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String url = mTextCalendarUrl.getText().toString();
            String username = mTextUsername.getText().toString();
            String password = mTextPassword.getText().toString();
            String calendar = mTextPassword.getText().toString();
            long sync_interval = mSpinnerSyncInterval.getSelectedItemId();
            CalendarModel calendarModel = (CalendarModel) mSpinnerCalendar.getSelectedItem();
            int calID = calendarModel.getId();
            String calName = calendarModel.getName();

            /*if (!mActivity.setSource(url, null, username, password)) {
            TextView label = (TextView) dlg.findViewById(R.id.TextViewUrlError);
            label.setText(R.string.invalid_url);
            return;
            }*/

            Intent intent = new Intent(getActivity(), AlarmReceiver.class);
            intent.putExtra(AlarmReceiver.ACTION_ALARM, AlarmReceiver.ACTION_ALARM);
            final PendingIntent pIntent = PendingIntent.getBroadcast(getActivity(), 1234567, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            AlarmManager alarms = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
            alarms.cancel(pIntent);

            Settings settings = mActivity.getSettings();
            settings.putString(Settings.PREF_LASTURL, url);

            settings.putString(Settings.PREF_LASTURLUSERNAME, username);
            settings.putString(Settings.PREF_LASTURLPASSWORD, password);
            settings.putString(Settings.PREF_LASTCALENDARNAME, calName);
            settings.putInt(Settings.PREF_LASTCALENDARID, calID);
            settings.putInt(Settings.PREF_LASTSYNCINTERVAL, (int) sync_interval);
            mActivity.startIntent();
            dlg.dismiss();

        }
    };

    dlg.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(onClickTask);

}

From source file:com.dattasmoon.pebble.plugin.EditNotificationActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "Selected menu item id: " + String.valueOf(item.getItemId()));
    }/*w  w  w  .j  a  v a  2 s  .  com*/
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View v;
    ListViewHolder viewHolder;
    AdapterView.AdapterContextMenuInfo contextInfo;
    String app_name;
    final String package_name;
    switch (item.getItemId()) {
    case R.id.btnUncheckAll:

        builder.setTitle(R.string.dialog_confirm_title);
        builder.setMessage(getString(R.string.dialog_uncheck_message));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int buttonId) {
                if (lvPackages == null || lvPackages.getAdapter() == null
                        || ((packageAdapter) lvPackages.getAdapter()).selected == null) {
                    //something went wrong
                    return;
                }
                ((packageAdapter) lvPackages.getAdapter()).selected.clear();
                lvPackages.invalidateViews();
            }
        });
        builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int buttonId) {
                //do nothing!
            }
        });
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.show();

        return true;
    case R.id.btnSave:
        finish();
        return true;
    case R.id.btnDonate:
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(Constants.DONATION_URL));
        startActivity(i);
        return true;
    case R.id.btnSettings:
        Intent settings = new Intent(this, SettingsActivity.class);
        startActivity(settings);
        return true;
    case R.id.btnRename:
        contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        int position = contextInfo.position;
        long id = contextInfo.id;
        // the child view who's info we're viewing (should be equal to v)
        v = contextInfo.targetView;
        app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString();
        viewHolder = (ListViewHolder) v.getTag();
        if (viewHolder == null || viewHolder.chkEnabled == null) {
            //failure
            return true;
        }
        package_name = (String) viewHolder.chkEnabled.getTag();
        builder.setTitle(R.string.dialog_title_rename_notification);
        final EditText input = new EditText(this);
        input.setHint(app_name);
        builder.setView(input);
        builder.setPositiveButton(R.string.confirm, null);
        builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //do nothing
            }
        });
        final AlertDialog d = builder.create();
        d.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
                if (b != null) {
                    b.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //can't be nothing
                            if (input.getText().length() > 0) {
                                if (Constants.IS_LOGGABLE) {
                                    Log.i(Constants.LOG_TAG,
                                            "Adding rename for " + package_name + " to " + input.getText());
                                }
                                JSONObject rename = new JSONObject();
                                try {
                                    rename.put("pkg", package_name);
                                    rename.put("to", input.getText());
                                    arrayRenames.put(rename);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged();

                                d.dismiss();
                            } else {
                                input.setText(R.string.error_cant_be_blank);
                            }

                        }
                    });
                }
            }
        });

        d.show();

        return true;
    case R.id.btnRemoveRename:
        contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        // the child view who's info we're viewing (should be equal to v)
        v = contextInfo.targetView;
        app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString();
        viewHolder = (ListViewHolder) v.getTag();
        if (viewHolder == null || viewHolder.chkEnabled == null) {
            if (Constants.IS_LOGGABLE) {
                Log.i(Constants.LOG_TAG, "Viewholder is null or chkEnabled is null");
            }
            //failure
            return true;
        }
        package_name = (String) viewHolder.chkEnabled.getTag();
        builder.setTitle(
                getString(R.string.dialog_title_remove_rename) + app_name + " (" + package_name + ")?");
        builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "Before remove is: " + String.valueOf(arrayRenames.length()));
                }
                JSONArray tmp = new JSONArray();
                try {
                    for (int i = 0; i < arrayRenames.length(); i++) {
                        if (!arrayRenames.getJSONObject(i).getString("pkg").equalsIgnoreCase(package_name)) {
                            tmp.put(arrayRenames.getJSONObject(i));
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                arrayRenames = tmp;
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "After remove is: " + String.valueOf(arrayRenames.length()));
                }
                ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged();
            }
        });
        builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //do nothing
            }
        });
        builder.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.java

/**
 * setup a filter// ww  w. jav  a  2s.  c  o  m
 */
private void filter() {
    Log.v(TAG, "setting filter");
    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(HciDebuggerActivity.this);

    LayoutInflater inflater = getLayoutInflater();
    final View dialogView = inflater.inflate(R.layout.filter_dialog, null);
    dialogBuilder.setView(dialogView);

    //packet type
    setupSpinnerAdapter(R.array.packet_type_array, dialogView, R.id.packet_type_filter,
            filters.getPacketTypeFilter());

    //event type
    setupSpinnerAdapter(R.array.event_type_array, dialogView, R.id.event_type_filter,
            filters.getEventTypeFilter());

    //ogf
    setupSpinnerAdapter(R.array.ogf_array, dialogView, R.id.cmd_ogf_filter, filters.getOgfFilter());

    //subevent_type_filter
    setupSpinnerAdapter(R.array.subevent_array, dialogView, R.id.subevent_type_filter,
            filters.getSubeventFilter());

    EditText addressText = (EditText) dialogView.findViewById(R.id.device_address_edit);
    addressText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            filters.setAddress(s.toString());

            SharedPreferences.Editor editor = prefs.edit();
            editor.putString(Constants.PREFERENCES_ADVERTISING_ADDR, s.toString());
            editor.commit();
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
    addressText.setText(filters.getAdvertizingAddr());

    final AlertDialog alertDialog = dialogBuilder.create();

    final Button button_withdraw_filter = (Button) dialogView.findViewById(R.id.button_withdraw_filter);

    if (isFiltered)
        button_withdraw_filter.setVisibility(View.VISIBLE);
    else
        button_withdraw_filter.setVisibility(View.GONE);

    button_withdraw_filter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            isFiltered = false;
            packetAdapter.setPacketList(packetList);
            notifyAdapter();

            alertDialog.cancel();
            alertDialog.dismiss();
            packetFilteredList.clear();
        }
    });

    Button button_apply = (Button) dialogView.findViewById(R.id.button_apply_filter);

    button_apply.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Spinner packet_type_filter = (Spinner) dialogView.findViewById(R.id.packet_type_filter);
            Spinner ogf_filter = (Spinner) dialogView.findViewById(R.id.cmd_ogf_filter);
            Spinner event_type_filter = (Spinner) dialogView.findViewById(R.id.event_type_filter);
            Spinner subevent_type_filter = (Spinner) dialogView.findViewById(R.id.subevent_type_filter);
            EditText device_address_edit = (EditText) dialogView.findViewById(R.id.device_address_edit);

            filters = new Filters(HciDebuggerActivity.this, packet_type_filter.getSelectedItem().toString(),
                    event_type_filter.getSelectedItem().toString(), ogf_filter.getSelectedItem().toString(),
                    subevent_type_filter.getSelectedItem().toString(),
                    device_address_edit.getText().toString());

            packetFilteredList = new ArrayList<Packet>();
            for (int i = 0; i < packetList.size(); i++) {

                if (matchFilter(packetList.get(i))) {
                    packetFilteredList.add(packetList.get(i));
                }
            }

            isFiltered = true;

            packetAdapter.setPacketList(packetFilteredList);
            notifyAdapter();

            alertDialog.cancel();
            alertDialog.dismiss();
        }
    });

    Button button_cancel = (Button) dialogView.findViewById(R.id.button_cancel_filter);

    button_cancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alertDialog.cancel();
            alertDialog.dismiss();
        }
    });

    alertDialog.show();
}

From source file:org.odk.collect.android.activities.MainMenuActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case PASSWORD_DIALOG:

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final AlertDialog passwordDialog = builder.create();
        passwordDialog.setTitle(getString(R.string.enter_admin_password));
        LayoutInflater inflater = this.getLayoutInflater();
        View dialogView = inflater.inflate(R.layout.dialogbox_layout, null);
        passwordDialog.setView(dialogView, 20, 10, 20, 10);
        final CheckBox checkBox = (CheckBox) dialogView.findViewById(R.id.checkBox);
        final EditText input = (EditText) dialogView.findViewById(R.id.editText);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override//from w w w .  java  2 s .c o m
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (!checkBox.isChecked()) {
                    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                } else {
                    input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
            }
        });
        passwordDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String value = input.getText().toString();
                        String pw = adminPreferences.getString(AdminKeys.KEY_ADMIN_PW, "");
                        if (pw.compareTo(value) == 0) {
                            Intent i = new Intent(getApplicationContext(), AdminPreferencesActivity.class);
                            startActivity(i);
                            input.setText("");
                            passwordDialog.dismiss();
                        } else {
                            ToastUtils.showShortToast(R.string.admin_password_incorrect);
                            Collect.getInstance().getActivityLogger().logAction(this, "adminPasswordDialog",
                                    "PASSWORD_INCORRECT");
                        }
                    }
                });

        passwordDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        Collect.getInstance().getActivityLogger().logAction(this, "adminPasswordDialog",
                                "cancel");
                        input.setText("");
                        return;
                    }
                });

        passwordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        return passwordDialog;

    }
    return null;
}

From source file:es.ugr.swad.swadroid.modules.downloads.DownloadsManager.java

/**
 * Method that shows information file and allows its download
 * It has a button to confirm the download. If It is confirmed  getFile will be requested to get the link
 *//*ww  w. ja va2 s  .  c  om*/
private AlertDialog createFileInfoDialog(String name, long size, long time, String uploader, long fileCode,
        String license) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    AlertDialog dialog;
    final long code = fileCode;
    this.fileSize = size;

    Date d = new Date(time * 1000);
    java.text.DateFormat dateShortFormat = android.text.format.DateFormat.getDateFormat(this);
    java.text.DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(this);

    String uploaderName;
    if (uploader.compareTo("") != 0)
        uploaderName = uploader;
    else
        uploaderName = this.getResources().getString(R.string.unknown);

    StringBuilder message;

    Resources res = getResources();

    message = new StringBuilder(res.getString(R.string.fileTitle)).append(" ").append(name).append("\n")
            .append(getString(R.string.sizeFileTitle)).append(" ")
            .append(DownloadFactory.humanReadableByteCount(size, true)).append("\n")
            .append(res.getString(R.string.uploaderTitle)).append(" ").append(uploaderName).append("\n")
            .append(res.getString(R.string.licenseType)).append(" ").append(license).append("\n")
            .append(res.getString(R.string.creationTimeTitle)).append(" ").append(dateShortFormat.format(d))
            .append("  ").append(timeFormat.format(d));

    builder.setTitle(name);
    builder.setMessage(message);
    builder.setPositiveButton(R.string.downloadFileTitle, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            requestGetFile(code);
        }
    });
    builder.setNegativeButton(R.string.cancelMsg, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });

    dialog = builder.create();
    return dialog;
}

From source file:com.hybris.mobile.app.commerce.adapter.AccountPaymentAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    View rowView;/*from   w ww  .j a va2 s.com*/

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rowView = inflater.inflate(R.layout.item_payment_details, parent, false);
        rowView.setTag(new PaymentViewHolder(rowView, position));
    } else {
        rowView = convertView;
    }

    PaymentViewHolder mPaymentViewHolder = (PaymentViewHolder) rowView.getTag();

    final PaymentDetails paymentDetails = getItem(position);

    if (paymentDetails != null) {

        mPaymentViewHolder.paymentCardholderName.setText(paymentDetails.getAccountHolderName());
        mPaymentViewHolder.cardDetails
                .setText(paymentDetails.getCardType().getName() + "\n" + paymentDetails.getCardNumber() + "\n"
                        + paymentDetails.getExpiryMonth() + "/" + paymentDetails.getExpiryYear());

        if (paymentDetails.getBillingAddress() != null) {

            mPaymentViewHolder.billingAddress
                    .setText(StringUtils.isNotBlank(paymentDetails.getBillingAddress().getFormattedAddress())
                            ? paymentDetails.getBillingAddress().getFormattedAddress()
                            : paymentDetails.getBillingAddress().getLine1() + " "
                                    + paymentDetails.getBillingAddress().getLine2() + ",\n "
                                    + paymentDetails.getBillingAddress().getTown() + " "
                                    + paymentDetails.getBillingAddress().getPostalCode());
        }

        mPaymentViewHolder.paymentDefaultImageView.setVisibility(View.GONE);
        mPaymentViewHolder.paymentSetDefaultButton.setVisibility(View.INVISIBLE);

        mPaymentViewHolder.paymentDefaultImageView.setVisibility(position == 0 ? View.VISIBLE : View.INVISIBLE);
        //mPaymentViewHolder.paymentSetDefaultButton.setVisibility(position == 0 ? View.INVISIBLE : View.VISIBLE);
        mPaymentViewHolder.paymentDeleteButton.setVisibility(View.VISIBLE);

        mPaymentViewHolder.paymentSetDefaultButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                setDefaultPayment(paymentDetails);
                Alert.showSuccess(getContext(),
                        getContext().getString(R.string.payment_default_updated_message));

            }
        });

        mPaymentViewHolder.paymentDetailsLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mOnPaymentSelectedListener.onPaymentSelected(paymentDetails);
            }
        });
    }

    mPaymentViewHolder.paymentDeleteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog dialog;
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setMessage(R.string.payment_delete_message)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                            QueryPayment queryPayment = new QueryPayment();
                            queryPayment.setPaymentDetailsId(paymentDetails.getId());

                            CommerceApplication.getContentServiceHelper()
                                    .deleteUserPaymentDetails(new ResponseReceiverEmpty() {
                                        @Override
                                        public void onResponse(Response<EmptyResponse> response) {

                                            Alert.showSuccess(getContext(), getContext()
                                                    .getString(R.string.payment_delete_success_message));

                                            if (position < mPaymentList.size()) {
                                                mPaymentList.remove(position);
                                            }
                                            mOnPaymentSelectedListener.onPaymentListRefreshed();

                                            //Default is the first but if deleted select the next one as default
                                            if (mPaymentList != null && !mPaymentList.isEmpty()
                                                    && position == 0) {
                                                setDefaultPayment(mPaymentList.get(0));
                                            }
                                        }

                                        @Override
                                        public void onError(Response<ErrorList> response) {

                                        }
                                    }, null, queryPayment, null, false, null, null);

                            dialog.dismiss();

                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });

            dialog = builder.create();
            dialog.show();
        }
    });

    return rowView;
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Creates and shows a custom Alert dialog that will execute
 * the actions specified for positive, negative and 
 * neutral buttons.// ww  w  .j a  v  a2 s. co  m
 * 
 * @param context
 * @param title
 * @param message
 * @param positiveBtnActions   Can be null. When null button is not shown.
 * @param negativeBtnActions   Can be null. When null button is not shown.
 * @param neutralBtnActions   Can be null.
 */
public static void dialog_showCustomActionsDialog(Context context, String title, String message,
        String positiveBtnText, final Runnable positiveBtnActions, String negativeBtnText,
        final Runnable negativeBtnActions, String neutralBtnText, final Runnable neutralBtnActions) {

    AlertDialog dialog = new AlertDialog.Builder(context).create();

    dialog.setTitle(title);
    dialog.setMessage(message);

    dialog.setCancelable(true);
    dialog.setButton(AlertDialog.BUTTON_NEUTRAL, neutralBtnText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            if (neutralBtnActions != null) {
                neutralBtnActions.run();
            }
            dialog.dismiss();
        }
    });

    if (negativeBtnActions != null) {
        dialog.setButton(AlertDialog.BUTTON_NEGATIVE, negativeBtnText, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                negativeBtnActions.run();
            }
        });
    }

    if (positiveBtnActions != null) {
        dialog.setButton(AlertDialog.BUTTON_POSITIVE, positiveBtnText, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                positiveBtnActions.run();
            }
        });
    }

    dialog.show();
}

From source file:org.awesomeapp.messenger.MainActivity.java

public void showGroupChatDialog() {

    // This example shows how to add a custom layout to an AlertDialog
    LayoutInflater factory = LayoutInflater.from(this);

    final View dialogGroup = factory.inflate(R.layout.alert_dialog_group_chat, null);
    //TextView tvServer = (TextView) dialogGroup.findViewById(R.id.chat_server);
    // tvServer.setText(ImApp.DEFAULT_GROUPCHAT_SERVER);// need to make this a list

    // final Spinner listAccounts = (Spinner) dialogGroup.findViewById(R.id.choose_list);
    // setupAccountSpinner(listAccounts);

    AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.create_group).setView(dialogGroup)
            .setPositiveButton(R.string.connect, new DialogInterface.OnClickListener() {
                @Override/*from w w w  . j  av  a  2  s  .c o m*/
                public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked OK so do some stuff */

                    String chatRoom = null;
                    String chatServer = "";
                    String nickname = "";

                    TextView tv = (TextView) dialogGroup.findViewById(R.id.chat_room);
                    chatRoom = tv.getText().toString();

                    /**
                     tv = (TextView) dialogGroup.findViewById(R.id.chat_server);
                     chatServer = tv.getText().toString();
                            
                     tv = (TextView) dialogGroup.findViewById(R.id.nickname);
                     nickname = tv.getText().toString();
                     **/

                    try {
                        IImConnection conn = mApp.getConnection(mApp.getDefaultProviderId(),
                                mApp.getDefaultAccountId());
                        if (conn.getState() == ImConnection.LOGGED_IN)
                            startGroupChat(chatRoom, chatServer, nickname, null, conn);

                    } catch (RemoteException re) {

                    }

                    dialog.dismiss();

                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked cancel so do some stuff */
                    dialog.dismiss();
                }
            }).create();
    dialog.show();

    Typeface typeface;

    if ((typeface = CustomTypefaceManager.getCurrentTypeface(this)) != null) {
        TextView textView = (TextView) dialog.findViewById(android.R.id.message);
        if (textView != null)
            textView.setTypeface(typeface);

        textView = (TextView) dialog.findViewById(R.id.alertTitle);
        if (textView != null)
            textView.setTypeface(typeface);

        Button btn = (Button) dialog.findViewById(android.R.id.button1);
        if (btn != null)
            btn.setTypeface(typeface);

        btn = (Button) dialog.findViewById(android.R.id.button2);
        if (btn != null)
            btn.setTypeface(typeface);

        btn = (Button) dialog.findViewById(android.R.id.button3);
        if (btn != null)
            btn.setTypeface(typeface);

    }

}

From source file:com.fitme.MainActivity.java

public void onTrainingEditRequested(final TrainingRow oldTrain, final TrainingsListAdapter tla) {
    final Activity activity = MainActivity.this;
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(getString(R.string.title_upd_training_dialog));
    builder.setView(getLayoutInflater().inflate(R.layout.dialog_add_training, null));
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog trainDialog = builder.create();
    trainDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override//from  w w w.ja  v  a2  s  .  c om
        public void onShow(DialogInterface dialog) {
            Button positive = trainDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    EditText etName = (EditText) trainDialog.findViewById(R.id.edittext_training_name);
                    String trainName = etName.getText().toString();
                    // Validating form fields
                    // Check if program name changed
                    if (!trainName.equals(oldTrain.getName())) {
                        // If chanded - check it
                        // Check if empty
                        if (trainName.isEmpty()) {
                            Toast.makeText(MainActivity.this, getString(R.string.toast_err_training_empty),
                                    Toast.LENGTH_SHORT).show();
                            return;
                        }
                        // Check if training already exists

                        TrainingDAO td = new TrainingDAO(MainActivity.this);
                        long programId = getActiveProgramId();
                        if (td.getTrainingByName(programId, trainName)
                                .getId() != TrainingDAO.ID_TRAINING_NOT_FOUND) {
                            Toast.makeText(MainActivity.this, getString(R.string.toast_err_training_exists),
                                    Toast.LENGTH_SHORT).show();
                            return;
                        }
                    } else {
                        // if program name stays the same - do nothing
                        trainDialog.dismiss();
                        return;

                    }

                    // if everything is ok - update program record
                    TrainingDAO td = new TrainingDAO(activity);
                    Training t = new Training();
                    long programId = getActiveProgramId();
                    t.setName(trainName);
                    t.setProgramId(programId);
                    t.setId(oldTrain.getId());
                    td.updateTraining(t);
                    Toast.makeText(activity, getText(R.string.toast_upd_training_ok), Toast.LENGTH_SHORT)
                            .show();
                    tla.updateTraining(t);
                    trainDialog.dismiss();
                }
            });

        }
    });
    trainDialog.show();
    // Initiate data with old program entry
    EditText etName = (EditText) trainDialog.findViewById(R.id.edittext_training_name);
    etName.setText(oldTrain.getName());
}