Skip to content

Commit

Permalink
library和sample拆分,library用java语言重写,library回归用support包
Browse files Browse the repository at this point in the history
  • Loading branch information
lilei committed Feb 19, 2019
1 parent b44ef0c commit 793b033
Show file tree
Hide file tree
Showing 55 changed files with 4,472 additions and 11 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,32 @@
### 绑定RecyclerView

```Kotlin
mCardLayoutHelper = CardLayoutHelper()
mCardLayoutHelper = CardLayoutHelper<T>()
mCardLayoutHelper.attachToRecyclerView(recycler_view)
```
### 绑定数据源List

```Kotlin
mCardLayoutHelper.bindDataSource(object : CardLayoutHelper.BindDataSource{
override fun bind(): List<Any> {
return list
}
})
mCardLayoutHelper.bindDataSource(object : CardLayoutHelper.BindDataSource<T> {
override fun bind(): List<T> {
return list
}
})
```
绑定数据源采用回调接口形式,需要返回绑定的RecyclerView对应Adapter下的数据源List


### 卡片参数配置

```Kotlin
mCardLayoutHelper.setConfig(CardLayoutHelper.Config(maxCount = 2,offset = 12.dp,duration = 300,swipeThreshold = 0.4f))
mCardLayoutHelper.setConfig(CardLayoutHelper.Config().setCardCount(2).setMaxRotation(20f))
```
CardLayoutHelper.Config接受参数配置,主要参数含义:
- maxCount //卡片布局最多包含卡片个数,默认是2个
- cardCount //卡片布局最多包含卡片个数,默认是2个
- offset //卡片之间的偏移量,单位是像素
- duration //卡片动画执行时间
- swipeThreshold //拖拽卡片触发移除的阈值
- maxRotation //拖拽过程中最大旋转角度(角度制)

### 操作Back和Next

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ org.gradle.jvmargs=-Xmx1536m
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
#android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
#android.enableJetifier=true

1 change: 1 addition & 0 deletions library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
21 changes: 21 additions & 0 deletions library/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package me.hiten.jkcardlayout;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("me.hiten.jkcardlayout.test", appContext.getPackageName());
}
}
1 change: 1 addition & 0 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="me.hiten.jkcardlayout" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package me.hiten.jkcardlayout;



import android.animation.TypeEvaluator;
import android.util.Property;
import android.view.View;

import java.util.LinkedList;
import java.util.Random;

public class CardAnimatorManager {

public static class AnimatorInfoEvaluator implements TypeEvaluator<AnimatorInfo> {

AnimatorInfo mTemp = new AnimatorInfo();

@Override
public AnimatorInfo evaluate(float fraction, AnimatorInfo startValue, AnimatorInfo endValue) {
mTemp.targetRotation = startValue.targetRotation+(endValue.targetRotation-startValue.targetRotation)*fraction;
mTemp.targetXr = startValue.targetXr+(endValue.targetXr-startValue.targetXr)*fraction;
mTemp.targetYr = startValue.targetYr+(endValue.targetYr-startValue.targetYr)*fraction;
return mTemp;
}
}

public static class AnimatorInfoProperty extends Property<View,AnimatorInfo>{

private float baseX;

private float baseY;

public AnimatorInfoProperty(float baseX,float baseY) {
super(AnimatorInfo.class, null);
this.baseX = baseX;
this.baseY = baseY;
}

@Override
public void set(View object, AnimatorInfo value) {
object.setTranslationX(value.targetXr*baseX);
object.setTranslationY(value.targetYr*baseY);
object.setRotation(value.targetRotation);
}

@Override
public AnimatorInfo get(View object) {
return null;
}
}


private LinkedList<AnimatorInfo> mStack = new LinkedList<>();

public AnimatorInfo takeAdd() {
AnimatorInfo pop = null;
if (mStack.size() > 0) {
pop = mStack.pop();
}
if (pop == null) {
pop = new AnimatorInfo();
}
return pop;
}


public void addRemoveToBackStack(AnimatorInfo animatorInfo) {
mStack.push(animatorInfo);
}

public AnimatorInfo createRemove() {
AnimatorInfo animatorInfo = new AnimatorInfo();
boolean b = new Random().nextBoolean();
animatorInfo.targetXr = b ? -1.0f : 1.0f;
animatorInfo.targetYr = 1f;
animatorInfo.targetRotation = 10;
return animatorInfo;
}


public static class AnimatorInfo {
float targetXr;
float targetYr;
float targetRotation;

public static AnimatorInfo ZERO = new AnimatorInfo();
}

}
Loading

0 comments on commit 793b033

Please sign in to comment.