Search in sources :

Example 81 with Builder

use of android.support.v7.app.AlertDialog.Builder in project CoCoin by Nightonke.

the class RecordCheckDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context context = getActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    View view = LayoutInflater.from(context).inflate(R.layout.fragment_dialog_list, null, false);
    recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    RecordCheckDialogRecyclerViewAdapter adapter = new RecordCheckDialogRecyclerViewAdapter(context, list, this);
    recyclerView.setAdapter(adapter);
    builder.setTitle("Title");
    builder.setView(view);
    builder.setPositiveButton(mContext.getResources().getString(R.string.get), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    final AlertDialog alert = builder.create();
    TextView title = new TextView(mContext);
    title.setHeight(120);
    title.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    title.setTypeface(CoCoinUtil.typefaceLatoLight);
    title.setText(this.title);
    alert.setCustomTitle(title);
    alert.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button btnPositive = alert.getButton(Dialog.BUTTON_POSITIVE);
            btnPositive.setTypeface(CoCoinUtil.typefaceLatoLight);
        }
    });
    return alert;
}
Also used : Context(android.content.Context) AlertDialog(android.app.AlertDialog) RecordCheckDialogRecyclerViewAdapter(com.nightonke.saver.adapter.RecordCheckDialogRecyclerViewAdapter) DialogInterface(android.content.DialogInterface) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) Button(android.widget.Button) TextView(android.widget.TextView) NonNull(android.support.annotation.NonNull)

Example 82 with Builder

use of android.support.v7.app.AlertDialog.Builder in project Rajawali by Rajawali.

the class ExceptionDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.exception_dialog_title);
    builder.setMessage(R.string.exception_dialog_message_unknown);
    final Bundle bundle = getArguments();
    if (bundle != null) {
        if (bundle.containsKey(BUNDLE_KEY_MESSAGE))
            builder.setMessage(bundle.getString(BUNDLE_KEY_MESSAGE));
        if (bundle.containsKey(BUNDLE_KEY_TITLE))
            builder.setTitle(bundle.getString(BUNDLE_KEY_TITLE));
    }
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setCancelable(false);
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Bundle(android.os.Bundle) NonNull(android.support.annotation.NonNull)

Example 83 with Builder

use of android.support.v7.app.AlertDialog.Builder in project NewPipe by TeamNewPipe.

the class VideoItemDetailFragment method setupActionBarHandler.

private void setupActionBarHandler(final StreamInfo info) {
    actionBarHandler.setupStreamList(info.video_streams);
    actionBarHandler.setOnShareListener(new ActionBarHandler.OnActionListener() {

        @Override
        public void onActionSelected(int selectedStreamId) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_TEXT, info.webpage_url);
            intent.setType("text/plain");
            activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.share_dialog_title)));
        }
    });
    actionBarHandler.setOnOpenInBrowserListener(new ActionBarHandler.OnActionListener() {

        @Override
        public void onActionSelected(int selectedStreamId) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(info.webpage_url));
            activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.choose_browser)));
        }
    });
    actionBarHandler.setOnOpenInPopupListener(new ActionBarHandler.OnActionListener() {

        @Override
        public void onActionSelected(int selectedStreamId) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !PermissionHelper.checkSystemAlertWindowPermission(activity)) {
                Toast.makeText(activity, R.string.msg_popup_permission, Toast.LENGTH_LONG).show();
                return;
            }
            if (streamThumbnail != null)
                ActivityCommunicator.getCommunicator().backgroundPlayerThumbnail = streamThumbnail;
            VideoStream selectedVideoStream = info.video_streams.get(selectedStreamId);
            Intent i = new Intent(activity, PopupVideoPlayer.class);
            Toast.makeText(activity, "Starting in popup mode", Toast.LENGTH_SHORT).show();
            i.putExtra(PopupVideoPlayer.VIDEO_TITLE, info.title).putExtra(PopupVideoPlayer.STREAM_URL, selectedVideoStream.url).putExtra(PopupVideoPlayer.CHANNEL_NAME, info.uploader).putExtra(PopupVideoPlayer.VIDEO_URL, info.webpage_url);
            activity.startService(i);
        }
    });
    actionBarHandler.setOnPlayWithKodiListener(new ActionBarHandler.OnActionListener() {

        @Override
        public void onActionSelected(int selectedStreamId) {
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setPackage(KORE_PACKET);
                intent.setData(Uri.parse(info.webpage_url.replace("https", "http")));
                activity.startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
                AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                builder.setMessage(R.string.kore_not_found).setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(activity.getString(R.string.fdroid_kore_url)));
                        activity.startActivity(intent);
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
                builder.create().show();
            }
        }
    });
    actionBarHandler.setOnDownloadListener(new ActionBarHandler.OnActionListener() {

        @Override
        public void onActionSelected(int selectedStreamId) {
            if (!PermissionHelper.checkStoragePermissions(getActivity())) {
                return;
            }
            try {
                Bundle args = new Bundle();
                if (info.audio_streams != null) {
                    AudioStream audioStream = info.audio_streams.get(getPreferredAudioStreamId(info));
                    String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format);
                    args.putString(DownloadDialog.AUDIO_URL, audioStream.url);
                    args.putString(DownloadDialog.FILE_SUFFIX_AUDIO, audioSuffix);
                }
                if (info.video_streams != null) {
                    VideoStream selectedStreamItem = info.video_streams.get(selectedStreamId);
                    String videoSuffix = "." + MediaFormat.getSuffixById(selectedStreamItem.format);
                    args.putString(DownloadDialog.FILE_SUFFIX_VIDEO, videoSuffix);
                    args.putString(DownloadDialog.VIDEO_URL, selectedStreamItem.url);
                }
                args.putString(DownloadDialog.TITLE, info.title);
                DownloadDialog downloadDialog = DownloadDialog.newInstance(args);
                downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
            } catch (Exception e) {
                Toast.makeText(VideoItemDetailFragment.this.getActivity(), R.string.could_not_setup_download_menu, Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }
    });
    if (info.audio_streams == null) {
        actionBarHandler.showAudioAction(false);
    } else {
        actionBarHandler.setOnPlayAudioListener(new ActionBarHandler.OnActionListener() {

            @Override
            public void onActionSelected(int selectedStreamId) {
                boolean useExternalAudioPlayer = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(activity.getString(R.string.use_external_audio_player_key), false);
                Intent intent;
                AudioStream audioStream = info.audio_streams.get(getPreferredAudioStreamId(info));
                if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 18) {
                    //internal music player: explicit intent
                    if (!BackgroundPlayer.isRunning && streamThumbnail != null) {
                        ActivityCommunicator.getCommunicator().backgroundPlayerThumbnail = streamThumbnail;
                        intent = new Intent(activity, BackgroundPlayer.class);
                        intent.setAction(Intent.ACTION_VIEW);
                        Log.i(TAG, "audioStream is null:" + (audioStream == null));
                        Log.i(TAG, "audioStream.url is null:" + (audioStream.url == null));
                        intent.setDataAndType(Uri.parse(audioStream.url), MediaFormat.getMimeById(audioStream.format));
                        intent.putExtra(BackgroundPlayer.TITLE, info.title);
                        intent.putExtra(BackgroundPlayer.WEB_URL, info.webpage_url);
                        intent.putExtra(BackgroundPlayer.SERVICE_ID, streamingServiceId);
                        intent.putExtra(BackgroundPlayer.CHANNEL_NAME, info.uploader);
                        activity.startService(intent);
                    }
                } else {
                    intent = new Intent();
                    try {
                        intent.setAction(Intent.ACTION_VIEW);
                        intent.setDataAndType(Uri.parse(audioStream.url), MediaFormat.getMimeById(audioStream.format));
                        intent.putExtra(Intent.EXTRA_TITLE, info.title);
                        intent.putExtra("title", info.title);
                        // HERE !!!
                        activity.startActivity(intent);
                    } catch (Exception e) {
                        e.printStackTrace();
                        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                        builder.setMessage(R.string.no_player_found).setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent();
                                intent.setAction(Intent.ACTION_VIEW);
                                intent.setData(Uri.parse(activity.getString(R.string.fdroid_vlc_url)));
                                activity.startActivity(intent);
                            }
                        }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Log.i(TAG, "You unlocked a secret unicorn.");
                            }
                        });
                        builder.create().show();
                        Log.e(TAG, "Either no Streaming player for audio was installed, or something important crashed:");
                        e.printStackTrace();
                    }
                }
            }
        });
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) PopupVideoPlayer(org.schabi.newpipe.player.PopupVideoPlayer) InfoItemBuilder(org.schabi.newpipe.info_list.InfoItemBuilder) VideoStream(org.schabi.newpipe.extractor.stream_info.VideoStream) DownloadDialog(org.schabi.newpipe.download.DownloadDialog) Intent(android.content.Intent) Point(android.graphics.Point) AudioStream(org.schabi.newpipe.extractor.stream_info.AudioStream)

Example 84 with Builder

use of android.support.v7.app.AlertDialog.Builder in project SeriesGuide by UweTrottmann.

the class TraktCancelCheckinDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity().getApplicationContext();
    final Bundle args = getArguments();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setMessage(context.getString(R.string.traktcheckin_inprogress, mWait < 0 ? context.getString(R.string.not_available) : DateUtils.formatElapsedTime(mWait)));
    final SgApp app = SgApp.from(getActivity());
    builder.setPositiveButton(R.string.traktcheckin_cancel, new OnClickListener() {

        @Override
        @SuppressLint("CommitTransaction")
        public void onClick(DialogInterface dialog, int which) {
            AsyncTask<String, Void, String> cancelCheckinTask = new AsyncTask<String, Void, String>() {

                @Override
                protected String doInBackground(String... params) {
                    // check for credentials
                    if (!TraktCredentials.get(context).hasCredentials()) {
                        return context.getString(R.string.trakt_error_credentials);
                    }
                    try {
                        retrofit2.Response<Void> response = traktCheckin.get().deleteActiveCheckin().execute();
                        if (response.isSuccessful()) {
                            return null;
                        } else {
                            if (SgTrakt.isUnauthorized(context, response)) {
                                return context.getString(R.string.trakt_error_credentials);
                            }
                            SgTrakt.trackFailedRequest(context, "delete check-in", response);
                        }
                    } catch (IOException e) {
                        SgTrakt.trackFailedRequest(context, "delete check-in", e);
                    }
                    return context.getString(R.string.api_error_generic, context.getString(R.string.trakt));
                }

                @Override
                protected void onPostExecute(String message) {
                    if (message == null) {
                        // all good
                        Toast.makeText(context, R.string.checkin_canceled_success_trakt, Toast.LENGTH_SHORT).show();
                        // relaunch the trakt task which called us to
                        // try the check in again
                        AsyncTaskCompat.executeParallel(new TraktTask(app, args));
                    } else {
                        // well, something went wrong
                        Toast.makeText(context, message, Toast.LENGTH_LONG).show();
                    }
                }
            };
            AsyncTaskCompat.executeParallel(cancelCheckinTask);
        }
    });
    builder.setNegativeButton(R.string.traktcheckin_wait, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // broadcast check-in success
            EventBus.getDefault().post(new TraktTask.TraktActionCompleteEvent(TraktAction.valueOf(args.getString(InitBundle.TRAKTACTION)), true, null));
        }
    });
    return builder.create();
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) InitBundle(com.battlelancer.seriesguide.util.TraktTask.InitBundle) TraktTask(com.battlelancer.seriesguide.util.TraktTask) AsyncTask(android.os.AsyncTask) IOException(java.io.IOException) SgApp(com.battlelancer.seriesguide.SgApp) SuppressLint(android.annotation.SuppressLint) OnClickListener(android.content.DialogInterface.OnClickListener) SuppressLint(android.annotation.SuppressLint) NonNull(android.support.annotation.NonNull)

Example 85 with Builder

use of android.support.v7.app.AlertDialog.Builder in project material-dialogs by afollestad.

the class MaterialListPreference method showDialog.

@Override
protected void showDialog(Bundle state) {
    if (getEntries() == null || getEntryValues() == null) {
        throw new IllegalStateException("ListPreference requires an entries array and an entryValues array.");
    }
    int preselect = findIndexOfValue(getValue());
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context).title(getDialogTitle()).icon(getDialogIcon()).dismissListener(this).onAny(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            switch(which) {
                default:
                    MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                    break;
                case NEUTRAL:
                    MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
                    break;
                case NEGATIVE:
                    MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
                    break;
            }
        }
    }).negativeText(getNegativeButtonText()).items(getEntries()).autoDismiss(// immediately close the dialog after selection
    true).itemsCallbackSingleChoice(preselect, new MaterialDialog.ListCallbackSingleChoice() {

        @Override
        public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
            onClick(null, DialogInterface.BUTTON_POSITIVE);
            if (which >= 0 && getEntryValues() != null) {
                try {
                    Field clickedIndex = ListPreference.class.getDeclaredField("mClickedDialogEntryIndex");
                    clickedIndex.setAccessible(true);
                    clickedIndex.set(MaterialListPreference.this, which);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return true;
        }
    });
    final View contentView = onCreateDialogView();
    if (contentView != null) {
        onBindDialogView(contentView);
        builder.customView(contentView, false);
    } else {
        builder.content(getDialogMessage());
    }
    PrefUtil.registerOnActivityDestroyListener(this, this);
    dialog = builder.build();
    if (state != null) {
        dialog.onRestoreInstanceState(state);
    }
    onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
    dialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ListPreference(android.preference.ListPreference) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Field(java.lang.reflect.Field) DialogAction(com.afollestad.materialdialogs.DialogAction)

Aggregations

AlertDialog (android.support.v7.app.AlertDialog)114 DialogInterface (android.content.DialogInterface)76 View (android.view.View)67 TextView (android.widget.TextView)48 Intent (android.content.Intent)36 RecyclerView (android.support.v7.widget.RecyclerView)27 ListView (android.widget.ListView)23 Dialog (android.app.Dialog)22 LayoutInflater (android.view.LayoutInflater)20 ImageView (android.widget.ImageView)20 EditText (android.widget.EditText)18 SuppressLint (android.annotation.SuppressLint)17 Context (android.content.Context)17 Bundle (android.os.Bundle)15 NonNull (android.support.annotation.NonNull)14 Button (android.widget.Button)13 ArrayList (java.util.ArrayList)12 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)10 OnClickListener (android.content.DialogInterface.OnClickListener)10 ScrollView (android.widget.ScrollView)10