From e324e8f54569785908bd3c43e775bf42f1642a94 Mon Sep 17 00:00:00 2001
From: Iiro <iiro.krankka@gmail.com>
Date: Tue, 1 Mar 2016 23:36:35 +0200
Subject: [PATCH] Compatibility to API Level 8 by using different animations
 for different system versions.

---
 .idea/gradle.xml                                   |  2 +-
 .idea/misc.xml                                     |  2 +-
 .idea/vcs.xml                                      |  2 +-
 sample/sample.iml                                  |  4 +--
 .../com/roughike/swipeselector/SwipeAdapter.java   | 30 ++++++++++++----------
 swipe-selector/swipe-selector.iml                  |  7 +++--
 6 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 66cc4b7..3ee4ec8 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -6,7 +6,7 @@
         <option name="distributionType" value="LOCAL" />
         <option name="externalProjectPath" value="$PROJECT_DIR$" />
         <option name="gradleHome" value="F:\Program Files\Android\Android Studio\gradle\gradle-2.8" />
-        <option name="gradleJvm" value="1.8" />
+        <option name="gradleJvm" value="1.7" />
         <option name="modules">
           <set>
             <option value="$PROJECT_DIR$" />
diff --git a/.idea/misc.xml b/.idea/misc.xml
index fbb6828..1a3eaff 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
     <ConfirmationsSetting value="0" id="Add" />
     <ConfirmationsSetting value="0" id="Remove" />
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 6564d52..35eb1dd 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="VcsDirectoryMappings">
-    <mapping directory="" vcs="" />
+    <mapping directory="" vcs="Git" />
   </component>
 </project>
\ No newline at end of file
diff --git a/sample/sample.iml b/sample/sample.iml
index f4f73e2..78f5648 100644
--- a/sample/sample.iml
+++ b/sample/sample.iml
@@ -81,11 +81,11 @@
     </content>
     <orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" exported="" name="animated-vector-drawable-23.2.0" level="project" />
     <orderEntry type="library" exported="" name="support-v4-23.2.0" level="project" />
     <orderEntry type="library" exported="" name="support-annotations-23.2.0" level="project" />
-    <orderEntry type="library" exported="" name="appcompat-v7-23.2.0" level="project" />
-    <orderEntry type="library" exported="" name="animated-vector-drawable-23.2.0" level="project" />
     <orderEntry type="library" exported="" name="support-vector-drawable-23.2.0" level="project" />
+    <orderEntry type="library" exported="" name="appcompat-v7-23.2.0" level="project" />
     <orderEntry type="module" module-name="swipe-selector" exported="" />
   </component>
 </module>
\ No newline at end of file
diff --git a/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java b/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
index 919a812..90ee99b 100644
--- a/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
+++ b/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
@@ -1,5 +1,7 @@
 package com.roughike.swipeselector;
 
+import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
 import android.content.Context;
 import android.graphics.Typeface;
 import android.graphics.drawable.ShapeDrawable;
@@ -121,7 +123,7 @@ private SwipeAdapter(ViewPager viewPager, ViewGroup indicatorContainer, int indi
      * Using the Java Builder Pattern here, because the SwipeSelector class was getting
      * messy and that's where most will look at. This class is protected, and contains no
      * methods that the users can use, so it's OK for this to look like absolute vomit.
-     *
+     * <p/>
      * At least that's my opinion. But my opinions are always right.
      */
     protected static class Builder {
@@ -144,7 +146,8 @@ private SwipeAdapter(ViewPager viewPager, ViewGroup indicatorContainer, int indi
         private int descriptionTextAppearance;
         private int descriptionGravity;
 
-        protected Builder(){}
+        protected Builder() {
+        }
 
         protected Builder viewPager(ViewPager viewPager) {
             this.viewPager = viewPager;
@@ -336,7 +339,7 @@ public void destroyItem(ViewGroup container, int position, Object object) {
 
     @Override
     public int getCount() {
-        return mItems != null? mItems.size() : 0;
+        return mItems != null ? mItems.size() : 0;
     }
 
     @Override
@@ -423,16 +426,16 @@ private int getGravity(int gravity) {
         int realGravityValue;
 
         switch (gravity) {
-            case 0 :
+            case 0:
                 realGravityValue = Gravity.START;
                 break;
-            case 1 :
+            case 1:
                 realGravityValue = Gravity.CENTER_HORIZONTAL;
                 break;
-            case 2 :
+            case 2:
                 realGravityValue = Gravity.END;
                 break;
-            default :
+            default:
                 throw new IllegalArgumentException("Invalid value " +
                         "specified for swipe_descriptionGravity. " +
                         "Use \"left\", \"center\", \"right\" or leave " +
@@ -473,9 +476,10 @@ private void animate(float alpha, ImageView button) {
                     .setDuration(120)
                     .start();
         } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
-            button.animate()
-                    .alpha(alpha)
-                    .setDuration(120);
+            ObjectAnimator.ofFloat(button, "alpha",
+                    alpha == 1 ? 0 : alpha, alpha == 1 ? alpha : 0)
+                    .setDuration(120)
+                    .start();
         } else {
             setAlpha(alpha, button);
         }
@@ -483,10 +487,10 @@ private void animate(float alpha, ImageView button) {
 
     @SuppressWarnings("deprecation")
     private void setAlpha(float alpha, ImageView button) {
-        if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
+        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
             button.setAlpha(alpha);
-        else {
-            button.setAlpha((int) (alpha*255));
+        } else {
+            button.setAlpha((int) (alpha * 255));
         }
     }
 }
diff --git a/swipe-selector/swipe-selector.iml b/swipe-selector/swipe-selector.iml
index c17888b..4dcd08c 100644
--- a/swipe-selector/swipe-selector.iml
+++ b/swipe-selector/swipe-selector.iml
@@ -65,6 +65,7 @@
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/docs" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
@@ -82,15 +83,17 @@
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
+      <excludeFolder url="file://$MODULE_DIR$/build/libs" />
       <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/poms" />
       <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
     </content>
     <orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" exported="" name="animated-vector-drawable-23.2.0" level="project" />
     <orderEntry type="library" exported="" name="support-v4-23.2.0" level="project" />
     <orderEntry type="library" exported="" name="support-annotations-23.2.0" level="project" />
-    <orderEntry type="library" exported="" name="appcompat-v7-23.2.0" level="project" />
-    <orderEntry type="library" exported="" name="animated-vector-drawable-23.2.0" level="project" />
     <orderEntry type="library" exported="" name="support-vector-drawable-23.2.0" level="project" />
+    <orderEntry type="library" exported="" name="appcompat-v7-23.2.0" level="project" />
   </component>
 </module>
\ No newline at end of file
