Example usage for android.app Dialog setContentView

List of usage examples for android.app Dialog setContentView

Introduction

In this page you can find the example usage for android.app Dialog setContentView.

Prototype

public void setContentView(@NonNull View view) 

Source Link

Document

Set the screen content to an explicit view.

Usage

From source file:com.birdeye.MainActivity.java

private void removeAdsDialog() {

    final Dialog dialog = new Dialog(MainActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    dialog.setContentView(R.layout.progress_pre);

    TextView tv_pay15 = (TextView) dialog.findViewById(R.id.tv_pay15);

    tv_pay15.setOnClickListener(new View.OnClickListener() {
        @Override//from   w w w  .j  a  va2  s . c  o  m
        public void onClick(View v) {

            if (!BillingProcessor.isIabServiceAvailable(MainActivity.this)) {
                showToast(
                        "In-app billing service is unavailable, please upgrade Android Market/Play to version >= 3.9.16");
            }

            else {

                //    asdasd

                //  onFuturePaymentPressed(v);
                bp.subscribe(MainActivity.this, SUBSCRIPTION_ID);

            }

            dialog.dismiss();

        }
    });

    dialog.setCancelable(true);

    dialog.show();

}

From source file:com.woofy.haifa.MapActivity.java

private boolean initMap() {
    if (mMap == null) {
        SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mMap = mapFrag.getMap();/*  ww  w  .j av a  2  s .  c  o  m*/

        if (mMap != null) {
            mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

                @Override
                public View getInfoWindow(Marker marker) {

                    // Getting view from the layout file
                    LayoutInflater inflater = LayoutInflater.from(MapActivity.this);
                    View v = inflater.inflate(R.layout.info_window, null);

                    TextView locality = (TextView) v.findViewById(R.id.tv_locality);
                    locality.setText(marker.getTitle());

                    //                   TextView title = (TextView) v.findViewById(R.id.tv_lat);
                    //                   title.setText(marker.getTitle());

                    TextView address = (TextView) v.findViewById(R.id.tv_lng);
                    address.setText(marker.getSnippet());

                    ImageView img = (ImageView) v.findViewById(R.id.imageView1);
                    if (lastbitmap != null) {
                        img.setImageBitmap(lastbitmap);
                    }
                    if (pic_map.containsKey(marker.getTitle())) {
                        img.setImageBitmap(pic_map.get(marker.getTitle()));
                    }
                    if (marker.getTitle().equals("You")) {
                        img.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.you_marker));
                    }

                    if (marker.getSnippet().length() < 30) {

                        //                   img.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.bad_dog));
                        new HttpLib.MarkerPic(marker.getTitle(), img, marker).execute();
                        //                   HttpLib.DownloadImageTask task=new HttpLib.DownloadImageTask(img,marker);
                        //                   task.execute("http://52.1.192.145/uploads/img_1434327703156_kgqsjhlevp9fj6tcs7su32gj43.jpg");
                        //                   
                        Vector<BasicNameValuePair> vec = new Vector<BasicNameValuePair>();
                        vec.add(new BasicNameValuePair("name", marker.getTitle()));
                        new HttpLib.MarkerInfoWindow(vec, marker).execute();

                    }

                    return v;
                    //                  return null;
                }

                @Override
                public View getInfoContents(Marker marker) {

                    View v = getLayoutInflater().inflate(R.layout.info_window, null);
                    TextView tvLocality = (TextView) v.findViewById(R.id.tv_locality);
                    TextView tvLat = (TextView) v.findViewById(R.id.tv_lat);
                    TextView tvLng = (TextView) v.findViewById(R.id.tv_lng);
                    TextView tvSnippet = (TextView) v.findViewById(R.id.tv_snippet);
                    //                  ImageView img = (ImageView) v.findViewById(R.id.imageView1);
                    LatLng ll = marker.getPosition();

                    tvLocality.setText(marker.getTitle());
                    //                  tvLat.setText("Dogs: " + "Woofy, Goofy");
                    //                  tvLng.setText("Click for more info");
                    //                  tvSnippet.setText(marker.getSnippet());

                    ImageView img = (ImageView) v.findViewById(R.id.imageView1);

                    if (lastbitmap != null) {
                        img.setImageBitmap(lastbitmap);
                        Log.d("Set bitmap", "Set bitmap");
                    } else {
                        new HttpLib.MarkerPic(marker.getTitle(), img, marker).execute();
                    }
                    if (marker.getSnippet().length() < 30) {

                        //                      img.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.bad_dog));

                        //                      HttpLib.DownloadImageTask task=new HttpLib.DownloadImageTask(img,marker);
                        //                      task.execute("http://52.1.192.145/uploads/img_1434327703156_kgqsjhlevp9fj6tcs7su32gj43.jpg");
                        //                      
                        Vector<BasicNameValuePair> vec = new Vector<BasicNameValuePair>();
                        vec.add(new BasicNameValuePair("name", marker.getTitle()));
                        new HttpLib.MarkerInfoWindow(vec, marker).execute();

                    }

                    return v;

                }
            });

            mMap.setOnMapLongClickListener(new OnMapLongClickListener() {

                @Override
                public void onMapLongClick(final LatLng point) {

                    final Dialog dialog = new Dialog(MapActivity.this);
                    dialog.setContentView(R.layout.alert_layout);
                    dialog.setCancelable(true);
                    dialog.show();

                    //                       .setMessage(R.string.really_quit)
                    Button b = (Button) dialog.findViewById(R.id.yesmeet);
                    b.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            String t1 = ((EditText) dialog.findViewById(R.id.meet_name)).getText().toString();
                            //                               String t2 = ((EditText)dialog.findViewById(R.id.editText1111)).getText().toString();

                            if (meet != null)
                                meet.remove();
                            MarkerOptions options;
                            options = new MarkerOptions().title(t1).position(point)
                                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
                                    .anchor(.5f, .5f) //center the icon
                                    .draggable(true);

                            Marker mar = mMap.addMarker(options);

                            //                           MeetingMarkers.add(mar);
                            meet = mar;

                            dialog.dismiss();

                        }

                    });

                    Button b1 = (Button) dialog.findViewById(R.id.nomeet);
                    b1.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            dialog.dismiss();

                        }
                    });

                }
            });

            mMap.setOnCameraChangeListener(new OnCameraChangeListener() {
                @Override
                public void onCameraChange(CameraPosition position) {
                    if (SystemClock.uptimeMillis() - show_people_last_updated > 1000) {
                        show_people_last_updated = SystemClock.uptimeMillis();
                        showPeople();
                    }
                }
            });

            mMap.setOnMarkerClickListener(new OnMarkerClickListener() {

                @Override
                public boolean onMarkerClick(final Marker marker) {

                    lastbitmap = null;
                    marker.hideInfoWindow();
                    marker.showInfoWindow();

                    return false;
                }
            });

            mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

                @Override
                public void onInfoWindowClick(Marker marker) {
                    Log.d("Open profile page", marker.getTitle());
                    Intent intent = new Intent(MapActivity.this, Profile.class);
                    intent.putExtra("name", marker.getTitle());
                    startActivity(intent);

                }
            });

            mMap.setOnMarkerDragListener(new OnMarkerDragListener() {

                @Override
                public void onMarkerDragStart(Marker marker) {
                    marker.remove();
                    MarkerOptions options;
                    options = new MarkerOptions().title(marker.getTitle()).position(marker.getPosition())
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.custom_marker))
                            .anchor(.5f, .5f) //center the icon
                            .draggable(true);

                    String name = marker.getTitle();
                    if (selected_markers.contains(name)) {
                        selected_markers.remove(name);
                    } else {
                        selected_markers.add(name);
                        options.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_checked));
                    }

                    Marker addmarker = mMap.addMarker(options);
                    PersonMarkers.add(addmarker);
                }

                @Override
                public void onMarkerDragEnd(Marker marker) {

                }

                @Override
                public void onMarkerDrag(Marker arg0) {

                }
            });
        }
    }
    return (mMap != null);
}

From source file:Steps.StepsFragment.java

private void showStickerMoreInfo(final Sticker clickedSticker) {
    // custom dialog
    clickedSticker.getName();//from  w w  w  . jav a2s  . c om
    Log.d("NAMe", clickedSticker.getName());

    final Dialog dialog = new Dialog(getActivity());

    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    });

    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));
    dialog.setContentView(R.layout.sticker_dialog);
    ImageView image = (ImageView) (dialog).findViewById(R.id.image);

    //get the correct image
    String file = clickedSticker.getImagesrc();
    file = file.substring(0, file.lastIndexOf(".")); //trim the extension
    Resources resources = getActivity().getResources();
    int resourceId = resources.getIdentifier(file, "drawable", getActivity().getPackageName());
    image.setImageBitmap(SampleImage.decodeSampledBitmapFromResource(getResources(), resourceId, 250, 250));

    //load the additional details and information
    TextView id = (TextView) (dialog).findViewById(R.id.sticker_id);
    id.setText("#" + Integer.toString(clickedSticker.getId()));

    TextView status = (TextView) (dialog).findViewById(R.id.sticker_status);
    //at this poinrt only glued and notSticker available glued=1 notGlued=0
    String statuss = clickedSticker.getStatus().equals(2) ? "1" : "0";
    Integer count = clickedSticker.getCount();
    status.setText("(" + statuss + " glued, " + count + " left)");

    TextView title = (TextView) (dialog).findViewById(R.id.sticker_title);
    title.setText(clickedSticker.getName());

    TextView rarity = (TextView) (dialog).findViewById(R.id.rarity);
    rarity.setText(clickedSticker.getPopularity());

    TextView movie = (TextView) (dialog).findViewById(R.id.sticker_movie);
    movie.setText(clickedSticker.getMovie());
    //set the layout to have the same widh and height as the  windows screen

    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = width;
    lp.height = height;
    dialog.getWindow().setAttributes(lp);
    RelativeLayout mainLayout = (RelativeLayout) dialog.findViewById(R.id.showStickerLayout);
    dialog.show();
    // if button is clicked, close the custom dialog
    mainLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();

        }

    });
    //listen for the inf tab
    ImageView info = (ImageView) (dialog).findViewById(R.id.info_image);
    info.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showInfoDialog(clickedSticker);
        }

    });

}

From source file:su.comp.bk.ui.BkEmuActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_COMPUTER_MODEL:
        final CharSequence[] models;
        List<String> modelList = new ArrayList<String>();
        for (Configuration model : Configuration.values()) {
            int modelNameId = getResources().getIdentifier(model.name().toLowerCase(), "string",
                    getPackageName());/*  w  ww . j a  v  a  2  s.co m*/
            modelList.add((modelNameId != 0) ? getString(modelNameId) : model.name());
        }
        models = modelList.toArray(new String[modelList.size()]);
        return new AlertDialog.Builder(this).setTitle(R.string.menu_select_model).setSingleChoiceItems(models,
                getComputerConfiguration().ordinal(), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        // Mark selected item by tag
                        ListView listView = ((AlertDialog) dialog).getListView();
                        listView.setTag(Integer.valueOf(which));
                    }
                }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Get tagged selected item, if any
                        ListView listView = ((AlertDialog) dialog).getListView();
                        Integer selected = (Integer) listView.getTag();
                        if (selected != null) {
                            Configuration config = Configuration.values()[selected];
                            if (computer.getConfiguration() != config) {
                                // Set new computer configuration and restart activity
                                setComputerConfiguration(config);
                                restartActivity(null);
                            }
                        }
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Do nothing on cancel
                    }
                }).create();
    case DIALOG_ABOUT:
        Dialog aboutDialog = new Dialog(this);
        aboutDialog.setTitle(R.string.menu_about);
        aboutDialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
        aboutDialog.setContentView(R.layout.about_dialog);
        aboutDialog.getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
                android.R.drawable.ic_dialog_info);
        TextView versionTextView = (TextView) aboutDialog.findViewById(R.id.about_version);
        try {
            versionTextView.setText(getResources().getString(R.string.about_version,
                    getPackageManager().getPackageInfo(getPackageName(), 0).versionName));
        } catch (NameNotFoundException e) {
        }
        return aboutDialog;
    case DIALOG_DISK_MANAGER:
        Dialog fddManagerDialog = new Dialog(this);
        fddManagerDialog.setTitle(R.string.menu_disk_manager);
        fddManagerDialog.setContentView(R.layout.fdd_mgr_dialog);
        return fddManagerDialog;
    case DIALOG_DISK_MOUNT_ERROR:
        return new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.err)
                .setMessage(R.string.dialog_disk_mount_error).setPositiveButton(R.string.ok, null).create();
    }
    return null;
}

From source file:com.kircherelectronics.accelerationfilter.activity.AccelerationPlotActivity.java

private void showHelpDialog() {
    Dialog helpDialog = new Dialog(this);
    helpDialog.setCancelable(true);/*w w  w  .  j  a va 2  s . c o m*/
    helpDialog.setCanceledOnTouchOutside(true);

    helpDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    helpDialog.setContentView(getLayoutInflater().inflate(R.layout.help_dialog_view, null));

    helpDialog.show();
}

From source file:Steps.StepsFragment.java

private void showNewSticker(final Sticker sticker_1, final Sticker sticker_2, final Sticker sticker_3) {
    // custom dialog

    final Dialog dialog = new Dialog(getActivity());

    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override//from w  w w  .j  a v a2 s  .co  m
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    });

    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    dialog.setContentView(R.layout.new_stickers_dialog);
    //get the correct image -1st sticker

    ImageView image = (ImageView) (dialog).findViewById(R.id.sticker1);
    image.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showStickerMoreInfo(sticker_1);
        }
    });
    String file = sticker_1.getImagesrc();
    file = file.substring(0, file.lastIndexOf(".")); //trim the extension
    Resources resources = getActivity().getResources();
    int resourceId = resources.getIdentifier(file, "drawable", getActivity().getPackageName());
    TextView number = (TextView) (dialog).findViewById(R.id.text_sticker1);
    number.setText("#" + Integer.toString(sticker_1.getId()));
    RelativeLayout image_layout = (RelativeLayout) (dialog).findViewById(R.id.sticker1_layout);
    ImageView imageCategory = (ImageView) (dialog).findViewById(R.id.category_image1);
    determineCategoty(imageCategory, sticker_1);
    determinePicture(sticker_1, image, resourceId);
    animate(image_layout, 3000);

    //get the correct image -2nd sticker
    ImageView image2 = (ImageView) (dialog).findViewById(R.id.sticker2);
    image2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showStickerMoreInfo(sticker_2);
        }
    });
    String file2 = sticker_2.getImagesrc();
    file2 = file2.substring(0, file2.lastIndexOf(".")); //trim the extension
    Resources resources2 = getActivity().getResources();
    int resourceId2 = resources2.getIdentifier(file2, "drawable", getActivity().getPackageName());
    TextView number2 = (TextView) (dialog).findViewById(R.id.text_sticker2);
    number2.setText("#" + Integer.toString(sticker_2.getId()));
    RelativeLayout image_layout2 = (RelativeLayout) (dialog).findViewById(R.id.sticker2_layout);
    ImageView imageCategory2 = (ImageView) (dialog).findViewById(R.id.category_image2);
    determineCategoty(imageCategory2, sticker_2);
    determinePicture(sticker_2, image2, resourceId2);
    animate(image_layout2, 3000);

    //get the correct image -3rd sticker
    ImageView image3 = (ImageView) (dialog).findViewById(R.id.sticker3);
    image3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showStickerMoreInfo(sticker_3);
        }
    });
    String file3 = sticker_3.getImagesrc();
    file3 = file3.substring(0, file3.lastIndexOf(".")); //trim the extension
    Resources resources3 = getActivity().getResources();
    int resourceId3 = resources3.getIdentifier(file3, "drawable", getActivity().getPackageName());

    TextView number3 = (TextView) (dialog).findViewById(R.id.text_sticker3);
    number3.setText("#" + Integer.toString(sticker_3.getId()));
    RelativeLayout image_layout3 = (RelativeLayout) (dialog).findViewById(R.id.sticker3_layout);
    ImageView imageCategory3 = (ImageView) (dialog).findViewById(R.id.category_image3);
    determineCategoty(imageCategory3, sticker_3);
    determinePicture(sticker_3, image3, resourceId3);
    animate(image_layout3, 3000);

    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    //set the layout to have the same widh and height as the  windows screen
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = width;
    lp.height = height;
    dialog.getWindow().setAttributes(lp);
    RelativeLayout mainLayout = (RelativeLayout) dialog.findViewById(R.id.showStickerLayout);
    dialog.show();
    // if button is clicked, close the custom dialog
    Button doneButton = (Button) (dialog).findViewById(R.id.doneButton);
    doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();

        }

    });
}

From source file:com.birdeye.MainActivity.java

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {

    switch (item.getItemId()) {
    case R.id.logout:

        fullReset();//from   w w  w  . ja  v a  2  s.  com
        startActivity(LoginActivity.create(this));
        finish();

        return true;

    case R.id.About:

        final Dialog dialog2 = new Dialog(MainActivity.this);
        dialog2.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog2.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog2.setContentView(R.layout.about);
        dialog2.setCancelable(false);

        dialog2.show();

        return true;

    case R.id.ShareApp:

        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/html");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(
                "<p>Hey, am using this really cool hashtag activated camera app. Get it here #birdeyecamera.</p>"));
        startActivity(Intent.createChooser(sharingIntent, "Share using"));

        return true;

    case R.id.Recommend:

        Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("BirdEyeCamera", "birdeyecamera@digitalbabi.es", null));
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feature Recommendation");
        startActivity(Intent.createChooser(emailIntent, "Send email..."));

        return true;

    case R.id.rateApp:

        final Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
        final Intent rateAppIntent = new Intent(Intent.ACTION_VIEW, uri);

        if (getPackageManager().queryIntentActivities(rateAppIntent, 0).size() > 0) {
            startActivity(rateAppIntent);
        } else {
            /* handle your error case: the device has no way to handle market urls */
        }

        return true;

    case R.id.RemoveAds:

        if (Globals.hasPaid) {
            Toast.makeText(MainActivity.this, "You already are in a premium account", Toast.LENGTH_SHORT)
                    .show();

        } else {

            removeAdsDialog();

        }

        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void showSettings() {
    final SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
    int selfReportIntervalSpinnerPosition = sharedPref.getInt("selfReportIntervalSpinnerPosition", 2);
    int selfReportVarianceSpinnerPosition = sharedPref.getInt("selfReportVarianceSpinnerPosition", 0);
    int questionnaireSpinnerPosition = sharedPref.getInt("questionnaireSpinnerPosition", 0);
    //int baselineQuestionnaireSpinnerPosition = sharedPref.getInt("baselineQuestionnaireSpinnerPosition", 0);
    String activityName = sharedPref.getString("activityName", "");
    String participantFirstName = sharedPref.getString("participantFirstName", "");
    String participantLastName = sharedPref.getString("participantLastName", "");
    boolean configureInterval = sharedPref.getBoolean("configureInterval", false);
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.settings);
    dialog.setTitle(getString(R.string.action_settings));
    dialog.setCancelable(true);//w  ww. j a  v a 2s  .  c om
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.MATCH_PARENT;
    dialog.getWindow().setAttributes(lp);
    selfReportIntervalSpinner = (Spinner) dialog.findViewById(R.id.self_report_interval_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.study_protocol_settings_self_report_interval_values, android.R.layout.simple_spinner_item);
    selfReportIntervalSpinner.setAdapter(adapter);
    selfReportIntervalSpinner.setSelection(selfReportIntervalSpinnerPosition);
    selfReportVarianceSpinner = (Spinner) dialog.findViewById(R.id.self_report_variance_spinner);
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this,
            R.array.study_protocol_settings_self_report_variance_values, android.R.layout.simple_spinner_item);
    selfReportVarianceSpinner.setAdapter(adapter2);
    selfReportVarianceSpinner.setSelection(selfReportVarianceSpinnerPosition);

    questionnaireSpinner = (Spinner) dialog.findViewById(R.id.questionnaireSpinner);
    //baselineQuestionnaireSpinner = (Spinner) dialog.findViewById(R.id.baseline_questionnaireSpinner);

    String[] questionnaireTitles = new String[0];
    try {
        questionnaireTitles = new String[questionnaireCount];
        for (int i = 0; i < questionnaireCount; i++) {
            String questionnaireFilename = questionnaireFilenames[i];
            String questionnairePath = "questionnaires/" + localeString + "/" + questionnaireFilename;
            try {
                JSONObject questionnaire = Utils
                        .getJSONObjectFromInputStream(getAssets().open(questionnairePath));
                String questionnaireTitle = questionnaire.getJSONObject("questionnaire").getString("title");
                questionnaireTitles[i] = questionnaireTitle;
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    ArrayAdapter<String> qSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
            questionnaireTitles);
    questionnaireSpinner.setAdapter(qSpinnerAdapter);
    questionnaireSpinner.setSelection(questionnaireSpinnerPosition);
    //baselineQuestionnaireSpinner.setAdapter(qSpinnerAdapter);
    //baselineQuestionnaireSpinner.setSelection(baselineQuestionnaireSpinnerPosition);

    final EditText participantFirstNameEditText = (EditText) dialog
            .findViewById(R.id.participant_first_name_edit_text);
    final EditText participantLastNameEditText = (EditText) dialog
            .findViewById(R.id.participant_last_name_edit_text);
    final EditText activityNameEditText = (EditText) dialog.findViewById(R.id.activity_name_edit_text);
    participantFirstNameEditText.setText(participantFirstName);
    participantLastNameEditText.setText(participantLastName);
    activityNameEditText.setText(activityName);

    final Switch configureIntervalSwitch = (Switch) dialog.findViewById(R.id.configure_interval_switch);
    configureIntervalSwitch.setChecked(configureInterval);
    if (configureInterval) {
        dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.VISIBLE);
        dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.VISIBLE);
    } else {
        dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.GONE);
        dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.GONE);
    }

    Button saveButton = (Button) dialog.findViewById(R.id.saveButton);
    saveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            selfReportInterval = Integer.valueOf(selfReportIntervalSpinner.getSelectedItem().toString());
            selfReportVariance = Integer.valueOf(selfReportVarianceSpinner.getSelectedItem().toString());

            MainActivity.this.participantFirstName = participantFirstNameEditText.getText().toString().trim();
            MainActivity.this.participantLastName = participantLastNameEditText.getText().toString().trim();
            MainActivity.this.activityName = activityNameEditText.getText().toString().trim();
            MainActivity.this.intervalConfigured = configureIntervalSwitch.isChecked();

            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putInt("selfReportIntervalSpinnerPosition",
                    selfReportIntervalSpinner.getSelectedItemPosition());
            editor.putInt("selfReportVarianceSpinnerPosition",
                    selfReportVarianceSpinner.getSelectedItemPosition());
            editor.putInt("questionnaireSpinnerPosition", questionnaireSpinner.getSelectedItemPosition());
            //editor.putInt("baselineQuestionnaireSpinnerPosition", baselineQuestionnaireSpinner.getSelectedItemPosition());
            editor.putInt("selfReportInterval",
                    Integer.valueOf(selfReportIntervalSpinner.getSelectedItem().toString()));
            editor.putInt("selfReportVariance",
                    Integer.valueOf(selfReportVarianceSpinner.getSelectedItem().toString()));

            editor.putString("participantFirstName", participantFirstNameEditText.getText().toString().trim());
            editor.putString("participantLastName", participantLastNameEditText.getText().toString().trim());
            editor.putString("activityName", activityNameEditText.getText().toString().trim());
            editor.putBoolean("configureInterval", configureIntervalSwitch.isChecked());
            editor.apply();

            dialog.dismiss();
        }
    });

    configureIntervalSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.VISIBLE);
                dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.VISIBLE);
            } else {
                dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.GONE);
                dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.GONE);
            }
        }
    });
    dialog.show();
}

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

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

    Calendar cal;/*from  w w w .jav a 2 s  .  com*/
    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.appolis.move.AcMoveDetails.java

/**
 * // w ww  .  j a  va 2s  . c om
 * @param mContext
 * @param newClass
 * @param strMessages
 */
public void showPopUp(final Context mContext, final Class<?> newClass, final String strMessages) {
    String message;
    if (strMessages.equals(GlobalParams.BLANK)) {
        message = GlobalParams.WRONG_USER;
    } else {
        message = strMessages;
    }

    final Dialog dialog = new Dialog(mContext, R.style.Dialog_NoTitle);
    dialog.setContentView(R.layout.dialogwarning);
    // set the custom dialog components - text, image and button      
    TextView text2 = (TextView) dialog.findViewById(R.id.tvScantitle2);
    text2.setText(message);

    LanguagePreferences langPref = new LanguagePreferences(mContext);
    Button dialogButtonOk = (Button) dialog.findViewById(R.id.dialogButtonOK);
    dialogButtonOk.setText(langPref.getPreferencesString(GlobalParams.OK, GlobalParams.OK));

    dialogButtonOk.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            scanFlag = GlobalParams.FLAG_ACTIVE;
        }
    });
    dialog.show();
}