Helper class to make any view 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.
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)
rotationCount(float count)
rotataionDistance(float distance)
pivotX(int pivotXValue)
pivotY(int pivotYValue)
// or
pivot(int pivotXValue, int pivotYValue)
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)
rotatable.setTouchEnable(boolean enable)
rotatable.isTouchEnable()
rotatable.setDirection(int direction)
rotatable.orientationChanged(int newOrientation)
rotatable.drop()
rotatable.takeAttention()
Add library dependency to your build.gradle
file:
dependencies {
compile 'com.yayandroid:Rotatable:1.1.2'
}
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.