11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 yanbo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SlideLayout
2 |
3 | 纯手工超级迷你轻量级全方向完美滑动处理侧滑控件(比官方 support v4 包 SlidingPaneLayout 控件更加 Q 迷你,累计代码不足 300 行),支持上下左右有各种侧拉,可配置侧拉松手临界距离,支持单独使用、ListView、GridView、RecycleView、ScrollView、ViewPager 等各种嵌套(作为 item 使用或者作为以上所有控件的父容器使用),具体不同配置展示效果如下图。
4 |
5 |
6 |
7 | # 说明文档
8 |
9 | 如下是关于 SlideLayout 的相关使用方式、属性说明、拓展自定义的解释说明。
10 |
11 | ### 使用样例
12 |
13 | 实现类似手机 QQ 侧滑效果,ListView 向右侧滑拉出侧边栏。
14 | ```xml
15 |
20 |
24 |
25 |
30 |
31 | ```
32 |
33 | 实现类似手机 QQ ListView 聊天列表任意 item 向左滑动呼出删除按钮效果。
34 | ```xml
35 |
38 |
43 |
44 |
48 |
54 |
55 |
61 |
62 |
63 | ```
64 |
65 | ### 已实现类说明
66 |
67 | | 类别 | 类名 | 说明 |
68 | | ----- | ----- | ----- |
69 | | library | SlideLayout | 支持配置各种方向侧滑和各种嵌套或者被嵌套的侧滑控件。 |
70 |
71 | ### 属性说明
72 |
73 | | 属性 | 含义 |
74 | | ----- | ----- |
75 | |app:slideCriticalValue | SlideLayout 任意方向侧滑拉出多大距离后松手敏感距离,譬如侧滑大于 50dp 后松手则自动滑开,小于 50 dp 内松手则自动收起;不设置默认为 SlideLayout 控件第二个子成员 width 的二分之一。|
76 | |app:slideDirection | 侧滑从哪边拉出,默认为从右侧拉出,可取值为 fromRight、fromLeft、fromTop、fromBottom。 |
77 |
78 | ### SlideLayout 提供方法说明
79 |
80 | | 方法 | 说明 |
81 | | ----- | ----- |
82 | | int getSlideState() | 获取当前侧滑控件所处状态,STATE_CLOSE、STATE_SLIDING、STATE_OPEN。 |
83 | | void smoothCloseSlide() | 平滑的收起侧滑。 |
84 | | void smoothOpenSlide() | 平滑的打开侧滑。 |
85 |
86 | ### SlideLayout 使用注意事项
87 |
88 | SlideLayout 控件有且必须包含两个子控件,第一个为 content 布局,默认撑满整个 SlideLayout,第二个为 slide 布局,默认不可见;切记两个子控件所处顺序,子控件层级不限,具体模板如下:
89 |
90 | ```
91 |
94 | <控件一(Content),不限嵌套层级等,默认可见/>
95 |
96 | <控件二(slide),不限嵌套层级等,默认不可见/>
97 |
98 | ```
99 |
100 | # License 声明
101 |
102 | MIT License
103 |
104 | Copyright (c) 2016 yanbo
105 |
106 | Permission is hereby granted, free of charge, to any person obtaining a copy
107 | of this software and associated documentation files (the "Software"), to deal
108 | in the Software without restriction, including without limitation the rights
109 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
110 | copies of the Software, and to permit persons to whom the Software is
111 | furnished to do so, subject to the following conditions:
112 |
113 | The above copyright notice and this permission notice shall be included in all
114 | copies or substantial portions of the Software.
115 |
116 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
117 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
118 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
119 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
120 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
121 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
122 | SOFTWARE.
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "23.0.1"
6 | defaultConfig {
7 | applicationId "cn.yan.slidelayout"
8 | minSdkVersion 14
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
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 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:24.2.1'
28 | testCompile 'junit:junit:4.12'
29 | compile project(':library')
30 | }
31 |
--------------------------------------------------------------------------------
/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 /usr/yan/android-sdk-linux/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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/cn/yan/slidelayout/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package cn.yan.slidelayout;
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("cn.yan.slidelayout", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/yan/slidelayout/DemoListAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.yan.slidelayout;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseAdapter;
7 | import android.widget.TextView;
8 | import android.widget.Toast;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import cn.yan.library.MiniSlideRightLayout;
14 | import cn.yan.library.SlideLayout;
15 |
16 | /**
17 | * Created by yan on 17-1-8.
18 | */
19 |
20 | public class DemoListAdapter extends BaseAdapter {
21 | private List mListData;
22 |
23 | public DemoListAdapter() {
24 | mListData = new ArrayList<>();
25 | mListData.add("AbsListView 测试案例");
26 | mListData.add("AbsListView 快来试试");
27 | mListData.add("AbsListView 不服来一局");
28 | mListData.add("AbsListView 来呀来呀,来呀");
29 | mListData.add("AbsListView 我了个去");
30 | mListData.add("AbsListView 山炮玩意儿");
31 | mListData.add("AbsListView 支持是一种鼓励");
32 | mListData.add("AbsListView 坚持");
33 | mListData.add("AbsListView 加油");
34 | mListData.add("AbsListView 哈哈,我去");
35 | }
36 |
37 | @Override
38 | public int getCount() {
39 | return mListData.size();
40 | }
41 |
42 | @Override
43 | public String getItem(int position) {
44 | return mListData.get(position);
45 | }
46 |
47 | @Override
48 | public long getItemId(int position) {
49 | return position;
50 | }
51 |
52 | @Override
53 | public View getView(final int position, View convertView, final ViewGroup parent) {
54 | //TODO
55 | final SlideLayout itemView = (SlideLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.item_demo_list, parent, false);
56 | TextView content = (TextView) itemView.findViewById(R.id.content_id);
57 | TextView slide = (TextView) itemView.findViewById(R.id.slide_id);
58 | content.setText(mListData.get(position));
59 |
60 | content.setOnClickListener(new View.OnClickListener() {
61 | @Override
62 | public void onClick(View v) {
63 | if (itemView.getSlideState() == MiniSlideRightLayout.STATE_OPEN) {
64 | itemView.smoothCloseSlide();
65 | } else {
66 | Toast.makeText(parent.getContext().getApplicationContext(), mListData.get(position), Toast.LENGTH_SHORT).show();
67 | }
68 | }
69 | });
70 | slide.setOnClickListener(new View.OnClickListener() {
71 | @Override
72 | public void onClick(View v) {
73 | Toast.makeText(parent.getContext().getApplicationContext(), "Slide Clicked!!!!", Toast.LENGTH_SHORT).show();
74 | }
75 | });
76 | return itemView;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/yan/slidelayout/DemoPageAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.yan.slidelayout;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.support.v4.view.PagerAdapter;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | /**
13 | * Created by yan on 17-1-8.
14 | */
15 |
16 | public class DemoPageAdapter extends PagerAdapter {
17 | private List mListData;
18 | private int[] mColors = {Color.GREEN, Color.YELLOW, Color.RED};
19 |
20 | public DemoPageAdapter(Context context) {
21 | mListData = new ArrayList<>();
22 | for (int index=0; index<3; index++) {
23 | View page = LayoutInflater.from(context).inflate(R.layout.item_demo_page, null);
24 | mListData.add(page);
25 | }
26 | }
27 |
28 | @Override
29 | public boolean isViewFromObject(View arg0, Object arg1) {
30 | return arg0 == arg1;
31 | }
32 |
33 | @Override
34 | public int getCount() {
35 | return mListData.size();
36 | }
37 |
38 | @Override
39 | public void destroyItem(ViewGroup container, int position,
40 | Object object) {
41 | container.removeView(mListData.get(position));
42 | }
43 |
44 | @Override
45 | public Object instantiateItem(ViewGroup container, int position) {
46 | TextView view = (TextView) mListData.get(position).findViewById(R.id.content_id);
47 | view.setText("ViewPager"+position);
48 | view.setBackgroundColor(mColors[position%mColors.length]);
49 | container.addView(mListData.get(position), container.getLayoutParams());
50 | return mListData.get(position);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/yan/slidelayout/MainActivity.java:
--------------------------------------------------------------------------------
1 | package cn.yan.slidelayout;
2 |
3 | import android.support.v4.view.ViewPager;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.widget.ListView;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 | private ListView mListView;
10 | private ViewPager mViewPager;
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 |
17 | mListView = (ListView) this.findViewById(R.id.listview_id);
18 | DemoListAdapter adapter = new DemoListAdapter();
19 | mListView.setAdapter(adapter);
20 |
21 | mViewPager = (ViewPager) this.findViewById(R.id.viewpager);
22 | DemoPageAdapter pageAdapter = new DemoPageAdapter(this);
23 | mViewPager.setAdapter(pageAdapter);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sqrt_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/SlideLayout/5cb92e09fb34a25c45ef42e830453687b0a23078/app/src/main/res/drawable/sqrt_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
20 |
25 |
31 |
32 |
38 |
39 |
40 |
45 |
51 |
52 |
58 |
59 |
60 |
65 |
71 |
72 |
78 |
79 |
80 |
85 |
91 |
92 |
98 |
99 |
100 |
101 |
107 |
112 |
113 |
118 |
119 |
120 |
126 |
131 |
136 |
137 |
143 |
144 |
145 |
151 |
155 |
159 |
163 |
168 |
169 |
174 |
175 |
180 |
181 |
186 |
187 |
192 |
193 |
198 |
199 |
200 |
206 |
207 |
208 |
209 |
210 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_demo_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
11 |
15 |
21 |
22 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_demo_page.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
14 |
15 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/SlideLayout/5cb92e09fb34a25c45ef42e830453687b0a23078/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/SlideLayout/5cb92e09fb34a25c45ef42e830453687b0a23078/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/SlideLayout/5cb92e09fb34a25c45ef42e830453687b0a23078/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/SlideLayout/5cb92e09fb34a25c45ef42e830453687b0a23078/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/SlideLayout/5cb92e09fb34a25c45ef42e830453687b0a23078/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SlideLayout
3 |
4 |
5 | fdsfsgfdsgsgdsg 1
6 | fdsfsgfdsgsgdsg 3
7 | fdsfsgfdsgsgdsg 5
8 | fdsfsgfdsgsgdsg 7
9 | fdsfsgfdsgsgdsg 9
10 | fdsfsgfdsgsgdsg a
11 | fdsfsgfdsgsgdsg b
12 | fdsfsgfdsgsgdsg c
13 | fdsfsgfdsgsgdsg d
14 | fdsfsgfdsgsgdsg e
15 | fdsfsgfdsgsgdsg f
16 | fdsfsgfdsgsgdsg g
17 | fdsfsgfdsgsgdsg h
18 | fdsfsgfdsgsgdsg i
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/cn/yan/slidelayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.yan.slidelayout;
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 | }
--------------------------------------------------------------------------------
/art/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/SlideLayout/5cb92e09fb34a25c45ef42e830453687b0a23078/art/demo.gif
--------------------------------------------------------------------------------
/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.2.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 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanbober/SlideLayout/5cb92e09fb34a25c45ef42e830453687b0a23078/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 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.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/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 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 24
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:24.2.1'
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
--------------------------------------------------------------------------------
/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 /usr/yan/android-sdk-linux/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/src/androidTest/java/cn/yan/library/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package cn.yan.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("cn.yan.library.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/yan/library/MiniSlideRightLayout.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2016 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.library;
25 |
26 | import android.content.Context;
27 | import android.util.AttributeSet;
28 | import android.view.MotionEvent;
29 | import android.view.View;
30 | import android.widget.LinearLayout;
31 | import android.widget.Scroller;
32 | /**
33 | * like SlidingPaneLayout, but this used to mini lib and only support right slide.
34 | * used to no support v4 import.
35 | */
36 | public class MiniSlideRightLayout extends LinearLayout {
37 | public static final int STATE_CLOSE = 0;
38 | public static final int STATE_SLIDING = 1;
39 | public static final int STATE_OPEN = 2;
40 |
41 | private View mContentView;
42 | private View mSlideView;
43 |
44 | private Scroller mScroller;
45 |
46 | private int mLastX = 0;
47 | private int mLastY = 0;
48 |
49 | private int mSlideSensitiveWidth = 0;
50 |
51 | private boolean mIsScrolling = false;
52 |
53 | public MiniSlideRightLayout(Context context) {
54 | this(context, null);
55 | }
56 |
57 | public MiniSlideRightLayout(Context context, AttributeSet attrs) {
58 | this(context, attrs, 0);
59 | }
60 |
61 | public MiniSlideRightLayout(Context context, AttributeSet attrs, int defStyleAttr) {
62 | super(context, attrs, defStyleAttr);
63 | init(context, attrs);
64 | }
65 |
66 | private void init(Context context, AttributeSet attrs) {
67 | setOrientation(HORIZONTAL);
68 | mScroller = new Scroller(context);
69 | }
70 |
71 | @Override
72 | protected void onFinishInflate() {
73 | super.onFinishInflate();
74 | if (getChildCount() != 2) {
75 | throw new IllegalArgumentException("SlideLayout only need contains two child (content and slide).");
76 | }
77 |
78 | mContentView = getChildAt(0);
79 | mSlideView = getChildAt(1);
80 | }
81 |
82 | public int getSlideState() {
83 | int retValue = STATE_CLOSE;
84 | if (mIsScrolling) {
85 | retValue = STATE_SLIDING;
86 | } else {
87 | retValue = (getScrollX() == 0) ? STATE_CLOSE : STATE_OPEN;
88 | }
89 | return retValue;
90 | }
91 |
92 | public void smoothCloseSlide() {
93 | smoothScrollTo(0, 0);
94 | }
95 |
96 | public void smoothOpenSlide() {
97 | smoothScrollTo(mSlideView.getMeasuredWidth(), 0);
98 | }
99 |
100 | @Override
101 | public boolean onInterceptTouchEvent(MotionEvent event) {
102 | return mIsScrolling || super.onInterceptTouchEvent(event);
103 | }
104 |
105 | @Override
106 | public boolean dispatchTouchEvent(MotionEvent event) {
107 | int eventX = (int) event.getX();
108 | int eventY = (int) event.getY();
109 | int scrollX = getScrollX();
110 |
111 | switch (event.getAction()) {
112 | case MotionEvent.ACTION_DOWN:
113 | mLastX = (int) event.getX();
114 | mLastY = (int) event.getY();
115 | mIsScrolling = false;
116 | //Maybe child not set OnClickListener, so ACTION_DOWN need to return true and use super.
117 | super.dispatchTouchEvent(event);
118 | return true;
119 | case MotionEvent.ACTION_MOVE:
120 | int offsetX = eventX - mLastX;
121 | int offsetY = eventY - mLastY;
122 | if (Math.abs(offsetX) - Math.abs(offsetY) < 1) {
123 | break;
124 | }
125 | getParent().requestDisallowInterceptTouchEvent(true);
126 | mIsScrolling = true;
127 | int newScrollX = scrollX - offsetX;
128 | if (newScrollX < 0) {
129 | newScrollX = 0;
130 | } else if (newScrollX > mSlideView.getMeasuredWidth()) {
131 | newScrollX = mSlideView.getMeasuredWidth();
132 | }
133 | scrollTo(newScrollX, 0);
134 | break;
135 | case MotionEvent.ACTION_UP:
136 | case MotionEvent.ACTION_CANCEL:
137 | mIsScrolling = false;
138 | getParent().requestDisallowInterceptTouchEvent(false);
139 | int finalScrollX = 0;
140 | mSlideSensitiveWidth = mSlideView.getMeasuredWidth() / 2;
141 | if (scrollX > mSlideSensitiveWidth) {
142 | finalScrollX = mSlideView.getMeasuredWidth();
143 | }
144 | smoothScrollTo(finalScrollX, 0);
145 | break;
146 | }
147 |
148 | mLastX = eventX;
149 | mLastY = eventY;
150 | return super.dispatchTouchEvent(event);
151 | }
152 |
153 | private void smoothScrollTo(int destX, int destY) {
154 | int scrollX = getScrollX();
155 | int deltaX = destX - scrollX;
156 | int scrollY = getScrollY();
157 | int deltaY = destY - scrollY;
158 | mScroller.startScroll(scrollX, scrollY, deltaX, deltaY,
159 | (int) (Math.abs(Math.sqrt(deltaX*deltaX + deltaY*deltaY)) * 3));
160 | postInvalidate();
161 | }
162 |
163 | @Override
164 | public void computeScroll() {
165 | if (mScroller.computeScrollOffset()) {
166 | scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
167 | postInvalidate();
168 | }
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/yan/library/SlideLayout.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MIT License
3 | *
4 | * Copyright (c) 2016 yanbo
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package cn.yan.library;
25 |
26 | import android.content.Context;
27 | import android.content.res.TypedArray;
28 | import android.util.AttributeSet;
29 | import android.view.MotionEvent;
30 | import android.view.View;
31 | import android.view.ViewConfiguration;
32 | import android.view.ViewGroup;
33 | import android.widget.Scroller;
34 |
35 | /**
36 | * like SlidingPaneLayout, all direction support.
37 | */
38 | public class SlideLayout extends ViewGroup {
39 | public static final int STATE_CLOSE = 0;
40 | public static final int STATE_SLIDING = 1;
41 | public static final int STATE_OPEN = 2;
42 |
43 | private static final int SLIDE_RIGHT = 0;
44 | private static final int SLIDE_LEFT = 1;
45 | private static final int SLIDE_TOP = 2;
46 | private static final int SLIDE_BOTTOM = 3;
47 |
48 | private View mContentView;
49 | private View mSlideView;
50 |
51 | private Scroller mScroller;
52 |
53 | private int mLastX = 0;
54 | private int mLastY = 0;
55 |
56 | private int mSlideCriticalValue = 0;
57 | private boolean mIsScrolling = false;
58 | private int mSlideDirection;
59 |
60 | public SlideLayout(Context context) {
61 | this(context, null);
62 | }
63 |
64 | public SlideLayout(Context context, AttributeSet attrs) {
65 | this(context, attrs, 0);
66 | }
67 |
68 | public SlideLayout(Context context, AttributeSet attrs, int defStyleAttr) {
69 | super(context, attrs, defStyleAttr);
70 | init(context, attrs);
71 | }
72 |
73 | private void init(Context context, AttributeSet attrs) {
74 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SlideLayout);
75 | mSlideDirection = typedArray.getInt(R.styleable.SlideLayout_slideDirection, SLIDE_RIGHT);
76 | mSlideCriticalValue = typedArray.getDimensionPixelSize(R.styleable.SlideLayout_slideCriticalValue, 0);
77 | typedArray.recycle();
78 |
79 | mScroller = new Scroller(context);
80 | }
81 |
82 | public int getSlideState() {
83 | int retValue = STATE_CLOSE;
84 | if (mIsScrolling) {
85 | retValue = STATE_SLIDING;
86 | } else {
87 | int scrollOffset = (mSlideDirection == SLIDE_LEFT || mSlideDirection == SLIDE_RIGHT) ?
88 | getScrollX() : getScrollY();
89 | retValue = (scrollOffset == 0) ? STATE_CLOSE : STATE_OPEN;
90 | }
91 | return retValue;
92 | }
93 |
94 | public void smoothCloseSlide() {
95 | smoothScrollTo(0, 0);
96 | }
97 |
98 | public void smoothOpenSlide() {
99 | switch (mSlideDirection) {
100 | case SLIDE_RIGHT:
101 | smoothScrollTo(mSlideView.getMeasuredWidth(), 0);
102 | break;
103 | case SLIDE_LEFT:
104 | smoothScrollTo(-mSlideView.getMeasuredWidth(), 0);
105 | break;
106 | case SLIDE_TOP:
107 | smoothScrollTo(0, -mSlideView.getMeasuredHeight());
108 | break;
109 | case SLIDE_BOTTOM:
110 | smoothScrollTo(0, mSlideView.getMeasuredHeight());
111 | break;
112 | }
113 | }
114 |
115 | @Override
116 | protected void onFinishInflate() {
117 | super.onFinishInflate();
118 | if (getChildCount() != 2) {
119 | throw new IllegalArgumentException("SlideLayout only need contains two child (content and slide).");
120 | }
121 |
122 | mContentView = getChildAt(0);
123 | mSlideView = getChildAt(1);
124 | }
125 |
126 | @Override
127 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
128 | measureChildren(widthMeasureSpec, heightMeasureSpec);
129 | setMeasuredDimension(mContentView.getMeasuredWidth(), mContentView.getMeasuredHeight());
130 | }
131 |
132 | @Override
133 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
134 | mContentView.layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
135 | switch (mSlideDirection) {
136 | case SLIDE_LEFT:
137 | mSlideView.layout(-mSlideView.getMeasuredWidth(), 0, 0, getMeasuredHeight());
138 | break;
139 | case SLIDE_RIGHT:
140 | mSlideView.layout(getMeasuredWidth(), 0,
141 | mSlideView.getMeasuredWidth() + getMeasuredWidth(), getMeasuredHeight());
142 | break;
143 | case SLIDE_TOP:
144 | mSlideView.layout(0, -mSlideView.getMeasuredHeight(), getMeasuredWidth(), 0);
145 | break;
146 | case SLIDE_BOTTOM:
147 | mSlideView.layout(0, getMeasuredHeight(),
148 | getMeasuredWidth(), mSlideView.getMeasuredHeight() + getMeasuredHeight());
149 | break;
150 | }
151 | }
152 |
153 | @Override
154 | public boolean onInterceptTouchEvent(MotionEvent event) {
155 | return mIsScrolling || super.onInterceptTouchEvent(event);
156 | }
157 |
158 | @Override
159 | public boolean dispatchTouchEvent(MotionEvent event) {
160 | int eventX = (int) event.getX();
161 | int eventY = (int) event.getY();
162 | int scrollX = getScrollX();
163 | int scrollY = getScrollY();
164 | switch (event.getAction()) {
165 | case MotionEvent.ACTION_DOWN:
166 | mLastX = (int) event.getX();
167 | mLastY = (int) event.getY();
168 | mIsScrolling = false;
169 | //Maybe child not set OnClickListener, so ACTION_DOWN need to return true and use super.
170 | super.dispatchTouchEvent(event);
171 | return true;
172 | case MotionEvent.ACTION_MOVE:
173 | int offsetX = eventX - mLastX;
174 | int offsetY = eventY - mLastY;
175 | int directionMoveOffset = 0;
176 | if (mSlideDirection == SLIDE_LEFT || mSlideDirection == SLIDE_RIGHT) {
177 | directionMoveOffset = Math.abs(offsetX) - Math.abs(offsetY);
178 | } else {
179 | directionMoveOffset = Math.abs(offsetY) - Math.abs(offsetX);
180 | }
181 | if (!mIsScrolling && directionMoveOffset < ViewConfiguration.getTouchSlop()) {
182 | break;
183 | }
184 | getParent().requestDisallowInterceptTouchEvent(true);
185 | mIsScrolling = true;
186 | int newScrollX = 0;
187 | int newScrollY = 0;
188 | switch (mSlideDirection) {
189 | case SLIDE_RIGHT:
190 | newScrollX = scrollX - offsetX;
191 | if (newScrollX < 0) {
192 | newScrollX = 0;
193 | } else if (newScrollX > mSlideView.getMeasuredWidth()) {
194 | newScrollX = mSlideView.getMeasuredWidth();
195 | }
196 | break;
197 | case SLIDE_LEFT:
198 | newScrollX = scrollX - offsetX;
199 | if (newScrollX < -mSlideView.getMeasuredWidth()) {
200 | newScrollX = -mSlideView.getMeasuredWidth();
201 | } else if (newScrollX > 0) {
202 | newScrollX = 0;
203 | }
204 | break;
205 | case SLIDE_TOP:
206 | newScrollY = scrollY - offsetY;
207 | if (newScrollY < -mSlideView.getMeasuredHeight()) {
208 | newScrollY = -mSlideView.getMeasuredHeight();
209 | } else if (newScrollY > 0) {
210 | newScrollY = 0;
211 | }
212 | break;
213 | case SLIDE_BOTTOM:
214 | newScrollY = scrollY - offsetY;
215 | if (newScrollY < 0) {
216 | newScrollY = 0;
217 | } else if (newScrollY > mSlideView.getMeasuredHeight()) {
218 | newScrollY = mSlideView.getMeasuredHeight();
219 | }
220 | break;
221 | }
222 | scrollTo(newScrollX, newScrollY);
223 | break;
224 | case MotionEvent.ACTION_UP:
225 | case MotionEvent.ACTION_CANCEL:
226 | mIsScrolling = false;
227 | getParent().requestDisallowInterceptTouchEvent(false);
228 | int finalScrollX = 0;
229 | int finalScrollY = 0;
230 | switch (mSlideDirection) {
231 | case SLIDE_RIGHT:
232 | if (scrollX > getSlideCriticalValue()) {
233 | finalScrollX = mSlideView.getMeasuredWidth();
234 | }
235 | break;
236 | case SLIDE_LEFT:
237 | if (scrollX < -getSlideCriticalValue()) {
238 | finalScrollX = -mSlideView.getMeasuredWidth();
239 | }
240 | break;
241 | case SLIDE_TOP:
242 | if (scrollY < -getSlideCriticalValue()) {
243 | finalScrollY = -mSlideView.getMeasuredHeight();
244 | }
245 | break;
246 | case SLIDE_BOTTOM:
247 | if (scrollY > getSlideCriticalValue()) {
248 | finalScrollY = mSlideView.getMeasuredHeight();
249 | }
250 | break;
251 | }
252 | smoothScrollTo(finalScrollX, finalScrollY);
253 | break;
254 | }
255 |
256 | mLastX = eventX;
257 | mLastY = eventY;
258 | return super.dispatchTouchEvent(event);
259 | }
260 |
261 | //TODO when mSlideCriticalValue != 0, slide critical need fix.
262 | private int getSlideCriticalValue() {
263 | if (mSlideDirection == SLIDE_LEFT || mSlideDirection == SLIDE_RIGHT) {
264 | if (mSlideCriticalValue == 0) {
265 | mSlideCriticalValue = mSlideView.getMeasuredWidth() / 2;
266 | }
267 | } else {
268 | if (mSlideCriticalValue == 0) {
269 | mSlideCriticalValue = mSlideView.getMeasuredHeight() / 2;
270 | }
271 | }
272 | return mSlideCriticalValue;
273 | }
274 |
275 | private void smoothScrollTo(int destX, int destY) {
276 | int scrollX = getScrollX();
277 | int deltaX = destX - scrollX;
278 | int scrollY = getScrollY();
279 | int deltaY = destY - scrollY;
280 | mScroller.startScroll(scrollX, scrollY, deltaX, deltaY,
281 | (int) (Math.abs(Math.sqrt(deltaX*deltaX + deltaY*deltaY)) * 3));
282 | postInvalidate();
283 | }
284 |
285 | @Override
286 | public void computeScroll() {
287 | if (mScroller.computeScrollOffset()) {
288 | scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
289 | postInvalidate();
290 | }
291 | }
292 | }
293 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/library/src/test/java/cn/yan/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.yan.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 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------