33import android .app .Dialog ;
44import android .content .Context ;
55import android .graphics .drawable .Drawable ;
6+ import android .graphics .drawable .GradientDrawable ;
67import android .support .annotation .NonNull ;
8+ import android .support .v4 .content .ContextCompat ;
79import android .view .Gravity ;
810import android .view .View ;
911import android .view .WindowManager ;
1921 * Created by ENES on 7.12.2018.
2022 */
2123public class FastDialogBuilder {
24+ private final static int INFO_DIALOG = 0 ;
25+ private final static int ERROR_DIALOG = 1 ;
26+ private final static int WARNING_DIALOG = 2 ;
27+ private final static int DIALOG = 3 ;
28+ private final static int PROGRESS_DIALOG = 4 ;
2229 private Dialog dialog ;
30+ private int type = -1 ;
2331 private Context context ;
2432 private TextView tvTitle ;
2533 private TextView tvProgress ;
@@ -32,99 +40,83 @@ public class FastDialogBuilder {
3240 private PossitiveClick possitiveClick ;
3341 private NegativeClick negativeClick ;
3442
35- public FastDialogBuilder (@ NonNull Context context ){
43+ public FastDialogBuilder (@ NonNull Context context , int type ){
3644 this .context =context ;
45+ this .type =type ;
3746 dialog =new Dialog (context );
38- dialog .setContentView (R .layout .warning_dialog );
39- WindowManager .LayoutParams lWindowParams = new WindowManager .LayoutParams ();
40- lWindowParams .copyFrom (getDialog ().getWindow ().getAttributes ());
41- lWindowParams .width = WindowManager .LayoutParams .MATCH_PARENT ;
42- lWindowParams .height = WindowManager .LayoutParams .WRAP_CONTENT ;
43- dialog .getWindow ().setAttributes (lWindowParams );
44- tvTitle = dialog .findViewById (R .id .warning_dialog_title );
45- lawWarning = dialog .findViewById (R .id .warning_dialog_animation );
46- tvWarning = dialog .findViewById (R .id .warning_dialog_text );
47- etWarning = dialog .findViewById (R .id .warning_dialog_et );
48- etWarningDecimal = dialog .findViewById (R .id .warning_dialog_et_decimal );
49- btCancel = dialog .findViewById (R .id .warning_dialog_cancel_bt );
50- btOk = dialog .findViewById (R .id .warning_dialog_ok_bt );
51- btCancel .setOnClickListener (new View .OnClickListener () {
52- @ Override
53- public void onClick (View v ) {
54- if (negativeClick != null )
55- negativeClick .onClick (v );
56- dialog .dismiss ();
57- }
58- });
59- btOk .setOnClickListener (new View .OnClickListener () {
60- @ Override
61- public void onClick (View v ) {
62- if (possitiveClick != null )
63- possitiveClick .onClick (v );
64- }
65- });
66- Drawable etDrawable = new DrawableBuilder ()
67- .rectangle ()
68- .hairlineBordered ()
69- .bottomLeftRadius (20 )
70- .topLeftRadius (20 )
71- .topRightRadius (20 )
72- .bottomRightRadius (20 )
73- .strokeColor (context .getColor (R .color .colorPrimaryDark ))
74- .build ();
75- etWarningDecimal .setBackground (etDrawable );
76- etWarning .setBackground (etDrawable );
77- Drawable btDrawable = new DrawableBuilder ()
78- .rectangle ()
79- .solidColor (context .getColor (R .color .colorPrimaryDark ))
80- .bottomLeftRadius (20 )
81- .topLeftRadius (20 )
82- .topRightRadius (20 )
83- .bottomRightRadius (20 )
84- .build ();
85- btOk .setBackground (btDrawable );
86- btCancel .setBackground (btDrawable );
47+ if (type == PROGRESS_DIALOG ){
48+ dialog .setContentView (R .layout .progress_dialog );
49+ WindowManager .LayoutParams lWindowParams = new WindowManager .LayoutParams ();
50+ lWindowParams .copyFrom (getDialog ().getWindow ().getAttributes ());
51+ lWindowParams .width = WindowManager .LayoutParams .MATCH_PARENT ;
52+ lWindowParams .height = WindowManager .LayoutParams .WRAP_CONTENT ;
53+ dialog .getWindow ().setAttributes (lWindowParams );
54+ tvProgress = dialog .findViewById (R .id .wait_text );
55+ }else {
56+ dialog .setContentView (R .layout .warning_dialog );
57+ WindowManager .LayoutParams lWindowParams = new WindowManager .LayoutParams ();
58+ lWindowParams .copyFrom (getDialog ().getWindow ().getAttributes ());
59+ lWindowParams .width = WindowManager .LayoutParams .MATCH_PARENT ;
60+ lWindowParams .height = WindowManager .LayoutParams .WRAP_CONTENT ;
61+ dialog .getWindow ().setAttributes (lWindowParams );
62+ tvTitle = dialog .findViewById (R .id .warning_dialog_title );
63+ lawWarning = dialog .findViewById (R .id .warning_dialog_animation );
64+ tvWarning = dialog .findViewById (R .id .warning_dialog_text );
65+ etWarning = dialog .findViewById (R .id .warning_dialog_et );
66+ etWarningDecimal = dialog .findViewById (R .id .warning_dialog_et_decimal );
67+ btCancel = dialog .findViewById (R .id .warning_dialog_cancel_bt );
68+ btOk = dialog .findViewById (R .id .warning_dialog_ok_bt );
69+ btCancel .setOnClickListener (new View .OnClickListener () {
70+ @ Override
71+ public void onClick (View v ) {
72+ if (negativeClick != null )
73+ negativeClick .onClick (v );
74+ dialog .dismiss ();
75+ }
76+ });
77+ btOk .setOnClickListener (new View .OnClickListener () {
78+ @ Override
79+ public void onClick (View v ) {
80+ if (possitiveClick != null )
81+ possitiveClick .onClick (v );
82+ }
83+ });
84+ GradientDrawable shape = new GradientDrawable ();
85+ shape .setShape (GradientDrawable .RECTANGLE );
86+ //shape.setCornerRadii(new float[] { 20,20,20,20,20,20,20,20 });
87+ shape .setCornerRadius (20 );
88+ shape .setColor (ContextCompat .getColor (context ,R .color .primary ));
89+ shape .setStroke (3 , ContextCompat .getColor (context ,R .color .primary ));
90+ btOk .setBackground (shape );
91+ btCancel .setBackground (shape );
8792
88- tvTitle .setVisibility (View .GONE );
89- lawWarning .setVisibility (View .GONE );
90- tvWarning .setVisibility (View .GONE );
91- etWarning .setVisibility (View .GONE );
92- etWarningDecimal .setVisibility (View .GONE );
93- btCancel .setVisibility (View .GONE );
94- btOk .setVisibility (View .GONE );
93+ tvTitle .setVisibility (View .VISIBLE );
94+ lawWarning .setVisibility (View .VISIBLE );
95+ tvWarning .setVisibility (View .GONE );
96+ etWarning .setVisibility (View .GONE );
97+ etWarningDecimal .setVisibility (View .GONE );
98+ btCancel .setVisibility (View .GONE );
99+ btOk .setVisibility (View .GONE );
100+ }
95101 }
96102 public FastDialogBuilder changeColor (int colorItem ,int colorItemText ,int colorText ){
97103 tvTitle .setBackgroundColor (colorItem );
98104 tvTitle .setTextColor (colorItemText );
99105 tvWarning .setTextColor (colorText );
100- Drawable btDrawable = new DrawableBuilder ()
101- .rectangle ()
102- .bottomLeftRadius (20 )
103- .topLeftRadius (20 )
104- .topRightRadius (20 )
105- .bottomRightRadius (20 )
106- .solidColor (colorItem )
107- .build ();
108- Drawable etDrawable = new DrawableBuilder ()
109- .rectangle ()
110- .bottomLeftRadius (20 )
111- .topLeftRadius (20 )
112- .topRightRadius (20 )
113- .bottomRightRadius (20 )
114- .hairlineBordered ()
115- .strokeColor (colorItem )
116- .build ();
117- etWarning .setBackground (etDrawable );
118- etWarningDecimal .setBackground (etDrawable );
119- btCancel .setBackground (btDrawable );
120- btOk .setBackground (btDrawable );
106+ GradientDrawable shape = new GradientDrawable ();
107+ shape .setShape (GradientDrawable .RECTANGLE );
108+ //shape.setCornerRadii(new float[] { 20,20,20,20,20,20,20,20 });
109+ shape .setCornerRadius (20 );
110+ shape .setColor (colorItem );
111+ shape .setStroke (3 , colorItem );
112+
113+ btCancel .setBackground (shape );
114+ btOk .setBackground (shape );
121115 btCancel .setTextColor (colorItemText );
122116 btOk .setTextColor (colorItemText );
123117 return this ;
124118 }
125- public FastDialogBuilder progressDialog (String progressString ){
126- dialog .setContentView (R .layout .progress_dialog );
127- tvProgress = dialog .findViewById (R .id .wait_text );
119+ public FastDialogBuilder progressText (String progressString ){
128120 tvProgress .setText (progressString );
129121 return this ;
130122 }
@@ -158,13 +150,16 @@ public FastDialogBuilder setPosition(Positions position){
158150 }
159151 return this ;
160152 }
161- public FastDialogBuilder setTitle (String title ){
162- tvTitle .setVisibility (View .VISIBLE );
153+ public FastDialogBuilder setTitleText (String title ){
163154 tvTitle .setText (title );
164155 return this ;
165156 }
166- public FastDialogBuilder withIcon (){
167- lawWarning .setVisibility (View .VISIBLE );
157+ public FastDialogBuilder hideTitle (){
158+ tvTitle .setVisibility (View .GONE );
159+ return this ;
160+ }
161+ public FastDialogBuilder hideIcon (){
162+ lawWarning .setVisibility (View .GONE );
168163 return this ;
169164 }
170165 public FastDialogBuilder setText (String text ){
@@ -188,14 +183,9 @@ public FastDialogBuilder possitiveText(String possitive){
188183 btOk .setText (possitive );
189184 return this ;
190185 }
191- public FastDialogBuilder decimalEditText (boolean bool ){
192- if (bool ){
193- etWarning .setVisibility (View .GONE );
194- etWarningDecimal .setVisibility (View .VISIBLE );
195- }else {
196- etWarning .setVisibility (View .VISIBLE );
197- etWarningDecimal .setVisibility (View .GONE );
198- }
186+ public FastDialogBuilder decimalEditText (){
187+ etWarning .setVisibility (View .GONE );
188+ etWarningDecimal .setVisibility (View .VISIBLE );
199189 return this ;
200190 }
201191 public FastDialogBuilder possitiveClickListener (PossitiveClick click ){
0 commit comments