Helper class to make any view rotatable

Overview

Rotatable

This is a helper class actually, it simplifies having a view as rotatable by setting touch events and handling a lot of boilerplate works! So if you need a component that needs to be able to rotate by touch, you do not have to deal with all these stuff.

Sample Video

Rotatable Sample Video

Usage

You can apply this rotatable class to any view in your xml, just need to pass the required view into Rotatable builder and configure up to your needs.

Rotatable rotatable = new Rotatable.Builder(findViewById(R.id.targetView))
                .sides(R.id.frontView, R.id.backView) 
                .direction(Rotatable.ROTATE_X)
                .listener(rotationListener)
                .rotationCount(floatValue)
                .rotataionDistance(floatValue)
                .pivotX(intValue)
                .pivotY(intValue)
                .build();

Rotatable.Builder

sides(int frontViewResId, int backViewResId)
  • is optional, if you need your view to be rotated and display another view, you simply tell the library which one is front and which one is back -assuming that these two views are already in your rootView, otherwise it will crash- and library will swap them smoothly whenever it suppossed to.
rotationCount(float count)
  • Let's assume that you don't want user to swap over and over again your card so you can simply set how many times user can swap the view and library will calculate its maximum distance up to screen's width and height by user's touch and it will be limited to your selected count.
rotataionDistance(float distance)
  • You can also specify distance manually, but be aware of multi screen resolution and calculate carefully if you really need to do it. And important thing is that you cannot have both `rotationCount` and `rotationDistance` defined in your builder, because they have different calculations, so it will crash if you defined both.
pivotX(int pivotXValue)
pivotY(int pivotYValue)
// or 
pivot(int pivotXValue, int pivotYValue)
  • You may need to change pivot position somehow to do it, you can use above methods or .pivot(intXValue, intYValue) to change both in once.

    But test it carefully! Because this can cause view not being drawn. How? & Why? Ok, Let's assume that you have a view with width matches screen's and you set pivotX as beginning, while rotating that will cause view's rotated width exceed screen's border and view will not be drawn until you get a point it can be fit to screen and drawn again.

Rotatable Object

We have built into Rotatable object, but why do we need that? Rotatable object has some useful methods that you may need to change some of configurations or notify rotatable on configuration changes. Such as:

rotatable.rotate(int direction, float degree, int duration, Animator.AnimatorListener listener)
  • Since you have this library implemented, and a rootView already defined into Rotatable object, why bother to create and ObjectAnimator and do your own animation? Simply call this method and library will do it. It has multiple rotate methods with different parameters, so you can call whichever works for you. You do not need to specify duration or listener.
rotatable.setTouchEnable(boolean enable)
rotatable.isTouchEnable()
  • You can enable / disable touch events or check whether touch is enable on rotatable object or not at anytime.
rotatable.setDirection(int direction)
  • Possible to change rotation direction at runtime as well, but only with defined direction values in Rotatable class otherwise it will crash, so ensure that it is not possible to pass this method any other values except ROTATE_X - ROTATE_Y - ROTATE_BOTH
rotatable.orientationChanged(int newOrientation)
  • If your rotatable object needs to calculate its rotationCount or rotationDistance, then it might be tricky while user rotates screen and change orientation. So prevent this, you can listen orientationChanges and notify rotatable object about it, so it can rearrange itself. To do it so, you need to declare `configChanges` in your AndroidManifest.xml as `orientation` but as it is described [here][1] after Android v3.0 it is also required `screenSize` to capture this orientationChange events.
rotatable.drop()
  • This method is quite important, especially when you changed any pivot value of the rootView and you wanted to change some configurations of rotatable. So call drop method first, then you rebuild your rotatable object with same view but different configurations.
rotatable.takeAttention()
  • This is actually just for fun :) You can call this method where you want user to realize that he/she can move this component around :)

Download

Add library dependency to your build.gradle file:

dependencies {    
     compile 'com.yayandroid:Rotatable:1.1.2'
}

License

The MIT License (MIT)

Copyright (c) 2015 yayandroid

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.
You might also like...
Make a cool intro for your Android app.
Make a cool intro for your Android app.

AppIntro AppIntro is an Android Library that helps you build a cool carousel intro for your App. AppIntro has support for requesting permissions and h

A set of Android-UI components to make it easier to request permission in a user friendly way.
A set of Android-UI components to make it easier to request permission in a user friendly way.

Permission UI A set of Android-UI components to make it easier to request permission in a user friendly way. Access background location A jetpack comp

A simple use of canvas to make real life clock

ClockView A simple use of canvas to make real life clock PR-viewer

Android View for displaying and selecting values in a circle-shaped View, with animations and touch gestures.
Android View for displaying and selecting values in a circle-shaped View, with animations and touch gestures.

CircleDisplay Android View for displaying and selecting (by touch) values / percentages in a circle-shaped View, with animations. Features Core featur

用于做Path动画的自定义View。 I have a path.I have a view. (Oh~),Path(Anim)View.
用于做Path动画的自定义View。 I have a path.I have a view. (Oh~),Path(Anim)View.

PathAnimView 用于做Path动画的自定义View。 I have a path.I have a view. (Oh~),Path(Anim)View. 现已经找到图片-SVG-PATH的正确姿势, Now i have a pic.I have a view. Oh~,Path(A

A view that allows to paint and saves the result as a bitmap
A view that allows to paint and saves the result as a bitmap

Android Drawable View Sample app: An Android view that allows to paint with a finger in the screen and saves the result as a Bitmap. Importing to your

Provides 9-patch based drop shadow for view elements. Works on API level 9 or later.
Provides 9-patch based drop shadow for view elements. Works on API level 9 or later.

Material Shadow 9-Patch This library provides 9-patch based drop shadow for view elements. Works on API level 14 or later. Target platforms API level

Snake View is a simple and animated linear chart for Android.
Snake View is a simple and animated linear chart for Android.

Snake View Snake library is a simple and animation line chart for Android. Latest Version How to use Configuring your project dependencies Add the lib

(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.
(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.

BottomBar (Deprecated) I don't have time to maintain this anymore. I basically wrote the whole library in a rush, without tests, while being a serious

Comments
  • Pitching a feature

    Pitching a feature

    Great library but I think you missing the real "killer feature" it can provide. If you add support for automatic rotation according to the device sensors it will allow developer to liven up their apps. While I know it can't get to be as good as seene ( https://play.google.com/store/apps/details?id=com.obviousengine.seene.android.core&hl=en ) without several images, I still think they nailed a great concept and will be interesting to try and do something similar with rotations and skewing of a single image

    opened by Shailevy 1
Owner
Yahya Bayramoğlu
Yahya Bayramoğlu
[] A simple way to "badge" any given Android view at runtime without having to cater for it in layout

Android ViewBadger A simple way to "badge" any given Android view at runtime without having to cater for it in layout. Note: If your aim is to replica

Jeff Gilfelt 3k Nov 28, 2022
Pop animation with circular dust effect for any view updation

Popview-Android Pop animation with circular dust effect for any view updation Getting Started In your build.gradle dependencies { compile 'rb.popv

R B Krishna 489 Dec 28, 2022
Android layout decorators : Injecting custom attributes in layout files, Using decorators to get rid of unnecessary class explosion with custom views

Decor Decor is a library that applies decorators to Android layout with additional attributes without the need to extend and create a custom View for

Mouna Cheikhna 304 Nov 25, 2022
🎨 Android colorpicker for getting colors from any images by tapping on the desired color.

ColorPickerView ?? ColorPickerView implements getting HSV colors, ARGB values, Hex color codes from any image drawables or your gallery pictures by ta

Jaewoong Eum 1.3k Dec 26, 2022
FogView is a android library that can show fog on any layout and the fog removes when user rubs it.

Fog View Android Library Min SDK 8 (Android 2.2–2.2.3 Froyo) Screnshots How to use If you want use this library, you can download project and import i

Chetan Kaushik 631 Dec 31, 2022
Overscroll any scrollable items!

ComposeOverscroll Overscroll any scrollable items! Preview compare with iOS demo Preview.for.overscroll.and.nested.invoke.mp4 How to use for column :

null 7 Dec 15, 2022
Make a cool intro for your Android app.

AppIntro AppIntro is an Android Library that helps you build a cool carousel intro for your App. AppIntro has support for requesting permissions and h

AppIntro Team 10.3k Dec 30, 2022
:bread: Make your native android Toasts Tasty

TastyToast Make your native android toast look beautiful. Preview About Refer Here Wiki Grab the above demo app from here : Dependency Add dependency

Rahul Yadav 2k Dec 29, 2022
Make your native android Toasts Fancy. A library that takes the standard Android toast to the next level with a variety of styling options. Style your toast from code.

FancyToast-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ... ma

Shashank Singhal 1.2k Dec 26, 2022
Make your native android Dialog Fancy. A library that takes the standard Android Dialog to the next level with a variety of styling options. Style your dialog from code.

FancyAlertDialog-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ..

Shashank Singhal 350 Dec 9, 2022