Skip to content

Commit

Permalink
Added custom image with no android icon
Browse files Browse the repository at this point in the history
  • Loading branch information
shashank singhal committed Apr 29, 2019
1 parent 8661a2c commit 6418fbc
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 50 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ FancyToast.makeText(this,"Hello World !",FancyToast.LENGTH_LONG,FancyToast.CONFU
```
You can also remove the android icon on top-right corner by passing last parameter false.
``` java
FancyToast.makeText(yourContext, "I'm a Toast", duration, type, boolen value).show();
FancyToast.makeText(yourContext, "I'm a Toast", duration, type, boolean value).show();
```

You can also create your custom Toasts with passing your image:
You can also create your custom Toasts with passing your image with or without android icon(top-right corner):
``` java
FancyToast.makeText(yourContext, "I'm a custom Toast", duration, type, yourimage).show();
FancyToast.makeText(yourContext, "I'm a custom Toast", duration, type, yourimage, boolean value).show();
```
To display the custom Toast with no android icon:

``` java
FancyToast.makeText(this, "This is Custom Toast with no android icon", FancyToast.LENGTH_LONG, FancyToast.CONFUSING, R.drawable.ic_android_black_24dp, false);
```
## Screenshots

**Please click the image below to enlarge.**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
import com.shashank.sony.fancytoastlib.FancyToast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button b1,b2,b3,b4,b5,b6,b7,b8,b9;
Button b1, b2, b3, b4, b5, b6, b7, b8, b9;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button) findViewById(R.id.button);
b2=(Button) findViewById(R.id.button2);
b3=(Button) findViewById(R.id.button3);
b4=(Button) findViewById(R.id.button4);
b5=(Button) findViewById(R.id.button5);
b6=(Button) findViewById(R.id.button6);
b7=(Button) findViewById(R.id.button7);
b8=(Button) findViewById(R.id.button8);
b9=(Button) findViewById(R.id.button9);
b1 = (Button) findViewById(R.id.button);
b2 = (Button) findViewById(R.id.button2);
b3 = (Button) findViewById(R.id.button3);
b4 = (Button) findViewById(R.id.button4);
b5 = (Button) findViewById(R.id.button5);
b6 = (Button) findViewById(R.id.button6);
b7 = (Button) findViewById(R.id.button7);
b8 = (Button) findViewById(R.id.button8);
b9 = (Button) findViewById(R.id.button9);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
Expand All @@ -35,24 +36,24 @@ protected void onCreate(Bundle savedInstanceState) {
}

@Override
public void onClick(View v)
{ if(v.getId()==R.id.button)
FancyToast.makeText(this,"This is Default Toast",FancyToast.LENGTH_LONG,FancyToast.DEFAULT,true).show();
else if(v.getId()==R.id.button2)
FancyToast.makeText(this,"Success Toast !",FancyToast.LENGTH_LONG,FancyToast.SUCCESS,true).show();
else if(v.getId()==R.id.button3)
FancyToast.makeText(this,"This is an Error Toast",FancyToast.LENGTH_LONG,FancyToast.ERROR,true).show();
else if(v.getId()==R.id.button4)
FancyToast.makeText(this,"Beware of dog",FancyToast.LENGTH_LONG,FancyToast.WARNING,true).show();
else if(v.getId()==R.id.button5)
FancyToast.makeText(this,"Here is some Info for you",FancyToast.LENGTH_LONG,FancyToast.INFO,true).show();
else if(v.getId()==R.id.button6)
FancyToast.makeText(this,"This is Confusing Toast",FancyToast.LENGTH_LONG,FancyToast.CONFUSING,false).show();
else if(v.getId()==R.id.button7)
FancyToast.makeText(this,"This is Custom Toast",FancyToast.LENGTH_LONG,FancyToast.CONFUSING,R.drawable.ic_android_black_24dp).show();
else if(v.getId()==R.id.button8)
FancyToast.makeText(this,"This is Custom Toast with no android icon",FancyToast.LENGTH_LONG,FancyToast.CONFUSING,R.drawable.ic_android_black_24dp, false).show();
else if(v.getId()==R.id.button9)
FancyToast.makeText(this,"This is a Success Toast",FancyToast.LENGTH_LONG,FancyToast.SUCCESS,false).show();
public void onClick(View v) {
if (v.getId() == R.id.button)
FancyToast.makeText(this, "This is Default Toast", FancyToast.LENGTH_LONG, FancyToast.DEFAULT, true).show();
else if (v.getId() == R.id.button2)
FancyToast.makeText(this, "Success Toast !", FancyToast.LENGTH_LONG, FancyToast.SUCCESS, true).show();
else if (v.getId() == R.id.button3)
FancyToast.makeText(this, "This is an Error Toast", FancyToast.LENGTH_LONG, FancyToast.ERROR, true).show();
else if (v.getId() == R.id.button4)
FancyToast.makeText(this, "Beware of dog", FancyToast.LENGTH_LONG, FancyToast.WARNING, true).show();
else if (v.getId() == R.id.button5)
FancyToast.makeText(this, "Here is some Info for you", FancyToast.LENGTH_LONG, FancyToast.INFO, true).show();
else if (v.getId() == R.id.button6)
FancyToast.makeText(this, "This is Confusing Toast", FancyToast.LENGTH_LONG, FancyToast.CONFUSING, false).show();
else if (v.getId() == R.id.button7)
FancyToast.makeText(this, "This is Custom Toast", FancyToast.LENGTH_LONG, FancyToast.CONFUSING, R.drawable.ic_android_black_24dp, true).show();
else if (v.getId() == R.id.button8)
FancyToast.makeText(this, "This is Custom Toast with no android icon", FancyToast.LENGTH_LONG, FancyToast.CONFUSING, R.drawable.ic_android_black_24dp, false).show();
else if (v.getId() == R.id.button9)
FancyToast.makeText(this, "This is a Success Toast", FancyToast.LENGTH_LONG, FancyToast.SUCCESS, false).show();
}
}
12 changes: 6 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Default"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
android:text="Default" />

<Button
android:id="@+id/button2"
Expand All @@ -27,8 +27,8 @@
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:text="Error" />

<Button
Expand Down Expand Up @@ -59,8 +59,8 @@
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/button"
android:layout_below="@+id/button4"
android:layout_alignEnd="@+id/button"
android:layout_marginTop="23dp"
android:text="Custom icon" />

Expand All @@ -69,9 +69,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button5"
android:layout_marginTop="23dp"
android:layout_centerHorizontal="true"
android:text="Custom 2" />
android:layout_marginTop="23dp"
android:text="Custom \n(No android icon)" />

<Button
android:id="@+id/button9"
Expand Down
2 changes: 1 addition & 1 deletion fancytoastlib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.Shashank02051997'
group = 'com.github.Shashank02051997'

android {
compileSdkVersion 28
Expand Down
3 changes: 1 addition & 2 deletions fancytoastlib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
</application>
android:supportsRtl="true"></application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public FancyToast(Context context) {
super(context);
}

public static Toast makeText(Context context, String message, int duration, int type, boolean androidicon) {
public static Toast makeText(Context context, String message, int duration, int type, boolean androidIcon) {
Toast toast = new Toast(context);
toast.setDuration(duration);
View layout = LayoutInflater.from(context).inflate(R.layout.fancytoast_layout, null, false);
Expand All @@ -41,10 +41,10 @@ public static Toast makeText(Context context, String message, int duration, int
ImageView img = (ImageView) layout.findViewById(R.id.toast_icon);
ImageView img1 = (ImageView) layout.findViewById(R.id.imageView4);
l1.setText(message);
if(androidicon==true)
img1.setVisibility(View.VISIBLE);
else if(androidicon==false)
img1.setVisibility(View.GONE);
if (androidIcon == true)
img1.setVisibility(View.VISIBLE);
else if (androidIcon == false)
img1.setVisibility(View.GONE);
switch (type) {
case 1:
linearLayout.setBackgroundResource(R.drawable.success_shape);
Expand Down Expand Up @@ -76,15 +76,21 @@ else if(androidicon==false)
}


public static Toast makeText(Context context,String message,int duration,int type,int ImageResource, boolean androidIcon) {


public static Toast makeText(Context context, String message, int duration, int type, int ImageResource, boolean androidIcon) {
Toast toast = new Toast(context);
View layout = LayoutInflater.from(context).inflate(R.layout.fancytoast_layout, null, false);
TextView l1 = (TextView) layout.findViewById(R.id.toast_text);
LinearLayout linearLayout=(LinearLayout) layout.findViewById(R.id.toast_type);
ImageView img=(ImageView) layout.findViewById(R.id.toast_icon);
ImageView img1=(ImageView) layout.findViewById(R.id.imageView4);
LinearLayout linearLayout = (LinearLayout) layout.findViewById(R.id.toast_type);
ImageView img = (ImageView) layout.findViewById(R.id.toast_icon);
ImageView img1 = (ImageView) layout.findViewById(R.id.imageView4);
l1.setText(message);
img.setImageResource(ImageResource);
if (androidIcon == true)
img1.setVisibility(View.VISIBLE);
else if (androidIcon == false)
img1.setVisibility(View.GONE);
switch (type) {
case 1:
linearLayout.setBackgroundResource(R.drawable.success_shape);
Expand Down

0 comments on commit 6418fbc

Please sign in to comment.