FullScreenDialog.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. package com.kongzue.dialogx.dialogs;
  2. import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
  3. import android.animation.ObjectAnimator;
  4. import android.animation.ValueAnimator;
  5. import android.app.Activity;
  6. import android.graphics.Outline;
  7. import android.graphics.Rect;
  8. import android.graphics.drawable.GradientDrawable;
  9. import android.os.Handler;
  10. import android.os.Looper;
  11. import android.view.View;
  12. import android.view.ViewGroup;
  13. import android.view.ViewOutlineProvider;
  14. import android.view.animation.Animation;
  15. import android.view.animation.DecelerateInterpolator;
  16. import android.widget.RelativeLayout;
  17. import androidx.annotation.ColorInt;
  18. import androidx.annotation.ColorRes;
  19. import androidx.annotation.Nullable;
  20. import androidx.lifecycle.Lifecycle;
  21. import com.kongzue.dialogx.DialogX;
  22. import com.kongzue.dialogx.R;
  23. import com.kongzue.dialogx.interfaces.BaseDialog;
  24. import com.kongzue.dialogx.interfaces.DialogConvertViewInterface;
  25. import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
  26. import com.kongzue.dialogx.interfaces.DialogXAnimInterface;
  27. import com.kongzue.dialogx.interfaces.DialogXBaseBottomDialog;
  28. import com.kongzue.dialogx.interfaces.DialogXStyle;
  29. import com.kongzue.dialogx.interfaces.OnBackPressedListener;
  30. import com.kongzue.dialogx.interfaces.OnBackgroundMaskClickListener;
  31. import com.kongzue.dialogx.interfaces.OnBindView;
  32. import com.kongzue.dialogx.interfaces.OnSafeInsetsChangeListener;
  33. import com.kongzue.dialogx.interfaces.ScrollController;
  34. import com.kongzue.dialogx.util.FullScreenDialogTouchEventInterceptor;
  35. import com.kongzue.dialogx.util.ObjectRunnable;
  36. import com.kongzue.dialogx.util.views.ActivityScreenShotImageView;
  37. import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
  38. import com.kongzue.dialogx.util.views.MaxRelativeLayout;
  39. /**
  40. * @author: Kongzue
  41. * @github: https://github.com/kongzue/
  42. * @homepage: http://kongzue.com/
  43. * @mail: myzcxhh@live.cn
  44. * @createTime: 2020/10/6 15:17
  45. */
  46. public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDialog {
  47. public static int overrideEnterDuration = -1;
  48. public static int overrideExitDuration = -1;
  49. public static BOOLEAN overrideCancelable;
  50. protected OnBindView<FullScreenDialog> onBindView;
  51. protected OnBackPressedListener<FullScreenDialog> onBackPressedListener;
  52. protected BOOLEAN privateCancelable;
  53. protected boolean hideZoomBackground;
  54. protected float backgroundRadius = -1;
  55. protected boolean allowInterceptTouch = true;
  56. protected DialogXAnimInterface<FullScreenDialog> dialogXAnimImpl;
  57. protected boolean bottomNonSafetyAreaBySelf = false;
  58. protected DialogLifecycleCallback<FullScreenDialog> dialogLifecycleCallback;
  59. protected OnBackgroundMaskClickListener<FullScreenDialog> onBackgroundMaskClickListener;
  60. protected FullScreenDialog me = this;
  61. protected FullScreenDialog() {
  62. super();
  63. }
  64. private View dialogView;
  65. public static FullScreenDialog build() {
  66. return new FullScreenDialog();
  67. }
  68. public static FullScreenDialog build(OnBindView<FullScreenDialog> onBindView) {
  69. return new FullScreenDialog(onBindView);
  70. }
  71. public FullScreenDialog(OnBindView<FullScreenDialog> onBindView) {
  72. this.onBindView = onBindView;
  73. }
  74. public static FullScreenDialog show(OnBindView<FullScreenDialog> onBindView) {
  75. FullScreenDialog fullScreenDialog = new FullScreenDialog(onBindView);
  76. fullScreenDialog.show();
  77. return fullScreenDialog;
  78. }
  79. public FullScreenDialog show() {
  80. if (isHide && getDialogView() != null && isShow) {
  81. if (hideWithExitAnim && getDialogImpl() != null) {
  82. getDialogView().setVisibility(View.VISIBLE);
  83. getDialogImpl().getDialogXAnimImpl().doShowAnim(me, getDialogImpl().bkg);
  84. } else {
  85. getDialogView().setVisibility(View.VISIBLE);
  86. }
  87. return this;
  88. }
  89. super.beforeShow();
  90. if (getDialogView() == null) {
  91. dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
  92. dialogImpl = new DialogImpl(dialogView);
  93. if (dialogView != null) dialogView.setTag(me);
  94. }
  95. show(dialogView);
  96. return this;
  97. }
  98. public void show(Activity activity) {
  99. super.beforeShow();
  100. if (getDialogView() == null) {
  101. dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
  102. dialogImpl = new DialogImpl(dialogView);
  103. if (dialogView != null) dialogView.setTag(me);
  104. }
  105. show(activity, dialogView);
  106. }
  107. protected DialogImpl dialogImpl;
  108. public class DialogImpl implements DialogConvertViewInterface {
  109. private FullScreenDialogTouchEventInterceptor fullScreenDialogTouchEventInterceptor;
  110. public ActivityScreenShotImageView imgZoomActivity;
  111. public DialogXBaseRelativeLayout boxRoot;
  112. public RelativeLayout boxBkg;
  113. public MaxRelativeLayout bkg;
  114. public RelativeLayout boxCustom;
  115. public ScrollController scrollView;
  116. public DialogImpl setScrollView(ScrollController scrollView) {
  117. this.scrollView = scrollView;
  118. return this;
  119. }
  120. public DialogImpl(View convertView) {
  121. if (convertView == null) return;
  122. imgZoomActivity = convertView.findViewById(R.id.img_zoom_activity);
  123. boxRoot = convertView.findViewById(R.id.box_root);
  124. boxBkg = convertView.findViewById(R.id.box_bkg);
  125. bkg = convertView.findViewById(R.id.bkg);
  126. boxCustom = convertView.findViewById(R.id.box_custom);
  127. imgZoomActivity.bindDialog(FullScreenDialog.this);
  128. if (hideZoomBackground) {
  129. dialogView.setBackgroundResource(R.color.black20);
  130. imgZoomActivity.setVisibility(View.GONE);
  131. } else {
  132. dialogView.setBackgroundResource(R.color.black);
  133. imgZoomActivity.setVisibility(View.VISIBLE);
  134. }
  135. init();
  136. dialogImpl = this;
  137. refreshView();
  138. }
  139. public float bkgEnterAimY = -1;
  140. protected int enterY;
  141. public float getEnterY() {
  142. return boxRoot.getSafeHeight() - enterY > 0 ? boxRoot.getSafeHeight() - enterY : 0;
  143. }
  144. @Override
  145. public void init() {
  146. boxRoot.setParentDialog(me);
  147. boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
  148. @Override
  149. public void onShow() {
  150. isShow = true;
  151. preShow = false;
  152. setLifecycleState(Lifecycle.State.CREATED);
  153. onDialogShow();
  154. getDialogLifecycleCallback().onShow(me);
  155. FullScreenDialog.this.onShow(me);
  156. }
  157. @Override
  158. public void onDismiss() {
  159. isShow = false;
  160. getDialogLifecycleCallback().onDismiss(me);
  161. FullScreenDialog.this.onDismiss(me);
  162. fullScreenDialogTouchEventInterceptor = null;
  163. dialogImpl = null;
  164. dialogLifecycleCallback = null;
  165. setLifecycleState(Lifecycle.State.DESTROYED);
  166. System.gc();
  167. }
  168. });
  169. boxRoot.setOnBackPressedListener(new DialogXBaseRelativeLayout.PrivateBackPressedListener() {
  170. @Override
  171. public boolean onBackPressed() {
  172. if (onBackPressedListener != null) {
  173. if (onBackPressedListener.onBackPressed(me)) {
  174. dismiss();
  175. }
  176. } else {
  177. if (isCancelable()) {
  178. dismiss();
  179. }
  180. }
  181. return true;
  182. }
  183. });
  184. fullScreenDialogTouchEventInterceptor = new FullScreenDialogTouchEventInterceptor(me, dialogImpl);
  185. boxRoot.setBkgAlpha(0f);
  186. bkg.setY(boxRoot.getHeight());
  187. boxRoot.post(new Runnable() {
  188. @Override
  189. public void run() {
  190. getDialogXAnimImpl().doShowAnim(me, bkg);
  191. setLifecycleState(Lifecycle.State.RESUMED);
  192. }
  193. });
  194. boxRoot.setOnSafeInsetsChangeListener(new OnSafeInsetsChangeListener() {
  195. @Override
  196. public void onChange(Rect unsafeRect) {
  197. makeEnterY();
  198. if (!enterAnimRunning) {
  199. bkg.setY(getEnterY());
  200. }
  201. }
  202. });
  203. bkg.setOnYChanged(new MaxRelativeLayout.OnYChanged() {
  204. @Override
  205. public void y(float y) {
  206. float realY = y + bkg.getTop();
  207. float zoomScale = 1 - (boxRoot.getHeight() - realY) * 0.00002f;
  208. if (zoomScale > 1) zoomScale = 1;
  209. if (!hideZoomBackground) {
  210. imgZoomActivity.setScale(zoomScale);
  211. imgZoomActivity.setRadius(dip2px(15) * ((boxRoot.getHeight() - realY) / boxRoot.getHeight()));
  212. }
  213. }
  214. });
  215. onDialogInit();
  216. }
  217. private boolean isMatchParentHeightCustomView() {
  218. if (onBindView != null && onBindView.getCustomView() != null) {
  219. ViewGroup.LayoutParams lp = onBindView.getCustomView().getLayoutParams();
  220. if (lp != null) {
  221. return lp.height == MATCH_PARENT;
  222. }
  223. }
  224. return false;
  225. }
  226. private void makeEnterY() {
  227. int customViewHeight = boxCustom.getHeight();
  228. if (customViewHeight == 0 || isMatchParentHeightCustomView()) {
  229. customViewHeight = ((int) boxRoot.getSafeHeight());
  230. }
  231. if (getMaxHeight() != 0) {
  232. enterY = Math.min(getMaxHeight() - boxRoot.getUnsafePlace().bottom, customViewHeight);
  233. } else {
  234. enterY = customViewHeight;
  235. }
  236. }
  237. @Override
  238. public void refreshView() {
  239. if (boxRoot == null || getOwnActivity() == null) {
  240. return;
  241. }
  242. boxRoot.setRootPadding(screenPaddings[0], screenPaddings[1], screenPaddings[2], screenPaddings[3]);
  243. if (backgroundColor != -1) {
  244. tintColor(bkg, backgroundColor);
  245. }
  246. bkg.setMaxWidth(getMaxWidth());
  247. bkg.setMaxHeight(getMaxHeight());
  248. bkg.setMinimumWidth(getMinWidth());
  249. bkg.setMinimumHeight(getMinHeight());
  250. if (isCancelable()) {
  251. boxRoot.setOnClickListener(new View.OnClickListener() {
  252. @Override
  253. public void onClick(View v) {
  254. if (onBackgroundMaskClickListener == null || !onBackgroundMaskClickListener.onClick(me, v)) {
  255. doDismiss(v);
  256. }
  257. }
  258. });
  259. } else {
  260. boxRoot.setOnClickListener(null);
  261. }
  262. if (backgroundRadius > -1) {
  263. GradientDrawable gradientDrawable = (GradientDrawable) bkg.getBackground();
  264. if (gradientDrawable != null) gradientDrawable.setCornerRadii(new float[]{
  265. backgroundRadius, backgroundRadius, backgroundRadius, backgroundRadius, 0, 0, 0, 0
  266. });
  267. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
  268. bkg.setOutlineProvider(new ViewOutlineProvider() {
  269. @Override
  270. public void getOutline(View view, Outline outline) {
  271. outline.setRoundRect(0, 0, view.getWidth(), (int) (view.getHeight() + backgroundRadius), backgroundRadius);
  272. }
  273. });
  274. bkg.setClipToOutline(true);
  275. }
  276. }
  277. if (onBindView != null) {
  278. onBindView.bindParent(boxCustom, me);
  279. if (onBindView.getCustomView() instanceof ScrollController) {
  280. scrollView = (ScrollController) onBindView.getCustomView();
  281. } else {
  282. View scrollController = onBindView.getCustomView().findViewWithTag("ScrollController");
  283. if (scrollController instanceof ScrollController) {
  284. scrollView = (ScrollController) scrollController;
  285. }
  286. }
  287. }
  288. if (hideZoomBackground) {
  289. dialogView.setBackgroundResource(R.color.black20);
  290. imgZoomActivity.setVisibility(View.GONE);
  291. } else {
  292. dialogView.setBackgroundResource(R.color.black);
  293. imgZoomActivity.setVisibility(View.VISIBLE);
  294. }
  295. fullScreenDialogTouchEventInterceptor.refresh(me, this);
  296. onDialogRefreshUI();
  297. }
  298. @Override
  299. public void doDismiss(View v) {
  300. if (v != null) v.setEnabled(false);
  301. if (getOwnActivity() == null) return;
  302. if (!dismissAnimFlag && getDialogXAnimImpl() != null) {
  303. dismissAnimFlag = true;
  304. getDialogXAnimImpl().doExitAnim(me, bkg);
  305. runOnMainDelay(new Runnable() {
  306. @Override
  307. public void run() {
  308. if (boxRoot != null) {
  309. boxRoot.setVisibility(View.GONE);
  310. }
  311. dismiss(dialogView);
  312. }
  313. }, getExitAnimationDuration());
  314. }
  315. }
  316. public void preDismiss() {
  317. if (isCancelable()) {
  318. doDismiss(boxRoot);
  319. } else {
  320. long exitAnimDurationTemp = 300;
  321. if (overrideExitDuration >= 0) {
  322. exitAnimDurationTemp = overrideExitDuration;
  323. }
  324. if (exitAnimDuration >= 0) {
  325. exitAnimDurationTemp = exitAnimDuration;
  326. }
  327. ObjectAnimator exitAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), bkgEnterAimY);
  328. exitAnim.setDuration(exitAnimDurationTemp);
  329. exitAnim.start();
  330. }
  331. }
  332. private boolean enterAnimRunning = true;
  333. protected DialogXAnimInterface<FullScreenDialog> getDialogXAnimImpl() {
  334. if (dialogXAnimImpl == null) {
  335. dialogXAnimImpl = new DialogXAnimInterface<FullScreenDialog>() {
  336. @Override
  337. public void doShowAnim(FullScreenDialog dialog, ViewGroup dialogBodyView) {
  338. long enterAnimDurationTemp = getEnterAnimationDuration();
  339. makeEnterY();
  340. bkgEnterAimY = boxRoot.getSafeHeight() - enterY;
  341. if (bkgEnterAimY < 0) bkgEnterAimY = 0;
  342. ObjectAnimator enterAnim = ObjectAnimator.ofFloat(bkg, "y", boxRoot.getHeight(), bkgEnterAimY);
  343. enterAnim.setDuration(enterAnimDurationTemp);
  344. enterAnim.setInterpolator(new DecelerateInterpolator());
  345. enterAnim.start();
  346. bkg.setVisibility(View.VISIBLE);
  347. ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
  348. bkgAlpha.setDuration(enterAnimDurationTemp);
  349. bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  350. @Override
  351. public void onAnimationUpdate(ValueAnimator animation) {
  352. float value = (float) animation.getAnimatedValue();
  353. boxRoot.setBkgAlpha(value);
  354. enterAnimRunning = !(value == 1f);
  355. }
  356. });
  357. bkgAlpha.start();
  358. }
  359. @Override
  360. public void doExitAnim(FullScreenDialog dialog, ViewGroup dialogBodyView) {
  361. long exitAnimDurationTemp = getExitAnimationDuration();
  362. ObjectAnimator exitAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), boxBkg.getHeight());
  363. exitAnim.setDuration(exitAnimDurationTemp);
  364. exitAnim.start();
  365. ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
  366. bkgAlpha.setDuration(exitAnimDurationTemp);
  367. bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  368. @Override
  369. public void onAnimationUpdate(ValueAnimator animation) {
  370. float value = (float) animation.getAnimatedValue();
  371. boxRoot.setBkgAlpha(value);
  372. enterAnimRunning = !(value == 1f);
  373. }
  374. });
  375. bkgAlpha.start();
  376. }
  377. };
  378. }
  379. return dialogXAnimImpl;
  380. }
  381. public long getExitAnimationDuration() {
  382. long exitAnimDurationTemp = 300;
  383. if (overrideExitDuration >= 0) {
  384. exitAnimDurationTemp = overrideExitDuration;
  385. }
  386. if (exitAnimDuration != -1) {
  387. exitAnimDurationTemp = exitAnimDuration;
  388. }
  389. return exitAnimDurationTemp;
  390. }
  391. public long getEnterAnimationDuration() {
  392. long enterAnimDurationTemp = 300;
  393. if (overrideEnterDuration >= 0) {
  394. enterAnimDurationTemp = overrideEnterDuration;
  395. }
  396. if (enterAnimDuration >= 0) {
  397. enterAnimDurationTemp = enterAnimDuration;
  398. }
  399. return enterAnimDurationTemp;
  400. }
  401. }
  402. @Override
  403. public String dialogKey() {
  404. return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
  405. }
  406. public void refreshUI() {
  407. if (getDialogImpl() == null) return;
  408. runOnMain(new Runnable() {
  409. @Override
  410. public void run() {
  411. if (dialogImpl != null) dialogImpl.refreshView();
  412. }
  413. });
  414. }
  415. public void dismiss() {
  416. runOnMain(new Runnable() {
  417. @Override
  418. public void run() {
  419. if (dialogImpl == null) return;
  420. dialogImpl.doDismiss(null);
  421. }
  422. });
  423. }
  424. public DialogLifecycleCallback<FullScreenDialog> getDialogLifecycleCallback() {
  425. return dialogLifecycleCallback == null ? new DialogLifecycleCallback<FullScreenDialog>() {
  426. } : dialogLifecycleCallback;
  427. }
  428. public FullScreenDialog setDialogLifecycleCallback(DialogLifecycleCallback<FullScreenDialog> dialogLifecycleCallback) {
  429. this.dialogLifecycleCallback = dialogLifecycleCallback;
  430. if (isShow) dialogLifecycleCallback.onShow(me);
  431. return this;
  432. }
  433. public OnBackPressedListener<FullScreenDialog> getOnBackPressedListener() {
  434. return (OnBackPressedListener<FullScreenDialog>) onBackPressedListener;
  435. }
  436. public FullScreenDialog setOnBackPressedListener(OnBackPressedListener<FullScreenDialog> onBackPressedListener) {
  437. this.onBackPressedListener = onBackPressedListener;
  438. refreshUI();
  439. return this;
  440. }
  441. public FullScreenDialog setStyle(DialogXStyle style) {
  442. this.style = style;
  443. return this;
  444. }
  445. public FullScreenDialog setTheme(DialogX.THEME theme) {
  446. this.theme = theme;
  447. return this;
  448. }
  449. public boolean isCancelable() {
  450. if (privateCancelable != null) {
  451. return privateCancelable == BOOLEAN.TRUE;
  452. }
  453. if (overrideCancelable != null) {
  454. return overrideCancelable == BOOLEAN.TRUE;
  455. }
  456. return cancelable;
  457. }
  458. public FullScreenDialog setCancelable(boolean cancelable) {
  459. this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
  460. refreshUI();
  461. return this;
  462. }
  463. public DialogImpl getDialogImpl() {
  464. return dialogImpl;
  465. }
  466. public FullScreenDialog setCustomView(OnBindView<FullScreenDialog> onBindView) {
  467. this.onBindView = onBindView;
  468. refreshUI();
  469. return this;
  470. }
  471. public View getCustomView() {
  472. if (onBindView == null) return null;
  473. return onBindView.getCustomView();
  474. }
  475. public FullScreenDialog removeCustomView() {
  476. this.onBindView.clean();
  477. refreshUI();
  478. return this;
  479. }
  480. public int getBackgroundColor() {
  481. return backgroundColor;
  482. }
  483. public FullScreenDialog setBackgroundColor(@ColorInt int backgroundColor) {
  484. this.backgroundColor = backgroundColor;
  485. refreshUI();
  486. return this;
  487. }
  488. public FullScreenDialog setBackgroundColorRes(@ColorRes int backgroundColorRes) {
  489. this.backgroundColor = getColor(backgroundColorRes);
  490. refreshUI();
  491. return this;
  492. }
  493. public long getEnterAnimDuration() {
  494. return enterAnimDuration;
  495. }
  496. public FullScreenDialog setEnterAnimDuration(long enterAnimDuration) {
  497. this.enterAnimDuration = enterAnimDuration;
  498. return this;
  499. }
  500. public long getExitAnimDuration() {
  501. return exitAnimDuration;
  502. }
  503. public FullScreenDialog setExitAnimDuration(long exitAnimDuration) {
  504. this.exitAnimDuration = exitAnimDuration;
  505. return this;
  506. }
  507. public boolean isHideZoomBackground() {
  508. return hideZoomBackground;
  509. }
  510. public FullScreenDialog setHideZoomBackground(boolean hideZoomBackground) {
  511. this.hideZoomBackground = hideZoomBackground;
  512. refreshUI();
  513. return this;
  514. }
  515. @Override
  516. public void restartDialog() {
  517. if (dialogView != null) {
  518. dismiss(dialogView);
  519. isShow = false;
  520. }
  521. if (getDialogImpl().boxCustom != null) {
  522. getDialogImpl().boxCustom.removeAllViews();
  523. }
  524. enterAnimDuration = 0;
  525. dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
  526. dialogImpl = new DialogImpl(dialogView);
  527. if (dialogView != null) dialogView.setTag(me);
  528. show(dialogView);
  529. }
  530. private boolean isHide;
  531. public void hide() {
  532. isHide = true;
  533. hideWithExitAnim = false;
  534. if (getDialogView() != null) {
  535. getDialogView().setVisibility(View.GONE);
  536. }
  537. }
  538. protected boolean hideWithExitAnim;
  539. public void hideWithExitAnim() {
  540. hideWithExitAnim = true;
  541. isHide = true;
  542. if (getDialogImpl() != null) {
  543. getDialogImpl().getDialogXAnimImpl().doExitAnim(me, getDialogImpl().bkg);
  544. runOnMainDelay(new Runnable() {
  545. @Override
  546. public void run() {
  547. if (getDialogView() != null) {
  548. getDialogView().setVisibility(View.GONE);
  549. }
  550. }
  551. }, getDialogImpl().getExitAnimationDuration());
  552. }
  553. }
  554. @Override
  555. protected void shutdown() {
  556. dismiss();
  557. }
  558. public FullScreenDialog setMaxWidth(int maxWidth) {
  559. this.maxWidth = maxWidth;
  560. refreshUI();
  561. return this;
  562. }
  563. public FullScreenDialog setMaxHeight(int maxHeight) {
  564. this.maxHeight = maxHeight;
  565. refreshUI();
  566. return this;
  567. }
  568. public FullScreenDialog setMinHeight(int minHeight) {
  569. this.minHeight = minHeight;
  570. refreshUI();
  571. return this;
  572. }
  573. public FullScreenDialog setMinWidth(int minWidth) {
  574. this.minWidth = minWidth;
  575. refreshUI();
  576. return this;
  577. }
  578. public FullScreenDialog setDialogImplMode(DialogX.IMPL_MODE dialogImplMode) {
  579. this.dialogImplMode = dialogImplMode;
  580. return this;
  581. }
  582. public OnBackgroundMaskClickListener<FullScreenDialog> getOnBackgroundMaskClickListener() {
  583. return onBackgroundMaskClickListener;
  584. }
  585. public FullScreenDialog setOnBackgroundMaskClickListener(OnBackgroundMaskClickListener<FullScreenDialog> onBackgroundMaskClickListener) {
  586. this.onBackgroundMaskClickListener = onBackgroundMaskClickListener;
  587. return this;
  588. }
  589. public FullScreenDialog setRadius(float radiusPx) {
  590. backgroundRadius = radiusPx;
  591. refreshUI();
  592. return this;
  593. }
  594. public float getRadius() {
  595. return backgroundRadius;
  596. }
  597. public boolean isAllowInterceptTouch() {
  598. return allowInterceptTouch;
  599. }
  600. public FullScreenDialog setAllowInterceptTouch(boolean allowInterceptTouch) {
  601. this.allowInterceptTouch = allowInterceptTouch;
  602. refreshUI();
  603. return this;
  604. }
  605. public DialogXAnimInterface<FullScreenDialog> getDialogXAnimImpl() {
  606. return dialogXAnimImpl;
  607. }
  608. public FullScreenDialog setDialogXAnimImpl(DialogXAnimInterface<FullScreenDialog> dialogXAnimImpl) {
  609. this.dialogXAnimImpl = dialogXAnimImpl;
  610. return this;
  611. }
  612. public FullScreenDialog setRootPadding(int padding) {
  613. this.screenPaddings = new int[]{padding, padding, padding, padding};
  614. refreshUI();
  615. return this;
  616. }
  617. public FullScreenDialog setRootPadding(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
  618. this.screenPaddings = new int[]{paddingLeft, paddingTop, paddingRight, paddingBottom};
  619. refreshUI();
  620. return this;
  621. }
  622. /**
  623. * 用于使用 new 构建实例时,override 的生命周期事件
  624. * 例如:
  625. * new FullScreenDialog() {
  626. *
  627. * @param dialog self
  628. * @Override public void onShow(FullScreenDialog dialog) {
  629. * //...
  630. * }
  631. * }
  632. */
  633. public void onShow(FullScreenDialog dialog) {
  634. }
  635. /**
  636. * 用于使用 new 构建实例时,override 的生命周期事件
  637. * 例如:
  638. * new FullScreenDialog() {
  639. *
  640. * @param dialog self
  641. * @Override public boolean onDismiss(FullScreenDialog dialog) {
  642. * WaitDialog.show("Please Wait...");
  643. * if (dialog.getButtonSelectResult() == BUTTON_SELECT_RESULT.BUTTON_OK) {
  644. * //点击了OK的情况
  645. * //...
  646. * } else {
  647. * //其他按钮点击、对话框dismiss的情况
  648. * //...
  649. * }
  650. * return false;
  651. * }
  652. * }
  653. */
  654. //用于使用 new 构建实例时,override 的生命周期事件
  655. public void onDismiss(FullScreenDialog dialog) {
  656. }
  657. public boolean isBottomNonSafetyAreaBySelf() {
  658. return bottomNonSafetyAreaBySelf;
  659. }
  660. public FullScreenDialog setBottomNonSafetyAreaBySelf(boolean bottomNonSafetyAreaBySelf) {
  661. this.bottomNonSafetyAreaBySelf = bottomNonSafetyAreaBySelf;
  662. return this;
  663. }
  664. }