Search in sources :

Example 21 with Builder

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

the class DialogUtils method showBlacklistDialog.

public static void showBlacklistDialog(final Context context) {
    View view = LayoutInflater.from(context).inflate(R.layout.dialog_blacklist, null);
    final MaterialDialog.Builder builder = getBuilder(context).title(R.string.blacklist_title).customView(view, false).positiveText(R.string.close).negativeText(R.string.pref_title_clear_blacklist).onNegative((materialDialog, dialogAction) -> {
        BlacklistHelper.deleteAllSongs();
        Toast.makeText(context, R.string.blacklist_deleted, Toast.LENGTH_SHORT).show();
    });
    final Dialog dialog = builder.build();
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    final BlacklistAdapter blacklistAdapter = new BlacklistAdapter();
    blacklistAdapter.setBlackListListener((v, position, song) -> {
        BlacklistHelper.deleteSong(song.id);
        if (blacklistAdapter.items.size() == 0) {
            dialog.dismiss();
        }
    });
    recyclerView.setAdapter(blacklistAdapter);
    Observable<List<Song>> songsObservable = SqlBriteUtils.createContinuousQuery(ShuttleApplication.getInstance(), Song::new, Song.getQuery()).first();
    Observable<List<BlacklistedSong>> blacklistObservable = BlacklistHelper.getBlacklistSongsObservable();
    Subscription subscription = Observable.combineLatest(songsObservable, blacklistObservable, (songs, blacklistedSongs) -> Stream.of(songs).filter(song -> Stream.of(blacklistedSongs).anyMatch(blacklistedSong -> blacklistedSong.songId == song.id)).sorted((a, b) -> ComparisonUtils.compare(a.albumArtistName, b.albumArtistName)).sorted((a, b) -> ComparisonUtils.compareInt(b.year, a.year)).sorted((a, b) -> ComparisonUtils.compareInt(a.track, b.track)).sorted((a, b) -> ComparisonUtils.compareInt(a.discNumber, b.discNumber)).sorted((a, b) -> ComparisonUtils.compare(a.albumName, b.albumName)).map(song -> (AdaptableItem) new BlacklistView(song)).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(blacklistViews -> {
        if (blacklistViews.size() == 0) {
            blacklistAdapter.addItem(0, new EmptyView(R.string.blacklist_empty));
        } else {
            blacklistAdapter.setItems(blacklistViews);
        }
    });
    dialog.setOnDismissListener(dialogInterface -> subscription.unsubscribe());
    dialog.show();
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ProgressBar(android.widget.ProgressBar) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Drawable(android.graphics.drawable.Drawable) FileProvider(android.support.v4.content.FileProvider) Song(com.simplecity.amp_library.model.Song) FileObject(com.simplecity.amp_library.model.FileObject) Schedulers(rx.schedulers.Schedulers) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) BlacklistAdapter(com.simplecity.amp_library.ui.adapters.BlacklistAdapter) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) WhitelistAdapter(com.simplecity.amp_library.ui.adapters.WhitelistAdapter) R.id.album(com.simplecity.amp_library.R.id.album) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) R.id.artist(com.simplecity.amp_library.R.id.artist) WhitelistHelper(com.simplecity.amp_library.sql.databases.WhitelistHelper) FileNotFoundException(java.io.FileNotFoundException) CustomColorPicker(com.simplecity.amp_library.ui.views.CustomColorPicker) List(java.util.List) TextView(android.widget.TextView) ColorAdapter(com.simplecity.amp_library.ui.adapters.ColorAdapter) Html(android.text.Html) LastFmArtist(com.simplecity.amp_library.lastfm.LastFmArtist) ListView(android.widget.ListView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Call(retrofit2.Call) Subscription(rx.Subscription) NumberPicker(android.widget.NumberPicker) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity) Context(android.content.Context) LastFmAlbum(com.simplecity.amp_library.lastfm.LastFmAlbum) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) HttpClient(com.simplecity.amp_library.http.HttpClient) Dialog(android.app.Dialog) Intent(android.content.Intent) RemoteException(android.os.RemoteException) StringRes(android.support.annotation.StringRes) Response(retrofit2.Response) SettingsFragment(com.simplecity.amp_library.ui.fragments.SettingsFragment) ArrayList(java.util.ArrayList) Observable(rx.Observable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) BlacklistedSong(com.simplecity.amp_library.model.BlacklistedSong) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) IntentCompat(android.support.v4.content.IntentCompat) FileOutputStream(java.io.FileOutputStream) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) IOException(java.io.IOException) File(java.io.File) OperationApplicationException(android.content.OperationApplicationException) Color(android.graphics.Color) RecyclerView(android.support.v7.widget.RecyclerView) ArrayAdapter(android.widget.ArrayAdapter) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) Callback(retrofit2.Callback) ScrollView(android.widget.ScrollView) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) TextView(android.widget.TextView) ListView(android.widget.ListView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) BlacklistAdapter(com.simplecity.amp_library.ui.adapters.BlacklistAdapter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) ArrayList(java.util.ArrayList) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) Subscription(rx.Subscription) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Example 22 with Builder

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

the class BitmapPalette method start.

protected void start(@NonNull final Bitmap bitmap) {
    final boolean skipCache = this.skipCache;
    if (!skipCache) {
        Palette palette = CACHE.get(url);
        if (palette != null) {
            apply(palette, true);
            return;
        }
    }
    Palette.Builder builder = new Palette.Builder(bitmap);
    if (interceptor != null) {
        builder = interceptor.intercept(builder);
    }
    builder.generate(new Palette.PaletteAsyncListener() {

        @Override
        public void onGenerated(Palette palette) {
            if (!skipCache) {
                CACHE.put(url, palette);
            }
            apply(palette, false);
        }
    });
}
Also used : Palette(android.support.v7.graphics.Palette)

Example 23 with Builder

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

the class SettingFragment method showIconDialog.

private void showIconDialog() {
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View dialogLayout = inflater.inflate(R.layout.icon_dialog, (ViewGroup) getActivity().findViewById(R.id.dialog_root));
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setView(dialogLayout);
    final AlertDialog alertDialog = builder.create();
    LinearLayout layoutTypeOne = (LinearLayout) dialogLayout.findViewById(R.id.layout_one);
    layoutTypeOne.setClickable(true);
    RadioButton radioTypeOne = (RadioButton) dialogLayout.findViewById(R.id.radio_one);
    LinearLayout layoutTypeTwo = (LinearLayout) dialogLayout.findViewById(R.id.layout_two);
    layoutTypeTwo.setClickable(true);
    RadioButton radioTypeTwo = (RadioButton) dialogLayout.findViewById(R.id.radio_two);
    TextView done = (TextView) dialogLayout.findViewById(R.id.done);
    radioTypeOne.setClickable(false);
    radioTypeTwo.setClickable(false);
    alertDialog.show();
    switch(mSharedPreferenceUtil.getIconType()) {
        case 0:
            radioTypeOne.setChecked(true);
            radioTypeTwo.setChecked(false);
            break;
        case 1:
            radioTypeOne.setChecked(false);
            radioTypeTwo.setChecked(true);
            break;
    }
    layoutTypeOne.setOnClickListener(v -> {
        radioTypeOne.setChecked(true);
        radioTypeTwo.setChecked(false);
    });
    layoutTypeTwo.setOnClickListener(v -> {
        radioTypeOne.setChecked(false);
        radioTypeTwo.setChecked(true);
    });
    done.setOnClickListener(v -> {
        mSharedPreferenceUtil.setIconType(radioTypeOne.isChecked() ? 0 : 1);
        String[] iconsText = getResources().getStringArray(R.array.icons);
        mChangeIcons.setSummary(radioTypeOne.isChecked() ? iconsText[0] : iconsText[1]);
        alertDialog.dismiss();
        Snackbar.make(getView(), "切换成功,重启应用生效", Snackbar.LENGTH_INDEFINITE).setAction("重启", v1 -> {
            Intent intent = new Intent(getActivity(), MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            getActivity().startActivity(intent);
            getActivity().finish();
            RxBus.getDefault().post(new ChangeCityEvent());
        }).show();
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) SharedPreferenceUtil(com.xiecc.seeWeather.common.utils.SharedPreferenceUtil) RadioButton(android.widget.RadioButton) R(com.xiecc.seeWeather.R) BaseApplication(com.xiecc.seeWeather.base.BaseApplication) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) Observable(rx.Observable) SeekBar(android.widget.SeekBar) Func1(rx.functions.Func1) ImageLoader(com.xiecc.seeWeather.component.ImageLoader) View(android.view.View) RxUtils(com.xiecc.seeWeather.common.utils.RxUtils) RxBus(com.xiecc.seeWeather.component.RxBus) AutoUpdateService(com.xiecc.seeWeather.modules.service.AutoUpdateService) LayoutInflater(android.view.LayoutInflater) ChangeCityEvent(com.xiecc.seeWeather.modules.main.domain.ChangeCityEvent) MainActivity(com.xiecc.seeWeather.modules.main.ui.MainActivity) ViewGroup(android.view.ViewGroup) File(java.io.File) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) FileUtil(com.xiecc.seeWeather.common.utils.FileUtil) Preference(android.preference.Preference) PreferenceFragment(android.preference.PreferenceFragment) Notification(android.app.Notification) SimpleSubscriber(com.xiecc.seeWeather.common.utils.SimpleSubscriber) Snackbar(android.support.design.widget.Snackbar) FileSizeUtil(com.xiecc.seeWeather.common.utils.FileSizeUtil) Intent(android.content.Intent) RadioButton(android.widget.RadioButton) MainActivity(com.xiecc.seeWeather.modules.main.ui.MainActivity) ChangeCityEvent(com.xiecc.seeWeather.modules.main.domain.ChangeCityEvent) View(android.view.View) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 24 with Builder

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

the class SettingFragment method showUpdateDialog.

private void showUpdateDialog() {
    //将 SeekBar 放入 Dialog 的方案 http://stackoverflow.com/questions/7184104/how-do-i-put-a-seek-bar-in-an-alert-dialog
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View dialogLayout = inflater.inflate(R.layout.update_dialog, (ViewGroup) getActivity().findViewById(R.id.dialog_root));
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setView(dialogLayout);
    final AlertDialog alertDialog = builder.create();
    final SeekBar mSeekBar = (SeekBar) dialogLayout.findViewById(R.id.time_seekbar);
    final TextView tvShowHour = (TextView) dialogLayout.findViewById(R.id.tv_showhour);
    TextView tvDone = (TextView) dialogLayout.findViewById(R.id.done);
    mSeekBar.setMax(24);
    mSeekBar.setProgress(mSharedPreferenceUtil.getAutoUpdate());
    tvShowHour.setText(String.format("每%s小时", mSeekBar.getProgress()));
    alertDialog.show();
    mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            tvShowHour.setText(String.format("每%s小时", mSeekBar.getProgress()));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    tvDone.setOnClickListener(v -> {
        mSharedPreferenceUtil.setAutoUpdate(mSeekBar.getProgress());
        mChangeUpdate.setSummary(mSharedPreferenceUtil.getAutoUpdate() == 0 ? "禁止刷新" : "每" + mSharedPreferenceUtil.getAutoUpdate() + "小时更新");
        getActivity().startService(new Intent(getActivity(), AutoUpdateService.class));
        alertDialog.dismiss();
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) SeekBar(android.widget.SeekBar) LayoutInflater(android.view.LayoutInflater) AutoUpdateService(com.xiecc.seeWeather.modules.service.AutoUpdateService) TextView(android.widget.TextView) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView)

Example 25 with Builder

use of android.support.v7.app.AlertDialog.Builder in project WordPress-Android by wordpress-mobile.

the class EditorFragment method onMediaTapped.

public void onMediaTapped(final String mediaId, final MediaType mediaType, final JSONObject meta, String uploadStatus) {
    if (mediaType == null || !isAdded()) {
        return;
    }
    switch(uploadStatus) {
        case "uploading":
            // Display 'cancel upload' dialog
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(getString(R.string.stop_upload_dialog_title));
            builder.setPositiveButton(R.string.stop_upload_button, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    mEditorFragmentListener.onMediaUploadCancelClicked(mediaId, true);
                    mWebView.post(new Runnable() {

                        @Override
                        public void run() {
                            switch(mediaType) {
                                case IMAGE:
                                    mWebView.execJavaScriptFromString("ZSSEditor.removeImage(" + mediaId + ");");
                                    break;
                                case VIDEO:
                                    mWebView.execJavaScriptFromString("ZSSEditor.removeVideo(" + mediaId + ");");
                            }
                            mUploadingMedia.remove(mediaId);
                        }
                    });
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();
            break;
        case "failed":
            // Retry media upload
            mEditorFragmentListener.onMediaRetryClicked(mediaId);
            mWebView.post(new Runnable() {

                @Override
                public void run() {
                    switch(mediaType) {
                        case IMAGE:
                            mWebView.execJavaScriptFromString("ZSSEditor.unmarkImageUploadFailed(" + mediaId + ");");
                            break;
                        case VIDEO:
                            mWebView.execJavaScriptFromString("ZSSEditor.unmarkVideoUploadFailed(" + mediaId + ");");
                    }
                    mFailedMediaIds.remove(mediaId);
                    mUploadingMedia.put(mediaId, mediaType);
                }
            });
            break;
        default:
            if (!mediaType.equals(MediaType.IMAGE)) {
                return;
            }
            // Only show image options fragment for image taps
            FragmentManager fragmentManager = getFragmentManager();
            if (fragmentManager.findFragmentByTag(ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_TAG) != null) {
                return;
            }
            mEditorFragmentListener.onTrackableEvent(TrackableEvent.IMAGE_EDITED);
            ImageSettingsDialogFragment imageSettingsDialogFragment = new ImageSettingsDialogFragment();
            imageSettingsDialogFragment.setTargetFragment(this, ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_REQUEST_CODE);
            Bundle dialogBundle = new Bundle();
            dialogBundle.putString("maxWidth", mBlogSettingMaxImageWidth);
            dialogBundle.putBoolean("featuredImageSupported", mFeaturedImageSupported);
            // Request and add an authorization header for HTTPS images
            // Use https:// when requesting the auth header, in case the image is incorrectly using http://.
            // If an auth header is returned, force https:// for the actual HTTP request.
            HashMap<String, String> headerMap = new HashMap<>();
            if (mCustomHttpHeaders != null) {
                headerMap.putAll(mCustomHttpHeaders);
            }
            try {
                final String imageSrc = meta.getString("src");
                String authHeader = mEditorFragmentListener.onAuthHeaderRequested(UrlUtils.makeHttps(imageSrc));
                if (authHeader.length() > 0) {
                    meta.put("src", UrlUtils.makeHttps(imageSrc));
                    headerMap.put("Authorization", authHeader);
                }
            } catch (JSONException e) {
                AppLog.e(T.EDITOR, "Could not retrieve image url from JSON metadata");
            }
            dialogBundle.putSerializable("headerMap", headerMap);
            dialogBundle.putString("imageMeta", meta.toString());
            String imageId = JSONUtils.getString(meta, "attachment_id");
            if (!imageId.isEmpty()) {
                dialogBundle.putBoolean("isFeatured", mFeaturedImageId == Integer.parseInt(imageId));
            }
            imageSettingsDialogFragment.setArguments(dialogBundle);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            fragmentTransaction.add(android.R.id.content, imageSettingsDialogFragment, ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_TAG).addToBackStack(null).commit();
            mWebView.notifyVisibilityChanged(false);
            break;
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Bundle(android.os.Bundle) JSONException(org.json.JSONException) SpannableString(android.text.SpannableString) SuppressLint(android.annotation.SuppressLint) FragmentManager(android.app.FragmentManager) OnClickListener(android.content.DialogInterface.OnClickListener) FragmentTransaction(android.app.FragmentTransaction)

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