public class BackgroundNoteDialog extends BottomSheetDialogFragment {

private DialogBackgroundNoteBinding binding; public void setStandard(Standard standard) { this.standard = standard; } private Standard standard; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = DialogBackgroundNoteBinding.inflate(inflater, container, false); return binding.getRoot(); } @SuppressLint("ClickableViewAccessibility") @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Light_NoTitleBar); binding.fab.setOnClickListener(v -> { Bitmap bitmap = getBitmapByView(binding.getRoot()); / / Intent share_intent = new Intent(); share_intent.setAction(Intent.ACTION_SEND); // Set share_intent.setType("image/*"); // Set the type of shared content to share_intent.setPackage("com.android.bluetooth"); EXTRA_STREAM (intent.extra_stream, saveBitmap(bitmap," XXX ")); // Create a shared Dialog requireActivity().startActivity(share_intent); }); binding.fileName.setText(standard.getFileName()); binding.methodName.setText(standard.getMethodName()); binding.projectName.setText(standard.getProjectName()); binding.FZname.setText(standard.getFZname()); binding.serialNumber.setText(standard.getSerialNumber()); binding.sampleName.setText(standard.getSampleName()); binding.measuringTime.setText(standard.getMeasuringTime()); binding.measuringResult.setText(standard.getMeasuringResult()); } /** * private static Uri saveBitmap(Bitmap bm, String picName) { try { String dir= Environment.getExternalStorageDirectory().getAbsolutePath()+"/renji/"+picName+".jpg"; File f = new File(dir); if (! f.exists()) { f.getParentFile().mkdirs(); f.createNewFile(); } FileOutputStream out = new FileOutputStream(f); bm.compress(Bitmap.CompressFormat.PNG, 90, out); out.flush(); out.close(); Uri uri = Uri.fromFile(f); return uri; } catch (IOException e) { e.printStackTrace(); } return null; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState);Copy the code

// Objects.requireNonNull(getDialog()).setCancelable(false); // Objects.requireNonNull(getDialog()).setCanceledOnTouchOutside(false); Window window = getDialog().getWindow(); //window.setWindowAnimations(R.style.TopDialogAnimation); WindowManager.LayoutParams windowParams = window.getAttributes(); WindowParams. DimAmount = 0.0 f; / / outside borders transparent Dialog window. SetLayout (ViewGroup. LayoutParams. MATCH_PARENT, ViewGroup. LayoutParams. WRAP_CONTENT); // Height adaptive, width full screen Windowparams. gravity = gravity. // Display window.setAttributes(windowParams) at the top; }

@override public void show(FragmentManager manager, String tag) {try {// Add a remove transaction before each add transaction. Prevent sequential add Manager.beginTransaction ().remove(this).commit(); super.show(manager, tag); / / Margaret spellings endEmptyMessageDelayed (1200); } catch (Exception e) {// The same instance with a different tag will be an Exception, e.printStackTrace(); } /** * get the content and width of the row.  */ private String getTextNeiRon(TextView edit){ Layout layout = edit.getLayout(); String text = edit.getText().toString(); int start = layout.getLineEnd(0); int end; StringBuilder line= new StringBuilder(); for (int i = 1; i < edit.getLineCount(); i++) { end = layout.getLineEnd(i); line.append(text.substring(start, end)); // Start = end; //float width = layout.getLineWidth(i); } return line.tostring (); } private BottomSheetBehavior mBottomSheetBehavior; @Override public void onStart() { super.onStart(); Dialog dialog = getDialog(); WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes(); layoutParams.dimAmount = 0f; // Adjust transparency dialog.getwindow ().setAttributes(layoutParams); if (dialog ! = null) { View bottomSheet = dialog.findViewById(R.id.design_bottom_sheet); bottomSheet.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT; } final View view = getView(); view.post(new Runnable() { @Override public void run() { View parent = (View) view.getParent(); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) (parent).getLayoutParams(); mBottomSheetBehavior = (BottomSheetBehavior) params.getBehavior(); assert mBottomSheetBehavior ! = null; mBottomSheetBehavior.setPeekHeight(view.getMeasuredHeight() / 2); }}); } public static Bitmap getBitmapByView(NestedScrollView scrollView) { int h = 0; Bitmap bitmap = null; for (int i = 0; i < scrollView.getChildCount(); i++) { h += scrollView.getChildAt(i).getHeight(); } bitmap = Bitmap.createBitmap(scrollView.getWidth(), h,Bitmap.Config.RGB_565); final Canvas canvas = new Canvas(bitmap); scrollView.draw(canvas); return bitmap; }Copy the code

}