Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
dkzwm committed Jan 23, 2019
1 parent 4d5602d commit 3d26bce
Show file tree
Hide file tree
Showing 23 changed files with 571 additions and 69 deletions.
107 changes: 107 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,109 @@
# EasySwipeLayout
[![Release](https://img.shields.io/badge/JCenter-0.0.1-brightgreen.svg)](https://bintray.com/dkzwm/maven/esl)
[![MinSdk](https://img.shields.io/badge/MinSdk-14-blue.svg)](https://developer.android.com/about/versions/android-4.0.html)
## [English](https://github.com/dkzwm/EasySwipeLayout/blob/master/README_EN.md) | 中文
A simple sliding layout view, 一款简单高效的滑动库,模仿MIUI滑动返回功能。

## 特性:
- 支持上下左右边缘拉出.
- 支持全局添加、Xml添加、单独添加.
- 支持自定义效果.
- 支持多点触摸.

## 引入
添加如下依赖到你的 build.gradle 文件:
```
dependencies {
implementation 'me.dkzwm.widget.esl:core:0.0.1'
}
```

## 快照
![](https://github.com/dkzwm/EasySwipeLayout/blob/master/snapshot/demo.gif)

## 使用
#### 在Xml中配置
```
<?xml version="1.0" encoding="utf-8"?>
<me.dkzwm.widget.esl.EasySwipeLayout
android:id="@+id/easySwipeLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:esl_direction="right"
//指定自定义Drawer的类名
app:esl_specified="@string/specified_the_class_name"
//指定样式为自定义,此时需要配置esl_specified属性
app:esl_style="custom">
</me.dkzwm.widget.esl.EasySwipeLayout>
```
#### Java代码全局配置
```
EasySwipeConfig config =
new EasySwipeConfig.Builder(application)
.direction(Constants.DIRECTION_ALL)
.style(Constants.STYLE_MIUI)
.build();
EasySwipeManager.init(config);
}
```
#### Java代码单独配置
```
EasySwipeLayout layout = EasySwipeManager.attach(activity);
if (layout != null) {
layout.setDirection(Constants.DIRECTION_LEFT);
layout.setDrawer(new CustomDrawer(this));
layout.setSwipeListener(
new OnSwipeListener() {
@Override
public void onSwipe(int side) {
onBackPressed();
}
});
}
```
#### Xml属性
|名称|类型|描述|
|:---:|:---:|:---:|
|esl_edgeDiff|reference|配置边缘点击容差,默认为2倍系统触摸容差(系统ScaledTouchSlop*2)|
|esl_style|enum|配置拉出的效果,默认MIUI效果|
|esl_specified|string|配置自定义效果的实现类路径,仅当`esl_style``custom`时生效|
|esl_resistance|float|配置移动阻尼(默认:`3f`|
|esl_durationOfClose|int|配置收起效果的时长(默认:`500`|
|esl_direction|enum|配置支持划出方向(默认:`左边缘往右划`|

#### java属性设置方法
|名称|参数|描述|
|:---:|:---:|:---:|
|setSwipeListener|OnSwipeListener|配置监听|
|setDirection|int|配置支持划出方向|
|setStyle|int,String|配置拉出的效果|
|setDrawer|Drawer|配置指定自定义效果实现|
|setEdgeDiff|int|配置边缘点击容差|
|setResistance|float|配置移动阻尼|
|setDurationOfClose|int|配置收起效果的时长|

## License

MIT License

Copyright (c) 2018 dkzwm

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
107 changes: 107 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# EasySwipeLayout
[![Release](https://img.shields.io/badge/JCenter-0.0.1-brightgreen.svg)](https://bintray.com/dkzwm/maven/esl)
[![MinSdk](https://img.shields.io/badge/MinSdk-14-blue.svg)](https://developer.android.com/about/versions/android-4.0.html)
## English | [中文](https://github.com/dkzwm/EasySwipeLayout/blob/master/README.md)
A simple sliding layout view

## Features:
- Supports all direction.
- Supports code addition, xml addition.
- Supports custom drawer.
- Supports Multi-Touch.

## Installation
Add the following dependency to your build.gradle file:
```
dependencies {
implementation 'me.dkzwm.widget.esl:core:0.0.1'
}
```

## Snapshot
![](https://github.com/dkzwm/EasySwipeLayout/blob/master/snapshot/demo.gif)

## How to use
#### Xml
```
<?xml version="1.0" encoding="utf-8"?>
<me.dkzwm.widget.esl.EasySwipeLayout
android:id="@+id/easySwipeLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:esl_direction="right"
app:esl_specified="@string/specified_the_class_name"
app:esl_style="custom">
</me.dkzwm.widget.esl.EasySwipeLayout>
```
#### Global
```
EasySwipeConfig config =
new EasySwipeConfig.Builder(application)
.direction(Constants.DIRECTION_ALL)
.style(Constants.STYLE_MIUI)
.build();
EasySwipeManager.init(config);
}
```
#### Separate
```
EasySwipeLayout layout = EasySwipeManager.attach(activity);
if (layout != null) {
layout.setDirection(Constants.DIRECTION_LEFT);
layout.setDrawer(new CustomDrawer(this));
layout.setSwipeListener(
new OnSwipeListener() {
@Override
public void onSwipe(int side) {
onBackPressed();
}
});
}
```
#### Xml attr
|Name|Format|Desc|
|:---:|:---:|:---:|
|esl_edgeDiff|reference|Configure the distance in pixels a touch can wander before we think the user is scrolling(default:two times of system ScaledTouchSlop)|
|esl_style|enum|Configure the style of Drawer, (Default: MIUI)|
|esl_specified|string|Configure the path to the implementation class for the custom style,Only valid when `esl_style` is `custom`|
|esl_resistance|float|Configure resistance to touch movement(Default:`3f`|
|esl_durationOfClose|int|Configure the duration of close Drawer(Default:`500`|
|esl_direction|enum|Configure support direction(Default:`left`|

#### Java method
|Name|Params|Desc|
|:---:|:---:|:---:|
|setSwipeListener|OnSwipeListener|Configure listener|
|setDirection|int|Configure support direction|
|setStyle|int,String|Configure the style of Drawer|
|setDrawer|Drawer|Configure the custom Drawer|
|setEdgeDiff|int|Configure the distance in pixels a touch can wander before we think the user is scrolling|
|setResistance|float|Configure resistance to touch movement|
|setDurationOfClose|int|Configure the duration of close Drawer|

## License

MIT License

Copyright (c) 2018 dkzwm

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 11 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
applicationId "me.dkzwm.widget.esl.demo"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
minSdkVersion 16
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false
}
}


dependencies {
implementation project(':core')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation rootProject.ext.libs.appcompatV7
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".ui.CustomActivity"/>
<activity android:name=".ui.XmlCustomActivity"/>
<activity android:name=".ui.CodeCustomActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package me.dkzwm.widget.esl.demo.ui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import me.dkzwm.widget.esl.EasySwipeLayout;
import me.dkzwm.widget.esl.EasySwipeManager;
import me.dkzwm.widget.esl.IgnoreMakeEasy;
import me.dkzwm.widget.esl.OnSwipeListener;
import me.dkzwm.widget.esl.config.Constants;
import me.dkzwm.widget.esl.demo.R;
import me.dkzwm.widget.esl.demo.graphics.CustomDrawer;

public class CodeCustomActivity extends AppCompatActivity implements IgnoreMakeEasy {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_code_custom);
EasySwipeLayout layout = EasySwipeManager.attach(this);
if (layout != null) {
layout.setDirection(Constants.DIRECTION_LEFT);
layout.setDrawer(new CustomDrawer(this));
layout.setSwipeListener(
new OnSwipeListener() {
@Override
public void onSwipe(int side) {
onBackPressed();
}
});
}
}

@Override
protected void onDestroy() {
super.onDestroy();
EasySwipeManager.detach(this);
}
}
14 changes: 12 additions & 2 deletions app/src/main/java/me/dkzwm/widget/esl/demo/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ public void run() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button_go_custom)
findViewById(R.id.button_go_xml_custom)
.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, CustomActivity.class));
startActivity(
new Intent(MainActivity.this, XmlCustomActivity.class));
}
});
findViewById(R.id.button_go_code_custom)
.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(
new Intent(MainActivity.this, CodeCustomActivity.class));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import me.dkzwm.widget.esl.OnSwipeListener;
import me.dkzwm.widget.esl.demo.R;

public class CustomActivity extends AppCompatActivity implements IgnoreMakeEasy {
public class XmlCustomActivity extends AppCompatActivity implements IgnoreMakeEasy {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom);
setContentView(R.layout.activity_xml_custom);
EasySwipeLayout layout = findViewById(R.id.easySwipeLayout);
layout.setSwipeListener(
new OnSwipeListener() {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_code_custom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="16dp"
android:text="@string/only_supports_left_side_swipe"
android:textColor="@android:color/black"
android:textSize="24sp"/>
27 changes: 21 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,28 @@
android:layout_height="match_parent"
android:background="@android:color/holo_blue_light"/>

<Button
android:id="@+id/button_go_custom"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/custom"
android:textAllCaps="false"/>
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">

<Button
android:id="@+id/button_go_xml_custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/test_xml_custom"
android:textAllCaps="false"/>

<Button
android:id="@+id/button_go_code_custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/test_code_custom"
android:textAllCaps="false"/>
</LinearLayout>

<View
android:layout_width="200dp"
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<string name="app_name">EasySwipeLayout</string>
<string name="press_again_to_exit">再按一次退出</string>
<string name="specified_the_class_name">.graphics.CustomDrawer</string>
<string name="custom">自定义</string>
<string name="test_xml_custom">Xml自定义</string>
<string name="only_supports_right_side_swipe">测试只支持右侧拉出</string>
<string name="only_supports_left_side_swipe">测试只支持左侧拉出</string>
<string name="test_code_custom">代码自定义</string>
</resources>
Loading

0 comments on commit 3d26bce

Please sign in to comment.