Example usage for android.app AlertDialog.Builder getContext

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

Introduction

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

Prototype

public final @NonNull Context getContext() 

Source Link

Document

Retrieve the Context this Dialog is running in.

Usage

From source file:cc.metapro.openct.utils.ActivityUtils.java

public static AlertDialog addViewToAlertDialog(@NonNull final AlertDialog.Builder builder,
        @NonNull final View view) {
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null) {
        parent.removeView(view);//from w ww  .jav a  2s. c o m
    }

    ScrollView scrollView = new ScrollView(builder.getContext());
    scrollView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    scrollView.addView(view);

    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            InputMethodManager imm = (InputMethodManager) builder.getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    });

    AlertDialog dialog = builder.setView(scrollView).create();
    Window window = dialog.getWindow();
    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }
    return dialog;
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.UpdaterDialogManager.java

@SuppressLint("NewApi")
private static View createMessageDialogContentsView(Activity activity, MessageDescription messageDescription) {

    Context context = activity;/*from  w  w w . j  a  v  a 2 s . c om*/

    final AlertDialog.Builder builder;

    // Workaround for dialog theme problems
    if (android.os.Build.VERSION.SDK_INT > 10) {
        builder = new AlertDialog.Builder(context);
        context = builder.getContext();
    } else {
        context = new ContextThemeWrapper(context, android.R.style.Theme_Dialog);
        builder = new AlertDialog.Builder(context);
    }

    builder.setTitle("Send feedback");

    final LayoutInflater inflater = LayoutInflater.from(context);
    final View dialogContentsView = inflater.inflate(R.layout.updater_dialog_message, null, false);
    final TextView textView = (TextView) dialogContentsView.findViewById(R.id.dialog_update_message_text);
    final ImageView imageView = (ImageView) dialogContentsView.findViewById(R.id.dialog_update_message_image);
    final ViewSwitcher switcher = (ViewSwitcher) dialogContentsView
            .findViewById(R.id.dialog_update_message_switcher);

    String messageText = null;
    String imageUrl = null;

    if (messageDescription != null) {
        messageText = messageDescription.get(MessageDescription.KEY_MESSAGE);
        imageUrl = messageDescription.get(MessageDescription.KEY_IMAGE_URL);
    }

    if (Utilities.isNullOrEmpty(messageText)) {
        textView.setVisibility(View.GONE);
    } else {
        textView.setText(messageText);
    }

    if (Utilities.isNullOrEmpty(imageUrl)) {
        switcher.setVisibility(View.GONE);
    } else {
        URI uri;
        try {
            uri = new URI(imageUrl);
        } catch (URISyntaxException e) {
            uri = null;
        }

        if (uri != null) {
            DownloadRequest request = new DownloadRequest();
            request.setUri(uri);
            request.setDownloadHandler(new DownloadHandler() {

                @Override
                public void onSuccess(byte[] result) {
                    // Load image from byte array
                    final Bitmap bitmap = BitmapFactory.decodeByteArray(result, 0, result.length);
                    imageView.setImageBitmap(bitmap);

                    // Hide progress bar and display image
                    if (switcher != null) {
                        switcher.setDisplayedChild(1);
                    }
                }

                @Override
                public void onProgress(Integer percent) {

                }

                @Override
                public void onFail(Exception ex) {
                    Log.e("Message image couldn't be loaded", ex);
                }

                @Override
                public void onCancelled() {

                }
            });
            HttpClient client = Utilities.createClient("Turkcell Updater/1.0 ", false);
            try {
                request.executeAsync(client);
            } catch (Exception e) {
                Log.e("Message image couldn't be loaded", e);
            }

        } else {
            switcher.setVisibility(View.GONE);
        }

    }

    return dialogContentsView;
}

From source file:net.simonvt.schematic.sample.ui.dialog.NewListDialog.java

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

    View v = LayoutInflater.from(builder.getContext()).inflate(R.layout.dialog_new_list, null);
    final EditText listName = (EditText) v.findViewById(R.id.listName);

    builder.setView(v);/*from  ww  w.ja  v a2  s  .  c  om*/

    builder.setTitle(R.string.new_list)
            .setPositiveButton(R.string.create_list, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    final String name = listName.getText().toString();
                    final Context context = getActivity().getApplicationContext();
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            ContentValues cv = new ContentValues();
                            cv.put(ListColumns.TITLE, name);
                            context.getContentResolver().insert(Lists.CONTENT_URI, cv);
                        }
                    }).start();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });

    return builder.create();
}

From source file:org.getlantern.firetweet.fragment.support.RetweetQuoteDialogFragment.java

@NonNull
@Override//from  w  w  w.jav  a 2 s.c om
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
    final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
    final Context context = builder.getContext();
    final LayoutInflater inflater = LayoutInflater.from(context);
    @SuppressLint("InflateParams")
    final View view = inflater.inflate(R.layout.dialog_scrollable_status, null);
    final StatusViewHolder holder = new StatusViewHolder(new DummyStatusHolderAdapter(context),
            view.findViewById(R.id.item_content));
    final ParcelableStatus status = getStatus();

    builder.setView(view);
    builder.setTitle(R.string.retweet_quote_confirm_title);
    builder.setPositiveButton(isMyRetweet(status) ? R.string.cancel_retweet : R.string.retweet, this);
    builder.setNeutralButton(R.string.quote, this);
    builder.setNegativeButton(android.R.string.cancel, null);

    holder.displayStatus(status, null, false, true);

    view.findViewById(R.id.item_menu).setVisibility(View.GONE);
    view.findViewById(R.id.action_buttons).setVisibility(View.GONE);

    return builder.create();
}

From source file:com.ruesga.rview.fragments.EditAssigneeDialogFragment.java

@Override
public void buildDialog(AlertDialog.Builder builder, Bundle savedInstanceState) {
    LayoutInflater inflater = LayoutInflater.from(builder.getContext());
    mBinding = DataBindingUtil.inflate(inflater, R.layout.edit_assignee_dialog, null, true);
    mBinding.assignee.addTextChangedListener(mTextWatcher);
    mBinding.assignee.setOnItemClickListener((parent, view, position, id) -> {
        AccountInfo account = ((AccountsAdapter) (parent.getAdapter())).getAccountAt((position));
        mModel.assignee = String.valueOf(account.accountId);
        mBinding.setModel(mModel);/*from   w w  w  .  j  a  va2  s .  c  om*/
        AndroidHelper.hideSoftKeyboard(getContext(), getDialog().getWindow());
    });
    mBinding.setModel(mModel);
    AccountsAdapter adapter = new AccountsAdapter(mBinding.getRoot().getContext());
    mBinding.assignee.setAdapter(adapter);

    builder.setTitle(R.string.edit_assignee_title).setView(mBinding.getRoot())
            .setNegativeButton(R.string.action_cancel, null)
            .setPositiveButton(R.string.action_assign, (dialog, which) -> performAssigneeSelected());
}

From source file:de.vanita5.twittnuker.fragment.support.RetweetQuoteDialogFragment.java

@NonNull
@Override//from   w  w w.  j  av  a 2s.  com
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
    final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
    final Context context = builder.getContext();
    final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(context,
            SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final ImageLoaderWrapper loader = TwittnukerApplication.getInstance(context).getImageLoaderWrapper();
    final ImageLoadingHandler handler = new ImageLoadingHandler(R.id.media_preview_progress);
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final LayoutInflater inflater = LayoutInflater.from(context);
    @SuppressLint("InflateParams")
    final View view = inflater.inflate(R.layout.dialog_scrollable_status, null);
    final StatusViewHolder holder = new StatusViewHolder(view.findViewById(R.id.item_content));
    final int profileImageStyle = Utils
            .getProfileImageStyle(preferences.getString(KEY_PROFILE_IMAGE_STYLE, null));
    final int mediaPreviewStyle = Utils
            .getMediaPreviewStyle(preferences.getString(KEY_MEDIA_PREVIEW_STYLE, null));
    final ParcelableStatus status = getStatus();

    builder.setView(view);
    builder.setTitle(R.string.retweet_quote_confirm_title);
    builder.setPositiveButton(isMyRetweet(status) ? R.string.cancel_retweet : R.string.retweet, this);
    builder.setNeutralButton(R.string.quote, this);
    builder.setNegativeButton(android.R.string.cancel, null);

    holder.displayStatus(context, loader, handler, twitter, profileImageStyle, mediaPreviewStyle, true,
            getStatus(), null, true);
    view.findViewById(R.id.item_menu).setVisibility(View.GONE);
    view.findViewById(R.id.action_buttons).setVisibility(View.GONE);
    view.findViewById(R.id.reply_retweet_status).setVisibility(View.GONE);

    return builder.create();
}

From source file:net.simonvt.cathode.ui.dialog.RatingDialog.java

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

    View v = LayoutInflater.from(builder.getContext()).inflate(R.layout.dialog_rating, null);
    final int rating = getArguments().getInt(ARG_RATING);
    final TextView ratingText = (TextView) v.findViewById(R.id.ratingText);
    ratingText.setText(this.ratingText[this.rating]);
    final RatingBar ratingBar = (RatingBar) v.findViewById(R.id.rating);
    ratingBar.setRating(rating);// w w w .j av  a2  s  . c om
    ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
        @Override
        public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
            RatingDialog.this.rating = (int) v;
            ratingText.setText(RatingDialog.this.ratingText[(int) v]);
        }
    });

    builder.setView(v);
    builder.setPositiveButton(R.string.action_rate, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            switch (type) {
            case SHOW:
                showScheduler.rate(id, (int) ratingBar.getRating());
                break;

            case EPISODE:
                episodeScheduler.rate(id, (int) ratingBar.getRating());
                break;

            case MOVIE:
                movieScheduler.rate(id, (int) ratingBar.getRating());
                break;
            }
        }
    });

    return builder.create();
}

From source file:com.ruesga.rview.fragments.AddReviewerDialogFragment.java

@Override
public void buildDialog(AlertDialog.Builder builder, Bundle savedInstanceState) {
    LayoutInflater inflater = LayoutInflater.from(builder.getContext());
    mBinding = DataBindingUtil.inflate(inflater, R.layout.add_reviewer_dialog, null, true);
    mBinding.reviewer.addTextChangedListener(mTextWatcher);
    mBinding.reviewer.setOnItemClickListener((parent, view, position, id) -> {
        SuggestedReviewerInfo reviewer = ((SuggestedReviewersAdapter) (parent.getAdapter()))
                .getSuggestedReviewerAt(position);
        mModel.reviewer = reviewer.account != null ? String.valueOf(reviewer.account.accountId)
                : reviewer.group.id;/*  www  .  ja v  a 2 s.c  o  m*/
        mBinding.setModel(mModel);
        AndroidHelper.hideSoftKeyboard(getContext(), getDialog().getWindow());
    });
    mBinding.setModel(mModel);
    SuggestedReviewersAdapter adapter = new SuggestedReviewersAdapter(mBinding.getRoot().getContext(),
            mLegacyChangeId);
    mBinding.reviewer.setAdapter(adapter);

    builder.setTitle(mReviewerState.equals(AddReviewerState.REVIEWER) ? R.string.change_details_add_reviewer
            : R.string.change_details_add_cc).setView(mBinding.getRoot())
            .setNegativeButton(R.string.action_cancel, null)
            .setPositiveButton(R.string.action_add, (dialog, which) -> performAddReviewer());
}

From source file:org.gateshipone.malp.application.fragments.TextDialog.java

@NonNull
@Override//ww w  . j av  a2s .  com
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();

    if (null != args) {
        mTitle = args.getString(EXTRA_DIALOG_TITLE);
        mText = args.getString(EXTRA_DIALOG_TEXT);
    }

    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    // create edit text for title
    final EditText editTextTitle = new EditText(builder.getContext());
    editTextTitle.setText(mText);

    // Add a listener that just removes the text on first clicking
    editTextTitle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mFirstClick) {
                editTextTitle.setText("");
                mFirstClick = true;
            }
        }
    });
    builder.setView(editTextTitle);

    builder.setMessage(mTitle)
            .setPositiveButton(R.string.dialog_action_save, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // accept title and call callback method
                    String objectTitle = editTextTitle.getText().toString();
                    mSaveCallback.onFinished(objectTitle);
                }
            }).setNegativeButton(R.string.dialog_action_cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User cancelled the dialog don't save object
                    getDialog().cancel();
                }
            });
    // Create the AlertDialog object and return it
    return builder.create();
}

From source file:com.crcrch.chromatictuner.app.NotePickerFragment.java

@NonNull
@Override/* ww w .j a va2s .c  om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());

    View dialogContent = LayoutInflater.from(dialogBuilder.getContext()).inflate(R.layout.fragment_note_picker,
            null);

    final NumberPicker notePicker = (NumberPicker) dialogContent.findViewById(R.id.picker_note);
    notePicker.setMinValue(0);
    notePicker.setMaxValue(MiscMusic.CHROMATIC_SCALE.length - 1);
    notePicker.setDisplayedValues(MiscMusic.CHROMATIC_SCALE);
    notePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    final NumberPicker octavePicker = (NumberPicker) dialogContent.findViewById(R.id.picker_octave);
    octavePicker.setMinValue(0);
    octavePicker.setMaxValue(MAX_OCTAVE);
    octavePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    octavePicker.setWrapSelectorWheel(false);

    final TextView frequencyView = (TextView) dialogContent.findViewById(R.id.frequency);
    notePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            frequencyView.setText(selectFrequency(newVal, octavePicker.getValue()));
        }
    });
    octavePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            frequencyView.setText(selectFrequency(notePicker.getValue(), newVal));
        }
    });

    double frequencyToDisplay;
    if (savedInstanceState == null) {
        frequencyToDisplay = initialFrequency;
    } else {
        frequencyToDisplay = savedInstanceState.getDouble(STATE_FREQUENCY);
    }
    frequencyView.setText(selectFrequency(frequencyToDisplay));
    int note = getNoteForFrequency(frequencyToDisplay);
    octavePicker.setValue(getOctaveForNote(note));
    octavePicker.invalidate();
    notePicker.setValue(getNoteIndexForNote(note));
    notePicker.invalidate();

    return dialogBuilder.setTitle(R.string.dialog_title_note_picker).setView(dialogContent)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    listener.onFrequencySelected(frequency);
                    dialog.dismiss();
                }
            }).setNegativeButton(android.R.string.cancel, null).create();
}