johnpersano / supertoasts Goto Github PK
View Code? Open in Web Editor NEWA library that extends the Android toast framework.
License: Apache License 2.0
A library that extends the Android toast framework.
License: Apache License 2.0
SuperActivityToast/SuperCardToast will crash when using the onSaveState() call sometimes depending on the state of the Activity. This is due to the classes not being parcelable.
Change from setTextSize(int) to setTextSize(float).
mMessageTextView.setTextSize expects float, not int.
// SuperToast
public void setTextSize(int textSize) {
mMessageTextView.setTextSize(textSize);
}
duration infinite?
Couldn't add as maven dependecy. Added as module in intellij and changed the pom.xml to be able to use it.
please ignore this.
Starting with KitKat, Toasts now have rounded corners. Would be nice to have that for SuperToasts, too. What do you think?
For some reason, SuperToasts appear on the lock screen when shown from an Activity, but not from a BroadcastReceiver (they show up on the home screen below the lock screen instead - you can see them if you quickly unlock the screen while the toast is still showing).
A lot of people like to see how to use the library easily without digging through a demo/sample app. It also serves as a good reference for people utilizing the library.
Hi John!
Well, now I see how you want to "restore" OnClickListeners for Buttons in Toasts - using the Wrapper classes and a tag. But your example case is too simple: how should I transport information to my potentially restored OnClickListener between orientation changes? In your demo it is clear that the "potentially destructive action" which gives a toast with a button cannot use any context data, like what should restored when the button is clicked!
...that is one reason why I do not like the restoring of toasts at all!
In my use cases, I create an OnClickListener class that inherently "knows" which data is to be worked on, just because I use inner classes. That cannot be done using your model at all. What is needed is a way to maybe also give a bundle to the Wrapper for each use of the toast - and that will have to be restored on orientation change as well...
See what I mean?
Thanks!
Olaf
What is the easiest way to change the background colour of a SuperToast
, while preserving the Drawable
shape of the default style?
Hi! I'm trying to add this library to my app. I-m using android.support.v4.widget.DrawerLayout as a root layout for my activity. Do you know of any compatibility issue? I don't get any specific error but the toast doesn't appears.
Thanks!
how can i set layout to show the supertoast include 2 text or 2 images?
For example "dummy_layout.xml" .
If you just need its id to be declared, just declare an id in a "ids.xml" file.
In order to find all of the unused resources, I suggest to run Lint (and on the way to also check other warnings of it).
Because of the missing Typeface-setting option, I tried a real clue:
Setting texts using SpannableStrings that include a different MetricAffectingSpan
(see http://stackoverflow.com/a/15181195/273456)
But when doing that, the padding around the text gets really small, the toasts become extremely thin...
Could you help?
I m having action bar with tabs implemented. I want to use the progress bar on top of list view. But the dismiss animation is too poor and laggy.
You should not use JavaDoc commenting
/** ..... */
where it is not a JavaDoc comment.
For inline comments use line comments
// comment
or normal comments
/* comment */
instead. :)
There is a strange intermittent issue with using a retained fragment to save listeners on orientation change. The retained fragment will be removed in the next release.
The creator method in parcelable referenceholder should be static. Now it crashes when you those need need to be restored with the following exception "expected receiver of type com.github.johnpersano.supertoasts.SuperCardToast$ReferenceHolder, but got null"
first , Super Toast is a great project。
and then,could provide the Demo source code?
I would like to slightly adjust the position of a SuperActivityToast, but it doesn't seem to have a setGravity() method, like SuperToast does. Can this be added?
Hi,
very good library ! I want to be able to customize my toast layout in order to manage by myself title's and button's text/padding on SuperActivityToast.
Could it be possible to set the action button without any icon, and after that to change every padding in the toast layout ?
Thx in advance !
I notice, that the naming conventions of member fields, local variables and parameters are wildly mixed in the code.
In Android, it's convention to use the prefix "m" for member fields only, not for local variables. In your code, sometimes you have member fields without any prefix but also some local variables have an "m" prefix.
Makes your code hard to read and understand. I would offer help, but I am new to github and don't know how to contribute...
Behind the SuperCardToast there is a shadow I would like to remove. How would I do that?
In SuperCardToast
as an example, I found things like this:
if (activity.findViewById(R.id.card_container) != null) {
mViewGroup = (LinearLayout) activity
.findViewById(R.id.card_container);
Now, findViewById is an expensive operation - is has to travel the view hierarchy just to find a specific id. It is unnecessary to call this method twice in a row when just caching the result and checking against null would yield the same result.
Could you improve your code in this respect, please?
Show toast, press home.
Go back to the app : Toast is still there, and doesn't dismiss
I've a Fragment that holds a ViewPager. This ViewPager has 2 fragments (let's call them, "FragmentA" and "FragmentB" as tabbed views.
Both FragmentA and FragmentB have:
As root on their XML layout.
When FragmentB is on the screen and the user presses something in there to fire a Toast the Toast is displayed, always, on FragmentA (which is not visible to the user) and not in the FragmentB (where the user is).
It should fire the Toasts in the "on screen" fragment.
Is this a bug? I can't find out a solution for this and I can't find anything on google regarding this issue.
I want to implement horizontal progress bar as well as simple progress bar. And i want to dismiss them after my uploading function returns, not automatically after specific time. Can anyone help me out ?
Right now if you attempt to build the project with an api level less than 15 you'll get the following error:
ERROR: Debug has an indirect dependency on Android API level 15, but minSdkVersion for variant 'Debug' is API level 9
There's really no reason why support shouldn't be given for API level 8/9.
Can you please deploy JAR on Maven Central or GitHub?
It will be very useful for Maven projects.
I wanted to supply my own typeface to the toasts - but the method named setTypeface
actually takes an int and that is just the style to apply to the internal type face that is not accessible.
This method should be named setTypefaceStyle
and it would be nice to have a real setTypeface
that takes an arbitrary Typeface
object.
Is it necessary to have the svn directory&files in the git repository? Somehow this leads to strange effects when cloning the git repo!
SuperActivityToast works awesome, but I want to use it from an open dialog and it shows behind the dialog. Can you change it to show above all dialogs?
Alternatively, if you could put the LinearLayout for the SuperCardToast in any views layout instead of just the main layout, this would work as well.
In my app it would help greatly to define how close the toast is allowed to be at the bottom edge of the screen. Because there are some elements a user might want to interact with and that gets disturbed while the toast is being displayed.
Is it possible to add an option to define the position of the toasts?
While I definitely like the SuperToasts be coupled tightly with the Activity to preserve context, I found the following problem:
When my activity has an active SuperActivityToast with a relatively long duration and the user leaves this activity to another one, works there and then later goes back to the activity showing the SuperActivityToast, the toast still there. This is on the other hand another "context" problem as the action that initiated this toast can be really old and forgotten.
Then, because you added your Manager classes, I figured, I might add
SuperActivityToast.cancelAllSuperActivityToasts() in my onResume() method to make sure everything is cleaned up.
But with this addition I immediately ended up in an even worse situation: the former SuperActivityToast is still displayed and never disappears.
Must be a cleanup bug in the Manager?
I found there were just four system animations(ANIMATION_FADE, ANIMATION_FLYIN, ANIMATION_SCALE, ANIMATION_POPUP) in SuperToast. I want to add some other custom animations. I try to do so, but it is noneffective. Can you add some custom animations?
Hi
I want to implement superActivityToast on top of DialogFragment but it is shown in parent fragment only. Is it possible to set custom root view ?
how can i change flyin animate from top to down not right to left
Have you thought in adding a 'floating' style to SuperCardToasts? Something like what Crouton does.
I really like SuperCardToast and the customization possibilities, but two things made me finally discard it:
It would be nice to have the possibility to display the card over the current layout
I'm working on an Android app beside iOS developers, and the client wants a toast to appear similar to the way iOS can handle them, i.e. visible until something on the screen is touched (within the app's display, ignoring Notification bar & on-screen buttons)
Is it possible to have the "touch to dismiss" option to have the touch full-screen, and the toast to remain visible until the touch event?
Thanks in advance
Have you though of letting the setters return the according SuperToasts instance?
E.g.
SuperActivityToast superActivityToast = new SuperActivityToast(activity)
.setText(
activity.getResources().getString(R.string.added_to_deck))
.setDuration(SuperToast.Duration.LONG)
.setAnimations(SuperToast.Animations.POPUP)
.setIcon(
R.drawable.ic_added_to_deck,
SuperToast.IconPosition.LEFT)
.setBackground(R.color.DeepYellow)
.setTextColor(Color.WHITE)
.setTextSize(16)
.setTouchToDismiss(true)
.show();
looks more readable than
SuperActivityToast superActivityToast = new SuperActivityToast(activity);
superActivityToast.setText(
activity.getResources().getString(R.string.added_to_deck));
superActivityToast.setDuration(SuperToast.Duration.LONG);
superActivityToast.setAnimations(SuperToast.Animations.POPUP);
superActivityToast.setIcon(
R.drawable.ic_added_to_deck,
SuperToast.IconPosition.LEFT);
superActivityToast.setBackground(R.color.DeepYellow);
superActivityToast.setTextColor(Color.WHITE);
superActivityToast.setTextSize(16);
superActivityToast.setTouchToDismiss(true);
superActivityToast.show();
Just a proposal.
Hi,
THanks man for building this nice library.
I'm doing some proof of concept test with this library.
My big big problem is I'm not able to change background of Toast based on what I want.
This is my singleton class:
public final class SuperToast {
private static SuperToast superToast;
private static SuperActivityToast superActivityToast;
private SuperToast()
{
}
public static SuperToast getInstance(Activity activity)
{
if (superToast == null || superActivityToast == null)
{
superToast = new SuperToast();
superActivityToast = new SuperActivityToast(activity, Style.getStyle(Style.GREEN));
config();
}
return superToast;
}
private static void config()
{
superActivityToast.setIcon(R.drawable.ic_launcher, IconPosition.LEFT);
superActivityToast.setDuration(Duration.LONG);
superActivityToast.setAnimations(Animations.SCALE);
superActivityToast.setTextSize(17);
}
public void show(String message)
{
superActivityToast.setText(message);
superActivityToast.show();
}
}
Above class work fine however if I add superActivityToast.setBackground(Color.BLACK);
code inside my config file then application crashes. and this is my log:
Process: com.myteksi.passenger, PID: 23154
android.content.res.Resources$NotFoundException: Resource ID #0xff000000
at android.content.res.Resources.getValue(Resources.java:1195)
at android.content.res.Resources.getDrawable(Resources.java:729)
at android.content.res.Resources.getDrawable(Resources.java:711)
at android.view.View.setBackgroundResource(View.java:15327)
at com.github.johnpersano.supertoasts.SuperActivityToast.setBackground(SuperActivityToast.java:526)
at com.test.widget.SuperToast.config(SuperToast.java:49)
at com.test.widget.SuperToast.getInstance(SuperToast.java:36)
at com.test.passenger.v3.fragment.book.BookingFragment.onClick(BookingFragment.java:479)
at android.view.View.performClick(View.java:4445)
at android.view.View$PerformClick.run(View.java:18446)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
at dalvik.system.NativeStart.main(Native Method)
I also tried to extend your Style class and override getStyle() method but had same problem.
Any idea would be appreciated...
Right now there's five completely unrelated classes. Though works fine they're too large and difficult to read. A lot of code duplication can also be avoided.
It would be great to introduce some hierarchy and maybe couple interfaces...
I am using SuperActivityToast to show a confirmation with an optional info button (which launches another activity).
Occasionally the toast doesn't come up. Occasionally it comes up but the button is not clickable. Noticed this happens when we try using it frequently. I am using it from a fragment. Any clues ?
Code below:
subscribeConfirmationToast = new SuperActivityToast(getActivity(), SuperToast.Type.BUTTON);
subscribeConfirmationToast.setTouchToDismiss(true);
subscribeConfirmationToast.setText(getResources().getString(R.string.button_subscribe_confirmation));
subscribeConfirmationToast.setButtonIcon(R.drawable.ic_action_database,
getResources().getString(R.string.page_title_subscribed));
subscribeConfirmationToast.setDuration(SuperToast.Duration.SHORT);
subscribeConfirmationToast.setOnClickWrapper(new OnClickWrapper(this.getClass().getName(), new OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
SuperActivityToast.cancelAllSuperActivityToasts();
EventBus.getDefault().post(new Event.ShowMyShowsClicked(getActivity())); // This will launch another activity.
}
}));
public void onEventMainThread(Event.ShowSubscribed event) {
// some other UI updations
if(subscribeConfirmationToast != null) {
subscribeConfirmationToast.show();
}
}
I was just puzzeled - I had a toast on screen when I switched the app. Now brought back my app, and the toast is still there - and never goes away. :-(
I do NOT use any method to save or restore toasts, as I don't want that. But the toast is just there.
Could it be that I need to do the onSave/onResume actions to make the toast go away properly? Then I would like that to be more present in the documentation. For me, I thought I just implement that if I want toasts to be persistent....
How about choosing the animation interpolator? Like bouncing, fading, coming from left to right or the other way around?
Using SuperCardToasts with buttons isn't working so well for me in 1.3.2.
The button seems to have an OnTouchListener that dismisses the toast before the wrapped OnClickListener is called.
Why are you using Touch listeners instead of Click listeners for the button?
Hello,
I think there is a bug with the library.
if, while a SuperActivityToast is shown, you navigate to another activity there is a serious chance it won't dismiss the toast until you exit the app. It just seems to get stuck there.
Can you reproduce this?
The picture you show are oval-shaped,but when i use are only tectangle?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.