我正在尝试通过图像链接设置壁纸。
我的问题是:如何显示对话框“从服务器加载图像”,然后是“设置壁纸”。此后,弹出窗口会询问用户他们想在哪里设置壁纸。
当前情况:当用户点击“设置壁纸”按钮时,它仅显示对话框消息并继续加载。然后用户需要关闭弹出窗口并再次点击。这意味着他们需要点击两次才能设置壁纸。我希望让他们更容易理解。
基本上,我希望我的用户知道在安卓中运行了哪些进程。
以下是代码:
progressDialog = ProgressDialog.show(getActivity(),"Please wait...","Set as your wallpaper...",false,true);
Picasso.get()
.load(setImgLink)
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getActivity());
try {
if (bitmap != null) {
wallpaperManager.setBitmap(bitmap);
Snackbar.make(relative_image_slider, "Wallpaper was set", Snackbar.LENGTH_SHORT).show();
progressDialog.dismiss();
ct_popup.setText("Wallpaper was set");
final AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
builder1.setView(subView);
builder1.setPositiveButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
((ViewGroup)subView.getParent()).removeView(subView);
}
});
builder1.setIcon(R.mipmap.ic_launcher);
builder1.setCancelable(false);
builder1.create();
builder1.show();
}else {
Toast.makeText(getActivity(), "Unable to set your wallpaper !!", Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
Toast.makeText(getActivity(), "Something went wrong !!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
@Override
public void onBitmapFailed(Exception e, Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});