• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An upgraded Snackbar for Android that provides more options and easy to use

CafeBar

Build Status Codacy Badge License

An upgraded Snackbar for Android that provides more options and easy to use. Download sample apk from here.

Gradle Dependency

The minimum API level supported by this library is API 14

Add JitPack repository to root build.gradle

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

Add the dependency

dependencies {
    implementation 'com.github.danimahardhika:cafebar:1.3.1'
}

Usage

Old release 1.0.0 - 1.2.0 take a look here

Show simple CafeBar

CafeBar.make(context, R.string.text, CafeBar.Duration.SHORT).show();

Show simple CafeBar with action

CafeBar.make(context, R.string.text, CafeBar.Duration.SHORT)
    .setAction(actionText, actionColor, callback)
    .show();

Using builder

CafeBar.builder(context)
    .theme(CafeBarTheme.LIGHT)
    .duration(CafeBar.Duration.MEDIUM)
    .content(R.string.text)
    .neutralText("Action")
    //You can parse string color
    .neutralColor(Color.parseColor("#EEFF41"))
    //Or use color resource
    .neutralColor(R.color.neutralText)
    .show();

Retrieve CafeBar view

CafeBar.Builder builder = new CafeBar.Builder(context);
...
CafeBar cafeBar = builder.build();

View v = cafeBar.getView();
//Do something
cafeBar.show();

Floating CafeBar

 CafeBar.builder(context)
    .content("some text")
    .floating(true)
    .show();

CafeBar above Translucent NavigationBar

CafeBar.builder(context)
    .content(R.string.text)
    //automatically determine if device has soft navigation bar and translucent navigation bar
    .fitSystemWindow()
    .show();

Custom Theme

CafeBar.builder(context)
    //Text color (content and buttons) automatically set
    .theme(CafeBarTheme.Custom(Color.parseColor("#F44336")));
    .content(R.string.text)
    .show();

Custom Font

CafeBar.builder(context)
    .content(R.string.text)
    //You must place your font inside assets/fonts/ folder
    .contentTypeface("RobotoMono-Regular.ttf")
    //Or
    .contentTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/RobotoMono-Regular.ttf");
    .show();

Customization

Builder

  • customView() β†’ Use custom view
  • to() β†’ Set target view, it should be CoordinatorLayout
  • content() β†’ Content text
  • contentTypeface() β†’ Custom typeface for content
  • maxLines() β†’ Max content lines, must be between 1 to 6.
  • duration() β†’ Show duration
  • theme() β†’ CafeBar theme, there are 3 choices available DARK (default), LIGHT, and CLEAR_BLACK. You can use custom theme CafeBarTheme.Custom(int).
  • icon() β†’ Icon shown on left side of content
  • showShadow() β†’ Enable or disable shadow
  • autoDismiss() β†’ Enable or disable auto dismiss, default is true
  • swipeToDismiss() β†’ Enable or disable swipe to dismiss, only works with target view CoordinatorLayout.
  • floating() β†’ Set CafeBar style to floating
  • gravity() β†’ Set CafeBar view gravity, only works for tablet and floating
  • fitSystemWindow() β†’ Show CafeBar above translucent navigation bar
  • neutralText() β†’ Neutral action text
  • neutralColor() β†’ Neutral action text color
  • neutralTypeface() β†’ Custom typeface for neutral text
  • onNeutral() β†’ Neutral action callback
  • positiveText() β†’ Positive action text
  • positiveColor() β†’ Positive action text color
  • positiveTypeface() β†’ Custom typeface for positive text
  • onPositive() β†’ Positive action callback
  • negativeText() β†’ Negative action text
  • negativeColor() β†’ Negative action text color
  • negativeTypeface() β†’ Custom typeface for negative text
  • onNegative() β†’ Negative action callback
  • buttonColor() β†’ Set all buttons color
  • buttonTypeface() β†’ Set all buttons typeface
  • typeface() β†’ Set content and button typeface
  • show() β†’ Show CafeBar directly from builder
  • build() β†’ Create CafeBar

CafeBar

  • make() β†’ Create CafeBar
  • setAction() β†’ It's the same with neutral action from builder, if neutralText() already set from builder setAction() will be ignored.
  • getView() β†’ Get root view of CafeBar
  • show() β†’ Show CafeBar
  • dismiss() β†’ Dismiss CafeBar

License

Copyright (c) 2017 Dani Mahardhika

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.