1
1
package com .developer .kalert ;
2
2
3
- import android .app .AlertDialog ;
3
+ import android .app .Dialog ;
4
4
import android .content .Context ;
5
5
import android .graphics .drawable .Drawable ;
6
6
import android .os .Bundle ;
12
12
import android .view .animation .AnimationSet ;
13
13
import android .view .animation .Transformation ;
14
14
import android .widget .Button ;
15
+ import android .widget .EditText ;
15
16
import android .widget .FrameLayout ;
16
17
import android .widget .ImageView ;
17
18
import android .widget .TextView ;
19
+ <<<<<<< HEAD
20
+ =======
21
+
22
+ >>>>>>> 357968d 342f 7 ba2ebb7cde76a39e44438efdff44
18
23
import java .util .Objects ;
19
24
20
25
/**
21
26
* @author akshay sunil masram
22
27
*/
28
+ <<<<<<< HEAD
23
29
public class KAlertDialog extends AlertDialog implements View .OnClickListener {
24
30
25
31
private final AnimationSet mModalInAnim ,mModalOutAnim ,mErrorXInAnim ;//,mSuccessLayoutAnimSet;
@@ -48,22 +54,49 @@ public class KAlertDialog extends AlertDialog implements View.OnClickListener {
48
54
49
55
private int mAlertType ;
50
56
public static final int NORMAL_TYPE = 0 ;
57
+ =======
58
+ public class KAlertDialog extends Dialog implements View .OnClickListener {
59
+
60
+ >>>>>>> 357968d 342f 7 ba2ebb7cde76a39e44438efdff44
51
61
public static final int ERROR_TYPE = 1 ;
52
62
public static final int SUCCESS_TYPE = 2 ;
53
63
public static final int WARNING_TYPE = 3 ;
54
64
public static final int CUSTOM_IMAGE_TYPE = 4 ;
55
65
public static final int PROGRESS_TYPE = 5 ;
66
+ <<<<<<< HEAD
56
67
57
68
public static boolean DARK_STYLE = false ;
58
69
59
70
public interface KAlertClickListener {
60
71
void onClick (KAlertDialog kAlertDialog );
61
72
}
73
+ =======
74
+ public static final int INPUT_TYPE = 6 ;
75
+ private static final int NORMAL_TYPE = 0 ;
76
+ private final AnimationSet mModalInAnim , mModalOutAnim , mErrorXInAnim , mSuccessLayoutAnimSet ;
77
+ private final Animation mOverlayOutAnim , mErrorInAnim , mSuccessBowAnim ;
78
+ private final ProgressHelper mProgressHelper ;
79
+ private EditText mEditText ;
80
+ private TextView mTitleTextView , mContentTextView ;
81
+ private ImageView mErrorX , mCustomImage ;
82
+ private Drawable mCustomImgDrawable ;
83
+ private Button mConfirmButton , mCancelButton ;
84
+ private Drawable mColor , mCancelColor ;
85
+ private View mDialogView , mSuccessLeftMask , mSuccessRightMask ;
86
+ private String mTitleText , mContentText , mCancelText , mConfirmText ;
87
+ private boolean mShowCancel , mShowContent , mShowTitleText , mCloseFromCancel ;
88
+ private FrameLayout mErrorFrame , mSuccessFrame , mProgressFrame , mWarningFrame , mEditTextFrame ;
89
+ private SuccessTickView mSuccessTick ;
90
+ private KAlertClickListener mCancelClickListener ;
91
+ private KAlertClickListener mConfirmClickListener ;
92
+ private int mAlertType ;
93
+ >>>>>>> 357968d 342f 7 ba2ebb7cde76a39e44438efdff44
62
94
63
95
public KAlertDialog (Context context ) {
64
96
this (context , NORMAL_TYPE );
65
97
}
66
98
99
+ <<<<<<< HEAD
67
100
protected void onCreate (Bundle savedInstanceState ) {
68
101
super .onCreate (savedInstanceState );
69
102
setContentView (R .layout .alert_dialog );
@@ -98,6 +131,8 @@ protected void onCreate(Bundle savedInstanceState) {
98
131
changeAlertType (mAlertType , true );
99
132
}
100
133
134
+ =======
135
+ >>>>>>> 357968d 342f 7 ba2ebb7cde76a39e44438efdff44
101
136
public KAlertDialog (Context context , int alertType ) {
102
137
super (context , DARK_STYLE ? R .style .alert_dialog_dark : R .style .alert_dialog_light );
103
138
@@ -113,7 +148,8 @@ public KAlertDialog(Context context, int alertType) {
113
148
mModalOutAnim = (AnimationSet ) AnimationLoader .loadAnimation (getContext (), R .anim .modal_out );
114
149
Objects .requireNonNull (mModalOutAnim ).setAnimationListener (new Animation .AnimationListener () {
115
150
@ Override
116
- public void onAnimationStart (Animation animation ) { }
151
+ public void onAnimationStart (Animation animation ) {
152
+ }
117
153
118
154
@ Override
119
155
public void onAnimationEnd (Animation animation ) {
@@ -128,7 +164,8 @@ public void onAnimationEnd(Animation animation) {
128
164
}
129
165
130
166
@ Override
131
- public void onAnimationRepeat (Animation animation ) { }
167
+ public void onAnimationRepeat (Animation animation ) {
168
+ }
132
169
});
133
170
mOverlayOutAnim = new Animation () {
134
171
@ Override
@@ -139,14 +176,52 @@ protected void applyTransformation(float interpolatedTime, Transformation t) {
139
176
}
140
177
};
141
178
mOverlayOutAnim .setDuration (120 );
179
+
180
+ Objects .requireNonNull (this .getWindow ()).setSoftInputMode (WindowManager .LayoutParams .SOFT_INPUT_STATE_ALWAYS_HIDDEN );
142
181
}
143
182
144
- private void restore () {
183
+ protected void onCreate (Bundle savedInstanceState ) {
184
+
185
+ super .onCreate (savedInstanceState );
186
+ setContentView (R .layout .alert_dialog );
187
+
188
+ mDialogView = Objects .requireNonNull (getWindow ()).getDecorView ().findViewById (android .R .id .content );
189
+ mEditText = findViewById (R .id .edit_text );
190
+ mTitleTextView = findViewById (R .id .title_text );
191
+ mContentTextView = findViewById (R .id .content_text );
192
+ mErrorFrame = findViewById (R .id .error_frame );
193
+ mErrorX = Objects .requireNonNull (mErrorFrame ).findViewById (R .id .error_x );
194
+ mSuccessFrame = findViewById (R .id .success_frame );
195
+ mProgressFrame = findViewById (R .id .progress_dialog );
196
+ mSuccessTick = mSuccessFrame .findViewById (R .id .success_tick );
197
+ mSuccessLeftMask = mSuccessFrame .findViewById (R .id .mask_left );
198
+ mSuccessRightMask = mSuccessFrame .findViewById (R .id .mask_right );
199
+ mCustomImage = findViewById (R .id .custom_image );
200
+ mWarningFrame = findViewById (R .id .warning_frame );
201
+ mEditTextFrame = findViewById (R .id .edit_text_frame );
202
+ mProgressHelper .setProgressWheel (findViewById (R .id .progressWheel ));
203
+
204
+ mConfirmButton = findViewById (R .id .custom_confirm_button );
205
+ mCancelButton = findViewById (R .id .cancel_button );
206
+ mConfirmButton .setOnClickListener (this );
207
+ mCancelButton .setOnClickListener (this );
208
+
209
+ setTitleText (mTitleText );
210
+ setContentText (mContentText );
211
+ setCancelText (mCancelText );
212
+ setConfirmText (mConfirmText );
213
+ setConfirmButtonColor (mColor );
214
+ setCancelButtonColor (mCancelColor );
215
+ changeAlertType (mAlertType , true );
216
+ }
217
+
218
+ private void restore () {
145
219
mCustomImage .setVisibility (View .GONE );
146
220
mErrorFrame .setVisibility (View .GONE );
147
221
mSuccessFrame .setVisibility (View .GONE );
148
222
mWarningFrame .setVisibility (View .GONE );
149
223
mProgressFrame .setVisibility (View .GONE );
224
+ mEditTextFrame .setVisibility (View .GONE );
150
225
mConfirmButton .setVisibility (View .VISIBLE );
151
226
152
227
mConfirmButton .setBackgroundResource (R .drawable .button_background );
@@ -157,7 +232,7 @@ private void restore () {
157
232
//mSuccessRightMask.clearAnimation();
158
233
}
159
234
160
- private void playAnimation () {
235
+ private void playAnimation () {
161
236
if (mAlertType == ERROR_TYPE ) {
162
237
mErrorFrame .startAnimation (mImageAnim );
163
238
mErrorX .startAnimation (mErrorXInAnim );
@@ -197,6 +272,11 @@ private void changeAlertType(int alertType, boolean fromCreate) {
197
272
mConfirmButton .setVisibility (View .GONE );
198
273
setConfirmButtonColor (mColor );
199
274
break ;
275
+ case INPUT_TYPE :
276
+ mEditText .requestFocus ();
277
+ mEditTextFrame .setVisibility (View .VISIBLE );
278
+ setConfirmButtonColor (mColor );
279
+ break ;
200
280
}
201
281
if (!fromCreate ) {
202
282
playAnimation ();
@@ -208,6 +288,7 @@ public void changeAlertType(int alertType) {
208
288
changeAlertType (alertType , false );
209
289
}
210
290
291
+ <<<<<<< HEAD
211
292
public KAlertDialog setTitleText (String text ) {
212
293
213
294
mTitleText = text ;
@@ -219,14 +300,16 @@ public KAlertDialog setTitleText (String text) {
219
300
return this ;
220
301
}
221
302
303
+ =======
304
+ >>>>>>> 357968d 342f 7 ba2ebb7cde76a39e44438efdff44
222
305
private void showTitleText () {
223
306
mShowTitleText = true ;
224
307
if (mTitleTextView != null ) {
225
308
mTitleTextView .setVisibility (View .VISIBLE );
226
309
}
227
310
}
228
311
229
- public KAlertDialog setCustomImage (int resourceId ) {
312
+ public KAlertDialog setCustomImage (int resourceId ) {
230
313
return setCustomImage (getContext ().getResources ().getDrawable (resourceId ));
231
314
}
232
315
@@ -239,6 +322,7 @@ private KAlertDialog setCustomImage(Drawable drawable) {
239
322
return this ;
240
323
}
241
324
325
+ <<<<<<< HEAD
242
326
public KAlertDialog setContentText (String text ) {
243
327
/*
244
328
mContentText = text;
@@ -262,6 +346,9 @@ public KAlertDialog setContentText (String text) {
262
346
}
263
347
264
348
public KAlertDialog showCancelButton (boolean isShow ) {
349
+ =======
350
+ public KAlertDialog showCancelButton (boolean isShow ) {
351
+ >>>>>>> 357968d 342f 7 ba2ebb7cde76a39e44438efdff44
265
352
mShowCancel = isShow ;
266
353
if (mCancelButton != null ) {
267
354
mCancelButton .setVisibility (mShowCancel ? View .VISIBLE : View .GONE );
@@ -276,29 +363,12 @@ private void showContentText() {
276
363
}
277
364
}
278
365
279
- public KAlertDialog setCancelText (String text ) {
280
- mCancelText = text ;
281
- if (mCancelButton != null && mCancelText != null ) {
282
- showCancelButton (true );
283
- mCancelButton .setText (mCancelText );
284
- }
285
- return this ;
286
- }
287
-
288
- public KAlertDialog setConfirmText (String text ) {
289
- mConfirmText = text ;
290
- if (mConfirmButton != null && mConfirmText != null ) {
291
- mConfirmButton .setText (mConfirmText );
292
- }
293
- return this ;
294
- }
295
-
296
- public KAlertDialog setCancelClickListener (KAlertClickListener listener ) {
366
+ public KAlertDialog setCancelClickListener (KAlertClickListener listener ) {
297
367
mCancelClickListener = listener ;
298
368
return this ;
299
369
}
300
370
301
- public KAlertDialog setConfirmClickListener (KAlertClickListener listener ) {
371
+ public KAlertDialog setConfirmClickListener (KAlertClickListener listener ) {
302
372
mConfirmClickListener = listener ;
303
373
return this ;
304
374
}
@@ -315,15 +385,15 @@ public void cancel() {
315
385
316
386
private KAlertDialog setConfirmButtonColor (Drawable background ) {
317
387
mColor = background ;
318
- if (mConfirmButton != null && mColor !=null ) {
388
+ if (mConfirmButton != null && mColor != null ) {
319
389
mConfirmButton .setBackground (mColor );
320
390
}
321
391
return this ;
322
392
}
323
393
324
394
private KAlertDialog setCancelButtonColor (Drawable background ) {
325
395
mCancelColor = background ;
326
- if (mCancelButton != null && mCancelColor !=null ) {
396
+ if (mCancelButton != null && mCancelColor != null ) {
327
397
mCancelButton .setBackground (mCancelColor );
328
398
}
329
399
return this ;
@@ -347,39 +417,82 @@ public int getAlertType() {
347
417
return mAlertType ;
348
418
}
349
419
350
- public String getTitleText () {
420
+ public String getTitleText () {
351
421
return mTitleText ;
352
422
}
353
423
354
- public boolean isShowTitleText () {
424
+ public KAlertDialog setTitleText (String text ) {
425
+ mTitleText = text ;
426
+ if (mTitleTextView != null && mTitleText != null ) {
427
+ showTitleText ();
428
+ mTitleTextView .setText (mTitleText );
429
+ }
430
+ return this ;
431
+ }
432
+
433
+ public boolean isShowTitleText () {
355
434
return mShowTitleText ;
356
435
}
357
436
358
- public String getContentText () {
437
+ public String getContentText () {
359
438
return mContentText ;
360
439
}
361
440
362
- public boolean isShowCancelButton () {
441
+ public KAlertDialog setContentText (String text ) {
442
+ mContentText = text ;
443
+ if (mContentTextView != null && mContentText != null ) {
444
+ showContentText ();
445
+ mContentTextView .setText (mContentText );
446
+ }
447
+ return this ;
448
+ }
449
+
450
+ public String getInputText () {
451
+ return mEditText .getText ().toString ();
452
+ }
453
+
454
+ public void setInputText (String text ) {
455
+ mEditText .setText (text );
456
+ }
457
+
458
+ public boolean isShowCancelButton () {
363
459
return mShowCancel ;
364
460
}
365
461
366
- public boolean isShowContentText () {
462
+ public boolean isShowContentText () {
367
463
return mShowContent ;
368
464
}
369
465
370
- public String getCancelText () {
466
+ public String getCancelText () {
371
467
return mCancelText ;
372
468
}
373
469
374
- public String getConfirmText () {
470
+ public KAlertDialog setCancelText (String text ) {
471
+ mCancelText = text ;
472
+ if (mCancelButton != null && mCancelText != null ) {
473
+ showCancelButton (true );
474
+ mCancelButton .setText (mCancelText );
475
+ }
476
+ return this ;
477
+ }
478
+
479
+ public String getConfirmText () {
375
480
return mConfirmText ;
376
481
}
377
482
378
- public KAlertDialog confirmButtonColor (int color ) {
483
+ public KAlertDialog setConfirmText (String text ) {
484
+ mConfirmText = text ;
485
+ if (mConfirmButton != null && mConfirmText != null ) {
486
+ mConfirmButton .setText (mConfirmText );
487
+ }
488
+ return this ;
489
+ }
490
+
491
+ public KAlertDialog confirmButtonColor (int color ) {
379
492
return setConfirmButtonColor (getContext ().getResources ().getDrawable (color ));
380
493
}
381
494
382
- public KAlertDialog cancelButtonColor (int color ) {
495
+ public KAlertDialog cancelButtonColor (int color ) {
383
496
return setCancelButtonColor (getContext ().getResources ().getDrawable (color ));
384
497
}
385
498
@@ -419,7 +532,11 @@ public void onClick(View v) {
419
532
}
420
533
}
421
534
422
- public ProgressHelper getProgressHelper () {
535
+ public ProgressHelper getProgressHelper () {
423
536
return mProgressHelper ;
424
537
}
538
+
539
+ public interface KAlertClickListener {
540
+ void onClick (KAlertDialog kAlertDialog );
541
+ }
425
542
}
0 commit comments