BottomMenu.java 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459
  1. package com.kongzue.dialogx.dialogs;
  2. import static android.view.View.OVER_SCROLL_NEVER;
  3. import android.graphics.Bitmap;
  4. import android.graphics.drawable.BitmapDrawable;
  5. import android.graphics.drawable.Drawable;
  6. import android.text.TextUtils;
  7. import android.view.MotionEvent;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.AdapterView;
  11. import android.widget.BaseAdapter;
  12. import androidx.annotation.ColorInt;
  13. import androidx.annotation.ColorRes;
  14. import com.kongzue.dialogx.DialogX;
  15. import com.kongzue.dialogx.R;
  16. import com.kongzue.dialogx.interfaces.BottomMenuListViewTouchEvent;
  17. import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
  18. import com.kongzue.dialogx.interfaces.DialogXAnimInterface;
  19. import com.kongzue.dialogx.interfaces.DialogXRunnable;
  20. import com.kongzue.dialogx.interfaces.DialogXStyle;
  21. import com.kongzue.dialogx.interfaces.MenuItemLayoutRefreshCallback;
  22. import com.kongzue.dialogx.interfaces.MenuItemTextInfoInterceptor;
  23. import com.kongzue.dialogx.interfaces.OnBackPressedListener;
  24. import com.kongzue.dialogx.interfaces.OnBackgroundMaskClickListener;
  25. import com.kongzue.dialogx.interfaces.OnBindView;
  26. import com.kongzue.dialogx.interfaces.OnBottomMenuButtonClickListener;
  27. import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
  28. import com.kongzue.dialogx.interfaces.OnIconChangeCallBack;
  29. import com.kongzue.dialogx.interfaces.OnMenuItemClickListener;
  30. import com.kongzue.dialogx.interfaces.OnMenuItemSelectListener;
  31. import com.kongzue.dialogx.util.BottomMenuArrayAdapter;
  32. import com.kongzue.dialogx.util.TextInfo;
  33. import com.kongzue.dialogx.util.views.BottomDialogListView;
  34. import java.util.ArrayList;
  35. import java.util.Arrays;
  36. import java.util.HashMap;
  37. import java.util.List;
  38. /**
  39. * @author: Kongzue
  40. * @github: https://github.com/kongzue/
  41. * @homepage: http://kongzue.com/
  42. * @mail: myzcxhh@live.cn
  43. * @createTime: 2020/10/6 23:48
  44. */
  45. public class BottomMenu extends BottomDialog {
  46. public enum SELECT_MODE {
  47. NONE,
  48. SINGLE,
  49. MULTIPLE
  50. }
  51. protected BottomMenu me = this;
  52. protected int selectionIndex = -1;
  53. protected SELECT_MODE selectMode = SELECT_MODE.NONE;
  54. protected ArrayList<Integer> selectionItems;
  55. protected boolean showSelectedBackgroundTips = false;
  56. protected MenuItemLayoutRefreshCallback<BottomMenu> menuMenuItemLayoutRefreshCallback;
  57. protected OnMenuItemClickListener<BottomMenu> onMenuItemClickListener;
  58. public static BottomMenu build() {
  59. return new BottomMenu();
  60. }
  61. public static BottomMenu build(DialogXStyle style) {
  62. return new BottomMenu().setStyle(style);
  63. }
  64. public static BottomMenu build(OnBindView<BottomDialog> onBindView) {
  65. return new BottomMenu().setCustomView(onBindView);
  66. }
  67. protected BottomMenu() {
  68. super();
  69. }
  70. protected OnIconChangeCallBack<BottomMenu> onIconChangeCallBack;
  71. protected MenuItemTextInfoInterceptor<BottomMenu> menuItemTextInfoInterceptor;
  72. protected BottomDialogListView listView;
  73. protected BaseAdapter menuListAdapter;
  74. protected List<CharSequence> menuList;
  75. protected List<Integer> iconResIds;
  76. protected boolean autoTintIconInLightOrDarkMode = true;
  77. public static BottomMenu show(List<CharSequence> menuList) {
  78. BottomMenu bottomMenu = new BottomMenu();
  79. bottomMenu.setMenuList(menuList);
  80. bottomMenu.show();
  81. return bottomMenu;
  82. }
  83. public static BottomMenu show(List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  84. BottomMenu bottomMenu = new BottomMenu();
  85. bottomMenu.setMenuList(menuList);
  86. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  87. bottomMenu.show();
  88. return bottomMenu;
  89. }
  90. public static BottomMenu showStringList(List<String> menuList) {
  91. BottomMenu bottomMenu = new BottomMenu();
  92. bottomMenu.setMenuStringList(menuList);
  93. bottomMenu.show();
  94. return bottomMenu;
  95. }
  96. public static BottomMenu showStringList(List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  97. BottomMenu bottomMenu = new BottomMenu();
  98. bottomMenu.setMenuStringList(menuList);
  99. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  100. bottomMenu.show();
  101. return bottomMenu;
  102. }
  103. public static BottomMenu show(String... menuList) {
  104. BottomMenu bottomMenu = new BottomMenu();
  105. bottomMenu.setMenuList(menuList);
  106. bottomMenu.show();
  107. return bottomMenu;
  108. }
  109. public static BottomMenu show(String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  110. BottomMenu bottomMenu = new BottomMenu();
  111. bottomMenu.setMenuList(menuList);
  112. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  113. bottomMenu.show();
  114. return bottomMenu;
  115. }
  116. public static BottomMenu show(CharSequence[] menuList) {
  117. BottomMenu bottomMenu = new BottomMenu();
  118. bottomMenu.setMenuList(menuList);
  119. bottomMenu.show();
  120. return bottomMenu;
  121. }
  122. public static BottomMenu show(CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  123. BottomMenu bottomMenu = new BottomMenu();
  124. bottomMenu.setMenuList(menuList);
  125. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  126. bottomMenu.show();
  127. return bottomMenu;
  128. }
  129. public static BottomMenu show(CharSequence title, CharSequence message, List<CharSequence> menuList) {
  130. BottomMenu bottomMenu = new BottomMenu();
  131. bottomMenu.title = title;
  132. bottomMenu.message = message;
  133. bottomMenu.setMenuList(menuList);
  134. bottomMenu.show();
  135. return bottomMenu;
  136. }
  137. public static BottomMenu show(CharSequence title, CharSequence message, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  138. BottomMenu bottomMenu = new BottomMenu();
  139. bottomMenu.title = title;
  140. bottomMenu.message = message;
  141. bottomMenu.setMenuList(menuList);
  142. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  143. bottomMenu.show();
  144. return bottomMenu;
  145. }
  146. public static BottomMenu show(CharSequence title, List<CharSequence> menuList) {
  147. BottomMenu bottomMenu = new BottomMenu();
  148. bottomMenu.title = title;
  149. bottomMenu.setMenuList(menuList);
  150. bottomMenu.show();
  151. return bottomMenu;
  152. }
  153. public static BottomMenu show(CharSequence title, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  154. BottomMenu bottomMenu = new BottomMenu();
  155. bottomMenu.title = title;
  156. bottomMenu.setMenuList(menuList);
  157. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  158. bottomMenu.show();
  159. return bottomMenu;
  160. }
  161. public static BottomMenu showStringList(CharSequence title, CharSequence message, List<String> menuList) {
  162. BottomMenu bottomMenu = new BottomMenu();
  163. bottomMenu.title = title;
  164. bottomMenu.message = message;
  165. bottomMenu.setMenuStringList(menuList);
  166. bottomMenu.show();
  167. return bottomMenu;
  168. }
  169. public static BottomMenu showStringList(CharSequence title, CharSequence message, List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  170. BottomMenu bottomMenu = new BottomMenu();
  171. bottomMenu.title = title;
  172. bottomMenu.message = message;
  173. bottomMenu.setMenuStringList(menuList);
  174. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  175. bottomMenu.show();
  176. return bottomMenu;
  177. }
  178. public static BottomMenu show(CharSequence title, CharSequence message, String[] menuList) {
  179. BottomMenu bottomMenu = new BottomMenu();
  180. bottomMenu.title = title;
  181. bottomMenu.message = message;
  182. bottomMenu.setMenuList(menuList);
  183. bottomMenu.show();
  184. return bottomMenu;
  185. }
  186. public static BottomMenu show(CharSequence title, CharSequence message, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  187. BottomMenu bottomMenu = new BottomMenu();
  188. bottomMenu.title = title;
  189. bottomMenu.message = message;
  190. bottomMenu.setMenuList(menuList);
  191. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  192. bottomMenu.show();
  193. return bottomMenu;
  194. }
  195. public static BottomMenu show(CharSequence title, CharSequence message, CharSequence[] menuList) {
  196. BottomMenu bottomMenu = new BottomMenu();
  197. bottomMenu.title = title;
  198. bottomMenu.message = message;
  199. bottomMenu.setMenuList(menuList);
  200. bottomMenu.show();
  201. return bottomMenu;
  202. }
  203. public static BottomMenu show(CharSequence title, CharSequence message, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  204. BottomMenu bottomMenu = new BottomMenu();
  205. bottomMenu.title = title;
  206. bottomMenu.message = message;
  207. bottomMenu.setMenuList(menuList);
  208. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  209. bottomMenu.show();
  210. return bottomMenu;
  211. }
  212. public static BottomMenu show(String title, String message, List<CharSequence> menuList) {
  213. BottomMenu bottomMenu = new BottomMenu();
  214. bottomMenu.title = title;
  215. bottomMenu.message = message;
  216. bottomMenu.setMenuList(menuList);
  217. bottomMenu.show();
  218. return bottomMenu;
  219. }
  220. public static BottomMenu show(String title, String message, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  221. BottomMenu bottomMenu = new BottomMenu();
  222. bottomMenu.title = title;
  223. bottomMenu.message = message;
  224. bottomMenu.setMenuList(menuList);
  225. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  226. bottomMenu.show();
  227. return bottomMenu;
  228. }
  229. public static BottomMenu showStringList(String title, String message, List<String> menuList) {
  230. BottomMenu bottomMenu = new BottomMenu();
  231. bottomMenu.title = title;
  232. bottomMenu.message = message;
  233. bottomMenu.setMenuStringList(menuList);
  234. bottomMenu.show();
  235. return bottomMenu;
  236. }
  237. public static BottomMenu showStringList(String title, String message, List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  238. BottomMenu bottomMenu = new BottomMenu();
  239. bottomMenu.title = title;
  240. bottomMenu.message = message;
  241. bottomMenu.setMenuStringList(menuList);
  242. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  243. bottomMenu.show();
  244. return bottomMenu;
  245. }
  246. public static BottomMenu show(String title, String message, String[] menuList) {
  247. BottomMenu bottomMenu = new BottomMenu();
  248. bottomMenu.title = title;
  249. bottomMenu.message = message;
  250. bottomMenu.setMenuList(menuList);
  251. bottomMenu.show();
  252. return bottomMenu;
  253. }
  254. public static BottomMenu show(String title, String message, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  255. BottomMenu bottomMenu = new BottomMenu();
  256. bottomMenu.title = title;
  257. bottomMenu.message = message;
  258. bottomMenu.setMenuList(menuList);
  259. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  260. bottomMenu.show();
  261. return bottomMenu;
  262. }
  263. public static BottomMenu show(String title, String message, CharSequence[] menuList) {
  264. BottomMenu bottomMenu = new BottomMenu();
  265. bottomMenu.title = title;
  266. bottomMenu.message = message;
  267. bottomMenu.setMenuList(menuList);
  268. bottomMenu.show();
  269. return bottomMenu;
  270. }
  271. public static BottomMenu show(String title, String message, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  272. BottomMenu bottomMenu = new BottomMenu();
  273. bottomMenu.title = title;
  274. bottomMenu.message = message;
  275. bottomMenu.setMenuList(menuList);
  276. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  277. bottomMenu.show();
  278. return bottomMenu;
  279. }
  280. public static BottomMenu show(int titleResId, int messageResId, List<CharSequence> menuList) {
  281. BottomMenu bottomMenu = new BottomMenu();
  282. bottomMenu.title = bottomMenu.getString(titleResId);
  283. bottomMenu.message = bottomMenu.getString(messageResId);
  284. bottomMenu.setMenuList(menuList);
  285. bottomMenu.show();
  286. return bottomMenu;
  287. }
  288. public static BottomMenu show(int titleResId, List<CharSequence> menuList) {
  289. BottomMenu bottomMenu = new BottomMenu();
  290. bottomMenu.title = bottomMenu.getString(titleResId);
  291. bottomMenu.setMenuList(menuList);
  292. bottomMenu.show();
  293. return bottomMenu;
  294. }
  295. public static BottomMenu showStringList(int titleResId, int messageResId, List<String> menuList) {
  296. BottomMenu bottomMenu = new BottomMenu();
  297. bottomMenu.title = bottomMenu.getString(titleResId);
  298. bottomMenu.message = bottomMenu.getString(messageResId);
  299. bottomMenu.setMenuStringList(menuList);
  300. bottomMenu.show();
  301. return bottomMenu;
  302. }
  303. public static BottomMenu show(int titleResId, int messageResId, String[] menuList) {
  304. BottomMenu bottomMenu = new BottomMenu();
  305. bottomMenu.title = bottomMenu.getString(titleResId);
  306. bottomMenu.message = bottomMenu.getString(messageResId);
  307. bottomMenu.setMenuList(menuList);
  308. bottomMenu.show();
  309. return bottomMenu;
  310. }
  311. public static BottomMenu show(int titleResId, int messageResId, CharSequence[] menuList) {
  312. BottomMenu bottomMenu = new BottomMenu();
  313. bottomMenu.title = bottomMenu.getString(titleResId);
  314. bottomMenu.message = bottomMenu.getString(messageResId);
  315. bottomMenu.setMenuList(menuList);
  316. bottomMenu.show();
  317. return bottomMenu;
  318. }
  319. public static BottomMenu show(int titleResId, int messageResId, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  320. BottomMenu bottomMenu = new BottomMenu();
  321. bottomMenu.title = bottomMenu.getString(titleResId);
  322. bottomMenu.message = bottomMenu.getString(messageResId);
  323. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  324. bottomMenu.setMenuList(menuList);
  325. bottomMenu.show();
  326. return bottomMenu;
  327. }
  328. public static BottomMenu show(int titleResId, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  329. BottomMenu bottomMenu = new BottomMenu();
  330. bottomMenu.title = bottomMenu.getString(titleResId);
  331. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  332. bottomMenu.setMenuList(menuList);
  333. bottomMenu.show();
  334. return bottomMenu;
  335. }
  336. public static BottomMenu showStringList(int titleResId, int messageResId, List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  337. BottomMenu bottomMenu = new BottomMenu();
  338. bottomMenu.title = bottomMenu.getString(titleResId);
  339. bottomMenu.message = bottomMenu.getString(messageResId);
  340. bottomMenu.setMenuStringList(menuList);
  341. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  342. bottomMenu.show();
  343. return bottomMenu;
  344. }
  345. public static BottomMenu show(int titleResId, int messageResId, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  346. BottomMenu bottomMenu = new BottomMenu();
  347. bottomMenu.title = bottomMenu.getString(titleResId);
  348. bottomMenu.message = bottomMenu.getString(messageResId);
  349. bottomMenu.setMenuList(menuList);
  350. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  351. bottomMenu.show();
  352. return bottomMenu;
  353. }
  354. public static BottomMenu show(int titleResId, int messageResId, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  355. BottomMenu bottomMenu = new BottomMenu();
  356. bottomMenu.title = bottomMenu.getString(titleResId);
  357. bottomMenu.message = bottomMenu.getString(messageResId);
  358. bottomMenu.setMenuList(menuList);
  359. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  360. bottomMenu.show();
  361. return bottomMenu;
  362. }
  363. public static BottomMenu show(CharSequence title, CharSequence[] menuList) {
  364. BottomMenu bottomMenu = new BottomMenu();
  365. bottomMenu.title = title;
  366. bottomMenu.setMenuList(menuList);
  367. bottomMenu.show();
  368. return bottomMenu;
  369. }
  370. public static BottomMenu show(CharSequence title, String[] menuList) {
  371. BottomMenu bottomMenu = new BottomMenu();
  372. bottomMenu.title = title;
  373. bottomMenu.setMenuList(menuList);
  374. bottomMenu.show();
  375. return bottomMenu;
  376. }
  377. public static BottomMenu show(CharSequence title, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  378. BottomMenu bottomMenu = new BottomMenu();
  379. bottomMenu.title = title;
  380. bottomMenu.setMenuList(menuList);
  381. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  382. bottomMenu.show();
  383. return bottomMenu;
  384. }
  385. public static BottomMenu show(CharSequence title, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  386. BottomMenu bottomMenu = new BottomMenu();
  387. bottomMenu.title = title;
  388. bottomMenu.setMenuList(menuList);
  389. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  390. bottomMenu.show();
  391. return bottomMenu;
  392. }
  393. public static BottomMenu show(int titleResId, CharSequence[] menuList) {
  394. BottomMenu bottomMenu = new BottomMenu();
  395. bottomMenu.title = bottomMenu.getString(titleResId);
  396. bottomMenu.setMenuList(menuList);
  397. bottomMenu.show();
  398. return bottomMenu;
  399. }
  400. public static BottomMenu show(int titleResId, String[] menuList) {
  401. BottomMenu bottomMenu = new BottomMenu();
  402. bottomMenu.title = bottomMenu.getString(titleResId);
  403. bottomMenu.setMenuList(menuList);
  404. bottomMenu.show();
  405. return bottomMenu;
  406. }
  407. public static BottomMenu show(int titleResId, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  408. BottomMenu bottomMenu = new BottomMenu();
  409. bottomMenu.title = bottomMenu.getString(titleResId);
  410. bottomMenu.setMenuList(menuList);
  411. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  412. bottomMenu.show();
  413. return bottomMenu;
  414. }
  415. public static BottomMenu show(int titleResId, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  416. BottomMenu bottomMenu = new BottomMenu();
  417. bottomMenu.title = bottomMenu.getString(titleResId);
  418. bottomMenu.setMenuList(menuList);
  419. bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
  420. bottomMenu.show();
  421. return bottomMenu;
  422. }
  423. private float touchDownY;
  424. public static final int ITEM_CLICK_DELAY = 100;
  425. private long lastClickTime = 0;
  426. private int[] resultArray;
  427. private CharSequence[] selectTextArray;
  428. @Override
  429. protected void onDialogShow() {
  430. if (getDialogImpl() != null) {
  431. getDialogImpl().boxList.setVisibility(View.VISIBLE);
  432. if (!isAllowInterceptTouch()) {
  433. getDialogImpl().bkg.setMaxHeight((int) bottomDialogMaxHeight);
  434. if (bottomDialogMaxHeight != 0) {
  435. dialogImpl.scrollView.lockScroll(true);
  436. }
  437. }
  438. int dividerDrawableResId = 0;
  439. int dividerHeight = 1;
  440. if (style.overrideBottomDialogRes() != null) {
  441. dividerDrawableResId = style.overrideBottomDialogRes().overrideMenuDividerDrawableRes(isLightTheme());
  442. dividerHeight = style.overrideBottomDialogRes().overrideMenuDividerHeight(isLightTheme());
  443. }
  444. if (dividerDrawableResId == 0) {
  445. dividerDrawableResId = isLightTheme() ? R.drawable.rect_dialogx_material_menu_split_divider : R.drawable.rect_dialogx_material_menu_split_divider_night;
  446. }
  447. if (!isLightTheme()) {
  448. listView = new BottomDialogListView(getDialogImpl(), getOwnActivity(), R.style.DialogXCompatThemeDark);
  449. } else {
  450. listView = new BottomDialogListView(getDialogImpl(), getOwnActivity());
  451. }
  452. listView.setOverScrollMode(OVER_SCROLL_NEVER);
  453. listView.setDivider(getResources().getDrawable(dividerDrawableResId));
  454. listView.setDividerHeight(dividerHeight);
  455. listView.setBottomMenuListViewTouchEvent(new BottomMenuListViewTouchEvent() {
  456. @Override
  457. public void down(MotionEvent event) {
  458. touchDownY = getDialogImpl().bkg.getY();
  459. }
  460. });
  461. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  462. @Override
  463. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  464. haptic(view);
  465. long currentTime = System.currentTimeMillis();
  466. if (currentTime - lastClickTime > ITEM_CLICK_DELAY) {
  467. lastClickTime = currentTime;
  468. float deltaY = Math.abs(touchDownY - getDialogImpl().bkg.getY());
  469. if (deltaY > dip2px(15)) {
  470. return;
  471. }
  472. selectionIndex = position;
  473. switch (selectMode) {
  474. case NONE:
  475. if (onMenuItemClickListener != null) {
  476. if (!onMenuItemClickListener.onClick(me, menuList.get(position), position)) {
  477. dismiss();
  478. }
  479. } else {
  480. dismiss();
  481. }
  482. break;
  483. case SINGLE:
  484. if (onMenuItemClickListener instanceof OnMenuItemSelectListener) {
  485. OnMenuItemSelectListener<BottomMenu> onMenuItemSelectListener = (OnMenuItemSelectListener<BottomMenu>) onMenuItemClickListener;
  486. if (!onMenuItemSelectListener.onClick(me, menuList.get(position), position)) {
  487. dismiss();
  488. } else {
  489. menuListAdapter.notifyDataSetInvalidated();
  490. onMenuItemSelectListener.onOneItemSelect(me, menuList.get(position), position, true);
  491. }
  492. } else {
  493. if (onMenuItemClickListener != null) {
  494. if (!onMenuItemClickListener.onClick(me, menuList.get(position), position)) {
  495. dismiss();
  496. }
  497. } else {
  498. dismiss();
  499. }
  500. }
  501. break;
  502. case MULTIPLE:
  503. if (onMenuItemClickListener instanceof OnMenuItemSelectListener) {
  504. OnMenuItemSelectListener<BottomMenu> onMenuItemSelectListener = (OnMenuItemSelectListener<BottomMenu>) onMenuItemClickListener;
  505. if (!onMenuItemSelectListener.onClick(me, menuList.get(position), position)) {
  506. dismiss();
  507. } else {
  508. if (selectionItems.contains(position)) {
  509. selectionItems.remove(new Integer(position));
  510. } else {
  511. selectionItems.add(position);
  512. }
  513. menuListAdapter.notifyDataSetInvalidated();
  514. resultArray = new int[selectionItems.size()];
  515. selectTextArray = new CharSequence[selectionItems.size()];
  516. for (int i = 0; i < selectionItems.size(); i++) {
  517. resultArray[i] = selectionItems.get(i);
  518. selectTextArray[i] = menuList.get(resultArray[i]);
  519. }
  520. onMenuItemSelectListener.onMultiItemSelect(me, selectTextArray, resultArray);
  521. }
  522. } else {
  523. if (onMenuItemClickListener != null) {
  524. if (!onMenuItemClickListener.onClick(me, menuList.get(position), position)) {
  525. dismiss();
  526. }
  527. } else {
  528. dismiss();
  529. }
  530. }
  531. break;
  532. }
  533. }
  534. }
  535. });
  536. if (style.overrideBottomDialogRes() != null) {
  537. if (style.overrideBottomDialogRes().overrideMenuItemLayout(true, 0, 0, false) != 0) {
  538. listView.setSelector(R.color.empty);
  539. }
  540. }
  541. ViewGroup.LayoutParams listViewLp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  542. getDialogImpl().boxList.addView(listView, listViewLp);
  543. refreshUI();
  544. }
  545. }
  546. @Override
  547. public void refreshUI() {
  548. if (getDialogImpl() == null) return;
  549. if (listView != null) {
  550. if (menuListAdapter == null) {
  551. menuListAdapter = new BottomMenuArrayAdapter(me, getOwnActivity(), menuList);
  552. }
  553. if (listView.getAdapter() == null) {
  554. listView.setAdapter(menuListAdapter);
  555. } else {
  556. if (listView.getAdapter() != menuListAdapter) {
  557. listView.setAdapter(menuListAdapter);
  558. } else {
  559. menuListAdapter.notifyDataSetChanged();
  560. }
  561. }
  562. }
  563. // 部分主题下选中项默认按下效果
  564. if (showSelectedBackgroundTips) {
  565. listView.post(new Runnable() {
  566. @Override
  567. public void run() {
  568. if (menuListAdapter instanceof BottomMenuArrayAdapter && showSelectedBackgroundTips) {
  569. BottomMenuArrayAdapter bottomMenuArrayAdapter = ((BottomMenuArrayAdapter) menuListAdapter);
  570. View selectItemView = listView.getChildAt(getSelection());
  571. if (selectItemView != null) {
  572. selectItemView.post(new Runnable() {
  573. @Override
  574. public void run() {
  575. selectItemView.setPressed(true);
  576. }
  577. });
  578. }
  579. }
  580. }
  581. });
  582. }
  583. super.refreshUI();
  584. }
  585. public void preRefreshUI() {
  586. if (getDialogImpl() == null) return;
  587. runOnMain(new Runnable() {
  588. @Override
  589. public void run() {
  590. refreshUI();
  591. }
  592. });
  593. }
  594. @Override
  595. public String dialogKey() {
  596. return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
  597. }
  598. public List<CharSequence> getMenuList() {
  599. return menuList;
  600. }
  601. public BottomMenu setMenuList(List<CharSequence> menuList) {
  602. this.menuList = menuList;
  603. this.menuListAdapter = null;
  604. preRefreshUI();
  605. return this;
  606. }
  607. private boolean isSameSize(int menuListSize) {
  608. if (this.menuList == null || this.menuList.size() == 0) {
  609. return true;
  610. }
  611. return this.menuList.size() == menuListSize;
  612. }
  613. public BottomMenu setMenuStringList(List<String> menuList) {
  614. this.menuList = new ArrayList<>();
  615. this.menuList.addAll(menuList);
  616. this.menuListAdapter = null;
  617. preRefreshUI();
  618. return this;
  619. }
  620. public BottomMenu setMenuList(String[] menuList) {
  621. this.menuList = new ArrayList<>();
  622. this.menuList.addAll(Arrays.asList(menuList));
  623. this.menuListAdapter = null;
  624. preRefreshUI();
  625. return this;
  626. }
  627. public BottomMenu setMenuList(CharSequence[] menuList) {
  628. this.menuList = Arrays.asList(menuList);
  629. this.menuListAdapter = null;
  630. preRefreshUI();
  631. return this;
  632. }
  633. public BottomMenu setMenus(CharSequence... menuList) {
  634. this.menuList = Arrays.asList(menuList);
  635. this.menuListAdapter = null;
  636. preRefreshUI();
  637. return this;
  638. }
  639. public BottomMenu setMenus(String... menuList) {
  640. this.menuList = Arrays.asList(menuList);
  641. this.menuListAdapter = null;
  642. preRefreshUI();
  643. return this;
  644. }
  645. public OnIconChangeCallBack<BottomMenu> getOnIconChangeCallBack() {
  646. return onIconChangeCallBack;
  647. }
  648. public BottomMenu setOnIconChangeCallBack(OnIconChangeCallBack<BottomMenu> onIconChangeCallBack) {
  649. this.onIconChangeCallBack = onIconChangeCallBack;
  650. return this;
  651. }
  652. public OnBackPressedListener<BottomDialog> getOnBackPressedListener() {
  653. return (OnBackPressedListener<BottomDialog>) onBackPressedListener;
  654. }
  655. public BottomMenu setOnBackPressedListener(OnBackPressedListener<BottomDialog> onBackPressedListener) {
  656. this.onBackPressedListener = onBackPressedListener;
  657. preRefreshUI();
  658. return this;
  659. }
  660. public BottomMenu setDialogLifecycleCallback(DialogLifecycleCallback<BottomDialog> dialogLifecycleCallback) {
  661. this.dialogLifecycleCallback = dialogLifecycleCallback;
  662. if (isShow) dialogLifecycleCallback.onShow(me);
  663. return this;
  664. }
  665. public BottomMenu setStyle(DialogXStyle style) {
  666. this.style = style;
  667. return this;
  668. }
  669. public BottomMenu setTheme(DialogX.THEME theme) {
  670. this.theme = theme;
  671. return this;
  672. }
  673. public boolean isCancelable() {
  674. if (privateCancelable != null) {
  675. return privateCancelable == BOOLEAN.TRUE;
  676. }
  677. if (overrideCancelable != null) {
  678. return overrideCancelable == BOOLEAN.TRUE;
  679. }
  680. return cancelable;
  681. }
  682. public BottomMenu setCancelable(boolean cancelable) {
  683. this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
  684. preRefreshUI();
  685. return this;
  686. }
  687. public DialogImpl getDialogImpl() {
  688. return dialogImpl;
  689. }
  690. public CharSequence getTitle() {
  691. return title;
  692. }
  693. public BottomMenu setTitle(CharSequence title) {
  694. this.title = title;
  695. preRefreshUI();
  696. return this;
  697. }
  698. public BottomMenu setTitle(int titleResId) {
  699. this.title = getString(titleResId);
  700. preRefreshUI();
  701. return this;
  702. }
  703. public CharSequence getMessage() {
  704. return message;
  705. }
  706. public BottomMenu setMessage(CharSequence message) {
  707. this.message = message;
  708. preRefreshUI();
  709. return this;
  710. }
  711. public BottomMenu setMessage(int messageResId) {
  712. this.message = getString(messageResId);
  713. preRefreshUI();
  714. return this;
  715. }
  716. public CharSequence getCancelButton() {
  717. return cancelText;
  718. }
  719. public BottomMenu setCancelButton(CharSequence cancelText) {
  720. this.cancelText = cancelText;
  721. preRefreshUI();
  722. return this;
  723. }
  724. public BottomMenu setCancelButton(int cancelTextResId) {
  725. this.cancelText = getString(cancelTextResId);
  726. preRefreshUI();
  727. return this;
  728. }
  729. public BottomMenu setCancelButton(OnBottomMenuButtonClickListener<BottomMenu> cancelButtonClickListener) {
  730. this.cancelButtonClickListener = cancelButtonClickListener;
  731. return this;
  732. }
  733. public BottomMenu setCancelButton(CharSequence cancelText, OnBottomMenuButtonClickListener<BottomMenu> cancelButtonClickListener) {
  734. this.cancelText = cancelText;
  735. this.cancelButtonClickListener = cancelButtonClickListener;
  736. preRefreshUI();
  737. return this;
  738. }
  739. public BottomMenu setCancelButton(int cancelTextResId, OnBottomMenuButtonClickListener<BottomMenu> cancelButtonClickListener) {
  740. this.cancelText = getString(cancelTextResId);
  741. this.cancelButtonClickListener = cancelButtonClickListener;
  742. preRefreshUI();
  743. return this;
  744. }
  745. /**
  746. * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setCancelButton(OnBottomMenuButtonClickListener<BottomMenu>)}
  747. */
  748. @Deprecated
  749. public BottomMenu setCancelButton(OnDialogButtonClickListener<BottomDialog> cancelButtonClickListener) {
  750. this.cancelButtonClickListener = cancelButtonClickListener;
  751. return this;
  752. }
  753. /**
  754. * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setCancelButton(CharSequence cancelText, OnBottomMenuButtonClickListener<BottomMenu>)}
  755. */
  756. @Deprecated
  757. public BottomMenu setCancelButton(CharSequence cancelText, OnDialogButtonClickListener<BottomDialog> cancelButtonClickListener) {
  758. this.cancelText = cancelText;
  759. this.cancelButtonClickListener = cancelButtonClickListener;
  760. preRefreshUI();
  761. return this;
  762. }
  763. /**
  764. * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setCancelButton(int cancelTextResId, OnBottomMenuButtonClickListener<BottomMenu>)}
  765. */
  766. @Deprecated
  767. public BottomMenu setCancelButton(int cancelTextResId, OnDialogButtonClickListener<BottomDialog> cancelButtonClickListener) {
  768. this.cancelText = getString(cancelTextResId);
  769. this.cancelButtonClickListener = cancelButtonClickListener;
  770. preRefreshUI();
  771. return this;
  772. }
  773. public BottomMenu setCustomView(OnBindView<BottomDialog> onBindView) {
  774. this.onBindView = onBindView;
  775. preRefreshUI();
  776. return this;
  777. }
  778. public View getCustomView() {
  779. if (onBindView == null) return null;
  780. return onBindView.getCustomView();
  781. }
  782. public BottomMenu removeCustomView() {
  783. this.onBindView.clean();
  784. preRefreshUI();
  785. return this;
  786. }
  787. public boolean isAllowInterceptTouch() {
  788. return super.isAllowInterceptTouch();
  789. }
  790. public BottomMenu setAllowInterceptTouch(boolean allowInterceptTouch) {
  791. this.allowInterceptTouch = allowInterceptTouch;
  792. preRefreshUI();
  793. return this;
  794. }
  795. public float getBottomDialogMaxHeight() {
  796. return bottomDialogMaxHeight;
  797. }
  798. public BottomMenu setBottomDialogMaxHeight(float bottomDialogMaxHeight) {
  799. this.bottomDialogMaxHeight = bottomDialogMaxHeight;
  800. return this;
  801. }
  802. public OnMenuItemClickListener<BottomMenu> getOnMenuItemClickListener() {
  803. return onMenuItemClickListener;
  804. }
  805. public BottomMenu setOnMenuItemClickListener(OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
  806. this.onMenuItemClickListener = onMenuItemClickListener;
  807. return this;
  808. }
  809. public BaseAdapter getMenuListAdapter() {
  810. return menuListAdapter;
  811. }
  812. public BottomMenu setMenuListAdapter(BaseAdapter menuListAdapter) {
  813. this.menuListAdapter = menuListAdapter;
  814. return this;
  815. }
  816. public OnBottomMenuButtonClickListener<BottomMenu> getBottomMenuCancelButtonClickListener() {
  817. return (OnBottomMenuButtonClickListener<BottomMenu>) cancelButtonClickListener;
  818. }
  819. public BottomMenu setCancelButtonClickListener(OnBottomMenuButtonClickListener<BottomMenu> cancelButtonClickListener) {
  820. this.cancelButtonClickListener = cancelButtonClickListener;
  821. return this;
  822. }
  823. public TextInfo getTitleTextInfo() {
  824. return titleTextInfo;
  825. }
  826. public BottomMenu setTitleTextInfo(TextInfo titleTextInfo) {
  827. this.titleTextInfo = titleTextInfo;
  828. preRefreshUI();
  829. return this;
  830. }
  831. public TextInfo getMessageTextInfo() {
  832. return messageTextInfo;
  833. }
  834. public BottomMenu setMessageTextInfo(TextInfo messageTextInfo) {
  835. this.messageTextInfo = messageTextInfo;
  836. preRefreshUI();
  837. return this;
  838. }
  839. public TextInfo getCancelTextInfo() {
  840. return cancelTextInfo;
  841. }
  842. public BottomMenu setCancelTextInfo(TextInfo cancelTextInfo) {
  843. this.cancelTextInfo = cancelTextInfo;
  844. preRefreshUI();
  845. return this;
  846. }
  847. public int getBackgroundColor() {
  848. return backgroundColor;
  849. }
  850. public BottomMenu setBackgroundColor(@ColorInt int backgroundColor) {
  851. this.backgroundColor = backgroundColor;
  852. preRefreshUI();
  853. return this;
  854. }
  855. public int getSelection() {
  856. return selectionIndex;
  857. }
  858. public ArrayList<Integer> getSelectionList() {
  859. return selectionItems;
  860. }
  861. public BottomMenu setSelection(int selectionIndex) {
  862. this.selectMode = SELECT_MODE.SINGLE;
  863. this.selectionIndex = selectionIndex;
  864. this.selectionItems = null;
  865. menuListAdapter = null;
  866. preRefreshUI();
  867. return this;
  868. }
  869. public BottomMenu setSingleSelection() {
  870. this.selectMode = SELECT_MODE.SINGLE;
  871. this.selectionIndex = -1;
  872. this.selectionItems = null;
  873. menuListAdapter = null;
  874. preRefreshUI();
  875. return this;
  876. }
  877. public BottomMenu setSelection(int[] selectionItems) {
  878. this.selectMode = SELECT_MODE.MULTIPLE;
  879. this.selectionIndex = -1;
  880. this.selectionItems = new ArrayList<>();
  881. if (selectionItems != null) {
  882. for (int itemIndex : selectionItems) {
  883. this.selectionItems.add(itemIndex);
  884. }
  885. }
  886. menuListAdapter = null;
  887. preRefreshUI();
  888. return this;
  889. }
  890. public BottomMenu setMultiSelection() {
  891. this.selectMode = SELECT_MODE.MULTIPLE;
  892. this.selectionIndex = -1;
  893. this.selectionItems = new ArrayList<>();
  894. menuListAdapter = null;
  895. preRefreshUI();
  896. return this;
  897. }
  898. public BottomMenu setSelection(List<Integer> selectionItems) {
  899. this.selectMode = SELECT_MODE.MULTIPLE;
  900. this.selectionIndex = -1;
  901. this.selectionItems = new ArrayList<>(selectionItems);
  902. menuListAdapter = null;
  903. preRefreshUI();
  904. return this;
  905. }
  906. public BottomMenu setNoSelect() {
  907. this.selectMode = SELECT_MODE.NONE;
  908. this.selectionIndex = -1;
  909. this.selectionItems = null;
  910. menuListAdapter = null;
  911. preRefreshUI();
  912. return this;
  913. }
  914. public BottomMenu setBackgroundColorRes(@ColorRes int backgroundRes) {
  915. this.backgroundColor = getColor(backgroundRes);
  916. preRefreshUI();
  917. return this;
  918. }
  919. public CharSequence getOkButton() {
  920. return okText;
  921. }
  922. public BottomMenu setOkButton(CharSequence okText) {
  923. this.okText = okText;
  924. preRefreshUI();
  925. return this;
  926. }
  927. public BottomMenu setOkButton(int OkTextResId) {
  928. this.okText = getString(OkTextResId);
  929. preRefreshUI();
  930. return this;
  931. }
  932. public BottomMenu setOkButton(OnBottomMenuButtonClickListener<BottomMenu> okButtonClickListener) {
  933. this.okButtonClickListener = okButtonClickListener;
  934. return this;
  935. }
  936. public BottomMenu setOkButton(CharSequence okText, OnBottomMenuButtonClickListener<BottomMenu> okButtonClickListener) {
  937. this.okText = okText;
  938. this.okButtonClickListener = okButtonClickListener;
  939. return this;
  940. }
  941. public BottomMenu setOkButton(int okTextResId, OnBottomMenuButtonClickListener<BottomMenu> okButtonClickListener) {
  942. this.okText = getString(okTextResId);
  943. this.okButtonClickListener = okButtonClickListener;
  944. return this;
  945. }
  946. public BottomMenu setHapticFeedbackEnabled(boolean isHapticFeedbackEnabled) {
  947. this.isHapticFeedbackEnabled = isHapticFeedbackEnabled ? 1 : 0;
  948. return this;
  949. }
  950. /**
  951. * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOkButton(OnBottomMenuButtonClickListener<BottomMenu>)}
  952. */
  953. @Deprecated
  954. public BottomMenu setOkButton(OnDialogButtonClickListener<BottomDialog> okButtonClickListener) {
  955. this.okButtonClickListener = okButtonClickListener;
  956. return this;
  957. }
  958. /**
  959. * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOkButton(CharSequence okText, OnBottomMenuButtonClickListener<BottomMenu>)}
  960. */
  961. @Deprecated
  962. public BottomMenu setOkButton(CharSequence okText, OnDialogButtonClickListener<BottomDialog> okButtonClickListener) {
  963. this.okText = okText;
  964. this.okButtonClickListener = okButtonClickListener;
  965. return this;
  966. }
  967. /**
  968. * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOkButton(int okTextResId, OnBottomMenuButtonClickListener<BottomMenu>)}
  969. */
  970. @Deprecated
  971. public BottomMenu setOkButton(int okTextResId, OnDialogButtonClickListener<BottomDialog> okButtonClickListener) {
  972. this.okText = getString(okTextResId);
  973. this.okButtonClickListener = okButtonClickListener;
  974. return this;
  975. }
  976. public CharSequence getOtherButton() {
  977. return otherText;
  978. }
  979. public BottomMenu setOtherButton(CharSequence otherText) {
  980. this.otherText = otherText;
  981. preRefreshUI();
  982. return this;
  983. }
  984. public BottomMenu setOtherButton(int OtherTextResId) {
  985. this.otherText = getString(OtherTextResId);
  986. preRefreshUI();
  987. return this;
  988. }
  989. public BottomMenu setOtherButton(OnBottomMenuButtonClickListener<BottomMenu> otherButtonClickListener) {
  990. this.otherButtonClickListener = otherButtonClickListener;
  991. return this;
  992. }
  993. public BottomMenu setOtherButton(CharSequence otherText, OnBottomMenuButtonClickListener<BottomMenu> otherButtonClickListener) {
  994. this.otherText = otherText;
  995. this.otherButtonClickListener = otherButtonClickListener;
  996. return this;
  997. }
  998. public BottomMenu setOtherButton(int otherTextResId, OnBottomMenuButtonClickListener<BottomMenu> otherButtonClickListener) {
  999. this.otherText = getString(otherTextResId);
  1000. this.otherButtonClickListener = otherButtonClickListener;
  1001. return this;
  1002. }
  1003. /**
  1004. * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOtherButton(OnBottomMenuButtonClickListener<BottomMenu>)}
  1005. */
  1006. @Deprecated
  1007. public BottomMenu setOtherButton(OnDialogButtonClickListener<BottomDialog> otherButtonClickListener) {
  1008. this.otherButtonClickListener = otherButtonClickListener;
  1009. return this;
  1010. }
  1011. /**
  1012. * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOtherButton(CharSequence otherText, OnBottomMenuButtonClickListener<BottomMenu>)}
  1013. */
  1014. @Deprecated
  1015. public BottomMenu setOtherButton(CharSequence otherText, OnDialogButtonClickListener<BottomDialog> otherButtonClickListener) {
  1016. this.otherText = otherText;
  1017. this.otherButtonClickListener = otherButtonClickListener;
  1018. return this;
  1019. }
  1020. /**
  1021. * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOtherButton(int otherTextResId, OnBottomMenuButtonClickListener<BottomMenu>)}
  1022. */
  1023. @Deprecated
  1024. public BottomMenu setOtherButton(int otherTextResId, OnDialogButtonClickListener<BottomDialog> otherButtonClickListener) {
  1025. this.otherText = getString(otherTextResId);
  1026. this.otherButtonClickListener = otherButtonClickListener;
  1027. return this;
  1028. }
  1029. public BottomMenu setMaskColor(@ColorInt int maskColor) {
  1030. this.maskColor = maskColor;
  1031. preRefreshUI();
  1032. return this;
  1033. }
  1034. public long getEnterAnimDuration() {
  1035. return enterAnimDuration;
  1036. }
  1037. public BottomMenu setEnterAnimDuration(long enterAnimDuration) {
  1038. this.enterAnimDuration = enterAnimDuration;
  1039. return this;
  1040. }
  1041. public long getExitAnimDuration() {
  1042. return exitAnimDuration;
  1043. }
  1044. public BottomMenu setExitAnimDuration(long exitAnimDuration) {
  1045. this.exitAnimDuration = exitAnimDuration;
  1046. return this;
  1047. }
  1048. public SELECT_MODE getSelectMode() {
  1049. return selectMode;
  1050. }
  1051. @Override
  1052. protected void shutdown() {
  1053. dismiss();
  1054. }
  1055. public BottomMenu setMaxWidth(int maxWidth) {
  1056. this.maxWidth = maxWidth;
  1057. refreshUI();
  1058. return this;
  1059. }
  1060. public BottomMenu setMaxHeight(int maxHeight) {
  1061. this.maxHeight = maxHeight;
  1062. refreshUI();
  1063. return this;
  1064. }
  1065. public BottomMenu setMinHeight(int minHeight) {
  1066. this.minHeight = minHeight;
  1067. refreshUI();
  1068. return this;
  1069. }
  1070. public BottomMenu setMinWidth(int minWidth) {
  1071. this.minWidth = minWidth;
  1072. refreshUI();
  1073. return this;
  1074. }
  1075. public BottomMenu setDialogImplMode(DialogX.IMPL_MODE dialogImplMode) {
  1076. this.dialogImplMode = dialogImplMode;
  1077. return this;
  1078. }
  1079. public TextInfo getMenuTextInfo() {
  1080. if (menuTextInfo == null) return DialogX.menuTextInfo;
  1081. return menuTextInfo;
  1082. }
  1083. public BottomMenu setMenuTextInfo(TextInfo menuTextInfo) {
  1084. this.menuTextInfo = menuTextInfo;
  1085. return this;
  1086. }
  1087. public MenuItemTextInfoInterceptor<BottomMenu> getMenuItemTextInfoInterceptor() {
  1088. return menuItemTextInfoInterceptor;
  1089. }
  1090. public BottomMenu setMenuItemTextInfoInterceptor(MenuItemTextInfoInterceptor<BottomMenu> menuItemTextInfoInterceptor) {
  1091. this.menuItemTextInfoInterceptor = menuItemTextInfoInterceptor;
  1092. return this;
  1093. }
  1094. public boolean isBkgInterceptTouch() {
  1095. return bkgInterceptTouch;
  1096. }
  1097. public BottomMenu setBkgInterceptTouch(boolean bkgInterceptTouch) {
  1098. this.bkgInterceptTouch = bkgInterceptTouch;
  1099. return this;
  1100. }
  1101. public OnBackgroundMaskClickListener<BottomDialog> getOnBackgroundMaskClickListener() {
  1102. return onBackgroundMaskClickListener;
  1103. }
  1104. public BottomMenu setOnBackgroundMaskClickListener(OnBackgroundMaskClickListener<BottomDialog> onBackgroundMaskClickListener) {
  1105. this.onBackgroundMaskClickListener = onBackgroundMaskClickListener;
  1106. return this;
  1107. }
  1108. public BottomMenu setRadius(float radiusPx) {
  1109. backgroundRadius = radiusPx;
  1110. refreshUI();
  1111. return this;
  1112. }
  1113. public float getRadius() {
  1114. return backgroundRadius;
  1115. }
  1116. public BottomMenu setTitleIcon(Bitmap titleIcon) {
  1117. this.titleIcon = new BitmapDrawable(getResources(), titleIcon);
  1118. refreshUI();
  1119. return this;
  1120. }
  1121. public BottomMenu setTitleIcon(int titleIconResId) {
  1122. this.titleIcon = getResources().getDrawable(titleIconResId);
  1123. refreshUI();
  1124. return this;
  1125. }
  1126. public BottomMenu setTitleIcon(Drawable titleIcon) {
  1127. this.titleIcon = titleIcon;
  1128. refreshUI();
  1129. return this;
  1130. }
  1131. public DialogXAnimInterface<BottomDialog> getDialogXAnimImpl() {
  1132. return dialogXAnimImpl;
  1133. }
  1134. public BottomMenu setDialogXAnimImpl(DialogXAnimInterface<BottomDialog> dialogXAnimImpl) {
  1135. this.dialogXAnimImpl = dialogXAnimImpl;
  1136. return this;
  1137. }
  1138. public BottomMenu setRootPadding(int padding) {
  1139. this.screenPaddings = new int[]{padding, padding, padding, padding};
  1140. refreshUI();
  1141. return this;
  1142. }
  1143. public BottomMenu setRootPadding(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
  1144. this.screenPaddings = new int[]{paddingLeft, paddingTop, paddingRight, paddingBottom};
  1145. refreshUI();
  1146. return this;
  1147. }
  1148. public boolean isShowSelectedBackgroundTips() {
  1149. return showSelectedBackgroundTips;
  1150. }
  1151. public BottomMenu setShowSelectedBackgroundTips(boolean showSelectedBackgroundTips) {
  1152. this.showSelectedBackgroundTips = showSelectedBackgroundTips;
  1153. refreshUI();
  1154. return this;
  1155. }
  1156. // 返回点击的菜单索引
  1157. public int getSelectionIndex() {
  1158. return selectionIndex;
  1159. }
  1160. // 返回多选时,选择的菜单索引集合
  1161. public int[] getSelectionIndexArray() {
  1162. return resultArray;
  1163. }
  1164. // 返回多选时,选择的菜单文本集合
  1165. public CharSequence[] getSelectTextArray() {
  1166. return selectTextArray;
  1167. }
  1168. public MenuItemLayoutRefreshCallback<BottomMenu> getMenuMenuItemLayoutRefreshCallback() {
  1169. return menuMenuItemLayoutRefreshCallback;
  1170. }
  1171. public BottomMenu setMenuMenuItemLayoutRefreshCallback(MenuItemLayoutRefreshCallback<BottomMenu> menuMenuItemLayoutRefreshCallback) {
  1172. this.menuMenuItemLayoutRefreshCallback = menuMenuItemLayoutRefreshCallback;
  1173. return this;
  1174. }
  1175. public TextInfo getOkTextInfo() {
  1176. return okTextInfo;
  1177. }
  1178. public BottomMenu setOkTextInfo(TextInfo okTextInfo) {
  1179. this.okTextInfo = okTextInfo;
  1180. return this;
  1181. }
  1182. public TextInfo getOtherTextInfo() {
  1183. return otherTextInfo;
  1184. }
  1185. public BottomMenu setOtherTextInfo(TextInfo otherTextInfo) {
  1186. this.otherTextInfo = otherTextInfo;
  1187. return this;
  1188. }
  1189. public BottomMenu setScrollableWhenContentLargeThanVisibleRange(boolean scrollableWhenContentLargeThanVisibleRange) {
  1190. this.scrollableWhenContentLargeThanVisibleRange = scrollableWhenContentLargeThanVisibleRange;
  1191. return this;
  1192. }
  1193. public BottomMenu setData(String key, Object obj) {
  1194. if (data == null) data = new HashMap<>();
  1195. data.put(key, obj);
  1196. return this;
  1197. }
  1198. public BottomMenu onShow(DialogXRunnable<BottomDialog> dialogXRunnable) {
  1199. onShowRunnable = dialogXRunnable;
  1200. if (isShow() && onShowRunnable != null) {
  1201. onShowRunnable.run(this);
  1202. }
  1203. return this;
  1204. }
  1205. public BottomMenu onDismiss(DialogXRunnable<BottomDialog> dialogXRunnable) {
  1206. onDismissRunnable = dialogXRunnable;
  1207. return this;
  1208. }
  1209. public BottomMenu setEnableImmersiveMode(boolean enableImmersiveMode) {
  1210. this.enableImmersiveMode = enableImmersiveMode;
  1211. refreshUI();
  1212. return this;
  1213. }
  1214. public List<Integer> getIconResIds() {
  1215. return iconResIds;
  1216. }
  1217. public int getIconResIds(int position) {
  1218. if (iconResIds != null && position >= 0 && position < iconResIds.size()) {
  1219. return iconResIds.get(position);
  1220. }
  1221. return 0;
  1222. }
  1223. public BottomMenu setIconResIds(List<Integer> iconResIds) {
  1224. this.iconResIds = iconResIds;
  1225. refreshUI();
  1226. return this;
  1227. }
  1228. public BottomMenu setIconResIds(int... resIds) {
  1229. if (iconResIds == null) {
  1230. iconResIds = new ArrayList<>();
  1231. }
  1232. for (int id : resIds) {
  1233. iconResIds.add(id);
  1234. }
  1235. refreshUI();
  1236. return this;
  1237. }
  1238. public boolean isAutoTintIconInLightOrDarkMode() {
  1239. return autoTintIconInLightOrDarkMode;
  1240. }
  1241. public BottomMenu setAutoTintIconInLightOrDarkMode(boolean autoTintIconInLightOrDarkMode) {
  1242. this.autoTintIconInLightOrDarkMode = autoTintIconInLightOrDarkMode;
  1243. refreshUI();
  1244. return this;
  1245. }
  1246. public BottomMenu appendMessage(CharSequence message){
  1247. this.message = TextUtils.concat(this.message, message);
  1248. refreshUI();
  1249. return this;
  1250. }
  1251. }