Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sad-adnan committed Mar 12, 2021
0 parents commit 01bcd92
Show file tree
Hide file tree
Showing 53 changed files with 1,111 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CustomToast/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions CustomToast/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id 'com.android.library'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Empty file added CustomToast/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions CustomToast/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.sadadnan.customtoastlib;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.sadadnan.customtoastlib.test", appContext.getPackageName());
}
}
5 changes: 5 additions & 0 deletions CustomToast/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sadadnan.customtoastlib">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.sadadnan.customtoastlib;

import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;

public class CustomToast {
public static void ShowSuccessToast(Context mContext, boolean isLong, String successMessage) {
Toast toast = new Toast(mContext);
if (isLong){
toast.setDuration(Toast.LENGTH_LONG);
}else{
toast.setDuration(Toast.LENGTH_SHORT);
}

//inflate view
View custom_view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.toast_icon_text, null);
((TextView) custom_view.findViewById(R.id.message)).setText(successMessage);

((ImageView) custom_view.findViewById(R.id.icon)).setImageResource(R.drawable.ic_done);
((CardView) custom_view.findViewById(R.id.parent_view)).setCardBackgroundColor(((AppCompatActivity)mContext).getResources().getColor(R.color.green500));

toast.setView(custom_view);
toast.show();
}

public static void ShowErrorToast(Context mContext, boolean isLong, String errorMessage) {
Toast toast = new Toast(mContext);
if (isLong){
toast.setDuration(Toast.LENGTH_LONG);
}else{
toast.setDuration(Toast.LENGTH_SHORT);
}

//inflate view
View custom_view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.toast_icon_text, null);
((TextView) custom_view.findViewById(R.id.message)).setText(errorMessage);

((ImageView) custom_view.findViewById(R.id.icon)).setImageResource(R.drawable.ic_close);
((CardView) custom_view.findViewById(R.id.parent_view)).setCardBackgroundColor(((AppCompatActivity)mContext).getResources().getColor(R.color.red500));

toast.setView(custom_view);
toast.show();
}

public static void ShowInfoToast(Context mContext, boolean isLong, String infoMessage) {
Toast toast = new Toast(mContext);
if (isLong){
toast.setDuration(Toast.LENGTH_LONG);
}else{
toast.setDuration(Toast.LENGTH_SHORT);
}

//inflate view
View custom_view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.toast_icon_text, null);
((TextView) custom_view.findViewById(R.id.message)).setText(infoMessage);

((ImageView) custom_view.findViewById(R.id.icon)).setImageResource(R.drawable.ic_error_outline);
((CardView) custom_view.findViewById(R.id.parent_view)).setCardBackgroundColor(((AppCompatActivity)mContext).getResources().getColor(R.color.blue500));

toast.setView(custom_view);
toast.show();
}

public static void showToastWithCustomDrawableAndBG(Context mContext, boolean isLong, String message,int drawableRes,int colorRes){
Toast toast = new Toast(mContext);
if (isLong){
toast.setDuration(Toast.LENGTH_LONG);
}else{
toast.setDuration(Toast.LENGTH_SHORT);
}

//inflate view
View custom_view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.toast_icon_text, null);
((TextView) custom_view.findViewById(R.id.message)).setText(message);

try {
((ImageView) custom_view.findViewById(R.id.icon)).setImageResource(drawableRes);
} catch (Exception e) {
e.printStackTrace();
((ImageView) custom_view.findViewById(R.id.icon)).setImageResource(R.drawable.ic_error_outline);
}
try {
((CardView) custom_view.findViewById(R.id.parent_view)).setCardBackgroundColor(((AppCompatActivity)mContext).getResources().getColor(colorRes));
} catch (Resources.NotFoundException e) {
e.printStackTrace();
((CardView) custom_view.findViewById(R.id.parent_view)).setCardBackgroundColor(((AppCompatActivity)mContext).getResources().getColor(R.color.blue500));
}

toast.setView(custom_view);
toast.show();
}
}
9 changes: 9 additions & 0 deletions CustomToast/src/main/res/drawable/ic_close.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>
9 changes: 9 additions & 0 deletions CustomToast/src/main/res/drawable/ic_done.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
</vector>
9 changes: 9 additions & 0 deletions CustomToast/src/main/res/drawable/ic_error_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
</vector>
51 changes: 51 additions & 0 deletions CustomToast/src/main/res/layout/toast_icon_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/parent_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
app:cardBackgroundColor="@color/grey_90"
app:cardCornerRadius="23dp"
app:cardElevation="0dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="@dimen/spacing_middle"
android:paddingLeft="@dimen/spacing_smlarge"
android:paddingRight="@dimen/spacing_smlarge"
android:paddingTop="@dimen/spacing_middle">

<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/spacing_mlarge"
android:layout_height="@dimen/spacing_mlarge"
app:tint="@android:color/white"
android:src="@drawable/ic_close" />

<View
android:layout_width="@dimen/spacing_middle"
android:layout_height="0dp" />

<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1"
android:singleLine="true"
android:text="Error Toast"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@color/grey_5" />

<View
android:layout_width="@dimen/spacing_middle"
android:layout_height="0dp" />

</LinearLayout>

</androidx.cardview.widget.CardView>
8 changes: 8 additions & 0 deletions CustomToast/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="grey_90">#263238</color>
<color name="grey_5">#f2f2f2</color>
<color name="green500">#4CAF50</color>
<color name="red500">#F44336</color>
<color name="blue500">#2196F3</color>
</resources>
Loading

0 comments on commit 01bcd92

Please sign in to comment.