LikesLayout


Source link: https://github.com/Iojjj/LikesLayout

Likes Layout

LikesLayout is an implementation of layout that can draw likes similar to Periscope app.

Setup and usage

To include this library to your project add dependency in build.gradle file:

dependencies {

  compile 'com.github.iojjj:likeslayout:1.0.0' 
}

There are three implementations of LikesLayout interface: LikesFrameLayout, LikesLinearLayout, LikesRelativeLayout. You can add them to your view via XML or in Java code.

<com.github.iojjj.likeslayout.LikesLinearLayout

android:layout_width="match_parent"

android:layout_height="250dp"

app:likes_drawable="drawable resource id"

app:likes_drawableWidth="custom drawable width"

app:likes_drawableHeight="custom drawable height"

app:likes_produceInterval="produce interval in milliseconds"

app:likes_animationDuration="animationduration in milliseconds"

app:likes_tintMode="off|on_successively|on_random"

app:likes_tintColors="array resource id"

app:likes_drawableAnimator="cannonical class name"

app:likes_drawablePositionAnimator="cannonical class name"

>

<ImageButton

 ...

 app:likes_drawable="drawable resource id"

 app:likes_drawableWidth="custom drawable width"

 app:likes_drawableHeight="custom drawable height"

 app:likes_mode="enabled|disabled"

 app:likes_produceInterval="produce interval in milliseconds"

 app:likes_animationDuration="animationduration in milliseconds"

 app:likes_tintMode="off|on_successively|on_random"

 app:likes_tintColors="array resource id"

 app:likes_drawableAnimator="cannonical class name"

 app:likes_drawablePositionAnimator="cannonical class name"

 />

  </com.github.iojjj.likeslayout.LikesLinearLayout>

or

// create new LikesLayout LikesLinearLayout likesLinearLayout = new LikesLinearLayout(getContext());
 likesLinearLayout.setId(R.id.likes_layout);
 // set layout height final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,

(int) (getResources().getDisplayMetrics().density * 250));
 likesLinearLayout.setLayoutParams(params);
 likesLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
 // make sure your buttons located at the bottom of LikesLayout likesLinearLayout.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
 likesLinearLayout.setPadding(0, 0, 0, (int) (getResources().getDisplayMetrics().density * 16));
 // get attributes object that will store default values likesLinearLayout.getAttributes().setAnimationDuration(1200);
 likesLinearLayout.getAttributes().setTintMode(LikesAttributes.TINT_MODE_ON_SUCCESSIVELY);
 likesLinearLayout.getAttributes().setTintColors(colors);
  // it's time to add a button ImageButton button = new ImageButton(getContext(), null, R.style.LikeButton_Grade);
 button.setId(R.id.btn_grade);
 button.setImageResource(R.drawable.ic_grade);
 DrawableCompat.setTint(button.getDrawable(), ContextCompat.getColor(getContext(), R.color.colorAccent));
 // you can create layout params for your button using LikesLayout.newLayoutParamsBuilder() method // then using a builder you can set all necessary attributes values final ViewGroup.LayoutParams params = likesLinearLayout

.newLayoutParamsBuilder(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)

.setDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_grade_normal))

.setAnimationDuration(3000)

.setProduceInterval(500)

.setPositionAnimatorFactory(new CustomPositionAnimatorFactory2())

// don't forget to enable likes mode :)

.setLikesMode(LikesAttributes.LIKES_MODE_ENABLED)

.build();
 // set parameters and add button to LikesLayout button.setLayoutParams(params);
 likesLinearLayout.addView(button);

There is the list of available attributes:

Attribute name ATLL CBOBC Description Default value
likes_animationDuration yes yes Animation duration in milliseconds. 1200
likes_drawable yes yes Drawable that will be drawn when user presses view. null
likes_drawableAnimator yes yes Drawable animator factory. @string/likes_drawable_animator_factory
likes_drawableHeight yes yes Custom drawable height. 0
likes_drawablePositionAnimator yes yes Drawable's position animator factory. @string/likes_position_animator_factory
likes_drawableWidth yes yes Custom drawable width. 0
likes_mode no yes Switch that allows to enable/disable drawing likes on touching child view. If likes_drawable is null, likes_mode will be considered as disabled. disabled
likes_produceInterval yes yes Rate at which new likes drawables are produced in milliseconds. 300
likes_tintMode yes yes Switch that allows to enable/disable tinting drawables. not_set
likes_tintColors yes yes Array of colors used for tinting drawables. If array is empty, likes_tintMode will be considered as off. null

Where:

  • ATLL - Available to LikesLayout
  • CBOBC - Can be overridden by child?

Produce likes programmatically

For this case you can use LikesLayout.produceLikes(...) methods, for example:

mLikesLayout.produceLikes(mBtnFavorite, 3, TimeUnit.SECONDS);

Make sure that child passed as an argument ( mBtnFavorite) was added to this mLikesLayout (via XML or Java code). Otherwise you will get IllegalArgumentException.

Custom Animations

You can provide your own animations. There are two types of animators available: DrawableAnimator and PositionAnimator. First one used for animating drawable itself (size, alpha, etc). Second one used for animating drawable's position. Note that PositionAnimator animates center of drawable. To use your custom animations you need to create DrawableAnimator.Factory or PositionAnimator.Factory implementations. Then you can set them via XML or in Java code.

Restrictions

  • If you will not set likes_mode or set it to disabled, this view will not draw any likes.
  • All attributes applicable to LikesLayout will be used as default values for child with likes_mode set to enabled.
  • Custom drawable width and height will set exact size ignoring aspect ratio.
  • Likes floating from bottom to top.

## Changelog
Version Changes
v.1.0.0 First public release

## Support

You can support this library by creating a pull request with bug fixes and/or new features on develop branch. Any pull requests on master branch will be removed.


## License * * * The MIT License (MIT)
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

Wiv

Wiv - Multiple ImageViewer.

Mystique is a Kotlin library for Android’s RecyclerView which allows you to create homogeneous and heterogeneous lists effortlessly using an universal adapter. It’s RecyclerView.Adapter on steroids, written purely in Kotlin (oh yeah, with extension functions too).

A lightweight, simple structured NoSQL database for Android.

A simple continuous animation library for Android UI.

A library of imitation picture tags,you can create and edit tags, add ripple effect.

Library of an android button activated by swipe.

Easy to use. Make your app look great Better UX in sensitive button

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