Code Monkey home page Code Monkey logo

cafebar's Introduction

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.

cafebar's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cafebar's Issues

java.lang.IllegalStateException: Accessibility off

Fatal Exception: java.lang.IllegalStateException: Accessibility off. Did you forget to check that?
       at android.view.accessibility.AccessibilityManager.sendAccessibilityEvent(AccessibilityManager.java:380)
       at android.view.ViewRootImpl.requestSendAccessibilityEvent(ViewRootImpl.java:6767)
       at android.view.ViewGroup.requestSendAccessibilityEvent(ViewGroup.java:891)
       at android.view.ViewGroup.requestSendAccessibilityEvent(ViewGroup.java:891)
       at android.view.ViewGroup.requestSendAccessibilityEvent(ViewGroup.java:891)
       at android.view.ViewGroup.requestSendAccessibilityEvent(ViewGroup.java:891)
       at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:6306)
       at android.view.View.sendAccessibilityEventUnchecked(View.java:6285)
       at android.view.ViewRootImpl$SendWindowContentChangedAccessibilityEvent.run(ViewRootImpl.java:7539)
       at android.view.ViewRootImpl$SendWindowContentChangedAccessibilityEvent.runOrPost(ViewRootImpl.java:7565)
       at android.view.ViewRootImpl.postSendWindowContentChangedCallback(ViewRootImpl.java:6677)
       at android.view.ViewRootImpl.notifySubtreeAccessibilityStateChanged(ViewRootImpl.java:6861)
       at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:3138)
       at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:3138)
       at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:3138)
       at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:3138)
       at android.view.View.notifySubtreeAccessibilityStateChangedIfNeeded(View.java:9441)
       at android.view.ViewGroup.addViewInner(ViewGroup.java:4517)
       at android.view.ViewGroup.addView(ViewGroup.java:4297)
       at android.view.ViewGroup.addView(ViewGroup.java:4237)
       at android.view.ViewGroup.addView(ViewGroup.java:4210)
       at android.support.design.widget.BaseTransientBottomBar.showView(SourceFile:436)
       at android.support.design.widget.BaseTransientBottomBar$1.handleMessage(SourceFile:177)
       at android.os.Handler.dispatchMessage(Handler.java:98)
       at android.os.Looper.loop(Looper.java:163)
       at android.app.ActivityThread.main(ActivityThread.java:6237)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

.buttonColor(int color) dont change buttom color

Also reproduce with .neutralColor/.positiveColor and etc.
library version 1.3.2
Code sample:

public static void actionBar(Activity activity, String text, String actionText, CafeBarCallback cafeBarCallback){
        CafeBar.builder(activity)
                .content(text)
                .to(activity.findViewById(R.id.coordinator))
                .floating(true)
                .fitSystemWindow()
                .buttonColor(R.color.color_yellow)
                .neutralText(actionText)
                .onNeutral(cafeBarCallback)
                .show();
    }


colors.xml
    <color name="color_yellow">#ffca28</color>

Result:
device-2017-11-30-002321

Crash in Activity

When I use cafebar in Activity but not AppCompatActivity, it will crashed. Wish to fix it.

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.