oubowu / SlideBack
- четверг, 27 октября 2016 г. в 03:13:41
Java
A library to close an activity with swipe gestures.
public class MyApplication extends Application {
private ActivityHelper mActivityHelper;
private static MyApplication sMyApplication;
@Override
public void onCreate() {
super.onCreate();
mActivityHelper = new ActivityHelper();
registerActivityLifecycleCallbacks(mActivityHelper);
sMyApplication = this;
}
public static ActivityHelper getActivityHelper(){
return sMyApplication.mActivityHelper;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
mSlideBackLayout = SlideBackHelper.attach(
// 当前Activity
this,
// Activity栈管理工具
MyApplication.getActivityHelper(),
// 参数的配置
new SlideConfig.Builder()
// 屏幕是否旋转
.rotateScreen(true)
// 是否侧滑
.edgeOnly(false)
// 是否禁止侧滑
.lock(false)
// 边缘滑动的响应阈值,0~1,对应屏幕宽度*percent
.edgePercent(0.1f)
// 关闭页面的阈值,0~1,对应屏幕宽度*percent
.slideOutPercent(0.5f).create(),
// 滑动的监听
null);
// 其它初始化
}
@Override
public void onBackPressed() {
super.onBackPressed();
mSlideBackLayout.isCommingToFinish();
overridePendingTransition(R.anim.anim_none, R.anim.anim_slide_out);
}
// 是否启用边缘滑动
mSlideBackLayout.edgeOnly(boolean);
// 是否禁止滑动
mSlideBackLayout.lock(boolean);
// 设置边缘滑动的响应阈值
mSlideBackLayout.setEdgeRangePercent(float);
// 设置关闭页面的阈值
mSlideBackLayout.setSlideOutRangePercent(float);
Copyright 2016 oubowu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.