├── README-CN.md
├── README.md
├── app
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── gw
│ │ └── swipebacksample
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── gw
│ │ │ └── swipebacksample
│ │ │ ├── MainActivity.java
│ │ │ ├── MainApplication.java
│ │ │ ├── activity
│ │ │ ├── CommonActivity.java
│ │ │ ├── CommonAttachToActivity.java
│ │ │ ├── HorizontalScrollViewActivity.java
│ │ │ ├── ListViewActivity.java
│ │ │ ├── NestedScrollViewActivity.java
│ │ │ ├── RecyclerViewActivity.java
│ │ │ ├── ScrollViewActivity.java
│ │ │ ├── SwipeRefreshLayoutActivity.java
│ │ │ ├── ViewPagerActivity.java
│ │ │ ├── WebViewActivity.java
│ │ │ └── WxCommonActivity.java
│ │ │ ├── base
│ │ │ ├── BaseActivity.java
│ │ │ ├── BaseSwipeBackActivity.java
│ │ │ └── BaseToolBarActivity.java
│ │ │ └── fragment
│ │ │ └── TestFragment.java
│ └── res
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_attach_to_common.xml
│ │ ├── activity_common.xml
│ │ ├── activity_common_wx.xml
│ │ ├── activity_horizontalscrollview.xml
│ │ ├── activity_listview.xml
│ │ ├── activity_main.xml
│ │ ├── activity_nestedscrollview.xml
│ │ ├── activity_recyclerview.xml
│ │ ├── activity_scrollview.xml
│ │ ├── activity_swipe_refresh_layout.xml
│ │ ├── activity_viewpager.xml
│ │ ├── activity_webview.xml
│ │ ├── fragment_test.xml
│ │ ├── layout_direction.xml
│ │ ├── radio_group.xml
│ │ └── recyclerview_item.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── ids.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── gw
│ └── swipebacksample
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── gw
│ │ └── swipeback
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── gw
│ │ │ └── swipeback
│ │ │ ├── SwipeBackLayout.java
│ │ │ ├── WxSwipeBackLayout.java
│ │ │ └── tools
│ │ │ ├── ActivityLifecycleCallbacksAdapter.java
│ │ │ ├── Util.java
│ │ │ └── WxSwipeBackActivityManager.java
│ └── res
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── gw
│ └── swipeback
│ └── ExampleUnitTest.java
├── sample-apks
└── app-debug-1.0.2.apk
├── screenshot
├── screenshot1.gif
└── screenshot2.gif
└── settings.gradle
/README-CN.md:
--------------------------------------------------------------------------------
1 | SwipeBackLayout
2 | ---
3 | SwipeBackLayout是一个通过手势滑动关闭Activity的库
4 |
5 | 你可以设置滑动关闭的方向,比如FROM_LEFT,FROM_TOP,FROM_RIGHT and FROM_BOTTOM.
6 |
7 | 你也可以设置是否只可以从边缘滑动
8 | ## 截屏
9 |
10 | | 普通风格 | 微信风格 |
11 | | ------------ | ------------- |
12 | |  |  |
13 |
14 | 示例Apk下载
15 | ---
16 | [示例Apk下载](https://github.com/gongwen/SwipeBackLayout/raw/master/sample-apks/app-debug-1.0.2.apk)
17 |
18 | 用法
19 | ---
20 | ##### Gradle
21 | ```
22 | dependencies {
23 | compile 'com.gongwen:swipeback:1.0.2'
24 | }
25 | ```
26 | ###### [布局中使用](app/src/main/res/layout/activity_common.xml)
27 | ```
28 |
37 |
38 |
39 |
40 |
41 | ```
42 |
43 | ```
44 |
53 |
54 |
55 |
56 |
57 |
58 | ```
59 | **注意:**
60 | 如果你想使用WxSwipeBackLayout,你必须在Application中调用 **WxSwipeBackActivityManager.getInstance().init(this)** 去初始化
61 | 如下 :
62 | ```
63 | public class MainApplication extends Application {
64 | @Override
65 | public void onCreate() {
66 | super.onCreate();
67 | WxSwipeBackActivityManager.getInstance().init(this);
68 | }
69 | }
70 | ```
71 |
72 | ###### 属性
73 | | Attribute 属性 | Description 描述 |
74 | |:--- |:---|
75 | | swipeBackFactor | 设置滑动因子 |
76 | | maskAlpha | 设置开始滑动时蒙层的透明度 |
77 | | directionMode | 设置滑动关闭的方向(上下左右) |
78 | | isSwipeFromEdge | 设置是否仅可以从边缘滑动 |
79 |
80 | ###### [代码中使用](app/src/main/java/com/gw/swipebacksample/activity/CommonAttachToActivity.java)
81 | ```
82 | public void onCreate(@Nullable Bundle savedInstanceState) {
83 | super.onCreate(savedInstanceState);
84 | //SwipeBackLayout is included in the layout
85 | setContentView(layoutId);
86 | SwipeBackLayout mSwipeBackLayout = (SwipeBackLayout) findViewById(R.id.swipeBackLayout);
87 | mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_LEFT);
88 | mSwipeBackLayout.setMaskAlpha(125);
89 | mSwipeBackLayout.setSwipeBackFactor(0.5f);
90 | mSwipeBackLayout.setSwipeBackListener(new SwipeBackLayout.OnSwipeBackListener() {
91 | @Override
92 | public void onViewPositionChanged(View mView, float swipeBackFraction, float SWIPE_BACK_FACTOR) {
93 |
94 | }
95 |
96 | @Override
97 | public void onViewSwipeFinished(View mView, boolean isEnd) {
98 |
99 | }
100 | });
101 | }
102 | ```
103 | 或
104 | ```
105 | public void onCreate(@Nullable Bundle savedInstanceState) {
106 | super.onCreate(savedInstanceState);
107 | SwipeBackLayout mSwipeBackLayout = new SwipeBackLayout(this);
108 | mSwipeBackLayout.addView(contentView);
109 | setContentView(mSwipeBackLayout);
110 | }
111 | ```
112 | 或
113 | ```
114 | public void onCreate(@Nullable Bundle savedInstanceState) {
115 | super.onCreate(savedInstanceState);
116 | //SwipeBackLayout is not included in the layout
117 | setContentView(layoutId);
118 | mSwipeBackLayout = new SwipeBackLayout(this);
119 | mSwipeBackLayout.attachToActivity(this);
120 | }
121 | ```
122 | ##### [设置透明主题](app/src/main/res/values/styles.xml)
123 | ```
124 |
128 | ```
129 |
130 | 支持View的类型
131 | ---
132 | SwipeBackLayout必须只有一个子View.
133 |
134 | 例如:
135 | * LinearLayout,RelativeLayout,FrameLayout,TableLayout etc.
136 | * ScrollView,HorizontalScrollView,NestedScrollView etc.
137 | * RecyclerView,the subClass of AbsListView(ListView etc.)
138 | * ViewPager,WebView etc.
139 |
140 | 参考
141 | ---
142 | ##### [ViewDragHelper详解](http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/0911/1680.html)
143 | ##### [SwipeBack](https://github.com/liuguangqiang/SwipeBack/)
144 | ##### [BGASwipeBackLayout-Android](https://github.com/bingoogolapple/BGASwipeBackLayout-Android)
145 | License
146 | ---
147 | Copyright (C) 2017 1798550470@qq.com
148 |
149 | Licensed under the Apache License, Version 2.0 (the "License");
150 | you may not use this file except in compliance with the License.
151 | You may obtain a copy of the License at
152 |
153 | http://www.apache.org/licenses/LICENSE-2.0
154 |
155 | Unless required by applicable law or agreed to in writing, software
156 | distributed under the License is distributed on an "AS IS" BASIS,
157 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
158 | See the License for the specific language governing permissions and
159 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | SwipeBackLayout
2 | ---
3 | [中文版点我](README-CN.md)
4 |
5 | SwipeBackLayout is an android library that can finish an activity by using gesture.
6 |
7 | You can set the slide direction,such as FROM_LEFT,FROM_TOP,FROM_RIGHT and FROM_BOTTOM.
8 |
9 | You can also set whether it can only slide from the edge.
10 | ## Screenshots
11 |
12 | | Custom-Style | WeChat-Style |
13 | | ------------ | ------------- |
14 | |  |  |
15 |
16 | Sample Apk Download
17 | ---
18 | [sample apk download](https://github.com/gongwen/SwipeBackLayout/raw/master/sample-apks/app-debug-1.0.2.apk)
19 |
20 | Usage
21 | ---
22 | ##### Gradle
23 | ```
24 | dependencies {
25 | compile 'com.gongwen:swipeback:1.0.2'
26 | }
27 | ```
28 | ###### [Layout](app/src/main/res/layout/activity_common.xml)
29 | ```
30 |
39 |
40 |
41 |
42 |
43 | ```
44 |
45 | ```
46 |
55 |
56 |
57 |
58 |
59 |
60 | ```
61 | **Attention:**
62 | If you are using WxSwipeBackLayout , you must call **WxSwipeBackActivityManager.getInstance().init(this)** to init it in Application.
63 | just like :
64 | ```
65 | public class MainApplication extends Application {
66 | @Override
67 | public void onCreate() {
68 | super.onCreate();
69 | WxSwipeBackActivityManager.getInstance().init(this);
70 | }
71 | }
72 | ```
73 |
74 | ###### Attributes
75 | | Attribute 属性 | Description 描述 |
76 | |:--- |:---|
77 | | swipeBackFactor | set the factor of swipeback |
78 | | maskAlpha | set the background alpha at the beginning of swipeback |
79 | | directionMode | set the direction of swiping to finish |
80 | | isSwipeFromEdge | set whether it can only slide from the edge |
81 |
82 | ###### [Code](app/src/main/java/com/gw/swipebacksample/activity/CommonAttachToActivity.java)
83 | ```
84 | public void onCreate(@Nullable Bundle savedInstanceState) {
85 | super.onCreate(savedInstanceState);
86 | //SwipeBackLayout is included in the layout
87 | setContentView(layoutId);
88 | SwipeBackLayout mSwipeBackLayout = (SwipeBackLayout) findViewById(R.id.swipeBackLayout);
89 | mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_LEFT);
90 | mSwipeBackLayout.setMaskAlpha(125);
91 | mSwipeBackLayout.setSwipeBackFactor(0.5f);
92 | mSwipeBackLayout.setSwipeBackListener(new SwipeBackLayout.OnSwipeBackListener() {
93 | @Override
94 | public void onViewPositionChanged(View mView, float swipeBackFraction, float SWIPE_BACK_FACTOR) {
95 |
96 | }
97 |
98 | @Override
99 | public void onViewSwipeFinished(View mView, boolean isEnd) {
100 |
101 | }
102 | });
103 | }
104 | ```
105 | or
106 | ```
107 | public void onCreate(@Nullable Bundle savedInstanceState) {
108 | super.onCreate(savedInstanceState);
109 | SwipeBackLayout mSwipeBackLayout = new SwipeBackLayout(this);
110 | mSwipeBackLayout.addView(contentView);
111 | setContentView(mSwipeBackLayout);
112 | }
113 | ```
114 | or
115 | ```
116 | public void onCreate(@Nullable Bundle savedInstanceState) {
117 | super.onCreate(savedInstanceState);
118 | //SwipeBackLayout is not included in the layout
119 | setContentView(layoutId);
120 | mSwipeBackLayout = new SwipeBackLayout(this);
121 | mSwipeBackLayout.attachToActivity(this);
122 | }
123 | ```
124 | ##### [Theme](app/src/main/res/values/styles.xml)
125 | ```
126 |
130 | ```
131 |
132 | Support Views
133 | ---
134 | SwipeBackLayout must contains only one direct child.
135 |
136 | Such as:
137 | * LinearLayout,RelativeLayout,FrameLayout,TableLayout etc.
138 | * ScrollView,HorizontalScrollView,NestedScrollView etc.
139 | * RecyclerView,the subClass of AbsListView(ListView etc.)
140 | * ViewPager,WebView etc.
141 |
142 | reference
143 | ---
144 | ##### [ViewDragHelper详解](http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/0911/1680.html)
145 | ##### [SwipeBack](https://github.com/liuguangqiang/SwipeBack/)
146 | ##### [BGASwipeBackLayout-Android](https://github.com/bingoogolapple/BGASwipeBackLayout-Android)
147 | License
148 | ---
149 | Copyright (C) 2017 1798550470@qq.com
150 |
151 | Licensed under the Apache License, Version 2.0 (the "License");
152 | you may not use this file except in compliance with the License.
153 | You may obtain a copy of the License at
154 |
155 | http://www.apache.org/licenses/LICENSE-2.0
156 |
157 | Unless required by applicable law or agreed to in writing, software
158 | distributed under the License is distributed on an "AS IS" BASIS,
159 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
160 | See the License for the specific language governing permissions and
161 | limitations under the License.
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.gw.swipebacksample"
8 | minSdkVersion 14
9 | targetSdkVersion 25
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 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | implementation 'com.android.support:appcompat-v7:25.4.0'
25 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation 'com.android.support.test:runner:0.5'
28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
29 |
30 | implementation "com.android.support:recyclerview-v7:25.4.0"
31 | implementation 'com.gongwen:swipeback:1.0.2'
32 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/fenghuacaijing/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/gw/swipebacksample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample;
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 | * Instrumented 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.gw.swipebacksample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
27 |
30 |
33 |
36 |
39 |
42 |
45 |
48 |
51 |
54 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.IdRes;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.gw.swipebacksample.activity.CommonActivity;
10 | import com.gw.swipebacksample.activity.CommonAttachToActivity;
11 | import com.gw.swipebacksample.activity.HorizontalScrollViewActivity;
12 | import com.gw.swipebacksample.activity.ListViewActivity;
13 | import com.gw.swipebacksample.activity.NestedScrollViewActivity;
14 | import com.gw.swipebacksample.activity.RecyclerViewActivity;
15 | import com.gw.swipebacksample.activity.ScrollViewActivity;
16 | import com.gw.swipebacksample.activity.SwipeRefreshLayoutActivity;
17 | import com.gw.swipebacksample.activity.ViewPagerActivity;
18 | import com.gw.swipebacksample.activity.WebViewActivity;
19 | import com.gw.swipebacksample.activity.WxCommonActivity;
20 | import com.gw.swipebacksample.base.BaseToolBarActivity;
21 |
22 | public class MainActivity extends BaseToolBarActivity implements View.OnClickListener {
23 | private Button btnCommon;
24 | private Button btnWxCommon;
25 | private Button btnAttachToCommon;
26 | private Button btnScrollView;
27 | private Button btnHorizontalScrollView;
28 | private Button btnNestedScrollView;
29 | private Button btnRecyclerView;
30 | private Button btnListView;
31 | private Button btnViewPager;
32 | private Button btnWebView;
33 | private Button btnSwipeRefreshLayout;
34 |
35 | @Override
36 | protected int getLayoutId() {
37 | return R.layout.activity_main;
38 | }
39 |
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 |
44 | btnCommon = initButton(R.id.btnCommon);
45 | btnWxCommon = initButton(R.id.btnWxCommon);
46 | btnAttachToCommon = initButton(R.id.btnAttachToCommon);
47 | btnScrollView = initButton(R.id.btnScrollView);
48 | btnHorizontalScrollView = initButton(R.id.btnHorizontalScrollView);
49 | btnNestedScrollView = initButton(R.id.btnNestedScrollView);
50 | btnListView = initButton(R.id.btnListView);
51 | btnRecyclerView = initButton(R.id.btnRecyclerView);
52 | btnWebView = initButton(R.id.btnWebView);
53 | btnViewPager = initButton(R.id.btnViewPager);
54 | btnSwipeRefreshLayout = initButton(R.id.btnSwipeRefreshLayout);
55 | }
56 |
57 | private Button initButton(@IdRes int id) {
58 | Button btn = (Button) findViewById(id);
59 | btn.setOnClickListener(this);
60 | return btn;
61 | }
62 |
63 |
64 | @Override
65 | public void onClick(View view) {
66 | switch (view.getId()) {
67 | case R.id.btnCommon:
68 | startActivity(CommonActivity.class);
69 | break;
70 | case R.id.btnWxCommon:
71 | startActivity(WxCommonActivity.class);
72 | break;
73 | case R.id.btnAttachToCommon:
74 | startActivity(CommonAttachToActivity.class);
75 | break;
76 | case R.id.btnScrollView:
77 | startActivity(ScrollViewActivity.class);
78 | break;
79 | case R.id.btnHorizontalScrollView:
80 | startActivity(HorizontalScrollViewActivity.class);
81 | break;
82 | case R.id.btnNestedScrollView:
83 | startActivity(NestedScrollViewActivity.class);
84 | break;
85 | case R.id.btnListView:
86 | startActivity(ListViewActivity.class);
87 | break;
88 | case R.id.btnRecyclerView:
89 | startActivity(RecyclerViewActivity.class);
90 | break;
91 | case R.id.btnViewPager:
92 | startActivity(ViewPagerActivity.class);
93 | break;
94 | case R.id.btnWebView:
95 | startActivity(WebViewActivity.class);
96 | break;
97 | case R.id.btnSwipeRefreshLayout:
98 | startActivity(SwipeRefreshLayoutActivity.class);
99 | break;
100 | }
101 | }
102 |
103 | public void startActivity(Class> clazz) {
104 | startActivity(new Intent(MainActivity.this, clazz));
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample;
2 |
3 | import android.app.Application;
4 |
5 | import com.gw.swipeback.tools.WxSwipeBackActivityManager;
6 |
7 | /**
8 | * Created by GongWen on 17/9/4.
9 | */
10 |
11 | public class MainApplication extends Application {
12 | @Override
13 | public void onCreate() {
14 | super.onCreate();
15 | WxSwipeBackActivityManager.getInstance().init(this);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/activity/CommonActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 |
6 | import com.gw.swipeback.SwipeBackLayout;
7 | import com.gw.swipebacksample.R;
8 | import com.gw.swipebacksample.base.BaseSwipeBackActivity;
9 |
10 | /**
11 | * Created by GongWen on 17/8/24.
12 | */
13 |
14 | public class CommonActivity extends BaseSwipeBackActivity {
15 |
16 | @Override
17 | protected int getLayoutId() {
18 | return R.layout.activity_common;
19 | }
20 |
21 | @Override
22 | protected void onCreate(@Nullable Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | switch (mSwipeBackLayout.getDirectionMode()) {
25 | case SwipeBackLayout.FROM_LEFT:
26 | fromLeftRb.setChecked(true);
27 | break;
28 | case SwipeBackLayout.FROM_TOP:
29 | fromTopRb.setChecked(true);
30 | break;
31 | case SwipeBackLayout.FROM_RIGHT:
32 | fromRightRb.setChecked(true);
33 | break;
34 | case SwipeBackLayout.FROM_BOTTOM:
35 | fromBottomRb.setChecked(true);
36 | break;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/activity/CommonAttachToActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.widget.CompoundButton;
6 | import android.widget.RadioButton;
7 |
8 | import com.gw.swipeback.SwipeBackLayout;
9 | import com.gw.swipebacksample.R;
10 | import com.gw.swipebacksample.base.BaseToolBarActivity;
11 |
12 | /**
13 | * Created by GongWen on 17/8/24.
14 | */
15 |
16 | public class CommonAttachToActivity extends BaseToolBarActivity implements CompoundButton.OnCheckedChangeListener {
17 | private SwipeBackLayout mSwipeBackLayout;
18 | private RadioButton fromLeftRb;
19 | private RadioButton fromTopRb;
20 | private RadioButton fromRightRb;
21 | private RadioButton fromBottomRb;
22 |
23 | @Override
24 | protected int getLayoutId() {
25 | return R.layout.activity_attach_to_common;
26 | }
27 |
28 | @Override
29 | protected void onCreate(@Nullable Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | fromLeftRb = (RadioButton) findViewById(R.id.fromLeftRb);
32 | fromLeftRb.setOnCheckedChangeListener(this);
33 | fromTopRb = (RadioButton) findViewById(R.id.fromTopRb);
34 | fromTopRb.setOnCheckedChangeListener(this);
35 | fromRightRb = (RadioButton) findViewById(R.id.fromRightRb);
36 | fromRightRb.setOnCheckedChangeListener(this);
37 | fromBottomRb = (RadioButton) findViewById(R.id.fromBottomRb);
38 | fromBottomRb.setOnCheckedChangeListener(this);
39 |
40 | mSwipeBackLayout = new SwipeBackLayout(this);
41 | mSwipeBackLayout.attachToActivity(this);
42 | }
43 |
44 | @Override
45 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
46 | if (isChecked) {
47 | switch (buttonView.getId()) {
48 | case R.id.fromLeftRb:
49 | mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_LEFT);
50 | break;
51 | case R.id.fromTopRb:
52 | mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_TOP);
53 | break;
54 | case R.id.fromRightRb:
55 | mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_RIGHT);
56 | break;
57 | case R.id.fromBottomRb:
58 | mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_BOTTOM);
59 | break;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/activity/HorizontalScrollViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.activity;
2 |
3 | import com.gw.swipebacksample.R;
4 | import com.gw.swipebacksample.base.BaseSwipeBackActivity;
5 |
6 | /**
7 | * Created by GongWen on 17/8/24.
8 | */
9 |
10 | public class HorizontalScrollViewActivity extends BaseSwipeBackActivity {
11 |
12 | @Override
13 | protected int getLayoutId() {
14 | return R.layout.activity_horizontalscrollview;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/activity/ListViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.view.View;
6 | import android.widget.AdapterView;
7 | import android.widget.ArrayAdapter;
8 | import android.widget.ListView;
9 | import android.widget.SimpleAdapter;
10 | import android.widget.Toast;
11 |
12 | import com.gw.swipebacksample.R;
13 | import com.gw.swipebacksample.base.BaseSwipeBackActivity;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | /**
19 | * Created by GongWen on 17/8/24.
20 | */
21 |
22 | public class ListViewActivity extends BaseSwipeBackActivity {
23 | private ListView mListView;
24 | private List dataList;
25 |
26 | @Override
27 | protected int getLayoutId() {
28 | return R.layout.activity_listview;
29 | }
30 |
31 | @Override
32 | protected void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | mListView = (ListView) findViewById(R.id.listView);
35 | dataList = new ArrayList<>();
36 | for (int i = 0; i < 30; i++) {
37 | dataList.add("Test" + i);
38 | }
39 | ArrayAdapter adapter = new ArrayAdapter(this,
40 | android.R.layout.simple_expandable_list_item_1,
41 | dataList);
42 | mListView.setAdapter(adapter);
43 | mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
44 |
45 | @Override
46 | public void onItemClick(AdapterView> parent, View view,
47 | int position, long id) {
48 | Toast.makeText(getApplicationContext(),
49 | dataList.get(position), Toast.LENGTH_LONG)
50 | .show();
51 | }
52 | });
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/activity/NestedScrollViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.activity;
2 |
3 | import com.gw.swipebacksample.R;
4 | import com.gw.swipebacksample.base.BaseSwipeBackActivity;
5 |
6 | /**
7 | * Created by GongWen on 17/8/24.
8 | */
9 |
10 | public class NestedScrollViewActivity extends BaseSwipeBackActivity {
11 |
12 | @Override
13 | protected int getLayoutId() {
14 | return R.layout.activity_nestedscrollview;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/activity/RecyclerViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.Gravity;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 |
12 | import com.gw.swipebacksample.R;
13 | import com.gw.swipebacksample.base.BaseSwipeBackActivity;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | /**
19 | * Created by GongWen on 17/8/24.
20 | */
21 |
22 | public class RecyclerViewActivity extends BaseSwipeBackActivity {
23 | private float density;
24 | private RecyclerView mRecyclerView;
25 | private List dataList;
26 |
27 | @Override
28 | protected int getLayoutId() {
29 | return R.layout.activity_recyclerview;
30 | }
31 |
32 | @Override
33 | protected void onCreate(@Nullable Bundle savedInstanceState) {
34 | density = getResources().getDisplayMetrics().density;
35 | super.onCreate(savedInstanceState);
36 | mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
37 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
38 | dataList = new ArrayList<>();
39 | for (int i = 0; i < 30; i++) {
40 | dataList.add("Test" + i);
41 | }
42 | mRecyclerView.setAdapter(adapter);
43 | }
44 |
45 | private RecyclerView.Adapter adapter = new RecyclerView.Adapter() {
46 | @Override
47 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
48 | TextView textView = new TextView(RecyclerViewActivity.this);
49 | textView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (40 * density)));
50 | textView.setGravity(Gravity.CENTER);
51 | return new ViewHolder(textView);
52 | }
53 |
54 | @Override
55 | public void onBindViewHolder(ViewHolder holder, int position) {
56 | holder.tv.setText(dataList.get(position));
57 | }
58 |
59 | @Override
60 | public int getItemCount() {
61 | return dataList.size();
62 | }
63 | };
64 |
65 | static class ViewHolder extends RecyclerView.ViewHolder {
66 | public TextView tv;
67 |
68 | public ViewHolder(View itemView) {
69 | super(itemView);
70 | tv = (TextView) itemView;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/activity/ScrollViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.util.Log;
6 |
7 | import com.gw.swipebacksample.R;
8 | import com.gw.swipebacksample.base.BaseSwipeBackActivity;
9 |
10 | /**
11 | * Created by GongWen on 17/8/24.
12 | */
13 |
14 | public class ScrollViewActivity extends BaseSwipeBackActivity {
15 |
16 | @Override
17 | protected int getLayoutId() {
18 | return R.layout.activity_scrollview;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/activity/SwipeRefreshLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.widget.SwipeRefreshLayout;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.Gravity;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import com.gw.swipebacksample.R;
15 | import com.gw.swipebacksample.base.BaseSwipeBackActivity;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | /**
21 | * Created by GongWen on 17/8/31.
22 | */
23 |
24 | public class SwipeRefreshLayoutActivity extends BaseSwipeBackActivity {
25 | private float density;
26 | private SwipeRefreshLayout mSwipeRefreshLayout;
27 | private RecyclerView mRecyclerView;
28 | private List dataList;
29 |
30 | @Override
31 | protected int getLayoutId() {
32 | return R.layout.activity_swipe_refresh_layout;
33 | }
34 |
35 | @Override
36 | protected void onCreate(@Nullable Bundle savedInstanceState) {
37 | density = getResources().getDisplayMetrics().density;
38 | super.onCreate(savedInstanceState);
39 | mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
40 | mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
41 | @Override
42 | public void onRefresh() {
43 | mSwipeRefreshLayout.postDelayed(new Runnable() {
44 | @Override
45 | public void run() {
46 | Toast.makeText(
47 | SwipeRefreshLayoutActivity.this,
48 | "The refresh is finished!",
49 | Toast.LENGTH_SHORT).show();
50 | mSwipeRefreshLayout.setRefreshing(false);
51 | }
52 | }, 2000);
53 |
54 | }
55 | });
56 | mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
57 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
58 | dataList = new ArrayList<>();
59 | for (int i = 0; i < 30; i++) {
60 | dataList.add("Test" + i);
61 | }
62 | mRecyclerView.setAdapter(adapter);
63 | }
64 |
65 | private RecyclerView.Adapter adapter = new RecyclerView.Adapter() {
66 | @Override
67 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
68 | TextView textView = new TextView(SwipeRefreshLayoutActivity.this);
69 | textView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (40 * density)));
70 | textView.setGravity(Gravity.CENTER);
71 | return new ViewHolder(textView);
72 | }
73 |
74 | @Override
75 | public void onBindViewHolder(ViewHolder holder, int position) {
76 | holder.tv.setText(dataList.get(position));
77 | }
78 |
79 | @Override
80 | public int getItemCount() {
81 | return dataList.size();
82 | }
83 | };
84 |
85 | static class ViewHolder extends RecyclerView.ViewHolder {
86 | public TextView tv;
87 |
88 | public ViewHolder(View itemView) {
89 | super(itemView);
90 | tv = (TextView) itemView;
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/activity/ViewPagerActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentPagerAdapter;
7 | import android.support.v4.view.ViewPager;
8 |
9 | import com.gw.swipebacksample.R;
10 | import com.gw.swipebacksample.base.BaseSwipeBackActivity;
11 | import com.gw.swipebacksample.fragment.TestFragment;
12 |
13 | /**
14 | * Created by GongWen on 17/8/24.
15 | */
16 |
17 | public class ViewPagerActivity extends BaseSwipeBackActivity {
18 | private ViewPager mViewPager;
19 |
20 | @Override
21 | protected int getLayoutId() {
22 | return R.layout.activity_viewpager;
23 | }
24 |
25 | @Override
26 | protected void onCreate(@Nullable Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | mViewPager = (ViewPager) findViewById(R.id.viewPager);
29 | mViewPager.setAdapter(adapter);
30 | }
31 |
32 | private FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
33 | @Override
34 | public Fragment getItem(int position) {
35 | return TestFragment.newInstance(String.valueOf(position));
36 | }
37 |
38 | @Override
39 | public int getCount() {
40 | return 3;
41 | }
42 | };
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/activity/WebViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.webkit.WebView;
6 | import android.webkit.WebViewClient;
7 |
8 | import com.gw.swipebacksample.R;
9 | import com.gw.swipebacksample.base.BaseSwipeBackActivity;
10 |
11 | /**
12 | * Created by GongWen on 17/8/24.
13 | */
14 |
15 | public class WebViewActivity extends BaseSwipeBackActivity {
16 | private WebView mWebView;
17 |
18 | @Override
19 | protected int getLayoutId() {
20 | return R.layout.activity_webview;
21 | }
22 |
23 | @Override
24 | protected void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | mWebView = (WebView) findViewById(R.id.webView);
27 | mWebView.getSettings().setJavaScriptEnabled(true);
28 | mWebView.setWebViewClient(new WebViewClient() {
29 | @Override
30 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
31 | view.loadUrl(url);
32 | return true;
33 | }
34 | });
35 | mWebView.loadUrl("https://wap.baidu.com");
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/activity/WxCommonActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 |
6 | import com.gw.swipebacksample.R;
7 | import com.gw.swipebacksample.base.BaseToolBarActivity;
8 |
9 | /**
10 | * Created by GongWen on 17/8/24.
11 | */
12 |
13 | public class WxCommonActivity extends BaseToolBarActivity {
14 |
15 | @Override
16 | protected int getLayoutId() {
17 | return R.layout.activity_common_wx;
18 | }
19 |
20 | @Override
21 | protected void onCreate(@Nullable Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.base;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 |
5 | /**
6 | * Created by GongWen on 17/8/24.
7 | */
8 |
9 | public class BaseActivity extends AppCompatActivity {
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/base/BaseSwipeBackActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.widget.CompoundButton;
6 | import android.widget.RadioButton;
7 |
8 | import com.gw.swipeback.SwipeBackLayout;
9 | import com.gw.swipebacksample.R;
10 |
11 | /**
12 | * Created by GongWen on 17/8/25.
13 | */
14 |
15 | public abstract class BaseSwipeBackActivity extends BaseToolBarActivity implements CompoundButton.OnCheckedChangeListener {
16 | protected SwipeBackLayout mSwipeBackLayout;
17 | protected RadioButton fromLeftRb;
18 | protected RadioButton fromTopRb;
19 | protected RadioButton fromRightRb;
20 | protected RadioButton fromBottomRb;
21 |
22 | @Override
23 | protected void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | mSwipeBackLayout = (SwipeBackLayout) findViewById(R.id.swipeBackLayout);
26 | fromLeftRb = (RadioButton) findViewById(R.id.fromLeftRb);
27 | fromLeftRb.setOnCheckedChangeListener(this);
28 | fromTopRb = (RadioButton) findViewById(R.id.fromTopRb);
29 | fromTopRb.setOnCheckedChangeListener(this);
30 | fromRightRb = (RadioButton) findViewById(R.id.fromRightRb);
31 | fromRightRb.setOnCheckedChangeListener(this);
32 | fromBottomRb = (RadioButton) findViewById(R.id.fromBottomRb);
33 | fromBottomRb.setOnCheckedChangeListener(this);
34 | }
35 |
36 | @Override
37 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
38 | if (isChecked) {
39 | switch (buttonView.getId()) {
40 | case R.id.fromLeftRb:
41 | mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_LEFT);
42 | break;
43 | case R.id.fromTopRb:
44 | mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_TOP);
45 | break;
46 | case R.id.fromRightRb:
47 | mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_RIGHT);
48 | break;
49 | case R.id.fromBottomRb:
50 | mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_BOTTOM);
51 | break;
52 | }
53 | }
54 | }
55 | }
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/base/BaseToolBarActivity.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 |
8 | import com.gw.swipebacksample.R;
9 |
10 | /**
11 | * Created by GongWen on 17/8/24.
12 | */
13 |
14 | public abstract class BaseToolBarActivity extends AppCompatActivity {
15 | protected final String TAG = getClass().getSimpleName();
16 | protected Toolbar toolbar;
17 |
18 | @Override
19 | protected void onCreate(@Nullable Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(getLayoutId());
22 | setTitle(TAG);
23 | toolbar = (Toolbar) findViewById(R.id.toolbar);
24 | setSupportActionBar(toolbar);
25 | }
26 |
27 | protected abstract int getLayoutId();
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gw/swipebacksample/fragment/TestFragment.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.TextView;
9 |
10 | import com.gw.swipebacksample.R;
11 |
12 | public class TestFragment extends Fragment {
13 |
14 | private static final String EXTRA_TITLE = "EXTRA_TITLE";
15 |
16 | public static TestFragment newInstance(String title) {
17 | TestFragment testFragment = new TestFragment();
18 | Bundle bundle = new Bundle();
19 | bundle.putString(EXTRA_TITLE, title);
20 | testFragment.setArguments(bundle);
21 | return testFragment;
22 | }
23 |
24 | @Override
25 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
26 | return inflater.inflate(R.layout.fragment_test, container, false);
27 | }
28 |
29 | @Override
30 | public void onActivityCreated(Bundle savedInstanceState) {
31 | super.onActivityCreated(savedInstanceState);
32 | TextView tvTitle = (TextView) getView().findViewById(R.id.tv);
33 | Bundle bundle = getArguments();
34 | if (bundle.containsKey(EXTRA_TITLE)) {
35 | tvTitle.setText(bundle.getString(EXTRA_TITLE));
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
17 |
22 |
27 |
32 |
37 |
42 |
47 |
52 |
57 |
62 |
67 |
72 |
77 |
82 |
87 |
92 |
97 |
102 |
107 |
112 |
113 |
114 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_attach_to_common.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_common.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_common_wx.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
24 |
25 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_horizontalscrollview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
23 |
24 |
28 |
29 |
30 |
31 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_listview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
20 |
21 |
22 |
23 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
19 |
20 |
24 |
25 |
34 |
35 |
44 |
45 |
54 |
55 |
64 |
65 |
74 |
75 |
84 |
85 |
94 |
95 |
96 |
105 |
106 |
115 |
116 |
125 |
126 |
136 |
137 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_nestedscrollview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
23 |
24 |
28 |
29 |
30 |
31 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_recyclerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
20 |
21 |
22 |
23 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scrollview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
23 |
24 |
28 |
29 |
30 |
31 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_swipe_refresh_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
20 |
21 |
22 |
23 |
27 |
28 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_viewpager.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
20 |
21 |
22 |
23 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_webview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
20 |
21 |
22 |
23 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_test.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_direction.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/radio_group.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
28 |
29 |
38 |
39 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/recyclerview_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #FFFFFF
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SwipeBack
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/test/java/com/gw/swipebacksample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipebacksample;
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | maven { url 'https://dl.google.com/dl/android/maven2' }
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.0-beta4'
11 | classpath 'com.novoda:bintray-release:0.5.0'
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | maven { url 'https://dl.google.com/dl/android/maven2' }
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/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/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 04 15:05:20 CST 2017
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-4.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/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | android {
5 | compileSdkVersion 25
6 | buildToolsVersion "25.0.2"
7 |
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 25
12 | versionCode 102
13 | versionName "1.0.2"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 |
29 | implementation 'com.android.support:appcompat-v7:25.4.0'
30 | testImplementation 'junit:junit:4.12'
31 | androidTestImplementation 'com.android.support.test:runner:0.5'
32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
33 |
34 | implementation "com.android.support:recyclerview-v7:25.4.0"
35 | }
36 |
37 | publish {
38 | userOrg = 'gongwen92' //bintray注册的用户名
39 | groupId = 'com.gongwen' //compile引用时的第1部分groupId
40 | artifactId = 'swipeback' //compile引用时的第2部分项目名
41 | publishVersion = '1.0.2' //compile引用时的第3部分版本号
42 | desc = 'SwipeBack is an android library that can finish a activity by using gesture.'
43 | website = 'https://github.com/gongwen/SwipeBackLayout'
44 | }
--------------------------------------------------------------------------------
/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 /Users/fenghuacaijing/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/gw/swipeback/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipeback;
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 | * Instrumented 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.gw.swipeback.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/library/src/main/java/com/gw/swipeback/SwipeBackLayout.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipeback;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.support.annotation.FloatRange;
9 | import android.support.annotation.IntDef;
10 | import android.support.annotation.IntRange;
11 | import android.support.annotation.NonNull;
12 | import android.support.annotation.Nullable;
13 | import android.support.v4.view.MotionEventCompat;
14 | import android.support.v4.view.ViewCompat;
15 | import android.support.v4.widget.ViewDragHelper;
16 | import android.util.AttributeSet;
17 | import android.view.MotionEvent;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 |
21 | import com.gw.swipeback.tools.Util;
22 |
23 | import java.lang.annotation.Retention;
24 | import java.lang.annotation.RetentionPolicy;
25 |
26 | /**
27 | * Created by GongWen on 17/8/24.
28 | */
29 |
30 | public class SwipeBackLayout extends ViewGroup {
31 | private static final String TAG = "SwipeBackLayout";
32 |
33 | public static final int FROM_LEFT = 1 << 0;
34 | public static final int FROM_RIGHT = 1 << 1;
35 | public static final int FROM_TOP = 1 << 2;
36 | public static final int FROM_BOTTOM = 1 << 3;
37 |
38 | @IntDef({FROM_LEFT, FROM_TOP, FROM_RIGHT, FROM_BOTTOM})
39 | @Retention(RetentionPolicy.SOURCE)
40 | public @interface DirectionMode {
41 | }
42 |
43 | private int mDirectionMode = FROM_LEFT;
44 |
45 | private final ViewDragHelper mDragHelper;
46 | private View mDragContentView;
47 | private View innerScrollView;
48 |
49 | private int width, height;
50 |
51 | private int mTouchSlop;
52 | private float swipeBackFactor = 0.5f;
53 | private float swipeBackFraction;
54 | private int maskAlpha = 125;
55 | private boolean isSwipeFromEdge = false;
56 | private float downX, downY;
57 |
58 | private int leftOffset = 0;
59 | private int topOffset = 0;
60 | private float autoFinishedVelocityLimit = 2000f;
61 |
62 | private int touchedEdge = ViewDragHelper.INVALID_POINTER;
63 |
64 | public SwipeBackLayout(@NonNull Context context) {
65 | this(context, null);
66 | }
67 |
68 | public SwipeBackLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
69 | this(context, attrs, 0);
70 | }
71 |
72 | public SwipeBackLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
73 | super(context, attrs, defStyleAttr);
74 | setWillNotDraw(false);
75 | mDragHelper = ViewDragHelper.create(this, 1f, new DragHelperCallback());
76 | mDragHelper.setEdgeTrackingEnabled(mDirectionMode);
77 | mTouchSlop = mDragHelper.getTouchSlop();
78 | setSwipeBackListener(defaultSwipeBackListener);
79 |
80 | init(context, attrs);
81 | }
82 |
83 | private void init(@NonNull Context context, @Nullable AttributeSet attrs) {
84 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeBackLayout);
85 | setDirectionMode(a.getInt(R.styleable.SwipeBackLayout_directionMode, mDirectionMode));
86 | setSwipeBackFactor(a.getFloat(R.styleable.SwipeBackLayout_swipeBackFactor, swipeBackFactor));
87 | setMaskAlpha(a.getInteger(R.styleable.SwipeBackLayout_maskAlpha, maskAlpha));
88 | isSwipeFromEdge = a.getBoolean(R.styleable.SwipeBackLayout_isSwipeFromEdge, isSwipeFromEdge);
89 | a.recycle();
90 | }
91 |
92 | public void attachToActivity(Activity activity) {
93 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
94 | ViewGroup decorChild = (ViewGroup) decorView.getChildAt(0);
95 | decorChild.setBackgroundColor(Color.TRANSPARENT);
96 | decorView.removeView(decorChild);
97 | addView(decorChild);
98 | decorView.addView(this);
99 | }
100 |
101 | @Override
102 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
103 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
104 | int childCount = getChildCount();
105 | if (childCount > 1) {
106 | throw new IllegalStateException("SwipeBackLayout must contains only one direct child.");
107 | }
108 | int defaultMeasuredWidth = 0;
109 | int defaultMeasuredHeight = 0;
110 | int measuredWidth;
111 | int measuredHeight;
112 | if (childCount > 0) {
113 | measureChildren(widthMeasureSpec, heightMeasureSpec);
114 | mDragContentView = getChildAt(0);
115 | defaultMeasuredWidth = mDragContentView.getMeasuredWidth();
116 | defaultMeasuredHeight = mDragContentView.getMeasuredHeight();
117 | }
118 | measuredWidth = View.resolveSize(defaultMeasuredWidth, widthMeasureSpec) + getPaddingLeft() + getPaddingRight();
119 | measuredHeight = View.resolveSize(defaultMeasuredHeight, heightMeasureSpec) + getPaddingTop() + getPaddingBottom();
120 |
121 | setMeasuredDimension(measuredWidth, measuredHeight);
122 | }
123 |
124 | @Override
125 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
126 | if (getChildCount() == 0) return;
127 |
128 | int left = getPaddingLeft() + leftOffset;
129 | int top = getPaddingTop() + topOffset;
130 | int right = left + mDragContentView.getMeasuredWidth();
131 | int bottom = top + mDragContentView.getMeasuredHeight();
132 | mDragContentView.layout(left, top, right, bottom);
133 |
134 | if (changed) {
135 | width = getWidth();
136 | height = getHeight();
137 | }
138 | innerScrollView = Util.findAllScrollViews(this);
139 | }
140 |
141 | @Override
142 | protected void onDraw(Canvas canvas) {
143 | super.onDraw(canvas);
144 | canvas.drawARGB(maskAlpha - (int) (maskAlpha * swipeBackFraction), 0, 0, 0);
145 | }
146 |
147 | @Override
148 | public boolean onInterceptTouchEvent(MotionEvent ev) {
149 | switch (MotionEventCompat.getActionMasked(ev)) {
150 | case MotionEvent.ACTION_DOWN:
151 | downX = ev.getRawX();
152 | downY = ev.getRawY();
153 | break;
154 | case MotionEvent.ACTION_MOVE:
155 | if (innerScrollView != null && Util.contains(innerScrollView, downX, downY)) {
156 | float distanceX = Math.abs(ev.getRawX() - downX);
157 | float distanceY = Math.abs(ev.getRawY() - downY);
158 | if (mDirectionMode == FROM_LEFT || mDirectionMode == FROM_RIGHT) {
159 | if (distanceY > mTouchSlop && distanceY > distanceX) {
160 | return super.onInterceptTouchEvent(ev);
161 | }
162 | } else if (mDirectionMode == FROM_TOP || mDirectionMode == FROM_BOTTOM) {
163 | if (distanceX > mTouchSlop && distanceX > distanceY) {
164 | return super.onInterceptTouchEvent(ev);
165 | }
166 | }
167 | }
168 | break;
169 | }
170 | boolean handled = mDragHelper.shouldInterceptTouchEvent(ev);
171 | return handled ? handled : super.onInterceptTouchEvent(ev);
172 | }
173 |
174 | @Override
175 | public boolean onTouchEvent(MotionEvent event) {
176 | mDragHelper.processTouchEvent(event);
177 | return true;
178 | }
179 |
180 | @Override
181 | public void computeScroll() {
182 | if (mDragHelper.continueSettling(true)) {
183 | ViewCompat.postInvalidateOnAnimation(this);
184 | }
185 | }
186 |
187 | public void smoothScrollToX(int finalLeft) {
188 | if (mDragHelper.settleCapturedViewAt(finalLeft, getPaddingTop())) {
189 | ViewCompat.postInvalidateOnAnimation(this);
190 | }
191 | }
192 |
193 | public void smoothScrollToY(int finalTop) {
194 | if (mDragHelper.settleCapturedViewAt(getPaddingLeft(), finalTop)) {
195 | ViewCompat.postInvalidateOnAnimation(this);
196 | }
197 | }
198 |
199 | private class DragHelperCallback extends ViewDragHelper.Callback {
200 |
201 | @Override
202 | public boolean tryCaptureView(View child, int pointerId) {
203 | return child == mDragContentView;
204 | }
205 |
206 | @Override
207 | public int clampViewPositionHorizontal(View child, int left, int dx) {
208 | leftOffset = getPaddingLeft();
209 | if (isSwipeEnabled()) {
210 | if (mDirectionMode == FROM_LEFT && !Util.canViewScrollRight(innerScrollView, downX, downY, false)) {
211 | leftOffset = Math.min(Math.max(left, getPaddingLeft()), width);
212 | } else if (mDirectionMode == FROM_RIGHT && !Util.canViewScrollLeft(innerScrollView, downX, downY, false)) {
213 | leftOffset = Math.min(Math.max(left, -width), getPaddingRight());
214 | }
215 | }
216 | return leftOffset;
217 | }
218 |
219 | @Override
220 | public int clampViewPositionVertical(View child, int top, int dy) {
221 | topOffset = getPaddingTop();
222 | if (isSwipeEnabled()) {
223 | if (mDirectionMode == FROM_TOP && !Util.canViewScrollUp(innerScrollView, downX, downY, false)) {
224 | topOffset = Math.min(Math.max(top, getPaddingTop()), height);
225 | } else if (mDirectionMode == FROM_BOTTOM && !Util.canViewScrollDown(innerScrollView, downX, downY, false)) {
226 | topOffset = Math.min(Math.max(top, -height), getPaddingBottom());
227 | }
228 | }
229 | return topOffset;
230 | }
231 |
232 | @Override
233 | public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
234 | super.onViewPositionChanged(changedView, left, top, dx, dy);
235 | left = Math.abs(left);
236 | top = Math.abs(top);
237 | switch (mDirectionMode) {
238 | case FROM_LEFT:
239 | case FROM_RIGHT:
240 | swipeBackFraction = 1.0f * left / width;
241 | break;
242 | case FROM_TOP:
243 | case FROM_BOTTOM:
244 | swipeBackFraction = 1.0f * top / height;
245 | break;
246 | }
247 | if (mSwipeBackListener != null) {
248 | mSwipeBackListener.onViewPositionChanged(mDragContentView, swipeBackFraction, swipeBackFactor);
249 | }
250 | }
251 |
252 | @Override
253 | public void onViewReleased(View releasedChild, float xvel, float yvel) {
254 | super.onViewReleased(releasedChild, xvel, yvel);
255 | leftOffset = topOffset = 0;
256 | if (!isSwipeEnabled()) {
257 | touchedEdge = ViewDragHelper.INVALID_POINTER;
258 | return;
259 | }
260 | touchedEdge = ViewDragHelper.INVALID_POINTER;
261 |
262 | boolean isBackToEnd = backJudgeBySpeed(xvel, yvel) || swipeBackFraction >= swipeBackFactor;
263 | if (isBackToEnd) {
264 | switch (mDirectionMode) {
265 | case FROM_LEFT:
266 | smoothScrollToX(width);
267 | break;
268 | case FROM_TOP:
269 | smoothScrollToY(height);
270 | break;
271 | case FROM_RIGHT:
272 | smoothScrollToX(-width);
273 | break;
274 | case FROM_BOTTOM:
275 | smoothScrollToY(-height);
276 | break;
277 | }
278 | } else {
279 | switch (mDirectionMode) {
280 | case FROM_LEFT:
281 | case FROM_RIGHT:
282 | smoothScrollToX(getPaddingLeft());
283 | break;
284 | case FROM_BOTTOM:
285 | case FROM_TOP:
286 | smoothScrollToY(getPaddingTop());
287 | break;
288 | }
289 | }
290 | }
291 |
292 | @Override
293 | public void onViewDragStateChanged(int state) {
294 | super.onViewDragStateChanged(state);
295 | if (state == ViewDragHelper.STATE_IDLE) {
296 | if (mSwipeBackListener != null) {
297 | if (swipeBackFraction == 0) {
298 | mSwipeBackListener.onViewSwipeFinished(mDragContentView, false);
299 | } else if (swipeBackFraction == 1) {
300 | mSwipeBackListener.onViewSwipeFinished(mDragContentView, true);
301 | }
302 | }
303 | }
304 | }
305 |
306 | @Override
307 | public int getViewHorizontalDragRange(View child) {
308 | return width;
309 | }
310 |
311 | @Override
312 | public int getViewVerticalDragRange(View child) {
313 | return height;
314 | }
315 |
316 | @Override
317 | public void onEdgeTouched(int edgeFlags, int pointerId) {
318 | super.onEdgeTouched(edgeFlags, pointerId);
319 | touchedEdge = edgeFlags;
320 | }
321 | }
322 |
323 | public void finish() {
324 | ((Activity) getContext()).finish();
325 | }
326 |
327 | private boolean isSwipeEnabled() {
328 | if (isSwipeFromEdge) {
329 | switch (mDirectionMode) {
330 | case FROM_LEFT:
331 | return touchedEdge == ViewDragHelper.EDGE_LEFT;
332 | case FROM_TOP:
333 | return touchedEdge == ViewDragHelper.EDGE_TOP;
334 | case FROM_RIGHT:
335 | return touchedEdge == ViewDragHelper.EDGE_RIGHT;
336 | case FROM_BOTTOM:
337 | return touchedEdge == ViewDragHelper.EDGE_BOTTOM;
338 | }
339 | }
340 | return true;
341 | }
342 |
343 | private boolean backJudgeBySpeed(float xvel, float yvel) {
344 | switch (mDirectionMode) {
345 | case FROM_LEFT:
346 | return xvel > autoFinishedVelocityLimit;
347 | case FROM_TOP:
348 | return yvel > autoFinishedVelocityLimit;
349 | case FROM_RIGHT:
350 | return xvel < -autoFinishedVelocityLimit;
351 | case FROM_BOTTOM:
352 | return yvel < -autoFinishedVelocityLimit;
353 | }
354 | return false;
355 | }
356 |
357 | public void setSwipeBackFactor(@FloatRange(from = 0.0f, to = 1.0f) float swipeBackFactor) {
358 | if (swipeBackFactor > 1) {
359 | swipeBackFactor = 1;
360 | } else if (swipeBackFactor < 0) {
361 | swipeBackFactor = 0;
362 | }
363 | this.swipeBackFactor = swipeBackFactor;
364 | }
365 |
366 | public float getSwipeBackFactor() {
367 | return swipeBackFactor;
368 | }
369 |
370 | public void setMaskAlpha(@IntRange(from = 0, to = 255) int maskAlpha) {
371 | if (maskAlpha > 255) {
372 | maskAlpha = 255;
373 | } else if (maskAlpha < 0) {
374 | maskAlpha = 0;
375 | }
376 | this.maskAlpha = maskAlpha;
377 | }
378 |
379 | public int getMaskAlpha() {
380 | return maskAlpha;
381 | }
382 |
383 | public void setDirectionMode(@DirectionMode int direction) {
384 | mDirectionMode = direction;
385 | mDragHelper.setEdgeTrackingEnabled(direction);
386 | }
387 |
388 | public int getDirectionMode() {
389 | return mDirectionMode;
390 | }
391 |
392 | public float getAutoFinishedVelocityLimit() {
393 | return autoFinishedVelocityLimit;
394 | }
395 |
396 | public void setAutoFinishedVelocityLimit(float autoFinishedVelocityLimit) {
397 | this.autoFinishedVelocityLimit = autoFinishedVelocityLimit;
398 | }
399 |
400 | public boolean isSwipeFromEdge() {
401 | return isSwipeFromEdge;
402 | }
403 |
404 | public void setSwipeFromEdge(boolean isSwipeFromEdge) {
405 | this.isSwipeFromEdge = isSwipeFromEdge;
406 | }
407 |
408 | private OnSwipeBackListener mSwipeBackListener;
409 |
410 | private OnSwipeBackListener defaultSwipeBackListener = new OnSwipeBackListener() {
411 | @Override
412 | public void onViewPositionChanged(View mView, float swipeBackFraction, float swipeBackFactor) {
413 | invalidate();
414 | }
415 |
416 | @Override
417 | public void onViewSwipeFinished(View mView, boolean isEnd) {
418 | if (isEnd) {
419 | finish();
420 | }
421 | }
422 | };
423 |
424 | public void setSwipeBackListener(OnSwipeBackListener mSwipeBackListener) {
425 | this.mSwipeBackListener = mSwipeBackListener;
426 | }
427 |
428 | public interface OnSwipeBackListener {
429 |
430 | void onViewPositionChanged(View mView, float swipeBackFraction, float swipeBackFactor);
431 |
432 | void onViewSwipeFinished(View mView, boolean isEnd);
433 | }
434 | }
435 |
--------------------------------------------------------------------------------
/library/src/main/java/com/gw/swipeback/WxSwipeBackLayout.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipeback;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.util.AttributeSet;
7 | import android.view.View;
8 |
9 | import com.gw.swipeback.tools.Util;
10 |
11 | /**
12 | * Created by GongWen on 17/8/24.
13 | */
14 |
15 | public class WxSwipeBackLayout extends SwipeBackLayout {
16 | private static final String TAG = "WxSwipeBackLayout";
17 |
18 | public WxSwipeBackLayout(@NonNull Context context) {
19 | this(context, null);
20 | }
21 |
22 | public WxSwipeBackLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
23 | this(context, attrs, 0);
24 | }
25 |
26 | public WxSwipeBackLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
27 | super(context, attrs, defStyleAttr);
28 | setSwipeBackListener(defaultSwipeBackListener);
29 | }
30 |
31 | @Override
32 | public void setDirectionMode(int direction) {
33 | super.setDirectionMode(direction);
34 | if (direction != SwipeBackLayout.FROM_LEFT)
35 | throw new IllegalArgumentException("The direction of WxSwipeBackLayout must be FROM_LEFT");
36 | }
37 |
38 | private OnSwipeBackListener defaultSwipeBackListener = new OnSwipeBackListener() {
39 | @Override
40 | public void onViewPositionChanged(View mView, float swipeBackFraction, float swipeBackFactor) {
41 | invalidate();
42 | Util.onPanelSlide(swipeBackFraction);
43 | }
44 |
45 | @Override
46 | public void onViewSwipeFinished(View mView, boolean isEnd) {
47 | if (isEnd) {
48 | finish();
49 | }
50 | Util.onPanelReset();
51 | }
52 | };
53 | }
54 |
--------------------------------------------------------------------------------
/library/src/main/java/com/gw/swipeback/tools/ActivityLifecycleCallbacksAdapter.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipeback.tools;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.os.Bundle;
6 |
7 | /**
8 | * Created by GongWen on 17/9/4.
9 | */
10 |
11 | public class ActivityLifecycleCallbacksAdapter implements Application.ActivityLifecycleCallbacks {
12 | @Override
13 | public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
14 |
15 | }
16 |
17 | @Override
18 | public void onActivityStarted(Activity activity) {
19 |
20 | }
21 |
22 | @Override
23 | public void onActivityResumed(Activity activity) {
24 |
25 | }
26 |
27 | @Override
28 | public void onActivityPaused(Activity activity) {
29 |
30 | }
31 |
32 | @Override
33 | public void onActivityStopped(Activity activity) {
34 |
35 | }
36 |
37 | @Override
38 | public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
39 |
40 | }
41 |
42 | @Override
43 | public void onActivityDestroyed(Activity activity) {
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/library/src/main/java/com/gw/swipeback/tools/Util.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipeback.tools;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Rect;
5 | import android.support.v4.view.ViewCompat;
6 | import android.support.v4.view.ViewPager;
7 | import android.support.v4.widget.NestedScrollView;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.webkit.WebView;
12 | import android.widget.AbsListView;
13 | import android.widget.HorizontalScrollView;
14 | import android.widget.ScrollView;
15 |
16 | /**
17 | * Created by GongWen on 17/8/25.
18 | */
19 |
20 | public class Util {
21 | public static boolean canViewScrollUp(View mView, float x, float y, boolean defaultValueForNull) {
22 | if (mView == null || !contains(mView, x, y)) {
23 | return defaultValueForNull;
24 | }
25 | return ViewCompat.canScrollVertically(mView, -1);
26 | }
27 |
28 | public static boolean canViewScrollDown(View mView, float x, float y, boolean defaultValueForNull) {
29 | if (mView == null || !contains(mView, x, y)) {
30 | return defaultValueForNull;
31 | }
32 | return ViewCompat.canScrollVertically(mView, 1);
33 | }
34 |
35 | public static boolean canViewScrollRight(View mView, float x, float y, boolean defaultValueForNull) {
36 | if (mView == null || !contains(mView, x, y)) {
37 | return defaultValueForNull;
38 | }
39 | return ViewCompat.canScrollHorizontally(mView, -1);
40 | }
41 |
42 | public static boolean canViewScrollLeft(View mView, float x, float y, boolean defaultValueForNull) {
43 | if (mView == null || !contains(mView, x, y)) {
44 | return defaultValueForNull;
45 | }
46 | return ViewCompat.canScrollHorizontally(mView, 1);
47 | }
48 |
49 |
50 | public static View findAllScrollViews(ViewGroup mViewGroup) {
51 | for (int i = 0; i < mViewGroup.getChildCount(); i++) {
52 | View mView = mViewGroup.getChildAt(i);
53 | if (mView.getVisibility() != View.VISIBLE) {
54 | continue;
55 | }
56 | if (isScrollableView(mView)) {
57 | return mView;
58 | }
59 | if (mView instanceof ViewGroup) {
60 | mView = findAllScrollViews((ViewGroup) mView);
61 | if (mView != null) {
62 | return mView;
63 | }
64 | }
65 | }
66 | return null;
67 | }
68 |
69 | public static boolean isScrollableView(View mView) {
70 | return mView instanceof ScrollView
71 | || mView instanceof HorizontalScrollView
72 | || mView instanceof NestedScrollView
73 | || mView instanceof AbsListView
74 | || mView instanceof RecyclerView
75 | || mView instanceof ViewPager
76 | || mView instanceof WebView;
77 | }
78 |
79 | public static boolean contains(View mView, float x, float y) {
80 | Rect localRect = new Rect();
81 | mView.getGlobalVisibleRect(localRect);
82 | return localRect.contains((int) x, (int) y);
83 | }
84 |
85 | public static void onPanelSlide(float fraction) {
86 | Activity activity = WxSwipeBackActivityManager.getInstance().getPenultimateActivity();
87 | if (activity != null && !activity.isFinishing()) {
88 | View decorView = activity.getWindow().getDecorView();
89 | ViewCompat.setTranslationX(decorView, -(decorView.getMeasuredWidth() / 3.0f) * (1 - fraction));
90 | }
91 | }
92 |
93 | public static void onPanelReset() {
94 | Activity activity = WxSwipeBackActivityManager.getInstance().getPenultimateActivity();
95 | if (activity != null) {
96 | View decorView = activity.getWindow().getDecorView();
97 | ViewCompat.setTranslationX(decorView, 0);
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/library/src/main/java/com/gw/swipeback/tools/WxSwipeBackActivityManager.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipeback.tools;
2 |
3 |
4 | import android.app.Activity;
5 | import android.app.Application;
6 | import android.os.Bundle;
7 |
8 | import java.util.Stack;
9 |
10 | /**
11 | * Created by GongWen on 17/9/4.
12 | */
13 |
14 | public class WxSwipeBackActivityManager extends ActivityLifecycleCallbacksAdapter {
15 | private static final WxSwipeBackActivityManager instance = new WxSwipeBackActivityManager();
16 | private Stack mActivityStack = new Stack<>();
17 |
18 | private WxSwipeBackActivityManager() {
19 | }
20 |
21 | public static WxSwipeBackActivityManager getInstance() {
22 | return instance;
23 | }
24 |
25 | public void init(Application mApplication) {
26 | mApplication.registerActivityLifecycleCallbacks(this);
27 | }
28 |
29 | @Override
30 | public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
31 | mActivityStack.add(activity);
32 | }
33 |
34 | @Override
35 | public void onActivityDestroyed(Activity activity) {
36 | mActivityStack.remove(activity);
37 | }
38 |
39 | /**
40 | * 获取倒数第二个Activity
41 | *
42 | * @return
43 | */
44 | public Activity getPenultimateActivity() {
45 | return mActivityStack.size() >= 2 ? mActivityStack.get(mActivityStack.size() - 2) : null;
46 | }
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/library/src/test/java/com/gw/swipeback/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.gw.swipeback;
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 | }
--------------------------------------------------------------------------------
/sample-apks/app-debug-1.0.2.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/sample-apks/app-debug-1.0.2.apk
--------------------------------------------------------------------------------
/screenshot/screenshot1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/screenshot/screenshot1.gif
--------------------------------------------------------------------------------
/screenshot/screenshot2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gongwen/SwipeBackLayout/36e556a7a519a72a179f52787ae16b698b973eb9/screenshot/screenshot2.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------