Code Monkey home page Code Monkey logo

swipeback's Introduction

SwipeBack Build Status

SwipeBack is a android library that can finish a activity by using gesture.

You can set the swipe direction,such as left,top,right and bottom.

Screenshots

image

image

Sample Download

Sample Download

image

Usage

Gradle

dependencies {
   	compile 'com.github.liuguangqiang.swipeback:library:1.0.2@aar'
}

Maven

<dependency>
  	<groupId>com.github.liuguangqiang.swipeback</groupId>
  	<artifactId>library</artifactId>
  	<version>1.0.2</version>
  	<type>aar</type>
</dependency>

SwipeBackActivity

SwipeBackActivity is a base activity for using this library more easier.This Activity will help us to show a shadow.

image

public class CommonActivity extends SwipeBackActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_common);
        setDragEdge(SwipeBackLayout.DragEdge.LEFT);
    }

}

Layout and activity theme.

SwipeBackLayout must contains only one direct child.

<com.liuguangqiang.swipeback.SwipeBackLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipeBackLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
	
	<!-- SwipeBackLayout must contains only one direct child -->

</com.liuguangqiang.swipeback.SwipeBackLayout>
 <style name="Theme.Swipe.Back" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
 </style>

Swipe Direction

You can set DragEdge to change the swipe direction.

 public enum DragEdge {
      	LEFT,
      	
        TOP,
        
        RIGHT,
        
        BOTTOM
    }

Support Views

SwipeBackLayout must contains only one direct child.

Such as:

  • LinearLayout,
  • RelativeLayout,
  • ListView,
  • ViewPager
  • WebView

License

Copyright 2015 Eric Liu

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.

swipeback's People

Contributors

john1024 avatar juliooa avatar liuguangqiang avatar pavel163 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swipeback's Issues

Add method setAnchorView

I've found a problem: If the developer add 2 multi views and hide or show this view, or I need set the archor to another view, the sliding of View not work good.

chkDragable(), 有问题

private void chkDragable() {
setOnTouchListener(new View.OnTouchListener() {
@OverRide
public boolean onTouch(View view, MotionEvent motionEvent) {

             if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                 lastY = motionEvent.getRawY();
                 lastX = motionEvent.getRawX();
             } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
                 newY = motionEvent.getRawY();

---------------------"lastX = motionEvent.getRawX();"------------------------

                 offsetY = Math.abs(newY - lastY);
                 lastY = newY;

                 offsetX = Math.abs(newX - lastX);
                 lastX = newX;

                 switch (dragEdge) {
                     case TOP:
                     case BOTTOM:
                         setEnablePullToBack(offsetY > offsetX);
                     case LEFT:
                     case RIGHT:
                         setEnablePullToBack(offsetY < offsetX);
                         break;
                 }
             }

             return false;
         }
     });
  }		      

}

标注的地方, 应该是
newX = motionEvent.getRawX();
但是修改之后, 拖拽就失效了

向右划与m.astuetz.PagerSlidingTabStrip 控件相冲突

PagerSlidingTabStrip 可以左右滑动
但如果设置了setDragEdge(SwipeBackLayout.DragEdge.LEFT);
导致PagerSlidingTabStrip向右划就失效了

可否根据用户第一次按下的位置来区分 到底是PagerSlidingTabStrip的切换 or SwipeBackAcitivy的退出?

Swipe only on header

I only want to trigger the Swipeback on the header (specific View) of the Activity. How can I do this?

Does not work with appcompat-v7:26.0.0'

I am getting errors building with the latest AppCompat library.

Error:(40, 8) error: cannot access ActionBarActivity
class file for android.support.v7.app.ActionBarActivity not found

I am importing the library properly
compile 'com.github.liuguangqiang.swipeback:library:1.0.2@aar'

AndroidManifest merge Android Studio error

I tried to add my own icon to my app in Android Studio and I encountered a Manifest merger fail. I fount an identical question here but his answer is not working for me. I tried adding tools:replace="android:icon" and tools:replace="android:icon,android:theme" (on 2 separate occasions of course) but no change. Can you remove the launcher icon from the library's manifest ?

Proguard

What are the necessary proguard rules for this library?

Running into the following when building with minifyEnabled true.

Warning:com.liuguangqiang.swipeback.SwipeBackActivity: can't find superclass or interface android.support.v7.app.ActionBarActivity
Warning:com.liuguangqiang.swipeback.SwipeBackActivity: can't find referenced class android.support.v7.app.ActionBarActivity
Warning:com.liuguangqiang.swipeback.SwipeBackActivity: can't find referenced method 'android.content.res.Resources getResources()' in program class com.liuguangqiang.swipeback.SwipeBackActivity
Warning:com.liuguangqiang.swipeback.SwipeBackActivity: can't find referenced class android.support.v7.app.ActionBarActivity

Getting more done in GitHub with ZenHub

Hola! @pmaingi has created a ZenHub account for the liuguangqiang organization. ZenHub is the leading team collaboration and project management solution built for GitHub.


How do I use ZenHub?

To get set up with ZenHub, all you have to do is download the browser extension and log in with your GitHub account. Once you do, you’ll get access to ZenHub’s complete feature-set immediately.

What can ZenHub do?

ZenHub adds a series of enhancements directly inside the GitHub UI:

  • Real-time, customizable task boards for GitHub issues;
  • Burndown charts, estimates, and velocity tracking based on GitHub Milestones;
  • Personal to-do lists and task prioritization;
  • “+1” button for GitHub issues and comments;
  • Drag-and-drop file sharing;
  • Time-saving shortcuts like a quick repo switcher.

Add ZenHub to GitHub

Still curious? See more ZenHub features or read user reviews. This issue was written by your friendly ZenHub bot, posted by request from @pmaingi.

ZenHub Board

关于引用该项目遇到的一些问题,以及解决办法

1.设置左滑之后,下滑禁止不掉
这个问题是因为你的Activity即继承了SwipeBackActivity,Activity的布局中又加上了SwipeBackLayout。解决办法是要么继承SwipeBackActivity,然后在onCreate直接setDragEdge()设置;要么再布局文件中加上SwipeBackLayout,然后在Activty里调用SwipeBackLayout的setDragEdge()方法;两者只能选一个。
2.Activity中有webview或者ListView、Recyclerview等可以上下拖动的控件时,侧滑很容易被触发。
这个问题是滑动冲突照成的,位于底部的SwipeBackLayout拦截了子View的触摸事件。所以我们要做的是继承SwipeBackLayout重写它的onInterceptTouchEvent()方法,当手指在Y轴的移动速度大于X轴的移动速度时不拦截这个触摸事件,代码如下:
public class MySwipeBackLayout extends SwipeBackLayout{
private float startY;
private float startX;
// 记录viewPager是否拖拽的标记
private boolean mIsVpDragger;
private int mTouchSlop;
public MySwipeBackLayout(Context context) {
super(context);
}
public MySwipeBackLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
setDragEdge(DragEdge.LEFT);
}
@OverRide
public boolean onInterceptTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// 记录手指按下的位置
startY = ev.getY();
startX = ev.getX();
// 初始化标记
mIsVpDragger = false;
break;
case MotionEvent.ACTION_MOVE:
// 如果viewpager正在拖拽中,那么不拦截它的事件,直接return false;
if(mIsVpDragger) {
return false;
}
// 获取当前手指位置
float endY = ev.getY();
float endX = ev.getX();
float distanceX = Math.abs(endX - startX);
float distanceY = Math.abs(endY - startY);
// 如果X轴位移大于Y轴位移,那么将事件交给viewPager处理。
/if(distanceX > mTouchSlop && distanceX > distanceY) {
mIsVpDragger = true;
return false;
}
/
if(distanceY > mTouchSlop && distanceY > distanceX) {
mIsVpDragger = true;
return false;
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
// 初始化标记
mIsVpDragger = false;
break;
}
// 如果是Y轴位移大于X轴,事件交给SwipeBackLayout处理。
return super.onInterceptTouchEvent(ev);
}
}
3.布局中有个viewpager或者横向的recyclerview时,向右滑触发SwipeBackLayout侧滑。
这也是滑动冲突照成的,我们要做的是重写viewpager或recyclerview的dispatchTouchEvent()方法。
代码如下:
public class MyRecyclerView extends RecyclerView{
public MyRecyclerView(Context context) {
super(context);
}
public MyRecyclerView(Context context, @nullable AttributeSet attrs) {
super(context, attrs);
}
public MyRecyclerView(Context context, @nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@OverRide
public boolean dispatchTouchEvent(MotionEvent ev) {
if (getParent() != null){
getParent().requestDisallowInterceptTouchEvent(true);
}
return super.dispatchTouchEvent(ev);
}
}

关于滑动冲突的问题

测试发现,如果代码中存在listview等可滚动控件,且没有放到布局代码的第一层(如下即为放到第一层)

tim 20180508173859

会存在滑动冲突问题,然而实际应用中,布局肯定十分复杂,很难直接放于第一层
研究源码发现代码中有这样一个方法 findScrollView,是用来寻找布局中可滚动的控件,但仅找了第一层,所以会出现以上问题
尝试将该方法改为递归后解决问题:即从整个布局代码中寻找滚动控件,但如果布局中存在多个滚动控件的话,可能会出问题
代码如下

private View findScrollView(ViewGroup viewGroup) {
View child = viewGroup;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
child = viewGroup.getChildAt(i);
if (child instanceof AbsListView || child instanceof ScrollView || child instanceof ViewPager || child instanceof WebView) {
return child;
} else if (child instanceof ViewGroup) {
child = findScrollView((ViewGroup) child);
if (child instanceof AbsListView || child instanceof ScrollView || child instanceof ViewPager || child instanceof WebView) {
return child;
} else {
continue;
}
} else {
continue;
}
}
return child;

}

tim 20180508174030

Add a multipler to slide

It will look good if we add a multipler to slider. If the user need slide to 50% of screen, the scroll need to be on bottom screen.
Look like (ideia):

View.setY(fingerPosition.getY/multipler);

Need more help? Contact me: [email protected] or on Hangouts: [email protected]

Scroll view inside the activity

Hi, Thank you for the awesome library. I am struck with a problem. I've an activity layout on which I've a banner and than details which are scrollable. The banner is fixed here while details can scroll. Now what I want is that when user touches the banner and swipes down than the activity shoud close otherwise if the details section is touched, it should scroll.

Everything works perfectly fine, but the only problem is when I scroll exactly at the bottom, take my finger off of the screen and now touch it again to scroll back up. It starts dragging the activity down instead of scrolling ( note here I am touching the details section, not the banner ), but if the scroll is not at the bottom and I repeat the same procedure, the scrolling works fine.

This has happened to me with another library where I happened to debug the files. The onTouchEvent of the library was called only when I repeat the above procedure and once it is called than the scrollview stopped working.

I hope I was able to explain it properly. Let me know if you've questions. I have been stuck on this since very long. Any help will be appreciated.

viewpager中setDragEdge(SwipeBackLayout.DragEdge.TOP|BOTTOM),左右滑动不灵敏

public class ViewPagerActivity extends SwipeBackActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_viewpager);
        initViews();
        setDragEdge(SwipeBackLayout.DragEdge.TOP);
    }

    private void initViews() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle(R.string.title_activity_viewpager);
        toolbar.setTitleTextColor(Color.WHITE);
        setSupportActionBar(toolbar);

        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager_demo);
        TestAdapter adapter = new TestAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
    }

}

AppCompat does not support Theme.Swipe.Back features

When creating an activity using the SwipeBack theme, the aplication crashes with the following error:

java.lang.IllegalArgumentException: AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: false, windowNoTitle: false

Presumably, as a result, swiping back does not show the activity behind it but instead fades it in after the animation completes.

Swipe down interrupts View pager

Current implementation Interrupts the view pager's slidder functionality, I want the swipe to enable only for some specific angles(85 to 95 & 265 to 275).

SwipeBack with dialogfragment

hi
thank you for this library

how can i use it with dialog fragment
i put SwipeBackLayout as parent and put other things in it
when i call dialog , after swiping app crashes with android.view.ContextThemeWrapper cannot be cast to android.app.Activity

can you please tell me how to use it with dialog fragment?

thank you very much

Animation trouble

Hi. Your library is good. But one problem i have found. Animation of closing common activity in your screen is correct, but in my phone i can't see the activity which is under of this.
Here is the screen
https://yadi.sk/i/WeM-j_Pw3F87Qt

Getting white screen when i swipe left to right for some time how to remove that.

I am getting this white screen attached below for some time like around 3 seconds when I swipe left to right so can you help me how to remove that, i want when i swipe left to right i want to display my previous activity directly instead of showing this white screen.

Also, can you help me how to reduce the time between this two activity transactions?

123

Is it possible to prevent activity to finish while scroll up in recyclerview?

Hello
I am using swipe back activity in one of my project activity. My activity layout contains recyclerview and other components as well. So the problem is when I scroll up my recyclerview items then activity get finished.
So is there any way to prevent activity to finish while recyclerview is visible ?

Background screen blank when swipe

When i was swiping left the activity, the background was blank until complete close of swipe activity.But i want to show background activity on swipe.Any help ??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.