Skip to content

Commit 59d48b5

Browse files
Initial Commit
2 parents d863b94 + 357968d commit 59d48b5

File tree

5 files changed

+208
-38
lines changed

5 files changed

+208
-38
lines changed

library/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ android {
2121
lintOptions {
2222
abortOnError false
2323
}
24+
compileOptions {
25+
sourceCompatibility = 1.8
26+
targetCompatibility = 1.8
27+
}
2428
}
2529

2630
dependencies {

library/src/main/java/com/developer/kalert/KAlertDialog.java

Lines changed: 154 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.developer.kalert;
22

3-
import android.app.AlertDialog;
3+
import android.app.Dialog;
44
import android.content.Context;
55
import android.graphics.drawable.Drawable;
66
import android.os.Bundle;
@@ -12,14 +12,20 @@
1212
import android.view.animation.AnimationSet;
1313
import android.view.animation.Transformation;
1414
import android.widget.Button;
15+
import android.widget.EditText;
1516
import android.widget.FrameLayout;
1617
import android.widget.ImageView;
1718
import android.widget.TextView;
19+
<<<<<<< HEAD
20+
=======
21+
22+
>>>>>>> 357968d342f7ba2ebb7cde76a39e44438efdff44
1823
import java.util.Objects;
1924

2025
/**
2126
* @author akshay sunil masram
2227
*/
28+
<<<<<<< HEAD
2329
public class KAlertDialog extends AlertDialog implements View.OnClickListener {
2430

2531
private final AnimationSet mModalInAnim,mModalOutAnim,mErrorXInAnim;//,mSuccessLayoutAnimSet;
@@ -48,22 +54,49 @@ public class KAlertDialog extends AlertDialog implements View.OnClickListener {
4854

4955
private int mAlertType;
5056
public static final int NORMAL_TYPE = 0;
57+
=======
58+
public class KAlertDialog extends Dialog implements View.OnClickListener {
59+
60+
>>>>>>> 357968d342f7ba2ebb7cde76a39e44438efdff44
5161
public static final int ERROR_TYPE = 1;
5262
public static final int SUCCESS_TYPE = 2;
5363
public static final int WARNING_TYPE = 3;
5464
public static final int CUSTOM_IMAGE_TYPE = 4;
5565
public static final int PROGRESS_TYPE = 5;
66+
<<<<<<< HEAD
5667

5768
public static boolean DARK_STYLE = false;
5869

5970
public interface KAlertClickListener {
6071
void onClick(KAlertDialog kAlertDialog);
6172
}
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+
>>>>>>> 357968d342f7ba2ebb7cde76a39e44438efdff44
6294

6395
public KAlertDialog(Context context) {
6496
this(context, NORMAL_TYPE);
6597
}
6698

99+
<<<<<<< HEAD
67100
protected void onCreate(Bundle savedInstanceState) {
68101
super.onCreate(savedInstanceState);
69102
setContentView(R.layout.alert_dialog);
@@ -98,6 +131,8 @@ protected void onCreate(Bundle savedInstanceState) {
98131
changeAlertType(mAlertType, true);
99132
}
100133

134+
=======
135+
>>>>>>> 357968d342f7ba2ebb7cde76a39e44438efdff44
101136
public KAlertDialog(Context context, int alertType) {
102137
super(context, DARK_STYLE ? R.style.alert_dialog_dark : R.style.alert_dialog_light);
103138

@@ -113,7 +148,8 @@ public KAlertDialog(Context context, int alertType) {
113148
mModalOutAnim = (AnimationSet) AnimationLoader.loadAnimation(getContext(), R.anim.modal_out);
114149
Objects.requireNonNull(mModalOutAnim).setAnimationListener(new Animation.AnimationListener() {
115150
@Override
116-
public void onAnimationStart(Animation animation) { }
151+
public void onAnimationStart(Animation animation) {
152+
}
117153

118154
@Override
119155
public void onAnimationEnd(Animation animation) {
@@ -128,7 +164,8 @@ public void onAnimationEnd(Animation animation) {
128164
}
129165

130166
@Override
131-
public void onAnimationRepeat(Animation animation) { }
167+
public void onAnimationRepeat(Animation animation) {
168+
}
132169
});
133170
mOverlayOutAnim = new Animation() {
134171
@Override
@@ -139,14 +176,52 @@ protected void applyTransformation(float interpolatedTime, Transformation t) {
139176
}
140177
};
141178
mOverlayOutAnim.setDuration(120);
179+
180+
Objects.requireNonNull(this.getWindow()).setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
142181
}
143182

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() {
145219
mCustomImage.setVisibility(View.GONE);
146220
mErrorFrame.setVisibility(View.GONE);
147221
mSuccessFrame.setVisibility(View.GONE);
148222
mWarningFrame.setVisibility(View.GONE);
149223
mProgressFrame.setVisibility(View.GONE);
224+
mEditTextFrame.setVisibility(View.GONE);
150225
mConfirmButton.setVisibility(View.VISIBLE);
151226

152227
mConfirmButton.setBackgroundResource(R.drawable.button_background);
@@ -157,7 +232,7 @@ private void restore () {
157232
//mSuccessRightMask.clearAnimation();
158233
}
159234

160-
private void playAnimation () {
235+
private void playAnimation() {
161236
if (mAlertType == ERROR_TYPE) {
162237
mErrorFrame.startAnimation(mImageAnim);
163238
mErrorX.startAnimation(mErrorXInAnim);
@@ -197,6 +272,11 @@ private void changeAlertType(int alertType, boolean fromCreate) {
197272
mConfirmButton.setVisibility(View.GONE);
198273
setConfirmButtonColor(mColor);
199274
break;
275+
case INPUT_TYPE:
276+
mEditText.requestFocus();
277+
mEditTextFrame.setVisibility(View.VISIBLE);
278+
setConfirmButtonColor(mColor);
279+
break;
200280
}
201281
if (!fromCreate) {
202282
playAnimation();
@@ -208,6 +288,7 @@ public void changeAlertType(int alertType) {
208288
changeAlertType(alertType, false);
209289
}
210290

291+
<<<<<<< HEAD
211292
public KAlertDialog setTitleText (String text) {
212293

213294
mTitleText = text;
@@ -219,14 +300,16 @@ public KAlertDialog setTitleText (String text) {
219300
return this;
220301
}
221302

303+
=======
304+
>>>>>>> 357968d342f7ba2ebb7cde76a39e44438efdff44
222305
private void showTitleText() {
223306
mShowTitleText = true;
224307
if (mTitleTextView != null) {
225308
mTitleTextView.setVisibility(View.VISIBLE);
226309
}
227310
}
228311

229-
public KAlertDialog setCustomImage (int resourceId) {
312+
public KAlertDialog setCustomImage(int resourceId) {
230313
return setCustomImage(getContext().getResources().getDrawable(resourceId));
231314
}
232315

@@ -239,6 +322,7 @@ private KAlertDialog setCustomImage(Drawable drawable) {
239322
return this;
240323
}
241324

325+
<<<<<<< HEAD
242326
public KAlertDialog setContentText (String text) {
243327
/*
244328
mContentText = text;
@@ -262,6 +346,9 @@ public KAlertDialog setContentText (String text) {
262346
}
263347

264348
public KAlertDialog showCancelButton (boolean isShow) {
349+
=======
350+
public KAlertDialog showCancelButton(boolean isShow) {
351+
>>>>>>> 357968d342f7ba2ebb7cde76a39e44438efdff44
265352
mShowCancel = isShow;
266353
if (mCancelButton != null) {
267354
mCancelButton.setVisibility(mShowCancel ? View.VISIBLE : View.GONE);
@@ -276,29 +363,12 @@ private void showContentText() {
276363
}
277364
}
278365

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) {
297367
mCancelClickListener = listener;
298368
return this;
299369
}
300370

301-
public KAlertDialog setConfirmClickListener (KAlertClickListener listener) {
371+
public KAlertDialog setConfirmClickListener(KAlertClickListener listener) {
302372
mConfirmClickListener = listener;
303373
return this;
304374
}
@@ -315,15 +385,15 @@ public void cancel() {
315385

316386
private KAlertDialog setConfirmButtonColor(Drawable background) {
317387
mColor = background;
318-
if (mConfirmButton != null && mColor !=null) {
388+
if (mConfirmButton != null && mColor != null) {
319389
mConfirmButton.setBackground(mColor);
320390
}
321391
return this;
322392
}
323393

324394
private KAlertDialog setCancelButtonColor(Drawable background) {
325395
mCancelColor = background;
326-
if (mCancelButton != null && mCancelColor !=null) {
396+
if (mCancelButton != null && mCancelColor != null) {
327397
mCancelButton.setBackground(mCancelColor);
328398
}
329399
return this;
@@ -347,39 +417,82 @@ public int getAlertType() {
347417
return mAlertType;
348418
}
349419

350-
public String getTitleText () {
420+
public String getTitleText() {
351421
return mTitleText;
352422
}
353423

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() {
355434
return mShowTitleText;
356435
}
357436

358-
public String getContentText () {
437+
public String getContentText() {
359438
return mContentText;
360439
}
361440

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() {
363459
return mShowCancel;
364460
}
365461

366-
public boolean isShowContentText () {
462+
public boolean isShowContentText() {
367463
return mShowContent;
368464
}
369465

370-
public String getCancelText () {
466+
public String getCancelText() {
371467
return mCancelText;
372468
}
373469

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() {
375480
return mConfirmText;
376481
}
377482

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) {
379492
return setConfirmButtonColor(getContext().getResources().getDrawable(color));
380493
}
381494

382-
public KAlertDialog cancelButtonColor (int color) {
495+
public KAlertDialog cancelButtonColor(int color) {
383496
return setCancelButtonColor(getContext().getResources().getDrawable(color));
384497
}
385498

@@ -419,7 +532,11 @@ public void onClick(View v) {
419532
}
420533
}
421534

422-
public ProgressHelper getProgressHelper () {
535+
public ProgressHelper getProgressHelper() {
423536
return mProgressHelper;
424537
}
538+
539+
public interface KAlertClickListener {
540+
void onClick(KAlertDialog kAlertDialog);
541+
}
425542
}

0 commit comments

Comments
 (0)