BottomMenu.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. package com.kongzue.dialogx.dialogs;
  2. import android.content.res.Configuration;
  3. import android.view.MotionEvent;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import android.widget.AdapterView;
  7. import android.widget.BaseAdapter;
  8. import android.widget.RelativeLayout;
  9. import androidx.annotation.ColorInt;
  10. import androidx.annotation.ColorRes;
  11. import com.kongzue.dialogx.DialogX;
  12. import com.kongzue.dialogx.R;
  13. import com.kongzue.dialogx.interfaces.BottomMenuListViewTouchEvent;
  14. import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
  15. import com.kongzue.dialogx.interfaces.DialogXStyle;
  16. import com.kongzue.dialogx.interfaces.OnBackPressedListener;
  17. import com.kongzue.dialogx.interfaces.OnBindView;
  18. import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
  19. import com.kongzue.dialogx.interfaces.OnIconChangeCallBack;
  20. import com.kongzue.dialogx.interfaces.OnMenuItemClickListener;
  21. import com.kongzue.dialogx.util.NormalMenuArrayAdapter;
  22. import com.kongzue.dialogx.util.TextInfo;
  23. import com.kongzue.dialogx.util.views.BottomDialogListView;
  24. import java.util.ArrayList;
  25. import java.util.Arrays;
  26. import java.util.List;
  27. import static android.view.View.OVER_SCROLL_NEVER;
  28. /**
  29. * @author: Kongzue
  30. * @github: https://github.com/kongzue/
  31. * @homepage: http://kongzue.com/
  32. * @mail: myzcxhh@live.cn
  33. * @createTime: 2020/10/6 23:48
  34. */
  35. public class BottomMenu extends BottomDialog {
  36. protected BottomMenu me = this;
  37. protected int selectionIndex = -1;
  38. protected OnMenuItemClickListener<BottomMenu> onMenuItemClickListener;
  39. public static BottomMenu build() {
  40. return new BottomMenu();
  41. }
  42. protected BottomMenu() {
  43. super();
  44. if (style.overrideBottomDialogRes() != null) {
  45. bottomDialogMaxHeight = style.overrideBottomDialogRes().overrideBottomDialogMaxHeight();
  46. }
  47. if (bottomDialogMaxHeight <= 1 && bottomDialogMaxHeight > 0f) {
  48. bottomDialogMaxHeight = (int) (getRootFrameLayout().getMeasuredHeight() * bottomDialogMaxHeight);
  49. }
  50. }
  51. private OnIconChangeCallBack onIconChangeCallBack;
  52. private BottomDialogListView listView;
  53. private BaseAdapter menuListAdapter;
  54. private List<CharSequence> menuList;
  55. public static BottomMenu show(List<CharSequence> menuList) {
  56. BottomMenu bottomMenu = new BottomMenu();
  57. bottomMenu.setMenuList(menuList);
  58. bottomMenu.show();
  59. return bottomMenu;
  60. }
  61. public static BottomMenu show(List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  62. BottomMenu bottomMenu = new BottomMenu();
  63. bottomMenu.setMenuList(menuList);
  64. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  65. bottomMenu.show();
  66. return bottomMenu;
  67. }
  68. public static BottomMenu showStringList(List<String> menuList) {
  69. BottomMenu bottomMenu = new BottomMenu();
  70. bottomMenu.setMenuStringList(menuList);
  71. bottomMenu.show();
  72. return bottomMenu;
  73. }
  74. public static BottomMenu showStringList(List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  75. BottomMenu bottomMenu = new BottomMenu();
  76. bottomMenu.setMenuStringList(menuList);
  77. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  78. bottomMenu.show();
  79. return bottomMenu;
  80. }
  81. public static BottomMenu show(String[] menuList) {
  82. BottomMenu bottomMenu = new BottomMenu();
  83. bottomMenu.setMenuList(menuList);
  84. bottomMenu.show();
  85. return bottomMenu;
  86. }
  87. public static BottomMenu show(String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  88. BottomMenu bottomMenu = new BottomMenu();
  89. bottomMenu.setMenuList(menuList);
  90. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  91. bottomMenu.show();
  92. return bottomMenu;
  93. }
  94. public static BottomMenu show(CharSequence[] menuList) {
  95. BottomMenu bottomMenu = new BottomMenu();
  96. bottomMenu.setMenuList(menuList);
  97. bottomMenu.show();
  98. return bottomMenu;
  99. }
  100. public static BottomMenu show(CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  101. BottomMenu bottomMenu = new BottomMenu();
  102. bottomMenu.setMenuList(menuList);
  103. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  104. bottomMenu.show();
  105. return bottomMenu;
  106. }
  107. public static BottomMenu show(CharSequence title, CharSequence message, List<CharSequence> menuList) {
  108. BottomMenu bottomMenu = new BottomMenu();
  109. bottomMenu.title = title;
  110. bottomMenu.message = message;
  111. bottomMenu.setMenuList(menuList);
  112. bottomMenu.show();
  113. return bottomMenu;
  114. }
  115. public static BottomMenu show(CharSequence title, CharSequence message, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  116. BottomMenu bottomMenu = new BottomMenu();
  117. bottomMenu.title = title;
  118. bottomMenu.message = message;
  119. bottomMenu.setMenuList(menuList);
  120. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  121. bottomMenu.show();
  122. return bottomMenu;
  123. }
  124. public static BottomMenu show(CharSequence title, List<CharSequence> menuList) {
  125. BottomMenu bottomMenu = new BottomMenu();
  126. bottomMenu.title = title;
  127. bottomMenu.setMenuList(menuList);
  128. bottomMenu.show();
  129. return bottomMenu;
  130. }
  131. public static BottomMenu show(CharSequence title, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  132. BottomMenu bottomMenu = new BottomMenu();
  133. bottomMenu.title = title;
  134. bottomMenu.setMenuList(menuList);
  135. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  136. bottomMenu.show();
  137. return bottomMenu;
  138. }
  139. public static BottomMenu showStringList(CharSequence title, CharSequence message, List<String> menuList) {
  140. BottomMenu bottomMenu = new BottomMenu();
  141. bottomMenu.title = title;
  142. bottomMenu.message = message;
  143. bottomMenu.setMenuStringList(menuList);
  144. bottomMenu.show();
  145. return bottomMenu;
  146. }
  147. public static BottomMenu showStringList(CharSequence title, CharSequence message, List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  148. BottomMenu bottomMenu = new BottomMenu();
  149. bottomMenu.title = title;
  150. bottomMenu.message = message;
  151. bottomMenu.setMenuStringList(menuList);
  152. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  153. bottomMenu.show();
  154. return bottomMenu;
  155. }
  156. public static BottomMenu show(CharSequence title, CharSequence message, String[] menuList) {
  157. BottomMenu bottomMenu = new BottomMenu();
  158. bottomMenu.title = title;
  159. bottomMenu.message = message;
  160. bottomMenu.setMenuList(menuList);
  161. bottomMenu.show();
  162. return bottomMenu;
  163. }
  164. public static BottomMenu show(CharSequence title, CharSequence message, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  165. BottomMenu bottomMenu = new BottomMenu();
  166. bottomMenu.title = title;
  167. bottomMenu.message = message;
  168. bottomMenu.setMenuList(menuList);
  169. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  170. bottomMenu.show();
  171. return bottomMenu;
  172. }
  173. public static BottomMenu show(CharSequence title, CharSequence message, CharSequence[] menuList) {
  174. BottomMenu bottomMenu = new BottomMenu();
  175. bottomMenu.title = title;
  176. bottomMenu.message = message;
  177. bottomMenu.setMenuList(menuList);
  178. bottomMenu.show();
  179. return bottomMenu;
  180. }
  181. public static BottomMenu show(CharSequence title, CharSequence message, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  182. BottomMenu bottomMenu = new BottomMenu();
  183. bottomMenu.title = title;
  184. bottomMenu.message = message;
  185. bottomMenu.setMenuList(menuList);
  186. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  187. bottomMenu.show();
  188. return bottomMenu;
  189. }
  190. public static BottomMenu show(String title, String message, List<CharSequence> menuList) {
  191. BottomMenu bottomMenu = new BottomMenu();
  192. bottomMenu.title = title;
  193. bottomMenu.message = message;
  194. bottomMenu.setMenuList(menuList);
  195. bottomMenu.show();
  196. return bottomMenu;
  197. }
  198. public static BottomMenu show(String title, String message, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  199. BottomMenu bottomMenu = new BottomMenu();
  200. bottomMenu.title = title;
  201. bottomMenu.message = message;
  202. bottomMenu.setMenuList(menuList);
  203. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  204. bottomMenu.show();
  205. return bottomMenu;
  206. }
  207. public static BottomMenu showStringList(String title, String message, List<String> menuList) {
  208. BottomMenu bottomMenu = new BottomMenu();
  209. bottomMenu.title = title;
  210. bottomMenu.message = message;
  211. bottomMenu.setMenuStringList(menuList);
  212. bottomMenu.show();
  213. return bottomMenu;
  214. }
  215. public static BottomMenu showStringList(String title, String message, List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  216. BottomMenu bottomMenu = new BottomMenu();
  217. bottomMenu.title = title;
  218. bottomMenu.message = message;
  219. bottomMenu.setMenuStringList(menuList);
  220. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  221. bottomMenu.show();
  222. return bottomMenu;
  223. }
  224. public static BottomMenu show(String title, String message, String[] menuList) {
  225. BottomMenu bottomMenu = new BottomMenu();
  226. bottomMenu.title = title;
  227. bottomMenu.message = message;
  228. bottomMenu.setMenuList(menuList);
  229. bottomMenu.show();
  230. return bottomMenu;
  231. }
  232. public static BottomMenu show(String title, String message, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  233. BottomMenu bottomMenu = new BottomMenu();
  234. bottomMenu.title = title;
  235. bottomMenu.message = message;
  236. bottomMenu.setMenuList(menuList);
  237. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  238. bottomMenu.show();
  239. return bottomMenu;
  240. }
  241. public static BottomMenu show(String title, String message, CharSequence[] menuList) {
  242. BottomMenu bottomMenu = new BottomMenu();
  243. bottomMenu.title = title;
  244. bottomMenu.message = message;
  245. bottomMenu.setMenuList(menuList);
  246. bottomMenu.show();
  247. return bottomMenu;
  248. }
  249. public static BottomMenu show(String title, String message, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  250. BottomMenu bottomMenu = new BottomMenu();
  251. bottomMenu.title = title;
  252. bottomMenu.message = message;
  253. bottomMenu.setMenuList(menuList);
  254. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  255. bottomMenu.show();
  256. return bottomMenu;
  257. }
  258. public static BottomMenu show(int titleResId, int messageResId, List<CharSequence> menuList) {
  259. BottomMenu bottomMenu = new BottomMenu();
  260. bottomMenu.title = bottomMenu.getString(titleResId);
  261. bottomMenu.message = bottomMenu.getString(messageResId);
  262. bottomMenu.setMenuList(menuList);
  263. bottomMenu.show();
  264. return bottomMenu;
  265. }
  266. public static BottomMenu show(int titleResId, List<CharSequence> menuList) {
  267. BottomMenu bottomMenu = new BottomMenu();
  268. bottomMenu.title = bottomMenu.getString(titleResId);
  269. bottomMenu.setMenuList(menuList);
  270. bottomMenu.show();
  271. return bottomMenu;
  272. }
  273. public static BottomMenu showStringList(int titleResId, int messageResId, List<String> menuList) {
  274. BottomMenu bottomMenu = new BottomMenu();
  275. bottomMenu.title = bottomMenu.getString(titleResId);
  276. bottomMenu.message = bottomMenu.getString(messageResId);
  277. bottomMenu.setMenuStringList(menuList);
  278. bottomMenu.show();
  279. return bottomMenu;
  280. }
  281. public static BottomMenu show(int titleResId, int messageResId, String[] menuList) {
  282. BottomMenu bottomMenu = new BottomMenu();
  283. bottomMenu.title = bottomMenu.getString(titleResId);
  284. bottomMenu.message = bottomMenu.getString(messageResId);
  285. bottomMenu.setMenuList(menuList);
  286. bottomMenu.show();
  287. return bottomMenu;
  288. }
  289. public static BottomMenu show(int titleResId, int messageResId, CharSequence[] menuList) {
  290. BottomMenu bottomMenu = new BottomMenu();
  291. bottomMenu.title = bottomMenu.getString(titleResId);
  292. bottomMenu.message = bottomMenu.getString(messageResId);
  293. bottomMenu.setMenuList(menuList);
  294. bottomMenu.show();
  295. return bottomMenu;
  296. }
  297. public static BottomMenu show(int titleResId, int messageResId, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  298. BottomMenu bottomMenu = new BottomMenu();
  299. bottomMenu.title = bottomMenu.getString(titleResId);
  300. bottomMenu.message = bottomMenu.getString(messageResId);
  301. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  302. bottomMenu.setMenuList(menuList);
  303. bottomMenu.show();
  304. return bottomMenu;
  305. }
  306. public static BottomMenu show(int titleResId, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  307. BottomMenu bottomMenu = new BottomMenu();
  308. bottomMenu.title = bottomMenu.getString(titleResId);
  309. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  310. bottomMenu.setMenuList(menuList);
  311. bottomMenu.show();
  312. return bottomMenu;
  313. }
  314. public static BottomMenu showStringList(int titleResId, int messageResId, List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  315. BottomMenu bottomMenu = new BottomMenu();
  316. bottomMenu.title = bottomMenu.getString(titleResId);
  317. bottomMenu.message = bottomMenu.getString(messageResId);
  318. bottomMenu.setMenuStringList(menuList);
  319. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  320. bottomMenu.show();
  321. return bottomMenu;
  322. }
  323. public static BottomMenu show(int titleResId, int messageResId, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  324. BottomMenu bottomMenu = new BottomMenu();
  325. bottomMenu.title = bottomMenu.getString(titleResId);
  326. bottomMenu.message = bottomMenu.getString(messageResId);
  327. bottomMenu.setMenuList(menuList);
  328. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  329. bottomMenu.show();
  330. return bottomMenu;
  331. }
  332. public static BottomMenu show(int titleResId, int messageResId, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  333. BottomMenu bottomMenu = new BottomMenu();
  334. bottomMenu.title = bottomMenu.getString(titleResId);
  335. bottomMenu.message = bottomMenu.getString(messageResId);
  336. bottomMenu.setMenuList(menuList);
  337. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  338. bottomMenu.show();
  339. return bottomMenu;
  340. }
  341. public static BottomMenu show(CharSequence title, CharSequence[] menuList) {
  342. BottomMenu bottomMenu = new BottomMenu();
  343. bottomMenu.title = title;
  344. bottomMenu.setMenuList(menuList);
  345. bottomMenu.show();
  346. return bottomMenu;
  347. }
  348. public static BottomMenu show(CharSequence title, String[] menuList) {
  349. BottomMenu bottomMenu = new BottomMenu();
  350. bottomMenu.title = title;
  351. bottomMenu.setMenuList(menuList);
  352. bottomMenu.show();
  353. return bottomMenu;
  354. }
  355. public static BottomMenu show(CharSequence title, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  356. BottomMenu bottomMenu = new BottomMenu();
  357. bottomMenu.title = title;
  358. bottomMenu.setMenuList(menuList);
  359. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  360. bottomMenu.show();
  361. return bottomMenu;
  362. }
  363. public static BottomMenu show(CharSequence title, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  364. BottomMenu bottomMenu = new BottomMenu();
  365. bottomMenu.title = title;
  366. bottomMenu.setMenuList(menuList);
  367. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  368. bottomMenu.show();
  369. return bottomMenu;
  370. }
  371. public static BottomMenu show(int titleResId, CharSequence[] menuList) {
  372. BottomMenu bottomMenu = new BottomMenu();
  373. bottomMenu.title = bottomMenu.getString(titleResId);
  374. bottomMenu.setMenuList(menuList);
  375. bottomMenu.show();
  376. return bottomMenu;
  377. }
  378. public static BottomMenu show(int titleResId, String[] menuList) {
  379. BottomMenu bottomMenu = new BottomMenu();
  380. bottomMenu.title = bottomMenu.getString(titleResId);
  381. bottomMenu.setMenuList(menuList);
  382. bottomMenu.show();
  383. return bottomMenu;
  384. }
  385. public static BottomMenu show(int titleResId, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  386. BottomMenu bottomMenu = new BottomMenu();
  387. bottomMenu.title = bottomMenu.getString(titleResId);
  388. bottomMenu.setMenuList(menuList);
  389. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  390. bottomMenu.show();
  391. return bottomMenu;
  392. }
  393. public static BottomMenu show(int titleResId, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  394. BottomMenu bottomMenu = new BottomMenu();
  395. bottomMenu.title = bottomMenu.getString(titleResId);
  396. bottomMenu.setMenuList(menuList);
  397. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  398. bottomMenu.show();
  399. return bottomMenu;
  400. }
  401. private float touchDownY;
  402. public static final int DELAY = 500;
  403. private long lastClickTime = 0;
  404. @Override
  405. protected void onDialogInit(final DialogImpl dialog) {
  406. if (dialog != null) {
  407. dialog.boxList.setVisibility(View.VISIBLE);
  408. if (!isAllowInterceptTouch()) {
  409. dialog.bkg.setMaxHeight((int) bottomDialogMaxHeight);
  410. if (bottomDialogMaxHeight != 0) {
  411. dialogImpl.scrollView.setEnabled(false);
  412. }
  413. }
  414. int dividerDrawableResId = 0;
  415. int dividerHeight = 1;
  416. if (style.overrideBottomDialogRes() != null) {
  417. dividerDrawableResId = style.overrideBottomDialogRes().overrideMenuDividerDrawableRes(isLightTheme());
  418. dividerHeight = style.overrideBottomDialogRes().overrideMenuDividerHeight(isLightTheme());
  419. }
  420. if (dividerDrawableResId == 0) {
  421. dividerDrawableResId = isLightTheme() ? R.drawable.rect_dialogx_material_menu_split_divider : R.drawable.rect_dialogx_material_menu_split_divider_night;
  422. }
  423. listView = new BottomDialogListView(dialog, getContext());
  424. listView.setOverScrollMode(OVER_SCROLL_NEVER);
  425. listView.setDivider(getResources().getDrawable(dividerDrawableResId));
  426. listView.setDividerHeight(dividerHeight);
  427. listView.setBottomMenuListViewTouchEvent(new BottomMenuListViewTouchEvent() {
  428. @Override
  429. public void down(MotionEvent event) {
  430. touchDownY = dialog.bkg.getY();
  431. }
  432. });
  433. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  434. @Override
  435. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  436. long currentTime = System.currentTimeMillis();
  437. if (currentTime - lastClickTime > DELAY) {
  438. lastClickTime = currentTime;
  439. float deltaY = Math.abs(touchDownY - dialog.bkg.getY());
  440. if (deltaY > dip2px(15)) {
  441. return;
  442. }
  443. if (onMenuItemClickListener != null) {
  444. if (!onMenuItemClickListener.onClick(me, menuList.get(position), position)) {
  445. dismiss();
  446. }
  447. } else {
  448. dismiss();
  449. }
  450. }
  451. }
  452. });
  453. if (style.overrideBottomDialogRes() != null) {
  454. if (style.overrideBottomDialogRes().overrideMenuItemLayout(true, 0, 0, false) != 0) {
  455. listView.setSelector(R.color.empty);
  456. }
  457. }
  458. RelativeLayout.LayoutParams listViewLp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  459. dialog.boxList.addView(listView, listViewLp);
  460. refreshUI();
  461. }
  462. }
  463. @Override
  464. public void refreshUI() {
  465. super.refreshUI();
  466. if (listView != null) {
  467. if (menuListAdapter == null) {
  468. menuListAdapter = new NormalMenuArrayAdapter(me, getContext(), menuList);
  469. }
  470. if (listView.getAdapter() == null) {
  471. listView.setAdapter(menuListAdapter);
  472. } else {
  473. if (listView.getAdapter() != menuListAdapter) {
  474. listView.setAdapter(menuListAdapter);
  475. } else {
  476. menuListAdapter.notifyDataSetChanged();
  477. }
  478. }
  479. }
  480. }
  481. @Override
  482. public String dialogKey() {
  483. return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
  484. }
  485. public List<CharSequence> getMenuList() {
  486. return menuList;
  487. }
  488. public BottomMenu setMenuList(List<CharSequence> menuList) {
  489. this.menuList = menuList;
  490. refreshUI();
  491. return this;
  492. }
  493. public BottomMenu setMenuStringList(List<String> menuList) {
  494. this.menuList = new ArrayList<>();
  495. this.menuList.addAll(menuList);
  496. refreshUI();
  497. return this;
  498. }
  499. public BottomMenu setMenuList(String[] menuList) {
  500. this.menuList = new ArrayList<>();
  501. this.menuList.addAll(Arrays.asList(menuList));
  502. refreshUI();
  503. return this;
  504. }
  505. public BottomMenu setMenuList(CharSequence[] menuList) {
  506. this.menuList = Arrays.asList(menuList);
  507. refreshUI();
  508. return this;
  509. }
  510. public OnIconChangeCallBack getOnIconChangeCallBack() {
  511. return onIconChangeCallBack;
  512. }
  513. public BottomMenu setOnIconChangeCallBack(OnIconChangeCallBack onIconChangeCallBack) {
  514. this.onIconChangeCallBack = onIconChangeCallBack;
  515. return this;
  516. }
  517. public OnBackPressedListener getOnBackPressedListener() {
  518. return onBackPressedListener;
  519. }
  520. public BottomMenu setOnBackPressedListener(OnBackPressedListener onBackPressedListener) {
  521. this.onBackPressedListener = onBackPressedListener;
  522. refreshUI();
  523. return this;
  524. }
  525. public BottomMenu setDialogLifecycleCallback(DialogLifecycleCallback<BottomDialog> dialogLifecycleCallback) {
  526. this.dialogLifecycleCallback = dialogLifecycleCallback;
  527. return this;
  528. }
  529. public BottomMenu setStyle(DialogXStyle style) {
  530. this.style = style;
  531. return this;
  532. }
  533. public BottomMenu setTheme(DialogX.THEME theme) {
  534. this.theme = theme;
  535. return this;
  536. }
  537. public boolean isCancelable() {
  538. if (privateCancelable != null) {
  539. return privateCancelable == BOOLEAN.TRUE;
  540. }
  541. if (overrideCancelable != null) {
  542. return overrideCancelable == BOOLEAN.TRUE;
  543. }
  544. return cancelable;
  545. }
  546. public BottomMenu setCancelable(boolean cancelable) {
  547. this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
  548. refreshUI();
  549. return this;
  550. }
  551. public DialogImpl getDialogImpl() {
  552. return dialogImpl;
  553. }
  554. public CharSequence getTitle() {
  555. return title;
  556. }
  557. public BottomMenu setTitle(CharSequence title) {
  558. this.title = title;
  559. refreshUI();
  560. return this;
  561. }
  562. public BottomMenu setTitle(int titleResId) {
  563. this.title = getString(titleResId);
  564. refreshUI();
  565. return this;
  566. }
  567. public CharSequence getMessage() {
  568. return message;
  569. }
  570. public BottomMenu setMessage(CharSequence message) {
  571. this.message = message;
  572. refreshUI();
  573. return this;
  574. }
  575. public BottomMenu setMessage(int messageResId) {
  576. this.message = getString(messageResId);
  577. refreshUI();
  578. return this;
  579. }
  580. public CharSequence getCancelButton() {
  581. return cancelText;
  582. }
  583. public BottomMenu setCancelButton(CharSequence cancelText) {
  584. this.cancelText = cancelText;
  585. refreshUI();
  586. return this;
  587. }
  588. public BottomMenu setCancelButton(int cancelTextResId) {
  589. this.cancelText = getString(cancelTextResId);
  590. refreshUI();
  591. return this;
  592. }
  593. public BottomMenu setCancelButton(OnDialogButtonClickListener cancelButtonClickListener) {
  594. this.cancelButtonClickListener = cancelButtonClickListener;
  595. return this;
  596. }
  597. public BottomMenu setCancelButton(CharSequence cancelText, OnDialogButtonClickListener cancelButtonClickListener) {
  598. this.cancelText = cancelText;
  599. this.cancelButtonClickListener = cancelButtonClickListener;
  600. refreshUI();
  601. return this;
  602. }
  603. public BottomMenu setCancelButton(int cancelTextResId, OnDialogButtonClickListener cancelButtonClickListener) {
  604. this.cancelText = getString(cancelTextResId);
  605. this.cancelButtonClickListener = cancelButtonClickListener;
  606. refreshUI();
  607. return this;
  608. }
  609. public BottomMenu setCustomView(OnBindView<BottomDialog> onBindView) {
  610. this.onBindView = onBindView;
  611. refreshUI();
  612. return this;
  613. }
  614. public View getCustomView() {
  615. if (onBindView == null) return null;
  616. return onBindView.getCustomView();
  617. }
  618. public BottomMenu removeCustomView() {
  619. this.onBindView.clean();
  620. refreshUI();
  621. return this;
  622. }
  623. public boolean isAllowInterceptTouch() {
  624. return super.isAllowInterceptTouch();
  625. }
  626. public BottomMenu setAllowInterceptTouch(boolean allowInterceptTouch) {
  627. this.allowInterceptTouch = allowInterceptTouch;
  628. refreshUI();
  629. return this;
  630. }
  631. public float getBottomDialogMaxHeight() {
  632. return bottomDialogMaxHeight;
  633. }
  634. public BottomMenu setBottomDialogMaxHeight(float bottomDialogMaxHeight) {
  635. this.bottomDialogMaxHeight = bottomDialogMaxHeight;
  636. return this;
  637. }
  638. public OnMenuItemClickListener<BottomMenu> getOnMenuItemClickListener() {
  639. return onMenuItemClickListener;
  640. }
  641. public BottomMenu setOnMenuItemClickListener(OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  642. this.onMenuItemClickListener = onMenuItemClickListener;
  643. return this;
  644. }
  645. public BaseAdapter getMenuListAdapter() {
  646. return menuListAdapter;
  647. }
  648. public BottomMenu setMenuListAdapter(BaseAdapter menuListAdapter) {
  649. this.menuListAdapter = menuListAdapter;
  650. return this;
  651. }
  652. public OnDialogButtonClickListener getCancelButtonClickListener() {
  653. return cancelButtonClickListener;
  654. }
  655. public BottomMenu setCancelButtonClickListener(OnDialogButtonClickListener cancelButtonClickListener) {
  656. this.cancelButtonClickListener = cancelButtonClickListener;
  657. return this;
  658. }
  659. public TextInfo getTitleTextInfo() {
  660. return titleTextInfo;
  661. }
  662. public BottomMenu setTitleTextInfo(TextInfo titleTextInfo) {
  663. this.titleTextInfo = titleTextInfo;
  664. refreshUI();
  665. return this;
  666. }
  667. public TextInfo getMessageTextInfo() {
  668. return messageTextInfo;
  669. }
  670. public BottomMenu setMessageTextInfo(TextInfo messageTextInfo) {
  671. this.messageTextInfo = messageTextInfo;
  672. refreshUI();
  673. return this;
  674. }
  675. public TextInfo getCancelTextInfo() {
  676. return cancelTextInfo;
  677. }
  678. public BottomMenu setCancelTextInfo(TextInfo cancelTextInfo) {
  679. this.cancelTextInfo = cancelTextInfo;
  680. refreshUI();
  681. return this;
  682. }
  683. public int getBackgroundColor() {
  684. return backgroundColor;
  685. }
  686. public BottomMenu setBackgroundColor(@ColorInt int backgroundColor) {
  687. this.backgroundColor = backgroundColor;
  688. refreshUI();
  689. return this;
  690. }
  691. public int getSelection() {
  692. return selectionIndex;
  693. }
  694. public BottomMenu setSelection(int selectionIndex) {
  695. this.selectionIndex = selectionIndex;
  696. menuListAdapter = null;
  697. refreshUI();
  698. return this;
  699. }
  700. public BottomMenu setBackgroundColorRes(@ColorRes int backgroundRes) {
  701. this.backgroundColor = getColor(backgroundRes);
  702. refreshUI();
  703. return this;
  704. }
  705. public CharSequence getOkButton() {
  706. return okText;
  707. }
  708. public BottomMenu setOkButton(CharSequence okText) {
  709. this.okText = okText;
  710. refreshUI();
  711. return this;
  712. }
  713. public BottomMenu setOkButton(int OkTextResId) {
  714. this.okText = getString(OkTextResId);
  715. refreshUI();
  716. return this;
  717. }
  718. public BottomMenu setOkButton(OnDialogButtonClickListener<BottomDialog> OkButtonClickListener) {
  719. this.okButtonClickListener = OkButtonClickListener;
  720. return this;
  721. }
  722. public BottomMenu setOkButton(CharSequence OkText, OnDialogButtonClickListener<BottomDialog> OkButtonClickListener) {
  723. this.okText = OkText;
  724. this.okButtonClickListener = OkButtonClickListener;
  725. return this;
  726. }
  727. public BottomMenu setOkButton(int OkTextResId, OnDialogButtonClickListener<BottomDialog> OkButtonClickListener) {
  728. this.okText = getString(OkTextResId);
  729. this.okButtonClickListener = OkButtonClickListener;
  730. return this;
  731. }
  732. public CharSequence getOtherButton() {
  733. return otherText;
  734. }
  735. public BottomMenu setOtherButton(CharSequence otherText) {
  736. this.otherText = otherText;
  737. refreshUI();
  738. return this;
  739. }
  740. public BottomMenu setOtherButton(int OtherTextResId) {
  741. this.otherText = getString(OtherTextResId);
  742. refreshUI();
  743. return this;
  744. }
  745. public BottomMenu setOtherButton(OnDialogButtonClickListener<BottomDialog> OtherButtonClickListener) {
  746. this.otherButtonClickListener = OtherButtonClickListener;
  747. return this;
  748. }
  749. public BottomMenu setOtherButton(CharSequence OtherText, OnDialogButtonClickListener<BottomDialog> OtherButtonClickListener) {
  750. this.otherText = OtherText;
  751. this.otherButtonClickListener = OtherButtonClickListener;
  752. return this;
  753. }
  754. public BottomMenu setOtherButton(int OtherTextResId, OnDialogButtonClickListener<BottomDialog> OtherButtonClickListener) {
  755. this.otherText = getString(OtherTextResId);
  756. this.otherButtonClickListener = OtherButtonClickListener;
  757. return this;
  758. }
  759. public BottomMenu setMaskColor(@ColorInt int maskColor) {
  760. this.maskColor = maskColor;
  761. refreshUI();
  762. return this;
  763. }
  764. public long getEnterAnimDuration() {
  765. return enterAnimDuration;
  766. }
  767. public BottomMenu setEnterAnimDuration(long enterAnimDuration) {
  768. this.enterAnimDuration = enterAnimDuration;
  769. return this;
  770. }
  771. public long getExitAnimDuration() {
  772. return exitAnimDuration;
  773. }
  774. public BottomMenu setExitAnimDuration(long exitAnimDuration) {
  775. this.exitAnimDuration = exitAnimDuration;
  776. return this;
  777. }
  778. }