Skip to content

Commit 6433454

Browse files
committed
Initial commit
0 parents  commit 6433454

File tree

73 files changed

+1869
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1869
-0
lines changed

.gitignore

+15
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

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OSMToastLib/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

OSMToastLib/.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OSMToastLib/.idea/gradle.xml

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OSMToastLib/.idea/misc.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OSMToastLib/.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OSMToastLib/.idea/runConfigurations.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OSMToastLib/build.gradle

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
plugins {
2+
id 'com.android.library'
3+
}
4+
5+
android {
6+
compileSdkVersion 31
7+
buildToolsVersion "30.0.3"
8+
9+
defaultConfig {
10+
minSdkVersion 22
11+
targetSdkVersion 31
12+
versionCode 1
13+
versionName "1.0"
14+
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
consumerProguardFiles "consumer-rules.pro"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
}
30+
31+
dependencies {
32+
33+
implementation 'androidx.appcompat:appcompat:1.4.1'
34+
implementation 'com.google.android.material:material:1.5.0'
35+
testImplementation 'junit:junit:4.+'
36+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
37+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
38+
}

OSMToastLib/consumer-rules.pro

Whitespace-only changes.

OSMToastLib/proguard-rules.pro

+21
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.library.osmtoast;
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("com.library.osmtoast.test", appContext.getPackageName());
25+
}
26+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.library.osmtoast">
4+
5+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package com.library.osmtoast;
2+
3+
import android.content.Context;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.widget.ImageView;
7+
import android.widget.LinearLayout;
8+
import android.widget.TextView;
9+
import android.widget.Toast;
10+
11+
import androidx.annotation.IntDef;
12+
13+
import java.lang.annotation.Retention;
14+
import java.lang.annotation.RetentionPolicy;
15+
16+
public class OSMToast extends Toast {
17+
18+
@Retention(RetentionPolicy.SOURCE)
19+
@IntDef({SUCCESS, WARNING, ERROR, INFO, DEFAULT, CONFUSING})
20+
public @interface LayoutType {}
21+
public static final int SUCCESS = 1;
22+
public static final int WARNING = 2;
23+
public static final int ERROR = 3;
24+
public static final int INFO = 4;
25+
public static final int DEFAULT = 5;
26+
public static final int CONFUSING = 6;
27+
28+
@Retention(RetentionPolicy.SOURCE)
29+
@IntDef({ LENGTH_SHORT, LENGTH_LONG })
30+
public @interface Duration {}
31+
public static final int LENGTH_SHORT = Toast.LENGTH_SHORT;
32+
public static final int LENGTH_LONG = Toast.LENGTH_LONG;
33+
public static Toast toast;
34+
35+
public OSMToast(Context context) {
36+
super(context);
37+
}
38+
39+
public static Toast makeText(Context context, CharSequence message, @Duration int duration, @LayoutType int type) {
40+
41+
if(toast!=null)
42+
toast.cancel();
43+
toast = new Toast(context);
44+
45+
toast.setDuration(duration);
46+
View layout = LayoutInflater.from(context).inflate(R.layout.layout_osmtoast, null, false);
47+
TextView l1 = layout.findViewById(R.id.toast_text);
48+
LinearLayout linearLayout = layout.findViewById(R.id.toast_type);
49+
ImageView img = layout.findViewById(R.id.toast_icon);
50+
ImageView logo = layout.findViewById(R.id.iv_logo);
51+
l1.setText(message);
52+
logo.setVisibility(View.GONE);
53+
switch (type) {
54+
case 1:
55+
linearLayout.setBackgroundResource(R.drawable.success_shape);
56+
img.setImageResource(R.drawable.ic_check_black_24dp);
57+
break;
58+
case 2:
59+
linearLayout.setBackgroundResource(R.drawable.warning_shape);
60+
img.setImageResource(R.drawable.ic_pan_tool_black_24dp);
61+
break;
62+
case 3:
63+
linearLayout.setBackgroundResource(R.drawable.error_shape);
64+
img.setImageResource(R.drawable.ic_clear_black_24dp);
65+
break;
66+
case 4:
67+
linearLayout.setBackgroundResource(R.drawable.info_shape);
68+
img.setImageResource(R.drawable.ic_info_outline_black_24dp);
69+
break;
70+
case 5:
71+
linearLayout.setBackgroundResource(R.drawable.default_shape);
72+
img.setVisibility(View.GONE);
73+
break;
74+
case 6:
75+
linearLayout.setBackgroundResource(R.drawable.confusing_shape);
76+
img.setImageResource(R.drawable.ic_refresh_black_24dp);
77+
break;
78+
}
79+
toast.setView(layout);
80+
return toast;
81+
82+
}
83+
84+
85+
public static Toast makeText(Context context, CharSequence message, @Duration int duration, @LayoutType int type, int ImageResource) {
86+
87+
if(toast!=null)
88+
toast.cancel();
89+
toast = new Toast(context);
90+
toast.setDuration(duration);
91+
View layout = LayoutInflater.from(context).inflate(R.layout.layout_osmtoast, null, false);
92+
TextView l1 = layout.findViewById(R.id.toast_text);
93+
LinearLayout linearLayout = layout.findViewById(R.id.toast_type);
94+
ImageView img = layout.findViewById(R.id.toast_icon);
95+
ImageView logo = layout.findViewById(R.id.iv_logo);
96+
l1.setText(message);
97+
logo.setImageResource(ImageResource);
98+
logo.setVisibility(View.VISIBLE);
99+
100+
switch (type) {
101+
case 1:
102+
linearLayout.setBackgroundResource(R.drawable.success_shape);
103+
img.setImageResource(R.drawable.ic_check_black_24dp);
104+
break;
105+
case 2:
106+
linearLayout.setBackgroundResource(R.drawable.warning_shape);
107+
img.setImageResource(R.drawable.ic_pan_tool_black_24dp);
108+
break;
109+
case 3:
110+
linearLayout.setBackgroundResource(R.drawable.error_shape);
111+
img.setImageResource(R.drawable.ic_clear_black_24dp);
112+
break;
113+
case 4:
114+
linearLayout.setBackgroundResource(R.drawable.info_shape);
115+
img.setImageResource(R.drawable.ic_info_outline_black_24dp);
116+
break;
117+
case 5:
118+
linearLayout.setBackgroundResource(R.drawable.default_shape);
119+
img.setVisibility(View.GONE);
120+
break;
121+
case 6:
122+
linearLayout.setBackgroundResource(R.drawable.confusing_shape);
123+
img.setImageResource(R.drawable.ic_refresh_black_24dp);
124+
break;
125+
}
126+
toast.setView(layout);
127+
return toast;
128+
129+
}
130+
}

0 commit comments

Comments
 (0)