0c6580dbd717d50f7cb237dc8c38e38de169a456.svn-base 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. package com.hjq.base;
  2. import android.content.Context;
  3. import android.content.DialogInterface;
  4. import android.content.res.Resources;
  5. import android.graphics.drawable.Drawable;
  6. import android.os.Build;
  7. import android.os.Handler;
  8. import android.os.Looper;
  9. import android.os.SystemClock;
  10. import android.support.annotation.ColorRes;
  11. import android.support.annotation.DrawableRes;
  12. import android.support.annotation.IdRes;
  13. import android.support.annotation.LayoutRes;
  14. import android.support.annotation.NonNull;
  15. import android.support.annotation.Nullable;
  16. import android.support.annotation.StringRes;
  17. import android.support.annotation.StyleRes;
  18. import android.support.v7.app.AppCompatDialog;
  19. import android.util.SparseArray;
  20. import android.util.SparseIntArray;
  21. import android.view.Gravity;
  22. import android.view.LayoutInflater;
  23. import android.view.View;
  24. import android.view.ViewGroup;
  25. import android.view.WindowManager;
  26. import android.widget.ImageView;
  27. import android.widget.TextView;
  28. import java.util.ArrayList;
  29. import java.util.List;
  30. /**
  31. * desc : Dialog 基类
  32. */
  33. public class BaseDialog extends AppCompatDialog implements
  34. DialogInterface.OnShowListener,
  35. DialogInterface.OnCancelListener,
  36. DialogInterface.OnDismissListener {
  37. private static final Handler HANDLER = new Handler(Looper.getMainLooper());
  38. private List<BaseDialog.OnShowListener> mOnShowListeners;
  39. private List<BaseDialog.OnCancelListener> mOnCancelListeners;
  40. private List<BaseDialog.OnDismissListener> mOnDismissListeners;
  41. public BaseDialog(Context context) {
  42. this(context, R.style.BaseDialogStyle);
  43. }
  44. public BaseDialog(Context context, int themeResId) {
  45. super(context, themeResId > 0 ? themeResId : R.style.BaseDialogStyle);
  46. }
  47. /**
  48. * 设置一个显示监听器
  49. *
  50. * @param listener 监听器对象
  51. * @deprecated 请使用 {@link #addOnShowListener(BaseDialog.OnShowListener)}}
  52. */
  53. @Deprecated
  54. @Override
  55. public void setOnShowListener(@Nullable DialogInterface.OnShowListener listener) {
  56. addOnShowListener(new ShowListenerWrapper(listener));
  57. }
  58. /**
  59. * 设置一个取消监听器
  60. *
  61. * @param listener 监听器对象
  62. * @deprecated 请使用 {@link #addOnCancelListener(BaseDialog.OnCancelListener)}
  63. */
  64. @Deprecated
  65. @Override
  66. public void setOnCancelListener(@Nullable DialogInterface.OnCancelListener listener) {
  67. addOnCancelListener(new CancelListenerWrapper(listener));
  68. }
  69. /**
  70. * 设置一个销毁监听器
  71. *
  72. * @param listener 监听器对象
  73. * @deprecated 请使用 {@link #addOnDismissListener(BaseDialog.OnDismissListener)}
  74. */
  75. @Deprecated
  76. @Override
  77. public void setOnDismissListener(@Nullable DialogInterface.OnDismissListener listener) {
  78. addOnDismissListener(new DismissListenerWrapper(listener));
  79. }
  80. /**
  81. * 添加一个取消监听器
  82. *
  83. * @param listener 监听器对象
  84. */
  85. public void addOnShowListener(@Nullable BaseDialog.OnShowListener listener) {
  86. if (mOnShowListeners == null) {
  87. mOnShowListeners = new ArrayList<>();
  88. super.setOnShowListener(this);
  89. }
  90. mOnShowListeners.add(listener);
  91. }
  92. /**
  93. * 添加一个取消监听器
  94. *
  95. * @param listener 监听器对象
  96. */
  97. public void addOnCancelListener(@Nullable BaseDialog.OnCancelListener listener) {
  98. if (mOnCancelListeners == null) {
  99. mOnCancelListeners = new ArrayList<>();
  100. super.setOnCancelListener(this);
  101. }
  102. mOnCancelListeners.add(listener);
  103. }
  104. /**
  105. * 添加一个销毁监听器
  106. *
  107. * @param listener 监听器对象
  108. */
  109. public void addOnDismissListener(@Nullable BaseDialog.OnDismissListener listener) {
  110. if (mOnDismissListeners == null) {
  111. mOnDismissListeners = new ArrayList<>();
  112. super.setOnDismissListener(this);
  113. }
  114. mOnDismissListeners.add(listener);
  115. }
  116. /**
  117. * 设置显示监听器集合
  118. */
  119. private void setOnShowListeners(@Nullable List<BaseDialog.OnShowListener> listeners) {
  120. super.setOnShowListener(this);
  121. mOnShowListeners = listeners;
  122. }
  123. /**
  124. * 设置取消监听器集合
  125. */
  126. private void setOnCancelListeners(@Nullable List<BaseDialog.OnCancelListener> listeners) {
  127. super.setOnCancelListener(this);
  128. mOnCancelListeners = listeners;
  129. }
  130. /**
  131. * 设置销毁监听器集合
  132. */
  133. private void setOnDismissListeners(@Nullable List<BaseDialog.OnDismissListener> listeners) {
  134. super.setOnDismissListener(this);
  135. mOnDismissListeners = listeners;
  136. }
  137. /**
  138. * {@link DialogInterface.OnShowListener}
  139. */
  140. @Override
  141. public void onShow(DialogInterface dialog) {
  142. if (mOnShowListeners != null) {
  143. for (BaseDialog.OnShowListener listener : mOnShowListeners) {
  144. listener.onShow(this);
  145. }
  146. }
  147. }
  148. /**
  149. * {@link DialogInterface.OnCancelListener}
  150. */
  151. @Override
  152. public void onCancel(DialogInterface dialog) {
  153. if (mOnCancelListeners != null) {
  154. for (BaseDialog.OnCancelListener listener : mOnCancelListeners) {
  155. listener.onCancel(this);
  156. }
  157. }
  158. }
  159. /**
  160. * {@link DialogInterface.OnDismissListener}
  161. */
  162. @Override
  163. public void onDismiss(DialogInterface dialog) {
  164. // 移除和这个 Dialog 相关的消息回调
  165. HANDLER.removeCallbacksAndMessages(this);
  166. if (mOnDismissListeners != null) {
  167. for (BaseDialog.OnDismissListener listener : mOnDismissListeners) {
  168. listener.onDismiss(this);
  169. }
  170. }
  171. }
  172. /**
  173. * 延迟执行
  174. */
  175. public final boolean post(Runnable r) {
  176. return postDelayed(r, 0);
  177. }
  178. /**
  179. * 延迟一段时间执行
  180. */
  181. public final boolean postDelayed(Runnable r, long delayMillis) {
  182. if (delayMillis < 0) {
  183. delayMillis = 0;
  184. }
  185. return postAtTime(r, SystemClock.uptimeMillis() + delayMillis);
  186. }
  187. /**
  188. * 在指定的时间执行
  189. */
  190. public final boolean postAtTime(Runnable r, long uptimeMillis) {
  191. return HANDLER.postAtTime(r, this, uptimeMillis);
  192. }
  193. /**
  194. * Dialog 动画样式
  195. */
  196. public static final class AnimStyle {
  197. // 默认动画效果
  198. static final int DEFAULT = R.style.ScaleAnimStyle;
  199. // 缩放动画
  200. public static final int SCALE = R.style.ScaleAnimStyle;
  201. // IOS 动画
  202. public static final int IOS = R.style.IOSAnimStyle;
  203. // 吐司动画
  204. public static final int TOAST = android.R.style.Animation_Toast;
  205. // 顶部弹出动画
  206. public static final int TOP = R.style.TopAnimStyle;
  207. // 底部弹出动画
  208. public static final int BOTTOM = R.style.BottomAnimStyle;
  209. // 左边弹出动画
  210. public static final int LEFT = R.style.LeftAnimStyle;
  211. // 右边弹出动画
  212. public static final int RIGHT = R.style.RightAnimStyle;
  213. }
  214. @SuppressWarnings("unchecked")
  215. public static class Builder<B extends Builder> {
  216. protected static final int MATCH_PARENT = ViewGroup.LayoutParams.MATCH_PARENT;
  217. protected static final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;
  218. private BaseDialog mDialog;
  219. // Context 对象
  220. private Context mContext;
  221. // Dialog 布局
  222. private View mContentView;
  223. // Dialog Show 监听
  224. private List<BaseDialog.OnShowListener> mOnShowListeners;
  225. // Dialog Cancel 监听
  226. private List<BaseDialog.OnCancelListener> mOnCancelListeners;
  227. // Dialog Dismiss 监听
  228. private List<BaseDialog.OnDismissListener> mOnDismissListeners;
  229. // Dialog Key 监听
  230. private OnKeyListener mOnKeyListener;
  231. // 点击空白是否能够取消 默认点击阴影可以取消
  232. private boolean mCancelable = true;
  233. private SparseArray<CharSequence> mTextArray = new SparseArray<>();
  234. private SparseIntArray mVisibilityArray = new SparseIntArray();
  235. private SparseArray<Drawable> mBackgroundArray = new SparseArray<>();
  236. private SparseArray<Drawable> mImageArray = new SparseArray<>();
  237. private SparseArray<BaseDialog.OnClickListener> mClickArray = new SparseArray<>();
  238. // 主题
  239. private int mThemeResId = -1;
  240. // 动画
  241. private int mAnimations = -1;
  242. // 位置
  243. private int mGravity = Gravity.CENTER;
  244. // 宽度和高度
  245. private int mWidth = WRAP_CONTENT;
  246. private int mHeight = WRAP_CONTENT;
  247. // 垂直和水平边距
  248. private int mVerticalMargin;
  249. private int mHorizontalMargin;
  250. public Builder(Context context) {
  251. mContext = context;
  252. }
  253. /**
  254. * 延迟执行,一定要在创建了Dialog之后调用(供子类调用)
  255. */
  256. protected final boolean post(Runnable r) {
  257. return mDialog.post(r);
  258. }
  259. /**
  260. * 延迟一段时间执行,一定要在创建了Dialog之后调用(仅供子类调用)
  261. */
  262. protected final boolean postDelayed(Runnable r, long delayMillis) {
  263. return mDialog.postDelayed(r, delayMillis);
  264. }
  265. /**
  266. * 在指定的时间执行,一定要在创建了Dialog之后调用(仅供子类调用)
  267. */
  268. protected final boolean postAtTime(Runnable r, long uptimeMillis) {
  269. return mDialog.postAtTime(r, uptimeMillis);
  270. }
  271. /**
  272. * 是否设置了取消(仅供子类调用)
  273. */
  274. protected boolean isCancelable() {
  275. return mCancelable;
  276. }
  277. /**
  278. * 获取上下文对象(仅供子类调用)
  279. */
  280. protected Context getContext() {
  281. return mContext;
  282. }
  283. /**
  284. * 获取 Dialog 重心(仅供子类调用)
  285. */
  286. protected int getGravity() {
  287. return mGravity;
  288. }
  289. /**
  290. * 获取资源对象(仅供子类调用)
  291. */
  292. protected Resources getResources() {
  293. return mContext.getResources();
  294. }
  295. /**
  296. * 根据 id 获取一个文本(仅供子类调用)
  297. */
  298. protected CharSequence getText(@StringRes int resId) {
  299. return mContext.getText(resId);
  300. }
  301. /**
  302. * 根据 id 获取一个 String(仅供子类调用)
  303. */
  304. protected String getString(@StringRes int resId) {
  305. return mContext.getString(resId);
  306. }
  307. /**
  308. * 根据 id 获取一个颜色(仅供子类调用)
  309. */
  310. protected int getColor(@ColorRes int id) {
  311. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  312. return mContext.getColor(id);
  313. }else {
  314. return mContext.getResources().getColor(id);
  315. }
  316. }
  317. /**
  318. * 根据 id 获取一个 Drawable(仅供子类调用)
  319. */
  320. protected Drawable getDrawable(@DrawableRes int id) {
  321. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  322. return mContext.getDrawable(id);
  323. }else {
  324. return mContext.getResources().getDrawable(id);
  325. }
  326. }
  327. /**
  328. * 根据 id 查找 View(仅供子类调用)
  329. */
  330. protected <V extends View> V findViewById(@IdRes int id) {
  331. return mContentView.findViewById(id);
  332. }
  333. /**
  334. * 获取当前 Dialog 对象(仅供子类调用)
  335. */
  336. protected BaseDialog getDialog() {
  337. return mDialog;
  338. }
  339. /**
  340. * 销毁当前 Dialog(仅供子类调用)
  341. */
  342. protected void dismiss() {
  343. mDialog.dismiss();
  344. }
  345. /**
  346. * 设置主题 id
  347. */
  348. public B setThemeStyle(@StyleRes int themeResId) {
  349. mThemeResId = themeResId;
  350. return (B) this;
  351. }
  352. /**
  353. * 设置布局
  354. */
  355. public B setContentView(@LayoutRes int layoutId) {
  356. return setContentView(LayoutInflater.from(mContext).inflate(layoutId, null));
  357. }
  358. public B setContentView(@NonNull View view) {
  359. mContentView = view;
  360. return (B) this;
  361. }
  362. /**
  363. * 设置重心位置
  364. */
  365. public B setGravity(int gravity) {
  366. // 适配 Android 4.2 新特性,布局反方向(开发者选项 - 强制使用从右到左的布局方向)
  367. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
  368. gravity = Gravity.getAbsoluteGravity(gravity, mContext.getResources().getConfiguration().getLayoutDirection());
  369. }
  370. mGravity = gravity;
  371. if (mAnimations == -1) {
  372. switch (mGravity) {
  373. case Gravity.TOP:
  374. mAnimations = AnimStyle.TOP;
  375. break;
  376. case Gravity.BOTTOM:
  377. mAnimations = AnimStyle.BOTTOM;
  378. break;
  379. case Gravity.LEFT:
  380. mAnimations = AnimStyle.LEFT;
  381. break;
  382. case Gravity.RIGHT:
  383. mAnimations = AnimStyle.RIGHT;
  384. break;
  385. }
  386. }
  387. return (B) this;
  388. }
  389. /**
  390. * 设置宽度
  391. */
  392. public B setWidth(int width) {
  393. mWidth = width;
  394. return (B) this;
  395. }
  396. /**
  397. * 设置高度
  398. */
  399. public B setHeight(int height) {
  400. mHeight = height;
  401. return (B) this;
  402. }
  403. /**
  404. * 是否可以取消
  405. */
  406. public B setCancelable(boolean cancelable) {
  407. mCancelable = cancelable;
  408. return (B) this;
  409. }
  410. /**
  411. * 设置动画,已经封装好几种样式,具体可见{@link AnimStyle}类
  412. */
  413. public B setAnimStyle(@StyleRes int resId) {
  414. mAnimations = resId;
  415. return (B) this;
  416. }
  417. /**
  418. * 设置垂直间距
  419. */
  420. public B setVerticalMargin(int margin) {
  421. mVerticalMargin = margin;
  422. return (B) this;
  423. }
  424. /**
  425. * 设置水平间距
  426. */
  427. public B setHorizontalMargin(int margin) {
  428. mHorizontalMargin = margin;
  429. return (B) this;
  430. }
  431. /**
  432. * 添加显示监听
  433. */
  434. public B addOnShowListener(@NonNull BaseDialog.OnShowListener listener) {
  435. if (mOnShowListeners == null) {
  436. mOnShowListeners = new ArrayList<>();
  437. }
  438. mOnShowListeners.add(listener);
  439. return (B) this;
  440. }
  441. /**
  442. * 添加取消监听
  443. */
  444. public B addOnCancelListener(@NonNull BaseDialog.OnCancelListener listener) {
  445. if (mOnCancelListeners == null) {
  446. mOnCancelListeners = new ArrayList<>();
  447. }
  448. mOnCancelListeners.add(listener);
  449. return (B) this;
  450. }
  451. /**
  452. * 添加销毁监听
  453. */
  454. public B addOnDismissListener(@NonNull BaseDialog.OnDismissListener listener) {
  455. if (mOnDismissListeners == null) {
  456. mOnDismissListeners = new ArrayList<>();
  457. }
  458. mOnDismissListeners.add(listener);
  459. return (B) this;
  460. }
  461. /**
  462. * 设置按键监听
  463. */
  464. public B setOnKeyListener(@NonNull OnKeyListener onKeyListener) {
  465. mOnKeyListener = onKeyListener;
  466. return (B) this;
  467. }
  468. /**
  469. * 设置文本
  470. */
  471. public B setText(@IdRes int id, @StringRes int resId) {
  472. return setText(id, mContext.getResources().getString(resId));
  473. }
  474. public B setText(@IdRes int id, CharSequence text) {
  475. mTextArray.put(id, text);
  476. return (B) this;
  477. }
  478. /**
  479. * 设置可见状态
  480. */
  481. public B setVisibility(@IdRes int id, int visibility) {
  482. mVisibilityArray.put(id, visibility);
  483. return (B) this;
  484. }
  485. /**
  486. * 设置背景
  487. */
  488. public B setBackground(@IdRes int id, @DrawableRes int resId) {
  489. return setBackground(id, mContext.getResources().getDrawable(resId));
  490. }
  491. public B setBackground(@IdRes int id, Drawable drawable) {
  492. mBackgroundArray.put(id, drawable);
  493. return (B) this;
  494. }
  495. /**
  496. * 设置图片
  497. */
  498. public B setImageDrawable(@IdRes int id, @DrawableRes int resId) {
  499. return setBackground(id, mContext.getResources().getDrawable(resId));
  500. }
  501. public B setImageDrawable(@IdRes int id, Drawable drawable) {
  502. mImageArray.put(id, drawable);
  503. return (B) this;
  504. }
  505. /**
  506. * 设置点击事件
  507. */
  508. public B setOnClickListener(@IdRes int id, @NonNull BaseDialog.OnClickListener listener) {
  509. mClickArray.put(id, listener);
  510. return (B) this;
  511. }
  512. /**
  513. * 创建
  514. */
  515. public BaseDialog create() {
  516. // 判断布局是否为空
  517. if (mContentView == null) {
  518. throw new IllegalArgumentException("Dialog layout cannot be empty");
  519. }
  520. ViewGroup.LayoutParams layoutParams = mContentView.getLayoutParams();
  521. if (layoutParams != null) {
  522. if (mWidth == ViewGroup.LayoutParams.WRAP_CONTENT) {
  523. mWidth = layoutParams.width;
  524. }
  525. if (mHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
  526. mHeight = layoutParams.height;
  527. }
  528. }
  529. // // 判断有没有设置主题
  530. // if (mThemeResId == -1) {
  531. // mDialog = new BaseDialog(mContext);
  532. // } else {
  533. // mDialog = new BaseDialog(mContext, mThemeResId);
  534. // }
  535. mDialog = createDialog(mContext, mThemeResId);
  536. mDialog.setContentView(mContentView);
  537. mDialog.setCancelable(mCancelable);
  538. if (mCancelable) {
  539. mDialog.setCanceledOnTouchOutside(true);
  540. }
  541. if (mOnShowListeners != null) {
  542. mDialog.setOnShowListeners(mOnShowListeners);
  543. }
  544. if (mOnCancelListeners != null) {
  545. mDialog.setOnCancelListeners(mOnCancelListeners);
  546. }
  547. if (mOnDismissListeners != null) {
  548. mDialog.setOnDismissListeners(mOnDismissListeners);
  549. }
  550. if (mOnKeyListener != null) {
  551. mDialog.setOnKeyListener(mOnKeyListener);
  552. }
  553. // 判断有没有设置动画
  554. if (mAnimations == -1) {
  555. // 没有的话就设置默认的动画
  556. mAnimations = AnimStyle.DEFAULT;
  557. }
  558. // 设置参数
  559. WindowManager.LayoutParams params = mDialog.getWindow().getAttributes();
  560. params.width = mWidth;
  561. params.height = mHeight;
  562. params.gravity = mGravity;
  563. params.windowAnimations = mAnimations;
  564. params.horizontalMargin = mHorizontalMargin;
  565. params.verticalMargin = mVerticalMargin;
  566. mDialog.getWindow().setAttributes(params);
  567. // 设置文本
  568. for (int i = 0; i < mTextArray.size(); i++) {
  569. ((TextView) mContentView.findViewById(mTextArray.keyAt(i))).setText(mTextArray.valueAt(i));
  570. }
  571. // 设置可见状态
  572. for (int i = 0; i < mVisibilityArray.size(); i++) {
  573. mContentView.findViewById(mVisibilityArray.keyAt(i)).setVisibility(mVisibilityArray.valueAt(i));
  574. }
  575. // 设置背景
  576. for (int i = 0; i < mBackgroundArray.size(); i++) {
  577. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
  578. mContentView.findViewById(mBackgroundArray.keyAt(i)).setBackground(mBackgroundArray.valueAt(i));
  579. }else {
  580. mContentView.findViewById(mBackgroundArray.keyAt(i)).setBackgroundDrawable(mBackgroundArray.valueAt(i));
  581. }
  582. }
  583. // 设置图片
  584. for (int i = 0; i < mImageArray.size(); i++) {
  585. ((ImageView) mContentView.findViewById(mImageArray.keyAt(i))).setImageDrawable(mImageArray.valueAt(i));
  586. }
  587. // 设置点击事件
  588. for (int i = 0; i < mClickArray.size(); i++) {
  589. mContentView.findViewById(mClickArray.keyAt(i)).setOnClickListener(new ViewClickWrapper(mDialog, mClickArray.valueAt(i)));
  590. }
  591. return mDialog;
  592. }
  593. /**
  594. * 创建对话框对象(子类可以重写此方法来改变 Dialog 类型)
  595. */
  596. protected BaseDialog createDialog(Context context, int themeResId) {
  597. return new BaseDialog(context, themeResId);
  598. }
  599. /**
  600. * 显示
  601. */
  602. public BaseDialog show() {
  603. final BaseDialog dialog = create();
  604. dialog.show();
  605. return dialog;
  606. }
  607. }
  608. public interface OnClickListener<V extends View> {
  609. void onClick(BaseDialog dialog, V view);
  610. }
  611. public interface OnShowListener {
  612. void onShow(BaseDialog dialog);
  613. }
  614. public interface OnCancelListener {
  615. void onCancel(BaseDialog dialog);
  616. }
  617. public interface OnDismissListener {
  618. void onDismiss(BaseDialog dialog);
  619. }
  620. /**
  621. * 点击事件包装类
  622. */
  623. private static final class ViewClickWrapper implements View.OnClickListener {
  624. private final BaseDialog mDialog;
  625. private final BaseDialog.OnClickListener mListener;
  626. private ViewClickWrapper(BaseDialog dialog, BaseDialog.OnClickListener listener) {
  627. mDialog = dialog;
  628. mListener = listener;
  629. }
  630. @SuppressWarnings("unchecked")
  631. @Override
  632. public final void onClick(View v) {
  633. mListener.onClick(mDialog, v);
  634. }
  635. }
  636. /**
  637. * 显示监听包装类
  638. */
  639. private static final class ShowListenerWrapper implements BaseDialog.OnShowListener {
  640. private final DialogInterface.OnShowListener mListener;
  641. private ShowListenerWrapper(DialogInterface.OnShowListener listener) {
  642. mListener = listener;
  643. }
  644. @Override
  645. public void onShow(BaseDialog dialog) {
  646. mListener.onShow(dialog);
  647. }
  648. }
  649. /**
  650. * 取消监听包装类
  651. */
  652. private static final class CancelListenerWrapper implements BaseDialog.OnCancelListener {
  653. private final DialogInterface.OnCancelListener mListener;
  654. private CancelListenerWrapper(DialogInterface.OnCancelListener listener) {
  655. mListener = listener;
  656. }
  657. @Override
  658. public void onCancel(BaseDialog dialog) {
  659. mListener.onCancel(dialog);
  660. }
  661. }
  662. /**
  663. * 销毁监听包装类
  664. */
  665. private static final class DismissListenerWrapper implements BaseDialog.OnDismissListener {
  666. private final DialogInterface.OnDismissListener mListener;
  667. private DismissListenerWrapper(DialogInterface.OnDismissListener listener) {
  668. mListener = listener;
  669. }
  670. @Override
  671. public void onDismiss(BaseDialog dialog) {
  672. mListener.onDismiss(dialog);
  673. }
  674. }
  675. }