Example usage for android.app AlertDialog.Builder setView

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

Introduction

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

Prototype

public void setView(View view) 

Source Link

Document

Set the view to display in that dialog.

Usage

From source file:com.doomy.decode.ScanActivity.java

private void openAboutDialog() {
    LayoutInflater mLayoutInflater = LayoutInflater.from(ScanActivity.this);
    View mView = mLayoutInflater.inflate(R.layout.view_about, null);

    ImageView mImageViewMrDoomy = (ImageView) mView.findViewById(R.id.imageViewMrDoomy);
    ImageView mImageViewStudio = (ImageView) mView.findViewById(R.id.imageViewStudio);
    ImageView mImageViewGitHub = (ImageView) mView.findViewById(R.id.imageViewGitHub);
    Drawable mMrDoomy = mImageViewMrDoomy.getDrawable();
    Drawable mStudio = mImageViewStudio.getDrawable();
    Drawable mGitHub = mImageViewGitHub.getDrawable();
    mMrDoomy.setColorFilter(getResources().getColor(R.color.greenDark), PorterDuff.Mode.SRC_ATOP);
    mStudio.setColorFilter(getResources().getColor(R.color.green), PorterDuff.Mode.SRC_ATOP);
    mGitHub.setColorFilter(getResources().getColor(R.color.greyMaterialDark), PorterDuff.Mode.SRC_ATOP);

    mImageViewGitHub.setOnClickListener(new View.OnClickListener() {
        @Override/* w  ww .  j a va 2 s  .  c  o  m*/
        public void onClick(View v) {
            Intent mIntent = new Intent();
            mIntent.setAction(Intent.ACTION_VIEW);
            mIntent.addCategory(Intent.CATEGORY_BROWSABLE);
            mIntent.setData(Uri.parse(getString(R.string.url)));
            startActivity(mIntent);
        }
    });

    AlertDialog.Builder mAlertDialog = new AlertDialog.Builder(ScanActivity.this, Utils.setThemeDialog());

    mAlertDialog.setTitle(getString(R.string.about));
    mAlertDialog.setView(mView);
    mAlertDialog.setPositiveButton(getString(R.string.okay), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    mAlertDialog.show();
}

From source file:com.andryr.musicplayer.fragments.dialog.ID3TagEditorDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.edit_tags);

    mSong.setGenre(MusicLibraryHelper.getSongGenre(getActivity(), mSong.getId()));//TODO rcuprer le genre de manire asynchrone ??
    View dialogView = getActivity().getLayoutInflater().inflate(R.layout.fragment_id3_tag_editor_dialog, null);
    builder.setView(dialogView);

    mTitleEditText = (EditText) dialogView.findViewById(R.id.title);
    mArtistEditText = (EditText) dialogView.findViewById(R.id.artist);
    mAlbumEditText = (EditText) dialogView.findViewById(R.id.album);
    mTrackEditText = (EditText) dialogView.findViewById(R.id.track_number);
    mGenreEditText = (EditText) dialogView.findViewById(R.id.genre);

    mTitleEditText.setText(mSong.getTitle());
    mArtistEditText.setText(mSong.getArtist());
    mAlbumEditText.setText(mSong.getAlbum());
    mTrackEditText.setText(String.valueOf(mSong.getTrackNumber()));
    mGenreEditText.setText(mSong.getGenre());

    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override//from  w ww  . ja  v a2s  .  c  o m
        public void onClick(DialogInterface dialog, int which) {

            final Activity activity = getActivity();
            dismiss();

            new AsyncTask<Object, Object, Boolean>() {

                @Override
                protected Boolean doInBackground(Object... params) {
                    return saveTags(activity);
                }

                @Override
                protected void onPostExecute(Boolean b) {
                    super.onPostExecute(b);
                    if (b) {
                        if (mListener != null) {
                            mListener.onTagsEditionSuccess();
                        }
                    } else {
                        Toast.makeText(getContext(), R.string.tags_edition_failed, Toast.LENGTH_SHORT).show();

                    }

                }
            }.execute();

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

    return builder.create();
}

From source file:com.duy.pascal.ui.debug.activities.DebugActivity.java

private void showDialogInput() {
    mHandler.post(new Runnable() {
        @Override/*from  w  ww  . j ava 2s  . co  m*/
        public void run() {
            AlertDialog.Builder builder = new AlertDialog.Builder(DebugActivity.this);
            builder.setView(R.layout.dialog_input);
            mAlertDialog = builder.create();
            mAlertDialog = builder.create();
            mAlertDialog.setCanceledOnTouchOutside(false);
            if (!isFinishing()) {
                mAlertDialog.show();
                final EditText editText = mAlertDialog.findViewById(R.id.edit_input);
                ((TextInputLayout) mAlertDialog.findViewById(R.id.hint))
                        .setHint(getString(R.string.enter_data));
                View.OnClickListener onClickListener = new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mLock instanceof IOLib) {
                            ((IOLib) mLock).setInputBuffer(editText.getText().toString());
                        }
                        mConsoleView.writeString(editText.getText().toString());
                        mAlertDialog.cancel();
                    }
                };
                mAlertDialog.findViewById(R.id.btn_ok).setOnClickListener(onClickListener);
                mAlertDialog.findViewById(R.id.btn_cancel).setVisibility(View.GONE);
            }
        }
    });
}

From source file:com.death.yttorrents.activity.MainActivity.java

/**
 * @param item/*from   w  w  w  . j  av a 2s . c o  m*/
 * @return
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.seedr) {
        count += 1;
        Toast.makeText(MainActivity.this, "Sorting by minimum rating 8 on page " + count, Toast.LENGTH_SHORT)
                .show();
        String url = "https://yts.ag/api/v2/list_movies.json?minimum_rating=8&limit=50&page=" + count;
        fetchMovies(url);
    }
    if (item.getItemId() == R.id.search) {
        count = 0;
        LayoutInflater li = LayoutInflater.from(MainActivity.this);
        View dialogView = li.inflate(R.layout.custom_query, null);
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this,
                R.style.MyDialogTheme);
        alertDialogBuilder.setTitle(Html.fromHtml("<font color='#ffffff'>Search Movie</font>"));
        alertDialogBuilder.setIcon(R.drawable.ic_icon);
        alertDialogBuilder.setView(dialogView);
        final EditText userInput = (EditText) dialogView.findViewById(R.id.et_input);
        alertDialogBuilder.setCancelable(false)
                .setPositiveButton("Search", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        query = userInput.getText().toString();
                        String dataUrl = "https://yts.ag/api/v2/list_movies.json?query_term=" + query
                                + "&limit=30";
                        fetchMovies(dataUrl);
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }
    if (item.getItemId() == R.id.mwiki) {
        startActivity(new Intent(MainActivity.this, MediaContainer.class));
    }

    if (item.getItemId() == R.id.about) {
        startActivity(new Intent(MainActivity.this, About.class));
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.team04adventure.Controller.OnlineStoryList.java

/**
 * Shows the help information for this fragment.
 *///from w w w  . ja  v a 2 s  .  co  m
private void help() {
    String helpText = "All stories are displayed here. Press a story to read it. Online stories contains all"
            + "the stories on the server. My stories contains all the stories written by you."
            + "Cached stories contains all the stories downloaded on your phone that aren't written by you. "
            + "The 'I'm Feeling Lucky!' button chooses a random story for you from the existing online stories."
            + "The 'Add Story' button lets you create a new story, and new stories can only be published by creating a"
            + "new story from here. The 'Sync' button locally mirrors the cached stories with the online stories so that"
            + "the cached stories are updated.";
    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    LinearLayout lila1 = new LinearLayout(this);
    lila1.setOrientation(1);

    final TextView helpTextView = new TextView(this);
    helpTextView.setText(helpText);
    lila1.addView(helpTextView);
    adb.setView(lila1);
    adb.setTitle("Help");

    adb.show();
}

From source file:com.dsi.ant.antplus.pluginsampler.weightscale.Dialog_ConfigUserProfile.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle("User Profile Configuration");
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View detailsView = inflater.inflate(R.layout.dialog_weightscale_configuserprofile, null);

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(detailsView);

    // Add action buttons
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override//from  w w w. ja va 2  s .  co  m
        public void onClick(DialogInterface dialog, int which) {
            profile.age = Integer.parseInt(et_age.getText().toString());
            profile.height = Integer.parseInt(et_height.getText().toString());
            profile.activityLevel = Integer.parseInt(et_activityLevel.getText().toString());
            profile.lifetimeAthlete = cb_lifetimeAthlete.isChecked();
            if (rb_male.isChecked())
                profile.gender = AntPlusWeightScalePcc.Gender.MALE;
            else
                profile.gender = AntPlusWeightScalePcc.Gender.FEMALE;
        }
    });

    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Let dialog dismiss
        }
    });

    tv_userProfileID = (TextView) detailsView.findViewById(R.id.textView_UserProfileID);
    et_age = (EditText) detailsView.findViewById(R.id.editText_Age);
    et_height = (EditText) detailsView.findViewById(R.id.editText_Height);
    et_activityLevel = (EditText) detailsView.findViewById(R.id.editText_ActivityLevel);
    cb_lifetimeAthlete = (CheckBox) detailsView.findViewById(R.id.checkBox_LifetimeAthlete);
    rb_female = (RadioButton) detailsView.findViewById(R.id.radioButton_Female);
    rb_male = (RadioButton) detailsView.findViewById(R.id.radioButton_Male);

    // Set data
    tv_userProfileID.setText(String.valueOf(profile.getUserProfileID()));
    et_age.setText(String.valueOf(profile.age));
    et_height.setText(String.valueOf(profile.height));
    et_activityLevel.setText(String.valueOf(profile.activityLevel));
    cb_lifetimeAthlete.setChecked(profile.lifetimeAthlete);
    if (profile.gender == AntPlusWeightScalePcc.Gender.MALE)
        rb_male.setChecked(true);
    else
        rb_female.setChecked(true);

    return builder.create();
}

From source file:com.example.anish.myapplication.MainActivity.java

private void showInputDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Change city");
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    builder.setView(input);
    builder.setPositiveButton("Go", new DialogInterface.OnClickListener() {
        @Override//w ww.  j a v  a2s.  c o  m
        public void onClick(DialogInterface dialog, int which) {
            changeCity(input.getText().toString());
        }
    });
    builder.show();
}

From source file:fi.mikuz.boarder.gui.internet.Uploads.java

private void boardUploader(final InternetFullBoard board, final int phpOperation) {
    LayoutInflater inflater = (LayoutInflater) Uploads.this.getSystemService(LAYOUT_INFLATER_SERVICE);
    final View layout = inflater.inflate(R.layout.internet_uploads_alert_upload_board,
            (ViewGroup) findViewById(R.id.alert_settings_root));

    TextView wikiLink = (TextView) layout.findViewById(R.id.wikiLink);
    wikiLink.setText("\n  Guide here!\n\n");

    wikiLink.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://github.com/Mikuz/Boarder/wiki/Uploading-guide"));
            startActivity(browserIntent);
        }//from  w ww  . ja  v a 2  s .c o m
    });

    AlertDialog.Builder builder = new AlertDialog.Builder(Uploads.this);
    builder.setView(layout);
    builder.setTitle("Upload board");

    refreshUploadAlertBoard(layout, board);

    final Button sendButton = (Button) layout.findViewById(R.id.sendButton);
    sendButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mWaitDialog = new TimeoutProgressDialog(Uploads.this, "Waiting for response", TAG, false);
            HashMap<String, String> sendList = getSendList(layout, board, phpOperation);
            new ConnectionManager(Uploads.this, InternetMenu.mUploadBoardURL, sendList);
        }
    });

    final Button previewButton = (Button) layout.findViewById(R.id.previewButton);
    previewButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            HashMap<String, String> sendList = getSendList(layout, board, phpOperation);

            // Simulate a board from web
            sendList.put(InternetMenu.BOARD_ID_KEY, "-1");
            sendList.put(InternetMenu.RATING_KEY, "0");
            sendList.put(InternetMenu.USERNAME_KEY, "Preview");

            JSONObject databaseValues = new JSONObject();
            if (sendList != null) {
                for (String key : sendList.keySet()) {
                    try {
                        databaseValues.put(key, sendList.get(key));
                    } catch (JSONException e) {
                        Log.e(TAG, "Error putting '" + key + "' to JSONObject as database value");
                    }
                }
            }

            JSONArray jArray = new JSONArray();
            jArray.put(databaseValues);
            JSONObject fakeMessage = null;
            try {
                fakeMessage = new JSONObject();
                fakeMessage.put(ConnectionUtils.returnData, jArray);
            } catch (JSONException e) {
                Log.e(TAG, "Error constructing fake json message", e);
            }

            Intent i = new Intent(Uploads.this, DownloadBoard.class);
            XStream xstream = new XStream();
            i.putExtra(DownloadBoard.SHOW_KEY, DownloadBoard.SHOW_PREVIEW_BOARD);
            i.putExtra(DownloadBoard.JSON_KEY, xstream.toXML(fakeMessage));
            startActivity(i);
        }
    });

    builder.show();
}

From source file:io.github.protino.codewatch.ui.LeaderboardFragment.java

@SuppressLint("InflateParams")
@Nullable/*from ww  w  . j ava 2  s .  co m*/
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_leaderboard, container, false);
    unbinder = ButterKnife.bind(this, rootView);

    context = getActivity();
    filterState = new FilterState();
    userId = CacheUtils.getWakatimeUserId(context);

    leadersAdapter = new LeadersAdapter(context, new ArrayList<>());
    leadersAdapter.setOnItemSelectedListener(this);

    //recyclerView setup
    recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    recyclerView.setAdapter(leadersAdapter);

    //Dialog related
    dialogView = inflater.inflate(R.layout.dialog_leaders_filter, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(dialogView).setPositiveButton(R.string.ok, null).setNegativeButton(R.string.cancel, null);
    dialog = builder.create();
    dialog.setOnShowListener(this);

    getLoaderManager().initLoader(LOADER_ID, null, this);

    swipeRefreshLayout.setOnRefreshListener(this);
    return rootView;
}

From source file:dtu.ds.warnme.app.dialog.RegisterDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_register, null);
    builder.setView(view);
    builder.setTitle(R.string.register);
    builder.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {

        @Override/*w w w.ja v a  2s. c o  m*/
        public void onClick(DialogInterface dialogInterface, int which) {
            // Nothing to do here...
        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int which) {
            // Nothing to do here...
        }
    });

    progressView = view.findViewById(R.id.dialog_register_progress);
    formView = view.findViewById(R.id.dialog_register_form);

    usernameEditText = (EditText) view.findViewById(R.id.dialog_register_edit_text_username);
    usernameEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            // Nothing to do here...
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Nothing to do here...
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            usernameEditText.setError(null);
        }
    });

    passwordEditText = (EditText) view.findViewById(R.id.dialog_register_edit_text_password);
    passwordEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            // Nothing to do here...
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Nothing to do here...
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            passwordEditText.setError(null);
        }
    });

    emailEditText = (EditText) view.findViewById(R.id.dialog_register_edit_text_email);
    emailEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            // Nothing to do here...
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Nothing to do here...
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            emailEditText.setError(null);
        }
    });

    dialog = builder.create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {

            final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String username = usernameEditText.getText().toString();
                    String password = passwordEditText.getText().toString();
                    String email = emailEditText.getText().toString();

                    boolean formOk = true;

                    if (StringUtils.isBlank(username)) {
                        usernameEditText.setError(getString(R.string.cannot_be_empty));
                        formOk = false;
                    }
                    if (StringUtils.isBlank(password)) {
                        passwordEditText.setError(getString(R.string.cannot_be_empty));
                        formOk = false;
                    }
                    if (StringUtils.isBlank(email)) {
                        emailEditText.setError(getString(R.string.cannot_be_empty));
                        formOk = false;
                    }
                    if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
                        emailEditText.setError(getString(R.string.invalid_email));
                        formOk = false;
                    }

                    if (!formOk) {
                        Log.d(TAG, "Form contains errors.");
                        return;
                    }

                    password = SecurityUtils.hashSHA512Base64(password);

                    User newUser = new User();
                    newUser.setUsername(username);
                    newUser.setPassword(password);
                    newUser.setEmail(email);

                    tempRestClient = new RestClient(Prefs.getHost(), Prefs.getPort(), Prefs.getWsContextPath(),
                            username, password, Prefs.getRealm());
                    tempRestClient.registerUser(dialog.getContext(), newUser,
                            new GsonHttpResponseHandler<User>(new TypeToken<User>() {
                            }.getType()) {

                                @Override
                                public void onFailure(int statusCode, Header[] headers, String responseBody,
                                        Throwable error) {
                                    Log.e(TAG, "Registration failed. [statusCode = " + statusCode + ", error="
                                            + error + "]");

                                    if (statusCode == 0) {
                                        Toast.makeText(dialog.getOwnerActivity(), R.string.check_connection,
                                                Toast.LENGTH_LONG).show();
                                        ;
                                        return;
                                    }

                                    Toast.makeText(dialog.getContext(), R.string.pick_different_username,
                                            Toast.LENGTH_LONG).show();

                                    listener.onRegisterFailure();
                                }

                                @Override
                                public void onFinish() {
                                    positiveButton.setEnabled(true);
                                    UiUtilities.fadeInFadeOut(formView, progressView);
                                }

                                @Override
                                public void onStart() {
                                    positiveButton.setEnabled(false);
                                    UiUtilities.fadeInFadeOut(progressView, formView);
                                }

                                @Override
                                public void onSuccess(int statusCode, Header[] headers, User object) {
                                    Log.i(TAG, "Registration succeeded. [statusCode = " + statusCode + "]");
                                    dialog.dismiss();

                                    listener.onRegisterSuccess();
                                }

                            });

                }
            });

            final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
            negativeButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (tempRestClient != null) {
                        tempRestClient.cancelRequests(dialog.getOwnerActivity(), true);
                    }
                    dialog.dismiss();
                }
            });
        }
    });

    return dialog;
}