├── CardSlidePanel.apk ├── CardSlidePanel ├── .gitignore ├── .idea │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ └── runConfigurations.xml ├── CardSlidePanel.iml ├── app │ ├── .gitignore │ ├── app.iml │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── stone │ │ │ └── card │ │ │ └── ApplicationTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ │ ├── wall01.jpg │ │ │ ├── wall02.jpg │ │ │ ├── wall03.jpg │ │ │ ├── wall04.jpg │ │ │ ├── wall05.jpg │ │ │ ├── wall06.jpg │ │ │ ├── wall07.jpg │ │ │ ├── wall08.jpg │ │ │ ├── wall09.jpg │ │ │ ├── wall10.jpg │ │ │ ├── wall11.jpg │ │ │ └── wall12.jpg │ │ ├── java │ │ │ └── com │ │ │ │ └── stone │ │ │ │ └── card │ │ │ │ ├── CardDataItem.java │ │ │ │ └── MainActivity.java │ │ └── res │ │ │ ├── drawable-xhdpi │ │ │ ├── bottom.9.png │ │ │ ├── home_normal.png │ │ │ ├── home_pressed.png │ │ │ ├── ic_launcher.png │ │ │ ├── ignore_normal.png │ │ │ ├── ignore_pressed.png │ │ │ ├── like_normal.png │ │ │ ├── like_pressed.png │ │ │ └── top.9.png │ │ │ ├── drawable-xxhdpi │ │ │ ├── card_left1.png │ │ │ ├── card_left2.png │ │ │ ├── card_photot.png │ │ │ ├── download.png │ │ │ └── ic_launcher.png │ │ │ ├── drawable │ │ │ ├── home_button.xml │ │ │ ├── ignore_button.xml │ │ │ └── like_button.xml │ │ │ ├── layout │ │ │ ├── activity_main.xml │ │ │ └── card_item.xml │ │ │ ├── menu │ │ │ └── menu_main.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-v21 │ │ │ └── styles.xml │ │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── ids.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── stone │ │ └── card │ │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library │ ├── .gitignore │ ├── build.gradle │ ├── library.iml │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── stone │ │ │ └── card │ │ │ └── library │ │ │ └── ExampleInstrumentedTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── stone │ │ │ │ └── card │ │ │ │ └── library │ │ │ │ ├── CardAdapter.java │ │ │ │ ├── CardItemView.java │ │ │ │ └── CardSlidePanel.java │ │ └── res │ │ │ └── values │ │ │ ├── attrs.xml │ │ │ └── strings.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── stone │ │ └── card │ │ └── library │ │ └── ExampleUnitTest.java └── settings.gradle ├── README.md └── capture4.jpg /CardSlidePanel.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel.apk -------------------------------------------------------------------------------- /CardSlidePanel/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /CardSlidePanel/.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 | -------------------------------------------------------------------------------- /CardSlidePanel/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /CardSlidePanel/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /CardSlidePanel/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /CardSlidePanel/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CardSlidePanel/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /CardSlidePanel/CardSlidePanel.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /CardSlidePanel/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /CardSlidePanel/app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 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 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /CardSlidePanel/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion '25.0.2' 6 | 7 | defaultConfig { 8 | applicationId "com.stone.card" 9 | minSdkVersion 14 10 | targetSdkVersion 25 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(include: ['*.jar'], dir: 'libs') 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:support-v4:25.3.1' 26 | compile 'com.github.bumptech.glide:glide:3.8.0' 27 | compile project(':library') 28 | } 29 | -------------------------------------------------------------------------------- /CardSlidePanel/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 D:\adt-bundle-windows-x86_64-20140702\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 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/androidTest/java/com/stone/card/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.stone.card; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall01.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall02.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall03.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall04.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall05.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall06.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall07.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall08.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall09.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall10.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall11.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/assets/wall12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/assets/wall12.jpg -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/java/com/stone/card/CardDataItem.java: -------------------------------------------------------------------------------- 1 | package com.stone.card; 2 | 3 | /** 4 | * 卡片数据装载对象 5 | * 6 | * @author xmuSistone 7 | */ 8 | public class CardDataItem { 9 | String imagePath; 10 | String userName; 11 | int likeNum; 12 | int imageNum; 13 | } 14 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/java/com/stone/card/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.stone.card; 2 | 3 | import android.graphics.Rect; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.support.v4.app.FragmentActivity; 7 | import android.util.Log; 8 | import android.view.View; 9 | import android.view.Window; 10 | import android.widget.ImageView; 11 | import android.widget.TextView; 12 | 13 | import com.bumptech.glide.Glide; 14 | import com.stone.card.library.CardAdapter; 15 | import com.stone.card.library.CardSlidePanel; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | public class MainActivity extends FragmentActivity { 21 | 22 | private CardSlidePanel.CardSwitchListener cardSwitchListener; 23 | 24 | private String imagePaths[] = {"file:///android_asset/wall01.jpg", 25 | "file:///android_asset/wall02.jpg", "file:///android_asset/wall03.jpg", 26 | "file:///android_asset/wall04.jpg", "file:///android_asset/wall05.jpg", 27 | "file:///android_asset/wall06.jpg", "file:///android_asset/wall07.jpg", 28 | "file:///android_asset/wall08.jpg", "file:///android_asset/wall09.jpg", 29 | "file:///android_asset/wall10.jpg", "file:///android_asset/wall11.jpg", 30 | "file:///android_asset/wall12.jpg"}; // 12个图片资源 31 | 32 | private String names[] = {"郭富城", "刘德华", "张学友", "李连杰", "成龙", "谢霆锋", "李易峰", 33 | "霍建华", "胡歌", "曾志伟", "吴孟达", "梁朝伟"}; // 12个人名 34 | 35 | private List dataList = new ArrayList<>(); 36 | 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | requestWindowFeature(Window.FEATURE_NO_TITLE); 42 | setContentView(R.layout.activity_main); 43 | initView(); 44 | } 45 | 46 | private void initView() { 47 | final CardSlidePanel slidePanel = (CardSlidePanel) findViewById(R.id.image_slide_panel); 48 | 49 | // 1. 左右滑动监听 50 | cardSwitchListener = new CardSlidePanel.CardSwitchListener() { 51 | 52 | @Override 53 | public void onShow(int index) { 54 | Log.d("Card", "正在显示-" + dataList.get(index).userName); 55 | } 56 | 57 | @Override 58 | public void onCardVanish(int index, int type) { 59 | Log.d("Card", "正在消失-" + dataList.get(index).userName + " 消失type=" + type); 60 | } 61 | }; 62 | slidePanel.setCardSwitchListener(cardSwitchListener); 63 | 64 | 65 | // 2. 绑定Adapter 66 | slidePanel.setAdapter(new CardAdapter() { 67 | @Override 68 | public int getLayoutId() { 69 | return R.layout.card_item; 70 | } 71 | 72 | @Override 73 | public int getCount() { 74 | return dataList.size(); 75 | } 76 | 77 | @Override 78 | public void bindView(View view, int index) { 79 | Object tag = view.getTag(); 80 | ViewHolder viewHolder; 81 | if (null != tag) { 82 | viewHolder = (ViewHolder) tag; 83 | } else { 84 | viewHolder = new ViewHolder(view); 85 | view.setTag(viewHolder); 86 | } 87 | 88 | viewHolder.bindData(dataList.get(index)); 89 | } 90 | 91 | @Override 92 | public Object getItem(int index) { 93 | return dataList.get(index); 94 | } 95 | 96 | @Override 97 | public Rect obtainDraggableArea(View view) { 98 | // 可滑动区域定制,该函数只会调用一次 99 | View contentView = view.findViewById(R.id.card_item_content); 100 | View topLayout = view.findViewById(R.id.card_top_layout); 101 | View bottomLayout = view.findViewById(R.id.card_bottom_layout); 102 | int left = view.getLeft() + contentView.getPaddingLeft() + topLayout.getPaddingLeft(); 103 | int right = view.getRight() - contentView.getPaddingRight() - topLayout.getPaddingRight(); 104 | int top = view.getTop() + contentView.getPaddingTop() + topLayout.getPaddingTop(); 105 | int bottom = view.getBottom() - contentView.getPaddingBottom() - bottomLayout.getPaddingBottom(); 106 | return new Rect(left, top, right, bottom); 107 | } 108 | }); 109 | 110 | 111 | Handler handler = new Handler(); 112 | handler.postDelayed(new Runnable() { 113 | @Override 114 | public void run() { 115 | prepareDataList(); 116 | slidePanel.getAdapter().notifyDataSetChanged(); 117 | } 118 | }, 500); 119 | 120 | // 3. notifyDataSetChanged调用 121 | findViewById(R.id.notify_change).setOnClickListener(new View.OnClickListener() { 122 | @Override 123 | public void onClick(View v) { 124 | appendDataList(); 125 | slidePanel.getAdapter().notifyDataSetChanged(); 126 | } 127 | }); 128 | } 129 | 130 | private void prepareDataList() { 131 | for (int i = 0; i < 6; i++) { 132 | CardDataItem dataItem = new CardDataItem(); 133 | dataItem.userName = names[i]; 134 | dataItem.imagePath = imagePaths[i]; 135 | dataItem.likeNum = (int) (Math.random() * 10); 136 | dataItem.imageNum = (int) (Math.random() * 6); 137 | dataList.add(dataItem); 138 | } 139 | } 140 | 141 | private void appendDataList() { 142 | for (int i = 0; i < 6; i++) { 143 | CardDataItem dataItem = new CardDataItem(); 144 | dataItem.userName = "From Append"; 145 | dataItem.imagePath = imagePaths[8]; 146 | dataItem.likeNum = (int) (Math.random() * 10); 147 | dataItem.imageNum = (int) (Math.random() * 6); 148 | dataList.add(dataItem); 149 | } 150 | } 151 | 152 | class ViewHolder { 153 | 154 | ImageView imageView; 155 | View maskView; 156 | TextView userNameTv; 157 | TextView imageNumTv; 158 | TextView likeNumTv; 159 | 160 | public ViewHolder(View view) { 161 | imageView = (ImageView) view.findViewById(R.id.card_image_view); 162 | maskView = view.findViewById(R.id.maskView); 163 | userNameTv = (TextView) view.findViewById(R.id.card_user_name); 164 | imageNumTv = (TextView) view.findViewById(R.id.card_pic_num); 165 | likeNumTv = (TextView) view.findViewById(R.id.card_like); 166 | } 167 | 168 | public void bindData(CardDataItem itemData) { 169 | Glide.with(MainActivity.this).load(itemData.imagePath).into(imageView); 170 | userNameTv.setText(itemData.userName); 171 | imageNumTv.setText(itemData.imageNum + ""); 172 | likeNumTv.setText(itemData.likeNum + ""); 173 | } 174 | } 175 | 176 | } 177 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xhdpi/bottom.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xhdpi/bottom.9.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xhdpi/home_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xhdpi/home_normal.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xhdpi/home_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xhdpi/home_pressed.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xhdpi/ignore_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xhdpi/ignore_normal.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xhdpi/ignore_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xhdpi/ignore_pressed.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xhdpi/like_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xhdpi/like_normal.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xhdpi/like_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xhdpi/like_pressed.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xhdpi/top.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xhdpi/top.9.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xxhdpi/card_left1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xxhdpi/card_left1.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xxhdpi/card_left2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xxhdpi/card_left2.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xxhdpi/card_photot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xxhdpi/card_photot.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xxhdpi/download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xxhdpi/download.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable/home_button.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable/ignore_button.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/drawable/like_button.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 21 | 22 | 29 | 30 | 31 | 32 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/layout/card_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 17 | 18 | 23 | 24 | 30 | 31 | 44 | 45 | 46 | 52 | 53 | 61 | 62 | 72 | 73 | 79 | 80 | 89 | 90 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | > 2 | 3 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | #a5c5ccf5 8 | #8f000000 9 | 10 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 16dp 6 | 312dp 7 | 220dp 8 | 9 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CardSlidePanel 3 | Settings 4 | 5 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /CardSlidePanel/app/src/test/java/com/stone/card/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.stone.card; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /CardSlidePanel/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:2.0.0' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | jcenter() 15 | } 16 | } 17 | 18 | task clean(type: Delete) { 19 | delete rootProject.buildDir 20 | } 21 | -------------------------------------------------------------------------------- /CardSlidePanel/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 -------------------------------------------------------------------------------- /CardSlidePanel/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/CardSlidePanel/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /CardSlidePanel/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Nov 30 10:13:14 CST 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.10-all.zip 7 | -------------------------------------------------------------------------------- /CardSlidePanel/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 | -------------------------------------------------------------------------------- /CardSlidePanel/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 | -------------------------------------------------------------------------------- /CardSlidePanel/library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /CardSlidePanel/library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | compile 'com.android.support:appcompat-v7:25.3.1' 30 | compile 'com.facebook.rebound:rebound:0.3.8' 31 | testCompile 'junit:junit:4.12' 32 | } 33 | -------------------------------------------------------------------------------- /CardSlidePanel/library/library.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 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 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /CardSlidePanel/library/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 D:\adt-bundle-windows-x86-20130917\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 | -------------------------------------------------------------------------------- /CardSlidePanel/library/src/androidTest/java/com/stone/card/library/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.stone.card.library; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.stone.card.library.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CardSlidePanel/library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CardSlidePanel/library/src/main/java/com/stone/card/library/CardAdapter.java: -------------------------------------------------------------------------------- 1 | package com.stone.card.library; 2 | 3 | import android.database.DataSetObservable; 4 | import android.database.DataSetObserver; 5 | import android.graphics.Rect; 6 | import android.view.View; 7 | 8 | /** 9 | * Created by xmuSistone on 2017/7/5. 10 | */ 11 | 12 | public abstract class CardAdapter { 13 | 14 | private final DataSetObservable mDataSetObservable = new DataSetObservable(); 15 | 16 | /** 17 | * layout文件ID,调用者必须实现 18 | */ 19 | public abstract int getLayoutId(); 20 | 21 | /** 22 | * item数量,调用者必须实现 23 | */ 24 | public abstract int getCount(); 25 | 26 | /** 27 | * View与数据绑定回调,可重载 28 | */ 29 | public abstract void bindView(View view, int index); 30 | 31 | /** 32 | * 获取数据用 33 | */ 34 | public abstract Object getItem(int index); 35 | 36 | 37 | /** 38 | * 可滑动区域定制 39 | * 40 | * @param view 拖动的View 41 | */ 42 | public Rect obtainDraggableArea(View view) { 43 | return null; 44 | } 45 | 46 | public void registerDataSetObserver(DataSetObserver observer) { 47 | mDataSetObservable.registerObserver(observer); 48 | } 49 | 50 | public void unregisterDataSetObserver(DataSetObserver observer) { 51 | mDataSetObservable.unregisterObserver(observer); 52 | } 53 | 54 | public void notifyDataSetChanged() { 55 | mDataSetObservable.notifyChanged(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /CardSlidePanel/library/src/main/java/com/stone/card/library/CardItemView.java: -------------------------------------------------------------------------------- 1 | package com.stone.card.library; 2 | 3 | import android.animation.ObjectAnimator; 4 | import android.animation.ValueAnimator; 5 | import android.annotation.SuppressLint; 6 | import android.content.Context; 7 | import android.util.AttributeSet; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.widget.FrameLayout; 11 | 12 | import com.facebook.rebound.SimpleSpringListener; 13 | import com.facebook.rebound.Spring; 14 | import com.facebook.rebound.SpringConfig; 15 | import com.facebook.rebound.SpringSystem; 16 | 17 | /** 18 | * 卡片View项 19 | * 20 | * @author xmuSistone 21 | */ 22 | @SuppressLint("NewApi") 23 | public class CardItemView extends FrameLayout { 24 | 25 | private Spring springX, springY; 26 | private CardSlidePanel parentView; 27 | private ObjectAnimator alphaAnimator; 28 | 29 | public CardItemView(Context context) { 30 | this(context, null); 31 | } 32 | 33 | public CardItemView(Context context, AttributeSet attrs) { 34 | this(context, attrs, 0); 35 | } 36 | 37 | public CardItemView(Context context, AttributeSet attrs, int defStyle) { 38 | super(context, attrs, defStyle); 39 | initSpring(); 40 | } 41 | 42 | private void initSpring() { 43 | SpringConfig springConfig = SpringConfig.fromBouncinessAndSpeed(15, 20); 44 | SpringSystem mSpringSystem = SpringSystem.create(); 45 | springX = mSpringSystem.createSpring().setSpringConfig(springConfig); 46 | springY = mSpringSystem.createSpring().setSpringConfig(springConfig); 47 | 48 | springX.addListener(new SimpleSpringListener() { 49 | @Override 50 | public void onSpringUpdate(Spring spring) { 51 | int xPos = (int) spring.getCurrentValue(); 52 | setScreenX(xPos); 53 | parentView.onViewPosChanged(CardItemView.this); 54 | } 55 | }); 56 | 57 | springY.addListener(new SimpleSpringListener() { 58 | @Override 59 | public void onSpringUpdate(Spring spring) { 60 | int yPos = (int) spring.getCurrentValue(); 61 | setScreenY(yPos); 62 | parentView.onViewPosChanged(CardItemView.this); 63 | } 64 | }); 65 | } 66 | 67 | /** 68 | * 动画移动到某个位置 69 | */ 70 | public void animTo(int xPos, int yPos) { 71 | setCurrentSpringPos(getLeft(), getTop()); 72 | springX.setEndValue(xPos); 73 | springY.setEndValue(yPos); 74 | } 75 | 76 | /** 77 | * 设置当前spring位置 78 | */ 79 | private void setCurrentSpringPos(int xPos, int yPos) { 80 | springX.setCurrentValue(xPos); 81 | springY.setCurrentValue(yPos); 82 | } 83 | 84 | public void setScreenX(int screenX) { 85 | this.offsetLeftAndRight(screenX - getLeft()); 86 | } 87 | 88 | public void setScreenY(int screenY) { 89 | this.offsetTopAndBottom(screenY - getTop()); 90 | } 91 | 92 | public void setParentView(CardSlidePanel parentView) { 93 | this.parentView = parentView; 94 | } 95 | 96 | public void onStartDragging() { 97 | springX.setAtRest(); 98 | springY.setAtRest(); 99 | } 100 | 101 | public void bindLayoutResId(int layoutResId) { 102 | LayoutInflater inflater = LayoutInflater.from(getContext()); 103 | View view = inflater.inflate(layoutResId, null); 104 | addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); 105 | } 106 | 107 | public void setVisibilityWithAnimation(final int visibility, int delayIndex) { 108 | if (visibility == View.VISIBLE && getVisibility() != View.VISIBLE) { 109 | setAlpha(0); 110 | setVisibility(visibility); 111 | 112 | if (null != alphaAnimator) { 113 | alphaAnimator.cancel(); 114 | } 115 | alphaAnimator = ObjectAnimator.ofFloat(this, "alpha", 116 | 0.0f, 1.0f); 117 | alphaAnimator.setDuration(360); 118 | alphaAnimator.setStartDelay(delayIndex * 200); 119 | alphaAnimator.start(); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /CardSlidePanel/library/src/main/java/com/stone/card/library/CardSlidePanel.java: -------------------------------------------------------------------------------- 1 | package com.stone.card.library; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.database.DataSetObserver; 7 | import android.graphics.Point; 8 | import android.graphics.Rect; 9 | import android.support.v4.view.GestureDetectorCompat; 10 | import android.support.v4.view.ViewCompat; 11 | import android.support.v4.widget.ViewDragHelper; 12 | import android.util.AttributeSet; 13 | import android.view.GestureDetector.SimpleOnGestureListener; 14 | import android.view.MotionEvent; 15 | import android.view.View; 16 | import android.view.ViewConfiguration; 17 | import android.view.ViewGroup; 18 | import android.view.ViewTreeObserver; 19 | 20 | import java.lang.ref.WeakReference; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | /** 25 | * 卡片滑动面板,主要逻辑实现类 26 | * 27 | * @author xmuSistone 28 | */ 29 | @SuppressLint({"HandlerLeak", "NewApi", "ClickableViewAccessibility"}) 30 | public class CardSlidePanel extends ViewGroup { 31 | private List viewList = new ArrayList<>(); // 存放的是每一层的view,从顶到底 32 | private List releasedViewList = new ArrayList<>(); // 手指松开后存放的view列表 33 | 34 | /* 拖拽工具类 */ 35 | private final ViewDragHelper mDragHelper; // 这个跟原生的ViewDragHelper差不多,我仅仅只是修改了Interpolator 36 | private int initCenterViewX = 0, initCenterViewY = 0; // 最初时,中间View的x位置,y位置 37 | private int allWidth = 0; // 面板的宽度 38 | private int allHeight = 0; // 面板的高度 39 | private int childWith = 0; // 每一个子View对应的宽度 40 | 41 | private static final float SCALE_STEP = 0.08f; // view叠加缩放的步长 42 | private static final int MAX_SLIDE_DISTANCE_LINKAGE = 500; // 水平距离+垂直距离 43 | 44 | private int itemMarginTop = 10; // 卡片距离顶部的偏移量 45 | private int bottomMarginTop = 40; // 底部按钮与卡片的margin值 46 | private int yOffsetStep = 40; // view叠加垂直偏移量的步长 47 | private int mTouchSlop = 5; // 判定为滑动的阈值,单位是像素 48 | 49 | private static final int X_VEL_THRESHOLD = 800; 50 | private static final int X_DISTANCE_THRESHOLD = 300; 51 | 52 | public static final int VANISH_TYPE_LEFT = 0; 53 | public static final int VANISH_TYPE_RIGHT = 1; 54 | 55 | private CardSwitchListener cardSwitchListener; // 回调接口 56 | private int isShowing = 0; // 当前正在显示的小项 57 | private boolean btnLock = false; 58 | private GestureDetectorCompat moveDetector; 59 | private Point downPoint = new Point(); 60 | private CardAdapter adapter; 61 | private static final int VIEW_COUNT = 4; 62 | private Rect draggableArea; 63 | private WeakReference savedFirstItemData; 64 | 65 | public CardSlidePanel(Context context) { 66 | this(context, null); 67 | } 68 | 69 | public CardSlidePanel(Context context, AttributeSet attrs) { 70 | this(context, attrs, 0); 71 | } 72 | 73 | public CardSlidePanel(Context context, AttributeSet attrs, int defStyle) { 74 | super(context, attrs, defStyle); 75 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.card); 76 | 77 | itemMarginTop = (int) a.getDimension(R.styleable.card_itemMarginTop, itemMarginTop); 78 | bottomMarginTop = (int) a.getDimension(R.styleable.card_bottomMarginTop, bottomMarginTop); 79 | yOffsetStep = (int) a.getDimension(R.styleable.card_yOffsetStep, yOffsetStep); 80 | // 滑动相关类 81 | mDragHelper = ViewDragHelper 82 | .create(this, 10f, new DragHelperCallback()); 83 | mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_BOTTOM); 84 | a.recycle(); 85 | 86 | ViewConfiguration configuration = ViewConfiguration.get(getContext()); 87 | mTouchSlop = configuration.getScaledTouchSlop(); 88 | moveDetector = new GestureDetectorCompat(context, 89 | new MoveDetector()); 90 | moveDetector.setIsLongpressEnabled(false); 91 | 92 | getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 93 | @Override 94 | public void onGlobalLayout() { 95 | if (getChildCount() != VIEW_COUNT) { 96 | doBindAdapter(); 97 | } 98 | } 99 | }); 100 | } 101 | 102 | private void doBindAdapter() { 103 | if (adapter == null || allWidth <= 0 || allHeight <= 0) { 104 | return; 105 | } 106 | 107 | // 1. addView添加到ViewGroup中 108 | for (int i = 0; i < VIEW_COUNT; i++) { 109 | CardItemView itemView = new CardItemView(getContext()); 110 | itemView.bindLayoutResId(adapter.getLayoutId()); 111 | itemView.setParentView(this); 112 | addView(itemView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); 113 | 114 | if (i == 0) { 115 | itemView.setAlpha(0); 116 | } 117 | } 118 | 119 | // 2. viewList初始化 120 | viewList.clear(); 121 | for (int i = 0; i < VIEW_COUNT; i++) { 122 | viewList.add((CardItemView) getChildAt(VIEW_COUNT - 1 - i)); 123 | } 124 | 125 | 126 | // 3. 填充数据 127 | int count = adapter.getCount(); 128 | for (int i = 0; i < VIEW_COUNT; i++) { 129 | if (i < count) { 130 | adapter.bindView(viewList.get(i), i); 131 | if (i == 0) { 132 | savedFirstItemData = new WeakReference<>(adapter.getItem(i)); 133 | } 134 | } else { 135 | viewList.get(i).setVisibility(View.INVISIBLE); 136 | } 137 | } 138 | } 139 | 140 | class MoveDetector extends SimpleOnGestureListener { 141 | 142 | @Override 143 | public boolean onScroll(MotionEvent e1, MotionEvent e2, float dx, 144 | float dy) { 145 | // 拖动了,touch不往下传递 146 | return Math.abs(dy) + Math.abs(dx) > mTouchSlop; 147 | } 148 | } 149 | 150 | 151 | /** 152 | * 这是viewdraghelper拖拽效果的主要逻辑 153 | */ 154 | private class DragHelperCallback extends ViewDragHelper.Callback { 155 | 156 | @Override 157 | public void onViewPositionChanged(View changedView, int left, int top, 158 | int dx, int dy) { 159 | onViewPosChanged((CardItemView) changedView); 160 | } 161 | 162 | @Override 163 | public boolean tryCaptureView(View child, int pointerId) { 164 | // 如果数据List为空,或者子View不可见,则不予处理 165 | 166 | if (adapter == null || adapter.getCount() == 0 167 | || child.getVisibility() != View.VISIBLE || child.getScaleX() <= 1.0f - SCALE_STEP) { 168 | // 一般来讲,如果拖动的是第三层、或者第四层的View,则直接禁止 169 | // 此处用getScale的用法来巧妙回避 170 | return false; 171 | } 172 | 173 | if (btnLock) { 174 | return false; 175 | } 176 | 177 | // 1. 只有顶部的View才允许滑动 178 | int childIndex = viewList.indexOf(child); 179 | if (childIndex > 0) { 180 | return false; 181 | } 182 | 183 | // 2. 获取可滑动区域 184 | ((CardItemView) child).onStartDragging(); 185 | if (draggableArea == null) { 186 | draggableArea = adapter.obtainDraggableArea(child); 187 | } 188 | 189 | 190 | // 3. 判断是否可滑动 191 | boolean shouldCapture = true; 192 | if (null != draggableArea) { 193 | shouldCapture = draggableArea.contains(downPoint.x, downPoint.y); 194 | } 195 | 196 | // 4. 如果确定要滑动,就让touch事件交给自己消费 197 | if (shouldCapture) { 198 | getParent().requestDisallowInterceptTouchEvent(shouldCapture); 199 | } 200 | return shouldCapture; 201 | } 202 | 203 | @Override 204 | public int getViewHorizontalDragRange(View child) { 205 | // 这个用来控制拖拽过程中松手后,自动滑行的速度 206 | return 256; 207 | } 208 | 209 | @Override 210 | public void onViewReleased(View releasedChild, float xvel, float yvel) { 211 | animToSide((CardItemView) releasedChild, (int) xvel, (int) yvel); 212 | } 213 | 214 | @Override 215 | public int clampViewPositionHorizontal(View child, int left, int dx) { 216 | return left; 217 | } 218 | 219 | @Override 220 | public int clampViewPositionVertical(View child, int top, int dy) { 221 | return top; 222 | } 223 | } 224 | 225 | 226 | public void onViewPosChanged(CardItemView changedView) { 227 | // 调用offsetLeftAndRight导致viewPosition改变,会调到此处,所以此处对index做保护处理 228 | int index = viewList.indexOf(changedView); 229 | if (index + 2 > viewList.size()) { 230 | return; 231 | } 232 | 233 | processLinkageView(changedView); 234 | } 235 | 236 | /** 237 | * 对View重新排序 238 | */ 239 | private void orderViewStack() { 240 | if (releasedViewList.size() == 0) { 241 | return; 242 | } 243 | 244 | CardItemView changedView = (CardItemView) releasedViewList.get(0); 245 | if (changedView.getLeft() == initCenterViewX) { 246 | releasedViewList.remove(0); 247 | return; 248 | } 249 | 250 | // 1. 消失的卡片View位置重置,由于大多手机会重新调用onLayout函数,所以此处大可以不做处理,不信你注释掉看看 251 | changedView.offsetLeftAndRight(initCenterViewX 252 | - changedView.getLeft()); 253 | changedView.offsetTopAndBottom(initCenterViewY 254 | - changedView.getTop() + yOffsetStep * 2); 255 | float scale = 1.0f - SCALE_STEP * 2; 256 | changedView.setScaleX(scale); 257 | changedView.setScaleY(scale); 258 | changedView.setAlpha(0); 259 | 260 | // 2. 卡片View在ViewGroup中的顺次调整 261 | LayoutParams lp = changedView.getLayoutParams(); 262 | removeViewInLayout(changedView); 263 | addViewInLayout(changedView, 0, lp, true); 264 | 265 | // 3. changedView填充新数据 266 | int newIndex = isShowing + 4; 267 | if (newIndex < adapter.getCount()) { 268 | adapter.bindView(changedView, newIndex); 269 | } else { 270 | changedView.setVisibility(View.INVISIBLE); 271 | } 272 | 273 | // 4. viewList中的卡片view的位次调整 274 | viewList.remove(changedView); 275 | viewList.add(changedView); 276 | releasedViewList.remove(0); 277 | 278 | // 5. 更新showIndex、接口回调 279 | if (isShowing + 1 < adapter.getCount()) { 280 | isShowing++; 281 | } 282 | if (null != cardSwitchListener) { 283 | cardSwitchListener.onShow(isShowing); 284 | } 285 | } 286 | 287 | /** 288 | * 顶层卡片View位置改变,底层的位置需要调整 289 | * 290 | * @param changedView 顶层的卡片view 291 | */ 292 | private void processLinkageView(View changedView) { 293 | int changeViewLeft = changedView.getLeft(); 294 | int changeViewTop = changedView.getTop(); 295 | int distance = Math.abs(changeViewTop - initCenterViewY) 296 | + Math.abs(changeViewLeft - initCenterViewX); 297 | float rate = distance / (float) MAX_SLIDE_DISTANCE_LINKAGE; 298 | 299 | float rate1 = rate; 300 | float rate2 = rate - 0.1f; 301 | 302 | if (rate > 1) { 303 | rate1 = 1; 304 | } 305 | 306 | if (rate2 < 0) { 307 | rate2 = 0; 308 | } else if (rate2 > 1) { 309 | rate2 = 1; 310 | } 311 | 312 | ajustLinkageViewItem(changedView, rate1, 1); 313 | ajustLinkageViewItem(changedView, rate2, 2); 314 | 315 | CardItemView bottomCardView = viewList.get(viewList.size() - 1); 316 | bottomCardView.setAlpha(rate2); 317 | } 318 | 319 | // 由index对应view变成index-1对应的view 320 | private void ajustLinkageViewItem(View changedView, float rate, int index) { 321 | int changeIndex = viewList.indexOf(changedView); 322 | int initPosY = yOffsetStep * index; 323 | float initScale = 1 - SCALE_STEP * index; 324 | 325 | int nextPosY = yOffsetStep * (index - 1); 326 | float nextScale = 1 - SCALE_STEP * (index - 1); 327 | 328 | int offset = (int) (initPosY + (nextPosY - initPosY) * rate); 329 | float scale = initScale + (nextScale - initScale) * rate; 330 | 331 | View ajustView = viewList.get(changeIndex + index); 332 | ajustView.offsetTopAndBottom(offset - ajustView.getTop() 333 | + initCenterViewY); 334 | ajustView.setScaleX(scale); 335 | ajustView.setScaleY(scale); 336 | } 337 | 338 | /** 339 | * 松手时处理滑动到边缘的动画 340 | */ 341 | private void animToSide(CardItemView changedView, int xvel, int yvel) { 342 | int finalX = initCenterViewX; 343 | int finalY = initCenterViewY; 344 | int flyType = -1; 345 | 346 | // 1. 下面这一坨计算finalX和finalY,要读懂代码需要建立一个比较清晰的数学模型才能理解,不信拉倒 347 | int dx = changedView.getLeft() - initCenterViewX; 348 | int dy = changedView.getTop() - initCenterViewY; 349 | 350 | // yvel < xvel * xyRate则允许以速度计算偏移 351 | final float xyRate = 3f; 352 | if (xvel > X_VEL_THRESHOLD && Math.abs(yvel) < xvel * xyRate) { 353 | // x正方向的速度足够大,向右滑动消失 354 | finalX = allWidth; 355 | finalY = yvel * (childWith + changedView.getLeft()) / xvel + changedView.getTop(); 356 | flyType = VANISH_TYPE_RIGHT; 357 | } else if (xvel < -X_VEL_THRESHOLD && Math.abs(yvel) < -xvel * xyRate) { 358 | // x负方向的速度足够大,向左滑动消失 359 | finalX = -childWith; 360 | finalY = yvel * (childWith + changedView.getLeft()) / (-xvel) + changedView.getTop(); 361 | flyType = VANISH_TYPE_LEFT; 362 | } else if (dx > X_DISTANCE_THRESHOLD && Math.abs(dy) < dx * xyRate) { 363 | // x正方向的位移足够大,向右滑动消失 364 | finalX = allWidth; 365 | finalY = dy * (childWith + initCenterViewX) / dx + initCenterViewY; 366 | flyType = VANISH_TYPE_RIGHT; 367 | } else if (dx < -X_DISTANCE_THRESHOLD && Math.abs(dy) < -dx * xyRate) { 368 | // x负方向的位移足够大,向左滑动消失 369 | finalX = -childWith; 370 | finalY = dy * (childWith + initCenterViewX) / (-dx) + initCenterViewY; 371 | flyType = VANISH_TYPE_LEFT; 372 | } 373 | 374 | // 如果斜率太高,就折中处理 375 | if (finalY > allHeight) { 376 | finalY = allHeight; 377 | } else if (finalY < -allHeight / 2) { 378 | finalY = -allHeight / 2; 379 | } 380 | 381 | // 如果没有飞向两侧,而是回到了中间,需要谨慎处理 382 | if (finalX == initCenterViewX) { 383 | changedView.animTo(initCenterViewX, initCenterViewY); 384 | } else { 385 | // 2. 向两边消失的动画 386 | releasedViewList.add(changedView); 387 | if (mDragHelper.smoothSlideViewTo(changedView, finalX, finalY)) { 388 | ViewCompat.postInvalidateOnAnimation(this); 389 | } 390 | 391 | // 3. 消失动画即将进行,listener回调 392 | if (flyType >= 0 && cardSwitchListener != null) { 393 | cardSwitchListener.onCardVanish(isShowing, flyType); 394 | } 395 | } 396 | } 397 | 398 | /** 399 | * 点击按钮消失动画 400 | */ 401 | private void vanishOnBtnClick(int type) { 402 | View animateView = viewList.get(0); 403 | if (animateView.getVisibility() != View.VISIBLE || releasedViewList.contains(animateView)) { 404 | return; 405 | } 406 | 407 | int finalX = 0; 408 | int extraVanishDistance = 100; // 为加快vanish的速度,额外添加消失的距离 409 | if (type == VANISH_TYPE_LEFT) { 410 | finalX = -childWith - extraVanishDistance; 411 | } else if (type == VANISH_TYPE_RIGHT) { 412 | finalX = allWidth + extraVanishDistance; 413 | } 414 | 415 | if (finalX != 0) { 416 | releasedViewList.add(animateView); 417 | if (mDragHelper.smoothSlideViewTo(animateView, finalX, initCenterViewY + allHeight / 2)) { 418 | ViewCompat.postInvalidateOnAnimation(this); 419 | } 420 | } 421 | 422 | if (type >= 0 && cardSwitchListener != null) { 423 | cardSwitchListener.onCardVanish(isShowing, type); 424 | } 425 | } 426 | 427 | @Override 428 | public void computeScroll() { 429 | if (mDragHelper.continueSettling(true)) { 430 | ViewCompat.postInvalidateOnAnimation(this); 431 | } else { 432 | // 动画结束 433 | if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) { 434 | orderViewStack(); 435 | btnLock = false; 436 | } 437 | } 438 | } 439 | 440 | @Override 441 | public boolean dispatchTouchEvent(MotionEvent ev) { 442 | int action = ev.getActionMasked(); 443 | // 按下时保存坐标信息 444 | if (action == MotionEvent.ACTION_DOWN) { 445 | this.downPoint.x = (int) ev.getX(); 446 | this.downPoint.y = (int) ev.getY(); 447 | } 448 | return super.dispatchTouchEvent(ev); 449 | } 450 | 451 | /* touch事件的拦截与处理都交给mDraghelper来处理 */ 452 | @Override 453 | public boolean onInterceptTouchEvent(MotionEvent ev) { 454 | boolean shouldIntercept = mDragHelper.shouldInterceptTouchEvent(ev); 455 | boolean moveFlag = moveDetector.onTouchEvent(ev); 456 | int action = ev.getActionMasked(); 457 | if (action == MotionEvent.ACTION_DOWN) { 458 | // ACTION_DOWN的时候就对view重新排序 459 | if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_SETTLING) { 460 | mDragHelper.abort(); 461 | } 462 | orderViewStack(); 463 | 464 | // 保存初次按下时arrowFlagView的Y坐标 465 | // action_down时就让mDragHelper开始工作,否则有时候导致异常 466 | mDragHelper.processTouchEvent(ev); 467 | } 468 | 469 | return shouldIntercept && moveFlag; 470 | } 471 | 472 | @Override 473 | public boolean onTouchEvent(MotionEvent e) { 474 | try { 475 | // 统一交给mDragHelper处理,由DragHelperCallback实现拖动效果 476 | // 该行代码可能会抛异常,正式发布时请将这行代码加上try catch 477 | mDragHelper.processTouchEvent(e); 478 | } catch (Exception ex) { 479 | ex.printStackTrace(); 480 | } 481 | return true; 482 | } 483 | 484 | @Override 485 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 486 | measureChildren(widthMeasureSpec, heightMeasureSpec); 487 | int maxWidth = MeasureSpec.getSize(widthMeasureSpec); 488 | int maxHeight = MeasureSpec.getSize(heightMeasureSpec); 489 | setMeasuredDimension( 490 | resolveSizeAndState(maxWidth, widthMeasureSpec, 0), 491 | resolveSizeAndState(maxHeight, heightMeasureSpec, 0)); 492 | 493 | allWidth = getMeasuredWidth(); 494 | allHeight = getMeasuredHeight(); 495 | } 496 | 497 | @Override 498 | protected void onLayout(boolean changed, int left, int top, int right, 499 | int bottom) { 500 | 501 | int childCount = getChildCount(); 502 | for (int i = 0; i < childCount; i++) { 503 | View viewItem = viewList.get(i); 504 | // 1. 先layout出来 505 | int childHeight = viewItem.getMeasuredHeight(); 506 | int viewLeft = (getWidth() - viewItem.getMeasuredWidth()) / 2; 507 | viewItem.layout(viewLeft, itemMarginTop, viewLeft + viewItem.getMeasuredWidth(), itemMarginTop + childHeight); 508 | 509 | // 2. 调整位置 510 | int offset = yOffsetStep * i; 511 | float scale = 1 - SCALE_STEP * i; 512 | if (i > 2) { 513 | // 备用的view 514 | offset = yOffsetStep * 2; 515 | scale = 1 - SCALE_STEP * 2; 516 | } 517 | viewItem.offsetTopAndBottom(offset); 518 | 519 | // 3. 调整缩放、重心等 520 | viewItem.setPivotY(viewItem.getMeasuredHeight()); 521 | viewItem.setPivotX(viewItem.getMeasuredWidth() / 2); 522 | viewItem.setScaleX(scale); 523 | viewItem.setScaleY(scale); 524 | } 525 | 526 | if (childCount > 0) { 527 | // 初始化一些中间参数 528 | initCenterViewX = viewList.get(0).getLeft(); 529 | initCenterViewY = viewList.get(0).getTop(); 530 | childWith = viewList.get(0).getMeasuredWidth(); 531 | } 532 | } 533 | 534 | public void setAdapter(final CardAdapter adapter) { 535 | this.adapter = adapter; 536 | doBindAdapter(); 537 | adapter.registerDataSetObserver(new DataSetObserver() { 538 | @Override 539 | public void onChanged() { 540 | orderViewStack(); 541 | 542 | boolean reset = false; 543 | if (adapter.getCount() > 0) { 544 | Object firstObj = adapter.getItem(0); 545 | if (null == savedFirstItemData) { 546 | // 此前就没有数据,需要保存第一条数据 547 | savedFirstItemData = new WeakReference<>(firstObj); 548 | isShowing = 0; 549 | } else { 550 | Object savedObj = savedFirstItemData.get(); 551 | if (firstObj != savedObj) { 552 | // 如果第一条数据不等的话,需要重置 553 | isShowing = 0; 554 | reset = true; 555 | savedFirstItemData = new WeakReference<>(firstObj); 556 | } 557 | } 558 | } 559 | 560 | int delay = 0; 561 | for (int i = 0; i < VIEW_COUNT; i++) { 562 | CardItemView itemView = viewList.get(i); 563 | if (isShowing + i < adapter.getCount()) { 564 | if (itemView.getVisibility() == View.VISIBLE) { 565 | if (!reset) { 566 | continue; 567 | } 568 | } else if (i == 0) { 569 | if (isShowing > 0) { 570 | isShowing++; 571 | } 572 | cardSwitchListener.onShow(isShowing); 573 | } 574 | if (i == VIEW_COUNT - 1) { 575 | itemView.setAlpha(0); 576 | itemView.setVisibility(View.VISIBLE); 577 | } else { 578 | itemView.setVisibilityWithAnimation(View.VISIBLE, delay++); 579 | } 580 | adapter.bindView(itemView, isShowing + i); 581 | } else { 582 | itemView.setVisibility(View.INVISIBLE); 583 | } 584 | } 585 | } 586 | }); 587 | } 588 | 589 | public CardAdapter getAdapter() { 590 | return adapter; 591 | } 592 | 593 | /** 594 | * 设置卡片操作回调 595 | */ 596 | public void setCardSwitchListener(CardSwitchListener cardSwitchListener) { 597 | this.cardSwitchListener = cardSwitchListener; 598 | } 599 | 600 | /** 601 | * 卡片回调接口 602 | */ 603 | public interface CardSwitchListener { 604 | /** 605 | * 新卡片显示回调 606 | * 607 | * @param index 最顶层显示的卡片的index 608 | */ 609 | public void onShow(int index); 610 | 611 | /** 612 | * 卡片飞向两侧回调 613 | * 614 | * @param index 飞向两侧的卡片数据index 615 | * @param type 飞向哪一侧{@link #VANISH_TYPE_LEFT}或{@link #VANISH_TYPE_RIGHT} 616 | */ 617 | public void onCardVanish(int index, int type); 618 | } 619 | } -------------------------------------------------------------------------------- /CardSlidePanel/library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CardSlidePanel/library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | library 3 | 4 | -------------------------------------------------------------------------------- /CardSlidePanel/library/src/test/java/com/stone/card/library/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.stone.card.library; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /CardSlidePanel/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':library' 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ### 有图有真相 3 | 模仿探探首页的卡片滑动效果:

4 | ![preview](capture4.jpg) 5 | 不得不说,探探的ui效果真的很赞。在着手这个project之前,我没有参考过github上其它类似的开源项目。所以,如果这个project重复造了轮子,请不要打我。

6 | 在这个仓库竣工之时,有一个小伙伴发了我另一个开源工程,颇有相似之处。我下载了源码,导入了studio,apk跑起来的时候,发现它存在一些问题:卡片飞到两侧,如果动画没有结束,则不允许下一轮拖动。这对强迫症的用户来说,应该是很不爽的。

7 | 然而,探探却克服了所有这些问题。或许,这个问题只有积淀过这些知识点的人才能琢磨的透吧。我确实思考了很久,想到了一个还不错的方案。
8 | 9 | ### 无耻一点 10 | 如果我能不要脸一些,我会说这个项目有以下优点:
11 | * 快。真的流畅,滑动的手速再快也赶不上代码刷新view的速度快。
12 | * 高效。仅仅四个卡片view轻松搞定任意多的数据。
13 | * 灵活。自定义ViewGroup对卡片view的高度实现了自适应。
14 | * 细节。卡片之间联动的视觉效果,是像素级的精确。
15 | 16 | 不信,你下载下来look look。 17 | ### 使用方法 18 | #### 1. 在xml文件中引入CardSlidePanel 19 | ```xml 20 | 27 | ``` 28 | #### 2. 左右滑动监听
29 | ```java 30 | cardSwitchListener = new CardSlidePanel.CardSwitchListener() { 31 | 32 | @Override 33 | public void onShow(int index) { 34 | Log.d("Card", "正在显示-" + dataList.get(index).userName); 35 | } 36 | 37 | @Override 38 | public void onCardVanish(int index, int type) { 39 | Log.d("Card", "正在消失-" + dataList.get(index).userName + " 消失type=" + type); 40 | } 41 | }; 42 | slidePanel.setCardSwitchListener(cardSwitchListener); 43 | ``` 44 | #### 3. 绑定Adapter
45 | ```java 46 | slidePanel.setAdapter(new CardAdapter() { 47 | @Override 48 | public int getLayoutId() { 49 |            // layout文件 50 |            return R.layout.card_item; 51 | } 52 | 53 | @Override 54 | public int getCount() { 55 |            // 卡片个数 56 |            return dataList.size(); 57 | } 58 | 59 | @Override 60 | public Rect obtainDraggableArea(View view) { 61 |            // 可滑动区域定制,仅调用一次 62 |            return new Rect(....) 63 |        } 64 | 65 | @Override 66 | public void bindView(View view, int index) { 67 |            // 数据绑定,参看demo 68 |            viewHolder.bindData(dataList.get(index)); 69 | } 70 | }); 71 | ``` 72 | #### 4. 数据更新
73 | ```java 74 | // appendDataList 75 | adapter.notifyDataSetChanged(); 76 | ``` 77 | #### Demo安装包 78 | [apk download](CardSlidePanel.apk) (就在thisProj工程之中) 79 | 80 | ## License 81 | 82 | Copyright 2016, xmuSistone 83 | 84 | Licensed under the Apache License, Version 2.0 (the "License"); 85 | you may not use this file except in compliance with the License. 86 | You may obtain a copy of the License at 87 | 88 | http://www.apache.org/licenses/LICENSE-2.0 89 | 90 | Unless required by applicable law or agreed to in writing, software 91 | distributed under the License is distributed on an "AS IS" BASIS, 92 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 93 | See the License for the specific language governing permissions and 94 | limitations under the License. 95 | 96 | -------------------------------------------------------------------------------- /capture4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmuSistone/CardSlidePanel/70dab2540745c39bfef805c4621b52ebfb85fc97/capture4.jpg --------------------------------------------------------------------------------