1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069 |
- package com.kongzue.dialogx.dialogs;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.AdapterView;
- import android.widget.BaseAdapter;
- import android.widget.RelativeLayout;
- import androidx.annotation.ColorInt;
- import androidx.annotation.ColorRes;
- import com.kongzue.dialogx.DialogX;
- import com.kongzue.dialogx.R;
- import com.kongzue.dialogx.interfaces.BottomMenuListViewTouchEvent;
- import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
- import com.kongzue.dialogx.interfaces.DialogXStyle;
- import com.kongzue.dialogx.interfaces.OnBackPressedListener;
- import com.kongzue.dialogx.interfaces.OnBindView;
- import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
- import com.kongzue.dialogx.interfaces.OnIconChangeCallBack;
- import com.kongzue.dialogx.interfaces.OnMenuItemClickListener;
- import com.kongzue.dialogx.interfaces.OnMenuItemSelectListener;
- import com.kongzue.dialogx.util.BottomMenuArrayAdapter;
- import com.kongzue.dialogx.util.TextInfo;
- import com.kongzue.dialogx.util.views.BottomDialogListView;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import static android.view.View.OVER_SCROLL_NEVER;
- /**
- * @author: Kongzue
- * @github: https://github.com/kongzue/
- * @homepage: http://kongzue.com/
- * @mail: myzcxhh@live.cn
- * @createTime: 2020/10/6 23:48
- */
- public class BottomMenu extends BottomDialog {
-
- public enum SELECT_MODE {
- NONE,
- SINGLE,
- MULTIPLE
- }
-
- protected BottomMenu me = this;
- protected int selectionIndex = -1;
- protected SELECT_MODE selectMode = SELECT_MODE.NONE;
- protected ArrayList<Integer> selectionItems;
-
- protected OnMenuItemClickListener<BottomMenu> onMenuItemClickListener;
-
- public static BottomMenu build() {
- return new BottomMenu();
- }
-
- public static BottomMenu build(OnBindView<BottomDialog> onBindView) {
- return new BottomMenu().setCustomView(onBindView);
- }
-
- protected BottomMenu() {
- super();
- if (style.overrideBottomDialogRes() != null) {
- bottomDialogMaxHeight = style.overrideBottomDialogRes().overrideBottomDialogMaxHeight();
- }
- if (bottomDialogMaxHeight <= 1 && bottomDialogMaxHeight > 0f) {
- bottomDialogMaxHeight = (int) (getRootFrameLayout().getMeasuredHeight() * bottomDialogMaxHeight);
- }
- }
-
- private OnIconChangeCallBack<BottomMenu> onIconChangeCallBack;
- private BottomDialogListView listView;
- private BaseAdapter menuListAdapter;
- private List<CharSequence> menuList;
-
- public static BottomMenu show(List<CharSequence> menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu showStringList(List<String> menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.setMenuStringList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu showStringList(List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.setMenuStringList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(String[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, CharSequence message, List<CharSequence> menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, CharSequence message, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, List<CharSequence> menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu showStringList(CharSequence title, CharSequence message, List<String> menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuStringList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu showStringList(CharSequence title, CharSequence message, List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuStringList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, CharSequence message, String[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, CharSequence message, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, CharSequence message, CharSequence[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, CharSequence message, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(String title, String message, List<CharSequence> menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(String title, String message, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu showStringList(String title, String message, List<String> menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuStringList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu showStringList(String title, String message, List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuStringList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(String title, String message, String[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(String title, String message, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(String title, String message, CharSequence[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(String title, String message, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.message = message;
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, int messageResId, List<CharSequence> menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.message = bottomMenu.getString(messageResId);
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, List<CharSequence> menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu showStringList(int titleResId, int messageResId, List<String> menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.message = bottomMenu.getString(messageResId);
- bottomMenu.setMenuStringList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, int messageResId, String[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.message = bottomMenu.getString(messageResId);
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, int messageResId, CharSequence[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.message = bottomMenu.getString(messageResId);
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, int messageResId, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.message = bottomMenu.getString(messageResId);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, List<CharSequence> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu showStringList(int titleResId, int messageResId, List<String> menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.message = bottomMenu.getString(messageResId);
- bottomMenu.setMenuStringList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, int messageResId, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.message = bottomMenu.getString(messageResId);
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, int messageResId, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.message = bottomMenu.getString(messageResId);
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, CharSequence[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, String[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(CharSequence title, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = title;
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, CharSequence[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, String[] menuList) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.setMenuList(menuList);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, CharSequence[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- public static BottomMenu show(int titleResId, String[] menuList, OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- BottomMenu bottomMenu = new BottomMenu();
- bottomMenu.title = bottomMenu.getString(titleResId);
- bottomMenu.setMenuList(menuList);
- bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
- bottomMenu.show();
- return bottomMenu;
- }
-
- private float touchDownY;
-
- public static final int ITEM_CLICK_DELAY = 100;
- private long lastClickTime = 0;
-
- @Override
- protected void onDialogInit(final DialogImpl dialog) {
- if (dialog != null) {
- dialog.boxList.setVisibility(View.VISIBLE);
-
- if (!isAllowInterceptTouch()) {
- dialog.bkg.setMaxHeight((int) bottomDialogMaxHeight);
- if (bottomDialogMaxHeight != 0) {
- dialogImpl.scrollView.lockScroll(true);
- }
- }
-
- int dividerDrawableResId = 0;
- int dividerHeight = 1;
- if (style.overrideBottomDialogRes() != null) {
- dividerDrawableResId = style.overrideBottomDialogRes().overrideMenuDividerDrawableRes(isLightTheme());
- dividerHeight = style.overrideBottomDialogRes().overrideMenuDividerHeight(isLightTheme());
- }
- if (dividerDrawableResId == 0) {
- dividerDrawableResId = isLightTheme() ? R.drawable.rect_dialogx_material_menu_split_divider : R.drawable.rect_dialogx_material_menu_split_divider_night;
- }
-
- listView = new BottomDialogListView(dialog, getContext());
- listView.setOverScrollMode(OVER_SCROLL_NEVER);
- listView.setDivider(getResources().getDrawable(dividerDrawableResId));
- listView.setDividerHeight(dividerHeight);
-
- listView.setBottomMenuListViewTouchEvent(new BottomMenuListViewTouchEvent() {
- @Override
- public void down(MotionEvent event) {
- touchDownY = dialog.bkg.getY();
- }
- });
-
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- long currentTime = System.currentTimeMillis();
- if (currentTime - lastClickTime > ITEM_CLICK_DELAY) {
- lastClickTime = currentTime;
- float deltaY = Math.abs(touchDownY - dialog.bkg.getY());
- if (deltaY > dip2px(15)) {
- return;
- }
- switch (selectMode) {
- case NONE:
- if (onMenuItemClickListener != null) {
- if (!onMenuItemClickListener.onClick(me, menuList.get(position), position)) {
- dismiss();
- }
- } else {
- dismiss();
- }
- break;
- case SINGLE:
- if (onMenuItemClickListener instanceof OnMenuItemSelectListener) {
- OnMenuItemSelectListener<BottomMenu> onMenuItemSelectListener = (OnMenuItemSelectListener<BottomMenu>) onMenuItemClickListener;
- if (!onMenuItemSelectListener.onClick(me, menuList.get(position), position)) {
- dismiss();
- } else {
- selectionIndex = position;
- menuListAdapter.notifyDataSetInvalidated();
- menuListAdapter.notifyDataSetChanged();
- onMenuItemSelectListener.onOneItemSelect(me, menuList.get(position), position, true);
- }
- } else {
- if (onMenuItemClickListener != null) {
- if (!onMenuItemClickListener.onClick(me, menuList.get(position), position)) {
- dismiss();
- }
- } else {
- dismiss();
- }
- }
- break;
- case MULTIPLE:
- if (onMenuItemClickListener instanceof OnMenuItemSelectListener) {
- OnMenuItemSelectListener<BottomMenu> onMenuItemSelectListener = (OnMenuItemSelectListener<BottomMenu>) onMenuItemClickListener;
- if (!onMenuItemSelectListener.onClick(me, menuList.get(position), position)) {
- dismiss();
- } else {
- if (selectionItems.contains(position)) {
- selectionItems.remove(new Integer(position));
- } else {
- selectionItems.add(position);
- }
- menuListAdapter.notifyDataSetInvalidated();
- menuListAdapter.notifyDataSetChanged();
- int[] resultArray = new int[selectionItems.size()];
- CharSequence[] selectTextArray = new CharSequence[selectionItems.size()];
- for (int i = 0; i < selectionItems.size(); i++) {
- resultArray[i] = selectionItems.get(i);
- selectTextArray[i] = menuList.get(resultArray[i]);
- }
- onMenuItemSelectListener.onMultiItemSelect(me, selectTextArray, resultArray);
- }
- } else {
- if (onMenuItemClickListener != null) {
- if (!onMenuItemClickListener.onClick(me, menuList.get(position), position)) {
- dismiss();
- }
- } else {
- dismiss();
- }
- }
- break;
- }
- }
- }
- });
- if (style.overrideBottomDialogRes() != null) {
- if (style.overrideBottomDialogRes().overrideMenuItemLayout(true, 0, 0, false) != 0) {
- listView.setSelector(R.color.empty);
- }
- }
-
- RelativeLayout.LayoutParams listViewLp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- dialog.boxList.addView(listView, listViewLp);
-
- refreshUI();
- }
- }
-
- @Override
- public void refreshUI() {
- if (getDialogImpl() == null) return;
- if (listView != null) {
- if (menuListAdapter == null) {
- menuListAdapter = new BottomMenuArrayAdapter(me, getContext(), menuList);
- }
- if (listView.getAdapter() == null) {
- listView.setAdapter(menuListAdapter);
- } else {
- if (listView.getAdapter() != menuListAdapter) {
- listView.setAdapter(menuListAdapter);
- } else {
- menuListAdapter.notifyDataSetChanged();
- }
- }
- }
- super.refreshUI();
- }
-
- public void preRefreshUI() {
- if (getDialogImpl() == null) return;
- runOnMain(new Runnable() {
- @Override
- public void run() {
- refreshUI();
- }
- });
- }
-
- @Override
- public String dialogKey() {
- return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
- }
-
- public List<CharSequence> getMenuList() {
- return menuList;
- }
-
- public BottomMenu setMenuList(List<CharSequence> menuList) {
- this.menuList = menuList;
- this.menuListAdapter = null;
- preRefreshUI();
- return this;
- }
-
- private boolean isSameSize(int menuListSize) {
- if (this.menuList == null || this.menuList.size() == 0) {
- return true;
- }
- return this.menuList.size() == menuListSize;
- }
-
- public BottomMenu setMenuStringList(List<String> menuList) {
- this.menuList = new ArrayList<>();
- this.menuList.addAll(menuList);
- this.menuListAdapter = null;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setMenuList(String[] menuList) {
- this.menuList = new ArrayList<>();
- this.menuList.addAll(Arrays.asList(menuList));
- this.menuListAdapter = null;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setMenuList(CharSequence[] menuList) {
- this.menuList = Arrays.asList(menuList);
- this.menuListAdapter = null;
- preRefreshUI();
- return this;
- }
-
- public OnIconChangeCallBack<BottomMenu> getOnIconChangeCallBack() {
- return onIconChangeCallBack;
- }
-
- public BottomMenu setOnIconChangeCallBack(OnIconChangeCallBack<BottomMenu> onIconChangeCallBack) {
- this.onIconChangeCallBack = onIconChangeCallBack;
- return this;
- }
-
- public OnBackPressedListener getOnBackPressedListener() {
- return onBackPressedListener;
- }
-
- public BottomMenu setOnBackPressedListener(OnBackPressedListener onBackPressedListener) {
- this.onBackPressedListener = onBackPressedListener;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setDialogLifecycleCallback(DialogLifecycleCallback<BottomDialog> dialogLifecycleCallback) {
- this.dialogLifecycleCallback = dialogLifecycleCallback;
- if (isShow) dialogLifecycleCallback.onShow(me);
- return this;
- }
-
- public BottomMenu setStyle(DialogXStyle style) {
- this.style = style;
- return this;
- }
-
- public BottomMenu setTheme(DialogX.THEME theme) {
- this.theme = theme;
- return this;
- }
-
- public boolean isCancelable() {
- if (privateCancelable != null) {
- return privateCancelable == BOOLEAN.TRUE;
- }
- if (overrideCancelable != null) {
- return overrideCancelable == BOOLEAN.TRUE;
- }
- return cancelable;
- }
-
- public BottomMenu setCancelable(boolean cancelable) {
- this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
- preRefreshUI();
- return this;
- }
-
- public DialogImpl getDialogImpl() {
- return dialogImpl;
- }
-
- public CharSequence getTitle() {
- return title;
- }
-
- public BottomMenu setTitle(CharSequence title) {
- this.title = title;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setTitle(int titleResId) {
- this.title = getString(titleResId);
- preRefreshUI();
- return this;
- }
-
- public CharSequence getMessage() {
- return message;
- }
-
- public BottomMenu setMessage(CharSequence message) {
- this.message = message;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setMessage(int messageResId) {
- this.message = getString(messageResId);
- preRefreshUI();
- return this;
- }
-
- public CharSequence getCancelButton() {
- return cancelText;
- }
-
- public BottomMenu setCancelButton(CharSequence cancelText) {
- this.cancelText = cancelText;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setCancelButton(int cancelTextResId) {
- this.cancelText = getString(cancelTextResId);
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setCancelButton(OnDialogButtonClickListener cancelButtonClickListener) {
- this.cancelButtonClickListener = cancelButtonClickListener;
- return this;
- }
-
- public BottomMenu setCancelButton(CharSequence cancelText, OnDialogButtonClickListener cancelButtonClickListener) {
- this.cancelText = cancelText;
- this.cancelButtonClickListener = cancelButtonClickListener;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setCancelButton(int cancelTextResId, OnDialogButtonClickListener cancelButtonClickListener) {
- this.cancelText = getString(cancelTextResId);
- this.cancelButtonClickListener = cancelButtonClickListener;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setCustomView(OnBindView<BottomDialog> onBindView) {
- this.onBindView = onBindView;
- preRefreshUI();
- return this;
- }
-
- public View getCustomView() {
- if (onBindView == null) return null;
- return onBindView.getCustomView();
- }
-
- public BottomMenu removeCustomView() {
- this.onBindView.clean();
- preRefreshUI();
- return this;
- }
-
- public boolean isAllowInterceptTouch() {
- return super.isAllowInterceptTouch();
- }
-
- public BottomMenu setAllowInterceptTouch(boolean allowInterceptTouch) {
- this.allowInterceptTouch = allowInterceptTouch;
- preRefreshUI();
- return this;
- }
-
- public float getBottomDialogMaxHeight() {
- return bottomDialogMaxHeight;
- }
-
- public BottomMenu setBottomDialogMaxHeight(float bottomDialogMaxHeight) {
- this.bottomDialogMaxHeight = bottomDialogMaxHeight;
- return this;
- }
-
- public OnMenuItemClickListener<BottomMenu> getOnMenuItemClickListener() {
- return onMenuItemClickListener;
- }
-
- public BottomMenu setOnMenuItemClickListener(OnMenuItemClickListener<BottomMenu> onMenuItemClickListener) {
- this.onMenuItemClickListener = onMenuItemClickListener;
- return this;
- }
-
- public BaseAdapter getMenuListAdapter() {
- return menuListAdapter;
- }
-
- public BottomMenu setMenuListAdapter(BaseAdapter menuListAdapter) {
- this.menuListAdapter = menuListAdapter;
- return this;
- }
-
- public OnDialogButtonClickListener getCancelButtonClickListener() {
- return cancelButtonClickListener;
- }
-
- public BottomMenu setCancelButtonClickListener(OnDialogButtonClickListener cancelButtonClickListener) {
- this.cancelButtonClickListener = cancelButtonClickListener;
- return this;
- }
-
- public TextInfo getTitleTextInfo() {
- return titleTextInfo;
- }
-
- public BottomMenu setTitleTextInfo(TextInfo titleTextInfo) {
- this.titleTextInfo = titleTextInfo;
- preRefreshUI();
- return this;
- }
-
- public TextInfo getMessageTextInfo() {
- return messageTextInfo;
- }
-
- public BottomMenu setMessageTextInfo(TextInfo messageTextInfo) {
- this.messageTextInfo = messageTextInfo;
- preRefreshUI();
- return this;
- }
-
- public TextInfo getCancelTextInfo() {
- return cancelTextInfo;
- }
-
- public BottomMenu setCancelTextInfo(TextInfo cancelTextInfo) {
- this.cancelTextInfo = cancelTextInfo;
- preRefreshUI();
- return this;
- }
-
- public int getBackgroundColor() {
- return backgroundColor;
- }
-
- public BottomMenu setBackgroundColor(@ColorInt int backgroundColor) {
- this.backgroundColor = backgroundColor;
- preRefreshUI();
- return this;
- }
-
- public int getSelection() {
- return selectionIndex;
- }
-
- public ArrayList<Integer> getSelectionList() {
- return selectionItems;
- }
-
- public BottomMenu setSelection(int selectionIndex) {
- this.selectMode = SELECT_MODE.SINGLE;
- this.selectionIndex = selectionIndex;
- this.selectionItems = null;
- menuListAdapter = null;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setSingleSelection() {
- this.selectMode = SELECT_MODE.SINGLE;
- this.selectionIndex = -1;
- this.selectionItems = null;
- menuListAdapter = null;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setSelection(int[] selectionItems) {
- this.selectMode = SELECT_MODE.MULTIPLE;
- this.selectionIndex = -1;
- this.selectionItems = new ArrayList<>();
- if (selectionItems != null) {
- for (int itemIndex : selectionItems) {
- this.selectionItems.add(itemIndex);
- }
- }
- menuListAdapter = null;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setMultiSelection() {
- this.selectMode = SELECT_MODE.MULTIPLE;
- this.selectionIndex = -1;
- this.selectionItems = new ArrayList<>();
- menuListAdapter = null;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setSelection(List<Integer> selectionItems) {
- this.selectMode = SELECT_MODE.MULTIPLE;
- this.selectionIndex = -1;
- this.selectionItems = new ArrayList<>(selectionItems);
- menuListAdapter = null;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setNoSelect() {
- this.selectMode = SELECT_MODE.NONE;
- this.selectionIndex = -1;
- this.selectionItems = null;
- menuListAdapter = null;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setBackgroundColorRes(@ColorRes int backgroundRes) {
- this.backgroundColor = getColor(backgroundRes);
- preRefreshUI();
- return this;
- }
-
- public CharSequence getOkButton() {
- return okText;
- }
-
- public BottomMenu setOkButton(CharSequence okText) {
- this.okText = okText;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setOkButton(int OkTextResId) {
- this.okText = getString(OkTextResId);
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setOkButton(OnDialogButtonClickListener<BottomDialog> OkButtonClickListener) {
- this.okButtonClickListener = OkButtonClickListener;
- return this;
- }
-
- public BottomMenu setOkButton(CharSequence OkText, OnDialogButtonClickListener<BottomDialog> OkButtonClickListener) {
- this.okText = OkText;
- this.okButtonClickListener = OkButtonClickListener;
- return this;
- }
-
- public BottomMenu setOkButton(int OkTextResId, OnDialogButtonClickListener<BottomDialog> OkButtonClickListener) {
- this.okText = getString(OkTextResId);
- this.okButtonClickListener = OkButtonClickListener;
- return this;
- }
-
- public CharSequence getOtherButton() {
- return otherText;
- }
-
- public BottomMenu setOtherButton(CharSequence otherText) {
- this.otherText = otherText;
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setOtherButton(int OtherTextResId) {
- this.otherText = getString(OtherTextResId);
- preRefreshUI();
- return this;
- }
-
- public BottomMenu setOtherButton(OnDialogButtonClickListener<BottomDialog> OtherButtonClickListener) {
- this.otherButtonClickListener = OtherButtonClickListener;
- return this;
- }
-
- public BottomMenu setOtherButton(CharSequence OtherText, OnDialogButtonClickListener<BottomDialog> OtherButtonClickListener) {
- this.otherText = OtherText;
- this.otherButtonClickListener = OtherButtonClickListener;
- return this;
- }
-
- public BottomMenu setOtherButton(int OtherTextResId, OnDialogButtonClickListener<BottomDialog> OtherButtonClickListener) {
- this.otherText = getString(OtherTextResId);
- this.otherButtonClickListener = OtherButtonClickListener;
- return this;
- }
-
- public BottomMenu setMaskColor(@ColorInt int maskColor) {
- this.maskColor = maskColor;
- preRefreshUI();
- return this;
- }
-
- public long getEnterAnimDuration() {
- return enterAnimDuration;
- }
-
- public BottomMenu setEnterAnimDuration(long enterAnimDuration) {
- this.enterAnimDuration = enterAnimDuration;
- return this;
- }
-
- public long getExitAnimDuration() {
- return exitAnimDuration;
- }
-
- public BottomMenu setExitAnimDuration(long exitAnimDuration) {
- this.exitAnimDuration = exitAnimDuration;
- return this;
- }
-
- public SELECT_MODE getSelectMode() {
- return selectMode;
- }
-
- @Override
- protected void shutdown() {
- dismiss();
- }
- }
|