Skip to content

Commit 197f2a1

Browse files
committed
1. Added SweetAlertDialog.
1 parent f31169b commit 197f2a1

29 files changed

+1696
-1
lines changed
0 Bytes
Binary file not shown.

app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,7 @@ dependencies {
5757

5858
// More Info: https://github.com/Yalantis/uCrop
5959
implementation 'com.github.yalantis:ucrop:2.2.2'
60+
61+
// Material Progress bar
62+
implementation 'com.pnikosis:materialish-progress:1.7'
6063
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.amit.dialog.sweetAlert;
2+
3+
import android.content.Context;
4+
import android.content.res.Resources;
5+
import android.content.res.XmlResourceParser;
6+
import android.util.AttributeSet;
7+
import android.util.Xml;
8+
import android.view.animation.AlphaAnimation;
9+
import android.view.animation.Animation;
10+
import android.view.animation.AnimationSet;
11+
import android.view.animation.RotateAnimation;
12+
import android.view.animation.ScaleAnimation;
13+
import android.view.animation.TranslateAnimation;
14+
15+
import org.xmlpull.v1.XmlPullParser;
16+
import org.xmlpull.v1.XmlPullParserException;
17+
18+
import java.io.IOException;
19+
20+
/**
21+
* Created by AMIT JANGID on 27/02/2019.
22+
**/
23+
public class OptAnimationLoader
24+
{
25+
public static Animation loadAnimation(Context context, int id) throws Resources.NotFoundException
26+
{
27+
XmlResourceParser parser = null;
28+
29+
try
30+
{
31+
parser = context.getResources().getAnimation(id);
32+
return createAnimationFromXml(context, parser);
33+
}
34+
catch (XmlPullParserException ex)
35+
{
36+
Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" +
37+
Integer.toHexString(id));
38+
rnf.initCause(ex);
39+
throw rnf;
40+
}
41+
catch (IOException ex)
42+
{
43+
Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" +
44+
Integer.toHexString(id));
45+
rnf.initCause(ex);
46+
throw rnf;
47+
}
48+
finally
49+
{
50+
if (parser != null) parser.close();
51+
}
52+
}
53+
54+
private static Animation createAnimationFromXml(Context c, XmlPullParser parser) throws XmlPullParserException, IOException
55+
{
56+
57+
return createAnimationFromXml(c, parser, null, Xml.asAttributeSet(parser));
58+
}
59+
60+
private static Animation createAnimationFromXml(Context c,
61+
XmlPullParser parser,
62+
AnimationSet parent,
63+
AttributeSet attrs)
64+
throws XmlPullParserException, IOException
65+
{
66+
Animation anim = null;
67+
68+
// Make sure we are on a start tag.
69+
int type;
70+
int depth = parser.getDepth();
71+
72+
while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
73+
&& type != XmlPullParser.END_DOCUMENT)
74+
{
75+
if (type != XmlPullParser.START_TAG)
76+
{
77+
continue;
78+
}
79+
80+
String name = parser.getName();
81+
82+
if (name.equals("set"))
83+
{
84+
anim = new AnimationSet(c, attrs);
85+
createAnimationFromXml(c, parser, (AnimationSet) anim, attrs);
86+
}
87+
else if (name.equals("alpha"))
88+
{
89+
anim = new AlphaAnimation(c, attrs);
90+
}
91+
else if (name.equals("scale"))
92+
{
93+
anim = new ScaleAnimation(c, attrs);
94+
}
95+
else if (name.equals("rotate"))
96+
{
97+
anim = new RotateAnimation(c, attrs);
98+
}
99+
else if (name.equals("translate"))
100+
{
101+
anim = new TranslateAnimation(c, attrs);
102+
}
103+
else
104+
{
105+
try
106+
{
107+
anim = (Animation) Class.forName(name).getConstructor(Context.class, AttributeSet.class).newInstance(c, attrs);
108+
}
109+
catch (Exception te)
110+
{
111+
throw new RuntimeException("Unknown animation name: " + parser.getName() + " error:" + te.getMessage());
112+
}
113+
}
114+
115+
if (parent != null)
116+
{
117+
parent.addAnimation(anim);
118+
}
119+
}
120+
121+
return anim;
122+
}
123+
}
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
package com.amit.dialog.sweetAlert;
2+
3+
import android.content.Context;
4+
5+
import com.amit.R;
6+
import com.pnikosis.materialishprogress.ProgressWheel;
7+
8+
/**
9+
* Created by AMIT JANGID on 27/02/2019.
10+
**/
11+
public class ProgressHelper
12+
{
13+
private ProgressWheel mProgressWheel;
14+
15+
private int mBarWidth;
16+
private int mBarColor;
17+
private int mRimWidth;
18+
private int mRimColor;
19+
20+
private boolean mToSpin;
21+
private float mSpinSpeed;
22+
23+
private int mCircleRadius;
24+
private float mProgressVal;
25+
26+
private boolean mIsInstantProgress;
27+
28+
public ProgressHelper(Context context)
29+
{
30+
mToSpin = true;
31+
mSpinSpeed = 0.75f;
32+
33+
mBarColor = context.getResources().getColor(R.color.success_stroke_color);
34+
mBarWidth = context.getResources().getDimensionPixelSize(R.dimen.common_circle_width) + 1;
35+
36+
mRimWidth = 0;
37+
mRimColor = 0x00000000;
38+
39+
mProgressVal = -1;
40+
mIsInstantProgress = false;
41+
42+
mCircleRadius = context.getResources().getDimensionPixelOffset(R.dimen.progress_circle_radius);
43+
}
44+
45+
public ProgressWheel getProgressWheel()
46+
{
47+
return mProgressWheel;
48+
}
49+
50+
public void setProgressWheel(ProgressWheel progressWheel)
51+
{
52+
this.mProgressWheel = progressWheel;
53+
updatePropsIfNeed();
54+
}
55+
56+
private void updatePropsIfNeed()
57+
{
58+
if (mProgressWheel != null)
59+
{
60+
if (!mToSpin && mProgressWheel.isSpinning())
61+
{
62+
mProgressWheel.stopSpinning();
63+
}
64+
else if (mToSpin && !mProgressWheel.isSpinning())
65+
{
66+
mProgressWheel.spin();
67+
}
68+
69+
if (mSpinSpeed != mProgressWheel.getSpinSpeed())
70+
{
71+
mProgressWheel.setSpinSpeed(mSpinSpeed);
72+
}
73+
74+
if (mBarWidth != mProgressWheel.getBarWidth())
75+
{
76+
mProgressWheel.setBarWidth(mBarWidth);
77+
}
78+
79+
if (mBarColor != mProgressWheel.getBarColor())
80+
{
81+
mProgressWheel.setBarColor(mBarColor);
82+
}
83+
84+
if (mRimWidth != mProgressWheel.getRimWidth())
85+
{
86+
mProgressWheel.setRimWidth(mRimWidth);
87+
}
88+
89+
if (mRimColor != mProgressWheel.getRimColor())
90+
{
91+
mProgressWheel.setRimColor(mRimColor);
92+
}
93+
94+
if (mProgressVal != mProgressWheel.getProgress())
95+
{
96+
if (mIsInstantProgress)
97+
{
98+
mProgressWheel.setInstantProgress(mProgressVal);
99+
}
100+
else
101+
{
102+
mProgressWheel.setProgress(mProgressVal);
103+
}
104+
}
105+
106+
if (mCircleRadius != mProgressWheel.getCircleRadius())
107+
{
108+
mProgressWheel.setCircleRadius(mCircleRadius);
109+
}
110+
}
111+
}
112+
113+
public void resetCount()
114+
{
115+
if (mProgressWheel != null)
116+
{
117+
mProgressWheel.resetCount();
118+
}
119+
}
120+
121+
public boolean isSpinning()
122+
{
123+
return mToSpin;
124+
}
125+
126+
public void spin()
127+
{
128+
mToSpin = true;
129+
updatePropsIfNeed();
130+
}
131+
132+
public void stopSpinning()
133+
{
134+
mToSpin = false;
135+
updatePropsIfNeed();
136+
}
137+
138+
public float getProgress()
139+
{
140+
return mProgressVal;
141+
}
142+
143+
public void setProgress(float progress)
144+
{
145+
mIsInstantProgress = false;
146+
mProgressVal = progress;
147+
148+
updatePropsIfNeed();
149+
}
150+
151+
public void setInstantProgress(float progress)
152+
{
153+
mProgressVal = progress;
154+
mIsInstantProgress = true;
155+
156+
updatePropsIfNeed();
157+
}
158+
159+
public int getCircleRadius()
160+
{
161+
return mCircleRadius;
162+
}
163+
164+
/**
165+
* @param circleRadius units using pixel
166+
**/
167+
public void setCircleRadius(int circleRadius)
168+
{
169+
mCircleRadius = circleRadius;
170+
updatePropsIfNeed();
171+
}
172+
173+
public int getBarWidth()
174+
{
175+
return mBarWidth;
176+
}
177+
178+
public void setBarWidth(int barWidth)
179+
{
180+
mBarWidth = barWidth;
181+
updatePropsIfNeed();
182+
}
183+
184+
public int getBarColor()
185+
{
186+
return mBarColor;
187+
}
188+
189+
public void setBarColor(int barColor)
190+
{
191+
mBarColor = barColor;
192+
updatePropsIfNeed();
193+
}
194+
195+
public int getRimWidth()
196+
{
197+
return mRimWidth;
198+
}
199+
200+
public void setRimWidth(int rimWidth)
201+
{
202+
mRimWidth = rimWidth;
203+
updatePropsIfNeed();
204+
}
205+
206+
public int getRimColor()
207+
{
208+
return mRimColor;
209+
}
210+
211+
public void setRimColor(int rimColor)
212+
{
213+
mRimColor = rimColor;
214+
updatePropsIfNeed();
215+
}
216+
217+
public float getSpinSpeed()
218+
{
219+
return mSpinSpeed;
220+
}
221+
222+
public void setSpinSpeed(float spinSpeed)
223+
{
224+
mSpinSpeed = spinSpeed;
225+
updatePropsIfNeed();
226+
}
227+
}

0 commit comments

Comments
 (0)