Skip to content

Commit 9523a7e

Browse files
committed
New Update
0 parents  commit 9523a7e

35 files changed

+1107
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

SToast/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

SToast/build.gradle

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
plugins {
2+
id 'com.android.library'
3+
}
4+
5+
android {
6+
namespace 'smith.lib.alerts.toast'
7+
compileSdk 33
8+
9+
defaultConfig {
10+
minSdk 21
11+
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+
}
26+
}
27+
compileOptions {
28+
sourceCompatibility JavaVersion.VERSION_17
29+
targetCompatibility JavaVersion.VERSION_17
30+
}
31+
}
32+
33+
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'
39+
}

SToast/consumer-rules.pro

Whitespace-only changes.

SToast/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package smith.lib.alerts.toast;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals( smith.lib.alerts.toast.test", appContext.getPackageName() );
25+
}
26+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
</manifest>
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
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.transition.AutoTransition;
10+
import android.transition.TransitionManager;
11+
import android.view.animation.AlphaAnimation;
12+
import android.view.View;
13+
import android.animation.ObjectAnimator;
14+
import android.view.ViewGroup;
15+
import android.widget.ImageView;
16+
import android.widget.LinearLayout;
17+
import android.widget.TextView;
18+
import android.widget.Toast;
19+
import java.util.Timer;
20+
21+
public class SToast {
22+
23+
private static final String DARK = "#212121";
24+
private static final String LIGHT = "#FFFFFF";
25+
26+
public static final int MODE_OK = 0;
27+
public static final int MODE_WARN = 1;
28+
public static final int MODE_DONE = 2;
29+
public static final int MODE_ERROR = 3;
30+
public static final int MODE_INFO = 4;
31+
public static final int MODE_HEART = 5;
32+
public static final int MODE_CONFUSE = 6;
33+
private static int type = MODE_INFO;
34+
35+
private static Toast toast;
36+
private static Context context;
37+
private static String titl, text;
38+
39+
private static int color = 0xFFFF5252;
40+
private static int icon = R.drawable.heart_img;
41+
42+
public static final int LONG = Toast.LENGTH_LONG;
43+
public static final int SHORT = Toast.LENGTH_SHORT;
44+
private static int length = Toast.LENGTH_SHORT;
45+
46+
public static class Adaptive {
47+
public Adaptive(Context ctx, int dur) {
48+
context = ctx;
49+
length = dur;
50+
}
51+
52+
public Adaptive setTitle(String ttl) {
53+
titl = ttl;
54+
return this;
55+
}
56+
57+
public Adaptive setText(String txt) {
58+
text = txt;
59+
return this;
60+
}
61+
62+
public Adaptive setIconAndColor(int ic, int clr) {
63+
icon = ic;
64+
color = clr;
65+
return this;
66+
}
67+
68+
public SToast show() {
69+
toast = new Toast(context);
70+
71+
View inflate = ((Activity) context).getLayoutInflater().inflate(R.layout.stoast_adaptive, null);
72+
LinearLayout main = (LinearLayout) inflate.findViewById(R.id.main);
73+
LinearLayout view = (LinearLayout) inflate.findViewById(R.id.main2);
74+
ImageView img = (ImageView) inflate.findViewById(R.id.img);
75+
TextView title = (TextView) inflate.findViewById(R.id.title);
76+
TextView desc = (TextView) inflate.findViewById(R.id.desc);
77+
78+
ui(main, color, 30);
79+
if (nightModeON()) {
80+
ui(view, Color.parseColor(DARK), 30);
81+
title.setTextColor(Color.parseColor(LIGHT));
82+
desc.setTextColor(Color.parseColor(LIGHT));
83+
} else {
84+
ui(view, Color.parseColor(LIGHT), 30);
85+
title.setTextColor(color);
86+
desc.setTextColor(Color.parseColor(DARK));
87+
}
88+
89+
animate(img, 230);
90+
91+
main.setClipToOutline(true);
92+
title.setText(titl);
93+
desc.setText(text);
94+
img.setImageResource(icon);
95+
96+
toast.setDuration(length);
97+
toast.setView(inflate);
98+
toast.show();
99+
100+
return new SToast();
101+
}
102+
}
103+
104+
public static class Mode {
105+
106+
public Mode(Context ctx, int dur) {
107+
context = ctx;
108+
length = dur;
109+
}
110+
111+
public Mode setTitle(String ttl) {
112+
titl = ttl;
113+
return this;
114+
}
115+
116+
public Mode setText(String txt) {
117+
text = txt;
118+
return this;
119+
}
120+
121+
public Mode setMode(int mode) {
122+
type = mode;
123+
return this;
124+
}
125+
126+
public SToast show() {
127+
toast = new Toast(context);
128+
129+
View inflate = ((Activity)context).getLayoutInflater().inflate(R.layout.stoast_modes, null);
130+
LinearLayout main = (LinearLayout) inflate.findViewById(R.id.main);
131+
ImageView img = (ImageView) inflate.findViewById(R.id.img);
132+
TextView title = (TextView) inflate.findViewById(R.id.title);
133+
TextView desc = (TextView) inflate.findViewById(R.id.desc);
134+
135+
switch (type) {
136+
case MODE_OK:
137+
change(main, img, "#1877F2");
138+
img.setImageResource(R.drawable.ok_img);
139+
break;
140+
case MODE_WARN:
141+
change(main, img, "#FF6801");
142+
img.setImageResource(R.drawable.warn_img);
143+
break;
144+
case MODE_DONE:
145+
change(main, img, "#43A047");
146+
img.setImageResource(R.drawable.true_img);
147+
break;
148+
case MODE_ERROR:
149+
change(main, img, "#FF5252");
150+
img.setImageResource(R.drawable.false_img);
151+
break;
152+
case MODE_INFO:
153+
change(main, img, "#0D47A1");
154+
img.setImageResource(R.drawable.default_img);
155+
break;
156+
case MODE_HEART:
157+
change(main, img, "#FF5252");
158+
img.setImageResource(R.drawable.heart_img);
159+
break;
160+
case MODE_CONFUSE:
161+
change(main, img, "#FF6801");
162+
img.setImageResource(R.drawable.confuse_img);
163+
break;
164+
}
165+
166+
main.setClipToOutline(true);
167+
ui(img, Color.parseColor("#ffffff"), 100);
168+
title.setText(titl);
169+
desc.setText(text);
170+
171+
animate(img, 230);
172+
173+
toast.setView(inflate);
174+
toast.setDuration(length);
175+
toast.show();
176+
177+
return new SToast();
178+
}
179+
}
180+
181+
private static void change(View v, ImageView im, String col) {
182+
ui(v, Color.parseColor(col), 30);
183+
im.setColorFilter(Color.parseColor(col));
184+
}
185+
186+
private static void animate(View v, int dur) {
187+
new CountDownTimer(dur, 1) {
188+
@Override public void onTick(long arg0) {}
189+
@Override public void onFinish() {
190+
ObjectAnimator animator = new ObjectAnimator();
191+
animator.setDuration(1000);
192+
animator.setFloatValues(0.0f, 1.0f);
193+
animator.setPropertyName("alpha");
194+
animator.setTarget(v);
195+
animator.start();
196+
}
197+
}.start();
198+
}
199+
200+
private static boolean nightModeON() {
201+
int flags =
202+
context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
203+
boolean isNightModeOn = flags == Configuration.UI_MODE_NIGHT_YES;
204+
if (isNightModeOn) return true;
205+
else return false;
206+
}
207+
208+
private static void ui(View view, int str, int i) {
209+
GradientDrawable gradientDrawable = new GradientDrawable();
210+
gradientDrawable.setColor(str);
211+
gradientDrawable.setCornerRadius((float) i);
212+
view.setBackground(gradientDrawable);
213+
}
214+
215+
/*
216+
*
217+
*
218+
* THIS LIBRARY CREATED BY HUSSEIN SHAKIR (SMITH)
219+
*
220+
* TELEGRAM : @SMITHDEV
221+
* YOUTUBE : HUSSEIN SMITH
222+
*
223+
* YOU GUYS ARE NOT ALLOWED TO MODIFY THIS LIBRARY,
224+
* WITHOT ANY PERMISSION FROM ME PERSONALLY..
225+
* ALL RIGHTS RESERVED © HUSSEIN SHAKIR, 2022.
226+
*
227+
*
228+
*/
229+
}
3.72 KB
Loading
3.24 KB
Loading

0 commit comments

Comments
 (0)