1
0

DialogBase.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package com.afollestad.materialdialogs.base;
  2. import android.app.AlertDialog;
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.graphics.Paint;
  6. import android.graphics.Typeface;
  7. import android.graphics.drawable.Drawable;
  8. import android.os.Build;
  9. import android.os.Message;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.TextView;
  13. /**
  14. * @author Aidan Follestad (afollestad)
  15. */
  16. public class DialogBase extends AlertDialog implements DialogInterface.OnShowListener {
  17. protected final static String POSITIVE = "POSITIVE";
  18. protected final static String NEGATIVE = "NEGATIVE";
  19. protected final static String NEUTRAL = "NEUTRAL";
  20. private OnShowListener mShowListener;
  21. protected DialogBase(Context context) {
  22. super(context);
  23. }
  24. protected void setVerticalMargins(View view, int topMargin, int bottomMargin) {
  25. ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
  26. boolean changed = false;
  27. if (topMargin > -1 && params.topMargin != topMargin) {
  28. params.topMargin = topMargin;
  29. changed = true;
  30. }
  31. if (bottomMargin > -1 && params.bottomMargin != bottomMargin) {
  32. params.bottomMargin = bottomMargin;
  33. changed = true;
  34. }
  35. if (changed)
  36. view.setLayoutParams(params);
  37. }
  38. /**
  39. * @deprecated Not supported by the Material dialog.
  40. */
  41. @Deprecated
  42. @Override
  43. public void setView(View view) {
  44. throw new RuntimeException("This method is not supported by the MaterialDialog.");
  45. }
  46. protected void setViewInternal(View view) {
  47. super.setView(view);
  48. }
  49. /**
  50. * @deprecated Not supported by the Material dialog.
  51. */
  52. @Deprecated
  53. @Override
  54. public void setView(View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight, int viewSpacingBottom) {
  55. throw new RuntimeException("This method is not supported by the MaterialDialog.");
  56. }
  57. /**
  58. * @deprecated Use setContent() instead.
  59. */
  60. @Deprecated
  61. @Override
  62. public void setMessage(CharSequence message) {
  63. throw new RuntimeException("This method is not supported by the MaterialDialog, use setContent() instead.");
  64. }
  65. /**
  66. * @deprecated Not supported by the Material dialog.
  67. */
  68. @Deprecated
  69. @Override
  70. public void setCustomTitle(View customTitleView) {
  71. throw new RuntimeException("This method is not supported by the MaterialDialog.");
  72. }
  73. /**
  74. * @deprecated Not supported by the Material dialog.
  75. */
  76. @Deprecated
  77. @Override
  78. public void setButton(int whichButton, CharSequence text, Message msg) {
  79. throw new RuntimeException("Use setActionButton(MaterialDialog.Button, CharSequence) instead.");
  80. }
  81. /**
  82. * @deprecated Not supported by the Material dialog.
  83. */
  84. @Deprecated
  85. @Override
  86. public void setButton(int whichButton, CharSequence text, OnClickListener listener) {
  87. throw new RuntimeException("Use setActionButton(MaterialDialog.Button, CharSequence) instead.");
  88. }
  89. @Override
  90. public final void setOnShowListener(OnShowListener listener) {
  91. mShowListener = listener;
  92. }
  93. protected final void setOnShowListenerInternal() {
  94. super.setOnShowListener(this);
  95. }
  96. @Override
  97. public void onShow(DialogInterface dialog) {
  98. if (mShowListener != null)
  99. mShowListener.onShow(dialog);
  100. }
  101. protected void setBackgroundCompat(View view, Drawable d) {
  102. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
  103. //noinspection deprecation
  104. view.setBackgroundDrawable(d);
  105. } else {
  106. view.setBackground(d);
  107. }
  108. }
  109. protected void setTypeface(TextView text, Typeface t) {
  110. if (t == null) return;
  111. int flags = text.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG;
  112. text.setPaintFlags(flags);
  113. text.setTypeface(t);
  114. }
  115. }