Skip to content

Commit 1b0f053

Browse files
committed
New Code Syntax
1 parent 9fa4049 commit 1b0f053

File tree

16 files changed

+445
-527
lines changed

16 files changed

+445
-527
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
/captures
1313
.externalNativeBuild
1414
.cxx
15-
local.properties
15+
local.properties
16+
.androidide

SToast/build.gradle

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,14 @@ android {
99
defaultConfig {
1010
minSdk 21
1111
targetSdk 33
12-
13-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14-
consumerProguardFiles "consumer-rules.pro"
15-
}
16-
17-
buildTypes {
18-
release {
19-
minifyEnabled false
20-
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21-
}
22-
debug {
23-
minifyEnabled false
24-
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25-
}
2612
}
13+
2714
compileOptions {
2815
sourceCompatibility JavaVersion.VERSION_17
2916
targetCompatibility JavaVersion.VERSION_17
3017
}
3118
}
3219

3320
dependencies {
34-
implementation 'androidx.appcompat:appcompat:1.5.1'
35-
implementation 'com.google.android.material:material:1.6.1'
36-
testImplementation 'junit:junit:4.13.2'
37-
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
38-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
21+
3922
}

SToast/src/androidTest/java/smith/lib/alerts/toast/ExampleInstrumentedTest.java

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package smith.lib.alerts.toast;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.content.res.Configuration;
6+
import android.graphics.Color;
7+
import android.graphics.drawable.GradientDrawable;
8+
import android.os.CountDownTimer;
9+
import android.view.View;
10+
import android.animation.ObjectAnimator;
11+
import android.widget.*;
12+
13+
public class AdaptiveSToast {
14+
15+
public static final int LENGTH_LONG = Toast.LENGTH_LONG;
16+
public static final int LENGTH_SHORT = Toast.LENGTH_SHORT;
17+
18+
private final String DARK = "#212121";
19+
private final String LIGHT = "#FFFFFF";
20+
private Context context;
21+
private String titleTxt, textTxt;
22+
private int color = 0xFFFF5252;
23+
private int icon = R.drawable.heart_img;
24+
private int duration = LENGTH_SHORT;
25+
26+
public static AdaptiveSToast with(Context ctx) {
27+
AdaptiveSToast ast = new AdaptiveSToast();
28+
ast.context = ctx;
29+
return ast;
30+
}
31+
32+
public AdaptiveSToast duration(int dur) {
33+
this.duration = dur;
34+
return this;
35+
}
36+
37+
public AdaptiveSToast title(String title) {
38+
this.titleTxt = title;
39+
return this;
40+
}
41+
42+
public AdaptiveSToast text(String text) {
43+
text = text;
44+
return this;
45+
}
46+
47+
public AdaptiveSToast icon(int icon, int iconColor) {
48+
icon = icon;
49+
color = iconColor;
50+
return this;
51+
}
52+
53+
public AdaptiveSToast icon(int icon, String iconColor) {
54+
icon = icon;
55+
color = Color.parseColor(iconColor);
56+
return this;
57+
}
58+
59+
public void show() {
60+
Toast toast = new Toast(context);
61+
62+
View inflate = ((Activity) context).getLayoutInflater().inflate(R.layout.stoast_adaptive, null);
63+
LinearLayout main = (LinearLayout) inflate.findViewById(R.id.main);
64+
LinearLayout view = (LinearLayout) inflate.findViewById(R.id.main2);
65+
ImageView img = (ImageView) inflate.findViewById(R.id.img);
66+
TextView title = (TextView) inflate.findViewById(R.id.title);
67+
TextView desc = (TextView) inflate.findViewById(R.id.desc);
68+
69+
ui(main, color, 30);
70+
if (nightModeON()) {
71+
ui(view, Color.parseColor(DARK), 30);
72+
title.setTextColor(Color.parseColor(LIGHT));
73+
desc.setTextColor(Color.parseColor(LIGHT));
74+
} else {
75+
ui(view, Color.parseColor(LIGHT), 30);
76+
title.setTextColor(color);
77+
desc.setTextColor(Color.parseColor(DARK));
78+
}
79+
80+
animate(img, 230);
81+
82+
main.setClipToOutline(true);
83+
title.setText(titleTxt);
84+
desc.setText(textTxt);
85+
img.setImageResource(icon);
86+
87+
toast.setDuration(duration);
88+
toast.setView(inflate);
89+
toast.show();
90+
}
91+
92+
private static void ui(View view, int str, int i) {
93+
GradientDrawable gradientDrawable = new GradientDrawable();
94+
gradientDrawable.setColor(str);
95+
gradientDrawable.setCornerRadius((float) i);
96+
view.setBackground(gradientDrawable);
97+
}
98+
99+
private static void animate(View v, int dur) {
100+
new CountDownTimer(dur, 1) {
101+
@Override public void onTick(long arg0) {}
102+
@Override public void onFinish() {
103+
ObjectAnimator animator = new ObjectAnimator();
104+
animator.setDuration(1000);
105+
animator.setFloatValues(0.0f, 1.0f);
106+
animator.setPropertyName("alpha");
107+
animator.setTarget(v);
108+
animator.start();
109+
}
110+
}.start();
111+
}
112+
113+
private boolean nightModeON() {
114+
int flags = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
115+
boolean isNightModeOn = flags == Configuration.UI_MODE_NIGHT_YES;
116+
if (isNightModeOn) return true;
117+
else return false;
118+
}
119+
120+
/*
121+
*
122+
*
123+
* THIS LIBRARY CREATED BY HUSSEIN SHAKIR (SMITH)
124+
*
125+
* TELEGRAM : @SMITHDEV
126+
* YOUTUBE : HUSSEIN SMITH
127+
*
128+
* YOU GUYS ARE NOT ALLOWED TO MODIFY THIS LIBRARY,
129+
* WITHOT ANY PERMISSION FROM ME PERSONALLY..
130+
* ALL RIGHTS RESERVED © HUSSEIN SHAKIR, 2022.
131+
*
132+
*
133+
*/
134+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package smith.lib.alerts.toast;
2+
3+
import android.animation.ObjectAnimator;
4+
import android.content.Context;
5+
import android.graphics.drawable.GradientDrawable;
6+
import android.os.CountDownTimer;
7+
import android.widget.Toast;
8+
import android.view.View;
9+
import android.app.Activity;
10+
import android.widget.*;
11+
import android.graphics.Color;
12+
13+
public class ModeSToast {
14+
15+
public static int LENGTH_LONG = Toast.LENGTH_LONG;
16+
public static int LENGTH_SHORT = Toast.LENGTH_SHORT;
17+
18+
public static final int MODE_OK = 0;
19+
public static final int MODE_WARN = 1;
20+
public static final int MODE_DONE = 2;
21+
public static final int MODE_ERROR = 3;
22+
public static final int MODE_INFO = 4;
23+
public static final int MODE_HEART = 5;
24+
public static final int MODE_CONFUSE = 6;
25+
26+
private int duration = LENGTH_SHORT;
27+
private int mode = MODE_INFO;
28+
private String titleTxt, textTxt;
29+
private Context context;
30+
31+
public static ModeSToast with(Context ctx) {
32+
ModeSToast mst = new ModeSToast();
33+
mst.context = ctx;
34+
return mst;
35+
}
36+
37+
public ModeSToast duration(int dur) {
38+
this.duration = dur;
39+
return this;
40+
}
41+
42+
public ModeSToast title(String title) {
43+
this.titleTxt = title;
44+
return this;
45+
}
46+
47+
public ModeSToast text(String text) {
48+
this.textTxt = text;
49+
return this;
50+
}
51+
52+
public ModeSToast mode(int mode) {
53+
this.mode = mode;
54+
return this;
55+
}
56+
57+
public void show() {
58+
Toast toast = new Toast(context);
59+
60+
View inflate = ((Activity) context).getLayoutInflater().inflate(R.layout.stoast_modes, null);
61+
LinearLayout main = (LinearLayout) inflate.findViewById(R.id.main);
62+
ImageView img = (ImageView) inflate.findViewById(R.id.img);
63+
TextView title = (TextView) inflate.findViewById(R.id.title);
64+
TextView desc = (TextView) inflate.findViewById(R.id.desc);
65+
66+
switch (mode) {
67+
case MODE_OK:
68+
change(main, img, "#1877F2");
69+
img.setImageResource(R.drawable.ok_img);
70+
break;
71+
case MODE_WARN:
72+
change(main, img, "#FF6801");
73+
img.setImageResource(R.drawable.warn_img);
74+
break;
75+
case MODE_DONE:
76+
change(main, img, "#43A047");
77+
img.setImageResource(R.drawable.true_img);
78+
break;
79+
case MODE_ERROR:
80+
change(main, img, "#FF5252");
81+
img.setImageResource(R.drawable.false_img);
82+
break;
83+
case MODE_INFO:
84+
change(main, img, "#0D47A1");
85+
img.setImageResource(R.drawable.default_img);
86+
break;
87+
case MODE_HEART:
88+
change(main, img, "#FF5252");
89+
img.setImageResource(R.drawable.heart_img);
90+
break;
91+
case MODE_CONFUSE:
92+
change(main, img, "#FF6801");
93+
img.setImageResource(R.drawable.confuse_img);
94+
break;
95+
}
96+
97+
main.setClipToOutline(true);
98+
ui(img, Color.parseColor("#ffffff"), 100);
99+
title.setText(titleTxt);
100+
desc.setText(textTxt);
101+
102+
animate(img, 230);
103+
104+
toast.setView(inflate);
105+
toast.setDuration(duration);
106+
toast.show();
107+
}
108+
109+
private static void change(View v, ImageView im, String col) {
110+
ui(v, Color.parseColor(col), 30);
111+
im.setColorFilter(Color.parseColor(col));
112+
}
113+
114+
private static void ui(View view, int str, int i) {
115+
GradientDrawable gradientDrawable = new GradientDrawable();
116+
gradientDrawable.setColor(str);
117+
gradientDrawable.setCornerRadius((float) i);
118+
view.setBackground(gradientDrawable);
119+
}
120+
121+
private static void animate(View v, int dur) {
122+
new CountDownTimer(dur, 1) {
123+
@Override public void onTick(long d) {}
124+
@Override public void onFinish() {
125+
ObjectAnimator animator = new ObjectAnimator();
126+
animator.setDuration(1000);
127+
animator.setFloatValues(0f, 1f);
128+
animator.setPropertyName("alpha");
129+
animator.setTarget(v);
130+
animator.start();
131+
}
132+
}.start();
133+
}
134+
}

0 commit comments

Comments
 (0)