Code Monkey home page Code Monkey logo

counterfab's Introduction

License Apache 2.0 minSdkVersion 16 compileSdkVersion 24 CircleCI maven-central

Android Arsenal CounterFab MaterialUp CounterFab

Icon

CounterFab

A FloatingActionButton subclass that shows a counter badge on right top corner

Sample

Get it on Google Play

It's also used by Louvre library.

Louvre

Installation

Include the library in your build.gradle (check badge at top for latest version)

dependencies{
    compile 'com.github.andremion:counterfab:x.y.z'
}

or in your pom.xml if you are using Maven

<dependency>
  <groupId>com.github.andremion</groupId>
  <artifactId>counterfab</artifactId>
  <version>x.y.z</version>
  <type>pom</type>
</dependency>

Usage

Add it as a regular FloatingActionButton on layout…

<com.andremion.counterfab.CounterFab
        android:id="@+id/counter_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_add_white_24dp" />

and programmatically you can use one of these methods:

CounterFab counterFab = (CounterFab) findViewById(R.id.counter_fab);
counterFab.setCount(10); // Set the count value to show on badge
counterFab.increase(); // Increase the current count value by 1
counterFab.decrease(); // Decrease the current count value by 1

Customization

The recommended way to customize the background color is by using the app:backgroundTint attribute

<com.andremion.counterfab.CounterFab
        android:id="@+id/counter_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="@color/colorAccent"
        android:src="@drawable/ic_add_white_24dp" />

To change the badge style you can use these attributes:

  • app:badgeBackgroundColor
  • app:badgeTextColor
  • app:badgePosition as RightTop, LeftBottom, LeftTop or RightBottom

For example:

<com.andremion.counterfab.CounterFab
        android:id="@+id/counter_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:badgeBackgroundColor="@color/red"
        app:badgeTextColor="@color/white"
        app:badgePosition="RightTop"
        android:src="@drawable/ic_add_white_24dp" />

See more at the sample

Libraries and tools used in the project

  • Design Support Library The Design package provides APIs to support adding material design components and patterns to your apps.

License

Copyright 2016 André Mion

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.

counterfab's People

Contributors

andremion avatar juanpmarin avatar nascimentodiego avatar stevenmichael3213 avatar

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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

counterfab's Issues

Unable to update counter value

Great library. I am trying to update the value of the counter but can only work on the initial setCount(), subsequent ones are not updating the value. I am currently setting the value at the onCreateView of a fragment where I can increase/decrease the value. However when I come back to the same fragment the new setCount() isn't working because the fragment never got destroyed though onCreateView is called and getCount() shows the value I set but doesn't update the value with the set value. Any advice why this is happening?

Badge showing different background color

Hi, when I change the counter badge background color using app:badgeBackgroundColor attribute, always badge color showing a darker color than I selected.
Example : if I set app:badgeBackgroundColor = "#ffffff", counter icon displaying with a grey color.
How can I fix this?
Thanks

implementation 'com.android.support:appcompat-v7:27.1.1' is creating issues

implementation 'com.android.support:appcompat-v7:27.1.1'
is not compatible with implementation 'com.github.andremion:counterfab:1.0.1'
I got an error

Program type already present: android.support.design.widget.CoordinatorLayout$Behavior
Message{kind=ERROR, text=Program type already present: android.support.design.widget.CoordinatorLayout$Behavior, sources=[Unknown source file], tool name=Optional.of(D8)}

please help I have to finish it soon

Could you please open the class CounterFab ?

If you open the Class CounterFab like below (add the keyword open in front of class) :

open class CounterFab @jvmoverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = R.attr.floatingActionButtonStyle
) : FloatingActionButton(context, attrs, defStyleAttr)

This will make it easy for others to inherit.

Image Issue

Hi
i have given custom width & height, & the image i have provided in src: method is showing in bottom right side.

icon is overlapped - fabSize mini

There are three different sizes of FAB available:

  • normal (56dp) 
  • mini (40dp)
  • auto (normal or mini - depend on window size)

If i use app:fabSize="mini" the icon is overlapped.

How to custom size image full width and height inside CounterFab

<com.andremion.counterfab.CounterFab
android:id="@+id/image_view_cart"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/shoppingcart"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/margin_8dp"
android:layout_centerVertical="true"
app:backgroundTint="@null"
android:background="@null"
android:scaleType="centerCrop"/>

BadParcelableException still exists in v1.2.0

Caused by android.os.BadParcelableException ClassNotFoundException when unmarshalling: android.support.design.stateful.ExtendableSavedState android.os.Parcel.readParcelableCreator (Parcel.java:2326) android.os.Parcel.readParcelable (Parcel.java:2276) android.view.AbsSavedState.<init> (AbsSavedState.java:57) android.view.View$BaseSavedState.<init> (View.java:20245) com.andremion.counterfab.CounterFab$SavedState.<init> (CounterFab.java:306) com.andremion.counterfab.CounterFab$SavedState.<init> (CounterFab.java:291) com.andremion.counterfab.CounterFab$SavedState$1.createFromParcel (CounterFab.java:343) com.andremion.counterfab.CounterFab$SavedState$1.createFromParcel

Not working

I get this error:

Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be smaller than version 16 declared in library [com.github.andremion:counterfab:1.0.3] /Users/vaevictis/.gradle/caches/transforms-1/files-1.1/counterfab-1.0.3.aar/a29aa8c4f85a075f9eafa82ab292b634/AndroidManifest.xml as the library might be using APIs not available in 15
  	Suggestion: use a compatible library with a minSdk of at most 15,
  		or increase this project's minSdk version to at least 16,
  		or use tools:overrideLibrary="com.andremion.counterfab" to force usage (may lead to runtime failures)

Let me know if I can provide anything else in order to better understand the issues, I am still a nobb at android ;)

Bug

I just loaded the recent Android update and I am getting this error.

Invalid drawable added to LayerDrawable! Drawable already belongs to another owner but does not expose a constant state.
java.lang.RuntimeException
at android.graphics.drawable.LayerDrawable$ChildDrawable.(LayerDrawable.java:1850)
at android.graphics.drawable.LayerDrawable$LayerState.(LayerDrawable.java:1967)
at android.graphics.drawable.RippleDrawable$RippleState.(RippleDrawable.java:997)
at android.graphics.drawable.RippleDrawable.createConstantState(RippleDrawable.java:988)
at android.graphics.drawable.RippleDrawable.createConstantState(RippleDrawable.java:986)
at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:1774)
at android.graphics.drawable.RippleDrawable.mutate(RippleDrawable.java:974)
at android.view.View.applyBackgroundTint(View.java:20601)
at android.view.View.setBackgroundDrawable(View.java:20472)
at android.support.design.widget.FloatingActionButton.access$001(FloatingActionButton.java:69)
at android.support.design.widget.FloatingActionButton$ShadowDelegateImpl.setBackgroundDrawable(FloatingActionButton.java:862)
at android.support.design.widget.FloatingActionButtonLollipop.setBackgroundDrawable(FloatingActionButtonLollipop.java:73)
at android.support.design.widget.FloatingActionButton.(FloatingActionButton.java:188)
at com.andremion.counterfab.CounterFab.(CounterFab.java:90)
at com.andremion.counterfab.CounterFab.(CounterFab.java:86)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:995)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:859)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.hattrick.aformula4success.ordering.Home.onCreate(Home.java:87)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

BadParcelableException in 1.1.0

CounterFab produces BadParcelableException.

Caused by: android.os.BadParcelableException: 
  at android.os.Parcel.readParcelableCreator (Parcel.java:2154)
  at android.os.Parcel.readParcelable (Parcel.java:2104)
  at android.view.AbsSavedState.<init> (AbsSavedState.java:57)
  at android.view.View$BaseSavedState.<init> (View.java:19694)
  at com.andremion.counterfab.CounterFab$SavedState.<init> (SourceFile:270)
  at com.andremion.counterfab.CounterFab$SavedState.<init> (SourceFile:255)
  at com.andremion.counterfab.CounterFab$SavedState$1.a (SourceFile:290)
  at com.andremion.counterfab.CounterFab$SavedState$1.createFromParcel (SourceFile:288)

Crash on Android 5.0

Crash on Android 5.0, ZenPad S 8.0 (Z580CA)
This comes from a production user so I don't have an exact reproduction scenario but other versions of Android from the same app haven't reproduced this crash so far.
CountraFab version 1.1.1

Crash log

Fatal Exception: java.lang.NoSuchMethodError: No direct method <init>(Landroid/os/Parcel;Ljava/lang/ClassLoader;)V in class Landroid/view/View$BaseSavedState; or its super classes (declaration of 'android.view.View$BaseSavedState' appears in /system/framework/framework.jar:classes2.dex)
       at com.andremion.counterfab.CounterFab$SavedState.<init>(CounterFab.java:281)
       at com.andremion.counterfab.CounterFab$SavedState.<init>(CounterFab.java:257)
       at com.andremion.counterfab.CounterFab$SavedState$1.createFromParcel(CounterFab.java:306)
       at com.andremion.counterfab.CounterFab$SavedState$1.createFromParcel(CounterFab.java:302)
       at android.os.Parcel.readParcelable(Parcel.java:2244)
       at android.os.Parcel.readValue(Parcel.java:2146)
       at android.os.Parcel.readSparseArrayInternal(Parcel.java:2540)
       at android.os.Parcel.readSparseArray(Parcel.java:1868)
       at android.os.Parcel.readValue(Parcel.java:2203)
       at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
       at android.os.BaseBundle.unparcel(BaseBundle.java:221)
       at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
       at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1361)
       at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
       at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
       at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
       at androidx.fragment.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:3223)
       at androidx.fragment.app.Fragment.restoreChildFragmentState(Fragment.java:1526)
       at androidx.fragment.app.Fragment.onCreate(Fragment.java:1497)
       at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:197)
       at androidx.fragment.app.Fragment.performCreate(Fragment.java:2414)
       at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1418)
       at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1684)
       at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3774)
       at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:120)
       at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:405)
       at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:387)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
       at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
       at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
       at com.myapp.MainActivity.onCreate(MainActivity.kt:59)
       at android.app.Activity.performCreate(Activity.java:5975)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376)
       at android.app.ActivityThread.access$800(ActivityThread.java:147)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5253)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)

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.