GithubHelp home page GithubHelp logo

nasduck / lesserpandatoast Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 2.0 4.25 MB

Simple progresshud/toast solution for Android with one line of code

License: Apache License 2.0

Java 100.00%
android toast progresshud dialog alert

lesserpandatoast's Introduction

banner

APIAPIAPI

LesserPandaToast provides the simplest solution to call different types of progresshuds or toasts and dismiss them in an indicated delay. Users could also customize their own styles.

If you are also interested at Dialog. Please take a look at another library GiantPandaDialog. From these libraries' names, you will find they are used together. Please enjoy them :D

Content

Setup

Adding jitpack repository in your project's build.gradle file:

allprojects {
	repositories {
		...
		maven { url 'https://www.jitpack.io' }
	}
}

Adding the following dependency to app build.gradle file:

dependencies {
    implementation 'com.github.nasduck:LesserPandaToast:2.0.1'
}

Usage

LesserPandaToast includes two types of Toast:Tip Toast and Loading Toast

Tip Toast

4 types of Toast are provided by default:

  1. Text only
  2. Success
  3. Failure
  4. Warning

Show Tip Toast

// Text only
LesserToastBuilder.show(this, "Toast Default");

// Success
LesserToastBuilder.showSuccess(this);                // Image only
LesserToastBuilder.showSuccess(this, "success");     // Image and text

// Failure
LesserToastBuilder.showFailure(this);                // Image only
LesserToastBuilder.showFailure(this, "failure");     // Image and text

// Warning
LesserToastBuilder.showWarning(this);                // Image only
LesserToastBuilder.showWarning(this, "warning");     // Image and text

Dismiss Tip Toast

Tip Toast is designed based on Android native Toast, so there is no need to hide manually and the display time is the same as that of native Toast.

Custom Tip Toast

LesserToastBuilder.getInstance(this)
	.setImage(Integer image)                            // set image
        .setAnimation(Integer animation)                    // set image animation
        .setBgColor(Integer bgColor)                        // set background color
        .setCornerRadius(Integer cornerRadius)              // set background corner radius
	.setPaddingTop(Integer paddingTop)                  // set top padding
	.setPaddingBottom(Integer paddingBottom)            // set bottom padding
	.setPaddingLeft(Integer paddingLeft)                // set left padding
	.setPaddingRight(Integer paddingRight)              // set right padding
        .setPaddingHorizontal(Integer paddingHorizontal)    // set horizontal padding
        .setPaddingVertical(Integer paddingVertical)        // set vertical padding
	.setPadding(Integer padding)                        // set padding
        .setText(String text)                               // set text
        .setTextColor(Integer textColor)                    // set text color
        .setTextSize(Integer textSize)                      // set text size
        .setGravity(Integer gravity)                        // set toast location in window
	.setXOffset(Integer xOffset)                        // set the offset in X
	.setYOffset(Integer yOffset)                        // set the offset in Y
	.setDuration(Integer duration)                      // set duration
	.show();

Loading Toast

Show Loading Toast

// Loading
DuckToast.showLoading(this);                // Image only
DuckToast.showLoading(this, "loading");     // Image and text

After showLoading is called, Toast will keep shown until user specifies how it will be dismissed.

Dismiss Loading Toast

Two dismiss solution:

  1. Dismiss immediately
  2. Dismiss with delay
LesserToastBuilder.dismiss();                // Dismiss immediately
LesserToastBuilder.dismiss(long delay);      // Dismiss with delay (ms)

Custom Loading Toast

Customize Toast:

LesserPandaToast.getInstance(this)
        .setImage(Integer image)                            // set image
        .setAnimation(Integer animation)                    // set iamge animation
        .setBgColor(Integer bgColor)                        // set background color
        .setCornerRadius(Integer cornerRadius)              // set background corner radius
	.setPaddingTop(Integer paddingTop)                  // set top padding
	.setPaddingBottom(Integer paddingBottom)            // set bottom padding
	.setPaddingLeft(Integer paddingLeft)                // set left padding
	.setPaddingRight(Integer paddingRight)              // set right padding
        .setPaddingHorizontal(Integer paddingHorizontal)    // set horizontal padding
        .setPaddingVertical(Integer paddingVertical)        // set vertical padding
	.setPadding(Integer padding)                        // set padding
        .setText(String text)                               // set text
        .setTextColor(Integer textColor)                    // set text color
        .setTextSize(Integer textSize)                      // set text size
        .show();
        
LesserPandaToast.dismiss(1500); 

Contributer

LICENSE

   Copyright (2019) Chuan Dong, Lihao Zhou

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

lesserpandatoast's People

Contributors

dongchuan avatar redrain39 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lesserpandatoast's Issues

a question about lifecycle

The toast lifecycle now follows the activity.
There are differences from native systems toast.
for example,
Activity A jump to Activity B, it use toast in Activity B for two seconds.
But After one second, it go back to Activity A.
The toast dismiss directly, not holding on for two seconds.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.