├── Library
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ ├── gradle.xml
│ ├── compiler.xml
│ └── misc.xml
├── app
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ └── java
│ │ │ └── com
│ │ │ └── yayandroid
│ │ │ └── rotatable
│ │ │ └── Rotatable.java
│ ├── proguard-rules.pro
│ ├── build.gradle
│ └── app.iml
├── settings.gradle
├── .gitignore
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── build.gradle
├── Library.iml
├── gradle.properties
├── gradlew.bat
├── maven_push.gradle
└── gradlew
├── Sample
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ ├── gradle.xml
│ ├── compiler.xml
│ └── misc.xml
├── app
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── sample_image.jpg
│ │ │ │ └── sample_image_2.jpg
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── menu
│ │ │ │ └── menu_rotation.xml
│ │ │ └── layout
│ │ │ │ ├── activity_landing.xml
│ │ │ │ ├── activity_animate.xml
│ │ │ │ └── activity_touch.xml
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── yayandroid
│ │ │ │ └── rotatable
│ │ │ │ └── sample
│ │ │ │ ├── LandingActivity.java
│ │ │ │ ├── AnimateActivity.java
│ │ │ │ └── TouchActivity.java
│ │ │ └── AndroidManifest.xml
│ ├── proguard-rules.pro
│ ├── build.gradle
│ └── app.iml
├── settings.gradle
├── .gitignore
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── build.gradle
├── gradle.properties
├── Sample.iml
├── TransitionSample.iml
├── gradlew.bat
└── gradlew
└── README.md
/Library/.idea/.name:
--------------------------------------------------------------------------------
1 | Library
--------------------------------------------------------------------------------
/Sample/.idea/.name:
--------------------------------------------------------------------------------
1 | Sample
--------------------------------------------------------------------------------
/Library/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Sample/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Library/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/Sample/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/Library/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | .idea
3 | .DS_Store
4 | /local.properties
5 | /build
6 | /captures
7 |
--------------------------------------------------------------------------------
/Sample/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | .idea
3 | .DS_Store
4 | /local.properties
5 | /build
6 | /captures
7 |
--------------------------------------------------------------------------------
/Library/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Sample/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Library/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Library/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yayaa/Rotatable/HEAD/Library/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Sample/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yayaa/Rotatable/HEAD/Sample/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Sample/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yayaa/Rotatable/HEAD/Sample/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Sample/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yayaa/Rotatable/HEAD/Sample/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Sample/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yayaa/Rotatable/HEAD/Sample/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yayaa/Rotatable/HEAD/Sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yayaa/Rotatable/HEAD/Sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Sample/app/src/main/res/mipmap-xxxhdpi/sample_image.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yayaa/Rotatable/HEAD/Sample/app/src/main/res/mipmap-xxxhdpi/sample_image.jpg
--------------------------------------------------------------------------------
/Sample/app/src/main/res/mipmap-xxxhdpi/sample_image_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yayaa/Rotatable/HEAD/Sample/app/src/main/res/mipmap-xxxhdpi/sample_image_2.jpg
--------------------------------------------------------------------------------
/Library/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Sample/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Sample/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/Library/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Nov 23 09:24:01 EET 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
7 |
--------------------------------------------------------------------------------
/Sample/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Nov 23 09:24:01 EET 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
7 |
--------------------------------------------------------------------------------
/Library/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Sample/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Sample/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/Sample/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 160dp
5 |
6 | 16dp
7 | 16dp
8 | 16dp
9 |
10 |
--------------------------------------------------------------------------------
/Sample/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/Library/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/Library/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Sample/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Library/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Sample/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Sample/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
8 |
9 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Library/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/ybayram/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/Sample/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/ybayram/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/Library/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Sample/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Library/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 23
10 | versionCode 4
11 | versionName "1.1.2"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | repositories {
22 | maven {
23 | url "https://jitpack.io"
24 | }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | compile 'com.android.support:appcompat-v7:23.1.1'
30 | }
31 |
32 | apply from: '../maven_push.gradle'
--------------------------------------------------------------------------------
/Sample/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.yayandroid.rotatable.sample"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:23.1.1'
25 | compile 'com.android.support:design:23.1.1'
26 | compile 'com.yayandroid:Rotatable:1.1.1'
27 | }
28 |
--------------------------------------------------------------------------------
/Sample/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/Sample/app/src/main/java/com/yayandroid/rotatable/sample/LandingActivity.java:
--------------------------------------------------------------------------------
1 | package com.yayandroid.rotatable.sample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.View;
8 |
9 | /**
10 | * Created by Yahya Bayramoglu on 04/12/15.
11 | */
12 | public class LandingActivity extends AppCompatActivity {
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_landing);
18 | setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
19 | }
20 |
21 | public void touchSampleClick(View v) {
22 | startActivity(new Intent(this, TouchActivity.class));
23 | }
24 |
25 | public void animateSampleClick(View v) {
26 | startActivity(new Intent(this, AnimateActivity.class));
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/Sample/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Library/Library.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Sample/Sample.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Sample/TransitionSample.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Sample/app/src/main/res/menu/menu_rotation.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
12 |
13 |
14 |
17 |
21 |
25 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Sample/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Rotatable
3 |
4 | Rotation Direction
5 | Rotate X
6 | Rotate Y
7 | Rotate Both
8 | Touch Enabled
9 | Touch Disabled
10 |
11 | Touch Rotation
12 | Animate Rotation
13 |
14 | Count
15 | Distance
16 | Pivot X
17 | Pivot Y
18 |
19 | Build
20 | Reset
21 | Random Animate
22 |
23 | You cannot specify rotation count and distance together.
24 |
25 |
--------------------------------------------------------------------------------
/Sample/app/src/main/res/layout/activity_landing.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
23 |
24 |
28 |
29 |
33 |
34 |
38 |
39 |
--------------------------------------------------------------------------------
/Library/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | POM_NAME=Rotatable Library
21 | POM_ARTIFACT_ID=Rotatable
22 | POM_PACKAGING=aar
23 | VERSION_NAME=1.1.2
24 | VERSION_CODE=4
25 | GROUP=com.yayandroid
26 |
27 | POM_DESCRIPTION=Rotatable Library
28 | POM_URL=https://github.com/yayaa/Rotatable
29 | POM_SCM_URL=https://github.com/yayaa/Rotatable
30 | POM_SCM_CONNECTION=scm:https://github.com/yayaa/Rotatable.git
31 | POM_SCM_DEV_CONNECTION=scm:https://github.com/yayaa/Rotatable.git
32 | POM_LICENCE_NAME=MIT License
33 | POM_LICENCE_URL=http://www.opensource.org/licenses/mit-license.php
34 | POM_LICENCE_DIST=repo
35 | POM_DEVELOPER_ID=yayaa
36 | POM_DEVELOPER_NAME=Yahya BAYRAMOGLU
37 |
38 | SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots
39 | RELEASE_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2
--------------------------------------------------------------------------------
/Sample/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
22 |
23 |
32 |
33 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Sample/app/src/main/java/com/yayandroid/rotatable/sample/AnimateActivity.java:
--------------------------------------------------------------------------------
1 | package com.yayandroid.rotatable.sample;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.MenuItem;
8 |
9 | import com.yayandroid.rotatable.Rotatable;
10 |
11 | /**
12 | * Created by Yahya Bayramoglu on 04/12/15.
13 | */
14 | public class AnimateActivity extends AppCompatActivity {
15 |
16 | private Handler handler;
17 | private final int ANIM_DURATION = 5000;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_animate);
23 | setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
24 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
25 |
26 | handler = new Handler();
27 | runAnimationOn(R.id.view1, Rotatable.ROTATE_Y, 3600, 300);
28 | runAnimationOn(R.id.view4, Rotatable.ROTATE_Y, 3960, 600);
29 | runAnimationOn(R.id.view2, Rotatable.ROTATE_BOTH, 1440, 1200);
30 | runAnimationOn(R.id.view3, Rotatable.ROTATE_X, 2880, 900);
31 | }
32 |
33 | private void runAnimationOn(final int resId, final int direction, final int degree, int delay) {
34 | handler.postDelayed(new Runnable() {
35 | @Override
36 | public void run() {
37 | Rotatable rotatable = new Rotatable.Builder(findViewById(resId))
38 | .direction(Rotatable.ROTATE_BOTH)
39 | .build();
40 | rotatable.rotate(direction, degree, ANIM_DURATION);
41 | }
42 | }, delay);
43 | }
44 |
45 | @Override
46 | public boolean onOptionsItemSelected(MenuItem item) {
47 | if (item.getItemId() == android.R.id.home) {
48 | finish();
49 | return true;
50 | }
51 | return super.onOptionsItemSelected(item);
52 | }
53 | }
--------------------------------------------------------------------------------
/Sample/app/src/main/res/layout/activity_animate.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
22 |
23 |
24 |
25 |
30 |
31 |
35 |
36 |
41 |
42 |
47 |
48 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Sample/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Library/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/Sample/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/Library/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/Library/maven_push.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'maven'
18 | apply plugin: 'signing'
19 |
20 | def isReleaseBuild() {
21 | return VERSION_NAME.contains("SNAPSHOT") == false
22 | }
23 |
24 | def getReleaseRepositoryUrl() {
25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
27 | }
28 |
29 | def getSnapshotRepositoryUrl() {
30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
31 | : "https://oss.sonatype.org/content/repositories/snapshots/"
32 | }
33 |
34 | def getRepositoryUsername() {
35 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
36 | }
37 |
38 | def getRepositoryPassword() {
39 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
40 | }
41 |
42 | afterEvaluate { project ->
43 | uploadArchives {
44 | repositories {
45 | mavenDeployer {
46 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
47 |
48 | pom.groupId = GROUP
49 | pom.artifactId = POM_ARTIFACT_ID
50 | pom.version = VERSION_NAME
51 |
52 | repository(url: getReleaseRepositoryUrl()) {
53 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
54 | }
55 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
56 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
57 | }
58 |
59 | pom.project {
60 | name POM_NAME
61 | packaging POM_PACKAGING
62 | description POM_DESCRIPTION
63 | url POM_URL
64 |
65 | scm {
66 | url POM_SCM_URL
67 | connection POM_SCM_CONNECTION
68 | developerConnection POM_SCM_DEV_CONNECTION
69 | }
70 |
71 | licenses {
72 | license {
73 | name POM_LICENCE_NAME
74 | url POM_LICENCE_URL
75 | distribution POM_LICENCE_DIST
76 | }
77 | }
78 |
79 | developers {
80 | developer {
81 | id POM_DEVELOPER_ID
82 | name POM_DEVELOPER_NAME
83 | }
84 | }
85 | }
86 | }
87 | }
88 | }
89 |
90 | signing {
91 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
92 | sign configurations.archives
93 | }
94 |
95 | //task androidJavadocs(type: Javadoc) {
96 | //source = android.sourceSets.main.allJava
97 | //}
98 |
99 | //task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
100 | //classifier = 'javadoc'
101 | //from androidJavadocs.destinationDir
102 | //}
103 |
104 | task androidSourcesJar(type: Jar) {
105 | classifier = 'sources'
106 | from android.sourceSets.main.java.sourceFiles
107 | }
108 |
109 | artifacts {
110 | archives androidSourcesJar
111 | }
112 | }
--------------------------------------------------------------------------------
/Library/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/Sample/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/Sample/app/src/main/java/com/yayandroid/rotatable/sample/TouchActivity.java:
--------------------------------------------------------------------------------
1 | package com.yayandroid.rotatable.sample;
2 |
3 | import android.content.res.Configuration;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.text.TextUtils;
8 | import android.view.Menu;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 | import android.widget.EditText;
12 | import android.widget.Toast;
13 |
14 | import com.yayandroid.rotatable.Rotatable;
15 |
16 | import java.util.Random;
17 |
18 | /**
19 | * Created by Yahya Bayramoglu on 24/11/15.
20 | */
21 | public class TouchActivity extends AppCompatActivity {
22 |
23 | private Rotatable rotatable;
24 |
25 | private final int DEFAULT_ROTATION_ID = R.id.action_rotate_y;
26 | private int selectedRotationId = DEFAULT_ROTATION_ID;
27 |
28 | private EditText rotationCount, rotationDistance, pivotX, pivotY;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_touch);
34 | setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
35 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
36 |
37 | rotationCount = (EditText) findViewById(R.id.rotationCount);
38 | rotationDistance = (EditText) findViewById(R.id.rotationDistance);
39 | pivotX = (EditText) findViewById(R.id.rotationPivotX);
40 | pivotY = (EditText) findViewById(R.id.rotationPivotY);
41 | }
42 |
43 | public void buildClick(View v) {
44 | boolean countIsEmpty = TextUtils.isEmpty(rotationCount.getText());
45 | boolean distanceIsEmpty = TextUtils.isEmpty(rotationDistance.getText());
46 |
47 | if (!countIsEmpty && !distanceIsEmpty) {
48 | Toast.makeText(getApplicationContext(), R.string.toast_count_distance, Toast.LENGTH_SHORT).show();
49 | return;
50 | }
51 |
52 | Rotatable.Builder builder = new Rotatable.Builder(findViewById(R.id.targetView))
53 | .sides(R.id.frontView, R.id.backView)
54 | .direction(getRotationDirectionById(selectedRotationId))
55 | .listener(rotationListener);
56 |
57 | if (!countIsEmpty) {
58 | builder.rotationCount(Float.parseFloat(rotationCount.getText().toString()));
59 | }
60 |
61 | if (!distanceIsEmpty) {
62 | builder.rotationDistance(Float.parseFloat(rotationDistance.getText().toString()));
63 | }
64 |
65 | String pivotXValue = pivotX.getText().toString();
66 | if (!TextUtils.isEmpty(pivotXValue)) {
67 | builder.pivotX(Integer.parseInt(pivotXValue));
68 | }
69 |
70 | String pivotYValue = pivotY.getText().toString();
71 | if (!TextUtils.isEmpty(pivotYValue)) {
72 | builder.pivotY(Integer.parseInt(pivotYValue));
73 | }
74 |
75 | if (rotatable != null) {
76 | rotatable.drop();
77 | }
78 | rotatable = builder.build();
79 | }
80 |
81 | public void resetClick(View v) {
82 | rotationCount.setText("");
83 | rotationDistance.setText("");
84 | pivotX.setText("");
85 | pivotY.setText("");
86 | rotatable.drop();
87 | rotatable = null;
88 | }
89 |
90 | public void randomAnimateClick(View v) {
91 | if (rotatable != null) {
92 | rotatable.rotate(getRotationDirectionById(selectedRotationId), new Random().nextInt(360));
93 | }
94 | }
95 |
96 | private Rotatable.RotationListener rotationListener = new Rotatable.RotationListener() {
97 | @Override
98 | public void onRotationChanged(float newRotationX, float newRotationY) {
99 | setTitle("X: " + newRotationX + ", Y: " + newRotationY);
100 | }
101 | };
102 |
103 | private int getRotationDirectionById(int actionId) {
104 | switch (actionId) {
105 | case R.id.action_rotate_x:
106 | return Rotatable.ROTATE_X;
107 | case R.id.action_rotate_y:
108 | return Rotatable.ROTATE_Y;
109 | case R.id.action_rotate_both:
110 | return Rotatable.ROTATE_BOTH;
111 | default:
112 | // will crash!
113 | return -1;
114 | }
115 | }
116 |
117 | private boolean isTouchEnabled() {
118 | if (rotatable != null) {
119 | return rotatable.isTouchEnable();
120 | }
121 | return false;
122 | }
123 |
124 | @Override
125 | public void onConfigurationChanged(Configuration newConfig) {
126 | super.onConfigurationChanged(newConfig);
127 | if (rotatable != null) {
128 | rotatable.orientationChanged(newConfig.orientation);
129 | }
130 | }
131 |
132 | @Override
133 | public boolean onCreateOptionsMenu(Menu menu) {
134 | getMenuInflater().inflate(R.menu.menu_rotation, menu);
135 | return true;
136 | }
137 |
138 | @Override
139 | public boolean onPrepareOptionsMenu(Menu menu) {
140 | for (int i = 0; i < menu.size(); i++) {
141 | MenuItem item = menu.getItem(i);
142 | if (item.isCheckable()) {
143 | if (item.getItemId() == R.id.action_touch) {
144 | item.setTitle(isTouchEnabled() ? R.string.action_touch_enabled : R.string.action_touch_disabled);
145 | item.setChecked(isTouchEnabled());
146 | } else {
147 | item.setChecked(item.getItemId() == selectedRotationId);
148 | }
149 | }
150 | }
151 | return super.onPrepareOptionsMenu(menu);
152 | }
153 |
154 | @Override
155 | public boolean onOptionsItemSelected(MenuItem item) {
156 | int menuItemId = item.getItemId();
157 | switch (menuItemId) {
158 | case android.R.id.home: {
159 | finish();
160 | return true;
161 | }
162 | case R.id.action_rotate_x:
163 | case R.id.action_rotate_y:
164 | case R.id.action_rotate_both: {
165 | selectedRotationId = menuItemId;
166 | if (rotatable != null) {
167 | rotatable.setDirection(getRotationDirectionById(selectedRotationId));
168 | }
169 | return true;
170 | }
171 | case R.id.action_touch: {
172 | if (rotatable != null) {
173 | rotatable.setTouchEnable(!rotatable.isTouchEnable());
174 | }
175 | return true;
176 | }
177 | }
178 | return super.onOptionsItemSelected(item);
179 | }
180 | }
--------------------------------------------------------------------------------
/Library/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Rotatable
2 | =========
3 |
4 |
5 |
6 |
7 | 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.
8 |
9 | Sample Video
10 | ============
11 | [](https://www.youtube.com/watch?v=Gkd9QpAZmU8)
12 |
13 | # Usage
14 |
15 | 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.
16 |
17 | ```java
18 | Rotatable rotatable = new Rotatable.Builder(findViewById(R.id.targetView))
19 | .sides(R.id.frontView, R.id.backView)
20 | .direction(Rotatable.ROTATE_X)
21 | .listener(rotationListener)
22 | .rotationCount(floatValue)
23 | .rotataionDistance(floatValue)
24 | .pivotX(intValue)
25 | .pivotY(intValue)
26 | .build();
27 | ```
28 |
29 | **Rotatable.Builder**
30 |
31 | ```java
32 | sides(int frontViewResId, int backViewResId)
33 | ```
34 | 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.
35 |
36 |
37 | ```java
38 | rotationCount(float count)
39 | ```
40 |
41 | 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.
42 |
43 |
44 | ```java
45 | rotataionDistance(float distance)
46 | ```
47 |
48 | 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.
49 |
50 |
51 | ```java
52 | pivotX(int pivotXValue)
53 | pivotY(int pivotYValue)
54 | // or
55 | pivot(int pivotXValue, int pivotYValue)
56 | ```
57 |
58 | 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.
59 |
60 | 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.
61 |
62 |
63 | **Rotatable Object**
64 |
65 | 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:
66 |
67 | ```java
68 | rotatable.rotate(int direction, float degree, int duration, Animator.AnimatorListener listener)
69 | ```
70 |
71 | 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.
72 |
73 |
74 | ```java
75 | rotatable.setTouchEnable(boolean enable)
76 | rotatable.isTouchEnable()
77 | ```
78 |
79 | You can enable / disable touch events or check whether touch is enable on rotatable object or not at anytime.
80 |
81 |
82 | ```java
83 | rotatable.setDirection(int direction)
84 | ```
85 |
86 | 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
87 |
88 |
89 | ```java
90 | rotatable.orientationChanged(int newOrientation)
91 | ```
92 |
93 | 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.
94 |
95 |
96 | ```java
97 | rotatable.drop()
98 | ```
99 |
100 | 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.
101 |
102 |
103 | ```java
104 | rotatable.takeAttention()
105 | ```
106 |
107 | 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 :)
108 |
109 |
110 | ## Download
111 | Add library dependency to your `build.gradle` file:
112 |
113 | ```groovy
114 | dependencies {
115 | compile 'com.yayandroid:Rotatable:1.1.2'
116 | }
117 | ```
118 |
119 | ## License
120 | ```
121 | The MIT License (MIT)
122 |
123 | Copyright (c) 2015 yayandroid
124 |
125 | Permission is hereby granted, free of charge, to any person obtaining a copy
126 | of this software and associated documentation files (the "Software"), to deal
127 | in the Software without restriction, including without limitation the rights
128 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
129 | copies of the Software, and to permit persons to whom the Software is
130 | furnished to do so, subject to the following conditions:
131 |
132 | The above copyright notice and this permission notice shall be included in
133 | all copies or substantial portions of the Software.
134 |
135 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
136 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
137 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
138 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
139 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
140 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
141 | THE SOFTWARE.
142 | ```
143 |
144 | [1]: http://stackoverflow.com/a/7366101/1171484
145 |
--------------------------------------------------------------------------------
/Sample/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/Sample/app/src/main/res/layout/activity_touch.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
20 |
21 |
22 |
23 |
29 |
30 |
37 |
38 |
45 |
46 |
54 |
55 |
56 |
65 |
66 |
71 |
72 |
76 |
77 |
84 |
85 |
86 |
87 |
95 |
96 |
100 |
101 |
108 |
109 |
110 |
111 |
112 |
117 |
118 |
122 |
123 |
130 |
131 |
132 |
133 |
141 |
142 |
146 |
147 |
154 |
155 |
156 |
157 |
158 |
163 |
164 |
173 |
174 |
183 |
184 |
185 |
193 |
194 |
195 |
196 |
197 |
198 |
--------------------------------------------------------------------------------
/Library/app/src/main/java/com/yayandroid/rotatable/Rotatable.java:
--------------------------------------------------------------------------------
1 | package com.yayandroid.rotatable;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.AnimatorSet;
6 | import android.animation.ObjectAnimator;
7 | import android.animation.ValueAnimator;
8 | import android.content.Context;
9 | import android.content.res.Configuration;
10 | import android.support.annotation.IntDef;
11 | import android.support.v4.view.animation.FastOutSlowInInterpolator;
12 | import android.util.DisplayMetrics;
13 | import android.util.Property;
14 | import android.view.Display;
15 | import android.view.MotionEvent;
16 | import android.view.View;
17 | import android.view.WindowManager;
18 | import android.view.animation.CycleInterpolator;
19 |
20 | import java.util.ArrayList;
21 |
22 | /**
23 | * Created by Yahya Bayramoglu on 01/12/15.
24 | */
25 | public class Rotatable implements View.OnTouchListener {
26 |
27 | private static final int NULL_INT = -1;
28 | private final int FIT_ANIM_TIME = 300;
29 |
30 | public static final int DEFAULT_ROTATE_ANIM_TIME = 500;
31 | public static final int ROTATE_BOTH = 0;
32 | public static final int ROTATE_X = 1;
33 | public static final int ROTATE_Y = 2;
34 |
35 | @IntDef({ROTATE_X, ROTATE_Y, ROTATE_BOTH})
36 | public @interface Direction {
37 | }
38 |
39 | public static final int FRONT_VIEW = 3;
40 | public static final int BACK_VIEW = 4;
41 |
42 | @IntDef({FRONT_VIEW, BACK_VIEW})
43 | public @interface Side {
44 | }
45 |
46 | private RotationListener rotationListener;
47 | private View rootView, frontView, backView;
48 |
49 | private boolean touchEnable = true;
50 | private boolean shouldSwapViews = false;
51 |
52 | private int rotation;
53 | private int screenWidth = NULL_INT, screenHeight = NULL_INT;
54 | private int currentVisibleView = FRONT_VIEW;
55 |
56 | private float rotationCount;
57 | private float rotationDistance;
58 | private float oldX, oldY, currentX, currentY;
59 | private float currentXRotation = 0, currentYRotation = 0;
60 | private float maxDistanceX = NULL_INT, maxDistanceY = NULL_INT;
61 | private float defaultPivotX = NULL_INT, defaultPivotY = NULL_INT;
62 |
63 | private Rotatable(Builder builder) {
64 | this.rootView = builder.root;
65 | this.defaultPivotX = rootView.getPivotX();
66 | this.defaultPivotY = rootView.getPivotY();
67 | this.rotationListener = builder.listener;
68 |
69 | if (builder.pivotX != NULL_INT) {
70 | this.rootView.setPivotX(builder.pivotX);
71 | }
72 |
73 | if (builder.pivotY != NULL_INT) {
74 | this.rootView.setPivotY(builder.pivotY);
75 | }
76 |
77 | if (builder.frontId != NULL_INT) {
78 | this.frontView = rootView.findViewById(builder.frontId);
79 | }
80 |
81 | if (builder.backId != NULL_INT) {
82 | this.backView = rootView.findViewById(builder.backId);
83 | }
84 |
85 | this.rotation = builder.rotation;
86 | this.rotationCount = builder.rotationCount;
87 | this.rotationDistance = builder.rotationDistance;
88 | this.shouldSwapViews = frontView != null && backView != null;
89 |
90 | rootView.setOnTouchListener(this);
91 | }
92 |
93 | /**
94 | * This method needs to be call, if only you need to reset and
95 | * rebuild a view as rotatable with different configurations
96 | */
97 | public void drop() {
98 | rootView.setPivotX(defaultPivotX);
99 | rootView.setPivotY(defaultPivotY);
100 | rootView.setOnTouchListener(null);
101 | rootView = null;
102 | frontView = null;
103 | backView = null;
104 | }
105 |
106 | /**
107 | * You can specify rotation direction as axis X, Y or BOTH
108 | */
109 | public void setDirection(@Direction int direction) {
110 | if (!isRotationValid(direction)) {
111 | throw new IllegalArgumentException("Cannot specify given value as rotation direction!");
112 | }
113 | this.rotation = direction;
114 | }
115 |
116 | /**
117 | * You may need to enable / disable touch interaction at some point,
118 | * so it is possible to do it so anytime by rotatable object
119 | */
120 | public void setTouchEnable(boolean enable) {
121 | this.touchEnable = enable;
122 | }
123 |
124 | /**
125 | * To determine rotatable object is currently touchable or not
126 | */
127 | public boolean isTouchEnable() {
128 | return touchEnable;
129 | }
130 |
131 | /**
132 | * If your application can be used multi orientated, then you have to declare
133 | * orientation changes to rotatable object, so it can recalculate its maxDistances.
134 | *
135 | * You only need to inform rotatable object about orientation changes, when you specified
136 | * {@link Builder#rotationCount(float)} or {@link Builder#rotationDistance(float)}
137 | */
138 | public void orientationChanged(int newOrientation) {
139 | if (screenWidth == NULL_INT) {
140 | calculateScreenDimensions();
141 | }
142 | measureScreenUpToOrientation(newOrientation);
143 |
144 | // reset maxDistances values to recalculate them
145 | maxDistanceX = NULL_INT;
146 | maxDistanceY = NULL_INT;
147 | }
148 |
149 | /**
150 | * Call this method to reveal rotatable view's existence
151 | */
152 | public void takeAttention() {
153 | ObjectAnimator animatorX = ObjectAnimator.ofFloat(rootView, View.ROTATION_X, 10);
154 | ObjectAnimator animatorY = ObjectAnimator.ofFloat(rootView, View.ROTATION_Y, -10);
155 | AnimatorSet set = new AnimatorSet();
156 | set.setDuration(DEFAULT_ROTATE_ANIM_TIME);
157 | set.setInterpolator(new CycleInterpolator(0.8f));
158 | set.addListener(new AnimatorListenerAdapter() {
159 | @Override
160 | public void onAnimationEnd(Animator animation) {
161 | super.onAnimationEnd(animation);
162 |
163 | rootView.animate().rotationX(0).rotationY(0).setDuration(FIT_ANIM_TIME)
164 | .setInterpolator(new FastOutSlowInInterpolator()).start();
165 | }
166 | });
167 | set.playTogether(animatorX, animatorY);
168 | set.start();
169 | }
170 |
171 | /**
172 | * Animate rotatable object with given direction and degree also possible
173 | * to set duration and a listener with other derivation of this method
174 | */
175 | public void rotate(int direction, float degree) {
176 | rotate(direction, degree, DEFAULT_ROTATE_ANIM_TIME);
177 | }
178 |
179 | public void rotate(int direction, float degree, int duration) {
180 | rotate(direction, degree, duration, null);
181 | }
182 |
183 | public void rotate(final int direction, float degree, int duration, Animator.AnimatorListener listener) {
184 | AnimatorSet animatorSet = new AnimatorSet();
185 | animatorSet.setDuration(duration);
186 | animatorSet.setInterpolator(new FastOutSlowInInterpolator());
187 |
188 | ArrayList animators = new ArrayList<>();
189 |
190 | if (direction == ROTATE_X || direction == ROTATE_BOTH) {
191 | animators.add(getAnimatorForProperty(View.ROTATION_X, direction, degree));
192 | }
193 |
194 | if (direction == ROTATE_Y || direction == ROTATE_BOTH) {
195 | animators.add(getAnimatorForProperty(View.ROTATION_Y, direction, degree));
196 | }
197 |
198 | if (listener != null) {
199 | animatorSet.addListener(listener);
200 | }
201 |
202 | animatorSet.addListener(new AnimatorListenerAdapter() {
203 | @Override
204 | public void onAnimationEnd(Animator animation) {
205 | super.onAnimationEnd(animation);
206 | updateRotationValues(true);
207 | }
208 | });
209 |
210 | animatorSet.playTogether(animators);
211 | animatorSet.start();
212 | }
213 |
214 | /**
215 | * Rotates once around in given direction
216 | */
217 | public void rotateOnce() {
218 | float toDegree;
219 | if (rotation == ROTATE_X) {
220 | toDegree = rootView.getRotationX();
221 | } else if (rotation == ROTATE_Y) {
222 | toDegree = rootView.getRotationY();
223 | } else {
224 | toDegree = rootView.getRotation();
225 | }
226 | toDegree += 180;
227 | rotate(rotation, toDegree);
228 | }
229 |
230 | /**
231 | * Returns true if currently frontView is visible, false otherwise
232 | */
233 | public boolean isFront() {
234 | return getCurrentVisibleView() == FRONT_VIEW;
235 | }
236 |
237 | /**
238 | * Returns currentVisibleView value as {@link Rotatable.Side}
239 | */
240 | public
241 | @Side
242 | int getCurrentVisibleView() {
243 | return currentVisibleView;
244 | }
245 |
246 | public float getCurrentXRotation() {
247 | return currentXRotation;
248 | }
249 |
250 | public float getCurrentYRotation() {
251 | return currentYRotation;
252 | }
253 |
254 | private Animator getAnimatorForProperty(Property property, final int direction, float degree) {
255 | ObjectAnimator animator = ObjectAnimator.ofFloat(rootView, property, degree);
256 |
257 | if (shouldSwapViews) {
258 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
259 | @Override
260 | public void onAnimationUpdate(ValueAnimator animation) {
261 | updateRotationValues(false);
262 | swapViews(direction);
263 | }
264 | });
265 | }
266 | return animator;
267 | }
268 |
269 | private void updateRotationValues(boolean notifyListener) {
270 | currentXRotation = rootView.getRotationX();
271 | currentYRotation = rootView.getRotationY();
272 |
273 | if (notifyListener) {
274 | notifyListenerRotationChanged();
275 | }
276 | }
277 |
278 | @Override
279 | public boolean onTouch(View v, MotionEvent event) {
280 | if (touchEnable) {
281 | switch (event.getAction()) {
282 | case MotionEvent.ACTION_DOWN: {
283 | restoreOldPositions(event);
284 | break;
285 | }
286 | case MotionEvent.ACTION_MOVE: {
287 | restoreNewPositions(event);
288 | handleRotation();
289 |
290 | if (shouldSwapViews) {
291 | swapViews(rotation);
292 | }
293 | notifyListenerRotationChanged();
294 | break;
295 | }
296 | case MotionEvent.ACTION_CANCEL:
297 | case MotionEvent.ACTION_UP: {
298 | fitRotation();
299 | break;
300 | }
301 | }
302 | return true;
303 | } else {
304 | return false;
305 | }
306 | }
307 |
308 | private void restoreOldPositions(MotionEvent event) {
309 | if (shouldRotateX()) {
310 | oldY = getYValue(event.getRawY());
311 | }
312 |
313 | if (shouldRotateY()) {
314 | oldX = getXValue(event.getRawX());
315 | }
316 | }
317 |
318 | private float getXValue(float rawX) {
319 | if (rotationCount != NULL_INT && maxDistanceX != NULL_INT) {
320 | return rawX * rotationCount * 180 / maxDistanceX;
321 | }
322 |
323 | if (rotationDistance != NULL_INT) {
324 | return rawX * 180 / rotationDistance;
325 | }
326 |
327 | return rawX;
328 | }
329 |
330 | private float getYValue(float rawY) {
331 | if (rotationCount != NULL_INT && maxDistanceY != NULL_INT) {
332 | return rawY * rotationCount * 180 / maxDistanceY;
333 | }
334 |
335 | if (rotationDistance != NULL_INT) {
336 | return rawY * 180 / rotationDistance;
337 | }
338 |
339 | return rawY;
340 | }
341 |
342 | private void restoreNewPositions(MotionEvent event) {
343 | if (shouldRotateX()) {
344 | if (rotationCount != NULL_INT && maxDistanceY == NULL_INT) {
345 | maxDistanceY = (event.getRawY() - oldY) > 0 ? (getScreenHeight() - oldY) : oldY;
346 | oldY = getYValue(oldY);
347 | }
348 | currentY = getYValue(event.getRawY());
349 | }
350 |
351 | if (shouldRotateY()) {
352 | if (rotationCount != NULL_INT && maxDistanceX == NULL_INT) {
353 | maxDistanceX = (event.getRawX() - oldX) > 0 ? (getScreenWidth() - oldX) : oldX;
354 | oldX = getXValue(oldX);
355 | }
356 | currentX = getXValue(event.getRawX());
357 | }
358 | }
359 |
360 | private int getScreenWidth() {
361 | if (screenWidth == NULL_INT) {
362 | calculateScreenDimensions();
363 | }
364 | return screenWidth;
365 | }
366 |
367 | private int getScreenHeight() {
368 | if (screenHeight == NULL_INT) {
369 | calculateScreenDimensions();
370 | }
371 | return screenHeight;
372 | }
373 |
374 | private void calculateScreenDimensions() {
375 | Display display = ((WindowManager) rootView.getContext()
376 | .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
377 | DisplayMetrics metrics = new DisplayMetrics();
378 | display.getMetrics(metrics);
379 | screenWidth = metrics.widthPixels;
380 | screenHeight = metrics.heightPixels;
381 | }
382 |
383 | private void measureScreenUpToOrientation(int screenOrientation) {
384 | int tempWidth = screenWidth, tempHeight = screenHeight;
385 | if (screenOrientation == Configuration.ORIENTATION_LANDSCAPE) {
386 | /**
387 | * If screenOrientation is landscape, then width will have a larger value than height
388 | */
389 | screenWidth = Math.max(tempWidth, tempHeight);
390 | screenHeight = Math.min(tempWidth, tempHeight);
391 | } else {
392 | /**
393 | * If screenOrientation:
394 | * is portrait, then width will have a smaller value than height
395 | * is square, then width and height will be same
396 | * is unknown, then unknown to rotatable as well
397 | * so either way...
398 | */
399 | screenWidth = Math.min(tempWidth, tempHeight);
400 | screenHeight = Math.max(tempWidth, tempHeight);
401 | }
402 | }
403 |
404 | private boolean shouldRotateX() {
405 | return rotation == ROTATE_X || rotation == ROTATE_BOTH;
406 | }
407 |
408 | private boolean shouldRotateY() {
409 | return rotation == ROTATE_Y || rotation == ROTATE_BOTH;
410 | }
411 |
412 | private void handleRotation() {
413 | if (shouldRotateX()) {
414 | float newXRotation = (rootView.getRotationX() + (oldY - currentY)) % 360;
415 | rootView.setRotationX(newXRotation);
416 | currentXRotation = newXRotation;
417 | oldY = currentY;
418 | }
419 |
420 | if (shouldRotateY()) {
421 | float newYRotation;
422 | if (isInFrontArea(currentXRotation)) {
423 | newYRotation = (rootView.getRotationY() + (currentX - oldX)) % 360;
424 | } else {
425 | newYRotation = (rootView.getRotationY() - (currentX - oldX)) % 360;
426 | }
427 |
428 | rootView.setRotationY(newYRotation);
429 | currentYRotation = newYRotation;
430 | oldX = currentX;
431 | }
432 | }
433 |
434 | private boolean isInFrontArea(float value) {
435 | return (-270 >= value && value >= -360)
436 | || (-90 <= value && value <= 90)
437 | || (270 <= value && value <= 360);
438 | }
439 |
440 | private void swapViews(int rotation) {
441 | boolean isFront = false;
442 | if (rotation == ROTATE_Y) {
443 | isFront = isInFrontArea(currentYRotation);
444 |
445 | if (!isInFrontArea(currentXRotation)) {
446 | isFront = !isFront;
447 | }
448 | }
449 |
450 | if (rotation == ROTATE_X) {
451 | isFront = isInFrontArea(currentXRotation);
452 |
453 | if (!isInFrontArea(currentYRotation)) {
454 | isFront = !isFront;
455 | }
456 | }
457 |
458 | if (rotation == ROTATE_BOTH) {
459 | isFront = (currentXRotation > -90 && currentXRotation < 90) && (currentYRotation > -90 && currentYRotation < 90)
460 |
461 | || (currentXRotation > -90 && currentXRotation < 90) && (currentYRotation > -360 && currentYRotation < -270)
462 | || (currentXRotation > -360 && currentXRotation < -270) && (currentYRotation > -90 && currentYRotation < 90)
463 |
464 | || (currentXRotation > -90 && currentXRotation < 90) && (currentYRotation > 270 && currentYRotation < 360)
465 | || (currentXRotation > 270 && currentXRotation < 360) && (currentYRotation > -90 && currentYRotation < 90)
466 |
467 | || (currentXRotation > 90 && currentXRotation < 270) && (currentYRotation > -270 && currentYRotation < -90)
468 | || (currentXRotation > -270 && currentXRotation < -90) && (currentYRotation > 90 && currentYRotation < 270)
469 |
470 | || (currentXRotation > 90 && currentXRotation < 270) && (currentYRotation > 90 && currentYRotation < 270)
471 | || (currentXRotation > -270 && currentXRotation < -90) && (currentYRotation > -270 && currentYRotation < -90);
472 | }
473 |
474 | boolean shouldSwap = (isFront && currentVisibleView == BACK_VIEW) || (!isFront && currentVisibleView == FRONT_VIEW);
475 | if (shouldSwap) {
476 | frontView.setVisibility(isFront ? View.VISIBLE : View.GONE);
477 | backView.setVisibility(isFront ? View.GONE : View.VISIBLE);
478 | currentVisibleView = isFront ? FRONT_VIEW : BACK_VIEW;
479 | }
480 | }
481 |
482 | private void notifyListenerRotationChanged() {
483 | if (rotationListener != null) {
484 | rotationListener.onRotationChanged(currentXRotation, currentYRotation);
485 | }
486 | }
487 |
488 | private void fitRotation() {
489 | AnimatorSet animatorSet = new AnimatorSet();
490 | animatorSet.setDuration(FIT_ANIM_TIME);
491 | animatorSet.setInterpolator(new FastOutSlowInInterpolator());
492 |
493 | ArrayList animators = new ArrayList<>();
494 |
495 | if (shouldRotateY()) {
496 | animators.add(ObjectAnimator.ofFloat(rootView, View.ROTATION_Y, getRequiredRotation(rootView.getRotationY())));
497 | }
498 |
499 | if (shouldRotateX()) {
500 | animators.add(ObjectAnimator.ofFloat(rootView, View.ROTATION_X, getRequiredRotation(rootView.getRotationX())));
501 | }
502 |
503 | animatorSet.playTogether(animators);
504 | animatorSet.addListener(new AnimatorListenerAdapter() {
505 | @Override
506 | public void onAnimationEnd(Animator animation) {
507 | super.onAnimationEnd(animation);
508 | updateRotationValues(true);
509 | }
510 | });
511 | animatorSet.start();
512 |
513 | // Reset max values to calculate again on touch down
514 | maxDistanceX = NULL_INT;
515 | maxDistanceY = NULL_INT;
516 | }
517 |
518 | private float getRequiredRotation(float currentRotation) {
519 | float requiredRotation;
520 | if (currentRotation < -270) {
521 | requiredRotation = -360;
522 | } else if (currentRotation < -90 && currentRotation > -270) {
523 | requiredRotation = -180;
524 | } else if (currentRotation > -90 && currentRotation < 90) {
525 | requiredRotation = 0;
526 | } else if (currentRotation > 90 && currentRotation < 270) {
527 | requiredRotation = 180;
528 | } else {
529 | requiredRotation = 360;
530 | }
531 | return requiredRotation;
532 | }
533 |
534 | /**
535 | * Listener to get notified whenever view's rotation is changed
536 | */
537 | public interface RotationListener {
538 | void onRotationChanged(float newRotationX, float newRotationY);
539 | }
540 |
541 | public static class Builder {
542 |
543 | private View root;
544 | private RotationListener listener;
545 | private int rotation = NULL_INT;
546 | private int frontId = NULL_INT;
547 | private int backId = NULL_INT;
548 | private int pivotX = NULL_INT;
549 | private int pivotY = NULL_INT;
550 | private float rotationCount = NULL_INT;
551 | private float rotationDistance = NULL_INT;
552 |
553 | public Builder(View viewToRotate) {
554 | this.root = viewToRotate;
555 | }
556 |
557 | /**
558 | * This listener will receive current rotation values of given view
559 | */
560 | public Builder listener(RotationListener listener) {
561 | this.listener = listener;
562 | return this;
563 | }
564 |
565 | /**
566 | * Declaring sides will provide swapping between them when necessary,
567 | * if not declared, then rootView will be rotating by itself without any other effect
568 | */
569 | public Builder sides(int frontViewId, int backViewId) {
570 | this.frontId = frontViewId;
571 | this.backId = backViewId;
572 | return this;
573 | }
574 |
575 | /**
576 | * Specify an axis or both axises to rotate around
577 | */
578 | public Builder direction(@Direction int rotation) {
579 | this.rotation = rotation;
580 | return this;
581 | }
582 |
583 | /**
584 | * This method provides view to rotate only as given rotation count,
585 | * irrelevant to its position or touch distance
586 | */
587 | public Builder rotationCount(float count) {
588 | if (rotationDistance != NULL_INT) {
589 | throw new IllegalArgumentException("You cannot specify both distance and count for rotation limitation.");
590 | }
591 |
592 | this.rotationCount = count;
593 | return this;
594 | }
595 |
596 | /**
597 | * This method provides view to rotate once in given distance,
598 | * note that it won't rotate full if touch distance is not enough
599 | * but it may still fit the rotation. If you want to ensure rotation gets completed
600 | * see {@link #rotationCount(float}
601 | */
602 | public Builder rotationDistance(float distance) {
603 | if (rotationCount != NULL_INT) {
604 | throw new IllegalArgumentException("You cannot specify both distance and count for rotation limitation.");
605 | }
606 |
607 | this.rotationDistance = distance;
608 | return this;
609 | }
610 |
611 | /**
612 | * Consider not to change pivot values because view may out of its bounders and get invisible.
613 | */
614 | public Builder pivot(int pivotX, int pivotY) {
615 | this.pivotX = pivotX;
616 | this.pivotY = pivotY;
617 | return this;
618 | }
619 |
620 | /**
621 | * Consider not to change pivot values because view may out of its bounders and get invisible.
622 | */
623 | public Builder pivotX(int pivotX) {
624 | this.pivotX = pivotX;
625 | return this;
626 | }
627 |
628 | /**
629 | * Consider not to change pivot values because view may out of its bounders and get invisible.
630 | */
631 | public Builder pivotY(int pivotY) {
632 | this.pivotY = pivotY;
633 | return this;
634 | }
635 |
636 | public Rotatable build() {
637 | if (rotation == NULL_INT || !isRotationValid(rotation)) {
638 | throw new IllegalArgumentException("You must specify a direction!");
639 | }
640 | return new Rotatable(this);
641 | }
642 |
643 | }
644 |
645 | private static boolean isRotationValid(int value) {
646 | return value == ROTATE_X || value == ROTATE_Y || value == ROTATE_BOTH;
647 | }
648 |
649 | }
--------------------------------------------------------------------------------