Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.2 #8

Merged
merged 2 commits into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
Change Log
==========

Version 1.0.2 *(2016-12-29)*
----------------------------

* 增加 setIsWeChatStyle 方法,设置是否是微信滑动返回样式,默认值为 true「如果需要启用微信滑动返回样式,必须在 Application 的 onCreate 方法中执行 BGASwipeBackManager.getInstance().init(this)」
* 增加 setShadowResId 方法,设置阴影资源 id,默认值为 R.drawable.bga_swipebacklayout_shadow
* 增加 setIsShadowAlphaGradient,设置阴影区域的透明度是否根据滑动的距离渐变。默认值为 true

Version 1.0.1 *(2016-12-28)*
----------------------------

* 增加 setSwipeBackEnable 方法,设置滑动返回是否可用
* 增加 setIsNeedShowShadow 方法,设置是否显示滑动返回的阴影效果
* 增加 setIsOnlyTrackingLeftEdge 方法,设置是否仅仅跟踪左侧边缘的滑动返回
* 增加 setSwipeBackEnable 方法,设置滑动返回是否可用,默认值为 true
* 增加 setIsNeedShowShadow 方法,设置是否显示滑动返回的阴影效果,默认值为 true
* 增加 setIsOnlyTrackingLeftEdge 方法,设置是否仅仅跟踪左侧边缘的滑动返回,默认值为 true

Version 1.0.0 *(2016-12-27)*
----------------------------
Expand Down
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
:running:BGASwipeBackLayout-Android:running:
============

强烈建议与 **[StatusBarUtil](https://github.com/laobie/StatusBarUtil)** 结合着一起使用

## 功能介绍

- [x] 通过修改 support-v4 包中 SlidingPaneLayout 的源码来实现滑动返回布局
- [x] 动态设置滑动返回是否可用
- [x] 动态设置是否仅仅跟踪左侧边缘的滑动返回
- [x] 动态设置是否是微信滑动返回样式「如果需要启用微信滑动返回样式,必须在 Application 的 onCreate 方法中执行 BGASwipeBackManager.getInstance().init(this)」
- [x] 动态设置是否显示滑动返回的阴影效果

## 效果图与示例 apk

![BGASwipeBackLayoutDemo](https://cloud.githubusercontent.com/assets/8949716/21512903/fac699f8-ccec-11e6-8437-1bfe8b9bd9d3.gif)
| 普通滑动返回样式 | 微信滑动返回样式 |
| ------------ | ------------- |
| ![BGASwipeBackLayoutDemo](https://cloud.githubusercontent.com/assets/8949716/21512903/fac699f8-ccec-11e6-8437-1bfe8b9bd9d3.gif) | ![BGASwipeBackLayoutDemo-WeChat](https://cloud.githubusercontent.com/assets/8949716/21536263/7aa0fe88-cdbb-11e6-801d-4b370d6c454c.gif) |

[点击下载 BGASwipeBackLayoutDemo.apk](http://fir.im/BGASwipeBackLayout) 或扫描下面的二维码安装

Expand Down Expand Up @@ -69,19 +74,23 @@ public class BaseActivity extends AppCompatActivity implements BGASwipeBackLayou
private void initSwipeBackFinish() {
if (isSupportSwipeBack()) {
mSwipeBackLayout = new BGASwipeBackLayout(this);
// 将该滑动返回控件添加到 Activity 上
mSwipeBackLayout.attachToActivity(this);
// 设置滑动监听器
mSwipeBackLayout.setPanelSlideListener(this);

// 下面三项可以不配置,这里只是为了讲述接口用法
// 下面六项可以不配置,这里只是为了讲述接口用法

// 设置滑动返回是否可用。默认值为 true
mSwipeBackLayout.setSwipeBackEnable(true);
// 设置是否仅仅跟踪左侧边缘的滑动返回。默认值为 true
mSwipeBackLayout.setIsOnlyTrackingLeftEdge(true);
// 设置是否是微信滑动返回样式。默认值为 true「如果需要启用微信滑动返回样式,必须在 Application 的 onCreate 方法中执行 BGASwipeBackManager.getInstance().init(this)」
mSwipeBackLayout.setIsWeChatStyle(true);
// 设置阴影资源 id。默认值为 R.drawable.bga_swipebacklayout_shadow
mSwipeBackLayout.setShadowResId(R.drawable.bga_swipebacklayout_shadow);
// 设置是否显示滑动返回的阴影效果。默认值为 true
mSwipeBackLayout.setIsNeedShowShadow(true);
// 设置阴影区域的透明度是否根据滑动的距离渐变。默认值为 true
mSwipeBackLayout.setIsShadowAlphaGradient(true);
}
}

Expand All @@ -105,7 +114,6 @@ public class BaseActivity extends AppCompatActivity implements BGASwipeBackLayou
}
}


@Override
public void onPanelClosed(View view) {
}
Expand All @@ -121,6 +129,12 @@ public class BaseActivity extends AppCompatActivity implements BGASwipeBackLayou
}
```

### 4.如果需要启用微信滑动返回样式,必须在 Application 的 onCreate 方法中配置

```java
BGASwipeBackManager.getInstance().init(this)
```

## demo 中用到的第三方库

* [StatusBarUtil](https://github.com/laobie/StatusBarUtil) A util for setting status bar style on Android App
Expand Down Expand Up @@ -149,6 +163,7 @@ public class BaseActivity extends AppCompatActivity implements BGASwipeBackLayou

## License

Copyright (C) 2012 The Android Open Source Project
Copyright 2015 bingoogolapple

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 2 additions & 2 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ android {

dependencies {
compile 'com.android.support:design:25.1.0'
// compile 'cn.bingoogolapple:bga-swipebacklayout:1.0.1@aar'
compile 'cn.bingoogolapple:bga-swipebacklayout:1.0.2@aar'
// 上面的依赖是必须的

compile project(':library')
// compile project(':library')

// 下面的依赖不是必须的,只是为了方便演示 demo
compile 'cn.bingoogolapple:bga-adapter:1.1.5@aar'
Expand Down
1 change: 1 addition & 0 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
19 changes: 19 additions & 0 deletions demo/src/main/java/cn/bingoogolapple/swipebacklayout/demo/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cn.bingoogolapple.swipebacklayout.demo;

import android.app.Application;

import cn.bingoogolapple.swipebacklayout.BGASwipeBackManager;

/**
* 作者:王浩 邮件:[email protected]
* 创建时间:16/12/28 下午11:55
* 描述:
*/
public class App extends Application {

@Override
public void onCreate() {
super.onCreate();
BGASwipeBackManager.getInstance().init(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.IdRes;
import android.support.annotation.IntRange;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
Expand Down Expand Up @@ -45,14 +47,21 @@ private void initSwipeBackFinish() {
mSwipeBackLayout.attachToActivity(this);
mSwipeBackLayout.setPanelSlideListener(this);

// 下面三项可以不配置,这里只是为了讲述接口用法
// 下面四项项可以不配置,这里只是为了讲述接口用法。
// 如果需要启用微信滑动返回样式,必须在 Application 的 onCreate 方法中执行 BGASwipeBackManager.getInstance().init(this)

// 设置滑动返回是否可用。默认值为 true
mSwipeBackLayout.setSwipeBackEnable(true);
// 设置是否仅仅跟踪左侧边缘的滑动返回。默认值为 true
mSwipeBackLayout.setIsOnlyTrackingLeftEdge(true);
// 设置是否是微信滑动返回样式。默认值为 true
mSwipeBackLayout.setIsWeChatStyle(true);
// 设置阴影资源 id。默认值为 R.drawable.bga_swipebacklayout_shadow
mSwipeBackLayout.setShadowResId(R.drawable.bga_swipebacklayout_shadow);
// 设置是否显示滑动返回的阴影效果。默认值为 true
mSwipeBackLayout.setIsNeedShowShadow(true);
// 设置阴影区域的透明度是否根据滑动的距离渐变。默认值为 true
mSwipeBackLayout.setIsShadowAlphaGradient(true);
}
}

Expand Down Expand Up @@ -203,8 +212,18 @@ public void executeSwipeBackAnim() {
*
* @param color
*/
protected void setStatusBarColor(int color) {
StatusBarUtil.setColorForSwipeBack(this, color);
protected void setStatusBarColor(@ColorInt int color) {
setStatusBarColor(color, StatusBarUtil.DEFAULT_STATUS_BAR_ALPHA);
}

/**
* 设置状态栏颜色
*
* @param color
* @param statusBarAlpha 透明度
*/
public void setStatusBarColor(@ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
StatusBarUtil.setColorForSwipeBack(this, color, statusBarAlpha);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected boolean isSupportSwipeBack() {
@Override
protected void initView(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
mToolbar = getViewById(R.id.toolbar);
}

@Override
Expand All @@ -33,6 +34,7 @@ protected void setListener() {

@Override
protected void processLogic(Bundle savedInstanceState) {
setSupportActionBar(mToolbar);
}

public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isOnlyTrackingLe
}
});

// 测试动态设置是否是微信滑动返回样式
((SwitchCompat) getViewById(R.id.weChatStyleSwitch)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isWeChatStyle) {
/**
* 设置是否是微信滑动返回样式。如果需要启用微信滑动返回样式,必须在 Application 的 onCreate 方法中执行 BGASwipeBackManager.getInstance().init(this)
*/
mSwipeBackLayout.setIsWeChatStyle(isWeChatStyle);
}
});

// 测试动态设置是否显示滑动返回的阴影效果
((SwitchCompat) getViewById(R.id.needShowShadowSwitch)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
Expand All @@ -110,6 +121,17 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isNeedShowShadow
mSwipeBackLayout.setIsNeedShowShadow(isNeedShowShadow);
}
});

// 测试动态设置阴影区域的透明度是否根据滑动的距离渐变
((SwitchCompat) getViewById(R.id.shadowAlphaGradientSwitch)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isShadowAlphaGradient) {
/**
* 设置阴影区域的透明度是否根据滑动的距离渐变
*/
mSwipeBackLayout.setIsShadowAlphaGradient(isShadowAlphaGradient);
}
});
}

public void onClickTranslucentFab(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public void onProgressChanged(WebView view, int newProgress) {
}
}
});
findViewById(R.id.retweet).setOnClickListener(this);
findViewById(R.id.comment).setOnClickListener(this);
findViewById(R.id.transparent).setOnClickListener(this);
findViewById(R.id.not_transparent).setOnClickListener(this);
findViewById(R.id.praise).setOnClickListener(this);
}

Expand Down Expand Up @@ -88,12 +88,12 @@ private void initWebView() {

@Override
public void onClick(View v) {
if (v.getId() == R.id.retweet) {
Toast.makeText(this, "点击了转发", Toast.LENGTH_SHORT).show();
} else if (v.getId() == R.id.comment) {
Toast.makeText(this, "点击了评论", Toast.LENGTH_SHORT).show();
if (v.getId() == R.id.transparent) {
setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
} else if (v.getId() == R.id.not_transparent) {
setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark), 0);
} else if (v.getId() == R.id.praise) {
Toast.makeText(this, "点击了赞", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "谢谢你的赞", Toast.LENGTH_SHORT).show();
}
}

Expand Down
5 changes: 3 additions & 2 deletions demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/MatchMatch.Vertical"
android:background="@android:color/white"
android:gravity="center">
android:background="@android:color/white">

<include layout="@layout/inc_toolbar"/>

<Button
android:id="@+id/btn_main_test"
Expand Down
61 changes: 46 additions & 15 deletions demo/src/main/res/layout/activity_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
style="@style/MatchMatch.Vertical"
android:background="@android:color/white">

Expand Down Expand Up @@ -35,9 +34,7 @@
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="250dp"
android:flipInterval="30"
android:persistentDrawingCache="animation"/>
android:layout_height="250dp"/>

<android.support.v7.widget.SwitchCompat
android:id="@+id/onlyTrackingLeftEdgeSwitch"
Expand All @@ -46,22 +43,19 @@
android:padding="@dimen/size_level3"
android:text="仅仅跟踪左侧边缘的滑动返回"/>

<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="@mipmap/bga_avatar"/>

<android.support.v7.widget.SwitchCompat
android:id="@+id/swipeBackEnableSwitch"
style="@style/WrapWrap"
android:checked="true"
android:padding="@dimen/size_level3"
android:text="滑动返回可用"/>

<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="@mipmap/bga_avatar"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/weChatStyleSwitch"
style="@style/WrapWrap"
android:checked="true"
android:padding="@dimen/size_level3"
android:text="微信滑动返回样式"/>

<android.support.v7.widget.SwitchCompat
android:id="@+id/needShowShadowSwitch"
Expand All @@ -70,9 +64,46 @@
android:padding="@dimen/size_level3"
android:text="显示滑动返回的阴影效果"/>

<android.support.v7.widget.SwitchCompat
android:id="@+id/shadowAlphaGradientSwitch"
style="@style/WrapWrap"
android:checked="true"
android:padding="@dimen/size_level3"
android:text="阴影区域的透明度根据滑动的距离渐变"/>

<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/bga_avatar"/>

<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/bga_avatar"/>

<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/bga_avatar"/>

<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/bga_avatar"/>

<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/bga_avatar"/>

<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/bga_avatar"/>

<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/bga_avatar"/>
</LinearLayout>
</ScrollView>
Expand Down
Loading