BottomDialog.java 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. package com.kongzue.dialogx.dialogs;
  2. import android.animation.ObjectAnimator;
  3. import android.animation.ValueAnimator;
  4. import android.app.Activity;
  5. import android.graphics.Bitmap;
  6. import android.graphics.Outline;
  7. import android.graphics.drawable.BitmapDrawable;
  8. import android.graphics.drawable.ColorDrawable;
  9. import android.graphics.drawable.Drawable;
  10. import android.graphics.drawable.GradientDrawable;
  11. import android.os.Handler;
  12. import android.os.Looper;
  13. import android.view.View;
  14. import android.view.ViewGroup;
  15. import android.view.ViewOutlineProvider;
  16. import android.view.animation.DecelerateInterpolator;
  17. import android.widget.ImageView;
  18. import android.widget.LinearLayout;
  19. import android.widget.RelativeLayout;
  20. import android.widget.TextView;
  21. import androidx.annotation.ColorInt;
  22. import androidx.annotation.ColorRes;
  23. import androidx.annotation.NonNull;
  24. import androidx.lifecycle.Lifecycle;
  25. import com.kongzue.dialogx.DialogX;
  26. import com.kongzue.dialogx.R;
  27. import com.kongzue.dialogx.interfaces.BaseDialog;
  28. import com.kongzue.dialogx.interfaces.BottomDialogSlideEventLifecycleCallback;
  29. import com.kongzue.dialogx.interfaces.DialogConvertViewInterface;
  30. import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
  31. import com.kongzue.dialogx.interfaces.DialogXAnimInterface;
  32. import com.kongzue.dialogx.interfaces.DialogXStyle;
  33. import com.kongzue.dialogx.interfaces.OnBackPressedListener;
  34. import com.kongzue.dialogx.interfaces.OnBackgroundMaskClickListener;
  35. import com.kongzue.dialogx.interfaces.OnBindView;
  36. import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
  37. import com.kongzue.dialogx.interfaces.ScrollController;
  38. import com.kongzue.dialogx.util.BottomDialogTouchEventInterceptor;
  39. import com.kongzue.dialogx.util.ObjectRunnable;
  40. import com.kongzue.dialogx.util.TextInfo;
  41. import com.kongzue.dialogx.util.views.BlurView;
  42. import com.kongzue.dialogx.util.views.BottomDialogScrollView;
  43. import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
  44. import com.kongzue.dialogx.util.views.MaxRelativeLayout;
  45. /**
  46. * @author: Kongzue
  47. * @github: https://github.com/kongzue/
  48. * @homepage: http://kongzue.com/
  49. * @mail: myzcxhh@live.cn
  50. * @createTime: 2020/10/6 15:17
  51. */
  52. public class BottomDialog extends BaseDialog {
  53. public static int overrideEnterDuration = -1;
  54. public static int overrideExitDuration = -1;
  55. public static BOOLEAN overrideCancelable;
  56. protected OnBindView<BottomDialog> onBindView;
  57. protected CharSequence title;
  58. protected CharSequence message;
  59. protected CharSequence cancelText;
  60. protected CharSequence okText;
  61. protected CharSequence otherText;
  62. protected boolean allowInterceptTouch = true;
  63. protected int maskColor = -1;
  64. protected OnDialogButtonClickListener<BottomDialog> cancelButtonClickListener;
  65. protected OnDialogButtonClickListener<BottomDialog> okButtonClickListener;
  66. protected OnDialogButtonClickListener<BottomDialog> otherButtonClickListener;
  67. protected OnBackgroundMaskClickListener<BottomDialog> onBackgroundMaskClickListener;
  68. protected OnBackPressedListener<BottomDialog> onBackPressedListener;
  69. protected BOOLEAN privateCancelable;
  70. protected boolean bkgInterceptTouch = true;
  71. protected float backgroundRadius = -1;
  72. protected Drawable titleIcon;
  73. protected DialogXAnimInterface<BottomDialog> dialogXAnimImpl;
  74. protected BUTTON_SELECT_RESULT buttonSelectResult = BUTTON_SELECT_RESULT.NONE;
  75. protected TextInfo titleTextInfo;
  76. protected TextInfo messageTextInfo;
  77. protected TextInfo menuTextInfo;
  78. protected TextInfo cancelTextInfo = new TextInfo().setBold(true);
  79. protected TextInfo okTextInfo = new TextInfo().setBold(true);
  80. protected TextInfo otherTextInfo = new TextInfo().setBold(true);
  81. /**
  82. * 此值用于,当禁用滑动时(style.overrideBottomDialogRes.touchSlide = false时)的最大显示高度。
  83. * 0:不限制,最大显示到屏幕可用高度。
  84. */
  85. protected float bottomDialogMaxHeight = 0f;
  86. protected DialogLifecycleCallback<BottomDialog> dialogLifecycleCallback;
  87. protected BottomDialog me = this;
  88. protected BottomDialog() {
  89. super();
  90. }
  91. @Override
  92. public String dialogKey() {
  93. return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
  94. }
  95. private View dialogView;
  96. public static BottomDialog build() {
  97. return new BottomDialog();
  98. }
  99. public static BottomDialog build(DialogXStyle style) {
  100. return new BottomDialog().setStyle(style);
  101. }
  102. public static BottomDialog build(OnBindView<BottomDialog> onBindView) {
  103. return new BottomDialog().setCustomView(onBindView);
  104. }
  105. public BottomDialog(CharSequence title, CharSequence message) {
  106. this.title = title;
  107. this.message = message;
  108. }
  109. public BottomDialog(int titleResId, int messageResId) {
  110. this.title = getString(titleResId);
  111. this.message = getString(messageResId);
  112. }
  113. public static BottomDialog show(CharSequence title, CharSequence message) {
  114. BottomDialog bottomDialog = new BottomDialog(title, message);
  115. bottomDialog.show();
  116. return bottomDialog;
  117. }
  118. public static BottomDialog show(int titleResId, int messageResId) {
  119. BottomDialog bottomDialog = new BottomDialog(titleResId, messageResId);
  120. bottomDialog.show();
  121. return bottomDialog;
  122. }
  123. public BottomDialog(CharSequence title, CharSequence message, OnBindView<BottomDialog> onBindView) {
  124. this.title = title;
  125. this.message = message;
  126. this.onBindView = onBindView;
  127. }
  128. public BottomDialog(int titleResId, int messageResId, OnBindView<BottomDialog> onBindView) {
  129. this.title = getString(titleResId);
  130. this.message = getString(messageResId);
  131. this.onBindView = onBindView;
  132. }
  133. public static BottomDialog show(CharSequence title, CharSequence message, OnBindView<BottomDialog> onBindView) {
  134. BottomDialog bottomDialog = new BottomDialog(title, message, onBindView);
  135. bottomDialog.show();
  136. return bottomDialog;
  137. }
  138. public static BottomDialog show(int titleResId, int messageResId, OnBindView<BottomDialog> onBindView) {
  139. BottomDialog bottomDialog = new BottomDialog(titleResId, messageResId, onBindView);
  140. bottomDialog.show();
  141. return bottomDialog;
  142. }
  143. public BottomDialog(CharSequence title, OnBindView<BottomDialog> onBindView) {
  144. this.title = title;
  145. this.onBindView = onBindView;
  146. }
  147. public BottomDialog(int titleResId, OnBindView<BottomDialog> onBindView) {
  148. this.title = getString(titleResId);
  149. this.onBindView = onBindView;
  150. }
  151. public static BottomDialog show(CharSequence title, OnBindView<BottomDialog> onBindView) {
  152. BottomDialog bottomDialog = new BottomDialog(title, onBindView);
  153. bottomDialog.show();
  154. return bottomDialog;
  155. }
  156. public static BottomDialog show(int titleResId, OnBindView<BottomDialog> onBindView) {
  157. BottomDialog bottomDialog = new BottomDialog(titleResId, onBindView);
  158. bottomDialog.show();
  159. return bottomDialog;
  160. }
  161. public BottomDialog(OnBindView<BottomDialog> onBindView) {
  162. this.onBindView = onBindView;
  163. }
  164. public static BottomDialog show(OnBindView<BottomDialog> onBindView) {
  165. BottomDialog bottomDialog = new BottomDialog(onBindView);
  166. bottomDialog.show();
  167. return bottomDialog;
  168. }
  169. public BottomDialog show() {
  170. if (isHide && getDialogView() != null && isShow) {
  171. if (hideWithExitAnim && getDialogImpl() != null) {
  172. getDialogView().setVisibility(View.VISIBLE);
  173. getDialogImpl().getDialogXAnimImpl().doShowAnim(me, new ObjectRunnable<Float>() {
  174. @Override
  175. public void run(Float value) {
  176. getDialogImpl().boxRoot.setBkgAlpha(value);
  177. }
  178. });
  179. } else {
  180. getDialogView().setVisibility(View.VISIBLE);
  181. }
  182. return this;
  183. }
  184. super.beforeShow();
  185. if (getDialogView() == null) {
  186. int layoutId = isLightTheme() ? R.layout.layout_dialogx_bottom_material : R.layout.layout_dialogx_bottom_material_dark;
  187. if (style.overrideBottomDialogRes() != null) {
  188. layoutId = style.overrideBottomDialogRes().overrideDialogLayout(isLightTheme());
  189. }
  190. dialogView = createView(layoutId);
  191. dialogImpl = new DialogImpl(dialogView);
  192. if (dialogView != null) dialogView.setTag(me);
  193. }
  194. show(dialogView);
  195. return this;
  196. }
  197. public void show(Activity activity) {
  198. super.beforeShow();
  199. if (getDialogView() == null) {
  200. int layoutId = isLightTheme() ? R.layout.layout_dialogx_bottom_material : R.layout.layout_dialogx_bottom_material_dark;
  201. if (style.overrideBottomDialogRes() != null) {
  202. layoutId = style.overrideBottomDialogRes().overrideDialogLayout(isLightTheme());
  203. }
  204. dialogView = createView(layoutId);
  205. dialogImpl = new DialogImpl(dialogView);
  206. if (dialogView != null) dialogView.setTag(me);
  207. }
  208. show(activity, dialogView);
  209. }
  210. protected DialogImpl dialogImpl;
  211. public class DialogImpl implements DialogConvertViewInterface {
  212. private BottomDialogTouchEventInterceptor bottomDialogTouchEventInterceptor;
  213. public DialogXBaseRelativeLayout boxRoot;
  214. public RelativeLayout boxBkg;
  215. public MaxRelativeLayout bkg;
  216. public ViewGroup boxBody;
  217. public ImageView imgTab;
  218. public TextView txtDialogTitle;
  219. public ScrollController scrollView;
  220. public LinearLayout boxContent;
  221. public TextView txtDialogTip;
  222. public View imgSplit;
  223. public RelativeLayout boxList;
  224. public RelativeLayout boxCustom;
  225. public BlurView blurView;
  226. public ViewGroup boxCancel;
  227. public TextView btnCancel;
  228. public BlurView cancelBlurView;
  229. public TextView btnSelectOther;
  230. public TextView btnSelectPositive;
  231. public DialogImpl(View convertView) {
  232. if (convertView == null) return;
  233. boxRoot = convertView.findViewById(R.id.box_root);
  234. boxBkg = convertView.findViewById(R.id.box_bkg);
  235. bkg = convertView.findViewById(R.id.bkg);
  236. boxBody = convertView.findViewWithTag("blurBody");
  237. imgTab = convertView.findViewById(R.id.img_tab);
  238. txtDialogTitle = convertView.findViewById(R.id.txt_dialog_title);
  239. scrollView = convertView.findViewById(R.id.scrollView);
  240. boxContent = convertView.findViewById(R.id.box_content);
  241. txtDialogTip = convertView.findViewById(R.id.txt_dialog_tip);
  242. imgSplit = convertView.findViewWithTag("split");
  243. boxList = convertView.findViewById(R.id.box_list);
  244. boxCustom = convertView.findViewById(R.id.box_custom);
  245. blurView = convertView.findViewById(R.id.blurView);
  246. boxCancel = convertView.findViewWithTag("cancelBox");
  247. btnCancel = convertView.findViewWithTag("cancel");
  248. btnSelectOther = convertView.findViewById(R.id.btn_selectOther);
  249. btnSelectPositive = convertView.findViewById(R.id.btn_selectPositive);
  250. init();
  251. dialogImpl = this;
  252. refreshView();
  253. }
  254. public void reBuild() {
  255. init();
  256. dialogImpl = this;
  257. refreshView();
  258. }
  259. /**
  260. * 此值记录了BottomDialog启动后的位置
  261. * ·当内容高度大于屏幕安全区高度时,BottomDialog会以全屏方式启动,但一开始只会展开到 0.8×屏幕高度,
  262. * 此时可以再次上划查看全部内容。
  263. * ·当内容高度小于屏幕安全区高度时,BottomDialog会以内容高度启动。
  264. * <p>
  265. * 记录这个值的目的是,当用户向下滑动时,判断情况该回到这个位置还是关闭对话框,
  266. * 并阻止当内容高度已经完全显示时的继续向上滑动操作。
  267. */
  268. public float bkgEnterAimY = -1;
  269. @Override
  270. public void init() {
  271. buttonSelectResult = BUTTON_SELECT_RESULT.NONE;
  272. if (titleTextInfo == null) titleTextInfo = DialogX.titleTextInfo;
  273. if (messageTextInfo == null) messageTextInfo = DialogX.messageTextInfo;
  274. if (okTextInfo == null) okTextInfo = DialogX.okButtonTextInfo;
  275. if (okTextInfo == null) okTextInfo = DialogX.buttonTextInfo;
  276. if (cancelTextInfo == null) cancelTextInfo = DialogX.buttonTextInfo;
  277. if (otherTextInfo == null) otherTextInfo = DialogX.buttonTextInfo;
  278. if (backgroundColor == -1) backgroundColor = DialogX.backgroundColor;
  279. if (cancelText == null) cancelText = DialogX.cancelButtonText;
  280. txtDialogTitle.getPaint().setFakeBoldText(true);
  281. if (btnCancel != null) btnCancel.getPaint().setFakeBoldText(true);
  282. if (btnSelectPositive != null) btnSelectPositive.getPaint().setFakeBoldText(true);
  283. if (btnSelectOther != null) btnSelectOther.getPaint().setFakeBoldText(true);
  284. boxBkg.setY(getRootFrameLayout().getMeasuredHeight());
  285. bkg.setMaxWidth(getMaxWidth());
  286. bkg.setMaxHeight(getMaxHeight());
  287. bkg.setMinimumWidth(getMinWidth());
  288. bkg.setMinimumHeight(getMinHeight());
  289. boxRoot.setParentDialog(me);
  290. boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
  291. @Override
  292. public void onShow() {
  293. isShow = true;
  294. preShow = false;
  295. lifecycle.setCurrentState(Lifecycle.State.CREATED);
  296. getDialogLifecycleCallback().onShow(me);
  297. BottomDialog.this.onShow(me);
  298. onDialogShow();
  299. boxRoot.post(new Runnable() {
  300. @Override
  301. public void run() {
  302. if (style.messageDialogBlurSettings() != null && style.messageDialogBlurSettings().blurBackground() && boxBody != null && boxCancel != null) {
  303. int blurFrontColor = getResources().getColor(style.messageDialogBlurSettings().blurForwardColorRes(isLightTheme()));
  304. blurView = new BlurView(getOwnActivity(), null);
  305. RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(bkg.getWidth(), bkg.getHeight());
  306. blurView.setOverlayColor(backgroundColor == -1 ? blurFrontColor : backgroundColor);
  307. blurView.setOverrideOverlayColor(backgroundColor != -1);
  308. blurView.setTag("blurView");
  309. blurView.setRadiusPx(style.messageDialogBlurSettings().blurBackgroundRoundRadiusPx());
  310. boxBody.addView(blurView, 0, params);
  311. cancelBlurView = new BlurView(getOwnActivity(), null);
  312. RelativeLayout.LayoutParams cancelButtonLp = new RelativeLayout.LayoutParams(boxCancel.getWidth(), boxCancel.getHeight());
  313. cancelBlurView.setOverlayColor(backgroundColor == -1 ? blurFrontColor : backgroundColor);
  314. cancelBlurView.setOverrideOverlayColor(backgroundColor != -1);
  315. cancelBlurView.setTag("blurView");
  316. cancelBlurView.setRadiusPx(style.messageDialogBlurSettings().blurBackgroundRoundRadiusPx());
  317. boxCancel.addView(cancelBlurView, 0, cancelButtonLp);
  318. }
  319. lifecycle.setCurrentState(Lifecycle.State.RESUMED);
  320. }
  321. });
  322. refreshUI();
  323. }
  324. @Override
  325. public void onDismiss() {
  326. isShow = false;
  327. getDialogLifecycleCallback().onDismiss(me);
  328. BottomDialog.this.onDismiss(me);
  329. dialogImpl = null;
  330. bottomDialogTouchEventInterceptor = null;
  331. dialogLifecycleCallback = null;
  332. lifecycle.setCurrentState(Lifecycle.State.DESTROYED);
  333. System.gc();
  334. }
  335. });
  336. if (btnCancel != null) {
  337. btnCancel.setOnClickListener(new View.OnClickListener() {
  338. @Override
  339. public void onClick(View v) {
  340. buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_CANCEL;
  341. if (cancelButtonClickListener != null) {
  342. if (!cancelButtonClickListener.onClick(me, v)) {
  343. dismiss();
  344. }
  345. } else {
  346. dismiss();
  347. }
  348. }
  349. });
  350. }
  351. if (btnSelectOther != null) {
  352. btnSelectOther.setOnClickListener(new View.OnClickListener() {
  353. @Override
  354. public void onClick(View v) {
  355. buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_OTHER;
  356. if (otherButtonClickListener != null) {
  357. if (!otherButtonClickListener.onClick(me, v)) {
  358. dismiss();
  359. }
  360. } else {
  361. dismiss();
  362. }
  363. }
  364. });
  365. }
  366. if (btnSelectPositive != null) {
  367. btnSelectPositive.setOnClickListener(new View.OnClickListener() {
  368. @Override
  369. public void onClick(View v) {
  370. buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_OK;
  371. if (okButtonClickListener != null) {
  372. if (!okButtonClickListener.onClick(me, v)) {
  373. dismiss();
  374. }
  375. } else {
  376. dismiss();
  377. }
  378. }
  379. });
  380. }
  381. if (imgSplit != null) {
  382. int dividerRes = style.overrideBottomDialogRes().overrideMenuDividerDrawableRes(isLightTheme());
  383. int dividerHeight = style.overrideBottomDialogRes().overrideMenuDividerHeight(isLightTheme());
  384. if (dividerRes != 0) imgSplit.setBackgroundResource(dividerRes);
  385. if (dividerHeight != 0) {
  386. ViewGroup.LayoutParams lp = imgSplit.getLayoutParams();
  387. lp.height = dividerHeight;
  388. imgSplit.setLayoutParams(lp);
  389. }
  390. }
  391. boxRoot.setOnBackPressedListener(new DialogXBaseRelativeLayout.PrivateBackPressedListener() {
  392. @Override
  393. public boolean onBackPressed() {
  394. if (onBackPressedListener != null) {
  395. if (onBackPressedListener.onBackPressed(me)) {
  396. dismiss();
  397. }
  398. } else {
  399. if (isCancelable()) {
  400. dismiss();
  401. }
  402. }
  403. return true;
  404. }
  405. });
  406. boxBkg.post(new Runnable() {
  407. @Override
  408. public void run() {
  409. getDialogXAnimImpl().doShowAnim(BottomDialog.this, new ObjectRunnable<Float>() {
  410. @Override
  411. public void run(Float value) {
  412. boxRoot.setBkgAlpha(value);
  413. if (value == 1f) {
  414. bottomDialogTouchEventInterceptor = new BottomDialogTouchEventInterceptor(me, dialogImpl);
  415. }
  416. }
  417. });
  418. }
  419. });
  420. onDialogInit();
  421. }
  422. @Override
  423. public void refreshView() {
  424. if (boxRoot == null || getTopActivity() == null) {
  425. return;
  426. }
  427. boxRoot.setRootPadding(screenPaddings[0], screenPaddings[1], screenPaddings[2], screenPaddings[3]);
  428. if (backgroundColor != -1) {
  429. tintColor(bkg, backgroundColor);
  430. if (blurView != null && cancelBlurView != null) {
  431. blurView.setOverlayColor(backgroundColor);
  432. blurView.setOverrideOverlayColor(true);
  433. cancelBlurView.setOverlayColor(backgroundColor);
  434. cancelBlurView.setOverrideOverlayColor(true);
  435. }
  436. tintColor(btnSelectOther, backgroundColor);
  437. tintColor(btnCancel, backgroundColor);
  438. tintColor(btnSelectPositive, backgroundColor);
  439. }
  440. showText(txtDialogTitle, title);
  441. showText(txtDialogTip, message);
  442. useTextInfo(txtDialogTitle, titleTextInfo);
  443. useTextInfo(txtDialogTip, messageTextInfo);
  444. useTextInfo(btnCancel, cancelTextInfo);
  445. useTextInfo(btnSelectOther, otherTextInfo);
  446. useTextInfo(btnSelectPositive, okTextInfo);
  447. if (titleIcon != null) {
  448. int size = (int) txtDialogTitle.getTextSize();
  449. titleIcon.setBounds(0, 0, size, size);
  450. txtDialogTitle.setCompoundDrawablePadding(dip2px(10));
  451. txtDialogTitle.setCompoundDrawables(titleIcon, null, null, null);
  452. }
  453. if (bkgInterceptTouch) {
  454. if (isCancelable()) {
  455. boxRoot.setOnClickListener(new View.OnClickListener() {
  456. @Override
  457. public void onClick(View v) {
  458. if (onBackgroundMaskClickListener == null || !onBackgroundMaskClickListener.onClick(me, v)) {
  459. doDismiss(v);
  460. }
  461. }
  462. });
  463. } else {
  464. boxRoot.setOnClickListener(null);
  465. }
  466. } else {
  467. boxRoot.setClickable(false);
  468. }
  469. boxBkg.setOnClickListener(new View.OnClickListener() {
  470. @Override
  471. public void onClick(View v) {
  472. boxRoot.callOnClick();
  473. }
  474. });
  475. if (backgroundRadius > -1) {
  476. GradientDrawable gradientDrawable = (GradientDrawable) bkg.getBackground();
  477. if (gradientDrawable != null) gradientDrawable.setCornerRadii(new float[]{
  478. backgroundRadius, backgroundRadius, backgroundRadius, backgroundRadius, 0, 0, 0, 0
  479. });
  480. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
  481. bkg.setOutlineProvider(new ViewOutlineProvider() {
  482. @Override
  483. public void getOutline(View view, Outline outline) {
  484. outline.setRoundRect(0, 0, view.getWidth(), (int) (view.getHeight() + backgroundRadius), backgroundRadius);
  485. }
  486. });
  487. bkg.setClipToOutline(true);
  488. }
  489. }
  490. if (maskColor != -1) {
  491. boxRoot.setBackground(new ColorDrawable(maskColor));
  492. }
  493. if (onBindView != null && onBindView.getCustomView() != null) {
  494. onBindView.bindParent(boxCustom, me);
  495. if (onBindView.getCustomView() instanceof ScrollController) {
  496. if (scrollView instanceof BottomDialogScrollView) {
  497. ((BottomDialogScrollView) scrollView).setVerticalScrollBarEnabled(false);
  498. }
  499. scrollView = (ScrollController) onBindView.getCustomView();
  500. } else {
  501. View scrollController = onBindView.getCustomView().findViewWithTag("ScrollController");
  502. if (scrollController instanceof ScrollController) {
  503. if (scrollView instanceof BottomDialogScrollView) {
  504. ((BottomDialogScrollView) scrollView).setVerticalScrollBarEnabled(false);
  505. }
  506. scrollView = (ScrollController) scrollController;
  507. }
  508. }
  509. }
  510. if (isAllowInterceptTouch() && isCancelable()) {
  511. if (imgTab != null) imgTab.setVisibility(View.VISIBLE);
  512. } else {
  513. if (imgTab != null) imgTab.setVisibility(View.GONE);
  514. }
  515. if (bottomDialogTouchEventInterceptor != null) {
  516. bottomDialogTouchEventInterceptor.refresh(me, this);
  517. }
  518. if (imgSplit != null) {
  519. if (txtDialogTitle.getVisibility() == View.VISIBLE || txtDialogTip.getVisibility() == View.VISIBLE) {
  520. imgSplit.setVisibility(View.VISIBLE);
  521. } else {
  522. imgSplit.setVisibility(View.GONE);
  523. }
  524. }
  525. if (boxCancel != null) {
  526. if (isNull(cancelText)) {
  527. boxCancel.setVisibility(View.GONE);
  528. } else {
  529. boxCancel.setVisibility(View.VISIBLE);
  530. }
  531. }
  532. showText(btnSelectPositive, okText);
  533. showText(btnCancel, cancelText);
  534. showText(btnSelectOther, otherText);
  535. onDialogRefreshUI();
  536. }
  537. @Override
  538. public void doDismiss(View v) {
  539. if (v != null) v.setEnabled(false);
  540. if (getTopActivity() == null) return;
  541. if (!dismissAnimFlag) {
  542. dismissAnimFlag = true;
  543. getDialogXAnimImpl().doExitAnim(BottomDialog.this, new ObjectRunnable<Float>() {
  544. @Override
  545. public void run(Float animatedValue) {
  546. if (boxRoot != null) {
  547. boxRoot.setBkgAlpha(animatedValue);
  548. }
  549. if (animatedValue == 0) {
  550. if (boxRoot != null) {
  551. boxRoot.setVisibility(View.GONE);
  552. }
  553. dismiss(dialogView);
  554. }
  555. }
  556. });
  557. runOnMainDelay(new Runnable() {
  558. @Override
  559. public void run() {
  560. }
  561. }, exitAnimDurationTemp);
  562. }
  563. }
  564. long exitAnimDurationTemp = 300;
  565. public void preDismiss() {
  566. if (isCancelable()) {
  567. if (getDialogLifecycleCallback() instanceof BottomDialogSlideEventLifecycleCallback) {
  568. if (!((BottomDialogSlideEventLifecycleCallback) getDialogLifecycleCallback()).onSlideClose(me)) {
  569. doDismiss(boxRoot);
  570. }
  571. return;
  572. }
  573. doDismiss(boxRoot);
  574. } else {
  575. long exitAnimDurationTemp = 300;
  576. if (overrideExitDuration >= 0) {
  577. exitAnimDurationTemp = overrideExitDuration;
  578. }
  579. if (exitAnimDuration >= 0) {
  580. exitAnimDurationTemp = exitAnimDuration;
  581. }
  582. ObjectAnimator exitAnim = ObjectAnimator.ofFloat(boxBkg, "y", boxBkg.getY(), boxRoot.getUnsafePlace().top);
  583. exitAnim.setDuration(exitAnimDurationTemp);
  584. exitAnim.start();
  585. }
  586. }
  587. protected DialogXAnimInterface<BottomDialog> getDialogXAnimImpl() {
  588. if (dialogXAnimImpl == null) {
  589. dialogXAnimImpl = new DialogXAnimInterface<BottomDialog>() {
  590. @Override
  591. public void doShowAnim(BottomDialog dialog, ObjectRunnable<Float> animProgress) {
  592. long enterAnimDurationTemp = 300;
  593. float customDialogTop = 0;
  594. if (dialog.isAllowInterceptTouch()) {
  595. if (bottomDialogMaxHeight > 0 && bottomDialogMaxHeight <= 1) {
  596. customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight * boxBkg.getHeight();
  597. } else if (bottomDialogMaxHeight > 1) {
  598. customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight;
  599. }
  600. } else {
  601. if (bottomDialogMaxHeight > 0 && bottomDialogMaxHeight <= 1) {
  602. customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight * boxBkg.getHeight();
  603. } else if (bottomDialogMaxHeight > 1) {
  604. customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight;
  605. }
  606. boxBkg.setPadding(0, 0, 0, (int) customDialogTop);
  607. }
  608. //上移动画
  609. ObjectAnimator enterAnim = ObjectAnimator.ofFloat(boxBkg, "y", boxBkg.getY(),
  610. bkgEnterAimY = boxRoot.getUnsafePlace().top + customDialogTop
  611. );
  612. if (overrideEnterDuration >= 0) {
  613. enterAnimDurationTemp = overrideEnterDuration;
  614. }
  615. if (enterAnimDuration >= 0) {
  616. enterAnimDurationTemp = enterAnimDuration;
  617. }
  618. enterAnim.setDuration(enterAnimDurationTemp);
  619. enterAnim.setAutoCancel(true);
  620. enterAnim.setInterpolator(new DecelerateInterpolator(2f));
  621. enterAnim.start();
  622. //遮罩层动画
  623. ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
  624. bkgAlpha.setDuration(enterAnimDurationTemp);
  625. bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  626. @Override
  627. public void onAnimationUpdate(ValueAnimator animation) {
  628. animProgress.run((Float) animation.getAnimatedValue());
  629. }
  630. });
  631. bkgAlpha.start();
  632. }
  633. @Override
  634. public void doExitAnim(BottomDialog dialog, ObjectRunnable<Float> animProgress) {
  635. if (overrideExitDuration >= 0) {
  636. exitAnimDurationTemp = overrideExitDuration;
  637. }
  638. if (exitAnimDuration >= 0) {
  639. exitAnimDurationTemp = exitAnimDuration;
  640. }
  641. ObjectAnimator exitAnim = ObjectAnimator.ofFloat(boxBkg, "y", boxBkg.getY(), boxBkg.getHeight());
  642. exitAnim.setDuration(exitAnimDurationTemp);
  643. exitAnim.start();
  644. ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
  645. bkgAlpha.setDuration(exitAnimDurationTemp);
  646. bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  647. @Override
  648. public void onAnimationUpdate(ValueAnimator animation) {
  649. animProgress.run((Float) animation.getAnimatedValue());
  650. }
  651. });
  652. bkgAlpha.start();
  653. }
  654. };
  655. }
  656. return dialogXAnimImpl;
  657. }
  658. }
  659. public void refreshUI() {
  660. if (getDialogImpl() == null) return;
  661. runOnMain(new Runnable() {
  662. @Override
  663. public void run() {
  664. if (dialogImpl != null) dialogImpl.refreshView();
  665. }
  666. });
  667. }
  668. public void dismiss() {
  669. runOnMain(new Runnable() {
  670. @Override
  671. public void run() {
  672. if (dialogImpl == null) return;
  673. dialogImpl.doDismiss(null);
  674. }
  675. });
  676. }
  677. public DialogLifecycleCallback<BottomDialog> getDialogLifecycleCallback() {
  678. return dialogLifecycleCallback == null ? new DialogLifecycleCallback<BottomDialog>() {
  679. } : dialogLifecycleCallback;
  680. }
  681. public BottomDialog setDialogLifecycleCallback(DialogLifecycleCallback<BottomDialog> dialogLifecycleCallback) {
  682. this.dialogLifecycleCallback = dialogLifecycleCallback;
  683. if (isShow) dialogLifecycleCallback.onShow(me);
  684. return this;
  685. }
  686. public OnBackPressedListener<BottomDialog> getOnBackPressedListener() {
  687. return (OnBackPressedListener<BottomDialog>) onBackPressedListener;
  688. }
  689. public BottomDialog setOnBackPressedListener(OnBackPressedListener<BottomDialog> onBackPressedListener) {
  690. this.onBackPressedListener = onBackPressedListener;
  691. refreshUI();
  692. return this;
  693. }
  694. public BottomDialog setStyle(DialogXStyle style) {
  695. this.style = style;
  696. return this;
  697. }
  698. public BottomDialog setTheme(DialogX.THEME theme) {
  699. this.theme = theme;
  700. return this;
  701. }
  702. public boolean isCancelable() {
  703. if (privateCancelable != null) {
  704. return privateCancelable == BOOLEAN.TRUE;
  705. }
  706. if (overrideCancelable != null) {
  707. return overrideCancelable == BOOLEAN.TRUE;
  708. }
  709. return cancelable;
  710. }
  711. public BottomDialog setCancelable(boolean cancelable) {
  712. this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
  713. refreshUI();
  714. return this;
  715. }
  716. public DialogImpl getDialogImpl() {
  717. return dialogImpl;
  718. }
  719. public CharSequence getTitle() {
  720. return title;
  721. }
  722. public BottomDialog setTitle(CharSequence title) {
  723. this.title = title;
  724. refreshUI();
  725. return this;
  726. }
  727. public BottomDialog setTitle(int titleResId) {
  728. this.title = getString(titleResId);
  729. refreshUI();
  730. return this;
  731. }
  732. public CharSequence getMessage() {
  733. return message;
  734. }
  735. public BottomDialog setMessage(CharSequence message) {
  736. this.message = message;
  737. refreshUI();
  738. return this;
  739. }
  740. public BottomDialog setMessage(int messageResId) {
  741. this.message = getString(messageResId);
  742. refreshUI();
  743. return this;
  744. }
  745. public CharSequence getCancelButton() {
  746. return cancelText;
  747. }
  748. public BottomDialog setCancelButton(CharSequence cancelText) {
  749. this.cancelText = cancelText;
  750. refreshUI();
  751. return this;
  752. }
  753. public BottomDialog setCancelButton(int cancelTextResId) {
  754. this.cancelText = getString(cancelTextResId);
  755. refreshUI();
  756. return this;
  757. }
  758. public BottomDialog setCancelButton(OnDialogButtonClickListener<BottomDialog> cancelButtonClickListener) {
  759. this.cancelButtonClickListener = cancelButtonClickListener;
  760. return this;
  761. }
  762. public BottomDialog setCancelButton(CharSequence cancelText, OnDialogButtonClickListener<BottomDialog> cancelButtonClickListener) {
  763. this.cancelText = cancelText;
  764. this.cancelButtonClickListener = cancelButtonClickListener;
  765. refreshUI();
  766. return this;
  767. }
  768. public BottomDialog setCancelButton(int cancelTextResId, OnDialogButtonClickListener<BottomDialog> cancelButtonClickListener) {
  769. this.cancelText = getString(cancelTextResId);
  770. this.cancelButtonClickListener = cancelButtonClickListener;
  771. refreshUI();
  772. return this;
  773. }
  774. public BottomDialog setCustomView(OnBindView<BottomDialog> onBindView) {
  775. this.onBindView = onBindView;
  776. refreshUI();
  777. return this;
  778. }
  779. public View getCustomView() {
  780. if (onBindView == null) return null;
  781. return onBindView.getCustomView();
  782. }
  783. public BottomDialog removeCustomView() {
  784. this.onBindView.clean();
  785. refreshUI();
  786. return this;
  787. }
  788. public boolean isAllowInterceptTouch() {
  789. if (style.overrideBottomDialogRes() == null) {
  790. return false;
  791. } else {
  792. return allowInterceptTouch && style.overrideBottomDialogRes().touchSlide();
  793. }
  794. }
  795. public BottomDialog setAllowInterceptTouch(boolean allowInterceptTouch) {
  796. this.allowInterceptTouch = allowInterceptTouch;
  797. refreshUI();
  798. return this;
  799. }
  800. public OnDialogButtonClickListener<BottomDialog> getCancelButtonClickListener() {
  801. return cancelButtonClickListener;
  802. }
  803. public BottomDialog setCancelButtonClickListener(OnDialogButtonClickListener<BottomDialog> cancelButtonClickListener) {
  804. this.cancelButtonClickListener = cancelButtonClickListener;
  805. return this;
  806. }
  807. public TextInfo getTitleTextInfo() {
  808. return titleTextInfo;
  809. }
  810. public BottomDialog setTitleTextInfo(TextInfo titleTextInfo) {
  811. this.titleTextInfo = titleTextInfo;
  812. refreshUI();
  813. return this;
  814. }
  815. public TextInfo getMessageTextInfo() {
  816. return messageTextInfo;
  817. }
  818. public BottomDialog setMessageTextInfo(TextInfo messageTextInfo) {
  819. this.messageTextInfo = messageTextInfo;
  820. refreshUI();
  821. return this;
  822. }
  823. public TextInfo getCancelTextInfo() {
  824. return cancelTextInfo;
  825. }
  826. public BottomDialog setCancelTextInfo(TextInfo cancelTextInfo) {
  827. this.cancelTextInfo = cancelTextInfo;
  828. refreshUI();
  829. return this;
  830. }
  831. public int getBackgroundColor() {
  832. return backgroundColor;
  833. }
  834. public BottomDialog setBackgroundColor(@ColorInt int backgroundColor) {
  835. this.backgroundColor = backgroundColor;
  836. refreshUI();
  837. return this;
  838. }
  839. public BottomDialog setBackgroundColorRes(@ColorRes int backgroundRes) {
  840. this.backgroundColor = getColor(backgroundRes);
  841. refreshUI();
  842. return this;
  843. }
  844. public CharSequence getOkButton() {
  845. return okText;
  846. }
  847. public BottomDialog setOkButton(CharSequence okText) {
  848. this.okText = okText;
  849. refreshUI();
  850. return this;
  851. }
  852. public BottomDialog setOkButton(int OkTextResId) {
  853. this.okText = getString(OkTextResId);
  854. refreshUI();
  855. return this;
  856. }
  857. public BottomDialog setOkButton(OnDialogButtonClickListener<BottomDialog> OkButtonClickListener) {
  858. this.okButtonClickListener = OkButtonClickListener;
  859. return this;
  860. }
  861. public BottomDialog setOkButton(CharSequence OkText, OnDialogButtonClickListener<BottomDialog> OkButtonClickListener) {
  862. this.okText = OkText;
  863. this.okButtonClickListener = OkButtonClickListener;
  864. refreshUI();
  865. return this;
  866. }
  867. public BottomDialog setOkButton(int OkTextResId, OnDialogButtonClickListener<BottomDialog> OkButtonClickListener) {
  868. this.okText = getString(OkTextResId);
  869. this.okButtonClickListener = OkButtonClickListener;
  870. refreshUI();
  871. return this;
  872. }
  873. public CharSequence getOtherButton() {
  874. return otherText;
  875. }
  876. public BottomDialog setOtherButton(CharSequence otherText) {
  877. this.otherText = otherText;
  878. refreshUI();
  879. return this;
  880. }
  881. public BottomDialog setOtherButton(int OtherTextResId) {
  882. this.otherText = getString(OtherTextResId);
  883. refreshUI();
  884. return this;
  885. }
  886. public BottomDialog setOtherButton(OnDialogButtonClickListener<BottomDialog> OtherButtonClickListener) {
  887. this.otherButtonClickListener = OtherButtonClickListener;
  888. return this;
  889. }
  890. public BottomDialog setOtherButton(CharSequence OtherText, OnDialogButtonClickListener<BottomDialog> OtherButtonClickListener) {
  891. this.otherText = OtherText;
  892. this.otherButtonClickListener = OtherButtonClickListener;
  893. refreshUI();
  894. return this;
  895. }
  896. public BottomDialog setOtherButton(int OtherTextResId, OnDialogButtonClickListener<BottomDialog> OtherButtonClickListener) {
  897. this.otherText = getString(OtherTextResId);
  898. this.otherButtonClickListener = OtherButtonClickListener;
  899. refreshUI();
  900. return this;
  901. }
  902. public BottomDialog setMaskColor(@ColorInt int maskColor) {
  903. this.maskColor = maskColor;
  904. refreshUI();
  905. return this;
  906. }
  907. public long getEnterAnimDuration() {
  908. return enterAnimDuration;
  909. }
  910. public BottomDialog setEnterAnimDuration(long enterAnimDuration) {
  911. this.enterAnimDuration = enterAnimDuration;
  912. return this;
  913. }
  914. public long getExitAnimDuration() {
  915. return exitAnimDuration;
  916. }
  917. public BottomDialog setExitAnimDuration(long exitAnimDuration) {
  918. this.exitAnimDuration = exitAnimDuration;
  919. return this;
  920. }
  921. @Override
  922. public void restartDialog() {
  923. if (dialogView != null) {
  924. dismiss(dialogView);
  925. isShow = false;
  926. }
  927. if (getDialogImpl().boxCustom != null) {
  928. getDialogImpl().boxCustom.removeAllViews();
  929. }
  930. if (getDialogImpl().boxList != null) {
  931. getDialogImpl().boxList.removeAllViews();
  932. }
  933. int layoutId = isLightTheme() ? R.layout.layout_dialogx_bottom_material : R.layout.layout_dialogx_bottom_material_dark;
  934. if (style.overrideBottomDialogRes() != null) {
  935. layoutId = style.overrideBottomDialogRes().overrideDialogLayout(isLightTheme());
  936. }
  937. enterAnimDuration = 0;
  938. dialogView = createView(layoutId);
  939. dialogImpl = new DialogImpl(dialogView);
  940. if (dialogView != null) dialogView.setTag(me);
  941. show(dialogView);
  942. }
  943. protected boolean isHide;
  944. public void hide() {
  945. isHide = true;
  946. hideWithExitAnim = false;
  947. if (getDialogView() != null) {
  948. getDialogView().setVisibility(View.GONE);
  949. }
  950. }
  951. protected boolean hideWithExitAnim;
  952. public void hideWithExitAnim() {
  953. hideWithExitAnim = true;
  954. isHide = true;
  955. if (getDialogImpl() != null) {
  956. getDialogImpl().getDialogXAnimImpl().doExitAnim(me, new ObjectRunnable<Float>() {
  957. @Override
  958. public void run(Float value) {
  959. if (getDialogImpl().boxRoot != null) {
  960. getDialogImpl().boxRoot.setBkgAlpha(value);
  961. }
  962. if (value == 0 && getDialogView() != null) {
  963. getDialogView().setVisibility(View.GONE);
  964. }
  965. }
  966. });
  967. }
  968. }
  969. @Override
  970. protected void shutdown() {
  971. dismiss();
  972. }
  973. public float getBottomDialogMaxHeight() {
  974. return bottomDialogMaxHeight;
  975. }
  976. public BottomDialog setBottomDialogMaxHeight(float bottomDialogMaxHeight) {
  977. this.bottomDialogMaxHeight = bottomDialogMaxHeight;
  978. return this;
  979. }
  980. public BottomDialog setMaxWidth(int maxWidth) {
  981. this.maxWidth = maxWidth;
  982. refreshUI();
  983. return this;
  984. }
  985. public BottomDialog setMaxHeight(int maxHeight) {
  986. this.maxHeight = maxHeight;
  987. refreshUI();
  988. return this;
  989. }
  990. public BottomDialog setMinHeight(int minHeight) {
  991. this.minHeight = minHeight;
  992. refreshUI();
  993. return this;
  994. }
  995. public BottomDialog setMinWidth(int minWidth) {
  996. this.minWidth = minWidth;
  997. refreshUI();
  998. return this;
  999. }
  1000. public BottomDialog setDialogImplMode(DialogX.IMPL_MODE dialogImplMode) {
  1001. this.dialogImplMode = dialogImplMode;
  1002. return this;
  1003. }
  1004. public boolean isBkgInterceptTouch() {
  1005. return bkgInterceptTouch;
  1006. }
  1007. public BottomDialog setBkgInterceptTouch(boolean bkgInterceptTouch) {
  1008. this.bkgInterceptTouch = bkgInterceptTouch;
  1009. return this;
  1010. }
  1011. public OnBackgroundMaskClickListener<BottomDialog> getOnBackgroundMaskClickListener() {
  1012. return (OnBackgroundMaskClickListener<BottomDialog>) onBackgroundMaskClickListener;
  1013. }
  1014. public BottomDialog setOnBackgroundMaskClickListener(OnBackgroundMaskClickListener<BottomDialog> onBackgroundMaskClickListener) {
  1015. this.onBackgroundMaskClickListener = onBackgroundMaskClickListener;
  1016. return this;
  1017. }
  1018. public BottomDialog setRadius(float radiusPx) {
  1019. backgroundRadius = radiusPx;
  1020. refreshUI();
  1021. return this;
  1022. }
  1023. public float getRadius() {
  1024. return backgroundRadius;
  1025. }
  1026. public Drawable getTitleIcon() {
  1027. return titleIcon;
  1028. }
  1029. public BottomDialog setTitleIcon(Bitmap titleIcon) {
  1030. this.titleIcon = new BitmapDrawable(getResources(), titleIcon);
  1031. refreshUI();
  1032. return this;
  1033. }
  1034. public BottomDialog setTitleIcon(int titleIconResId) {
  1035. this.titleIcon = getResources().getDrawable(titleIconResId);
  1036. refreshUI();
  1037. return this;
  1038. }
  1039. public BottomDialog setTitleIcon(Drawable titleIcon) {
  1040. this.titleIcon = titleIcon;
  1041. refreshUI();
  1042. return this;
  1043. }
  1044. public DialogXAnimInterface<BottomDialog> getDialogXAnimImpl() {
  1045. return dialogXAnimImpl;
  1046. }
  1047. public BottomDialog setDialogXAnimImpl(DialogXAnimInterface<BottomDialog> dialogXAnimImpl) {
  1048. this.dialogXAnimImpl = dialogXAnimImpl;
  1049. return this;
  1050. }
  1051. public BottomDialog setRootPadding(int padding) {
  1052. this.screenPaddings = new int[]{padding, padding, padding, padding};
  1053. refreshUI();
  1054. return this;
  1055. }
  1056. public BottomDialog setRootPadding(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
  1057. this.screenPaddings = new int[]{paddingLeft, paddingTop, paddingRight, paddingBottom};
  1058. refreshUI();
  1059. return this;
  1060. }
  1061. public BUTTON_SELECT_RESULT getButtonSelectResult() {
  1062. return buttonSelectResult;
  1063. }
  1064. /**
  1065. * 用于使用 new 构建实例时,override 的生命周期事件
  1066. * 例如:
  1067. * new BottomDialog() {
  1068. * @Override
  1069. * public void onShow(BottomDialog dialog) {
  1070. * //...
  1071. * }
  1072. * }
  1073. *
  1074. * @param dialog self
  1075. */
  1076. public void onShow(BottomDialog dialog){
  1077. }
  1078. /**
  1079. * 用于使用 new 构建实例时,override 的生命周期事件
  1080. * 例如:
  1081. * new BottomDialog() {
  1082. * @Override
  1083. * public boolean onDismiss(BottomDialog dialog) {
  1084. * WaitDialog.show("Please Wait...");
  1085. * if (dialog.getButtonSelectResult() == BUTTON_SELECT_RESULT.BUTTON_OK) {
  1086. * //点击了OK的情况
  1087. * //...
  1088. * } else {
  1089. * //其他按钮点击、对话框dismiss的情况
  1090. * //...
  1091. * }
  1092. * return false;
  1093. * }
  1094. * }
  1095. * @param dialog self
  1096. */
  1097. //用于使用 new 构建实例时,override 的生命周期事件
  1098. public void onDismiss(BottomDialog dialog){
  1099. }
  1100. }