Example usage for android.app AlertDialog.Builder create

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

Introduction

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

Prototype

public void create() 

Source Link

Document

Forces immediate creation of the dialog.

Usage

From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.repeater_list);

    overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);

    lv = (ListView) findViewById(R.id.repeaterListView);
    tvAddress = (TextView) findViewById(R.id.tvAddress);

    xlocation = new Repeater("", LAT_DEFAULT, LNG_DEFAULT);

    rl = RepeaterListActivity.loadData(R.raw.repeaterdata5, this);
    xlocation.calcDistanceAll(rl);//from w w  w .j a  v a2 s  .  c om
    rl.sort();

    adapter = new RepeaterAdapter(this, rl, xlocation, local_distance, excludeLink, excludeDirection);

    lv.setFastScrollEnabled(true);
    lv.setVerticalFadingEdgeEnabled(false);
    lv.setVerticalScrollBarEnabled(true);
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(this);

    // SharedPreferences prefs = getSharedPreferences("Location",
    // MODE_PRIVATE);
    SharedPreferences prefshare = PreferenceManager.getDefaultSharedPreferences(this);
    int walkcount = prefshare.getInt("walkthrough", WALK_VERSION_CODE);
    if (walkcount < (WALK_VERSION_CODE + 1)) {
        Intent intent = new Intent();

        intent.setClassName(getApplicationContext(), "net.mypapit.mobile.myrepeater.SettingsActivity");
        startActivity(intent);

        intent.setClassName(getApplicationContext(), "net.mypapit.mobile.myrepeater.WalkthroughActivity");
        SharedPreferences.Editor prefEditor = prefshare.edit();
        walkcount++;

        SharedPreferences repeater_prefs = PreferenceManager.getDefaultSharedPreferences(this);

        m_deviceid = repeater_prefs.getString("deviceid", this.generateCallsign());
        prefEditor.putInt("walkthrough", walkcount);
        // prefEditor.putString("callsign", new
        // StringBuilder("9W2-").append(this.generateCallsign()).toString());
        prefEditor.putString("deviceid", m_deviceid);
        prefEditor.commit();

        startActivity(intent);

    }

    // need to put token to avoid app from popping up annoying select manual
    // dialog will be triggered if location/gps is not enabled AND if the
    // date in dd/MM is not equal to 'token' saved in StaticLocationActivity
    // location dialog
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM", Locale.US);
    Date date = new Date();

    SharedPreferences preftoken = getSharedPreferences("Location", MODE_PRIVATE);

    if (!this.isLocationEnabled(this)
            && !dateFormat.format(date).equalsIgnoreCase(preftoken.getString("token", "28/10"))) {

        // show dialog if Location Services is not enabled
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.gps_not_found_title); // GPS not found
        builder.setMessage(R.string.gps_not_found_message); // Want to
        // enable?

        // if yes - bring user to enable Location Service settings
        builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {

                Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                getApplicationContext().startActivity(intent);
            }
        });

        // if no - bring user to selecting Static Location Activity
        builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setClassName(getApplicationContext(),
                        "net.mypapit.mobile.myrepeater.StaticLocationActivity");
                startActivity(intent);

            }

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

    }

    new GPSThread(this).start();

    lv.setAdapter(adapter);

}

From source file:com.abc.driver.MainActivity.java

public void chooseTruckLength(View v) {
    mTLtv = (TextView) findViewById(R.id.truck_length_tv);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    GridView gridView1 = new GridView(this);
    gridView1.setNumColumns(3);//from  w w w  .ja  va  2s. c om
    // (GridView)findViewById(R.id.gridView1);
    SimpleAdapter adapter = new SimpleAdapter(this, mTruckLengthList, R.layout.truck_length_griditem,
            new String[] { "TITLE", "TLENGTH" }, new int[] { R.id.griditem_title, R.id.griditem_length, });

    gridView1.setAdapter(adapter);
    builder.setTitle("Please Choose");
    builder.setInverseBackgroundForced(true);
    builder.setView(gridView1);
    final Dialog dialog = builder.create();

    gridView1.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
            mTLtv.setText(((TextView) view.findViewById(R.id.griditem_title)).getText());
            mTruckLength = ((TextView) view.findViewById(R.id.griditem_length)).getText().toString();
            dialog.dismiss();
        }
    });
    // */

    dialog.show();

}

From source file:net.sourceforge.kalimbaradio.androidapp.activity.DownloadActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    if (id == DIALOG_SAVE_PLAYLIST) {
        AlertDialog.Builder builder;

        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        final View layout = inflater.inflate(R.layout.save_playlist,
                (ViewGroup) findViewById(R.id.save_playlist_root));
        playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name);

        builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.download_playlist_title);
        builder.setMessage(R.string.download_playlist_name);
        builder.setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() {
            @Override/* w w  w. ja v a 2 s .  c  o m*/
            public void onClick(DialogInterface dialog, int id) {
                savePlaylistInBackground(String.valueOf(playlistNameView.getText()));
            }
        });
        builder.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        builder.setView(layout);
        builder.setCancelable(true);

        return builder.create();
    } else {
        return super.onCreateDialog(id);
    }
}

From source file:com.otaupdater.SettingsActivity.java

private void showGetProKeyDialog() {
    if (cfg.hasProKey())
        return;/*from w  ww  .j av a2  s  .com*/

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.settings_prokey_title);
    final boolean playServices = Utils.checkPlayServices(this);
    builder.setItems(playServices ? R.array.prokey_ops : R.array.prokey_ops_nomarket,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    which -= playServices ? 1 : 0;
                    switch (which) {
                    case -1:
                        try {
                            Bundle buyIntentBundle = service.getBuyIntent(3, getPackageName(),
                                    Config.PROKEY_SKU, "inapp", null);
                            PendingIntent buyIntent = buyIntentBundle.getParcelable("BUY_INTENT");
                            if (buyIntent != null)
                                startIntentSenderForResult(buyIntent.getIntentSender(), PROKEY_REQ_CODE,
                                        new Intent(), 0, 0, 0);
                        } catch (Exception e) {
                            Toast.makeText(SettingsActivity.this, R.string.prokey_error_init,
                                    Toast.LENGTH_SHORT).show();
                        }
                        break;
                    case 0:
                        redeemProKey();
                        break;
                    //                case 1:
                    //                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Config.SITE_BASE_URL + Config.DONATE_URL)));
                    //                    break;
                    }
                }
            });

    final AlertDialog dlg = builder.create();
    dlg.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            onDialogShown(dlg);
        }
    });
    dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            onDialogClosed(dlg);
        }
    });
    dlg.show();
}

From source file:de.baumann.hhsmoodle.activities.Activity_count.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    toDo_title = sharedPref.getString("count_title", "");
    String count_title = sharedPref.getString("count_content", "");
    toDo_icon = sharedPref.getString("count_icon", "");
    toDo_create = sharedPref.getString("count_create", "");
    String todo_attachment = sharedPref.getString("count_attachment", "");
    if (!sharedPref.getString("count_seqno", "").isEmpty()) {
        toDo_seqno = Integer.parseInt(sharedPref.getString("count_seqno", ""));
    }//w  w w .  j a v  a 2s.  c  om

    setContentView(R.layout.activity_count);
    setTitle(toDo_title);

    final EditText etNewItem = (EditText) findViewById(R.id.etNewItem);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String itemText = etNewItem.getText().toString();

            if (itemText.isEmpty()) {
                Snackbar.make(lvItems, R.string.todo_enter, Snackbar.LENGTH_LONG).show();
            } else {
                itemsTitle.add(0, itemText);
                itemsCount.add(0, "0");
                etNewItem.setText("");
                writeItemsTitle();
                writeItemsCount();
                lvItems.post(new Runnable() {
                    public void run() {
                        lvItems.setSelection(lvItems.getCount() - 1);
                    }
                });
                adapter.notifyDataSetChanged();
            }
        }
    });

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    helper_main.onStart(Activity_count.this);

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    try {
        FileOutputStream fOut = new FileOutputStream(newFileTitle());
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(count_title);
        myOutWriter.close();

        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }

    try {
        FileOutputStream fOut = new FileOutputStream(newFileCount());
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(todo_attachment);
        myOutWriter.close();

        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }

    lvItems = (ListView) findViewById(R.id.lvItems);
    itemsTitle = new ArrayList<>();
    readItemsTitle();
    readItemsCount();

    adapter = new CustomListAdapter(Activity_count.this, itemsTitle, itemsCount) {
        @NonNull
        @Override
        public View getView(final int position, View convertView, @NonNull ViewGroup parent) {

            View v = super.getView(position, convertView, parent);
            ImageButton ib_plus = (ImageButton) v.findViewById(R.id.but_plus);
            ImageButton ib_minus = (ImageButton) v.findViewById(R.id.but_minus);
            TextView tv = (TextView) v.findViewById(R.id.count_count);

            int count = Integer.parseInt(itemsCount.get(position));

            if (count < 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_red));
            } else if (count > 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_green));
            } else if (count == 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_grey));
            }

            ib_plus.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    int a = Integer.parseInt(itemsCount.get(position)) + 1;
                    String plus = String.valueOf(a);

                    itemsCount.remove(position);
                    itemsCount.add(position, plus);
                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();

                }
            });

            ib_minus.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    int a = Integer.parseInt(itemsCount.get(position)) - 1;
                    String minus = String.valueOf(a);

                    itemsCount.remove(position);
                    itemsCount.add(position, minus);
                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();
                }
            });

            return v;
        }
    };

    lvItems.setAdapter(adapter);

    lvItems.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(android.widget.AdapterView<?> parent, View view, final int position, long id) {

            final String title = itemsTitle.get(position);
            final String count = itemsCount.get(position);

            AlertDialog.Builder builder = new AlertDialog.Builder(Activity_count.this);
            View dialogView = View.inflate(Activity_count.this, R.layout.dialog_edit_text_singleline_count,
                    null);

            final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
            edit_title.setText(title);

            builder.setView(dialogView);
            builder.setTitle(R.string.number_edit_entry);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                    String inputTag = edit_title.getText().toString().trim();
                    // Remove the item within array at position
                    itemsTitle.remove(position);
                    itemsCount.remove(position);

                    itemsTitle.add(position, inputTag);
                    itemsCount.add(position, count);

                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();
                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final AlertDialog dialog2 = builder.create();
            // Display the custom alert dialog on interface
            dialog2.show();
            helper_main.showKeyboard(Activity_count.this, edit_title);
        }
    });

    lvItems.setOnItemLongClickListener(new android.widget.AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(android.widget.AdapterView<?> parent, View view, final int position,
                long id) {

            final String title = itemsTitle.get(position);
            final String count = itemsCount.get(position);

            // Remove the item within array at position
            itemsTitle.remove(position);
            itemsCount.remove(position);
            // Refresh the adapter
            adapter.notifyDataSetChanged();
            // Return true consumes the long click event (marks it handled)
            writeItemsTitle();
            writeItemsCount();

            Snackbar snackbar = Snackbar.make(lvItems, R.string.todo_removed, Snackbar.LENGTH_LONG)
                    .setAction(R.string.todo_removed_back, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            itemsTitle.add(position, title);
                            itemsCount.add(position, count);
                            // Refresh the adapter
                            adapter.notifyDataSetChanged();
                            // Return true consumes the long click event (marks it handled)
                            writeItemsTitle();
                            writeItemsCount();
                        }
                    });
            snackbar.show();

            return true;
        }
    });
}

From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java

protected void prolong(final String a) {
    long age = System.currentTimeMillis() - refreshtime;
    if (refreshing || age > MAX_CACHE_AGE) {
        Toast.makeText(getActivity(), R.string.account_no_concurrent, Toast.LENGTH_LONG).show();
        if (!refreshing) {
            refresh();//from   w w w .  java 2 s  . co m
        }
        return;
    }

    MultiStepResultHelper<String> msrhProlong = new MultiStepResultHelper<>(getActivity(), a,
            R.string.doing_prolong);
    msrhProlong.setCallback(new Callback<String>() {
        @Override
        public void onSuccess(MultiStepResult result) {
            if (getActivity() == null) {
                return;
            }
            invalidateData();

            if (result.getMessage() != null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setMessage(result.getMessage()).setCancelable(false).setNegativeButton(R.string.close,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                AlertDialog alert = builder.create();
                alert.show();
            }
        }

        @Override
        public void onError(MultiStepResult result) {
            if (getActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage(result.getMessage()).setCancelable(true)
                    .setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface d, int id) {
                            d.cancel();
                        }
                    }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface d) {
                            if (d != null) {
                                d.cancel();
                            }
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }

        @Override
        public void onUnhandledResult(MultiStepResult result) {
        }

        @Override
        public void onUserCancel() {
        }

        @Override
        public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection,
                String argument) {
            return new ProlongTask(helper, useraction, selection, argument);
        }
    });
    msrhProlong.start();
}

From source file:com.abc.driver.MainActivity.java

public void chooseTruckType(View v) {
    mTTtv = (TextView) this.findViewById(R.id.truck_type_tv);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    GridView gridView1 = new GridView(this);
    gridView1.setNumColumns(3);//ww w .  j ava  2  s  . c  o m
    // (GridView)findViewById(R.id.gridView1);
    SimpleAdapter adapter = new SimpleAdapter(this, mTruckTypeList, R.layout.truck_type_griditem,
            new String[] { "PIC", "TITLE", "TTYPE" },
            new int[] { R.id.griditem_pic, R.id.griditem_title, R.id.griditem_type, });

    gridView1.setAdapter(adapter);
    builder.setTitle("Please Choose");
    builder.setInverseBackgroundForced(true);
    builder.setView(gridView1);
    final Dialog dialog = builder.create();

    gridView1.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
            mTTtv.setText(((TextView) view.findViewById(R.id.griditem_title)).getText());
            mTruckType = ((TextView) view.findViewById(R.id.griditem_type)).getText().toString();
            dialog.dismiss();
        }
    });
    dialog.show();
}