LGSnackbar


Source link: https://github.com/loregr/LGSnackbar

An easy to use wrapper of the native Android Snackbar which stays visible across multiple activities. It provides different themes to start with, and allows you to easily manage common scenarios like success, warning, error, info.

Preview

Demo video:

Try it on Appetize:

Install

In your root/build.gradle:

allprojects {

repositories {

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

}
 
}
  

In your app/build.gradle

dependencies {

compile 'com.github.loregr:lgsnackbar:1.0.2' 
}

Preparing

Setup with a default theme

Define your default theme using LGSnackbarManager.prepare(...), in your Application class in the #onCreate() method.

@Override public void onCreate() {

  super.onCreate();

  LGSnackbarManager.prepare(getApplicationContext(),

  LGSnackBarThemeManager.LGSnackbarThemeName.SHINE);

  //.... 
}

You can check the available themes here.

Note: You can simply call LGSnackbarManager.prepare(getApplicationContext()), in this case SHINE theme will be automatically applied.

Setup with a custom theme

Create your own LGSnackbarTheme by passing 4 LGSnackBarStyle instances (one for each scenario of the theme) and the minHeight and the duration values that you want to apply to the Snackbar.

@Override public void onCreate() {

  super.onCreate();

  LGSnackbarManager.prepare(getApplicationContext(),

customTheme());

  //.... 
}
  //...  LGSnackBarTheme customTheme() {

  LGSnackBarStyle successStyle = new LGSnackBarStyle(successCustomColor,

 Color.WHITE,

 actionSuccessCustomColor,

 R.drawable.ic_done_white);

LGSnackBarStyle warningStyle = new LGSnackBarStyle(warningCustomColor,

 Color.WHITE,

 actionWarningCustomColor,

 R.drawable.ic_warning_white);

LGSnackBarStyle errorStyle = new LGSnackBarStyle(errorCustomColor,

 Color.WHITE,

 actionErrorCustomColor,

 R.drawable.ic_error_outline_white);

LGSnackBarStyle infoStyle = new LGSnackBarStyle(infoCustomColor,

 Color.WHITE,

 actionInfoCustomColor,

R.drawable.ic_info_outline_white);

return new LGSnackBarTheme(successStyle, warningStyle, errorStyle, infoStyle, 60, Snackbar.LENGTH_LONG);
 
}

Usage

After preparing is done, in order to show a snackbar you can simply call:

LGSnackbarManager.show(SUCCESS, "Everything is looking good! Awesome!");

Woooo, done! :-)

Callbacks and actions

You can add a callback and/or an action to your snackbar by calling:

Callback:

LGSnackbarManager.show(SUCCESS, "Everything is looking good! Awesome!",
new Snackbar.Callback() {

 @Override

 public void onShown(Snackbar sb) {

  super.onShown(sb);

  // LGSnackbar is now visible

 
}

  @Override

 public void onDismissed(Snackbar transientBottomBar, int event) {

  super.onDismissed(transientBottomBar, event);

  // LGSnackbar is now hidden

 
}
 
}
);

Action:

LGSnackbarManager.show(SUCCESS, "Everything is looking good! Awesome!",
new LGSnackbarAction("Action", new View.OnClickListener() {

@Override

public void onClick(View view) {

  // Action fired

}
 
}
));

Custom snackbar

If for any reason you may need to display a custom snackbar without setting a whole new theme, you can use an LGSnackbarBuilder

new LGSnackbar.LGSnackbarBuilder(getApplicationContext(), "This is a custom bar")

.duration(Snackbar.LENGTH_LONG)

.actionTextColor(Color.GREEN)

.backgroundColor(Color.GRAY)

.minHeightDp(50)

.textColor(Color.WHITE)

.iconID(R.drawable.ic_info_outline_white)

.callback(null)

.action(null)

.show();
Supported Attributes
Attribute Description Default value
style An LGSnackBarStyle instance Native Android snackbar style
duration How long to display the message. Either LENGTH_SHORT or LENGTH_LONG LENGTH_LONG
backgroundColor The color of the snackbar Native Android color
actionTextColor The color of the text of an action Native Android color
textColor The color of the text white
minHeightDp The height of the snackbar when only one line if text is displayed 48
iconID The drawable id of the icon NO_ICON_ID (-1)
callback The snackbar callback null
action The snackbar action null

Issues

Feel free to submit issues and features requests.

Contributing

Contributions are more then welcome. Your contribution may include bug fixing, new features or just new themes.

Please follow the "fork-and-pull" Git workflow (check here for more).

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that I can review your changes

If you contribute with a new theme, please update also the themes.md file.

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

Author

Lorenzo Greco

License

MIT License  Copyright (c) 2017 Lorenzo Greco  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. 

Resources

Espresso's consistency makes it really easy to learn.

Want to match a view with a specific id? Use withId(R.id.some_id). Need to match with a piece of text? Use withText(R.id.some_text) or withText("some text). Awesome, consistent and it's very clear what it is you are doing.

However...

After a few hours writing test code you'll find your code being a little bit too verbose. Not anymore.

Why should you need to explicitly specify that you are matching with some text if you are passing in some text as a parameter? Some for the view id, you can already see that it is a view id.

Ristretto allows you to write the same test code as you already write, but less verbose.

Complete abstraction from the Spannable API. Forget about all the boiler plate code and all the Object what nonsense that you have to deal with when working with Spannable.

  • Eliminate setSpan calls by using all the provided methods trough the StyleEZ interface.
  • Chain multiple spans with a fluent style
  • By using both the ContentEZ and StyleEZ interface it removes unnecessary methods from the autocomplete form, and thus it removes clutter.
  • Allows different ways of adding content (String, String Resource and Formatted String)
  • By default it does INCLUSIVE_INCLUSIVE to all the spans
  • After calling any of the inclusive/exclusive methods, all the next methods will be using that flag until apply is called or another flag is used
  • You can create your own locator by extending the Locator interface

FadingTextView is a TextView that changes its content automatically every few seconds.

An example android application to set dynamic span size on GridLayoutManager, RecyclerView.

Android Library for custom views to control brightness , volume and seek through swipable gestures . These views could easily replace the conventional volume / brightness / seek controls that we have in music player ,video player or gallery apps.

Changes the color of individual pixels in a Bitmap.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes