├── .gitignore ├── LICENSE ├── MaterialDialog ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── common │ │ └── design │ │ ├── CheckBox.java │ │ ├── CheckGroup.java │ │ ├── CheckView.java │ │ ├── ListItemAdapter.java │ │ ├── MaterialDialog.java │ │ ├── MaterialParams.java │ │ ├── Utils.java │ │ └── entity │ │ ├── Option.java │ │ └── OptionWrapper.java │ └── res │ ├── anim │ ├── material_dialog_in_anim.xml │ └── material_dialog_out_anim.xml │ ├── drawable-v21 │ └── button.xml │ ├── drawable │ ├── bg_button_normal.xml │ ├── bg_button_pressed.xml │ ├── button.xml │ └── material_card.xml │ ├── layout │ ├── checkbox.xml │ ├── material_dialog_layout.xml │ ├── material_dialog_list_item_layout.xml │ └── material_dialog_listview_layout.xml │ └── values │ ├── attrs.xml │ ├── color.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── app │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── app │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── app │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenRecord └── screen.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | 3 | .idea 4 | 5 | build 6 | 7 | .gradle/2.10/taskArtifacts/cache.properties 8 | 9 | .gradle/2.10/taskArtifacts/cache.properties.lock 10 | 11 | *.iml 12 | 13 | 14 | local.properties 15 | 16 | MaterialDialog/bintrayUpload.txt 17 | 18 | .DS_Store 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MaterialDialog/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | defaultConfig { 7 | minSdkVersion 14 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | } 12 | buildTypes { 13 | release { 14 | minifyEnabled false 15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 16 | } 17 | } 18 | } 19 | 20 | dependencies { 21 | implementation fileTree(dir: 'libs', include: ['*.jar']) 22 | } 23 | 24 | -------------------------------------------------------------------------------- /MaterialDialog/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/liujingxing/Documents/software/android-sdk_r24.0.2/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /MaterialDialog/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /MaterialDialog/src/main/java/com/common/design/CheckBox.java: -------------------------------------------------------------------------------- 1 | package com.common.design; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Color; 6 | import android.util.AttributeSet; 7 | import android.util.TypedValue; 8 | import android.view.Gravity; 9 | import android.view.View; 10 | import android.widget.LinearLayout; 11 | import android.widget.TextView; 12 | 13 | /** 14 | * 本视图包含标题功能 15 | * 16 | * @author liujingxing on 16/7/18. 17 | */ 18 | public class CheckBox extends LinearLayout { 19 | 20 | protected final String NAME_SPACE = "http://schemas.android.com/apk/res/android"; 21 | 22 | public int mDefaultSize; 23 | 24 | private TextView mTextView; 25 | private CheckView mCheckView; 26 | 27 | private OnCheckedChangeListener mListener; 28 | 29 | public CheckBox(Context context) { 30 | this(context, null); 31 | } 32 | 33 | public CheckBox(Context context, AttributeSet attrs) { 34 | super(context, attrs); 35 | setOrientation(HORIZONTAL); 36 | setGravity(Gravity.CENTER_VERTICAL); 37 | if (getBackground() == null) 38 | setBackgroundResource(R.drawable.button); 39 | mDefaultSize = dp2px(context, 10); 40 | initView(context, attrs); 41 | } 42 | 43 | 44 | private void initView(Context context, AttributeSet attrs) { 45 | boolean clickable = attrs.getAttributeBooleanValue(NAME_SPACE, "clickable", true); 46 | setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom()); 47 | setClickable(clickable); 48 | 49 | TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.CheckBox); 50 | String text = ta.getString(R.styleable.CheckBox_text); 51 | int textColor = ta.getColor(R.styleable.CheckBox_textColor, Color.BLACK); 52 | float textSize = ta.getDimension(R.styleable.CheckBox_textSize, dp2px(context, 17)); 53 | int middlePadding = ta.getDimensionPixelOffset(R.styleable.CheckBox_middlePadding, mDefaultSize); 54 | int checkBoxWidth = ta.getDimensionPixelOffset(R.styleable.CheckBox_checkBoxWidth, mDefaultSize * 2); 55 | int checkBoxHeight = ta.getDimensionPixelOffset(R.styleable.CheckBox_checkBoxHeight, mDefaultSize * 2); 56 | ta.recycle(); 57 | 58 | LayoutParams mCheckParams = new LayoutParams(checkBoxWidth, checkBoxHeight); 59 | mCheckView = new CheckView(context, attrs); 60 | 61 | LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 62 | mTextView = new TextView(context); 63 | params.leftMargin = middlePadding; 64 | mTextView.setLayoutParams(params); 65 | mTextView.setText(text); 66 | mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); 67 | mTextView.setTextColor(textColor); 68 | 69 | addView(mCheckView, mCheckParams); 70 | addView(mTextView, params); 71 | 72 | if (!isClickable()) return; 73 | setOnClickListener(new OnClickListener() { 74 | @Override 75 | public void onClick(View v) { 76 | mCheckView.toggle(true); 77 | if (mListener != null) { 78 | mListener.onCheckedChanged(CheckBox.this, mCheckView.isChecked()); 79 | } 80 | } 81 | }); 82 | } 83 | 84 | @Override 85 | public void setPadding(int left, int top, int right, int bottom) { 86 | int defaultPadding = dp2px(getContext(), 10); 87 | if (left == 0) left = defaultPadding; 88 | if (top == 0) top = defaultPadding; 89 | if (right == 0) right = defaultPadding; 90 | if (bottom == 0) bottom = defaultPadding; 91 | super.setPadding(left, top, right, bottom); 92 | } 93 | 94 | public int dp2px(Context context, float dipValue) { 95 | final float scale = context.getResources().getDisplayMetrics().density; 96 | return (int) (dipValue * scale + 0.5f); 97 | } 98 | 99 | public void toggle() { 100 | toggle(false); 101 | } 102 | 103 | public void toggle(boolean anim) { 104 | mCheckView.toggle(anim); 105 | } 106 | 107 | public boolean isChecked() { 108 | return mCheckView.isChecked(); 109 | } 110 | 111 | public void setChecked(boolean checked) { 112 | setChecked(checked, false); 113 | } 114 | 115 | public void setChecked(boolean checked, boolean anim) { 116 | mCheckView.setChecked(checked, anim); 117 | if (mListener != null) { 118 | mListener.onCheckedChanged(this, mCheckView.isChecked()); 119 | } 120 | } 121 | 122 | public void setCheckedColor(int checkedColor) { 123 | mCheckView.setCheckedColor(checkedColor); 124 | } 125 | 126 | public void setShape(int shape) { 127 | mCheckView.setShape(shape); 128 | } 129 | 130 | public void setText(CharSequence text) { 131 | mTextView.setText(text); 132 | } 133 | 134 | public String getText(String text) { 135 | return mTextView.getText().toString(); 136 | } 137 | 138 | public void setOnCheckedChangeListener(OnCheckedChangeListener l) { 139 | this.mListener = l; 140 | } 141 | 142 | public interface OnCheckedChangeListener { 143 | void onCheckedChanged(CheckBox checkBox, boolean isChecked); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /MaterialDialog/src/main/java/com/common/design/CheckGroup.java: -------------------------------------------------------------------------------- 1 | package com.common.design; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.util.AttributeSet; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.AdapterView; 10 | import android.widget.BaseAdapter; 11 | import android.widget.ListView; 12 | 13 | import com.common.design.entity.Option; 14 | import com.common.design.entity.OptionWrapper; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * 获取本实例后调用setOptionWrapper方法传入选项集合即可 20 | * 21 | * @author liujingxing on 16/7/19. 22 | * @see #setOptionWrapper(OptionWrapper) 23 | */ 24 | public class CheckGroup extends ListView implements AdapterView.OnItemClickListener { 25 | 26 | public static final int CIRCLE = 0;//画圆 27 | public static final int SQUARE = 1;//画正方形 28 | 29 | public int mShape = CIRCLE; 30 | 31 | private Context mContext; 32 | 33 | private OptionWrapper mOptionWrapper; 34 | 35 | /** 36 | * 选项适配器 37 | */ 38 | private OptionsAdapter mAdapter; 39 | 40 | /** 41 | * 选中时的颜色 42 | */ 43 | private int mCheckedColor = -1; 44 | 45 | private int leftPadding; 46 | 47 | 48 | public CheckGroup(Context context) { 49 | this(context, null); 50 | } 51 | 52 | public CheckGroup(Context context, AttributeSet attrs) { 53 | super(context, attrs); 54 | mContext = context; 55 | setDividerHeight(0); 56 | setOnItemClickListener(this); 57 | mOptionWrapper = new OptionWrapper(); 58 | mAdapter = new OptionsAdapter(mOptionWrapper.getOptions(), attrs); 59 | 60 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CheckBox); 61 | mShape = typedArray.getInt(R.styleable.CheckBox_shape, CIRCLE); 62 | typedArray.recycle(); 63 | } 64 | 65 | /** 66 | * 传入一个选项集合的封装类后,就可正常显示CheckGroup 67 | * 68 | * @param wrapper 选项集合的封装类 69 | */ 70 | public void setOptionWrapper(OptionWrapper wrapper) { 71 | if (wrapper == null) return; 72 | mOptionWrapper.set(wrapper); 73 | setAdapter(mAdapter); 74 | } 75 | 76 | @Override 77 | public void onItemClick(AdapterView parent, View view, int position, long id) { 78 | if (!mOptionWrapper.isEnabled()) return; 79 | if (mOptionWrapper.isSingleChoice()) { 80 | handleSingleChoice(parent, view, position); 81 | } else { 82 | handleMultiChoice((CheckBox) view, position); 83 | } 84 | if (mOnChangeListener != null) 85 | mOnChangeListener.onChange(parent, view, position); 86 | } 87 | 88 | private void handleMultiChoice(CheckBox checkBox, int position) { 89 | checkBox.toggle(true); 90 | mOptionWrapper.getOptionAt(position).toggle(); 91 | } 92 | 93 | /** 94 | * 处理单选时的情况,可能有人会问:

95 | * 为什么要那么麻烦,为什么不直接循环实体类集合,并将当前单击的item设为true,其他一概设为false,然后刷新适配器即可 96 | *

原因:重新刷新适配器的话,所有的item都需要重新绘制一遍,这样就会加大cup的工作量 97 | *

而通过以下方法的话,只要刷新两个item即可 98 | */ 99 | private void handleSingleChoice(AdapterView parent, View view, int position) { 100 | CheckBox checkBox; 101 | boolean isSet = false;//用于判断有没有将当前单击的item设为true 102 | int chileCount = parent.getChildCount();//得到item条数 103 | for (int i = 0; i < chileCount; i++) { 104 | View v = parent.getChildAt(i); 105 | checkBox = (CheckBox) v; 106 | boolean isCheck = checkBox.isChecked(); 107 | if (i == position && !isCheck) { 108 | //如果是当前单击的item且没有被选中,则设为选中 109 | checkBox.setChecked(true, true); 110 | mOptionWrapper.getOptionAt(i).setCheck(true); 111 | isSet = true; 112 | } else if (i != position && isCheck) { 113 | //如果不是当前单击的item且被选中,则设为不选中,即将上次选中的置为false,并结束循环 114 | checkBox.setChecked(false, true); 115 | mOptionWrapper.getOptionAt(i).setCheck(false); 116 | break; 117 | } 118 | } 119 | if (!isSet) {//如果没有将当前单击的item设为true,则直接通过View找到并设为true 120 | checkBox = (CheckBox) view; 121 | checkBox.setChecked(true, true); 122 | mOptionWrapper.getOptionAt(position).setCheck(true); 123 | } 124 | } 125 | 126 | /** 127 | * 设置选中时CheckBox的颜色 128 | * 129 | * @param checkedColor 选中时的颜色 130 | */ 131 | public void setCheckedColor(int checkedColor) { 132 | mCheckedColor = checkedColor; 133 | } 134 | 135 | /** 136 | * @return 选中的item集合 137 | */ 138 | public List

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.common.design; 18 | 19 | import android.animation.ValueAnimator; 20 | import android.annotation.TargetApi; 21 | import android.content.Context; 22 | import android.content.res.TypedArray; 23 | import android.graphics.Canvas; 24 | import android.graphics.Color; 25 | import android.graphics.Paint; 26 | import android.graphics.Path; 27 | import android.graphics.Point; 28 | import android.graphics.RectF; 29 | import android.os.Build; 30 | import android.os.Bundle; 31 | import android.os.Parcelable; 32 | import android.util.AttributeSet; 33 | import android.view.View; 34 | import android.view.animation.LinearInterpolator; 35 | import android.widget.Checkable; 36 | 37 | 38 | /** 39 | * 本视图仅仅是一个框,不带有标题功能 40 | * 41 | * @author liujingxing 2016/07/02 42 | */ 43 | 44 | class CheckView extends View implements Checkable { 45 | private static final String KEY_INSTANCE_STATE = "InstanceState"; 46 | 47 | 48 | private static final int COLOR_TICK = Color.WHITE; 49 | private static final int COLOR_UNCHECKED = Color.WHITE; 50 | private static final int COLOR_CHECKED = Color.parseColor("#FB4846"); 51 | private static final int COLOR_FLOOR_UNCHECKED = Color.parseColor("#828282"); 52 | 53 | private static final int DEF_DRAW_SIZE = 20; 54 | private static final int DEF_ANIM_DURATION = 300; 55 | 56 | public static final int CIRCLE = 0;//画圆 57 | public static final int SQUARE = 1;//画正方形 58 | public int mShape = CIRCLE; 59 | 60 | private Paint mPaint, mTickPaint, mFloorPaint; 61 | private Point[] mTickPoints; 62 | private Point mCenterPoint; 63 | private Path mTickPath; 64 | 65 | private float mLeftLineDistance, mRightLineDistance, mDrewDistance; 66 | private float mScaleVal = 1.0f, mFloorScale = 1.0f; 67 | private int mWidth, mAnimDuration, mStrokeWidth; 68 | private int mCheckedColor, mUnCheckedColor, mFloorColor, mFloorUnCheckedColor; 69 | private int mRadius;//矩形圆角度数 70 | 71 | private boolean mChecked; 72 | private boolean mTickDrawing; 73 | 74 | public CheckView(Context context) { 75 | this(context, null); 76 | } 77 | 78 | public CheckView(Context context, AttributeSet attrs) { 79 | this(context, attrs, 0); 80 | } 81 | 82 | public CheckView(Context context, AttributeSet attrs, int defStyleAttr) { 83 | super(context, attrs, defStyleAttr); 84 | init(attrs); 85 | } 86 | 87 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 88 | public CheckView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 89 | super(context, attrs, defStyleAttr, defStyleRes); 90 | init(attrs); 91 | } 92 | 93 | private void init(AttributeSet attrs) { 94 | 95 | TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.CheckBox); 96 | int tickColor = ta.getColor(R.styleable.CheckBox_colorTick, COLOR_TICK); 97 | mAnimDuration = ta.getInt(R.styleable.CheckBox_duration, DEF_ANIM_DURATION); 98 | mFloorColor = ta.getColor(R.styleable.CheckBox_colorUncheckedStroke, COLOR_FLOOR_UNCHECKED); 99 | mCheckedColor = ta.getColor(R.styleable.CheckBox_colorChecked, COLOR_CHECKED); 100 | mUnCheckedColor = ta.getColor(R.styleable.CheckBox_colorUnchecked, COLOR_UNCHECKED); 101 | mStrokeWidth = ta.getDimensionPixelSize(R.styleable.CheckBox_strokeWidth, dp2px(getContext(), 2)); 102 | mRadius = ta.getDimensionPixelSize(R.styleable.CheckBox_radius, dp2px(getContext(), 2)); 103 | mShape = ta.getInt(R.styleable.CheckBox_shape, 0); 104 | ta.recycle(); 105 | 106 | mFloorUnCheckedColor = mFloorColor; 107 | mTickPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 108 | mTickPaint.setStyle(Paint.Style.STROKE); 109 | mTickPaint.setStrokeCap(Paint.Cap.ROUND); 110 | mTickPaint.setColor(tickColor); 111 | 112 | mFloorPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 113 | mFloorPaint.setStyle(Paint.Style.FILL); 114 | mFloorPaint.setStrokeCap(Paint.Cap.ROUND); 115 | mFloorPaint.setStrokeWidth(mStrokeWidth); 116 | mFloorPaint.setColor(mFloorColor); 117 | 118 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 119 | mPaint.setStyle(Paint.Style.FILL); 120 | mPaint.setColor(mCheckedColor); 121 | 122 | mTickPath = new Path(); 123 | mCenterPoint = new Point(); 124 | mTickPoints = new Point[3]; 125 | mTickPoints[0] = new Point(); 126 | mTickPoints[1] = new Point(); 127 | mTickPoints[2] = new Point(); 128 | 129 | } 130 | 131 | @Override 132 | protected Parcelable onSaveInstanceState() { 133 | Bundle bundle = new Bundle(); 134 | bundle.putParcelable(KEY_INSTANCE_STATE, super.onSaveInstanceState()); 135 | bundle.putBoolean(KEY_INSTANCE_STATE, isChecked()); 136 | return bundle; 137 | } 138 | 139 | @Override 140 | protected void onRestoreInstanceState(Parcelable state) { 141 | if (state instanceof Bundle) { 142 | Bundle bundle = (Bundle) state; 143 | boolean isChecked = bundle.getBoolean(KEY_INSTANCE_STATE); 144 | setChecked(isChecked); 145 | super.onRestoreInstanceState(bundle.getParcelable(KEY_INSTANCE_STATE)); 146 | return; 147 | } 148 | super.onRestoreInstanceState(state); 149 | } 150 | 151 | @Override 152 | public boolean isChecked() { 153 | return mChecked; 154 | } 155 | 156 | @Override 157 | public void toggle() { 158 | this.setChecked(!isChecked()); 159 | } 160 | 161 | public void toggle(boolean animate) { 162 | this.setChecked(!isChecked(), animate); 163 | } 164 | 165 | @Override 166 | public void setChecked(boolean checked) { 167 | mChecked = checked; 168 | reset(); 169 | invalidate(); 170 | } 171 | 172 | /** 173 | * checked with animation 174 | * 175 | * @param checked checked 176 | * @param animate change with animation 177 | */ 178 | public void setChecked(boolean checked, boolean animate) { 179 | if (animate) { 180 | mTickDrawing = false; 181 | mChecked = checked; 182 | mDrewDistance = 0f; 183 | if (checked) { 184 | startCheckedAnimation(); 185 | } else { 186 | startUnCheckedAnimation(); 187 | } 188 | } else { 189 | this.setChecked(checked); 190 | } 191 | } 192 | 193 | public void setShape(int shape) { 194 | mShape = shape; 195 | } 196 | 197 | public void setCheckedColor(int checkedColor) { 198 | mCheckedColor = checkedColor; 199 | } 200 | 201 | private void reset() { 202 | mTickDrawing = true; 203 | mFloorScale = 1.0f; 204 | mScaleVal = isChecked() ? 0f : 1.0f; 205 | mFloorColor = isChecked() ? mCheckedColor : mFloorUnCheckedColor; 206 | mDrewDistance = isChecked() ? (mLeftLineDistance + mRightLineDistance) : 0; 207 | } 208 | 209 | private int measureSize(int measureSpec) { 210 | int defSize = dp2px(getContext(), DEF_DRAW_SIZE); 211 | int specSize = MeasureSpec.getSize(measureSpec); 212 | int specMode = MeasureSpec.getMode(measureSpec); 213 | 214 | int result = 0; 215 | switch (specMode) { 216 | case MeasureSpec.UNSPECIFIED: 217 | case MeasureSpec.AT_MOST: 218 | result = Math.min(defSize, specSize); 219 | break; 220 | case MeasureSpec.EXACTLY: 221 | result = specSize; 222 | break; 223 | } 224 | return result; 225 | } 226 | 227 | @Override 228 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 229 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 230 | setMeasuredDimension(measureSize(widthMeasureSpec), measureSize(heightMeasureSpec)); 231 | } 232 | 233 | @Override 234 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 235 | mWidth = getMeasuredWidth(); 236 | mCenterPoint.x = mWidth / 2; 237 | mCenterPoint.y = getMeasuredHeight() / 2; 238 | 239 | mTickPoints[0].x = Math.round((float) getMeasuredWidth() / 30 * 7); 240 | mTickPoints[0].y = Math.round((float) getMeasuredHeight() / 30 * 14); 241 | mTickPoints[1].x = Math.round((float) getMeasuredWidth() / 30 * 13); 242 | mTickPoints[1].y = Math.round((float) getMeasuredHeight() / 30 * 20); 243 | mTickPoints[2].x = Math.round((float) getMeasuredWidth() / 30 * 22); 244 | mTickPoints[2].y = Math.round((float) getMeasuredHeight() / 30 * 10); 245 | 246 | mLeftLineDistance = (float) Math.sqrt(Math.pow(mTickPoints[1].x - mTickPoints[0].x, 2) + 247 | Math.pow(mTickPoints[1].y - mTickPoints[0].y, 2)); 248 | mRightLineDistance = (float) Math.sqrt(Math.pow(mTickPoints[2].x - mTickPoints[1].x, 2) + 249 | Math.pow(mTickPoints[2].y - mTickPoints[1].y, 2)); 250 | mTickPaint.setStrokeWidth(mStrokeWidth); 251 | } 252 | 253 | @Override 254 | protected void onDraw(Canvas canvas) { 255 | drawCenter(canvas); 256 | drawBorder(canvas); 257 | drawTick(canvas); 258 | } 259 | 260 | private void drawCenter(Canvas canvas) { 261 | mPaint.setColor(mUnCheckedColor); 262 | float radius = (mCenterPoint.x - mStrokeWidth / 2) * mScaleVal; 263 | if (mShape == CIRCLE) { 264 | canvas.drawCircle(mCenterPoint.x, mCenterPoint.y, radius, mPaint); 265 | } else { 266 | RectF rectf = new RectF(mCenterPoint.x - radius, mCenterPoint.y - radius, mCenterPoint.x + radius, mCenterPoint.y + radius); 267 | canvas.drawRoundRect(rectf, mRadius, mRadius, mPaint); 268 | } 269 | } 270 | 271 | private void drawBorder(Canvas canvas) { 272 | mFloorPaint.setColor(mFloorColor); 273 | mFloorPaint.setStyle(isChecked() ? Paint.Style.FILL : Paint.Style.STROKE); 274 | int radius = mCenterPoint.x; 275 | if (mShape == CIRCLE) { 276 | radius -= (mChecked ? 0 : mStrokeWidth / 2); 277 | canvas.drawCircle(mCenterPoint.x, mCenterPoint.y, radius * mFloorScale, mFloorPaint); 278 | } else { 279 | float scale = radius * mFloorScale; 280 | float left = mCenterPoint.x - scale + (mChecked ? 0 : mStrokeWidth / 2); 281 | float top = mCenterPoint.y - scale + (mChecked ? 0 : mStrokeWidth / 2); 282 | float right = mCenterPoint.x + scale - (mChecked ? 0 : mStrokeWidth / 2); 283 | float bottom = mCenterPoint.y + scale - (mChecked ? 0 : mStrokeWidth / 2); 284 | RectF rectf = new RectF(left, top, right, bottom); 285 | canvas.drawRoundRect(rectf, mRadius, mRadius, mFloorPaint); 286 | } 287 | } 288 | 289 | private void drawTick(Canvas canvas) { 290 | if (mTickDrawing && isChecked()) { 291 | drawTickPath(canvas); 292 | } 293 | } 294 | 295 | private void drawTickPath(Canvas canvas) { 296 | mTickPath.reset(); 297 | // draw left of the tick 298 | if (mDrewDistance < mLeftLineDistance) { 299 | float step = (mWidth / 20.0f) < 3 ? 3 : (mWidth / 20.0f); 300 | mDrewDistance += step; 301 | float stopX = mTickPoints[0].x + (mTickPoints[1].x - mTickPoints[0].x) * mDrewDistance / mLeftLineDistance; 302 | float stopY = mTickPoints[0].y + (mTickPoints[1].y - mTickPoints[0].y) * mDrewDistance / mLeftLineDistance; 303 | 304 | mTickPath.moveTo(mTickPoints[0].x, mTickPoints[0].y); 305 | mTickPath.lineTo(stopX, stopY); 306 | canvas.drawPath(mTickPath, mTickPaint); 307 | 308 | if (mDrewDistance > mLeftLineDistance) { 309 | mDrewDistance = mLeftLineDistance; 310 | } 311 | } else { 312 | 313 | mTickPath.moveTo(mTickPoints[0].x, mTickPoints[0].y); 314 | mTickPath.lineTo(mTickPoints[1].x, mTickPoints[1].y); 315 | canvas.drawPath(mTickPath, mTickPaint); 316 | 317 | // draw right of the tick 318 | if (mDrewDistance < mLeftLineDistance + mRightLineDistance) { 319 | float stopX = mTickPoints[1].x + (mTickPoints[2].x - mTickPoints[1].x) * (mDrewDistance - mLeftLineDistance) / mRightLineDistance; 320 | float stopY = mTickPoints[1].y - (mTickPoints[1].y - mTickPoints[2].y) * (mDrewDistance - mLeftLineDistance) / mRightLineDistance; 321 | 322 | mTickPath.reset(); 323 | mTickPath.moveTo(mTickPoints[1].x, mTickPoints[1].y); 324 | mTickPath.lineTo(stopX, stopY); 325 | canvas.drawPath(mTickPath, mTickPaint); 326 | 327 | float step = (mWidth / 20) < 3 ? 3 : (mWidth / 20); 328 | mDrewDistance += step; 329 | } else { 330 | mTickPath.reset(); 331 | mTickPath.moveTo(mTickPoints[1].x, mTickPoints[1].y); 332 | mTickPath.lineTo(mTickPoints[2].x, mTickPoints[2].y); 333 | canvas.drawPath(mTickPath, mTickPaint); 334 | } 335 | } 336 | 337 | // invalidate 338 | if (mDrewDistance < mLeftLineDistance + mRightLineDistance) { 339 | postDelayed(new Runnable() { 340 | @Override 341 | public void run() { 342 | postInvalidate(); 343 | } 344 | }, 10); 345 | } 346 | } 347 | 348 | private void startCheckedAnimation() { 349 | ValueAnimator animator = ValueAnimator.ofFloat(1.0f, 0f); 350 | animator.setDuration(mAnimDuration / 3 * 2); 351 | animator.setInterpolator(new LinearInterpolator()); 352 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 353 | @Override 354 | public void onAnimationUpdate(ValueAnimator animation) { 355 | mScaleVal = (float) animation.getAnimatedValue(); 356 | mFloorColor = getGradientColor(mUnCheckedColor, mCheckedColor, 1 - mScaleVal); 357 | } 358 | }); 359 | animator.start(); 360 | 361 | ValueAnimator floorAnimator = ValueAnimator.ofFloat(1.0f, 0.8f, 1.0f); 362 | floorAnimator.setDuration(mAnimDuration); 363 | floorAnimator.setInterpolator(new LinearInterpolator()); 364 | floorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 365 | @Override 366 | public void onAnimationUpdate(ValueAnimator animation) { 367 | mFloorScale = (float) animation.getAnimatedValue(); 368 | postInvalidate(); 369 | } 370 | }); 371 | floorAnimator.start(); 372 | 373 | drawTickDelayed(); 374 | } 375 | 376 | private void startUnCheckedAnimation() { 377 | ValueAnimator animator = ValueAnimator.ofFloat(0f, 1.0f); 378 | animator.setDuration(mAnimDuration); 379 | animator.setInterpolator(new LinearInterpolator()); 380 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 381 | @Override 382 | public void onAnimationUpdate(ValueAnimator animation) { 383 | mScaleVal = (float) animation.getAnimatedValue(); 384 | mFloorColor = getGradientColor(mCheckedColor, mFloorUnCheckedColor, mScaleVal); 385 | postInvalidate(); 386 | } 387 | }); 388 | animator.start(); 389 | if (mUnCheckedColor == Color.TRANSPARENT) return; 390 | ValueAnimator floorAnimator = ValueAnimator.ofFloat(1.0f, 0.8f, 1.0f); 391 | floorAnimator.setDuration(mAnimDuration); 392 | floorAnimator.setInterpolator(new LinearInterpolator()); 393 | floorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 394 | @Override 395 | public void onAnimationUpdate(ValueAnimator animation) { 396 | mFloorScale = (float) animation.getAnimatedValue(); 397 | } 398 | }); 399 | floorAnimator.start(); 400 | } 401 | 402 | private void drawTickDelayed() { 403 | postDelayed(new Runnable() { 404 | @Override 405 | public void run() { 406 | mTickDrawing = true; 407 | postInvalidate(); 408 | } 409 | }, mAnimDuration); 410 | } 411 | 412 | private static int getGradientColor(int startColor, int endColor, float percent) { 413 | int sr = (startColor & 0xff0000) >> 0x10; 414 | int sg = (startColor & 0xff00) >> 0x8; 415 | int sb = (startColor & 0xff); 416 | 417 | int er = (endColor & 0xff0000) >> 0x10; 418 | int eg = (endColor & 0xff00) >> 0x8; 419 | int eb = (endColor & 0xff); 420 | 421 | int cr = (int) (sr * (1 - percent) + er * percent); 422 | int cg = (int) (sg * (1 - percent) + eg * percent); 423 | int cb = (int) (sb * (1 - percent) + eb * percent); 424 | return Color.argb(0xff, cr, cg, cb); 425 | } 426 | 427 | public int dp2px(Context context, float dipValue) { 428 | final float scale = context.getResources().getDisplayMetrics().density; 429 | return (int) (dipValue * scale + 0.5f); 430 | } 431 | } 432 | -------------------------------------------------------------------------------- /MaterialDialog/src/main/java/com/common/design/ListItemAdapter.java: -------------------------------------------------------------------------------- 1 | package com.common.design; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.TextView; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | /** 14 | * @author liujingxing on 16/4/21. 15 | */ 16 | class ListItemAdapter extends BaseAdapter { 17 | private Context mContext; 18 | private List mDataList; 19 | 20 | public ListItemAdapter(Context context, CharSequence[] data) { 21 | this(context, Arrays.asList(data)); 22 | } 23 | 24 | public ListItemAdapter(Context context, List data) { 25 | mContext = context; 26 | mDataList = data; 27 | } 28 | 29 | 30 | @Override 31 | public int getCount() { 32 | return mDataList.size(); 33 | } 34 | 35 | @Override 36 | public Object getItem(int position) { 37 | return mDataList.get(position); 38 | } 39 | 40 | @Override 41 | public long getItemId(int position) { 42 | return position; 43 | } 44 | 45 | @Override 46 | public View getView(int position, View convertView, ViewGroup parent) { 47 | ViewHolder holder; 48 | if (convertView == null) { 49 | convertView = LayoutInflater.from(mContext).inflate(R.layout.material_dialog_list_item_layout, null); 50 | holder = new ViewHolder(convertView); 51 | convertView.setTag(holder); 52 | } else { 53 | holder = (ViewHolder) convertView.getTag(); 54 | } 55 | holder.mTextView.setText(mDataList.get(position)); 56 | return convertView; 57 | } 58 | 59 | class ViewHolder { 60 | TextView mTextView; 61 | 62 | public ViewHolder(View view) { 63 | mTextView = (TextView) view.findViewById(R.id.text); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /MaterialDialog/src/main/java/com/common/design/MaterialDialog.java: -------------------------------------------------------------------------------- 1 | package com.common.design; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.graphics.Color; 7 | import android.graphics.drawable.ColorDrawable; 8 | import android.graphics.drawable.Drawable; 9 | import android.os.Build; 10 | import android.text.TextUtils; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.view.Window; 15 | import android.view.WindowManager; 16 | import android.widget.AdapterView; 17 | import android.widget.Button; 18 | import android.widget.LinearLayout; 19 | import android.widget.ListAdapter; 20 | import android.widget.ListView; 21 | import android.widget.TextView; 22 | 23 | import com.common.design.entity.OptionWrapper; 24 | 25 | import java.util.Arrays; 26 | import java.util.List; 27 | 28 | /** 29 | * @author liujingxing on 2016/04/20 30 | */ 31 | public class MaterialDialog extends Dialog { 32 | 33 | public MaterialDialog(Context context) { 34 | this(context, R.style.MaterialDialogStyle); 35 | } 36 | 37 | public MaterialDialog(Context context, int theme) { 38 | super(context, theme); 39 | } 40 | 41 | 42 | interface BaseListener { 43 | } 44 | 45 | /** 46 | * 可用于ListView点击item的监听,以及mPositiveButton,mNegativeButton,mNeutralButton3个按钮的监听 47 | */ 48 | public interface OnClickListener extends BaseListener { 49 | /** 50 | * @param dialog MaterialDialog接口对象 51 | * @param which 作为ListView中item的监听方法时,代表单击item的位置,即position 52 | * 作为mPositiveButton,mNegativeButton,mNeutralButton3个按钮的监听时,代表按钮的类型,即代表哪一个按钮 53 | * @return true 代表拦截后续的操作,即Dialog不会消失;反之,Dialog消失 54 | */ 55 | boolean onClick(DialogInterface dialog, int which); 56 | } 57 | 58 | /** 59 | * 单选框最后选择结果监听器 60 | */ 61 | public interface OnSCResultListener extends BaseListener { 62 | /** 63 | * 单选框最后选择结果监听方法 64 | * 65 | * @param dialog MaterialDialog接口对象 66 | * @param checkItem 单选框为true的位置,即选中的item的position 67 | * @return true 代表自己拦截后续的操作,即Dialog不会消失,反之,Dialog消失 68 | */ 69 | boolean onClick(DialogInterface dialog, int checkItem); 70 | } 71 | 72 | /** 73 | * 复选框最后选择结果监听器 74 | */ 75 | public interface OnMCResultListener extends BaseListener { 76 | /** 77 | * 复选框最后选择结果监听方法 78 | * 79 | * @param dialog MaterialDialog接口对象 80 | * @param checkItems 所有为true的复选框的位置的集合 81 | * @return true 代表自己拦截后续的操作,即Dialog不会消失,反之,Dialog消失 82 | */ 83 | boolean onClick(DialogInterface dialog, List checkItems); 84 | } 85 | 86 | /** 87 | * 复选框单击item时的监听器 88 | */ 89 | public interface OnMultiChoiceClickListener extends BaseListener { 90 | /** 91 | * 复选框单击item时的监听方法 92 | * 93 | * @param dialog MaterialDialog接口对象 94 | * @param position 单击item的位置 95 | * @param isChecked 单击item后复选框的状态 96 | */ 97 | void onClick(DialogInterface dialog, int position, boolean isChecked); 98 | } 99 | 100 | public static class Builder { 101 | private MaterialParams P; 102 | 103 | private MaterialDialog mMaterialDialog; 104 | 105 | private View mContentView; 106 | 107 | private LinearLayout mMaterialLayout; 108 | private TextView mTitleView; 109 | 110 | private LinearLayout mBottomLayout; 111 | private Button mPositiveButton; 112 | private Button mNegativeButton; 113 | private Button mNeutralButton; 114 | 115 | private TextView mMessageView; 116 | private LinearLayout mContentLayout; 117 | 118 | 119 | public Builder(Context context) { 120 | P = new MaterialParams(context); 121 | 122 | mContentView = LayoutInflater.from(context).inflate(R.layout.material_dialog_layout, null); 123 | 124 | mMaterialDialog = new MaterialDialog(context); 125 | mMaterialDialog.setContentView(mContentView); 126 | 127 | 128 | mMaterialLayout = (LinearLayout) mContentView.findViewById(R.id.ll_material_layout); 129 | mTitleView = (TextView) mContentView.findViewById(R.id.tv_title); 130 | 131 | mContentLayout = (LinearLayout) mContentView.findViewById(R.id.ll_content_layout); 132 | mMessageView = (TextView) mContentLayout.findViewById(R.id.tv_message); 133 | 134 | mBottomLayout = (LinearLayout) mContentView.findViewById(R.id.ll_bottom_layout); 135 | mPositiveButton = (Button) mBottomLayout.findViewById(R.id.btn_positive); 136 | mNegativeButton = (Button) mBottomLayout.findViewById(R.id.btn_negative); 137 | mNeutralButton = (Button) mBottomLayout.findViewById(R.id.btn_neutral); 138 | } 139 | 140 | 141 | public Builder setTitle(int resId) { 142 | P.setTitle(resId); 143 | return this; 144 | } 145 | 146 | public Builder setTitle(CharSequence title) { 147 | P.setTitle(title); 148 | return this; 149 | } 150 | 151 | public Builder setMessage(int resId) { 152 | P.setMessage(resId); 153 | return this; 154 | } 155 | 156 | public Builder setMessage(CharSequence message) { 157 | P.setMessage(message); 158 | return this; 159 | } 160 | 161 | public Builder setPositiveButton(OnClickListener listener) { 162 | return setPositiveButton(R.string.confirm, listener); 163 | } 164 | 165 | /** 166 | * 如果想知道多选框最后的选择结果,调用本方法传入一个监听器即可,实际上是一个变相的PositiveButton,只是传的监听器不一样 167 | * 168 | * @param listener 多选框最后结果监听器 169 | */ 170 | public Builder setMCResultButton(OnMCResultListener listener) { 171 | P.setPositive(R.string.confirm); 172 | P.setPositiveListener(listener); 173 | return this; 174 | } 175 | 176 | /** 177 | * 如果想知道单选框最后的选择结果,调用本方法传入一个监听器即可,实际上是一个变相的PositiveButton,只是传的监听器不一样 178 | * 179 | * @param listener 单选框最后结果监听器 180 | */ 181 | public Builder setSCResultButton(OnSCResultListener listener) { 182 | P.setPositive(R.string.confirm); 183 | P.setPositiveListener(listener); 184 | return this; 185 | } 186 | 187 | public Builder setPositiveButton(int resId, OnClickListener listener) { 188 | P.setPositive(resId); 189 | P.setPositiveListener(listener); 190 | return this; 191 | } 192 | 193 | public Builder setPositiveButton(CharSequence text, OnClickListener listener) { 194 | P.setPositive(text); 195 | P.setPositiveListener(listener); 196 | return this; 197 | } 198 | 199 | public Builder setNegativeButton(final OnClickListener listener) { 200 | return setNegativeButton(R.string.cancel, listener); 201 | } 202 | 203 | public Builder setNegativeButton(int resId, final OnClickListener listener) { 204 | P.setNegative(resId); 205 | P.mNegativeListener = listener; 206 | return this; 207 | } 208 | 209 | public Builder setNegativeButton(CharSequence text, final OnClickListener listener) { 210 | P.setNegative(text); 211 | P.mNegativeListener = listener; 212 | return this; 213 | } 214 | 215 | public Builder setNeutralButton(int resId, final OnClickListener listener) { 216 | P.setNeutral(resId); 217 | P.mNeutralListener = listener; 218 | return this; 219 | } 220 | 221 | public Builder setNeutralButton(CharSequence text, final OnClickListener listener) { 222 | P.setNeutral(text); 223 | P.mNeutralListener = listener; 224 | return this; 225 | } 226 | 227 | public Builder setItems(int itemsId, OnClickListener listener) { 228 | return setItems(P.getContext().getResources().getStringArray(itemsId), listener); 229 | } 230 | 231 | public Builder setItems(CharSequence[] items, final OnClickListener listener) { 232 | return setItems(Arrays.asList(items), listener); 233 | } 234 | 235 | public Builder setItems(List items, final OnClickListener listener) { 236 | ListItemAdapter adapter = new ListItemAdapter(P.getContext(), items); 237 | return setAdapter(adapter, listener); 238 | } 239 | 240 | 241 | public Builder setSingleChoiceItems(int itemsId, OnClickListener listener) { 242 | return setSingleChoiceItems(itemsId, 0, listener); 243 | } 244 | 245 | public Builder setSingleChoiceItems(int itemsId, int checkItem, OnClickListener listener) { 246 | return setSingleChoiceItems(P.getContext().getResources().getStringArray(itemsId), checkItem, listener); 247 | } 248 | 249 | public Builder setSingleChoiceItems(CharSequence[] items, OnClickListener listener) { 250 | return setSingleChoiceItems(items, 0, listener); 251 | } 252 | 253 | public Builder setSingleChoiceItems(CharSequence[] items, int checkItem, OnClickListener listener) { 254 | return setSingleChoiceItems(Arrays.asList(items), checkItem, listener); 255 | } 256 | 257 | public Builder setSingleChoiceItems(List items, OnClickListener listener) { 258 | return setSingleChoiceItems(items, 0, listener); 259 | } 260 | 261 | /** 262 | * 以上重载方法最终都会调用本方法实现单选框 263 | * 264 | * @param items 选项集合 265 | * @param checkItem 默认选中的item的position 266 | * @param listener 监听器 267 | */ 268 | public Builder setSingleChoiceItems(List items, int checkItem, final OnClickListener listener) { 269 | OptionWrapper optionWrapper = new OptionWrapper(true); 270 | optionWrapper.setOptions(items); 271 | optionWrapper.setChecked(checkItem); 272 | CheckGroup checkGroup = new CheckGroup(P.getContext()); 273 | checkGroup.setLeftPadding(P.getContext().getResources().getDimensionPixelOffset(R.dimen.content_title_paddingLeft)); 274 | checkGroup.setOptionWrapper(optionWrapper); 275 | checkGroup.setOnChangeListener(new CheckGroup.OnChangeListener() { 276 | @Override 277 | public void onChange(AdapterView parent, View view, int position) { 278 | if (listener == null) return; 279 | listener.onClick(mMaterialDialog, position); 280 | } 281 | }); 282 | setContentView(checkGroup, false); 283 | return this; 284 | } 285 | 286 | public Builder setMultiChoiceItems(int itemsId, OnMultiChoiceClickListener listener) { 287 | return setMultiChoiceItems(itemsId, null, listener); 288 | } 289 | 290 | public Builder setMultiChoiceItems(int itemsId, int[] checkedItems, OnMultiChoiceClickListener listener) { 291 | return setMultiChoiceItems(P.getContext().getResources().getStringArray(itemsId), checkedItems, listener); 292 | } 293 | 294 | public Builder setMultiChoiceItems(CharSequence[] items, OnMultiChoiceClickListener listener) { 295 | return setMultiChoiceItems(items, null, listener); 296 | } 297 | 298 | public Builder setMultiChoiceItems(CharSequence[] items, int[] checkedItems, OnMultiChoiceClickListener listener) { 299 | return setMultiChoiceItems(Arrays.asList(items), checkedItems, listener); 300 | } 301 | 302 | public Builder setMultiChoiceItems(List items, OnMultiChoiceClickListener listener) { 303 | return setMultiChoiceItems(items, null, listener); 304 | } 305 | 306 | /** 307 | * 以上重载方法最终都会调用本方法实现多选框功能 308 | * 309 | * @param items 选项集合 310 | * @param checkedItems 默认选中的item的position集合 311 | * @param listener 监听器 312 | */ 313 | public Builder setMultiChoiceItems(List items, int[] checkedItems, final OnMultiChoiceClickListener listener) { 314 | OptionWrapper optionWrapper = new OptionWrapper(); 315 | optionWrapper.setOptions(items); 316 | optionWrapper.setChecked(Utils.getArray(checkedItems)); 317 | CheckGroup checkGroup = new CheckGroup(P.getContext()); 318 | checkGroup.setLeftPadding(P.getContext().getResources().getDimensionPixelOffset(R.dimen.content_title_paddingLeft)); 319 | checkGroup.setOptionWrapper(optionWrapper); 320 | checkGroup.setShape(CheckGroup.SQUARE); 321 | checkGroup.setOnChangeListener(new CheckGroup.OnChangeListener() { 322 | @Override 323 | public void onChange(AdapterView parent, View view, int position) { 324 | if (listener == null) return; 325 | CheckBox checkBox = (CheckBox) view; 326 | listener.onClick(mMaterialDialog, position, checkBox.isChecked()); 327 | } 328 | }); 329 | setContentView(checkGroup, false); 330 | return this; 331 | } 332 | 333 | private Builder setAdapter(ListAdapter listAdapter, final OnClickListener listener) { 334 | ListView listView = (ListView) LayoutInflater.from(P.getContext()).inflate(R.layout.material_dialog_listview_layout, null); 335 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 336 | @Override 337 | public void onItemClick(AdapterView parent, View view, int position, long id) { 338 | if (listener == null || !listener.onClick(mMaterialDialog, position)) { 339 | mMaterialDialog.dismiss(); 340 | } 341 | } 342 | }); 343 | listView.setAdapter(listAdapter); 344 | setContentView(listView, false); 345 | return this; 346 | } 347 | 348 | public Builder setContentView(View contentView, boolean needSpace) { 349 | ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams( 350 | ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 351 | contentView.setLayoutParams(layoutParams); 352 | if (!needSpace) { 353 | mContentLayout.setPadding(0, 0, 0, 0); 354 | } 355 | if (mContentLayout != null) { 356 | mContentLayout.removeAllViews(); 357 | mContentLayout.addView(contentView); 358 | } 359 | return this; 360 | } 361 | 362 | public Builder setContentView(View contentView) { 363 | return setContentView(contentView, true); 364 | } 365 | 366 | public Builder setContentView(int layoutResId) { 367 | setContentView(LayoutInflater.from(P.getContext()).inflate(layoutResId, null)); 368 | return this; 369 | } 370 | 371 | public Builder setBackground(Drawable drawable) { 372 | mMaterialLayout.setBackgroundDrawable(drawable); 373 | return this; 374 | } 375 | 376 | public Builder setBackground(int resId) { 377 | mMaterialLayout.setBackgroundResource(resId); 378 | return this; 379 | } 380 | 381 | public Builder setLayout(int width, int height) { 382 | P.width = width; 383 | P.height = height; 384 | return this; 385 | } 386 | 387 | /** 388 | * 通过比例设置Dialog的宽高 389 | * 390 | * @param widthPercent 0~1之间 391 | * @param heightPercent 0~1之间 392 | */ 393 | public Builder setLayout(float widthPercent, float heightPercent) { 394 | P.width = (int) (P.getScreenWidth() * widthPercent); 395 | P.height = (int) (P.getScreenHeight() * heightPercent); 396 | return this; 397 | } 398 | 399 | public Builder setWidth(int width) { 400 | P.width = width; 401 | return this; 402 | } 403 | 404 | /** 405 | * 通过比例设置Dialog的宽度 406 | * 407 | * @param percent 0~1之间 408 | */ 409 | public Builder setWidth(float percent) { 410 | P.width = (int) (P.getScreenWidth() * percent); 411 | return this; 412 | } 413 | 414 | public Builder setHeight(int height) { 415 | P.height = height; 416 | return this; 417 | } 418 | 419 | /** 420 | * 通过比例设置Dialog的高度 421 | * 422 | * @param percent 0~1之间 423 | */ 424 | public Builder setHeight(float percent) { 425 | P.height = (int) (P.getScreenHeight() * percent); 426 | return this; 427 | } 428 | 429 | public Builder setCanceledOnTouchOutside(boolean canceledOnTouchOutside) { 430 | mMaterialDialog.setCanceledOnTouchOutside(canceledOnTouchOutside); 431 | return this; 432 | } 433 | 434 | public Builder setCancelable(boolean cancelable) { 435 | mMaterialDialog.setCancelable(cancelable); 436 | return this; 437 | } 438 | 439 | public Builder setOnDismissListener(OnDismissListener listener) { 440 | mMaterialDialog.setOnDismissListener(listener); 441 | return this; 442 | } 443 | 444 | public MaterialDialog create() { 445 | setAttributes(mMaterialDialog.getWindow()); 446 | 447 | setText(P.getTitle(), mTitleView); 448 | setText(P.getMessage(), mMessageView); 449 | setText(P.getPositiveText(), mPositiveButton, P.getPositiveListener()); 450 | setText(P.getNegativeText(), mNegativeButton, P.mNegativeListener); 451 | setText(P.getNeutralText(), mNeutralButton, P.mNeutralListener); 452 | 453 | if (!P.haveButton()) { 454 | mBottomLayout.setVisibility(View.GONE); 455 | } 456 | 457 | return mMaterialDialog; 458 | } 459 | 460 | private void setAttributes(Window window) { 461 | window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | 462 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 463 | window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE); 464 | window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 465 | window.setLayout(P.width, P.height); 466 | if (Build.VERSION.SDK_INT >= 14) { 467 | window.setDimAmount(0.6f); 468 | } else { 469 | WindowManager.LayoutParams attributes = window.getAttributes(); 470 | attributes.dimAmount = 0.6f; 471 | window.setAttributes(attributes); 472 | } 473 | } 474 | 475 | public void show() { 476 | create().show(); 477 | } 478 | 479 | private void setText(CharSequence text, TextView textView) { 480 | setText(text, textView, null); 481 | } 482 | 483 | private void setText(CharSequence text, TextView textView, final BaseListener listener) { 484 | if (TextUtils.isEmpty(text)) { 485 | textView.setVisibility(View.GONE); 486 | return; 487 | } 488 | textView.setText(text); 489 | if (!(textView instanceof Button)) return; 490 | textView.setOnClickListener(new View.OnClickListener() { 491 | @Override 492 | public void onClick(View v) { 493 | int which; 494 | if (v == mPositiveButton) { 495 | which = DialogInterface.BUTTON_POSITIVE; 496 | } else if (v == mNegativeButton) { 497 | which = DialogInterface.BUTTON_NEGATIVE; 498 | } else { 499 | which = DialogInterface.BUTTON_NEUTRAL; 500 | } 501 | if (listener == null) { 502 | mMaterialDialog.dismiss(); 503 | return; 504 | } 505 | boolean isIntercept = false; 506 | if (listener instanceof OnClickListener) { 507 | isIntercept = ((OnClickListener) listener).onClick(mMaterialDialog, which); 508 | } else { 509 | View childAt = mContentLayout.getChildAt(0); 510 | if (childAt instanceof CheckGroup) { 511 | CheckGroup checkGroup = (CheckGroup) childAt; 512 | if (listener instanceof OnSCResultListener) { 513 | isIntercept = ((OnSCResultListener) listener).onClick(mMaterialDialog, checkGroup.getCheckedIndex().get(0)); 514 | } else if (listener instanceof OnMCResultListener) { 515 | isIntercept = ((OnMCResultListener) listener).onClick(mMaterialDialog, checkGroup.getCheckedIndex()); 516 | } 517 | } 518 | } 519 | if (!isIntercept) { 520 | mMaterialDialog.dismiss(); 521 | } 522 | } 523 | }); 524 | } 525 | } 526 | } 527 | 528 | -------------------------------------------------------------------------------- /MaterialDialog/src/main/java/com/common/design/MaterialParams.java: -------------------------------------------------------------------------------- 1 | package com.common.design; 2 | 3 | import android.content.Context; 4 | import android.view.WindowManager; 5 | 6 | /** 7 | * 设置对话框的一些参数 8 | * 9 | * @author liujingxing on 16/4/20. 10 | */ 11 | class MaterialParams { 12 | 13 | Context mContext; 14 | int mTitleResId = -1;//标题资源id 15 | CharSequence mTitle;//标题 16 | int mMessageResId = -1;//内容资源id 17 | CharSequence mMessage;//内容 18 | 19 | int mPositiveResId = -1;//确定按钮文本资源id 20 | CharSequence mPositiveText;//确定按钮文本 21 | int mNegativeResId = -1;//取消按钮文本资源id 22 | CharSequence mNegativeText;//取消按钮文本 23 | int mNeutralResId = -1;//中间按钮文本资源id 24 | CharSequence mNeutralText;//中间按钮文本 25 | 26 | int width;//对话框宽度 27 | int height;//对话框高度 28 | 29 | //确定、取消、中间按钮单击监听器 30 | MaterialDialog.OnClickListener mPositiveListener, mNegativeListener, mNeutralListener; 31 | MaterialDialog.OnSCResultListener mOnSCResultListener;//单选对话框确定按钮监听器,会返回最终的选择结果 32 | MaterialDialog.OnMCResultListener mOnMCResultListener;//多选对话框确定按钮监听器,会返回最终的选择结果 33 | 34 | MaterialParams(Context context) { 35 | mContext = context; 36 | width = (int) (getScreenWidth() * 0.85f); 37 | height = WindowManager.LayoutParams.WRAP_CONTENT; 38 | } 39 | 40 | CharSequence getTitle() { 41 | return mTitleResId != -1 ? getString(mTitleResId) : mTitle; 42 | } 43 | 44 | void setTitle(int titleResId) { 45 | mTitleResId = titleResId; 46 | mTitle = null; 47 | } 48 | 49 | void setTitle(CharSequence title) { 50 | mTitle = title; 51 | mTitleResId = -1; 52 | } 53 | 54 | CharSequence getMessage() { 55 | return mMessageResId != -1 ? getString(mMessageResId) : mMessage; 56 | } 57 | 58 | void setMessage(int messageResId) { 59 | mMessageResId = messageResId; 60 | mMessage = null; 61 | } 62 | 63 | void setMessage(CharSequence message) { 64 | mMessage = message; 65 | mMessageResId = -1; 66 | } 67 | 68 | CharSequence getNegativeText() { 69 | return mNegativeResId != -1 ? getString(mNegativeResId) : mNegativeText; 70 | } 71 | 72 | boolean haveButton() { 73 | return getPositiveText() != null || getNegativeText() != null || getNeutralText() != null; 74 | } 75 | 76 | void setNegative(int negativeResId) { 77 | mNegativeResId = negativeResId; 78 | mNegativeText = null; 79 | } 80 | 81 | 82 | void setNegative(CharSequence negativeText) { 83 | mNegativeText = negativeText; 84 | mNegativeResId = -1; 85 | } 86 | 87 | CharSequence getPositiveText() { 88 | return mPositiveResId != -1 ? getString(mPositiveResId) : mPositiveText; 89 | } 90 | 91 | 92 | void setPositive(int positiveResId) { 93 | mPositiveResId = positiveResId; 94 | mPositiveText = null; 95 | } 96 | 97 | 98 | void setPositive(CharSequence positiveText) { 99 | mPositiveText = positiveText; 100 | mPositiveResId = -1; 101 | } 102 | 103 | MaterialDialog.BaseListener getPositiveListener() { 104 | if (mOnSCResultListener != null) return mOnSCResultListener; 105 | if (mOnMCResultListener != null) return mOnMCResultListener; 106 | return mPositiveListener; 107 | } 108 | 109 | void setPositiveListener(MaterialDialog.BaseListener listener) { 110 | if (listener instanceof MaterialDialog.OnSCResultListener) { 111 | mOnSCResultListener = (MaterialDialog.OnSCResultListener) listener; 112 | } else if (listener instanceof MaterialDialog.OnMCResultListener) { 113 | mOnMCResultListener = (MaterialDialog.OnMCResultListener) listener; 114 | } else { 115 | mPositiveListener = (MaterialDialog.OnClickListener) listener; 116 | } 117 | } 118 | 119 | CharSequence getNeutralText() { 120 | return mNeutralResId != -1 ? getString(mNeutralResId) : mNeutralText; 121 | } 122 | 123 | 124 | void setNeutral(int neutralResId) { 125 | mNeutralResId = neutralResId; 126 | } 127 | 128 | 129 | void setNeutral(CharSequence neutralText) { 130 | mNeutralText = neutralText; 131 | } 132 | 133 | Context getContext() { 134 | return mContext; 135 | } 136 | 137 | String getString(int resId) { 138 | return mContext.getString(resId); 139 | } 140 | 141 | public int getScreenWidth() { 142 | return mContext.getResources().getDisplayMetrics().widthPixels; 143 | } 144 | 145 | public int getScreenHeight() { 146 | return mContext.getResources().getDisplayMetrics().heightPixels; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /MaterialDialog/src/main/java/com/common/design/Utils.java: -------------------------------------------------------------------------------- 1 | package com.common.design; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * @author liujingxing on 16/8/9. 8 | */ 9 | class Utils { 10 | static List getArray(int[] array) { 11 | if (array == null || array.length == 0) return null; 12 | List list = new ArrayList<>(); 13 | for (int i : array) { 14 | list.add(i); 15 | } 16 | return list; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MaterialDialog/src/main/java/com/common/design/entity/Option.java: -------------------------------------------------------------------------------- 1 | package com.common.design.entity; 2 | 3 | /** 4 | * 选项实体类 5 | * 6 | * @author liujingxing on 16/7/24. 7 | */ 8 | public class Option { 9 | private CharSequence title; 10 | private boolean isCheck; 11 | 12 | private boolean enabled = true; 13 | 14 | public Option() { 15 | } 16 | 17 | public Option(CharSequence title) { 18 | this.title = title; 19 | } 20 | 21 | public Option(CharSequence title, boolean isCheck) { 22 | this.title = title; 23 | this.isCheck = isCheck; 24 | } 25 | 26 | public Option(boolean enabled, boolean isCheck, CharSequence title) { 27 | this.enabled = enabled; 28 | this.isCheck = isCheck; 29 | this.title = title; 30 | } 31 | 32 | public boolean isCheck() { 33 | return isCheck; 34 | } 35 | 36 | public void setCheck(boolean check) { 37 | isCheck = check; 38 | } 39 | 40 | public void toggle() { 41 | isCheck = !isCheck; 42 | } 43 | 44 | public boolean isEnabled() { 45 | return enabled; 46 | } 47 | 48 | public void setEnabled(boolean enabled) { 49 | this.enabled = enabled; 50 | } 51 | 52 | public CharSequence getTitle() { 53 | return title; 54 | } 55 | 56 | public void setTitle(CharSequence title) { 57 | this.title = title; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /MaterialDialog/src/main/java/com/common/design/entity/OptionWrapper.java: -------------------------------------------------------------------------------- 1 | package com.common.design.entity; 2 | 3 | import android.text.TextUtils; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | /** 10 | * 选项集合的封装类,默认多选 11 | * 12 | * @author liujingxing on 16/7/24. 13 | */ 14 | public class OptionWrapper { 15 | /** 16 | * 选项集合 17 | */ 18 | private List