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();
}
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);
}
});
}
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();
});
}
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();
});
}
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;
}
}
Aggregations