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.sssemil.sonyirremote.ir.ir.java

private void sendKeyBool(final String filename) {
    File to = new File(filename);
    spinner = ((Spinner) findViewById(R.id.spinner));
    if (spinner.getSelectedItem() != null) {
        if (!to.exists()) {
            AlertDialog.Builder adb1 = new AlertDialog.Builder(this);
            adb1.setTitle(getString(R.string.warning));
            adb1.setMessage(getString(R.string.not_exists));
            adb1.setIcon(android.R.drawable.ic_dialog_alert);
            adb1.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    startLearning(filename);
                }/*from ww  w. j  a v  a2  s.co m*/
            });

            adb1.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                }
            });
            adb1.show();
        } else {
            sendAction(filename);
        }
    } else {
        AlertDialog.Builder adb = new AlertDialog.Builder(this);
        adb.setTitle(getString(R.string.error));
        adb.setMessage(getString(R.string.you_need_to_select));
        adb.setIcon(android.R.drawable.ic_dialog_alert);
        adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        adb.show();
    }

}

From source file:org.ambientdynamix.core.HomeActivity.java

private void updateCheck() {
    new Thread(new Runnable() {
        @Override/*from  ww w  . j av  a2  s .  co m*/
        public void run() {
            try {
                PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
                int verCode = pInfo.versionCode;
                DefaultHttpClient client = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet("http://repo.smartphone-experimentation.eu/app/");
                try {
                    HttpResponse execute = client.execute(httpGet);
                    InputStream content = execute.getEntity().getContent();

                    BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
                    StringBuilder builder = new StringBuilder();
                    String s = "";
                    while ((s = buffer.readLine()) != null) {
                        builder.append(s);
                    }

                    try {
                        if (verCode != Integer.parseInt(builder.toString())) {
                            {
                                final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(activity);
                                alertBuilder.setTitle("Update Available");
                                alertBuilder.setMessage(
                                        "There is a newer version available for Organicity Experimentation. "
                                                + "Please click 'Update' to download and install the latest version.");
                                alertBuilder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        Intent browserIntent = new Intent(Intent.ACTION_DEFAULT, Uri.parse(
                                                "http://repo.smartphone-experimentation.eu/app/dynamix-framework-debug.apk"));
                                        startActivity(browserIntent);
                                    }
                                });
                                alertBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        // User cancelled the dialog
                                    }
                                });
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        alertBuilder.show();
                                    }
                                });
                            }
                        }
                    } catch (Exception ignore) {
                    }
                } catch (Exception ignore) {
                }
            } catch (PackageManager.NameNotFoundException e) {
            }
        }
    }).start();
}

From source file:com.dvn.vindecoder.ui.seller.AddVehicalAndPayment.java

private void startDilog() {
    AlertDialog.Builder myAlertDilog = new AlertDialog.Builder(AddVehicalAndPayment.this);
    myAlertDilog.setTitle("Upload picture option..");
    myAlertDilog.setMessage("Take Photo");
    myAlertDilog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
        @Override//from w  w  w .  ja  va2  s  .  co m
        public void onClick(DialogInterface dialog, int which) {
            Intent picIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
            picIntent.setType("image/*");
            picIntent.putExtra("return_data", true);
            startActivityForResult(picIntent, GALLERY_REQUEST);
        }
    });
    myAlertDilog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (checkPermission(Manifest.permission.CAMERA, AddVehicalAndPayment.this)) {
                    openCameraApplication();
                } else {
                    requestPermission(AddVehicalAndPayment.this, new String[] { Manifest.permission.CAMERA },
                            REQUEST_ACESS_CAMERA);
                }
            } else {
                openCameraApplication();
            }
        }
    });
    myAlertDilog.show();
}

From source file:com.ccxt.whl.activity.SettingsFragment.java

/**
 * /*from  ww w. j a v a 2  s .com*/
 */
public void change_sex() {

    AlertDialog.Builder builder = new Builder(getActivity());
    String[] strarr = { "", "" };
    builder.setItems(strarr, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
            String sex = "2";
            // TODO ? 
            if (arg1 == 0) {//
                sex = "1";
            } else {//
                sex = "2";
            }
            RequestParams params = new RequestParams();
            params.add("user", DemoApplication.getInstance().getUser());
            params.add("sex", sex);
            params.add("param", "sex");
            params.add("uid", uid);
            HttpRestClient.get(Constant.UPDATE_USER_URL, params, responseHandler);
            pd.show();
        }
    });
    builder.show();
}

From source file:com.slp.rss_api.activity.EditFeedActivity.java

public void onClickOk(View view) {
    // only in insert mode

    final String name = mNameEditText.getText().toString().trim();
    final String urlOrSearch = mUrlEditText.getText().toString().trim();
    if (urlOrSearch.isEmpty()) {
        Toast.makeText(this, R.string.error_feed_error, Toast.LENGTH_SHORT).show();
    }//from   w w w .  j ava2 s  .  com

    if (!urlOrSearch.contains(".") || !urlOrSearch.contains("/") || urlOrSearch.contains(" ")) {
        final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this);
        pd.setMessage(getString(R.string.loading));
        pd.setCancelable(true);
        pd.setIndeterminate(true);
        pd.show();

        getLoaderManager().restartLoader(1, null,
                new LoaderManager.LoaderCallbacks<ArrayList<HashMap<String, String>>>() {

                    @Override
                    public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int id, Bundle args) {
                        String encodedSearchText = urlOrSearch;
                        try {
                            encodedSearchText = URLEncoder.encode(urlOrSearch, Constants.UTF8);
                        } catch (UnsupportedEncodingException ignored) {
                        }

                        return new GetFeedSearchResultsLoader(EditFeedActivity.this, encodedSearchText);
                    }

                    @Override
                    public void onLoadFinished(Loader<ArrayList<HashMap<String, String>>> loader,
                            final ArrayList<HashMap<String, String>> data) {
                        pd.cancel();

                        if (data == null) {
                            Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
                        } else if (data.isEmpty()) {
                            Toast.makeText(EditFeedActivity.this, R.string.no_result, Toast.LENGTH_SHORT)
                                    .show();
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(EditFeedActivity.this);
                            builder.setTitle(R.string.feed_search);

                            // create the grid item mapping
                            String[] from = new String[] { FEED_SEARCH_TITLE, FEED_SEARCH_DESC };
                            int[] to = new int[] { android.R.id.text1, android.R.id.text2 };

                            // fill in the grid_item layout
                            SimpleAdapter adapter = new SimpleAdapter(EditFeedActivity.this, data,
                                    R.layout.item_search_result, from, to);
                            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    FeedDataContentProvider.addFeed(EditFeedActivity.this,
                                            data.get(which).get(FEED_SEARCH_URL),
                                            name.isEmpty() ? data.get(which).get(FEED_SEARCH_TITLE) : name,
                                            mRetrieveFulltextCb.isChecked());

                                    setResult(RESULT_OK);
                                    finish();
                                }
                            });
                            builder.show();
                        }
                    }

                    @Override
                    public void onLoaderReset(Loader<ArrayList<HashMap<String, String>>> loader) {
                    }
                });
    } else {
        FeedDataContentProvider.addFeed(EditFeedActivity.this, urlOrSearch, name,
                mRetrieveFulltextCb.isChecked());

        setResult(RESULT_OK);
        finish();
    }
}

From source file:com.google.zxing.client.android.history.HistoryActivity.java

@Override
protected void onListItemClick(ListView l, View v, final int positionItemList, long id) {
    progDialog = new ProgressDialog(this);

    if (adapter.getItem(positionItemList).getResult() != null) {
        Intent intent = new Intent(this, CaptureActivity.class);
        intent.putExtra(Intents.History.ITEM_NUMBER, positionItemList);
        setResult(Activity.RESULT_OK, intent);

        AlertDialog.Builder builder2 = new AlertDialog.Builder(this, 3);
        builder2.setMessage(getBaseContext().getResources().getString(R.string.alerta_enviar_dado));
        builder2.setCancelable(true);//w  ww.j  a v  a2  s . c o  m
        builder2.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int i2) {

                /*
                 * mandando somente um dado para o servidor
                 */
                boolean conectado = verificaConexao();
                if (conectado) {
                    try {
                        progDialog.setTitle(
                                getBaseContext().getResources().getString(R.string.alerta_enviando_dado));
                        progDialog.setMessage(
                                getBaseContext().getResources().getString(R.string.alerta_dado_sendo_enviado));
                        progDialog.setIcon(android.R.drawable.ic_menu_upload);
                        progDialog.show();

                        String dado = adapter.getItem(positionItemList).getDisplay();
                        enviarItemHistorico(dado);

                    } catch (Exception ex) {
                        // TODO: handle exception
                        ex.printStackTrace();
                    }
                }
                dialog.dismiss();
                reloadHistoryItems();
            }
        });
        builder2.setNegativeButton(R.string.button_cancel, null);
        builder2.show();

    }

}

From source file:com.umeng.message.example.MainActivity.java

/**
 * //from  www . ja va 2s  . co m
 * @param view
 */
public void upload(View view) {

    List<Map<String, Object>> all = pushDao.getAll();

    if (all.size() == 0) {
        Toast.makeText(this, "?", Toast.LENGTH_SHORT).show();
        return;
    }

    // ??
    final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);
    builder.setTitle("Upload");
    builder.setMessage("");
    builder.setCancelable(false);
    builder.setNegativeButton("", null);

    // 
    final Button btn = (Button) view;
    btn.setText("uploading ...");
    btn.setClickable(false);

    RequestParams params = new RequestParams();
    params.put("act", "upload_push_msg");
    params.put("data", gson.toJson(all));
    Log.e("jsondata", gson.toJson(all));

    new AsyncHttpClient().post("http://cms.orenda.com.cn:29055/upload_data", params,
            new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    super.onSuccess(statusCode, headers, response);
                    String hasErrors = getString(response, "hasErrors");
                    if ("false".equals(hasErrors)) {
                        builder.setMessage("?");
                        pushDao.clear();
                    } else {
                        String msg = getString(response, "message");
                        Log.e("upload.hasError=true", msg);
                        builder.setMessage(msg);
                    }

                    btn.setText("UPLOAD");
                    btn.setClickable(true);
                    builder.show();
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, String responseString,
                        Throwable throwable) {
                    super.onFailure(statusCode, headers, responseString, throwable);
                    Log.e("onFailure1", String.valueOf(responseString) + "|" + throwable);
                    builder.show();
                    btn.setText("UPLOAD");
                    btn.setClickable(true);
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, Throwable throwable,
                        JSONArray errorResponse) {
                    super.onFailure(statusCode, headers, throwable, errorResponse);
                    Log.e("onFailure2", String.valueOf(errorResponse) + "|" + throwable);
                    builder.show();
                    btn.setText("UPLOAD");
                    btn.setClickable(true);
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, Throwable throwable,
                        JSONObject errorResponse) {
                    super.onFailure(statusCode, headers, throwable, errorResponse);
                    Log.e("onFailure3", String.valueOf(errorResponse) + "|" + throwable);
                    builder.show();
                    btn.setText("UPLOAD");
                    btn.setClickable(true);
                }
            });
}

From source file:fi.mikuz.boarder.gui.DropboxMenu.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dropbox_menu);
    setTitle("Dropbox");
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    APP_KEY = ApiKeyLoader.loadDropboxApiKey(this.getApplicationContext(), TAG);
    APP_SECRET = ApiKeyLoader.loadDropboxApiSecret(this.getApplicationContext(), TAG);

    AndroidAuthSession session = buildSession();
    mApi = new DropboxAPI<AndroidAuthSession>(session);

    try {/*from   w  w w  .  ja v a2s.co m*/
        loadCbla();
    } catch (NullPointerException npe) {
    }

    mDropboxContent = (LinearLayout) findViewById(R.id.dropbox_content);
    mAuthDropbox = (Button) findViewById(R.id.auth_button);
    mDropboxDownload = (Button) findViewById(R.id.dropbox_download);
    mDropboxUpload = (Button) findViewById(R.id.dropbox_upload);
    mSelectAll = (Button) findViewById(R.id.select_all);
    mStart = (Button) findViewById(R.id.start);

    mAuthDropbox.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // This logs you out if you're logged in, or vice versa
            if (mLoggedIn) {
                logOut();
            } else {
                // Start the remote authentication
                mApi.getSession().startAuthentication(DropboxMenu.this);
            }
        }
    });

    mDropboxDownload.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mOperation = DOWNLOAD_OPERATION;
            try {
                loadCbla();
            } catch (NullPointerException npe) {
            }
        }
    });

    mDropboxUpload.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mOperation = UPLOAD_OPERATION;
            try {
                loadCbla();
            } catch (NullPointerException npe) {
            }
        }
    });

    mSelectAll.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mCbla.selectAll();
        }
    });

    mStart.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            AlertDialog.Builder cleanerBuilder = new AlertDialog.Builder(DropboxMenu.this);
            cleanerBuilder.setTitle("Cleaner");
            if (mOperation == UPLOAD_OPERATION) {
                cleanerBuilder.setMessage(
                        "Do you want to clean files that are not found locally but only in Dropbox?");
            } else if (mOperation == DOWNLOAD_OPERATION) {
                cleanerBuilder.setMessage(
                        "Do you want to clean files that are not found in Dropbox but only locally?");
            }

            cleanerBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    boolean cleanUnusedFiles = true;
                    initializeTransfer(mCbla.getAllSelectedTitles(), cleanUnusedFiles);
                }

            });

            cleanerBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    boolean cleanUnusedFiles = false;
                    initializeTransfer(mCbla.getAllSelectedTitles(), cleanUnusedFiles);
                }
            });
            cleanerBuilder.show();
        }
    });

    // Display the proper UI state if logged in or not
    setLoggedIn(mApi.getSession().isLinked());

}

From source file:de.quadrillenschule.azocamsynca.job.JobProcessor.java

public void doTestShots(final TriggerPhotoSerie job) {
    final NikonIR camera = ((AzoTriggerServiceApplication) getActivity().getApplication()).getCamera();
    final JobProcessor jobProcessor = ((AzoTriggerServiceApplication) getActivity().getApplication())
            .getJobProcessor();/*w  w w.  j  a v a2  s.c o m*/

    final AlertDialog.Builder adb = new AlertDialog.Builder(getActivity(), R.style.dialog);
    job.setTriggerStatus(PhotoSerie.TriggerJobStatus.WAITFORUSER);
    adb.setTitle("Test Shots");
    adb.setMessage("This series collects all images during preparation of the project\n" + job.getProject()
            + "\n" + "Camera controls time: " + camera.isExposureSetOnCamera(job.getExposure()));
    if (!job.isToggleIsOpen()) {
        adb.setPositiveButton("Finish", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                job.setTriggerStatus(PhotoSerie.TriggerJobStatus.FINISHED_TRIGGERING);
                jobProcessor.fireJobProgressEvent(job);
                processingLoop();
            }
        });
    }

    adb.setNegativeButton("Trigger", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            camera.trigger();
            if (!camera.isExposureSetOnCamera(job.getExposure())) {
                job.setToggleIsOpen(!job.isToggleIsOpen());

                if (!job.isToggleIsOpen()) {
                    job.setNumber(job.getNumber() + 1);
                    job.setTriggered(job.getTriggered() + 1);

                }

            } else {
                job.setNumber(job.getNumber() + 1);
                job.setTriggered(job.getTriggered() + 1);
            }
            doTestShots(job);
        }
    });
    MediaPlayer mediaPlayer = MediaPlayer.create(activity, R.raw.oida_peda);
    mediaPlayer.start();
    // adb.create().show();
    adb.create();

    alertDialog = adb.show();
}

From source file:com.ved.musicmapapp.LoginAcitivity.java

public void goToHome() {
    if (prefs.getString("FB_ID", "").length() == 0) {
        Statics.showToast(this, "Cannot get your Facebook infor. Please try again!");
        return;/*from   w  w w.  j  av  a 2  s  .c  om*/
    }
    if (prefs.getString("FB_USERNAME", "").length() == 0 || prefs.getString("FB_USERNAME", "") == null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Message");
        builder.setMessage("Unable to log into app. Please try again!");
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                edt = prefs.edit();
                edt.putString("FB_ID", null);
                edt.commit();
                finish();
            }
        });
        builder.setNeutralButton("Try again", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                edt = prefs.edit();
                edt.putString("FB_ID", null);
                edt.commit();
                finish();
                Intent i = new Intent(LoginAcitivity.this, LoginAcitivity.class);
                startActivity(i);
            }
        });
        builder.show();
        return;
    }
    if (!prefs.getBoolean("first_login", false))
        return;
    finish();
    Intent i = new Intent(LoginAcitivity.this, MainActivity.class);
    i.putExtra("FOLLOW_FBID", getIntent().getStringExtra("FOLLOW_FBID"));
    startActivity(i);

    /*
     * if(Statics.curUser != null && (Statics.curUser.getFbid() != null &&
     * (Statics.curUser != null && Statics.curUser.getFullName() != null &&
     * Statics.curUser.getFullName().length() > 0))){ finish(); Intent i =
     * new Intent(LoginAcitivity.this, MainActivity.class);
     * i.putExtra("FOLLOW_FBID", getIntent().getStringExtra("FOLLOW_FBID"));
     * startActivity(i); }else{ AlertDialog.Builder builder = new
     * AlertDialog.Builder(this); builder.setTitle("Message");
     * builder.setMessage("Unable to log into app. Please try again!");
     * builder.setNegativeButton("Cancel", new
     * DialogInterface.OnClickListener() {
     * 
     * @Override public void onClick(DialogInterface dialog, int which) { //
     * TODO Auto-generated method stub edt.putString("FB_ID", null);
     * edt.commit(); finish(); } }); builder.setNeutralButton("Try again",
     * new DialogInterface.OnClickListener() {
     * 
     * @Override public void onClick(DialogInterface dialog, int which) { //
     * TODO Auto-generated method stub edt.putString("FB_ID", null);
     * edt.commit(); finish(); Intent i = new Intent(LoginAcitivity.this,
     * LoginAcitivity.class); startActivity(i); } }); builder.show(); }
     */
}