ProperRatingBar


Source link: https://github.com/techery/ProperRatingBar

ProperRatingBar

Inspired by stock android RatingBar. Simpler, has features that original lacks.

What is this about

Whatever you need to display some rating or pricing category - just use ProperRatingBar so this:

<io.techery.properratingbar.ProperRatingBar

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="22sp"

android:textStyle="bold"

app:prb_defaultRating="4"

app:prb_symbolicTick="$"

app:prb_symbolicTickNormalColor="@android:color/darker_gray"

app:prb_symbolicTickSelectedColor="@android:color/holo_green_dark"

app:prb_totalTicks="5"

/>

becomes this:

Example

See video below for possible usage scenarios.

Motivation

Why bother and design our own element?

Well, stock Android RatingBar lacks some styling attributes that you would expect from it and sometimes offers unexpected behavior.

Besides that, we needed to use symbols like '$' as rating bar ticks in our project - none of third-patry libraries out there provides that functionality.

Installation

Library's minSdkVersion is set to 14.

We use jitpack, so you can obtain made-up library right from our github sources in your module's build.gradle file:

compile 'com.github.techery:properratingbar:{ version_name } '

Also you need to add jitpack as repository in the same file:

repositories {

// ...

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

  
}

API Reference

So far we only support customising via xml layout. Here is the list of applicable attributes:

  • prb_totalTicks: total number of ticks to show. Default is '5'

  • prb_defaultRating: use this to set rating from xml. Default is '3'

  • prb_clickable: if set to 'true' - use will be able to change rating by clicking. Default is 'false'

  • prb_symbolicTick: symbol to be used as a tick. Default is '$'

  • android:textSize: text size of symbolic tick. Default is '15sp'

  • android:textStyle: text style of symbolic tick. Possible: 'bold', 'italic', 'normal'. Default is 'normal'

  • prb_symbolicTickNormalColor: color of symbolic tick that is not selected (not rated). Default is '#FF000000' (black)

  • prb_symbolicTickSelectedColor: color of symbolic tick that is selected (rated). Default is '#FF888888' (gray)

  • prb_tickNormalDrawable: drawable resource to use as a tick that is not selected (not rated). No default value

  • prb_tickSelectedDrawable: drawable resource to use as a tick that is selected (rated). No default value

  • prb_tickSpacing: margin to be applied to tick drawables. Only applies to drawable-type ticks. Default is '1dp' (gray)

Also there's a number of methods to operate on ProperRatingBar programmatically:

public boolean isClickable();
  /**  * Nifty sugar method to just toggle clickable to opposite state.  */ public void toggleClickable();
  public void setClickable(boolean clickable);
  /** * Get the attached {
@link RatingListener
}
 * @return listener or null if none was set */ @Nullable public RatingListener getListener();
  /** * Set the {
@link RatingListener
}
 to be called when user taps rating bar's ticks * @param listener listener to set */ public void setListener(RatingListener listener);
  /** * Remove listener */ public void removeRatingListener();
  /** * Get the current rating shown * @return rating */ public int getRating();
  /** * Set the rating to show * @param rating new rating value */ public void setRating(int rating);

Tests

No test coverage is supplied so far - might be added later.

Versions

Actual version can be found here

Be warned that given code is likely to be refactored and partly re-done (including possible API changes with no backward-compatibility).

Contribution

PR's are welcome. Just follow the general code style (both xml and java).

Proper code style setup might be added later and included to repository.

License

The MIT License (MIT)  Copyright (c) 2016 Techery (http://techery.io/)  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

A library which helps developers to integrate Google Sign-in and Facebook Sign-in.

A simple implementation of Drag and Drop for RecyclerView

A cool android loading effect.

View that supports a foreground, like FrameLayout.

RevealFAB is a simple custom view that provides you intents between activities with ripple animation.

A light-weight image cropping layout, allowing UI customization and cropping box update listener. Image and the selected area (cropping box) is scale and fit into the predefined area.

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