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:com.fabernovel.alertevoirie.ReportDetailsActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    //Log.d("AlerteVoirie_PM", "Result : " + requestCode);
    switch (requestCode) {
    case R.id.existing_incidents_add_picture:
    case R.id.ImageView_far:
    case R.id.ImageView_close:
        if (resultCode == RESULT_OK) {
            try {

                String finalPath;

                if (data != null) {
                    Uri path = data.getData();
                    // OI FILE Manager
                    String filemanagerString = path.getPath();
                    // MEDIA GALLERY
                    String selectedImagePath = getPath(path);

                    if (selectedImagePath != null) {
                        finalPath = selectedImagePath;
                        System.out.println("selectedImagePath is the right one for you! " + finalPath);
                    } else {
                        finalPath = filemanagerString;
                        System.out.println("filemanagerstring is the right one for you!" + finalPath);
                    }//  w  w w .  j av  a  2 s.  com
                    // boolean isImage = true;
                } else {
                    finalPath = uriOfPicFromCamera.getPath();
                }

                // if (data == null || getMimeType(finalPath).startsWith("image")) {
                InputStream in;
                BitmapFactory.Options opt = new BitmapFactory.Options();

                // get the sample size to have a smaller image
                in = getContentResolver().openInputStream(Uri.fromFile(new File(finalPath)));
                opt.inSampleSize = getSampleSize(
                        getContentResolver().openInputStream(Uri.fromFile(new File(finalPath))));
                in.close();

                // decode a sampled version of the picture
                in = getContentResolver().openInputStream(Uri.fromFile(new File(finalPath)));
                Bitmap picture = BitmapFactory.decodeStream(in, null, opt);

                // Bitmap picture = BitmapFactory.decodeFile(finalPath);
                in.close();

                File f = new File(uriOfPicFromCamera.getPath());
                f.delete();

                // save the new image
                String pictureName = requestCode == R.id.ImageView_close ? CAPTURE_CLOSE : CAPTURE_FAR;
                FileOutputStream fos = openFileOutput(pictureName, MODE_PRIVATE);

                picture.compress(CompressFormat.JPEG, 80, fos);
                fos.close();

                if (requestCode == R.id.ImageView_far || mAdditionalImageType == ADDITIONAL_IMAGE_TYPE_FAR) {
                    loadZoom();
                } else if (mAdditionalImageType == ADDITIONAL_IMAGE_TYPE_CLOSE) {
                    File img = new File(getFilesDir() + "/" + CAPTURE_FAR);
                    mCurrentAction = ACTION_ADD_IMAGE;
                    timeoutHandler.postDelayed(timeout, TIMEOUT);
                    AVService.getInstance(this).postImage(this, Utils.getUdid(this), "",
                            Long.toString(currentIncident.id), null, img, false);
                }

                if (requestCode != R.id.existing_incidents_add_picture) {
                    setPictureToImageView(pictureName, (ImageView) findViewById(requestCode));
                }

                if (requestCode == R.id.ImageView_far
                        && ((TextView) findViewById(R.id.TextView_address)).getText().length() > 0) {
                    ((Button) findViewById(R.id.Button_validate)).setEnabled(true);
                }
                // }

                // FileOutputStream fos = openFileOutput("capture", MODE_WORLD_READABLE);
                // InputStream in = getContentResolver().openInputStream(uriOfPicFromCamera);
                // Utils.fromInputToOutput(in, fos);
                // fos.close();
                // in.close();

                mAdditionalImageType = 0;
            } catch (FileNotFoundException e) {
                Log.e("AlerteVoirie_PM", "", e);
            } catch (IOException e) {
                Log.e("AlerteVoirie_PM", "", e);
            } catch (NullPointerException e) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                AlertDialog alert;
                builder.setMessage("Image invalide").setCancelable(false).setPositiveButton("Ok", null);
                alert = builder.create();
                alert.show();
            }

        } else if (resultCode == RESULT_CANCELED) {
            if (uriOfPicFromCamera != null) {
                File tmpFile = new File(uriOfPicFromCamera.getPath());
                tmpFile.delete();
                uriOfPicFromCamera = null;
            }
        }
        break;

    case REQUEST_CATEGORY:
        if (resultCode == RESULT_OK) {
            setCategory(data.getLongExtra(IntentData.EXTRA_CATEGORY_ID, -1));
            // TODO do this when update request ready
            findViewById(R.id.Button_validate).setVisibility(View.VISIBLE);
        }
        break;
    case REQUEST_POSITION:
        if (resultCode == RESULT_OK) {
            currentIncident.address = data.getStringExtra(IntentData.EXTRA_ADDRESS);
            currentIncident.longitude = data.getDoubleExtra(IntentData.EXTRA_LONGITUDE, 0);
            currentIncident.latitude = data.getDoubleExtra(IntentData.EXTRA_LATITUDE, 0);
            ((TextView) findViewById(R.id.TextView_address)).setText(currentIncident.address);
            if (currentIncident.address != null && currentIncident.address.length() > 0 && canvalidate) {
                ((Button) findViewById(R.id.Button_validate)).setEnabled(true);
            }
            findViewById(R.id.Button_validate).setVisibility(View.VISIBLE);
        }
        break;
    case REQUEST_COMMENT:
        if (resultCode == RESULT_OK) {
            currentIncident.description = data.getStringExtra(IntentData.EXTRA_COMMENT);
            ((TextView) findViewById(R.id.TextView_comment)).setText(currentIncident.description);
            if (currentIncident.description != null)
                findViewById(R.id.TextView_nocomment).setVisibility(View.GONE);
            // findViewById(R.id.Button_validate).setVisibility(View.VISIBLE);
        }
        break;
    case REQUEST_IMAGE_COMMENT:
        if (resultCode == RESULT_OK) {
            showDialog(DIALOG_PROGRESS);
            File img = new File(getFilesDir() + "/arrowed.jpg");
            mCurrentAction = ACTION_ADD_IMAGE;
            timeoutHandler.postDelayed(timeout, TIMEOUT);
            AVService.getInstance(this).postImage(this, Utils.getUdid(this),
                    data.getStringExtra(IntentData.EXTRA_COMMENT), Long.toString(currentIncident.id), img, null,
                    false);
        }
        break;
    case REQUEST_COMMENT_BEFORE_EXIT:
        if (resultCode == RESULT_OK) {
            currentIncident.description = data.getStringExtra(IntentData.EXTRA_COMMENT);
            ((TextView) findViewById(R.id.TextView_comment)).setText(currentIncident.description);
            postNewIncident();
        }
        break;
    case REQUEST_DETAILS:
        if (resultCode == RESULT_OK) {
            // startActivityForResult(data, requestCode)

            if (mCurrentAction == ACTION_ADD_IMAGE) {
                Intent i = new Intent(getApplicationContext(), AddCommentActivity.class);
                startActivityForResult(i, REQUEST_IMAGE_COMMENT);
            } else {
                // set new img
                setPictureToImageView("arrowed.jpg", (ImageView) findViewById(R.id.ImageView_far));
                loadComment(REQUEST_COMMENT);
            }

        }
        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
}

From source file:com.alex.smartwomanmiddleeastfem.WebViewDemoActivity.java

@SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled" })
@Override/*from w  ww.  ja  v  a 2s .co  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.mainn);

    Intent intent = getIntent();
    reg = intent.getBooleanExtra("reg", false);

    i = (ImageView) findViewById(R.id.hj);

    try {

        big = new GifAnimationDrawable(getResources().openRawResource(R.raw.anim2));
        // big.setOneShot(true);
        android.util.Log.v("GifAnimationDrawable", "===>Four");
    } catch (IOException ioe) {

    }

    i.setImageDrawable(big);
    big.setVisible(true, true);

    sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
    // historyStack = new LinkedList<Link>();
    webview = (WebView) findViewById(R.id.webkit);

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webSettings.setDomStorageEnabled(true);
    // webview.addJavascriptInterface(new WebViewDemoActivity(), "Android");
    // webview.getSettings().setJavaScriptEnabled(true);

    webview.getSettings().setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        // webview.getSettings().setPluginState(PluginState.ON);
        // webview.getSettings().setJavaScriptEnabled(true);
    } else {
        // IMPORTANT!! this method is no longer available since Android 4.3
        // so the code doesn't compile anymore
        // webview.getSettings().setPluginsEnabled(true);
    }

    // Internet

    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    connected = false;
    if ((null != connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) && connectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED)
            || (null != connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) && connectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED)) {
        // we are connected to a network
        connected = true;
    }

    if (connected == false) {
        /*
         * Toast.makeText(Rss.this,
         * "Connect to internet and Restart Application",
         * Toast.LENGTH_SHORT).show();
         */
        webview.setVisibility(View.INVISIBLE);

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(WebViewDemoActivity.this);

        // alertDialogBuilder.setTitle("Please connect to Internet");
        alertDialogBuilder.setMessage(
                "Through our app offers some offline features, in order to stay actively connected to the SmartWoman community in realtime, you need an internet connection, tap here to check your settings or wait until you have connection.");
        // set positive button: Yes message

        alertDialogBuilder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // cancel the alert box and put a Toast to the user

                startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
            }
        });
        AlertDialog alertDialog = alertDialogBuilder.create();
        // show alert
        alertDialog.show();

    }

    // downloads
    // webview.setDownloadListener(new CustomDownloadListener());

    webview.setWebViewClient(new CustomWebViewClient());

    webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {

        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
        }

        @Override
        public void onReceivedIcon(WebView view, Bitmap icon) {

        }

    });

    // http://stackoverflow.com/questions/2083909/android-webview-refusing-user-input
    webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                    v.requestFocus();
                }
                break;
            }
            return false;
        }

    });

    if (reg == true) {
        if (Locale.getDefault().getLanguage().equals("es")) {

            webview.loadUrl("http://www.qa-msmartwoman.com/member/register");
            // webview.loadUrl("http://live-juice-guru.gotpantheon.com/user/login");
        } else {
            webview.loadUrl("http://www.qa-msmartwoman.com/member/register");
        }

        webview.requestFocus();
    } else {
        uhdj = sp.getString("your_int_key", "0");

        //   Log.e("Url is here ..............................", uhdj);
        // Welcome page loaded from assets directory
        if (Locale.getDefault().getLanguage().equals("es")) {

            webview.loadUrl(uhdj);
            // webview.loadUrl("http://live-juice-guru.gotpantheon.com/user/login");
        } else {
            webview.loadUrl(uhdj);
        }

        webview.requestFocus();
    }

}

From source file:com.mobicage.rogerthat.plugins.messaging.AttachmentViewerActivity.java

@SuppressLint({ "SetJavaScriptEnabled" })
protected void updateView(boolean isUpdate) {
    T.UI();//from   www  .j  a  v a  2s . c o  m

    if (!isUpdate && mGenerateThumbnail) {
        File thumbnail = new File(mFile.getAbsolutePath() + ".thumb");
        if (!thumbnail.exists()) {
            boolean isImage = mContentType.toLowerCase(Locale.US).startsWith("image/");
            boolean isVideo = !isImage && mContentType.toLowerCase(Locale.US).startsWith("video/");
            try {
                // Try to generate a thumbnail
                mMessagingPlugin.createAttachmentThumbnail(mFile.getAbsolutePath(), isImage, isVideo);
            } catch (Exception e) {
                L.e("Failed to generate attachment thumbnail", e);
            }
        }
    }

    final String fileOnDisk = "file://" + mFile.getAbsolutePath();

    if (mContentType.toLowerCase(Locale.US).startsWith("video/")) {
        MediaController mediacontroller = new MediaController(this);
        mediacontroller.setAnchorView(mVideoview);

        Uri video = Uri.parse(fileOnDisk);
        mVideoview.setMediaController(mediacontroller);
        mVideoview.setVideoURI(video);

        mVideoview.requestFocus();
        mVideoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mVideoview.start();
            }
        });

        mVideoview.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                L.e("Could not play video, what " + what + ", extra " + extra + ", content_type " + mContentType
                        + ", and url " + mDownloadUrl);

                AlertDialog.Builder builder = new AlertDialog.Builder(AttachmentViewerActivity.this);
                builder.setMessage(R.string.error_please_try_again);
                builder.setCancelable(true);
                builder.setTitle(null);
                builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        dialog.dismiss();
                        finish();
                    }
                });
                builder.setPositiveButton(R.string.rogerthat, new SafeDialogInterfaceOnClickListener() {
                    @Override
                    public void safeOnClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        finish();
                    }
                });
                builder.create().show();
                return true;
            }
        });

    } else if (CONTENT_TYPE_PDF.equalsIgnoreCase(mContentType)) {
        WebSettings settings = mWebview.getSettings();
        settings.setJavaScriptEnabled(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            settings.setAllowUniversalAccessFromFileURLs(true);
        }

        mWebview.setWebViewClient(new WebViewClient() {

            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
                if (fileOnDisk.equals(url)) {
                    return null;
                }
                L.d("404: Expected: '" + fileOnDisk + "'\n Received: '" + url + "'");
                return new WebResourceResponse("text/plain", "UTF-8", null);
            }
        });
        try {
            mWebview.loadUrl("file:///android_asset/pdfjs/web/viewer.html?file="
                    + URLEncoder.encode(fileOnDisk, "UTF-8"));
        } catch (UnsupportedEncodingException uee) {
            L.bug(uee);
        }
    } else {
        WebSettings settings = mWebview.getSettings();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            settings.setAllowFileAccessFromFileURLs(true);
        }
        settings.setBuiltInZoomControls(true);
        settings.setLoadWithOverviewMode(true);
        settings.setUseWideViewPort(true);

        if (mContentType.toLowerCase(Locale.US).startsWith("image/")) {
            String html = "<html><head></head><body><img style=\"width: 100%;\" src=\"" + fileOnDisk
                    + "\"></body></html>";
            mWebview.loadDataWithBaseURL("", html, "text/html", "utf-8", "");
        } else {
            mWebview.loadUrl(fileOnDisk);
        }
    }
    L.d("File on disk: " + fileOnDisk);
}

From source file:com.cloudkick.NodeViewActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.do_connectbot:
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String user = prefs.getString("sshUser", "root");
        Integer port = new Integer(prefs.getString("sshPort", "22"));
        String uri = "ssh://" + user + "@" + node.ipAddress + ":" + port + "/#" + user;
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        try {/*from w w w  .  ja va2 s  . c o m*/
            startActivity(i);
        } catch (ActivityNotFoundException e) {
            // Suggest ConnectBot
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("SSH Client Not Found");
            String mfaMessage = ("The ConnectBot SSH Client is required to complete this operation. "
                    + "Would you like to install ConnectBot from the Android Market now?");
            builder.setMessage(mfaMessage);
            builder.setCancelable(true);
            builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Intent marketActivity = new Intent(Intent.ACTION_VIEW);
                    marketActivity.setData(Uri.parse("market://details?id=org.connectbot"));
                    startActivity(marketActivity);
                }
            });
            builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog mfaDialog = builder.create();
            mfaDialog.show();
        }
        return true;
    default:
        // If its not recognized, do nothing
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.gigathinking.simpleapplock.ResetUnlockMethod.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_reset);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    mDialog = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER);
    mDialog.setIndeterminate(true);/*www.j a  va  2 s. c om*/
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    mResetReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            prefs.edit().putString(AppLockApplication.LOCKTYPE, AppLockApplication.LOCKTYPE_PIN).commit();
            prefs.edit()
                    .putString(AppLockApplication.PASSWORD, intent.getStringExtra(AppLockApplication.PASSWORD))
                    .commit();
            Toast.makeText(context, getString(R.string.pin_reset), Toast.LENGTH_LONG).show();
            startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
            //startActivity(new Intent(ResetUnlockMethod.this,UnlockWithPIN.class).putExtra("test","test"));
            finish();
        }
    };
    LocalBroadcastManager.getInstance(this).registerReceiver(mResetReceiver,
            new IntentFilter(AppLockApplication.RESET_UNLOCK));

    if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.register_complete),
            false)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getString(R.string.reset_register_device));
        builder.setTitle(getString(R.string.info));
        builder.setPositiveButton(getString(R.string.register), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                new Register().execute();
                if (mDialog != null) {
                    mDialog.setMessage(getString(R.string.register_ongoing));
                    mDialog.show();
                }
                dialog.dismiss();
            }
        });
        builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                finish();
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_HOME);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        });
        builder.create().show();
    } else {
        if (mDialog != null) {
            mDialog.setMessage(getString(R.string.connect_to_server));
            mDialog.show();
        }
        new DoRequestReset().execute();
    }
}

From source file:com.starwood.anglerslong.LicenseActivity.java

/*****************************************************************************************************
 * Handles the onClick of the button/image
 *****************************************************************************************************
 * @param v Holds the clicked view/*  www  .j  a va  2s. com*/
 *****************************************************************************************************/
private void clickedItem(View v) {
    for (int i = 0; i < imageViewIdArray.length; i++) {
        if (v.getId() == imageViewIdArray[i]) {
            currentItemID = i;
            break;
        }
    }

    //*******************************************************************************************************
    // Only goes here if they clicked the DELETE button in the actionbar menu.
    //*******************************************************************************************************
    if (isDeletable) {
        AlertDialog.Builder builder = new AlertDialog.Builder(LicenseActivity.this);
        builder.setMessage("Are you sure you want to delete this item from the list?").setTitle("Delete")
                .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        try {
                            delete(currentItemID);
                            onBackPressed();
                            Toast.makeText(getApplicationContext(), "Your item has been deleted!",
                                    Toast.LENGTH_SHORT).show();
                        } catch (IOException | JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });

        AlertDialog alert = builder.create();
        alert.show();
        isDeletable = false;
    }
    //*******************************************************************************************************
    // Go here if you just want to click the item, see info that's stored, and possibly add to it.
    //*******************************************************************************************************
    else {
        isEdit = true;
        Intent intent = new Intent();
        intent.setClass(getApplicationContext(), LicenseAddActivity.class);
        intent.putExtra("title", "License");
        intent.putExtra("isPopulated", isLicensePopulated);
        intent.putExtra("isArrayEmpty", isArrayEmpty);
        intent.putExtra("isEdit", isEdit);
        intent.putExtra("currentItemID", currentItemID);
        intent.putExtra("isLicense", true);
        startActivity(intent);
    }
}

From source file:com.dwdesign.tweetings.fragment.StatusFragment.java

protected void translate(final ParcelableStatus status) {
    ThreadPolicy tp = ThreadPolicy.LAX;
    StrictMode.setThreadPolicy(tp);//  w  ww .  j av  a  2 s .  com

    String language = Locale.getDefault().getLanguage();
    String url = "http://api.microsofttranslator.com/v2/Http.svc/Translate?contentType="
            + URLEncoder.encode("text/plain") + "&appId=" + BING_TRANSLATE_API_KEY + "&from=&to=" + language
            + "&text=";
    url = url + URLEncoder.encode(status.text_plain);
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = httpClient.execute(new HttpGet(url));

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        String sResponse;
        StringBuilder s = new StringBuilder();

        while ((sResponse = reader.readLine()) != null) {
            s = s.append(sResponse);
        }
        String finalString = s.toString();
        finalString = finalString
                .replace("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">", "");
        finalString = finalString.replace("</string>", "");

        AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
        builder.setTitle(getString(R.string.translate));
        builder.setMessage(finalString);
        builder.setCancelable(true);
        builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });

        AlertDialog alert = builder.create();
        alert.show();
        //Toast.makeText(getActivity(), finalString, Toast.LENGTH_LONG).show();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.mdlive.sav.MDLiveSearchProvider.java

/**
 * Instantiating array adapter to populate the listView
 * The layout android.R.layout.simple_list_item_single_choice creates radio button for each listview item
 *
 * @param list : Dependent users array list
 *///  w  w  w  .  j av  a2  s .co  m
private void showListViewDialog(final ArrayList<String> list, final TextView selectedText, final String key,
        final ArrayList<HashMap<String, String>> typeList) {

    /*We need to get the instance of the LayoutInflater*/
    final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MDLiveSearchProvider.this);
    LayoutInflater inflater = getLayoutInflater();
    View convertView = inflater.inflate(R.layout.mdlive_screen_popup, null);
    alertDialog.setView(convertView);
    ListView lv = (ListView) convertView.findViewById(R.id.popupListview);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
    lv.setAdapter(adapter);
    lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    final AlertDialog dialog = alertDialog.create();
    dialog.show();

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String SelectedText = list.get(position);
            HashMap<String, String> localMap = typeList.get(position);
            for (Map.Entry entry : localMap.entrySet()) {
                if (SelectedText.equals(entry.getValue().toString())) {
                    postParams.put(key, entry.getKey().toString());
                    break; //breaking because its one to one map
                }
            }
            specialityBasedOnProvider(SelectedText, key);

            String oldChoice = selectedText.getText().toString();
            selectedText.setText(SelectedText);
            dialog.dismiss();

            // if user selects a different Provider type, then reload this screen
            if (!oldChoice.equals(SelectedText)) {
                SharedPreferences sharedpreferences = getSharedPreferences(
                        PreferenceConstants.MDLIVE_USER_PREFERENCES, Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedpreferences.edit();
                editor.putString(PreferenceConstants.PROVIDER_MODE, SelectedText);

                int providerType = MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText) == null
                        ? MDLiveConfig.UNMAPPED
                        : MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText);
                if (providerType == MDLiveConfig.UNMAPPED)
                    editor.putString(PreferenceConstants.PROVIDERTYPE_ID, "");
                else
                    editor.putString(PreferenceConstants.PROVIDERTYPE_ID, String.valueOf(providerType));

                editor.commit();

                // now reload the screen
                //recreate();
            }
        }
    });
}

From source file:net.reichholf.dreamdroid.activities.TimerEditActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    final Dialog dialog;

    Calendar cal;//from  www .j a  v a  2 s .co m
    Button buttonApply;

    applyViewValues();

    switch (id) {

    case (DIALOG_PICK_BEGIN_ID):
        cal = getCalendarFromTimestamp(mTimer.getString("begin"));

        dialog = new Dialog(this);
        dialog.setContentView(R.layout.date_time_picker);
        dialog.setTitle(R.string.set_time_begin);

        setDateAndTimePicker(dialog, cal);
        dialogRegisterCancel(dialog);

        buttonApply = (Button) dialog.findViewById(R.id.ButtonApply);
        buttonApply.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onTimerBeginSet(getCalendarFromPicker(dialog));
            }
        });

        dialog.show();
        break;

    case (DIALOG_PICK_END_ID):
        cal = getCalendarFromTimestamp(mTimer.getString("end"));

        dialog = new Dialog(this);
        dialog.setContentView(R.layout.date_time_picker);
        dialog.setTitle(R.string.set_time_end);

        setDateAndTimePicker(dialog, cal);
        dialogRegisterCancel(dialog);

        buttonApply = (Button) dialog.findViewById(R.id.ButtonApply);
        buttonApply.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onTimerEndSet(getCalendarFromPicker(dialog));
            }
        });

        dialog.show();
        break;

    case (DIALOG_PICK_REPEATED_ID):
        CharSequence[] days = getResources().getTextArray(R.array.weekdays);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getText(R.string.choose_days));
        builder.setMultiChoiceItems(days, mCheckedDays, new OnMultiChoiceClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                mCheckedDays[which] = isChecked;

                String text = setRepeated(mCheckedDays, mTimer);
                mRepeatings.setText(text);

            }

        });
        dialog = builder.create();

        break;

    case (DIALOG_PICK_TAGS_ID):
        CharSequence[] tags = new CharSequence[DreamDroid.TAGS.size()];
        boolean[] selectedTags = new boolean[DreamDroid.TAGS.size()];

        int tc = 0;
        for (String tag : DreamDroid.TAGS) {
            tags[tc] = tag;

            if (mSelectedTags.contains(tag)) {
                selectedTags[tc] = true;
            } else {
                selectedTags[tc] = false;
            }

            tc++;
        }

        mTagsChanged = false;
        mOldTags = new ArrayList<String>();
        mOldTags.addAll(mSelectedTags);

        builder = new AlertDialog.Builder(this);
        builder.setTitle(getText(R.string.choose_tags));

        builder.setMultiChoiceItems(tags, selectedTags, new OnMultiChoiceClickListener() {
            /*
             * (non-Javadoc)
             * 
             * @see android.content.DialogInterface.
             * OnMultiChoiceClickListener
             * #onClick(android.content.DialogInterface, int, boolean)
             */
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                String tag = DreamDroid.TAGS.get(which);
                mTagsChanged = true;
                if (isChecked) {
                    if (!mSelectedTags.contains(tag)) {
                        mSelectedTags.add(tag);
                    }
                } else {
                    int idx = mSelectedTags.indexOf(tag);
                    if (idx >= 0) {
                        mSelectedTags.remove(idx);
                    }
                }
            }

        });

        builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mTagsChanged) {
                    // TODO Update current Tags
                    String tags = Tag.implodeTags(mSelectedTags);
                    mTimer.put(Timer.TAGS, tags);
                    mTags.setText(tags);
                }
                dialog.dismiss();
                removeDialog(DIALOG_PICK_TAGS_ID);
            }

        });

        builder.setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mSelectedTags.clear();
                mSelectedTags.addAll(mOldTags);
                dialog.dismiss();
                removeDialog(DIALOG_PICK_TAGS_ID);
            }

        });

        dialog = builder.create();
        break;
    default:
        dialog = null;
    }

    return dialog;
}

From source file:com.google.example.eightbitartist.DrawingActivity.java

private void showDialog(String title, String message) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this).setTitle(title).setMessage(message)
            .setCancelable(false).setPositiveButton("OK", null);

    mAlertDialog = alertDialogBuilder.create();
    mAlertDialog.show();/*from   w  w  w  . ja  v  a 2  s.  c o  m*/
}