Advertisement
Guest User

Untitled

a guest
Apr 24th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. //the relevant code
  2.  
  3.  
  4.  
  5. private void showDialog() {
  6. final View dialogView = View.inflate(MainActivity.this, R.layout.image_selector_dialog, null);
  7. AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  8. builder.setView(dialogView)
  9. .setCancelable(false);
  10. cameraDialog = builder.create();
  11. cameraDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
  12. cameraDialog.setOnShowListener(new DialogInterface.OnShowListener() {
  13. @Override
  14. public void onShow(DialogInterface dialog) {
  15. revealShow(dialogView, true, null);
  16. }
  17. });
  18. dialogView.findViewById(R.id.gallery_icon).setOnClickListener(new View.OnClickListener() {
  19. @Override
  20. public void onClick(View v) {
  21. galleryIntent();
  22. cameraDialog.dismiss();
  23.  
  24. }
  25. });
  26. dialogView.findViewById(R.id.camera_icon).setOnClickListener(new View.OnClickListener() {
  27. @Override
  28. public void onClick(View v) {
  29. cameraIntent();
  30. cameraDialog.dismiss();
  31.  
  32. }
  33. });
  34. cameraDialog.setCanceledOnTouchOutside(true);
  35. cameraDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
  36. Window window = cameraDialog.getWindow();
  37. window.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
  38. dialogView.setOnTouchListener(new View.OnTouchListener() {
  39. @Override
  40. public boolean onTouch(View v, MotionEvent event) {
  41.  
  42. if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
  43.  
  44. revealShow(dialogView, false, cameraDialog);
  45. }
  46. return false;
  47. }
  48. });
  49. cameraDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
  50. cameraDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
  51. @Override
  52. public void onCancel(DialogInterface dialog) {
  53. Log.d(TAG, "cancelled");
  54. }
  55. });
  56. cameraDialog.setCancelable(true);
  57. WindowManager.LayoutParams wmlp = cameraDialog.getWindow().getAttributes();
  58. //
  59. wmlp.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
  60.  
  61. wmlp.y = fab.getBaseline(); //y position
  62. createHandler(dialogView);
  63. if (imageHandler != null)
  64. new ImageLoader(imageHandler, this).execute();
  65. cameraDialog.show();
  66.  
  67. }
  68.  
  69. private void revealShow(View rootView, boolean reveal, final AlertDialog dialog) {
  70. final View view = rootView.findViewById(R.id.dialog_layout);
  71. int w = view.getWidth();
  72. int h = view.getHeight();
  73. Display display = getWindowManager().getDefaultDisplay();
  74. Point size = new Point();
  75. display.getSize(size);
  76.  
  77. int cx = (int) size.x - (fab.getLeft() + fab.getWidth());
  78. int cy = (int) size.y - (fab.getTop() + fab.getHeight());
  79. Log.d(TAG, "cx" + cx + "cy" + cy);
  80. Log.d(TAG, "datatop" + fab.getX() + "dataright" + fab.getLeft());
  81.  
  82. Log.d(TAG, "fabWidth" + fab.getWidth() + "fabHeight" + fab.getHeight());
  83. // int h = (view.getTop() + view.getBottom());
  84. float maxRadius = (float) Math.max(w, h);
  85. float minRadius = (float) fab.getWidth() / 4;
  86. Log.d(TAG, "radius" + maxRadius);
  87.  
  88. if (reveal) {
  89. SupportAnimator animator =
  90. ViewAnimationUtils.createCircularReveal(view, cx, cy, minRadius, maxRadius);
  91. animator.setInterpolator(new AccelerateDecelerateInterpolator());
  92. animator.setDuration(500);
  93. view.setVisibility(View.VISIBLE);
  94. animator.start();
  95.  
  96.  
  97. } else {
  98. SupportAnimator anim =
  99. ViewAnimationUtils.createCircularReveal(view, cx, cy, maxRadius, minRadius);
  100. anim.setInterpolator(new AccelerateDecelerateInterpolator());
  101. anim.setDuration(500);
  102. anim.addListener(new io.codetail.animation.SupportAnimator.AnimatorListener() {
  103.  
  104.  
  105. @Override
  106. public void onAnimationStart() {
  107.  
  108. }
  109.  
  110. @Override
  111. public void onAnimationEnd() {
  112.  
  113. dialog.dismiss();
  114. view.setVisibility(View.INVISIBLE);
  115. }
  116.  
  117. @Override
  118. public void onAnimationCancel() {
  119.  
  120. }
  121.  
  122. @Override
  123. public void onAnimationRepeat() {
  124.  
  125. }
  126. });
  127.  
  128. anim.start();
  129. }
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement