Android
0
Вклад в тег
public class CustomAlertDialog extends DialogFragment implements DialogInterface.OnClickListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.alert_custom_dialog, container, false);
ImageView background = (ImageView) rootView.findViewById(R.id.image);
Rect frame = new Rect();
getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, statusBarHeight, 0, 0);
background.setLayoutParams(params);
Bitmap map=takeScreenShot(getActivity());
Bitmap fast= FastBlur.doBlur(map, 10, true);
final Drawable draw=new BitmapDrawable(getActivity().getResources(),fast);
background.setImageDrawable(draw);
AlertDialog.Builder adb = new AlertDialog.Builder(getActivity())
.setPositiveButton("yes", this)
.setNegativeButton("no", this);
LayoutInflater dialogInflater = getActivity().getLayoutInflater();
adb.setView(dialogInflater.inflate(R.layout.slider_item, null)).show();
return rootView;
}
private static Bitmap takeScreenShot(Activity activity)
{
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b1 = view.getDrawingCache();
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay().getHeight();
Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
view.setDrawingCacheEnabled(false);
return b;
}
@Override
public void onClick(DialogInterface dialogInterface, int i) {
getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
}
}
public void showDialogFragment() {
View v = getActivity().getWindow().getDecorView();
v.setId(1);
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
DialogFragment newFragment = new CustomAlertDialog();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.add(1, newFragment)
.addToBackStack(null).commit();
}