├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── build.gradle
├── example
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── cn
│ │ └── carbs
│ │ └── android
│ │ └── mddialog
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── cn
│ │ │ └── carbs
│ │ │ └── android
│ │ │ └── mddialog
│ │ │ └── ActivityMain.java
│ └── res
│ │ ├── drawable
│ │ └── color_cursor.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── content_dialog.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
│ └── cn
│ └── carbs
│ └── android
│ └── mddialog
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── cn
│ │ └── carbs
│ │ └── android
│ │ └── library
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── cn
│ │ │ └── carbs
│ │ │ └── android
│ │ │ └── library
│ │ │ └── MDDialog.java
│ └── res
│ │ ├── layout
│ │ └── layout_mddialog.xml
│ │ └── values
│ │ ├── strings.xml
│ │ └── values_mddialog.xml
│ └── test
│ └── java
│ └── cn
│ └── carbs
│ └── android
│ └── library
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | MDDialog
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MDDialog
2 |
3 | [](http://android-arsenal.com/details/1/3822)
4 | * [English](#english)
5 |
6 | ## 前言
7 | `MDDialog`是一款`Material Designed`风格的`Dialog`,可以灵活定制其内容以及显示方式,如:可以添加中间的`ContentView`,可以对`ContentView`自由的添加代码操作,如添加点击事件等等;对于多个选项风格的dialog,提供了直接设置多个选项的功能,并提供了精细的UI按下效果、点击回调函数等等。
8 |
9 | ## 介绍
10 | 这款`Material Designed`风格的`Dialog`的设计灵感来自于MD设计理念,你可以通过使用和`AlertDialog`相似的代码来构建`MDDialog`。
11 |
12 | `MDDialog`具有多种有趣的属性:
13 | 1. 可以设置显示/隐藏title、显示/隐藏 确定/取消按钮(或者同时隐藏两个button,具体UI效果可见微信的选择对话框);
14 | 2. 可以向`MDDialog`添加一个自定义的`View`,同时可以在构建`MDDialog`时,使用`setContentViewOperator(...)`函数,添加操作自定义view的代码;
15 | 3. 可以给`MDDialog`设置`String[] messages`,构建`MDDialog`的`builder`中提供了响应点击每一个`String`的回调函数,即,通过`setOnItemClickListener(...)`设置点击每一条目的回调;
16 | 4. 可以自由定制`MDialog`的四个角的半径大小;
17 | 5. `MDDialog`自动为每个`message`提供了按下效果,且按下效果会随着此`item`是否具有圆角而改变;
18 | 6. 可以通过两种方式设置`MDDialog`的宽度,使用宽度占整个屏幕宽度的比值,或使用是精确的尺寸;
19 |
20 |
21 | ## 截图
22 |
23 | 
24 |
25 |
26 | 
27 |
28 |
29 | ## 使用
30 | 首先添加依赖
31 | ```
32 | dependencies {
33 | compile 'cn.carbs.android:MDDialog:1.0.0'
34 | }
35 | ```
36 | 在`java`代码中构造`MDDialog`
37 | ```
38 | 可以构建两种不同模式的MDDialog,这两种模式不能够同时使用
39 | 1.为MDDialog设置自定义View:
40 | new MDDialog.Builder(ActivityMain.this)
41 | // .setContentView(customizedView)
42 | .setContentView(R.layout.content_dialog)
43 | .setContentViewOperator(new MDDialog.ContentViewOperator() {
44 | @Override
45 | public void operate(View contentView) {//这里的contentView就是上面代码中传入的自定义的View或者layout资源inflate出来的view
46 | EditText et = (EditText) contentView.findViewById(R.id.edit0);
47 | et.setHint("hint set in operator");
48 | }
49 | })
50 | .setTitle("添加")
51 | .setNegativeButton(new View.OnClickListener() {
52 | @Override
53 | public void onClick(View v) {
54 | }
55 | })
56 | .setPositiveButton(new View.OnClickListener() {
57 | @Override
58 | public void onClick(View v) {
59 | }
60 | })
61 | .setPositiveButtonMultiListener(new MDDialog.OnMultiClickListener() {
62 | @Override
63 | public void onClick(View clickedView, View contentView) {
64 | //这里的contentView就是上面代码中传入的自定义的View或者layout资源inflate出来的view,目的是方便在确定/取消按键中对contentView进行操作,如获取数据等。
65 | EditText et = (EditText) contentView.findViewById(R.id.edit0);
66 | Toast.makeText(getApplicationContext(), "edittext 0 : " + et.getText(), Toast.LENGTH_SHORT).show();
67 | }
68 | })
69 | .setNegativeButtonMultiListener(new MDDialog.OnMultiClickListener() {
70 | @Override
71 | public void onClick(View clickedView, View contentView) {
72 | EditText et = (EditText) contentView.findViewById(R.id.edit1);
73 | Toast.makeText(getApplicationContext(), "edittext 1 : " + et.getText(), Toast.LENGTH_SHORT).show();
74 | }
75 | })
76 | .setWidthMaxDp(600)
77 | // .setShowTitle(false)//default is true
78 | // .setShowButtons(true)//default is true
79 | .create()
80 | .show();
81 |
82 | 2.设置 String[] messages,每一个String都将对应一个item,具体可以看效果图
83 |
84 | final String[] messages = new String[]{"两个黄鹂鸣翠柳,一行白鹭上青天。",
85 | "窗含西岭千秋雪,门泊东吴万里船。",
86 | "君不见,黄河之水天上来,奔流到海不复回;君不见,高堂明镜悲白发,朝如青丝暮如雪。"};
87 | new MDDialog.Builder(ActivityMain.this)
88 | .setMessages(messages)
89 | .setTitle("一首古诗")
90 | .setNegativeButton(new View.OnClickListener() {
91 | @Override
92 | public void onClick(View v) {
93 | }
94 | })
95 | .setPositiveButton(new View.OnClickListener() {
96 | @Override
97 | public void onClick(View v) {
98 | Toast.makeText(getApplicationContext(), "positive", Toast.LENGTH_SHORT).show();
99 | }
100 | })
101 | .setOnItemClickListener(new MDDialog.OnItemClickListener() {
102 | @Override
103 | public void onItemClicked(int index) {
104 | Toast.makeText(getApplicationContext(), messages[index], Toast.LENGTH_SHORT).show();
105 | }
106 | })
107 | .setWidthMaxDp(600)
108 | .setShowTitle(false)
109 | .setShowButtons(true)
110 | .create()
111 | .show();
112 |
113 | ```
114 |
115 |
116 | #English
117 |
118 | ## Abstract
119 | a material designed style dialog, can add operation of content view, set messages, respond to onclick of messages items and so on
120 |
121 | ## Introduction
122 | the `MDDialog` inspired by the `Material Design` Pattern. You can get a MD style dialog quickly by using `MDDialog Builder`.
123 | this `MDDialog` has many interesting configurations such as :
124 | 1. you can hide or show title or positive/negative button(or both)
125 | 2. you can add a `customized view` into the `MDDialog`, and can add code to control the customized view in Builder' fuction `setContentViewOperator(...)`
126 | 3. you can set an `String[] messages` into `MDDialog`, and each item of messages will be one view in `MDDialog`, and can set `setOnItemClickListener(...)` for each item of messages.
127 | 4. you can customize the corner's radius of `MDDialog`.
128 | 5. `MDDialog` has the pressed effect of each messages item, and the shape of pressed effect is the same as item's shape
129 | 6. two ways to set the `MDDialog` width, the ratio of screen width, or the exact dimension
130 |
131 | ## Screenshot
132 |
133 | 
134 |
135 |
136 | 
137 |
138 |
139 | ## Example
140 | first add dependences
141 | ```
142 | dependencies {
143 | compile 'cn.carbs.android:MDDialog:1.0.0'
144 | }
145 | ```
146 | how to build the `MDDialog` in java code
147 | ```
148 | two mode to create MDDialog
149 | 1.set customize view :
150 | new MDDialog.Builder(ActivityMain.this)
151 | // .setContentView(customizedView)
152 | .setContentView(R.layout.content_dialog)
153 | .setContentViewOperator(new MDDialog.ContentViewOperator() {
154 | @Override
155 | public void operate(View contentView) {
156 | EditText et = (EditText) contentView.findViewById(R.id.edit0);
157 | et.setHint("hint set in operator");
158 | }
159 | })
160 | .setTitle("添加")
161 | .setNegativeButton(new View.OnClickListener() {
162 | @Override
163 | public void onClick(View v) {
164 | }
165 | })
166 | .setPositiveButton(new View.OnClickListener() {
167 | @Override
168 | public void onClick(View v) {
169 | }
170 | })
171 | .setPositiveButtonMultiListener(new MDDialog.OnMultiClickListener() {
172 | @Override
173 | public void onClick(View clickedView, View contentView) {
174 | EditText et = (EditText) contentView.findViewById(R.id.edit0);
175 | Toast.makeText(getApplicationContext(), "edittext 0 : " + et.getText(), Toast.LENGTH_SHORT).show();
176 | }
177 | })
178 | .setNegativeButtonMultiListener(new MDDialog.OnMultiClickListener() {
179 | @Override
180 | public void onClick(View clickedView, View contentView) {
181 | EditText et = (EditText) contentView.findViewById(R.id.edit1);
182 | Toast.makeText(getApplicationContext(), "edittext 1 : " + et.getText(), Toast.LENGTH_SHORT).show();
183 | }
184 | })
185 | .setWidthMaxDp(600)
186 | // .setShowTitle(false)//default is true
187 | // .setShowButtons(true)//default is true
188 | .create()
189 | .show();
190 |
191 | 2.set String[] messages
192 |
193 | final String[] messages = new String[]{"两个黄鹂鸣翠柳,一行白鹭上青天。",
194 | "窗含西岭千秋雪,门泊东吴万里船。",
195 | "君不见,黄河之水天上来,奔流到海不复回;君不见,高堂明镜悲白发,朝如青丝暮如雪。"};
196 | new MDDialog.Builder(ActivityMain.this)
197 | .setMessages(messages)
198 | .setTitle("一首古诗")
199 | .setNegativeButton(new View.OnClickListener() {
200 | @Override
201 | public void onClick(View v) {
202 | }
203 | })
204 | .setPositiveButton(new View.OnClickListener() {
205 | @Override
206 | public void onClick(View v) {
207 | Toast.makeText(getApplicationContext(), "positive", Toast.LENGTH_SHORT).show();
208 | }
209 | })
210 | .setOnItemClickListener(new MDDialog.OnItemClickListener() {
211 | @Override
212 | public void onItemClicked(int index) {
213 | Toast.makeText(getApplicationContext(), messages[index], Toast.LENGTH_SHORT).show();
214 | }
215 | })
216 | .setWidthMaxDp(600)
217 | .setShowTitle(false)
218 | .setShowButtons(true)
219 | .create()
220 | .show();
221 |
222 | ```
223 |
224 | ## License
225 |
226 | Copyright 2016 Carbs (MDDialog)
227 |
228 | Licensed under the Apache License, Version 2.0 (the "License");
229 | you may not use this file except in compliance with the License.
230 | You may obtain a copy of the License at
231 |
232 | http://www.apache.org/licenses/LICENSE-2.0
233 |
234 | Unless required by applicable law or agreed to in writing, software
235 | distributed under the License is distributed on an "AS IS" BASIS,
236 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
237 | See the License for the specific language governing permissions and
238 | limitations under the License.
239 |
240 |
241 |
242 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.5.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "cn.carbs.android.mddialog"
9 | minSdkVersion 8
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile project(':library')
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | testCompile 'junit:junit:4.12'
26 | compile 'com.android.support:appcompat-v7:23.2.1'
27 | }
28 |
--------------------------------------------------------------------------------
/example/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 D:\Users\rick.wang.E-BAO\AppData\Local\Android\sdk/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 |
--------------------------------------------------------------------------------
/example/src/androidTest/java/cn/carbs/android/mddialog/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package cn.carbs.android.mddialog;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/example/src/main/java/cn/carbs/android/mddialog/ActivityMain.java:
--------------------------------------------------------------------------------
1 | package cn.carbs.android.mddialog;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.Button;
7 | import android.widget.EditText;
8 | import android.widget.Toast;
9 |
10 | import cn.carbs.android.library.MDDialog;
11 |
12 | public class ActivityMain extends AppCompatActivity {
13 |
14 | Button button1;
15 | Button button2;
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 | init();
21 | }
22 |
23 | private void init(){
24 | final String[] messages = new String[]{"两个黄鹂鸣翠柳,一行白鹭上青天。",
25 | "窗含西岭千秋雪,门泊东吴万里船。",
26 | "君不见,黄河之水天上来,奔流到海不复回;君不见,高堂明镜悲白发,朝如青丝暮如雪。"};
27 | button1 = (Button)this.findViewById(R.id.button1);
28 | button2 = (Button)this.findViewById(R.id.button2);
29 |
30 | /*final LinearLayout ll = new LinearLayout(this);
31 | LayoutInflater.from(this).inflate(R.layout.content, ll);*/
32 |
33 | button1.setOnClickListener(new View.OnClickListener() {
34 |
35 | @Override
36 | public void onClick(View v) {
37 | new MDDialog.Builder(ActivityMain.this)
38 | // .setContentView(ll)
39 | .setContentView(R.layout.content_dialog)
40 | .setContentViewOperator(new MDDialog.ContentViewOperator() {
41 | @Override
42 | public void operate(View contentView) {
43 | EditText et = (EditText)contentView.findViewById(R.id.edit0);
44 | et.setHint("hint set in operator");
45 | }
46 | })
47 | // .setMessages(messages)
48 | .setTitle("添加")
49 | .setNegativeButton(new View.OnClickListener() {
50 | @Override
51 | public void onClick(View v) {
52 | }
53 | })
54 | .setPositiveButton(new View.OnClickListener() {
55 | @Override
56 | public void onClick(View v) {
57 |
58 | }
59 | })
60 | .setPositiveButtonMultiListener(new MDDialog.OnMultiClickListener() {
61 |
62 | @Override
63 | public void onClick(View clickedView, View contentView) {
64 | EditText et = (EditText)contentView.findViewById(R.id.edit0);
65 | Toast.makeText(getApplicationContext(), "edittext 0 : " + et.getText(), Toast.LENGTH_SHORT).show();
66 | }
67 | })
68 | .setNegativeButtonMultiListener(new MDDialog.OnMultiClickListener() {
69 |
70 | @Override
71 | public void onClick(View clickedView, View contentView) {
72 | EditText et = (EditText)contentView.findViewById(R.id.edit1);
73 | Toast.makeText(getApplicationContext(), "edittext 1 : " + et.getText(), Toast.LENGTH_SHORT).show();
74 | }
75 | })
76 | .setOnItemClickListener(new MDDialog.OnItemClickListener() {
77 | @Override
78 | public void onItemClicked(int index) {
79 | if (index == 0) {
80 | Toast.makeText(getApplicationContext(), "index 0", Toast.LENGTH_SHORT).show();
81 | } else if (index == 1) {
82 | Toast.makeText(getApplicationContext(), "index 1", Toast.LENGTH_SHORT).show();
83 | } else if (index ==2 ){
84 | Toast.makeText(getApplicationContext(), "index 2", Toast.LENGTH_SHORT).show();
85 | }
86 | }
87 | })
88 | .setWidthMaxDp(600)
89 | // .setShowTitle(false)
90 | .setShowButtons(true)
91 | .create()
92 | .show();
93 | }
94 | });
95 |
96 | button2.setOnClickListener(new View.OnClickListener() {
97 |
98 | @Override
99 | public void onClick(View v) {
100 | new MDDialog.Builder(ActivityMain.this)
101 | .setMessages(messages)
102 | .setTitle("一首古诗")
103 | .setNegativeButton(new View.OnClickListener() {
104 | @Override
105 | public void onClick(View v) {
106 | }
107 | })
108 | .setPositiveButton(new View.OnClickListener() {
109 | @Override
110 | public void onClick(View v) {
111 | Toast.makeText(getApplicationContext(), "positive", Toast.LENGTH_SHORT).show();
112 | }
113 | })
114 | .setOnItemClickListener(new MDDialog.OnItemClickListener() {
115 | @Override
116 | public void onItemClicked(int index) {
117 | Toast.makeText(getApplicationContext(), messages[index], Toast.LENGTH_SHORT).show();
118 | }
119 | })
120 | .setWidthMaxDp(600)
121 | .setShowTitle(false)
122 | .setShowButtons(true)
123 | .create()
124 | .show();
125 | }
126 | });
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/example/src/main/res/drawable/color_cursor.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/content_dialog.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
13 |
14 |
22 |
23 |
32 |
33 |
40 |
41 |
42 |
49 |
50 |
58 |
59 |
68 |
69 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Carbs0126/MDDialog/6cbebffa149bf0e3c8f60b6ac3a42cabf22b97a9/example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Carbs0126/MDDialog/6cbebffa149bf0e3c8f60b6ac3a42cabf22b97a9/example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Carbs0126/MDDialog/6cbebffa149bf0e3c8f60b6ac3a42cabf22b97a9/example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Carbs0126/MDDialog/6cbebffa149bf0e3c8f60b6ac3a42cabf22b97a9/example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Carbs0126/MDDialog/6cbebffa149bf0e3c8f60b6ac3a42cabf22b97a9/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MDDialog
3 |
4 |
--------------------------------------------------------------------------------
/example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/example/src/test/java/cn/carbs/android/mddialog/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.carbs.android.mddialog;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Carbs0126/MDDialog/6cbebffa149bf0e3c8f60b6ac3a42cabf22b97a9/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 8
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.2.1'
25 | }
26 |
--------------------------------------------------------------------------------
/library/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 D:\Users\rick.wang.E-BAO\AppData\Local\Android\sdk/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 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/cn/carbs/android/library/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package cn.carbs.android.library;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/carbs/android/library/MDDialog.java:
--------------------------------------------------------------------------------
1 | package cn.carbs.android.library;
2 |
3 | /**
4 | * Created by Carbs.Wang on 2016/5/25.
5 | */
6 |
7 | import android.app.Dialog;
8 | import android.content.Context;
9 | import android.content.DialogInterface;
10 | import android.graphics.Color;
11 | import android.graphics.Paint;
12 | import android.graphics.drawable.Drawable;
13 | import android.graphics.drawable.ShapeDrawable;
14 | import android.graphics.drawable.StateListDrawable;
15 | import android.graphics.drawable.shapes.RoundRectShape;
16 | import android.os.Bundle;
17 | import android.text.TextUtils;
18 | import android.view.Gravity;
19 | import android.view.LayoutInflater;
20 | import android.view.View;
21 | import android.view.Window;
22 | import android.view.WindowManager;
23 | import android.widget.Button;
24 | import android.widget.ImageView;
25 | import android.widget.LinearLayout;
26 | import android.widget.RelativeLayout;
27 | import android.widget.TextView;
28 |
29 |
30 | /**
31 | * created by carbs.wang 2016/05/17
32 | */
33 | public class MDDialog extends Dialog implements View.OnClickListener{
34 |
35 | private static final String TAG = MDDialog.class.getSimpleName();
36 | //views
37 | private RelativeLayout rl_title;
38 | private RelativeLayout rl_buttons;
39 | private ImageView iv_title;
40 | private TextView tv_title;
41 | private LinearLayout ll_content;
42 | private Button btn_yes;
43 | private Button btn_no;
44 | private LinearLayout ll_container;
45 |
46 | //datas
47 | private Wrapper wrapper;
48 |
49 | private void setWrapper(Wrapper wrapper){
50 | this.wrapper = wrapper;
51 | }
52 |
53 | protected MDDialog(Context context) {
54 | super(context, R.style.dialog);
55 | }
56 |
57 | @Override
58 | protected void onCreate(Bundle savedInstanceState) {
59 | super.onCreate(savedInstanceState);
60 | setContentView(R.layout.layout_mddialog);
61 | initWindow();
62 | initView();
63 | }
64 |
65 | public void initWindow() {
66 |
67 | Window win = this.getWindow();
68 | win.getDecorView().setPadding(0, 0, 0, 0);
69 | WindowManager.LayoutParams lp = win.getAttributes();
70 | lp.width = (int)(wrapper.widthRatio * getScreenWidth(getContext()));
71 | if(wrapper.widthMaxDp != 0 && lp.width > dp2px(getContext(), wrapper.widthMaxDp)){
72 | lp.width = dp2px(getContext(), wrapper.widthMaxDp);
73 | }
74 | lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
75 | lp.gravity = Gravity.CENTER;
76 | win.setAttributes(lp);
77 |
78 | this.setCanceledOnTouchOutside(true);
79 | }
80 |
81 | private int getScreenWidth(Context context) {
82 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
83 | return wm.getDefaultDisplay().getWidth();
84 | }
85 |
86 | private void initView() {
87 | ll_container = (LinearLayout)this.findViewById(R.id.ll_container);
88 | rl_title = (RelativeLayout)this.findViewById(R.id.rl_title);
89 | iv_title = (ImageView)this.findViewById(R.id.iv_title);
90 | tv_title = (TextView)this.findViewById(R.id.tv_title);
91 | ll_content = (LinearLayout)this.findViewById(R.id.ll_content);
92 | rl_buttons = (RelativeLayout)this.findViewById(R.id.rl_buttons);
93 | btn_yes = (Button)this.findViewById(R.id.btn_yes);
94 | btn_no = (Button)this.findViewById(R.id.btn_no);
95 | if(wrapper == null){
96 | wrapper = new Wrapper();
97 | }
98 | if(!wrapper.showTitle){
99 | rl_title.setVisibility(View.GONE);
100 | }
101 | if(!wrapper.showButtons){
102 | rl_buttons.setVisibility(View.GONE);
103 | }
104 | if(!wrapper.showNegativeButton){
105 | btn_no.setVisibility(View.GONE);
106 | }
107 | if(!wrapper.showPositiveButton){
108 | btn_yes.setVisibility(View.GONE);
109 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)btn_no.getLayoutParams();
110 | params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
111 | }
112 |
113 | if(wrapper.icon != null){
114 | iv_title.setImageDrawable(wrapper.icon);
115 | iv_title.setVisibility(View.VISIBLE);
116 | tv_title.setPadding(0, 0, 0, 0);
117 | }
118 | tv_title.setText(wrapper.title);
119 | tv_title.setTextColor(wrapper.primaryTextColor);
120 | btn_yes.setTag(BUTTON_POSITIVE_INDEX);
121 | btn_yes.setOnClickListener(this);
122 | btn_yes.setTextColor(wrapper.primaryTextColor);
123 | if(!TextUtils.isEmpty(wrapper.btTextYes)){
124 | btn_yes.setText(wrapper.btTextYes);
125 | }
126 | btn_no.setTag(BUTTON_NEGATIVE_INDEX);
127 | btn_no.setOnClickListener(this);
128 | if(!TextUtils.isEmpty(wrapper.btTextNo)){
129 | btn_no.setText(wrapper.btTextNo);
130 | }
131 | ll_container.setBackgroundDrawable(getRoundRectShapeDrawable(getContext(), wrapper.cornerRadiusDp, Color.WHITE));
132 | btn_yes.setBackgroundDrawable(getStateListDrawable(getContext(), 0, 0xdddddddd, 0x00000000));
133 | btn_no.setBackgroundDrawable(getStateListDrawable(getContext(), 0, 0xdddddddd, 0x00000000));
134 |
135 | analyseContent();
136 | }
137 | private static final int BUTTON_POSITIVE_INDEX = -1;
138 | private static final int BUTTON_NEGATIVE_INDEX = -2;
139 |
140 | private void analyseContent(){
141 | if(wrapper.messages == null || wrapper.messages.length == 0){
142 | if(wrapper.contentView != null){
143 | ll_content.addView(wrapper.contentView);
144 | }else if(wrapper.contentViewLayoutResId != 0) {
145 | LayoutInflater.from(getContext()).inflate(wrapper.contentViewLayoutResId, ll_content);
146 | }
147 | if(wrapper.contentViewOperator != null && ll_content.getChildCount() != 0){
148 | wrapper.contentViewOperator.operate(ll_content.getChildAt(0));
149 | }
150 | return;
151 | }
152 |
153 | int itemPadding = dp2px(getContext(), wrapper.contentPaddingDp);
154 | int itemHeight = dp2px(getContext(), wrapper.contentItemHeightDp);
155 | for(int i = 0; i < wrapper.messages.length; i++){
156 | TextView tv = new TextView(getContext());
157 | tv.setText(wrapper.messages[i]);
158 | tv.setTextSize(wrapper.contentTextSizeDp);
159 | tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
160 | tv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
161 | LinearLayout.LayoutParams.WRAP_CONTENT));
162 | tv.setOnClickListener(this);
163 | tv.setClickable(wrapper.contentViewClickable);
164 | tv.setTextColor(wrapper.contentTextColor);
165 | tv.setTag(i);
166 | tv.setMinHeight(itemHeight);
167 | if(wrapper.messages.length == 1){
168 | if(wrapper.showTitle && wrapper.showButtons){
169 | tv.setBackgroundDrawable(getStateListDrawable(getContext(), 0, 0xdddddddd, 0x00000000));
170 | }else if(wrapper.showTitle && !wrapper.showButtons){
171 | tv.setBackgroundDrawable(getStateListDrawableForBottomItem(getContext(), wrapper.cornerRadiusDp, 0xdddddddd, 0x00000000));
172 | }else if(!wrapper.showTitle && wrapper.showButtons){
173 | tv.setBackgroundDrawable(getStateListDrawableForTopItem(getContext(), wrapper.cornerRadiusDp, 0xdddddddd, 0x00000000));
174 | }else{
175 | tv.setBackgroundDrawable(getStateListDrawable(getContext(), wrapper.cornerRadiusDp, 0xdddddddd, 0x00000000));
176 | }
177 | }else{
178 | if(i == 0){
179 | if(wrapper.showTitle){
180 | tv.setBackgroundDrawable(getStateListDrawable(getContext(), 0, 0xdddddddd, 0x00000000));
181 | }else{
182 | tv.setBackgroundDrawable(getStateListDrawableForTopItem(getContext(), wrapper.cornerRadiusDp, 0xdddddddd, 0x00000000));
183 | }
184 | }else if(i == wrapper.messages.length - 1){
185 | if(wrapper.showButtons){
186 | tv.setBackgroundDrawable(getStateListDrawable(getContext(), 0, 0xdddddddd, 0x00000000));
187 | }else{
188 | tv.setBackgroundDrawable(getStateListDrawableForBottomItem(getContext(), wrapper.cornerRadiusDp, 0xdddddddd, 0x00000000));
189 | }
190 | }else{
191 | tv.setBackgroundDrawable(getStateListDrawable(getContext(), 0, 0xdddddddd, 0x00000000));
192 | }
193 | }
194 | tv.setPadding(itemPadding, 0, itemPadding, 0);
195 | ll_content.addView(tv);
196 | if(i != wrapper.messages.length-1){
197 | View divider = new View(getContext());
198 | divider.setBackgroundColor(wrapper.contentDividerColor);
199 | LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
200 | dividerParams.setMargins(dp2px(getContext(), wrapper.dividerMarginHorizontalDp), 0,
201 | dp2px(getContext(), wrapper.dividerMarginHorizontalDp), 0);
202 | divider.setLayoutParams(dividerParams);
203 | ll_content.addView(divider);
204 | }
205 | }
206 | }
207 |
208 | @Override
209 | public void onClick(View v) {
210 | Object o = v.getTag();
211 | if(o != null && o instanceof Integer){
212 | if(((Integer)o) == BUTTON_POSITIVE_INDEX){
213 | if(wrapper.btListenerYes != null){
214 | wrapper.btListenerYes.onClick(v);
215 | }
216 | if(wrapper.btMultiListenerYes != null && (wrapper.contentView != null || wrapper.contentViewLayoutResId != 0)){
217 | if(ll_content.getChildCount() > 0){
218 | wrapper.btMultiListenerYes.onClick(v, ll_content.getChildAt(0));
219 | }
220 | }
221 | }else if(((Integer)o) == BUTTON_NEGATIVE_INDEX){
222 | if(wrapper.btListenerNo != null){
223 | wrapper.btListenerNo.onClick(v);
224 | }
225 | if(wrapper.btMultiListenerNo != null && (wrapper.contentView != null || wrapper.contentViewLayoutResId != 0)){
226 | if(ll_content.getChildCount() > 0){
227 | wrapper.btMultiListenerNo.onClick(v, ll_content.getChildAt(0));
228 | }
229 | }
230 | }else if(((Integer)o) >= 0){
231 | if(wrapper.onItemClickListener != null){
232 | wrapper.onItemClickListener.onItemClicked((Integer)o);
233 | }
234 | }
235 | }
236 | dismiss();
237 | }
238 |
239 | public interface OnItemClickListener{
240 | void onItemClicked(int index);
241 | }
242 |
243 | public interface ContentViewOperator{
244 | void operate(View contentView);
245 | }
246 |
247 | public interface OnMultiClickListener{
248 | void onClick(View clickedView, View contentView);
249 | }
250 |
251 | private static class Wrapper{
252 | public CharSequence title;
253 | public Context context;
254 | public CharSequence[] messages;
255 | public Drawable icon;
256 | public CharSequence btTextYes;
257 | public CharSequence btTextNo;
258 | public View.OnClickListener btListenerYes;
259 | public View.OnClickListener btListenerNo;
260 | public OnMultiClickListener btMultiListenerYes;
261 | public OnMultiClickListener btMultiListenerNo;
262 | public DialogInterface.OnCancelListener btListenerCancel;
263 | public DialogInterface.OnDismissListener btListenerDismiss;
264 | public OnItemClickListener onItemClickListener;
265 | public View contentView;//content view
266 | public ContentViewOperator contentViewOperator;
267 | public int contentViewLayoutResId;
268 | public boolean cancelable = true;
269 | public boolean showTitle = true;
270 | public boolean showButtons = true;
271 | public boolean showNegativeButton = true;
272 | public boolean showPositiveButton = true;
273 | public boolean contentViewClickable = true;
274 | public float widthRatio = 0.9f;
275 | public int widthMaxDp = 0;
276 | public int cornerRadiusDp = 3;
277 | public int dividerMarginHorizontalDp = 12;
278 | public int primaryTextColor = 0xff2ca99f;
279 | public int contentTextColor = 0xaa111111;
280 | public int contentDividerColor = 0x44999999;
281 | public int contentPaddingDp = 16;
282 | public int contentItemHeightDp = 56;
283 | public int contentTextSizeDp = 18;
284 | }
285 |
286 | public static class Builder {
287 |
288 | private final Wrapper wrapper;
289 |
290 | public Builder(Context context) {
291 | wrapper = new Wrapper();
292 | wrapper.context = context;
293 | }
294 |
295 | public Context getContext() {
296 | return wrapper.context;
297 | }
298 |
299 | public Builder setTitle(int titleId) {
300 | wrapper.title = wrapper.context.getText(titleId);
301 | return this;
302 | }
303 |
304 | public Builder setTitle(CharSequence title) {
305 | wrapper.title = title.toString();
306 | return this;
307 | }
308 |
309 | public Builder setMessages(int messagesId) {
310 | wrapper.context.getResources().getTextArray(messagesId);
311 | return this;
312 | }
313 |
314 | public Builder setMessages(CharSequence[] messages) {
315 | wrapper.messages = messages;
316 | return this;
317 | }
318 |
319 | public Builder setIcon(int iconId) {
320 | wrapper.icon = wrapper.context.getResources().getDrawable(iconId);
321 | return this;
322 | }
323 |
324 | public Builder setIcon(Drawable icon) {
325 | wrapper.icon = icon;
326 | return this;
327 | }
328 |
329 | public Builder setPositiveButton(final View.OnClickListener listener) {
330 | wrapper.btListenerYes = listener;
331 | return this;
332 | }
333 |
334 | public Builder setPositiveButton(int textId, final View.OnClickListener listener) {
335 | wrapper.btTextYes = wrapper.context.getText(textId);
336 | wrapper.btListenerYes = listener;
337 | return this;
338 | }
339 |
340 | public Builder setPositiveButton(CharSequence text, final View.OnClickListener listener) {
341 | wrapper.btTextYes = text;
342 | wrapper.btListenerYes = listener;
343 | return this;
344 | }
345 |
346 | public Builder setPositiveButtonMultiListener(final OnMultiClickListener btMultiListenerYes) {
347 | wrapper.btMultiListenerYes = btMultiListenerYes;
348 | return this;
349 | }
350 |
351 | public Builder setNegativeButton(final View.OnClickListener listener) {
352 | wrapper.btListenerNo = listener;
353 | return this;
354 | }
355 |
356 | public Builder setNegativeButton(int textId, final View.OnClickListener listener) {
357 | wrapper.btTextNo = wrapper.context.getText(textId);
358 | wrapper.btListenerNo = listener;
359 | return this;
360 | }
361 |
362 | public Builder setNegativeButton(CharSequence text, final View.OnClickListener listener) {
363 | wrapper.btTextNo = text;
364 | wrapper.btListenerNo = listener;
365 | return this;
366 | }
367 |
368 | public Builder setNegativeButtonMultiListener(final OnMultiClickListener btMultiListenerNo) {
369 | wrapper.btMultiListenerNo = btMultiListenerNo;
370 | return this;
371 | }
372 |
373 | public Builder setShowNegativeButton(boolean showNegativeButton){
374 | wrapper.showNegativeButton = showNegativeButton;
375 | return this;
376 | }
377 |
378 | public Builder setShowPositiveButton(boolean showPositiveButton){
379 | wrapper.showPositiveButton = showPositiveButton;
380 | return this;
381 | }
382 | public Builder setCancelable(boolean cancelable) {
383 | wrapper.cancelable = cancelable;
384 | return this;
385 | }
386 |
387 | public Builder setShowTitle(boolean showTitle) {
388 | wrapper.showTitle = showTitle;
389 | return this;
390 | }
391 |
392 | public Builder setShowButtons(boolean showButtons) {
393 | wrapper.showButtons = showButtons;
394 | return this;
395 | }
396 |
397 | public Builder setOnCancelListener(OnCancelListener onCancelListener) {
398 | wrapper.btListenerCancel = onCancelListener;
399 | return this;
400 | }
401 |
402 | public Builder setOnDismissListener(OnDismissListener onDismissListener) {
403 | wrapper.btListenerDismiss = onDismissListener;
404 | return this;
405 | }
406 |
407 | public Builder setOnItemClickListener(final OnItemClickListener listener) {
408 | wrapper.onItemClickListener = listener;
409 | return this;
410 | }
411 |
412 | public Builder setContentView(int layoutResId) {
413 | wrapper.contentView = null;
414 | wrapper.contentViewLayoutResId = layoutResId;
415 | return this;
416 | }
417 |
418 | public Builder setContentViewClickable(boolean clickable) {
419 | wrapper.contentViewClickable = clickable;
420 | return this;
421 | }
422 |
423 | public Builder setContentView(View contentView) {
424 | wrapper.contentView = contentView;
425 | wrapper.contentViewLayoutResId = 0;
426 | return this;
427 | }
428 |
429 | public Builder setWidthRatio(float widthRatio){
430 | wrapper.widthRatio = widthRatio;
431 | return this;
432 | }
433 |
434 | public Builder setWidthMaxDp(int widthMaxDp){
435 | wrapper.widthMaxDp = widthMaxDp;
436 | return this;
437 | }
438 |
439 | public Builder setBackgroundCornerRadius(int cornerRadiusDp){
440 | wrapper.cornerRadiusDp = cornerRadiusDp;
441 | return this;
442 | }
443 |
444 | public Builder setDividerMarginHorizontalDp(int marginHoriDp){
445 | wrapper.dividerMarginHorizontalDp = marginHoriDp;
446 | return this;
447 | }
448 |
449 | public Builder setPrimaryTextColor(int primaryTextColor){
450 | wrapper.primaryTextColor = primaryTextColor;
451 | return this;
452 | }
453 |
454 | public Builder setContentTextColor(int contentTextColor){
455 | wrapper.contentTextColor = contentTextColor;
456 | return this;
457 | }
458 |
459 | public Builder setContentDividerColor(int contentDividerColor){
460 | wrapper.contentDividerColor = contentDividerColor;
461 | return this;
462 | }
463 |
464 | public Builder setContentPaddingDp(int contentPaddingDp){
465 | wrapper.contentPaddingDp = contentPaddingDp;
466 | return this;
467 | }
468 |
469 | public Builder setContentItemHeightDp(int contentItemHeightDp){
470 | wrapper.contentItemHeightDp = contentItemHeightDp;
471 | return this;
472 | }
473 |
474 | public Builder setContentTextSizeDp(int contentTextSizeDp){
475 | wrapper.contentTextSizeDp = contentTextSizeDp;
476 | return this;
477 | }
478 |
479 | public Builder setContentViewOperator(ContentViewOperator operator){
480 | wrapper.contentViewOperator = operator;
481 | return this;
482 | }
483 |
484 | public MDDialog create() {
485 | final MDDialog dialog = new MDDialog(wrapper.context);
486 | dialog.setCancelable(wrapper.cancelable);
487 | dialog.setOnCancelListener(wrapper.btListenerCancel);
488 | dialog.setOnDismissListener(wrapper.btListenerDismiss);
489 | dialog.setWrapper(wrapper);
490 | return dialog;
491 | }
492 |
493 | public MDDialog show() {
494 | MDDialog dialog = create();
495 | dialog.show();
496 | return dialog;
497 | }
498 | }
499 |
500 | private Drawable getRoundRectShapeDrawable(float[] cornerRadiusPx, int color){
501 | RoundRectShape rr = new RoundRectShape(cornerRadiusPx, null, null);
502 | ShapeDrawable drawable = new ShapeDrawable(rr);
503 | drawable.getPaint().setColor(color);
504 | drawable.getPaint().setStyle(Paint.Style.FILL);
505 | return drawable;
506 | }
507 |
508 | private Drawable getRoundRectShapeDrawable(Context context, int cornerRadiusDp, int color){
509 | int cornerRadiusPx = dp2px(context, cornerRadiusDp);
510 | float[] outerR = new float[] { cornerRadiusPx, cornerRadiusPx, cornerRadiusPx, cornerRadiusPx,
511 | cornerRadiusPx, cornerRadiusPx, cornerRadiusPx, cornerRadiusPx};
512 | return getRoundRectShapeDrawable(outerR, color);
513 | }
514 |
515 | private Drawable getRoundRectShapeDrawableForTopItem(Context context, int cornerRadiusDp, int color){
516 | int cornerRadiusPx = dp2px(context, cornerRadiusDp);
517 | float[] outerR = new float[] { cornerRadiusPx, cornerRadiusPx, cornerRadiusPx, cornerRadiusPx, 0, 0, 0, 0};
518 | return getRoundRectShapeDrawable(outerR, color);
519 | }
520 |
521 | private Drawable getRoundRectShapeDrawableForBottomItem(Context context, int cornerRadiusDp, int color){
522 | int cornerRadiusPx = dp2px(context, cornerRadiusDp);
523 | float[] outerR = new float[] { 0, 0, 0, 0, cornerRadiusPx, cornerRadiusPx, cornerRadiusPx, cornerRadiusPx};
524 | return getRoundRectShapeDrawable(outerR, color);
525 | }
526 |
527 | private int dp2px(Context context, float dipValue) {
528 | final float scale = context.getResources().getDisplayMetrics().density;
529 | return (int) (dipValue * scale + 0.5f);
530 | }
531 |
532 | private int px2sp(Context context, float pxValue) {
533 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
534 | return (int) (pxValue / fontScale + 0.5f);
535 | }
536 |
537 | private Drawable getStateListDrawable(Context context, int cornerRadiusDp, int colorPressed, int colorNormal){
538 | StateListDrawable stateListDrawable = new StateListDrawable();
539 |
540 | int[] stateHighlighted = new int[]{android.R.attr.state_pressed};
541 | Drawable highlightedDrawable = getRoundRectShapeDrawable(context, cornerRadiusDp, colorPressed);
542 | stateListDrawable.addState(stateHighlighted, highlightedDrawable);
543 |
544 | int[] stateNormal = new int[]{};
545 | Drawable normalDrawable = getRoundRectShapeDrawable(context, cornerRadiusDp, colorNormal);
546 | stateListDrawable.addState(stateNormal, normalDrawable);
547 | return stateListDrawable;
548 | }
549 |
550 | private Drawable getStateListDrawableForTopItem(Context context, int cornerRadiusDp, int colorPressed, int colorNormal){
551 | StateListDrawable stateListDrawable = new StateListDrawable();
552 |
553 | int[] stateHighlighted = new int[]{android.R.attr.state_pressed};
554 | Drawable highlightedDrawable = getRoundRectShapeDrawableForTopItem(context, cornerRadiusDp, colorPressed);
555 | stateListDrawable.addState(stateHighlighted, highlightedDrawable);
556 |
557 | int[] stateNormal = new int[]{};
558 | Drawable normalDrawable = getRoundRectShapeDrawableForTopItem(context, cornerRadiusDp, colorNormal);
559 | stateListDrawable.addState(stateNormal, normalDrawable);
560 | return stateListDrawable;
561 | }
562 |
563 | private Drawable getStateListDrawableForBottomItem(Context context, int cornerRadiusDp, int colorPressed, int colorNormal){
564 | StateListDrawable stateListDrawable = new StateListDrawable();
565 |
566 | int[] stateHighlighted = new int[]{android.R.attr.state_pressed};
567 | Drawable highlightedDrawable = getRoundRectShapeDrawableForBottomItem(context, cornerRadiusDp, colorPressed);
568 | stateListDrawable.addState(stateHighlighted, highlightedDrawable);
569 |
570 | int[] stateNormal = new int[]{};
571 | Drawable normalDrawable = getRoundRectShapeDrawableForBottomItem(context, cornerRadiusDp, colorNormal);
572 | stateListDrawable.addState(stateNormal, normalDrawable);
573 | return stateListDrawable;
574 | }
575 |
576 | }
577 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/layout_mddialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
22 |
23 |
35 |
36 |
43 |
44 |
45 |
50 |
51 |
52 |
58 |
59 |
71 |
72 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/res/values/values_mddialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 64dp
4 | 56dp
5 | 8dp
6 | 8dp
7 | 20dp
8 | 16dp
9 | 8dp
10 | 64dp
11 | 8dp
12 | 16dp
13 | 16dp
14 | 56dp
15 | 18dp
16 | 12dp
17 |
18 | #ff4bd1c8
19 | #ff2ca99f
20 | #99666666
21 | #00000000
22 | #66999999
23 | #44999999
24 | #aa111111
25 |
26 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/library/src/test/java/cn/carbs/android/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.carbs.android.library;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':example', ':library'
2 |
--------------------------------------------------------------------------------