61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/dialog/src/main/java/com/kongzue/dialog/util/ShadowLayout.java:
--------------------------------------------------------------------------------
1 | package com.kongzue.dialog.util;
2 |
3 | /*
4 | * Copyright (C) 2015 Basil Miller
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.content.Context;
20 | import android.content.res.TypedArray;
21 | import android.graphics.Bitmap;
22 | import android.graphics.BlurMaskFilter;
23 | import android.graphics.Canvas;
24 | import android.graphics.Color;
25 | import android.graphics.Paint;
26 | import android.graphics.PorterDuff;
27 | import android.graphics.Rect;
28 | import android.support.annotation.FloatRange;
29 | import android.util.AttributeSet;
30 | import android.widget.FrameLayout;
31 |
32 | import com.kongzue.dialog.R;
33 |
34 | /**
35 | * Author: @GIGAMOLE
36 | * Github: https://github.com/Devlight/ShadowLayout
37 | * CreateTime: 13.04.2016
38 | */
39 | public class ShadowLayout extends FrameLayout {
40 |
41 | // Default shadow values
42 | private final static float DEFAULT_SHADOW_RADIUS = 30.0F;
43 | private final static float DEFAULT_SHADOW_DISTANCE = 15.0F;
44 | private final static float DEFAULT_SHADOW_ANGLE = 45.0F;
45 | private final static int DEFAULT_SHADOW_COLOR = Color.DKGRAY;
46 |
47 | // Shadow bounds values
48 | private final static int MAX_ALPHA = 255;
49 | private final static float MAX_ANGLE = 360.0F;
50 | private final static float MIN_RADIUS = 0.1F;
51 | private final static float MIN_ANGLE = 0.0F;
52 | // Shadow paint
53 | private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG) {
54 | {
55 | setDither(true);
56 | setFilterBitmap(true);
57 | }
58 | };
59 | // Shadow bitmap and canvas
60 | private Bitmap mBitmap;
61 | private final Canvas mCanvas = new Canvas();
62 | // View bounds
63 | private final Rect mBounds = new Rect();
64 | // Check whether need to redraw shadow
65 | private boolean mInvalidateShadow = true;
66 |
67 | // Detect if shadow is visible
68 | private boolean mIsShadowed;
69 |
70 | // Shadow variables
71 | private int mShadowColor;
72 | private int mShadowAlpha;
73 | private float mShadowRadius;
74 | private float mShadowDistance;
75 | private float mShadowAngle;
76 | private float mShadowDx;
77 | private float mShadowDy;
78 |
79 | public ShadowLayout(final Context context) {
80 | this(context, null);
81 | }
82 |
83 | public ShadowLayout(final Context context, final AttributeSet attrs) {
84 | this(context, attrs, 0);
85 | }
86 |
87 | public ShadowLayout(final Context context, final AttributeSet attrs, final int defStyleAttr) {
88 | super(context, attrs, defStyleAttr);
89 |
90 | setWillNotDraw(false);
91 | setLayerType(LAYER_TYPE_HARDWARE, mPaint);
92 |
93 | // Retrieve attributes from xml
94 | final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ShadowLayout);
95 | try {
96 | setIsShadowed(typedArray.getBoolean(R.styleable.ShadowLayout_sl_shadowed, true));
97 | setShadowRadius(
98 | typedArray.getDimension(
99 | R.styleable.ShadowLayout_sl_shadow_radius, DEFAULT_SHADOW_RADIUS
100 | )
101 | );
102 | setShadowDistance(
103 | typedArray.getDimension(
104 | R.styleable.ShadowLayout_sl_shadow_distance, DEFAULT_SHADOW_DISTANCE
105 | )
106 | );
107 | setShadowAngle(
108 | typedArray.getInteger(
109 | R.styleable.ShadowLayout_sl_shadow_angle, (int) DEFAULT_SHADOW_ANGLE
110 | )
111 | );
112 | setShadowColor(
113 | typedArray.getColor(
114 | R.styleable.ShadowLayout_sl_shadow_color, DEFAULT_SHADOW_COLOR
115 | )
116 | );
117 | } finally {
118 | typedArray.recycle();
119 | }
120 | }
121 |
122 | @Override
123 | protected void onDetachedFromWindow() {
124 | super.onDetachedFromWindow();
125 | // Clear shadow bitmap
126 | if (mBitmap != null) {
127 | mBitmap.recycle();
128 | mBitmap = null;
129 | }
130 | }
131 |
132 | public boolean isShadowed() {
133 | return mIsShadowed;
134 | }
135 |
136 | public void setIsShadowed(final boolean isShadowed) {
137 | mIsShadowed = isShadowed;
138 | postInvalidate();
139 | }
140 |
141 | public float getShadowDistance() {
142 | return mShadowDistance;
143 | }
144 |
145 | public void setShadowDistance(final float shadowDistance) {
146 | mShadowDistance = shadowDistance;
147 | resetShadow();
148 | }
149 |
150 | public float getShadowAngle() {
151 | return mShadowAngle;
152 | }
153 |
154 | @FloatRange
155 | public void setShadowAngle(@FloatRange(from = MIN_ANGLE, to = MAX_ANGLE) final float shadowAngle) {
156 | mShadowAngle = Math.max(MIN_ANGLE, Math.min(shadowAngle, MAX_ANGLE));
157 | resetShadow();
158 | }
159 |
160 | public float getShadowRadius() {
161 | return mShadowRadius;
162 | }
163 |
164 | public void setShadowRadius(final float shadowRadius) {
165 | mShadowRadius = Math.max(MIN_RADIUS, shadowRadius);
166 |
167 | if (isInEditMode()) return;
168 | // Set blur filter to paint
169 | mPaint.setMaskFilter(new BlurMaskFilter(mShadowRadius, BlurMaskFilter.Blur.NORMAL));
170 | resetShadow();
171 | }
172 |
173 | public int getShadowColor() {
174 | return mShadowColor;
175 | }
176 |
177 | public void setShadowColor(final int shadowColor) {
178 | mShadowColor = shadowColor;
179 | mShadowAlpha = Color.alpha(shadowColor);
180 |
181 | resetShadow();
182 | }
183 |
184 | public float getShadowDx() {
185 | return mShadowDx;
186 | }
187 |
188 | public float getShadowDy() {
189 | return mShadowDy;
190 | }
191 |
192 | // Reset shadow layer
193 | private void resetShadow() {
194 | // Detect shadow axis offset
195 | mShadowDx = (float) ((mShadowDistance) * Math.cos(mShadowAngle / 180.0F * Math.PI));
196 | mShadowDy = (float) ((mShadowDistance) * Math.sin(mShadowAngle / 180.0F * Math.PI));
197 |
198 | // Set padding for shadow bitmap
199 | final int padding = (int) (mShadowDistance + mShadowRadius);
200 | setPadding(padding, padding, padding, padding);
201 | requestLayout();
202 | }
203 |
204 | private int adjustShadowAlpha(final boolean adjust) {
205 | return Color.argb(
206 | adjust ? MAX_ALPHA : mShadowAlpha,
207 | Color.red(mShadowColor),
208 | Color.green(mShadowColor),
209 | Color.blue(mShadowColor)
210 | );
211 | }
212 |
213 | @Override
214 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
215 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
216 |
217 | // Set ShadowLayout bounds
218 | mBounds.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
219 | }
220 |
221 | @Override
222 | public void requestLayout() {
223 | // Redraw shadow
224 | mInvalidateShadow = true;
225 | super.requestLayout();
226 | }
227 |
228 | @Override
229 | protected void dispatchDraw(final Canvas canvas) {
230 | // If is not shadowed, skip
231 | if (mIsShadowed) {
232 | // If need to redraw shadow
233 | if (mInvalidateShadow) {
234 | // If bounds is zero
235 | if (mBounds.width() != 0 && mBounds.height() != 0) {
236 | // Reset bitmap to bounds
237 | mBitmap = Bitmap.createBitmap(
238 | mBounds.width(), mBounds.height(), Bitmap.Config.ARGB_8888
239 | );
240 | // Canvas reset
241 | mCanvas.setBitmap(mBitmap);
242 |
243 | // We just redraw
244 | mInvalidateShadow = false;
245 | // Main feature of this lib. We create the local copy of all content, so now
246 | // we can draw bitmap as a bottom layer of natural canvas.
247 | // We draw shadow like blur effect on bitmap, cause of setShadowLayer() method of
248 | // paint does`t draw shadow, it draw another copy of bitmap
249 | super.dispatchDraw(mCanvas);
250 |
251 | // Get the alpha bounds of bitmap
252 | final Bitmap extractedAlpha = mBitmap.extractAlpha();
253 | // Clear past content content to draw shadow
254 | mCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
255 |
256 | // Draw extracted alpha bounds of our local canvas
257 | mPaint.setColor(adjustShadowAlpha(false));
258 | mCanvas.drawBitmap(extractedAlpha, mShadowDx, mShadowDy, mPaint);
259 |
260 | // Recycle and clear extracted alpha
261 | extractedAlpha.recycle();
262 | } else {
263 | // Create placeholder bitmap when size is zero and wait until new size coming up
264 | mBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565);
265 | }
266 | }
267 |
268 | // Reset alpha to draw child with full alpha
269 | mPaint.setColor(adjustShadowAlpha(true));
270 | // Draw shadow bitmap
271 | if (mCanvas != null && mBitmap != null && !mBitmap.isRecycled())
272 | canvas.drawBitmap(mBitmap, 0.0F, 0.0F, mPaint);
273 | }
274 |
275 | // Draw child`s
276 | super.dispatchDraw(canvas);
277 | }
278 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/dialog/src/main/java/com/kongzue/dialog/v2/WaitDialog.java:
--------------------------------------------------------------------------------
1 | package com.kongzue.dialog.v2;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 | import android.graphics.Color;
6 | import android.graphics.Typeface;
7 | import android.os.Handler;
8 | import android.support.v4.app.FragmentManager;
9 | import android.support.v4.app.FragmentTransaction;
10 | import android.support.v7.app.AlertDialog;
11 | import android.support.v7.app.AppCompatActivity;
12 | import android.util.TypedValue;
13 | import android.view.KeyEvent;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.view.ViewTreeObserver;
18 | import android.view.Window;
19 | import android.widget.ProgressBar;
20 | import android.widget.RelativeLayout;
21 | import android.widget.TextView;
22 |
23 | import com.kongzue.dialog.R;
24 | import com.kongzue.dialog.listener.DialogLifeCycleListener;
25 | import com.kongzue.dialog.listener.OnBackPressListener;
26 | import com.kongzue.dialog.listener.OnDismissListener;
27 | import com.kongzue.dialog.util.BaseDialog;
28 | import com.kongzue.dialog.util.BlurView;
29 | import com.kongzue.dialog.util.KongzueDialogHelper;
30 | import com.kongzue.dialog.util.ProgressView;
31 | import com.kongzue.dialog.util.TextInfo;
32 |
33 | import static com.kongzue.dialog.v2.DialogSettings.THEME_LIGHT;
34 | import static com.kongzue.dialog.v2.DialogSettings.blur_alpha;
35 | import static com.kongzue.dialog.v2.DialogSettings.tipTextInfo;
36 | import static com.kongzue.dialog.v2.DialogSettings.tip_theme;
37 | import static com.kongzue.dialog.v2.DialogSettings.use_blur;
38 |
39 | public class WaitDialog extends BaseDialog {
40 |
41 | private OnBackPressListener onBackPressListener;
42 | private AlertDialog alertDialog;
43 | private WaitDialog waitDialog;
44 | private static boolean isCanCancel = false;
45 |
46 | private View customView;
47 | private TextInfo customTextInfo;
48 |
49 | private Context context;
50 | private String tip;
51 |
52 | private WaitDialog() {
53 | }
54 |
55 | public static WaitDialog show(Context context, String tip) {
56 | return show(context, tip, null, null, null);
57 | }
58 |
59 | public static WaitDialog show(Context context, String tip, DialogLifeCycleListener lifeCycleListener) {
60 | return show(context, tip, null, null, lifeCycleListener);
61 | }
62 |
63 | public static WaitDialog show(Context context, String tip, View customView) {
64 | return show(context, tip, customView, null, null);
65 | }
66 |
67 | public static WaitDialog show(Context context, String tip, View customView, DialogLifeCycleListener lifeCycleListener) {
68 | return show(context, tip, customView, null, lifeCycleListener);
69 | }
70 |
71 | public static WaitDialog show(Context context, String tip, TextInfo textInfo) {
72 | return show(context, tip, null, textInfo, null);
73 | }
74 |
75 | public static WaitDialog show(Context context, String tip, TextInfo textInfo, DialogLifeCycleListener lifeCycleListener) {
76 | return show(context, tip, null, textInfo, lifeCycleListener);
77 | }
78 |
79 | public static WaitDialog show(Context context, String tip, View customView, TextInfo textInfo) {
80 | return show(context, tip, customView, textInfo, null);
81 | }
82 |
83 | public static WaitDialog show(Context context, String tip, View customView, TextInfo textInfo, DialogLifeCycleListener lifeCycleListener) {
84 | synchronized (WaitDialog.class) {
85 | WaitDialog waitDialog = new WaitDialog();
86 | waitDialog.cleanDialogLifeCycleListener();
87 | waitDialog.context = context;
88 | waitDialog.tip = tip;
89 | waitDialog.log("装载等待对话框 -> " + tip);
90 | waitDialog.waitDialog = waitDialog;
91 | waitDialog.customView = customView;
92 | waitDialog.customTextInfo = textInfo;
93 | waitDialog.setDialogLifeCycleListener(lifeCycleListener);
94 | waitDialog.showDialog();
95 | return waitDialog;
96 | }
97 | }
98 |
99 | private BlurView blur;
100 | private int blur_front_color;
101 | private int font_color;
102 |
103 | private RelativeLayout boxInfo;
104 | private RelativeLayout boxBkg;
105 | private RelativeLayout boxProgress;
106 | private ProgressView progress;
107 | private TextView txtInfo;
108 |
109 | private KongzueDialogHelper kongzueDialogHelper;
110 |
111 | public void showDialog() {
112 | if (customTextInfo == null) {
113 | customTextInfo = tipTextInfo;
114 | }
115 |
116 | dialogList.add(waitDialog);
117 | log("显示等待对话框 -> " + tip);
118 |
119 | AlertDialog.Builder builder;
120 | int bkgResId;
121 | switch (tip_theme) {
122 | case THEME_LIGHT:
123 | builder = new AlertDialog.Builder(context, R.style.lightMode);
124 | bkgResId = R.drawable.rect_light;
125 | blur_front_color = Color.argb(blur_alpha, 255, 255, 255);
126 | font_color = Color.rgb(0, 0, 0);
127 | break;
128 | default:
129 | builder = new AlertDialog.Builder(context, R.style.darkMode);
130 | bkgResId = R.drawable.rect_dark;
131 | blur_front_color = Color.argb(blur_alpha, 0, 0, 0);
132 | font_color = Color.rgb(255, 255, 255);
133 | break;
134 | }
135 |
136 | alertDialog = builder.create();
137 |
138 |
139 | getDialogLifeCycleListener().onCreate(alertDialog);
140 | if (isCanCancel) alertDialog.setCanceledOnTouchOutside(true);
141 |
142 | FragmentManager fragmentManager = ((AppCompatActivity) context).getSupportFragmentManager();
143 | kongzueDialogHelper = new KongzueDialogHelper().setAlertDialog(alertDialog, new OnDismissListener() {
144 | @Override
145 | public void onDismiss() {
146 | dialogList.remove(waitDialog);
147 | if (boxProgress != null) boxProgress.removeAllViews();
148 | if (boxBkg != null) boxBkg.removeAllViews();
149 |
150 | getDialogLifeCycleListener().onDismiss();
151 | alertDialog = null;
152 | getOnDismissListener().onDismiss();
153 | }
154 | });
155 |
156 | View rootView = LayoutInflater.from(context).inflate(R.layout.dialog_wait, null);
157 | alertDialog.setView(rootView);
158 |
159 | boxInfo = rootView.findViewById(R.id.box_info);
160 | boxBkg = rootView.findViewById(R.id.box_bkg);
161 | boxProgress = rootView.findViewById(R.id.box_progress);
162 | progress = rootView.findViewById(R.id.progress);
163 | txtInfo = rootView.findViewById(R.id.txt_info);
164 |
165 | txtInfo.setTextColor(font_color);
166 |
167 | if (customView != null) {
168 | progress.setVisibility(View.GONE);
169 | boxProgress.removeAllViews();
170 | boxProgress.addView(customView);
171 | }
172 |
173 | if (tip_theme == THEME_LIGHT) {
174 | progress.setStrokeColors(new int[]{Color.rgb(0, 0, 0)});
175 | } else {
176 | progress.setStrokeColors(new int[]{Color.rgb(255, 255, 255)});
177 | }
178 |
179 | if (use_blur) {
180 | blur = new BlurView(context, null);
181 | boxBkg.post(new Runnable() {
182 | @Override
183 | public void run() {
184 | RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
185 | blur.setLayoutParams(params);
186 | blur.setOverlayColor(blur_front_color);
187 | boxBkg.addView(blur, 0, params);
188 | }
189 | });
190 | boxBkg.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
191 | @Override
192 | public void onGlobalLayout() {
193 | ViewGroup.LayoutParams boxBkgLayoutParams = boxBkg.getLayoutParams();
194 | boxBkgLayoutParams.width = boxInfo.getWidth();
195 | boxBkgLayoutParams.height = boxInfo.getHeight();
196 | boxBkg.setLayoutParams(boxBkgLayoutParams);
197 | }
198 | });
199 | } else {
200 | boxBkg.setBackgroundResource(bkgResId);
201 | }
202 |
203 | if (tip != null && !tip.isEmpty()) {
204 | txtInfo.setVisibility(View.VISIBLE);
205 | txtInfo.setText(tip);
206 | } else {
207 | txtInfo.setVisibility(View.GONE);
208 |
209 | RelativeLayout.LayoutParams lp = ((RelativeLayout.LayoutParams) boxProgress.getLayoutParams());
210 | lp.setMargins(0, 0, 0, 0);
211 | lp.addRule(RelativeLayout.CENTER_IN_PARENT);
212 | boxProgress.setLayoutParams(lp);
213 |
214 | }
215 |
216 | if (customTextInfo.getFontSize() > 0) {
217 | txtInfo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, customTextInfo.getFontSize());
218 | }
219 | if (customTextInfo.getFontColor() != 1) {
220 | txtInfo.setTextColor(customTextInfo.getFontColor());
221 | }
222 | if (customTextInfo.getGravity() != -1) {
223 | txtInfo.setGravity(customTextInfo.getGravity());
224 | }
225 |
226 | Typeface font = Typeface.create(Typeface.SANS_SERIF, customTextInfo.isBold() ? Typeface.BOLD : Typeface.NORMAL);
227 | txtInfo.setTypeface(font);
228 |
229 | alertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
230 | @Override
231 | public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
232 | if (event.getAction() == KeyEvent.ACTION_UP) {
233 | if (keyCode == KeyEvent.KEYCODE_BACK) {
234 | if (onBackPressListener != null) {
235 | onBackPressListener.OnBackPress(alertDialog);
236 | return true;
237 | }
238 | }
239 | }
240 | return false;
241 | }
242 | });
243 |
244 | getDialogLifeCycleListener().onShow(alertDialog);
245 |
246 | kongzueDialogHelper.show(fragmentManager, "kongzueDialog");
247 | kongzueDialogHelper.setCancelable(isCanCancel);
248 | }
249 |
250 | @Override
251 | public void doDismiss() {
252 | if (kongzueDialogHelper != null) kongzueDialogHelper.dismissAllowingStateLoss();
253 | }
254 |
255 | public WaitDialog setCanCancel(boolean canCancel) {
256 | if (kongzueDialogHelper != null) kongzueDialogHelper.setCancelable(canCancel);
257 | return this;
258 | }
259 |
260 | public static void setCanCancelGlobal(boolean canCancel) {
261 | isCanCancel = canCancel;
262 | }
263 |
264 | public WaitDialog setOnBackPressListener(OnBackPressListener onBackPressListener) {
265 | this.onBackPressListener = onBackPressListener;
266 | return this;
267 | }
268 |
269 | public static void dismiss() {
270 | for (BaseDialog dialog : dialogList) {
271 | if (dialog instanceof WaitDialog) {
272 | dialog.doDismiss();
273 | }
274 | }
275 | }
276 |
277 | public void setText(String s) {
278 | if (waitDialog != null && waitDialog.txtInfo != null) {
279 | waitDialog.txtInfo.setText(s);
280 | }
281 | }
282 |
283 | public AlertDialog getAlertDialog() {
284 | return alertDialog;
285 | }
286 | }
287 |
--------------------------------------------------------------------------------
/dialog/src/main/java/com/kongzue/dialog/v2/TipDialog.java:
--------------------------------------------------------------------------------
1 | package com.kongzue.dialog.v2;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Color;
7 | import android.graphics.Typeface;
8 | import android.graphics.drawable.Drawable;
9 | import android.os.Handler;
10 | import android.support.v4.app.FragmentManager;
11 | import android.support.v4.app.FragmentTransaction;
12 | import android.support.v7.app.AlertDialog;
13 | import android.support.v7.app.AppCompatActivity;
14 | import android.util.TypedValue;
15 | import android.view.LayoutInflater;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.view.ViewTreeObserver;
19 | import android.view.Window;
20 | import android.widget.ImageView;
21 | import android.widget.RelativeLayout;
22 | import android.widget.TextView;
23 |
24 | import com.kongzue.dialog.R;
25 | import com.kongzue.dialog.listener.OnDismissListener;
26 | import com.kongzue.dialog.util.BaseDialog;
27 | import com.kongzue.dialog.util.BlurView;
28 | import com.kongzue.dialog.util.KongzueDialogHelper;
29 | import com.kongzue.dialog.util.TextInfo;
30 |
31 | import java.util.Timer;
32 | import java.util.TimerTask;
33 |
34 | import static com.kongzue.dialog.v2.DialogSettings.THEME_LIGHT;
35 | import static com.kongzue.dialog.v2.DialogSettings.blur_alpha;
36 | import static com.kongzue.dialog.v2.DialogSettings.tipTextInfo;
37 | import static com.kongzue.dialog.v2.DialogSettings.tip_theme;
38 | import static com.kongzue.dialog.v2.DialogSettings.use_blur;
39 |
40 | public class TipDialog extends BaseDialog {
41 |
42 | public static final int SHOW_TIME_SHORT = 0;
43 | public static final int SHOW_TIME_LONG = 1;
44 |
45 | public static final int TYPE_CUSTOM_DRAWABLE = -2;
46 | public static final int TYPE_CUSTOM_BITMAP = -1;
47 | public static final int TYPE_WARNING = 0;
48 | public static final int TYPE_ERROR = 1;
49 | public static final int TYPE_FINISH = 2;
50 |
51 | private AlertDialog alertDialog;
52 | private TipDialog tipDialog;
53 | private Drawable customDrawable;
54 | private Bitmap customBitmap;
55 | private boolean isCanCancel = false;
56 |
57 | private TextInfo customTextInfo;
58 |
59 | private Context context;
60 | private String tip;
61 |
62 | private TipDialog() {
63 | }
64 |
65 | private int howLong = 0;
66 | private int type = 0;
67 |
68 | //Fast Function
69 | public static TipDialog show(Context context, String tip) {
70 | TipDialog tipDialog = build(context, tip, SHOW_TIME_SHORT, TYPE_WARNING);
71 | tipDialog.showDialog();
72 | return tipDialog;
73 | }
74 |
75 | public static TipDialog show(Context context, String tip, int type) {
76 | TipDialog tipDialog = build(context, tip, SHOW_TIME_SHORT, type);
77 | tipDialog.showDialog();
78 | return tipDialog;
79 | }
80 |
81 | public static TipDialog show(Context context, String tip, int howLong, int type) {
82 | TipDialog tipDialog = build(context, tip, howLong, type);
83 | tipDialog.showDialog();
84 | return tipDialog;
85 | }
86 |
87 | public static TipDialog build(Context context, String tip, int howLong, int type) {
88 | synchronized (TipDialog.class) {
89 | TipDialog tipDialog = new TipDialog();
90 | tipDialog.cleanDialogLifeCycleListener();
91 | tipDialog.context = context;
92 | tipDialog.tip = tip;
93 | tipDialog.howLong = howLong;
94 | tipDialog.type = type;
95 | tipDialog.log("装载提示对话框 -> " + tip);
96 | tipDialog.tipDialog = tipDialog;
97 | return tipDialog;
98 | }
99 | }
100 |
101 | public static TipDialog show(Context context, String tip, int howLong, Drawable customDrawable) {
102 | TipDialog tipDialog = build(context, tip, howLong, customDrawable);
103 | tipDialog.showDialog();
104 | return tipDialog;
105 | }
106 |
107 | public static TipDialog build(Context context, String tip, int howLong, Drawable customDrawable) {
108 | synchronized (TipDialog.class) {
109 | TipDialog tipDialog = new TipDialog();
110 | tipDialog.cleanDialogLifeCycleListener();
111 | tipDialog.context = context;
112 | tipDialog.tip = tip;
113 | tipDialog.customDrawable = customDrawable;
114 | tipDialog.howLong = howLong;
115 | tipDialog.type = TYPE_CUSTOM_DRAWABLE;
116 | tipDialog.log("装载提示对话框 -> " + tip);
117 | tipDialog.tipDialog = tipDialog;
118 | return tipDialog;
119 | }
120 | }
121 |
122 | public static TipDialog show(Context context, String tip, int howLong, Bitmap customBitmap) {
123 | TipDialog tipDialog = build(context, tip, howLong, customBitmap);
124 | tipDialog.showDialog();
125 | return tipDialog;
126 | }
127 |
128 | public static TipDialog build(Context context, String tip, int howLong, Bitmap customBitmap) {
129 | synchronized (TipDialog.class) {
130 | TipDialog tipDialog = new TipDialog();
131 | tipDialog.cleanDialogLifeCycleListener();
132 | tipDialog.context = context;
133 | tipDialog.tip = tip;
134 | tipDialog.customBitmap = customBitmap;
135 | tipDialog.howLong = howLong;
136 | tipDialog.type = TYPE_CUSTOM_BITMAP;
137 | tipDialog.log("装载提示对话框 -> " + tip);
138 | tipDialog.tipDialog = tipDialog;
139 | return tipDialog;
140 | }
141 | }
142 |
143 | private RelativeLayout boxInfo;
144 | private RelativeLayout boxBkg;
145 | private ImageView image;
146 | private TextView txtInfo;
147 |
148 | private BlurView blur;
149 | private int blur_front_color;
150 | private int font_color;
151 |
152 | private KongzueDialogHelper kongzueDialogHelper;
153 |
154 | public void showDialog() {
155 | if (customTextInfo == null) {
156 | customTextInfo = tipTextInfo;
157 | }
158 |
159 | AlertDialog.Builder builder;
160 | log("显示提示对话框 -> " + tip);
161 | dialogList.add(tipDialog);
162 |
163 | int bkgResId;
164 | switch (tip_theme) {
165 | case THEME_LIGHT:
166 | builder = new AlertDialog.Builder(context, R.style.lightMode);
167 | bkgResId = R.drawable.rect_light;
168 | blur_front_color = Color.argb(blur_alpha - 50, 255, 255, 255);
169 | font_color = Color.rgb(0, 0, 0);
170 | break;
171 | default:
172 | builder = new AlertDialog.Builder(context, R.style.darkMode);
173 | bkgResId = R.drawable.rect_dark;
174 | blur_front_color = Color.argb(blur_alpha, 0, 0, 0);
175 | font_color = Color.rgb(255, 255, 255);
176 | break;
177 | }
178 |
179 | alertDialog = builder.create();
180 | getDialogLifeCycleListener().onCreate(alertDialog);
181 | if (isCanCancel) alertDialog.setCanceledOnTouchOutside(true);
182 |
183 | FragmentManager fragmentManager = ((AppCompatActivity) context).getSupportFragmentManager();
184 | kongzueDialogHelper = new KongzueDialogHelper().setAlertDialog(alertDialog, new OnDismissListener() {
185 | @Override
186 | public void onDismiss() {
187 | dialogList.remove(tipDialog);
188 | if (boxBkg != null) boxBkg.removeAllViews();
189 | getDialogLifeCycleListener().onDismiss();
190 | getOnDismissListener().onDismiss();
191 | }
192 | });
193 |
194 | View rootView = LayoutInflater.from(context).inflate(R.layout.dialog_tip, null);
195 | alertDialog.setView(rootView);
196 |
197 | boxInfo = rootView.findViewById(R.id.box_info);
198 | boxBkg = rootView.findViewById(R.id.box_bkg);
199 | image = rootView.findViewById(R.id.image);
200 | txtInfo = rootView.findViewById(R.id.txt_info);
201 |
202 | txtInfo.setTextColor(font_color);
203 |
204 | if (use_blur) {
205 | blur = new BlurView(context, null);
206 | boxBkg.post(new Runnable() {
207 | @Override
208 | public void run() {
209 | RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
210 | blur.setLayoutParams(params);
211 | blur.setOverlayColor(blur_front_color);
212 | boxBkg.addView(blur, 0, params);
213 | }
214 | });
215 | boxBkg.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
216 | @Override
217 | public void onGlobalLayout() {
218 | ViewGroup.LayoutParams boxBkgLayoutParams = boxBkg.getLayoutParams();
219 | boxBkgLayoutParams.width = boxInfo.getWidth();
220 | boxBkgLayoutParams.height = boxInfo.getHeight();
221 | boxBkg.setLayoutParams(boxBkgLayoutParams);
222 | }
223 | });
224 |
225 | } else {
226 | boxInfo.setBackgroundResource(bkgResId);
227 | }
228 |
229 | switch (type) {
230 | case TYPE_WARNING:
231 | if (tip_theme == THEME_LIGHT) {
232 | image.setImageResource(R.mipmap.img_warning_dark);
233 | } else {
234 | image.setImageResource(R.mipmap.img_warning);
235 | }
236 | break;
237 | case TYPE_ERROR:
238 | if (tip_theme == THEME_LIGHT) {
239 | image.setImageResource(R.mipmap.img_error_dark);
240 | } else {
241 | image.setImageResource(R.mipmap.img_error);
242 | }
243 | break;
244 | case TYPE_FINISH:
245 | if (tip_theme == THEME_LIGHT) {
246 | image.setImageResource(R.mipmap.img_finish_dark);
247 | } else {
248 | image.setImageResource(R.mipmap.img_finish);
249 | }
250 | break;
251 | case TYPE_CUSTOM_BITMAP:
252 | image.setImageBitmap(customBitmap);
253 | break;
254 | case TYPE_CUSTOM_DRAWABLE:
255 | image.setImageDrawable(customDrawable);
256 | break;
257 | }
258 |
259 | if (!tip.isEmpty()) {
260 | boxInfo.setVisibility(View.VISIBLE);
261 | txtInfo.setText(tip);
262 | } else {
263 | boxInfo.setVisibility(View.GONE);
264 | }
265 |
266 | if (customTextInfo.getFontSize() > 0) {
267 | txtInfo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, customTextInfo.getFontSize());
268 | }
269 | if (customTextInfo.getFontColor() != 1) {
270 | txtInfo.setTextColor(customTextInfo.getFontColor());
271 | }
272 | if (customTextInfo.getGravity() != -1) {
273 | txtInfo.setGravity(customTextInfo.getGravity());
274 | }
275 | Typeface font = Typeface.create(Typeface.SANS_SERIF, customTextInfo.isBold() ? Typeface.BOLD : Typeface.NORMAL);
276 | txtInfo.setTypeface(font);
277 |
278 | getDialogLifeCycleListener().onShow(alertDialog);
279 |
280 | int time = 1500;
281 | switch (howLong) {
282 | case SHOW_TIME_SHORT:
283 | time = 1500;
284 | break;
285 | case SHOW_TIME_LONG:
286 | time = 3000;
287 | break;
288 | }
289 | new Timer().schedule(new TimerTask() {
290 | @Override
291 | public void run() {
292 | if (kongzueDialogHelper != null) kongzueDialogHelper.dismissAllowingStateLoss();
293 | }
294 | }, time);
295 |
296 | kongzueDialogHelper.show(fragmentManager, "kongzueDialog");
297 | kongzueDialogHelper.setCancelable(isCanCancel);
298 | }
299 |
300 | @Override
301 | public void doDismiss() {
302 | if (kongzueDialogHelper != null) kongzueDialogHelper.dismissAllowingStateLoss();
303 | }
304 |
305 | public TipDialog setCanCancel(boolean canCancel) {
306 | isCanCancel = canCancel;
307 | if (kongzueDialogHelper != null) kongzueDialogHelper.setCancelable(canCancel);
308 | return this;
309 | }
310 |
311 | public TipDialog setTxtInfo(TextView txtInfo) {
312 | this.txtInfo = txtInfo;
313 | return this;
314 | }
315 |
316 | public AlertDialog getAlertDialog() {
317 | return alertDialog;
318 | }
319 | }
320 |
--------------------------------------------------------------------------------
/README-Eng.md:
--------------------------------------------------------------------------------
1 | # Kongzue's Dialog 2.3
2 | To the products that require Android to follow apple's design (XD
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | Kongzue's Dialog have pop-up styles that provide the simplest way to invoke a message box, a selection box, an input box, a wait prompt, a warning prompt, a completion prompt, an error prompt, and so on. The following is a preview of all dialog styles currently included:
18 |
19 | 
20 |
21 | The trial can be downloaded from http://fir.im/kongzueDial
22 |
23 | 
24 |
25 | For example,this repository has DialogDemo(Dialog/app/)is the demo project source code,Library(Dialog/dialog/)is source code of Kongzue's Dialog.
26 |
27 | Maven: https://bintray.com/myzchh/maven/dialog
28 |
29 | This project follows the Apache - 2.0 open source protocol, which can be referenced: http://www.opensource.org/licenses/apache2.0.php
30 |
31 | ## Maven & Gradle
32 | Maven:
33 | ```
34 |
35 | com.kongzue.dialog
36 | dialog
37 | 2.5.2
38 | pom
39 |
40 | ```
41 | Gradle:
42 | ```
43 | implementation 'com.kongzue.dialog:dialog:2.5.2'
44 | ```
45 |
46 | ## Explanation
47 | 1) Initialization style of Kongzue's Dialog:
48 | ```
49 | DialogSettings.type = STYLE_MATERIAL;
50 | ```
51 |
52 | Material style: DialogSettings.STYLE_MATERIAL,
53 |
54 | Kongzue style: DialogSettings.STYLE_KONGZUE,
55 |
56 | iOS style: DialogSettings.STYLE_IOS
57 |
58 | Style settings are only for dialog boxes, not include prompt and wait boxes
59 |
60 | 2) Light & Dark Mode:
61 | ```
62 | DialogSettings.tip_theme = THEME_LIGHT; //Set the prompt box theme to a light color theme
63 | DialogSettings.dialog_theme = THEME_DARK; //Set the dialog box theme to a dark color theme
64 | ```
65 |
66 | Preview:
67 | 
68 |
69 | 3) Starting with version 2.0.4, provides notification capabilities that do not require suspend window permissions and can be displayed across domains, as shown in the following figure:
70 | 
71 |
72 | 4) Starting with version 2.1.0, the bottom menu is available and is available through com.kongzue.dialog.v2.BottomMenu, as shown in the following figure:
73 | 
74 |
75 | 5) Starting with version 2.1.1, iOS style dialogs, prompt boxes, and bottom menus add instant blur effects:
76 | 
77 |
78 | ## About v2 packages
79 | In the empty ancestors dialog component, still retains the generation of component library but is no longer recommended, this is to maintain compatibility, if forced to use you will see the name of the relevant class has a strikethrough.
80 |
81 | For more efficient development, we now strongly recommend using the v2 component library directly, which contains package addresses of: com.kongzue.dialog.v2
82 |
83 | ### About blur mode
84 | You can set blur mode by properties:
85 | ```
86 | DialogSettings.use_blur = true; //Sets whether obfuscation is enabled
87 | ```
88 | If you need to start, also need in your build.gradle(app) add code:
89 | ```
90 | android {
91 | ...
92 | defaultConfig {
93 | ...
94 |
95 | renderscriptTargetApi 19
96 | renderscriptSupportModeEnabled true
97 | }
98 | }
99 | ```
100 | The blur effect is currently valid only for three dialog boxes, prompt boxes, wait boxes, and bottom menus when DialogSettings.type = STYLE_IOS.
101 |
102 | ### Message Dialog:
103 | ```
104 | MessageDialog.show(me, "Title", "message", "ok", new DialogInterface.OnClickListener() {
105 | @Override
106 | public void onClick(DialogInterface dialog, int which) {
107 | }
108 | });
109 | ```
110 | Fast Function:
111 | ```
112 | MessageDialog.show(me, "Welcome", "Welcome to the kongzu home dialog box, which provides several common dialog box styles.\nIf you have any questions can be in https://github.com/kongzue/Dialog submit feedback");
113 | ```
114 |
115 | ### Selection Dialog:
116 | ```
117 | SelectDialog.show(me, "Title", "message", "ok", new DialogInterface.OnClickListener() {
118 | @Override
119 | public void onClick(DialogInterface dialog, int which) {
120 | Toast.makeText(me, "You click ok button.", Toast.LENGTH_SHORT).show();
121 | }
122 | }, "Cancel", new DialogInterface.OnClickListener() {
123 | @Override
124 | public void onClick(DialogInterface dialog, int which) {
125 | Toast.makeText(me, "You click cancel button.", Toast.LENGTH_SHORT).show();
126 | }
127 | });
128 | ```
129 | Fast Function:
130 | ```
131 | SelectDialog.show(me, "Title", "message", new DialogInterface.OnClickListener() {
132 | @Override
133 | public void onClick(DialogInterface dialog, int which) {
134 | Toast.makeText(me, "You click ok button.", Toast.LENGTH_SHORT).show();
135 | }
136 | });
137 | ```
138 |
139 | ### Input Dialog:
140 | ```
141 | InputDialog.show(me, "Set a nickname", "Set a nice name", "ok", new InputDialogOkButtonClickListener() {
142 | @Override
143 | public void onClick(Dialog dialog, String inputText) {
144 | Toast.makeText(me, "You entered:" + inputText, Toast.LENGTH_SHORT).show();
145 | }
146 | }, "Cancel", new DialogInterface.OnClickListener() {
147 | @Override
148 | public void onClick(DialogInterface dialog, int which) {
149 |
150 | }
151 | });
152 | ```
153 | Fast Function:
154 | ```
155 | InputDialog.show(me, "Set a nickname", "Set a nice name", new InputDialogOkButtonClickListener() {
156 | @Override
157 | public void onClick(Dialog dialog, String inputText) {
158 | Toast.makeText(me, "You entered:" + inputText, Toast.LENGTH_SHORT).show();
159 | }
160 | });
161 | ```
162 |
163 | ### Wait Dialog:
164 | ```
165 | WaitDialog.show(me, "Loading...");
166 | ```
167 |
168 | ### Tip Dialog - Finish:
169 | ```
170 | TipDialog.show(me, "Finish", TipDialog.SHOW_TIME_SHORT, TipDialog.TYPE_FINISH);
171 | ```
172 |
173 | ### Tip Dialog - Warning:
174 | ```
175 | TipDialog.show(me, "Warning", TipDialog.SHOW_TIME_SHORT, TipDialog.TYPE_WARNING);
176 | ```
177 |
178 | ### Tip Dialog - Error:
179 | ```
180 | TipDialog.show(me, "Error", TipDialog.SHOW_TIME_LONG, TipDialog.TYPE_ERROR);
181 | ```
182 |
183 | ### Notifaction:
184 |
185 | Note: that the notification class from com.kongzue.dialog.v2 is used here.
186 |
187 | The main difference between the notification message and the prompt frame is that the prompt frame will interrupt the operation used, and the message notification will not. the message notification is suitable for the business scenario in which the user needs to be reminded whether to process the message or not, and the prompt frame is suitable for the business scenario in which the user operation is blocked and the user is reminded of the current situation.
188 |
189 | ```
190 | Notification.show(me, id, iconResId, getString(R.string.app_name), "This is a message", Notification.SHOW_TIME_LONG, notifactionType)
191 | .setOnNotificationClickListener(new Notification.OnNotificationClickListener() {
192 | @Override
193 | public void OnClick(int id) {
194 | Toast.makeText(me,"Click the notification",SHOW_TIME_SHORT).show();
195 | }
196 | })
197 | ;
198 | ```
199 | Where the id is the notification message id and is called back in the OnNotificationClickListener after the user clicks on the notification.
200 |
201 | Note: that the message type colorType here is currently valid only for the Kongzue Style, and the styles provided are:
202 |
203 | type | color | Default
204 | ---|---|---
205 | TYPE_NORMAL | Grey black | Yes
206 | TYPE_FINISH | Green | No
207 | TYPE_WARNING | Orange | No
208 | TYPE_ERROR | Red | No
209 |
210 | After version 2.0.6, if the colorType is not the above setting, you can use the autoshape value, which is the return value of the Color class.
211 |
212 | Fast Function:
213 | ```
214 | Notification.show(me, 0, "", "This is a message", Notification.SHOW_TIME_SHORT, notifactionType);
215 | ```
216 |
217 | ### Bottom Menu:
218 |
219 | Note: that the BottomMenu class from com.kongzue.dialog.v2 is used here.
220 | ```
221 | List list = new ArrayList<>();
222 | list.add("Menu 1");
223 | list.add("Menu 2");
224 | list.add("Menu 3");
225 | BottomMenu.show(me, list, new OnMenuItemClickListener() {
226 | @Override
227 | public void onClick(String text, int index) {
228 | Toast.makeText(me,"Menu " + text + " be click.",SHOW_TIME_SHORT).show();
229 | }
230 | },true);
231 | ```
232 |
233 | Add title:
234 | ```
235 | BottomMenu.show(me, list).setTitle("这里是标题测试");
236 | ```
237 |
238 | Note: This menu is temporarily unaffected by night mode (THEME_DARK) and only provides light theme, but does not preclude subsequent versions from updating it.
239 |
240 | When using iOS style,DialogSettings.ios_normal_button_color affects the color of the menu content text, and other topics are not affected by this property.
241 |
242 | Fast Function:
243 | ```
244 | List list = new ArrayList<>();
245 | list.add("Menu 1");
246 | list.add("Menu 2");
247 | list.add("Menu 3");
248 | BottomMenu.show(me, list);
249 | ```
250 |
251 | ## Custom Layout:
252 | Custom layouts for message dialog, select dialog, input dialog, and bottom menu are supported from version 2.2.3. for some reasons, only dialog boxes using custom layouts are supported when selecting the material style.
253 |
254 | exp.
255 | ```
256 | //initViews:
257 | View customView = LayoutInflater.from(me).inflate(R.layout.layout_custom, null);
258 | //startDialog
259 | MessageDialog.show(me, null, null, "Ok", new DialogInterface.OnClickListener() {
260 | @Override
261 | public void onClick(DialogInterface dialog, int which) {
262 |
263 | }
264 | }).setCustomView(customView);
265 | ```
266 |
267 | ## additional function:
268 | In any kind of dialog box can use .setCanCancel(boolean) to set whether you can click on the dialog box outside the area closed dialog box, prompt class is prohibited by default, select, input dialog box is prohibited by default, the message dialog box is allowed by default.
269 |
270 | Use the method to refer to the following code:
271 | ```
272 | WaitDialog.show(me, "Loading...").setCanCancel(true);
273 | ```
274 | In the empty ancestors dialog component, you can use the listener to listen to the dialog lifecycle, demo is as follows:
275 | ```
276 | WaitDialog.show(me, "Loading...").setCanCancel(true).setDialogLifeCycleListener(new DialogLifeCycleListener() {
277 | @Override
278 | public void onCreate(AlertDialog alertDialog) {
279 | //dialog building
280 | }
281 | @Override
282 | public void onShow(AlertDialog alertDialog) {
283 | //dialog show
284 | }
285 | @Override
286 | public void onDismiss() {
287 | //dialog close
288 | }
289 | });
290 | ```
291 |
292 | Additional custom properties are available:
293 | ```
294 | DialogSettings.dialog_title_text_size = -1; //Set dialog title text size, <= 0 is not enabled
295 | DialogSettings.dialog_message_text_size = -1; //Set dialog box content text size, <= 0 is not enabled
296 | DialogSettings.dialog_button_text_size = -1; //Set dialog button text size, <= 0 is not enabled
297 | DialogSettings.dialog_menu_text_size = -1; //Set bottom menu text size, <= 0 is not enabled
298 | DialogSettings.tip_text_size = -1; //Set prompt box text size, <= 0 is not enabled
299 | DialogSettings.ios_normal_button_color = -1; //Set IOs style default button text color, = -1 not enabled
300 | ```
301 |
302 | ## License
303 | ```
304 | Copyright Kongzue Dialog
305 |
306 | Licensed under the Apache License, Version 2.0 (the "License");
307 | you may not use this file except in compliance with the License.
308 | You may obtain a copy of the License at
309 |
310 | http://www.apache.org/licenses/LICENSE-2.0
311 |
312 | Unless required by applicable law or agreed to in writing, software
313 | distributed under the License is distributed on an "AS IS" BASIS,
314 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
315 | See the License for the specific language governing permissions and
316 | limitations under the License.
317 | ```
318 |
--------------------------------------------------------------------------------