Coder Social home page Coder Social logo

jakir123 / notificationbanner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shasin89/notificationbanner

0.0 1.0 0.0 2.98 MB

Easy to use pop up notification banner for in app local notification.

Home Page: https://medium.com/@shasindranpoonudurai/the-effortless-in-app-notification-banner-library-for-your-android-app-9a9eb3f2bd5c

License: MIT License

Java 100.00%

notificationbanner's Introduction

Notification Banner for Android

A pop up notification banner for in app local notification. Easy to use with default layouts for success, info, warning, and error banners. The library allow to customize the layout with your own design and click events.

Blog: https://medium.com/@shasindranpoonudurai/the-effortless-in-app-notification-banner-library-for-your-android-app-9a9eb3f2bd5c

Top:

demo

Bottom:

demo

Auto dismiss and onClick listener:

demo

Below a view (eg Toolbar):

demo

FullScreen:

demo

Installation

Add the library to your build.gradle:

dependencies {
      compile 'com.github.shasin89:NotificationBanner:{latest-release}'
    }

This library is distributed via jitpack. Add following in your gradle if doesn't exist:

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

Prerequisites

The minimum API level supported by this library is API 14 (ICE_CREAM_SANDWICH).

Usage

In onCreate() of your activity, create a root view object for the banner:

View rootview = findViewById(android.R.id.content);

With the latest release of v1.1.0, you can now call the banner with one line of code:

Option 1: Choose default layouts

Banner.make(View view,Context context, int bannerType, String message, int position);

Option 2: Choose default layouts with auto dismiss after the given duration

Banner.make(View view,Context context, int bannerType, String message, int position, int duration);

Option 3: With custom layout:

Banner.make(View view,Context context, int position, int Customlayout);

Option 4: With custom layout and below a view (eg toolbar):

Banner make(View view,Context context, int position, int Customlayout,boolean asDropDown) 

Option 5: With custom layout and full screen:

Banner make(View view,Context context, int Customlayout,boolean fillScreen)

Example:

Banner.make(rootview,getBaseContext(),Banner.SUCCESS,"This is a successful message",Banner.TOP).show();
Banner.make(rootview,getBaseContext(),Banner.ERROR,"This is an error message",Banner.BOTTOM,2000).show();

For custom layout, pass your layout as shown below:

Banner.make(rootview,getBaseContext(),Banner.TOP,R.layout.banner);

If your custom banner has views that need to be set on runtime, instantiate your view objects as below:

textView = Banner.getInstance().getBannerView().findViewById(R.id.status_text);
relativeLayout = Banner.getInstance().getBannerView().findViewById(R.id.rlCancel);
textView.setText("This is text for the banner");

To listen to click events, you can implement the following code:

 textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getBaseContext(),"Banner has been clicked", Toast.LENGTH_LONG).show();
            }
        });

        relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Banner.getInstance().dismissBanner();
            }
        });

The library allow to set custom animation for the banner. You can set your own animation style as below:

Banner.getInstance().setCustomAnimationStyle(R.style.NotificationAnimationBottom);

If you want to auto dismiss your custom banner, set the duration as below:

Banner.getInstance().setDuration(2000);

Finally, invoke show method:

 Banner.getInstance().show();

Contribution

Pull requests for new features, bug fixes, and suggestions are welcome!

License

MIT License

Copyright (c) 2018 Shasindran Poonudurai

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

notificationbanner's People

Contributors

shasin89 avatar

Watchers

James Cloos avatar

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.