├── .gitattributes
├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── oubowu
│ │ └── slideback
│ │ └── demo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── oubowu
│ │ │ └── slideback
│ │ │ └── demo
│ │ │ ├── MainActivity.java
│ │ │ ├── MyApplication.java
│ │ │ ├── OnSeekBarChangeListenerAdapter.java
│ │ │ ├── ScrollActivity.java
│ │ │ └── SecondActivity.java
│ └── res
│ │ ├── anim
│ │ ├── anim_none.xml
│ │ ├── anim_slide_in.xml
│ │ └── anim_slide_out.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_scroll.xml
│ │ ├── activity_second.xml
│ │ ├── content_main.xml
│ │ ├── content_scroll.xml
│ │ ├── content_second.xml
│ │ ├── item_rv.xml
│ │ └── item_vp.xml
│ │ ├── menu
│ │ ├── menu_main.xml
│ │ └── menu_scroll.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── oubowu
│ └── slideback
│ └── demo
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── oubowu
│ │ └── slideback
│ │ ├── ActivityHelper.java
│ │ ├── SlideBackHelper.java
│ │ ├── SlideConfig.java
│ │ ├── callbak
│ │ ├── OnInternalStateListener.java
│ │ ├── OnSlideListener.java
│ │ └── OnSlideListenerAdapter.java
│ │ └── widget
│ │ ├── CacheDrawView.java
│ │ ├── ShadowView.java
│ │ └── SlideBackLayout.java
│ └── res
│ ├── anim
│ └── anim_out_none.xml
│ └── values
│ └── strings.xml
├── pic
├── demo.gif
└── demo2.gif
└── settings.gradle
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | .idea
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## 高仿微信视差手势滑动返回库(实验性质,请勿用于商业开发)
2 | #### 实现思路参考自「[Slidr](https://github.com/r0adkll/Slidr)」和「[and_swipeback](https://github.com/XBeats/and_swipeback)」
3 |
4 | ### 功能
5 | - 无需设置Activity主题透明
6 | - 支持动态切换全局或边缘滑动,亦可动态禁止或恢复滑动
7 | - 支持动态设置边缘响应和滑动关闭距离的阈值
8 | - 页面边缘附有阴影并随滑动距离而渐变
9 | - 优化了与RecyclerView、ViewPager等滑动控件手势冲突
10 | - 支持屏幕旋转
11 |
12 | ### 效果图
13 | 
14 | 
15 |
16 | ### 使用方法
17 | #### 1. 继承Application实现Activity生命周期的监听,ActivityHelper用于保存Activity栈供侧滑库使用
18 | public class MyApplication extends Application {
19 |
20 | private ActivityHelper mActivityHelper;
21 |
22 | private static MyApplication sMyApplication;
23 |
24 | @Override
25 | public void onCreate() {
26 | super.onCreate();
27 |
28 | mActivityHelper = new ActivityHelper();
29 | registerActivityLifecycleCallbacks(mActivityHelper);
30 |
31 | sMyApplication = this;
32 |
33 | }
34 |
35 | public static ActivityHelper getActivityHelper(){
36 | return sMyApplication.mActivityHelper;
37 | }
38 |
39 | }
40 | #### 2.在需要滑动的Activity使用SlideBackHelper去attach当前Activity
41 | @Override
42 | protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | setContentView(R.layout.activity_second);
45 |
46 | mSlideBackLayout = SlideBackHelper.attach(
47 | // 当前Activity
48 | this,
49 | // Activity栈管理工具
50 | MyApplication.getActivityHelper(),
51 | // 参数的配置
52 | new SlideConfig.Builder()
53 | // 屏幕是否旋转
54 | .rotateScreen(true)
55 | // 是否侧滑
56 | .edgeOnly(false)
57 | // 是否禁止侧滑
58 | .lock(false)
59 | // 边缘滑动的响应阈值,0~1,对应屏幕宽度*percent
60 | .edgePercent(0.1f)
61 | // 关闭页面的阈值,0~1,对应屏幕宽度*percent
62 | .slideOutPercent(0.5f).create(),
63 | // 滑动的监听
64 | null);
65 |
66 | // 其它初始化
67 | }
68 |
69 | #### 3.如果开启了屏幕旋转,SlideBackLayout需要监听Activity的结束事件,例如这里的onBackPressed,所以你需要在调用结束事件的地方加上SlideBackLayout.isComingToFinish()
70 | @Override
71 | public void onBackPressed() {
72 | super.onBackPressed();
73 | mSlideBackLayout.isCommingToFinish();
74 | overridePendingTransition(R.anim.anim_none, R.anim.anim_slide_out);
75 | }
76 |
77 | #### 4.SlideBackHelper.attach会返回处理侧滑的SlideBackLayout,可在适当时候动态控制侧滑几个参数
78 | ```
79 | // 是否启用边缘滑动
80 | mSlideBackLayout.edgeOnly(boolean);
81 | // 是否禁止滑动
82 | mSlideBackLayout.lock(boolean);
83 | // 设置边缘滑动的响应阈值
84 | mSlideBackLayout.setEdgeRangePercent(float);
85 | // 设置关闭页面的阈值
86 | mSlideBackLayout.setSlideOutRangePercent(float);
87 | ```
88 |
89 | ### 存在问题
90 | ##### 旋转屏幕后上一个Activity的布局也会随之旋转,但是ToolBar比例还是维持旋转之前的比例,无从下手,希望有大神告知>_<
91 | ##### 沉浸式状态栏支持有问题
92 | ##### 多个滑动页面快速返回有空指针问题,只能等页面取点焦点的时候才能滑动
93 |
94 | #### License
95 | ```
96 | Copyright 2016 oubowu
97 |
98 | Licensed under the Apache License, Version 2.0 (the "License");
99 | you may not use this file except in compliance with the License.
100 | You may obtain a copy of the License at
101 |
102 | http://www.apache.org/licenses/LICENSE-2.0
103 |
104 | Unless required by applicable law or agreed to in writing, software
105 | distributed under the License is distributed on an "AS IS" BASIS,
106 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
107 | See the License for the specific language governing permissions and
108 | limitations under the License.
109 | ```
110 |
111 |
112 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 | defaultConfig {
7 | applicationId "com.oubowu.slideback.demo"
8 | minSdkVersion 16
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(include: ['*.jar'], dir: 'libs')
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:27.0.2'
30 | compile 'com.android.support:design:27.0.2'
31 | testCompile 'junit:junit:4.12'
32 | compile project(':library')
33 | compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.1.3'
34 | }
35 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\AndroidSdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/oubowu/slideback/demo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.demo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.oubowu.slideback.demo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
28 |
29 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oubowu/slideback/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.demo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.View;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_main);
15 |
16 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
17 | setSupportActionBar(toolbar);
18 |
19 | }
20 |
21 | public void jump(View view) {
22 | startActivity(new Intent(this, SecondActivity.class));
23 | overridePendingTransition(R.anim.anim_slide_in, R.anim.anim_none);
24 | }
25 |
26 | public void jumpScroll(View view) {
27 | startActivity(new Intent(this, ScrollActivity.class));
28 | overridePendingTransition(R.anim.anim_slide_in, R.anim.anim_none);
29 | }
30 |
31 | @Override
32 | public void onBackPressed() {
33 | super.onBackPressed();
34 | overridePendingTransition(R.anim.anim_none, R.anim.anim_slide_out);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oubowu/slideback/demo/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.demo;
2 |
3 | import android.app.Application;
4 |
5 | import com.oubowu.slideback.ActivityHelper;
6 |
7 | /**
8 | * Created by Oubowu on 2016/9/22 0022 18:13.
9 | */
10 | public class MyApplication extends Application {
11 |
12 | private ActivityHelper mActivityHelper;
13 |
14 | private static MyApplication sMyApplication;
15 |
16 | @Override
17 | public void onCreate() {
18 | super.onCreate();
19 |
20 | mActivityHelper = new ActivityHelper();
21 | registerActivityLifecycleCallbacks(mActivityHelper);
22 |
23 | sMyApplication = this;
24 |
25 | }
26 |
27 | public static ActivityHelper getActivityHelper(){
28 | return sMyApplication.mActivityHelper;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oubowu/slideback/demo/OnSeekBarChangeListenerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.demo;
2 |
3 | import android.widget.SeekBar;
4 |
5 | /**
6 | * Created by Oubowu on 2016/9/23 1:03.
7 | */
8 | public class OnSeekBarChangeListenerAdapter implements SeekBar.OnSeekBarChangeListener{
9 |
10 | @Override
11 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
12 |
13 | }
14 |
15 | @Override
16 | public void onStartTrackingTouch(SeekBar seekBar) {
17 |
18 | }
19 |
20 | @Override
21 | public void onStopTrackingTouch(SeekBar seekBar) {
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oubowu/slideback/demo/ScrollActivity.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.demo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.view.PagerAdapter;
5 | import android.support.v4.view.ViewPager;
6 | import android.support.v4.widget.NestedScrollView;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.LayoutInflater;
12 | import android.view.Menu;
13 | import android.view.MenuItem;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.widget.TextView;
17 |
18 | import com.chad.library.adapter.base.BaseQuickAdapter;
19 | import com.chad.library.adapter.base.BaseViewHolder;
20 | import com.oubowu.slideback.SlideBackHelper;
21 | import com.oubowu.slideback.SlideConfig;
22 | import com.oubowu.slideback.widget.SlideBackLayout;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | public class ScrollActivity extends AppCompatActivity {
28 |
29 | private RecyclerView mRv;
30 | private NestedScrollView mNsv;
31 | private ViewPager mVp;
32 | private SlideBackLayout mSlideBackLayout;
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_scroll);
38 |
39 | mSlideBackLayout = SlideBackHelper.attach(
40 | // 当前Activity
41 | this,
42 | // Activity栈管理工具
43 | MyApplication.getActivityHelper(),
44 | // 参数的配置
45 | new SlideConfig.Builder()
46 | // 屏幕是否旋转
47 | .rotateScreen(true)
48 | // 是否侧滑
49 | .edgeOnly(false)
50 | // 是否禁止侧滑
51 | .lock(false)
52 | // 侧滑的响应阈值,0~1,对应屏幕宽度*percent
53 | .edgePercent(0.1f)
54 | // 关闭页面的阈值,0~1,对应屏幕宽度*percent
55 | .slideOutPercent(0.5f).create(),
56 | // 滑动的监听
57 | null);
58 |
59 | // MyApplication.getActivityHelper().printAllActivity();
60 |
61 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
62 | setSupportActionBar(toolbar);
63 |
64 | mRv = (RecyclerView) findViewById(R.id.rv);
65 | mNsv = (NestedScrollView) findViewById(R.id.nsv);
66 | mVp = (ViewPager) findViewById(R.id.vp);
67 |
68 | mRv.setLayoutManager(new LinearLayoutManager(this));
69 |
70 | ArrayList list = new ArrayList<>();
71 | for (int i = 0; i < 30; i++) {
72 | list.add(i);
73 | }
74 | mRv.setAdapter(new RvAdapter(R.layout.item_rv, list));
75 |
76 | mVp.setAdapter(new VpAdapter<>(list));
77 | mVp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
78 | @Override
79 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
80 |
81 | }
82 |
83 | @Override
84 | public void onPageSelected(int position) {
85 | if (position == 0) {
86 | mSlideBackLayout.edgeOnly(false);
87 | } else {
88 | mSlideBackLayout.edgeOnly(true);
89 | }
90 | }
91 |
92 | @Override
93 | public void onPageScrollStateChanged(int state) {
94 |
95 | }
96 | });
97 |
98 | }
99 |
100 | class RvAdapter extends BaseQuickAdapter {
101 |
102 | public RvAdapter(int layoutResId, List data) {
103 | super(layoutResId, data);
104 | }
105 |
106 | @Override
107 | protected void convert(BaseViewHolder baseViewHolder, Integer integer) {
108 |
109 | }
110 | }
111 |
112 | class VpAdapter extends PagerAdapter {
113 |
114 | private List mData;
115 |
116 | public VpAdapter(List data) {
117 | this.mData = data;
118 | }
119 |
120 | @Override
121 | public int getCount() {
122 | return mData == null ? 0 : mData.size();
123 | }
124 |
125 | @Override
126 | public Object instantiateItem(ViewGroup container, int position) {
127 |
128 | final View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_vp, container, false);
129 |
130 | TextView tvPage = (TextView) view.findViewById(R.id.tv_page);
131 |
132 | tvPage.setText("页面" + (position + 1));
133 |
134 | container.addView(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
135 |
136 | return view;
137 | }
138 |
139 | @Override
140 | public void destroyItem(ViewGroup container, int position, Object object) {
141 | container.removeView((View) object);
142 | }
143 |
144 | @Override
145 | public boolean isViewFromObject(View view, Object object) {
146 | return view == object;
147 | }
148 |
149 | }
150 |
151 | @Override
152 | public void onBackPressed() {
153 | super.onBackPressed();
154 | mSlideBackLayout.isComingToFinish();
155 | overridePendingTransition(R.anim.anim_none, R.anim.anim_slide_out);
156 | }
157 |
158 | @Override
159 | public boolean onCreateOptionsMenu(Menu menu) {
160 | getMenuInflater().inflate(R.menu.menu_scroll, menu);
161 | return true;
162 | }
163 |
164 | @Override
165 | public boolean onOptionsItemSelected(MenuItem item) {
166 |
167 | item.setChecked(true);
168 |
169 | switch (item.getItemId()) {
170 | case R.id.action_rv:
171 | mRv.setVisibility(View.VISIBLE);
172 | mNsv.setVisibility(View.INVISIBLE);
173 | mVp.setVisibility(View.INVISIBLE);
174 | break;
175 | case R.id.action_nsv:
176 | mRv.setVisibility(View.INVISIBLE);
177 | mNsv.setVisibility(View.VISIBLE);
178 | mVp.setVisibility(View.INVISIBLE);
179 | break;
180 | case R.id.action_vp:
181 | mRv.setVisibility(View.INVISIBLE);
182 | mNsv.setVisibility(View.INVISIBLE);
183 | mVp.setVisibility(View.VISIBLE);
184 | break;
185 | }
186 |
187 | return super.onOptionsItemSelected(item);
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oubowu/slideback/demo/SecondActivity.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.demo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.FloatRange;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.SeekBar;
11 | import android.widget.TextView;
12 |
13 | import com.oubowu.slideback.SlideBackHelper;
14 | import com.oubowu.slideback.SlideConfig;
15 | import com.oubowu.slideback.callbak.OnSlideListenerAdapter;
16 | import com.oubowu.slideback.widget.SlideBackLayout;
17 |
18 | public class SecondActivity extends AppCompatActivity {
19 |
20 | private SlideBackLayout mSlideBackLayout;
21 | private TextView mTvEdgeRange;
22 | private SeekBar mSbEdgeRange;
23 | private TextView mTvSlideOutRange;
24 | private SeekBar mSbSlideOutRange;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_second);
30 |
31 | // Log.e("TAG","SecondActivity-32行-onCreate(): ");
32 |
33 | mSlideBackLayout = SlideBackHelper.attach(
34 | // 当前Activity
35 | this, MyApplication.getActivityHelper(),
36 | // 参数的配置
37 | new SlideConfig.Builder()
38 | // 屏幕是否旋转
39 | .rotateScreen(true)
40 | // 是否侧滑
41 | .edgeOnly(false)
42 | // 是否禁止侧滑
43 | .lock(false)
44 | // 侧滑的响应阈值,0~1,对应屏幕宽度*percent
45 | .edgePercent(0.1f)
46 | // 关闭页面的阈值,0~1,对应屏幕宽度*percent
47 | .slideOutPercent(0.5f).create(),
48 | // 滑动的监听
49 | new OnSlideListenerAdapter() {
50 | @Override
51 | public void onSlide(@FloatRange(from = 0.0,
52 | to = 1.0) float percent) {
53 | super.onSlide(percent);
54 | }
55 | });
56 |
57 | // MyApplication.getActivityHelper().printAllActivity();
58 |
59 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
60 | setSupportActionBar(toolbar);
61 |
62 | mTvEdgeRange = (TextView) findViewById(R.id.tv_edge_range);
63 | mSbEdgeRange = (SeekBar) findViewById(R.id.sb_edge_range);
64 | mTvSlideOutRange = (TextView) findViewById(R.id.tv_slide_out_range);
65 | mSbSlideOutRange = (SeekBar) findViewById(R.id.sb_slide_out_range);
66 |
67 | if (mSlideBackLayout == null) {
68 | return;
69 | }
70 |
71 | mSbEdgeRange.setOnSeekBarChangeListener(new OnSeekBarChangeListenerAdapter() {
72 | @Override
73 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
74 | mTvEdgeRange.setText("边缘响应的最大值:屏幕宽度的" + progress + "%");
75 | if (fromUser) {
76 | mSlideBackLayout.setEdgeRangePercent(progress * 1.0f / mSbEdgeRange.getMax());
77 | }
78 | }
79 | });
80 |
81 | mSbSlideOutRange.setOnSeekBarChangeListener(new OnSeekBarChangeListenerAdapter() {
82 | @Override
83 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
84 | mTvSlideOutRange.setText("非快速滑动,关闭页面的最小值:屏幕宽度的" + progress + "%");
85 | if (fromUser) {
86 | mSlideBackLayout.setSlideOutRangePercent(progress * 1.0f / mSbSlideOutRange.getMax());
87 | }
88 | }
89 | });
90 |
91 | mSbEdgeRange.setProgress((int) (mSlideBackLayout.getEdgeRangePercent() * 100));
92 |
93 | mSbSlideOutRange.setProgress((int) (mSlideBackLayout.getSlideOutRangePercent() * 100));
94 |
95 | }
96 |
97 | public void jump(View view) {
98 | startActivity(new Intent(this, SecondActivity.class));
99 | overridePendingTransition(R.anim.anim_slide_in, R.anim.anim_none);
100 | }
101 |
102 | public void enableEdgeSlide(View view) {
103 | mSlideBackLayout.edgeOnly(!mSlideBackLayout.isEdgeOnly());
104 | ((Button) view).setText(mSlideBackLayout.isEdgeOnly() ? "开启全局侧滑\n(当前边缘侧滑)" : "开启边缘侧滑\n(当前全局侧滑)");
105 | }
106 |
107 | public void disableSlide(View view) {
108 | mSlideBackLayout.lock(!mSlideBackLayout.isLock());
109 | ((Button) view).setText(mSlideBackLayout.isLock() ? "开启侧滑\n(当前侧滑禁止)" : "禁止侧滑\n(当前侧滑开启)");
110 | }
111 |
112 | @Override
113 | public void onBackPressed() {
114 | super.onBackPressed();
115 | mSlideBackLayout.isComingToFinish();
116 | overridePendingTransition(R.anim.anim_none, R.anim.anim_slide_out);
117 | }
118 |
119 | }
120 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/anim_none.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/anim_slide_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/anim_slide_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scroll.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
24 |
25 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_scroll.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
21 |
22 |
23 |
24 |
29 |
30 |
34 |
35 |
36 |
37 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
25 |
26 |
34 |
35 |
41 |
42 |
50 |
51 |
61 |
62 |
70 |
71 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_rv.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 | w
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_vp.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_scroll.xml:
--------------------------------------------------------------------------------
1 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oubowu/SlideBack/a78df739ba1b4a51b6e7dc5419f6adb5540921f0/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oubowu/SlideBack/a78df739ba1b4a51b6e7dc5419f6adb5540921f0/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oubowu/SlideBack/a78df739ba1b4a51b6e7dc5419f6adb5540921f0/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oubowu/SlideBack/a78df739ba1b4a51b6e7dc5419f6adb5540921f0/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oubowu/SlideBack/a78df739ba1b4a51b6e7dc5419f6adb5540921f0/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
13 |
14 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #FFFFFF
8 |
9 | #445566
10 | #887654
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 侧滑测试Demo
3 | Settings
4 | 侧滑页面
5 | 滑动控件侧滑
6 |
7 | 2005年因参加选秀节目《我型我秀》而正式出道,2006年6月9日,发行首张个人原创同名专辑《薛之谦》,包揽了六首曲和五首词的创作[1] 。《认真的雪》打榜成绩和彩铃下载量更是名列前茅,一直成为各大排行榜上的常客,专辑销量1个月破20万张。[2]
8 | 时尚写真
9 | 时尚写真(9张)
10 | 2007年7月31日发行第二张个人原创专辑《你过得好吗》。短短一个月时间,销量迅速突破15万,获中歌榜冠军。[16] 同年,薛之谦受邀作为流行音乐的代表,和其他艺术家一起前往俄罗斯,参加由中华人民共和国文化部,和俄罗斯联邦文化电影署联合举办的中国文化节重点项目”沿伏尔加河友谊之旅”,在沿河11个城市作访问演出。[3]
11 | 2008年11月26日发行第三张个人原创专辑《深深爱过你》,同名主打歌《深深爱过你》荣登中歌榜等榜单首位,2009年获第9届全球华语歌曲排行榜最受欢迎二十大金曲奖。[17] 12月20日举行首场演唱会“谦年传说”。[4] 2008年,薛之谦当选火炬手,在河南省郑州市传递火炬[18]
12 | 2009年9月21日推出单曲《未完成的歌》,这是薛之谦逾一年的创作,迟迟没有发表是因为一直没有很好的词来配合这首曲,所以他一直等到能让他觉得感动的歌词。2009年12月11日发行新歌+精选集《未完成的歌》。[19]
13 |
14 | 2010年薛之谦跨界影视,主演了个人首部大银幕作品《一只狗的大学时光》[20] 。
15 | 2011年3月14日,推出单曲《我终于成了别人的女人》,这首歌曲的编曲由音乐人常石磊编写,音乐录影带由周杰伦的御用导演珍妮花拍摄[21] 。
16 | 2012年,主演青春励志片《音乐江湖》,在片中饰演了性格内向、对音乐执着的学生陈浩,并演唱影片主题曲《我们爱过就好》[22] ;7月17日,发行
17 | 薛之谦
18 | 薛之谦(11张)
19 | 专辑《几个薛之谦》,专辑筹备期长达两年半。期间,薛之谦陆续发行《我终于成了别人的女人》、《伏笔》、《几个你》等多首单曲[23] 。该唱片获2013年MusicRadio中国TOP排行榜内地推荐唱片奖[24] 。第二波深情主打《我知道你都知道》被湖南卫视最新大戏《胜女的代价》收为主插曲[25] ;同年,薛之谦第一家“上上谦”火锅店开业,现已扩张到五家店。之后薛之谦又自创了女装品牌UUJULY、童装品牌UUJULYKIDS、男装品牌Dangerous People[5] 。
20 | 2013年11月,发行专辑《意外》,并凭借该专辑获得第21届东方风云榜十大金曲奖。其中收录了主打歌《丑八怪》以及插曲《意外》、《你还要我怎样》、《方圆几里》等在内的10首歌曲[6] 。凭借新专辑《意外》在东方风云榜拿下最佳唱作人和十大金曲两座大奖。[26]
21 | 2015年6月8日,推出原创EP《绅士》,收录了《绅士》、《演员》、《下雨了》在内的3首歌曲[7] ;10月26日,推出个人原创EP《一半》[28] ,EP发布后试听量一路飙升,夺得多家权威音乐榜单冠军位,11月10日,薛之谦在北京举行EP《一半》试听量破亿庆功会[29] 。11月19日,单曲《Stay Here》MV首发,纪念自己曾经的倔强和已逝去的爱情[30] ;同年,搭档朴海镇、张亮主演都市爱情剧《男人帮·朋友》[31] ;10月5日,其主演的都市励志剧《妈妈像花儿一样》播出,并在剧中饰演“多情小叔子”张来福[9] 。
22 | 综艺活动
23 | 综艺活动(17张)
24 | 2016年,凭借歌曲《演员》、《一半》获得酷音乐亚洲盛典“年度电视音乐金曲艺人”、“年度电视音乐金曲艺人”; 5月17日,发行EP《初学者》[11] ,同时也是爱情喜剧片《A测试之爱情大冒险》的主题曲,该电影是由薛之谦首次特别主演[32] ,歌曲首发后评论数在一天突破8万,两天突破10万[33] 。6月1日,MV上线,这首歌是薛之谦独自包揽词曲,此次再度与金曲奖最佳音乐录像带奖得主黄中平导演合作拍MV[34] ;6月4日,参加真人秀节目《挑战者联盟》[35] ;6月7日,发行原创单曲《刚刚好》[36] ;6月17日,薛之谦《初学者》专辑的第二波伤情主打歌《刚刚好》MV正式首发[36] ;6月24日,推出个人原创单曲《我好像在哪见过你》,同时也是魔幻动画片《精灵王座》的主题曲;6月30日,参加中韩偶像互动音乐节目《作战吧偶像》[37] ;7月2日,参加湖南卫视音乐节目《中国新声代第四季》[38] ;7月17日,在北京举办《初学者》免费首唱会,7月18日新专辑《初学者》全网正式上线,实体专辑将制作CD碟及限量版,黑胶两个版本,将于8月初开售[39] 。9月12日,薛之谦携手黄龄献唱由导演冯小刚执导的电影《我不是潘金莲》的推广曲。[15] 9月15日,薛之谦担任《中国新歌声》第五战队队长强势踢馆《中国新歌声》。
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/test/java/com/oubowu/slideback/demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.demo;
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 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:3.0.1'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | google()
19 | maven { url "https://jitpack.io" }
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/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/oubowu/SlideBack/a78df739ba1b4a51b6e7dc5419f6adb5540921f0/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Feb 09 10:52:11 CST 2018
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/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 | defaultConfig {
7 | minSdkVersion 16
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 |
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 |
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | provided 'com.android.support:appcompat-v7:27.0.2'
26 | // provided 'com.android.support:design:24.2.1'
27 | }
28 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\AndroidSdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/library/src/main/java/com/oubowu/slideback/ActivityHelper.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 |
8 | import java.util.Stack;
9 |
10 | /**
11 | * Created by Oubowu on 2016/9/20 3:28.
12 | */
13 | public class ActivityHelper implements Application.ActivityLifecycleCallbacks {
14 |
15 | private static Stack mActivityStack;
16 |
17 | public ActivityHelper() {
18 | }
19 |
20 | @Override
21 | public void onActivityCreated(Activity activity, Bundle bundle) {
22 | if (mActivityStack == null) {
23 | mActivityStack = new Stack<>();
24 | }
25 | mActivityStack.add(activity);
26 | }
27 |
28 | @Override
29 | public void onActivityStarted(Activity activity) {
30 |
31 | }
32 |
33 | @Override
34 | public void onActivityResumed(Activity activity) {
35 |
36 | }
37 |
38 | @Override
39 | public void onActivityPaused(Activity activity) {
40 |
41 | }
42 |
43 | @Override
44 | public void onActivityStopped(Activity activity) {
45 |
46 | }
47 |
48 | @Override
49 | public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
50 |
51 | }
52 |
53 | @Override
54 | public void onActivityDestroyed(Activity activity) {
55 |
56 | // Log.e("TAG", "ActivityHelper-销毁: " + activity);
57 | mActivityStack.remove(activity);
58 |
59 | }
60 |
61 | public Activity getPreActivity() {
62 | if (mActivityStack == null) {
63 | return null;
64 | }
65 | int size = mActivityStack.size();
66 | if (size < 2) {
67 | return null;
68 | }
69 | return mActivityStack.elementAt(size - 2);
70 | }
71 |
72 | public void finishAllActivity() {
73 | if (mActivityStack == null) {
74 | return;
75 | }
76 | for (Activity activity : mActivityStack) {
77 | activity.finish();
78 | }
79 | }
80 |
81 | public void printAllActivity() {
82 | if (mActivityStack == null) {
83 | return;
84 | }
85 | for (int i = 0; i < mActivityStack.size(); i++) {
86 | Log.e("TAG", "位置" + i + ": " + mActivityStack.get(i));
87 | }
88 | }
89 |
90 | /**
91 | * 强制删掉activity,用于用户快速滑动页面的时候,因为页面还没来得及destroy导致的问题
92 | *
93 | * @param activity 删掉的activity
94 | */
95 | void postRemoveActivity(Activity activity) {
96 | if (mActivityStack != null) {
97 | mActivityStack.remove(activity);
98 | }
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/library/src/main/java/com/oubowu/slideback/SlideBackHelper.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback;
2 |
3 | import android.app.Activity;
4 | import android.graphics.drawable.Drawable;
5 | import android.support.annotation.NonNull;
6 | import android.support.annotation.Nullable;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.oubowu.slideback.callbak.OnInternalStateListener;
11 | import com.oubowu.slideback.callbak.OnSlideListener;
12 | import com.oubowu.slideback.widget.SlideBackLayout;
13 |
14 | /**
15 | * Created by Oubowu on 2016/9/22 0022 14:31.
16 | */
17 | // TODO: 2016/9/24 添加了上个页面的布局,如果页面有Toolbar的话其不随屏幕选择而大小变化,永远维持进入时的宽高比
18 | public class SlideBackHelper {
19 |
20 | public static ViewGroup getDecorView(Activity activity) {
21 | return (ViewGroup) activity.getWindow().getDecorView();
22 | }
23 |
24 | public static Drawable getDecorViewDrawable(Activity activity) {
25 | return getDecorView(activity).getBackground();
26 | }
27 |
28 | public static View getContentView(Activity activity) {
29 | return getDecorView(activity).getChildAt(0);
30 | }
31 |
32 | /**
33 | * 附着Activity,实现侧滑
34 | *
35 | * @param curActivity 当前Activity
36 | * @param helper Activity栈管理类
37 | * @param config 参数配置
38 | * @param listener 滑动的监听
39 | * @return 处理侧滑的布局,提高方法动态设置滑动相关参数
40 | */
41 | public static SlideBackLayout attach(@NonNull final Activity curActivity, @NonNull final ActivityHelper helper, @Nullable final SlideConfig config, @Nullable final OnSlideListener listener) {
42 |
43 | if (helper.getPreActivity()==null){
44 | // 内存不足应用被杀的话,直接返回一个空实现的SlideBackLayout,这时候滑动功能就失效了
45 | return new SlideBackLayout(curActivity);
46 | }
47 |
48 | final ViewGroup decorView = getDecorView(curActivity);
49 | final View contentView = decorView.getChildAt(0);
50 | decorView.removeViewAt(0);
51 |
52 | View content = contentView.findViewById(android.R.id.content);
53 | if (content.getBackground() == null) {
54 | content.setBackground(decorView.getBackground());
55 | }
56 |
57 | final Activity[] preActivity = {helper.getPreActivity()};
58 | final View[] preContentView = {getContentView(preActivity[0])};
59 | Drawable preDecorViewDrawable = getDecorViewDrawable(preActivity[0]);
60 | content = preContentView[0].findViewById(android.R.id.content);
61 | if (content.getBackground() == null) {
62 | content.setBackground(preDecorViewDrawable);
63 | }
64 |
65 | final SlideBackLayout slideBackLayout;
66 | slideBackLayout = new SlideBackLayout(curActivity, contentView, preContentView[0], preDecorViewDrawable, config, new OnInternalStateListener() {
67 |
68 | @Override
69 | public void onSlide(float percent) {
70 | if (listener != null) {
71 | listener.onSlide(percent);
72 | }
73 | }
74 |
75 | @Override
76 | public void onOpen() {
77 | if (listener != null) {
78 | listener.onOpen();
79 | }
80 | }
81 |
82 | @Override
83 | public void onClose(Boolean finishActivity) {
84 |
85 | // finishActivity为true时关闭页面,为false时不关闭页面,为null时为其他地方关闭页面时调用SlideBackLayout.isComingToFinish的回调
86 |
87 | if (listener != null) {
88 | listener.onClose();
89 | }
90 |
91 | if ((finishActivity == null || !finishActivity) && listener != null) {
92 | listener.onClose();
93 | }
94 |
95 | if (config != null && config.isRotateScreen()) {
96 |
97 | if (finishActivity != null && finishActivity) {
98 | // remove了preContentView后布局会重新调整,这时候contentView回到原处,所以要设不可见
99 | contentView.setVisibility(View.INVISIBLE);
100 | }
101 |
102 | if (preActivity[0] != null && preContentView[0].getParent() != getDecorView(preActivity[0])) {
103 | // Log.e("TAG", ((SlideBackLayout) preContentView[0].getParent()).getTestName() + "这里把欠人的布局放回到上个Activity");
104 | preContentView[0].setX(0);
105 | ((ViewGroup) preContentView[0].getParent()).removeView(preContentView[0]);
106 | getDecorView(preActivity[0]).addView(preContentView[0], 0);
107 | }
108 | //else {
109 | // Log.e("TAG", "这个页面你都没加过,还是在上一个那里,你没欠我");
110 | //}
111 | }
112 |
113 | if (finishActivity != null && finishActivity) {
114 | curActivity.finish();
115 | curActivity.overridePendingTransition(0, R.anim.anim_out_none);
116 | helper.postRemoveActivity(curActivity);
117 | } else if (finishActivity == null) {
118 | helper.postRemoveActivity(curActivity);
119 | }
120 | }
121 |
122 | @Override
123 | public void onCheckPreActivity(SlideBackLayout slideBackLayout) {
124 | // Log.e("TAG", "--------------------------------------------------");
125 | // helper.printAllActivity();
126 | // Log.e("TAG", "--------------------------------------------------");
127 | Activity activity = helper.getPreActivity();
128 | // Log.e("TAG", "SlideBackHelper-120行-onFocus(): " + preActivity[0] + ";" + activity);
129 | if (activity != preActivity[0]) {
130 | // Log.e("TAG", "SlideBackHelper-122行-onFocus(): 上个Activity变了");
131 | preActivity[0] = activity;
132 | preContentView[0] = getContentView(preActivity[0]);
133 | slideBackLayout.updatePreContentView(preContentView[0]);
134 | }
135 | }
136 |
137 | });
138 |
139 | decorView.addView(slideBackLayout);
140 |
141 | return slideBackLayout;
142 | }
143 |
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/library/src/main/java/com/oubowu/slideback/SlideConfig.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback;
2 |
3 | import android.support.annotation.FloatRange;
4 |
5 | /**
6 | * Created by Oubowu on 2016/9/22 23:37.
7 | */
8 | public class SlideConfig {
9 |
10 | private boolean mEdgeOnly;
11 | private boolean mLock;
12 |
13 | @FloatRange(from = 0.0,
14 | to = 1.0)
15 | private float mEdgePercent;
16 | @FloatRange(from = 0.0,
17 | to = 1.0)
18 | private float mSlideOutPercent;
19 |
20 | private float mSlideOutVelocity;
21 |
22 | private boolean mRotateScreen;
23 |
24 | public boolean isEdgeOnly() {
25 | return mEdgeOnly;
26 | }
27 |
28 | public boolean isLock() {
29 | return mLock;
30 | }
31 |
32 | public float getEdgePercent() {
33 | return mEdgePercent;
34 | }
35 |
36 | public float getSlideOutPercent() {
37 | return mSlideOutPercent;
38 | }
39 |
40 | public float getSlideOutVelocity() {
41 | return mSlideOutVelocity;
42 | }
43 |
44 | /**
45 | * 屏幕是否旋转,针对是否旋转两种方案实现侧滑
46 | *
47 | * @return true为屏幕旋转,false为屏幕不旋转
48 | */
49 | public boolean isRotateScreen() {
50 | return mRotateScreen;
51 | }
52 |
53 | private SlideConfig() {
54 | }
55 |
56 | public SlideConfig(Builder builder) {
57 | mEdgeOnly = builder.edgeOnly;
58 | mLock = builder.lock;
59 | mEdgePercent = builder.edgePercent;
60 | mSlideOutPercent = builder.slideOutPercent;
61 | mSlideOutVelocity = builder.slideOutVelocity;
62 | mRotateScreen = builder.rotateScreen;
63 | }
64 |
65 | public static class Builder {
66 |
67 | private boolean edgeOnly = false;
68 | private boolean lock = false;
69 |
70 | @FloatRange(from = 0.0,
71 | to = 1.0)
72 | private float edgePercent = 0.4f;
73 | @FloatRange(from = 0.0,
74 | to = 1.0)
75 | private float slideOutPercent = 0.1f;
76 |
77 | private float slideOutVelocity = 2000f;
78 |
79 | private boolean rotateScreen = false;
80 |
81 | public Builder() {
82 | }
83 |
84 | public SlideConfig create() {
85 | return new SlideConfig(this);
86 | }
87 |
88 | public Builder edgeOnly(boolean edgeOnly) {
89 | this.edgeOnly = edgeOnly;
90 | return this;
91 | }
92 |
93 | public Builder lock(boolean lock) {
94 | this.lock = lock;
95 | return this;
96 | }
97 |
98 | public Builder slideOutVelocity(float slideOutVelocity) {
99 | this.slideOutVelocity = slideOutVelocity;
100 | return this;
101 | }
102 |
103 | public Builder edgePercent(@FloatRange(from = 0.0,
104 | to = 1.0) float edgePercent) {
105 | this.edgePercent = edgePercent;
106 | return this;
107 | }
108 |
109 | public Builder slideOutPercent(@FloatRange(from = 0.0,
110 | to = 1.0) float slideOutPercent) {
111 | this.slideOutPercent = slideOutPercent;
112 | return this;
113 | }
114 |
115 | /**
116 | * 屏幕是否旋转,针对是否旋转两种方案实现侧滑
117 | *
118 | * @return true为屏幕旋转,false为屏幕不旋转
119 | */
120 | public Builder rotateScreen(boolean rotateScreen) {
121 | this.rotateScreen = rotateScreen;
122 | return this;
123 | }
124 |
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/library/src/main/java/com/oubowu/slideback/callbak/OnInternalStateListener.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.callbak;
2 |
3 | import android.support.annotation.FloatRange;
4 |
5 | import com.oubowu.slideback.widget.SlideBackLayout;
6 |
7 | /**
8 | * Created by Oubowu on 2016/9/22 0022 18:22.
9 | */
10 | public interface OnInternalStateListener {
11 |
12 | void onSlide(@FloatRange(from = 0.0,
13 | to = 1.0) float percent);
14 |
15 | void onOpen();
16 |
17 | void onClose(Boolean finishActivity);
18 |
19 | void onCheckPreActivity(SlideBackLayout slideBackLayout);
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/library/src/main/java/com/oubowu/slideback/callbak/OnSlideListener.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.callbak;
2 |
3 | import android.support.annotation.FloatRange;
4 |
5 | /**
6 | * Created by Oubowu on 2016/9/22 0022 18:22.
7 | */
8 | public interface OnSlideListener {
9 |
10 | void onSlide(@FloatRange(from = 0.0,
11 | to = 1.0) float percent);
12 |
13 | void onOpen();
14 |
15 | void onClose();
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/library/src/main/java/com/oubowu/slideback/callbak/OnSlideListenerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.callbak;
2 |
3 | import android.support.annotation.FloatRange;
4 |
5 | /**
6 | * Created by Oubowu on 2016/9/23 0:05.
7 | */
8 | public class OnSlideListenerAdapter implements OnSlideListener {
9 | @Override
10 | public void onSlide(@FloatRange(from = 0.0,
11 | to = 1.0) float percent) {
12 |
13 | }
14 |
15 | @Override
16 | public void onOpen() {
17 |
18 | }
19 |
20 | @Override
21 | public void onClose() {
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/library/src/main/java/com/oubowu/slideback/widget/CacheDrawView.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.view.View;
6 |
7 |
8 | /**
9 | * Created by Oubowu on 2016/9/20 0020 11:19.
10 | */
11 | public class CacheDrawView extends View {
12 |
13 | private View mCacheView;
14 |
15 | public CacheDrawView(Context context) {
16 | super(context);
17 | }
18 |
19 | public void drawCacheView(View cacheView) {
20 | mCacheView = cacheView;
21 | invalidate();
22 | }
23 |
24 | @Override
25 | protected void onDraw(Canvas canvas) {
26 | if (mCacheView != null) {
27 | // canvas.drawColor(Color.YELLOW);
28 | mCacheView.draw(canvas);
29 | // Log.e("TAG", "绘制上个Activity的内容视图...");
30 | }
31 | }
32 |
33 | @Override
34 | protected void onDetachedFromWindow() {
35 | super.onDetachedFromWindow();
36 | // Log.e("TAG", "CacheDrawView-37行-onDetachedFromWindow(): ");
37 | mCacheView = null;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/library/src/main/java/com/oubowu/slideback/widget/ShadowView.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.widget;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.res.Configuration;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.LinearGradient;
9 | import android.graphics.Paint;
10 | import android.graphics.RectF;
11 | import android.graphics.Shader;
12 | import android.support.annotation.FloatRange;
13 | import android.view.View;
14 |
15 | /**
16 | * Created by Oubowu on 2016/9/20 0020 11:22.
17 | */
18 | public class ShadowView extends View {
19 |
20 | private LinearGradient mLinearGradient;
21 | private Paint mPaint;
22 | private RectF mRectF;
23 | private float mAlphaPercent = -1;
24 |
25 | public ShadowView(Context context) {
26 | super(context);
27 | mPaint = new Paint();
28 | }
29 |
30 | @Override
31 | protected void onDraw(Canvas canvas) {
32 | if (mAlphaPercent >= 0) {
33 | // 绘制渐变阴影
34 | if (mLinearGradient == null) {
35 | mRectF = new RectF();
36 | int[] colors = {Color.parseColor("#0A000000"), Color.parseColor("#66000000"), Color.parseColor("#aa000000")};
37 | // 我设置着色器开始的位置为(0,0),结束位置为(getWidth(), 0)表示我的着色器要给整个View在水平方向上渲染
38 | mLinearGradient = new LinearGradient(0, 0, getWidth(), 0, colors, null, Shader.TileMode.REPEAT);
39 | mPaint.setShader(mLinearGradient);
40 | mRectF.set(0, 0, getWidth(), getHeight());
41 | }
42 | mPaint.setAlpha((int) (mAlphaPercent * 255));
43 | canvas.drawRect(mRectF, mPaint);
44 | }
45 | }
46 |
47 | public void redraw(@FloatRange(from = 0.0,
48 | to = 1.0) float alphaPercent) {
49 | mAlphaPercent = alphaPercent;
50 | invalidate();
51 | }
52 |
53 | @Override
54 | protected void onConfigurationChanged(Configuration newConfig) {
55 | super.onConfigurationChanged(newConfig);
56 | mLinearGradient = null;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/library/src/main/java/com/oubowu/slideback/widget/SlideBackLayout.java:
--------------------------------------------------------------------------------
1 | package com.oubowu.slideback.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.Configuration;
5 | import android.graphics.drawable.Drawable;
6 | import android.support.annotation.FloatRange;
7 | import android.support.annotation.NonNull;
8 | import android.support.v4.view.ViewGroupCompat;
9 | import android.support.v4.widget.ViewDragHelper;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.FrameLayout;
14 | import android.widget.LinearLayout;
15 |
16 | import com.oubowu.slideback.SlideConfig;
17 | import com.oubowu.slideback.callbak.OnInternalStateListener;
18 |
19 | /**
20 | * Created by Oubowu on 2016/9/22 0022 15:24.
21 | */
22 | public class SlideBackLayout extends FrameLayout {
23 |
24 | private static final int MIN_FLING_VELOCITY = 400;
25 | private String mTestName;
26 | private boolean mCheckPreContentView;
27 | private boolean mIsFirstAttachToWindow;
28 | private ViewDragHelper mDragHelper;
29 | private View mContentView;
30 | private CacheDrawView mCacheDrawView;
31 | private ShadowView mShadowView;
32 | private View mPreContentView;
33 | private Drawable mPreDecorViewDrawable;
34 | private int mScreenWidth;
35 |
36 | private boolean mEdgeOnly = false;
37 | private boolean mLock = false;
38 |
39 | @FloatRange(from = 0.0,
40 | to = 1.0)
41 | private float mSlideOutRangePercent = 0.4f;
42 |
43 | @FloatRange(from = 0.0,
44 | to = 1.0)
45 | private float mEdgeRangePercent = 0.1f;
46 |
47 | private float mSlideOutRange;
48 | private float mEdgeRange;
49 |
50 | private float mSlideOutVelocity;
51 |
52 | private boolean mIsEdgeRangeInside;
53 |
54 | private OnInternalStateListener mOnInternalStateListener;
55 |
56 | private float mDownX;
57 | private float mDownY;
58 |
59 | private float mSlidDistantX;
60 |
61 | private boolean mRotateScreen;
62 | private boolean mCloseFlagForWindowFocus;
63 | private boolean mCloseFlagForDetached;
64 | private boolean mEnableTouchEvent;
65 |
66 | public SlideBackLayout(@NonNull Context context) {
67 | super(context);
68 | }
69 |
70 | public SlideBackLayout(Context context, View contentView, View preContentView, Drawable preDecorViewDrawable, SlideConfig config, @NonNull OnInternalStateListener onInternalStateListener) {
71 | super(context);
72 | mContentView = contentView;
73 | mPreContentView = preContentView;
74 | mPreDecorViewDrawable = preDecorViewDrawable;
75 | mOnInternalStateListener = onInternalStateListener;
76 |
77 | initConfig(config);
78 |
79 | if (preContentView instanceof LinearLayout) {
80 | mTestName = "1号滑动";
81 | } else {
82 | mTestName = "2号滑动";
83 | }
84 | // Log.e("TAG", "创建了: " + mTestName);
85 |
86 | }
87 |
88 | private void initConfig(SlideConfig config) {
89 |
90 | if (config == null) {
91 | config = new SlideConfig.Builder().create();
92 | }
93 |
94 | mScreenWidth = getResources().getDisplayMetrics().widthPixels;
95 |
96 | final float density = getResources().getDisplayMetrics().density;
97 | final float minVel = MIN_FLING_VELOCITY * density;
98 |
99 | ViewGroupCompat.setMotionEventSplittingEnabled(this, false);
100 | SlideLeftCallback slideLeftCallback = new SlideLeftCallback();
101 | mDragHelper = ViewDragHelper.create(this, 1.0f, slideLeftCallback);
102 | // 最小拖动速度
103 | mDragHelper.setMinVelocity(minVel);
104 | mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
105 |
106 | mCacheDrawView = new CacheDrawView(getContext());
107 | mCacheDrawView.setVisibility(INVISIBLE);
108 | addView(mCacheDrawView);
109 |
110 | mShadowView = new ShadowView(getContext());
111 | mShadowView.setVisibility(INVISIBLE);
112 | addView(mShadowView, mScreenWidth / 28, LayoutParams.MATCH_PARENT);
113 |
114 | addView(mContentView);
115 |
116 | mEdgeOnly = config.isEdgeOnly();
117 | mLock = config.isLock();
118 | mRotateScreen = config.isRotateScreen();
119 |
120 | mSlideOutRangePercent = config.getSlideOutPercent();
121 | mEdgeRangePercent = config.getEdgePercent();
122 |
123 | mSlideOutRange = mScreenWidth * mSlideOutRangePercent;
124 | mEdgeRange = mScreenWidth * mEdgeRangePercent;
125 | mSlideOutVelocity = config.getSlideOutVelocity();
126 |
127 | mSlidDistantX = mScreenWidth / 20.0f;
128 |
129 | mContentView.setFitsSystemWindows(false);
130 |
131 | if (mRotateScreen) {
132 | mContentView.findViewById(android.R.id.content).setOnClickListener(new OnClickListener() {
133 | @Override
134 | public void onClick(View v) {
135 | // 屏蔽上个内容页的点击事件
136 | }
137 | });
138 | }
139 |
140 | }
141 |
142 | @Override
143 | public boolean onInterceptTouchEvent(MotionEvent event) {
144 |
145 | switch (event.getAction()) {
146 | case MotionEvent.ACTION_DOWN:
147 | mDownX = event.getX();
148 | mDownY = event.getY();
149 | break;
150 | case MotionEvent.ACTION_MOVE:
151 | // 优化侧滑的逻辑,不要一有稍微的滑动就被ViewDragHelper拦截掉了
152 | // Log.e("SlideBackLayout",event.getY()+" "+mDownY+" "+mSlidDistantX);
153 | if (Math.abs(event.getY() - mDownY) > mSlidDistantX){
154 | return false;
155 | }
156 | if (event.getX() - mDownX < mSlidDistantX) {
157 | return false;
158 | }
159 | break;
160 | }
161 |
162 | if (mLock) {
163 | return false;
164 | }
165 |
166 | if (mEdgeOnly) {
167 | float x = event.getX();
168 | mIsEdgeRangeInside = isEdgeRangeInside(x);
169 | return mIsEdgeRangeInside && mDragHelper.shouldInterceptTouchEvent(event);
170 | } else {
171 | return mDragHelper.shouldInterceptTouchEvent(event);
172 | }
173 |
174 | }
175 |
176 | private boolean isEdgeRangeInside(float x) {
177 | return x <= mEdgeRange;
178 | }
179 |
180 | @Override
181 | public boolean onTouchEvent(MotionEvent event) {
182 |
183 | if (mLock) {
184 | return super.onTouchEvent(event);
185 | }
186 |
187 | if (!mEdgeOnly || mIsEdgeRangeInside) {
188 | if (!mEnableTouchEvent) {
189 | return super.onTouchEvent(event);
190 | }
191 | if (mCloseFlagForDetached || mCloseFlagForWindowFocus) {
192 | // 针对快速滑动的时候,页面关闭的时候移除上个页面的时候,布局重新调整,这时候我们把contentView设为invisible,
193 | // 但是还是可以响应DragHelper的处理,所以这里根据页面关闭的标志位不给处理事件了
194 | // Log.e("TAG", mTestName + "都要死了,还处理什么触摸事件!!");
195 | return super.onTouchEvent(event);
196 | }
197 | mDragHelper.processTouchEvent(event);
198 | } else {
199 | return super.onTouchEvent(event);
200 | }
201 | return true;
202 | }
203 |
204 | private void addPreContentView() {
205 | if (mPreContentView.getParent() != SlideBackLayout.this) {
206 | // Log.e("TAG", mTestName + ": 我要把上个页面的内容页加到我这里啦!");
207 | mPreContentView.setTag("notScreenOrientationChange");
208 | ((ViewGroup) mPreContentView.getParent()).removeView(mPreContentView);
209 | SlideBackLayout.this.addView(mPreContentView, 0);
210 | mShadowView.setVisibility(VISIBLE);
211 | }
212 | }
213 |
214 | @Override
215 | public void computeScroll() {
216 | if (mDragHelper.continueSettling(true)) {
217 | invalidate();
218 | }
219 | }
220 |
221 | public void isComingToFinish() {
222 | if (mRotateScreen) {
223 | mCloseFlagForDetached = true;
224 | mCloseFlagForWindowFocus = false;
225 | mOnInternalStateListener.onClose(null);
226 | mPreContentView.setX(0);
227 | }
228 | }
229 |
230 | public String getTestName() {
231 | return mTestName;
232 | }
233 |
234 | public void updatePreContentView(View contentView) {
235 | mPreContentView = contentView;
236 | mCacheDrawView.drawCacheView(mPreContentView);
237 | }
238 |
239 | class SlideLeftCallback extends ViewDragHelper.Callback {
240 |
241 | @Override
242 | public boolean tryCaptureView(View child, int pointerId) {
243 | return child == mContentView;
244 | }
245 |
246 | @Override
247 | public int clampViewPositionHorizontal(View child, int left, int dx) {
248 | return Math.max(Math.min(mScreenWidth, left), 0);
249 | }
250 |
251 | @Override
252 | public int getViewHorizontalDragRange(View child) {
253 | return mScreenWidth;
254 | }
255 |
256 | @Override
257 | public void onViewReleased(View releasedChild, float xvel, float yvel) {
258 | if (releasedChild == mContentView) {
259 |
260 | if (xvel > mSlideOutVelocity) {
261 | mDragHelper.settleCapturedViewAt(mScreenWidth, 0);
262 | invalidate();
263 | return;
264 | }
265 |
266 | if (mContentView.getLeft() < mSlideOutRange) {
267 | mDragHelper.settleCapturedViewAt(0, 0);
268 | } else {
269 | mDragHelper.settleCapturedViewAt(mScreenWidth, 0);
270 | }
271 |
272 | invalidate();
273 | }
274 | }
275 |
276 | @Override
277 | public void onViewDragStateChanged(int state) {
278 | switch (state) {
279 | case ViewDragHelper.STATE_IDLE:
280 | if (mContentView.getLeft() == 0) {
281 | // 2016/9/22 0022 回到原处
282 | mOnInternalStateListener.onOpen();
283 | } else if (mContentView.getLeft() == mScreenWidth) {
284 | // 2016/9/22 0022 结束Activity
285 |
286 | // 这里再绘制一次是因为在屏幕旋转的模式下,remove了preContentView后布局会重新调整
287 | if (mRotateScreen && mCacheDrawView.getVisibility() == INVISIBLE) {
288 | mCacheDrawView.setBackground(mPreDecorViewDrawable);
289 | mCacheDrawView.drawCacheView(mPreContentView);
290 | mCacheDrawView.setVisibility(VISIBLE);
291 | // Log.e("TAG", mTestName + ": 这里再绘制一次是因为在屏幕旋转的模式下,remove了preContentView后布局会重新调整");
292 | mCloseFlagForWindowFocus = true;
293 | mCloseFlagForDetached = true;
294 | // Log.e("TAG", mTestName + ": 滑动到尽头了这个界面要死了,把preContentView给回上个Activity");
295 | // 这里setTag是因为下面的回调会把它移除出当前页面,这时候会触发它的onDetachedFromWindow事件,
296 | // 而它的onDetachedFromWindow实际上是来处理屏幕旋转的,所以设置个tag给它,让它知道是当前界面移除它的,并不是屏幕旋转导致的
297 | mPreContentView.setTag("notScreenOrientationChange");
298 | mOnInternalStateListener.onClose(true);
299 | mPreContentView.postDelayed(new Runnable() {
300 | @Override
301 | public void run() {
302 | mCacheDrawView.setBackground(mPreDecorViewDrawable);
303 | mCacheDrawView.drawCacheView(mPreContentView);
304 | }
305 | }, 10);
306 | } else if (!mRotateScreen) {
307 | mCloseFlagForWindowFocus = true;
308 | mCloseFlagForDetached = true;
309 | mOnInternalStateListener.onClose(true);
310 | }
311 |
312 | }
313 | break;
314 | default:
315 | break;
316 | }
317 | }
318 |
319 | @Override
320 | public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
321 |
322 | if (!mRotateScreen && mCacheDrawView.getVisibility() == INVISIBLE) {
323 | mCacheDrawView.setBackground(mPreDecorViewDrawable);
324 | mCacheDrawView.drawCacheView(mPreContentView);
325 | mCacheDrawView.setVisibility(VISIBLE);
326 | } else if (mRotateScreen) {
327 |
328 | if (!mCheckPreContentView) {
329 |
330 | // 在旋转屏幕的模式下,这里的检查很有必要,比如一个滑动activity先旋转了屏幕,然后再返回上个滑动activity的时候,由于屏幕旋转上个activity会重建,步骤是:
331 | // 上个activity会先新建一个activity,再把之前的销毁,所以新建的activity调SlideBackLayout.attach的时候传的上个activity实际上是要删掉的activity
332 | // (因为要删掉的activity的destroy有延时的,还没销毁掉),这就出错了;
333 | // 所以这里还要在当前页面取得焦点的时候回调,去检查下看是不是上个activity改了,改了再重新赋值
334 |
335 | mCheckPreContentView = true;
336 | // 只需要检查一次上个Activity是不是变了
337 | // Log.e("TAG","只需要检查一次上个Activity是不是变了");
338 | mOnInternalStateListener.onCheckPreActivity(SlideBackLayout.this);
339 | }
340 |
341 | addPreContentView();
342 |
343 | }
344 |
345 | if (mShadowView.getVisibility() != VISIBLE) {
346 | mShadowView.setVisibility(VISIBLE);
347 | }
348 |
349 | final float percent = left * 1.0f / mScreenWidth;
350 |
351 | mOnInternalStateListener.onSlide(percent);
352 |
353 | if (mRotateScreen) {
354 | // // Log.e("TAG", "滑动上个页面");
355 | mPreContentView.setX(-mScreenWidth / 2 + percent * (mScreenWidth / 2));
356 | } else {
357 | mCacheDrawView.setX(-mScreenWidth / 2 + percent * (mScreenWidth / 2));
358 | }
359 | mShadowView.setX(mContentView.getX() - mShadowView.getWidth());
360 | mShadowView.redraw(1 - percent);
361 | }
362 | }
363 |
364 |
365 | public void edgeOnly(boolean edgeOnly) {
366 | mEdgeOnly = edgeOnly;
367 | }
368 |
369 | public boolean isEdgeOnly() {
370 | return mEdgeOnly;
371 | }
372 |
373 | public void lock(boolean lock) {
374 | mLock = lock;
375 | }
376 |
377 | public boolean isLock() {
378 | return mLock;
379 | }
380 |
381 | public void setSlideOutRangePercent(float slideOutRangePercent) {
382 | mSlideOutRangePercent = slideOutRangePercent;
383 | mSlideOutRange = mScreenWidth * mSlideOutRangePercent;
384 | }
385 |
386 | public float getSlideOutRangePercent() {
387 | return mSlideOutRangePercent;
388 | }
389 |
390 | public void setEdgeRangePercent(float edgeRangePercent) {
391 | mEdgeRangePercent = edgeRangePercent;
392 | mEdgeRange = mScreenWidth * mEdgeRangePercent;
393 | }
394 |
395 | public float getEdgeRangePercent() {
396 | return mEdgeRangePercent;
397 | }
398 |
399 | @Override
400 | public void onWindowFocusChanged(boolean hasWindowFocus) {
401 | super.onWindowFocusChanged(hasWindowFocus);
402 | // // Log.e("TAG", "onWindowFocusChanged(): " + this + " ; " + hasWindowFocus);
403 |
404 | if (hasWindowFocus) {
405 |
406 | mEnableTouchEvent = true;
407 |
408 | // Log.e("TAG", "SlideBackLayout-378行-onWindowFocusChanged(): " + hasWindowFocus);
409 |
410 | // 当前页面
411 | if (!mIsFirstAttachToWindow) {
412 | mIsFirstAttachToWindow = true;
413 | // Log.e("TAG", mTestName + ": 第一次窗口取得焦点");
414 | } /*else if (mRotateScreen && mPreContentView.getParent() != SlideBackLayout.this) {
415 | // Log.e("TAG", mTestName + ": 从其他Activity返回来了 ");
416 | }*/
417 | } else {
418 | if (mRotateScreen) {
419 | // 1.跳转到另外一个Activity,例如也是需要滑动的,这时候就需要取当前Activity的contentView,所以这里把preContentView给回上个Activity
420 | if (mCloseFlagForWindowFocus) {
421 | mCloseFlagForWindowFocus = false;
422 | // Log.e("TAG", mTestName + ": onWindowFocusChanged前已经调了关闭");
423 | } else {
424 | // Log.e("TAG", mTestName + ": 跳转到另外一个Activity,取这个Activity的contentView前把preContentView给回上个Activity");
425 | mOnInternalStateListener.onClose(false);
426 | }
427 | }
428 | }
429 |
430 | }
431 |
432 | @Override
433 | protected void onDetachedFromWindow() {
434 | super.onDetachedFromWindow();
435 | mEnableTouchEvent = false;
436 | // // Log.e("TAG", "SlideBackLayout-345行-onDetachedFromWindow(): " + this);
437 | if (mRotateScreen) {
438 | // 1.旋转屏幕的时候必调此方法,这里掉onClose目的是把preContentView给回上个Activity
439 | if (mCloseFlagForDetached) {
440 | mCloseFlagForDetached = false;
441 | // Log.e("TAG", mTestName + ": onDetachedFromWindow(): " + "已经调了关闭");
442 | } else {
443 | if (getTag() != null && getTag().equals("notScreenOrientationChange")) {
444 | // 说明是手动删的不关旋转屏幕的事,所以不处理
445 | // Log.e("TAG", mTestName + ":说明是手动删的不关旋转屏幕的事,所以不处理");
446 | setTag(null);
447 | } else {
448 | // Log.e("TAG", mTestName + ":屏幕旋转了,重建界面: 把preContentView给回上个Activity");
449 | mOnInternalStateListener.onClose(false);
450 | }
451 | }
452 | }
453 | }
454 |
455 | @Override
456 | protected void onConfigurationChanged(Configuration newConfig) {
457 | super.onConfigurationChanged(newConfig);
458 | mScreenWidth = getResources().getDisplayMetrics().widthPixels;
459 | // Log.e("TAG", mTestName + ": SlideBackLayout-338行-onConfigurationChanged(): " + mScreenWidth);
460 | ViewGroup.LayoutParams layoutParams = mShadowView.getLayoutParams();
461 | layoutParams.width = mScreenWidth / 28;
462 | layoutParams.height = LayoutParams.MATCH_PARENT;
463 | }
464 |
465 | }
466 |
--------------------------------------------------------------------------------
/library/src/main/res/anim/anim_out_none.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 |
--------------------------------------------------------------------------------
/pic/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oubowu/SlideBack/a78df739ba1b4a51b6e7dc5419f6adb5540921f0/pic/demo.gif
--------------------------------------------------------------------------------
/pic/demo2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oubowu/SlideBack/a78df739ba1b4a51b6e7dc5419f6adb5540921f0/pic/demo2.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':library', ':app'
2 |
--------------------------------------------------------------------------------