Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show method doesn't make toast visible after set it to hide #3

Closed
Hesamedin opened this issue Oct 23, 2014 · 6 comments
Closed

Show method doesn't make toast visible after set it to hide #3

Hesamedin opened this issue Oct 23, 2014 · 6 comments

Comments

@Hesamedin
Copy link

Hi, me again :)

I created a singleton class like this:

public class NiftyToast
{

    private static final String TAG = NiftyToast.class.getSimpleName();
    private static final int VISIBLE_TIME = 1 * 60 * 1000; // 1 minute

    private static NiftyToast instance = null;

    private static NiftyNotificationView mNiftyView = null;

    private NiftyToast()
    {

    }

    public synchronized static NiftyToast getInstance(final Activity activity, final String msg,
            int viewGroupResId)
    {
        if(NiftyToast.instance == null)
        {
            NiftyToast.instance = new NiftyToast();
        }

        if(NiftyToast.mNiftyView == null)
        {
            NiftyToast.mNiftyView = NiftyNotificationView
                    .build(activity, msg, Effects.flip, viewGroupResId, getConfig())
                    .setIcon(R.drawable.ic_launcher);
        }

        return instance;
    }

    private static Configuration getConfig()
    {
        return new Configuration.Builder()
                .setAnimDuration(700)
                .setDispalyDuration(VISIBLE_TIME)
                .setBackgroundColor("#FFBDC3C7")
                .setTextColor("#FF444444")
                .setIconBackgroundColor("#FFFFFFFF")
                .setTextPadding(5)                      //dp
                .setViewHeight(48)                      //dp
                .setTextLines(2)                        //You had better use setViewHeight and setTextLines together
                .setTextGravity(Gravity.CENTER)         //only text def  Gravity.CENTER,contain icon Gravity.CENTER_VERTICAL
                .build();
    }

    public void showNiftyToast()
    {
        mNiftyView.show();
    }

    public void hideNiftyToast()
    {
        mNiftyView.hide();
    }
}

I want to display "Searching network..." when I have no internet connection and hide it once device connected. I have created Receiver class and it's working fine. So, I have following method in my activity:

private void displayInternetRequired(boolean connectivityStatus)
    {
        NiftyToast toast = NiftyToast.getInstance(this, "Searching network...", R.id.main_frame);
        if (!connectivityStatus)
        {
            toast.showNiftyToast();
        }
        else
        {
            toast.hideNiftyToast();
        }
    }
  1. I can see toast message when there is no Internet connection
  2. Toast dismisses once Internet connected.
  3. Toast doesn't displays when there is no Internet connection.

I guess something is wrong with hide method. I appreciate if you can double check. Thanks.

@litao0621
Copy link
Owner

Hi @Hesamedin
I add showSticky() and removeSticky() mothod , You can see the latest code

#2

@Hesamedin
Copy link
Author

Wow, you are so fast :)
How can I get jar files? Would you please upload it somewhere? Thanks ;)

@Hesamedin
Copy link
Author

Wow, I got it from your readme. Will check and let you know if I was successful. Thanks.

@litao0621
Copy link
Owner

You just download this jar.if worked,Please give me a feedback

e.g

notify.showSticky();
notify.removeSticky();

@Hesamedin
Copy link
Author

It's working like charm man ;)
Thanks a lot. You saved my days of working... 👍

  1. Just a request, It would be great if there is a method that I pass my custom TextView object, since I cannot set style to Bold or Italic.
  2. Another good idea would be having a method that make me able to pass a viewGroup. In this case user is able to close toast message by click on close image for example.

anyways, Thanks a lot for your help.

@litao0621
Copy link
Owner

😄
I’ll think about it,But it is complicated,This might take some time.if you are interested or have a good idea,Please send pull requests,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants