{"id":13644997,"url":"https://github.com/sockeqwe/SwipeBack","last_synced_at":"2025-04-21T11:32:25.659Z","repository":{"id":12929365,"uuid":"15607062","full_name":"sockeqwe/SwipeBack","owner":"sockeqwe","description":"SwipeBack for Android Activities to do pretty the same as the android \"back-button\" will do, but in a really intuitive way by using a swipe gesture","archived":false,"fork":false,"pushed_at":"2022-09-08T20:34:58.000Z","size":256,"stargazers_count":694,"open_issues_count":0,"forks_count":114,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-04-12T18:53:55.404Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sockeqwe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-03T10:30:55.000Z","updated_at":"2025-03-13T07:31:08.000Z","dependencies_parsed_at":"2022-07-09T23:46:27.792Z","dependency_job_id":null,"html_url":"https://github.com/sockeqwe/SwipeBack","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockeqwe%2FSwipeBack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockeqwe%2FSwipeBack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockeqwe%2FSwipeBack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockeqwe%2FSwipeBack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sockeqwe","download_url":"https://codeload.github.com/sockeqwe/SwipeBack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250048006,"owners_count":21366158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:02:23.425Z","updated_at":"2025-04-21T11:32:25.621Z","avatar_url":"https://github.com/sockeqwe.png","language":"Java","funding_links":[],"categories":["滑动返回","Java","Libs"],"sub_categories":["\u003cA NAME=\"Widget\"\u003e\u003c/A\u003eWidget"],"readme":"SwipeBack\n=========\n\nSwipeBack is for Android Activities to do pretty the same as the android \"back-button\" will do, but in a really intuitive way by using a swipe gesture\n\nNot Actively Maintained\n=========\nWarning: this project is not actively maintained. It works, but don't expect any future improvements or major bug fixes but I'm willing to merge any Pull Request.\n\nDemo\n====\n\n[kicker app](https://play.google.com/store/apps/details?id=com.netbiscuits.kicker)\n\n[![Kicker app](http://img.youtube.com/vi/-QgECTWOoa0/0.jpg)](http://www.youtube.com/watch?v=-QgECTWOoa0)\n\n[![See demo video](http://img.youtube.com/vi/T6mbg_wqlkc/0.jpg)](http://www.youtube.com/watch?v=T6mbg_wqlkc)\n\n\nDependency\n========\nSwipeBack is available on maven central\n\n```groovy\ncompile 'com.hannesdorfmann:swipeback:1.0.4'\n```\n\n\nHow to use it\n=============\nIt's not supported yet to build it from xml.\nYou simply have to set it up in you Activities onCreate() method.\nInstead of `Activity.setContentView()` call `SwipeBack.setContentView()`.\n\n```java\npublic class SwipeBackActivity extends FragmentActivity{\n\n\t@Override\n\tpublic void onCreate(Bundle saved){\n\t\tsuper.onCreate(saved);\n\n\t\t// Init the swipe back\n\t\tSwipeBack.attach(this, Position.LEFT)\n\t\t    .setContentView(R.layout.activity_simple)\n\t\t    .setSwipeBackView(R.layout.swipeback_default);\n\n\t}\n\n\n\t@Override\n\tpublic void onBackPressed(){\n\t\tsuper.onBackPressed();\n\t\toverridePendingTransition(R.anim.swipeback_stack_to_front,\n\t\t\t\tR.anim.swipeback_stack_right_out);\n\t}\n}\n```\n\nThe code above will use the default setup. `R.layout.swipeback_default`, the default swipe back layout is already provided by this library as well as `DefaultSwipeBackTransformer`, `R.anim.swipeback_stack_to_front`, `R.anim.swipeback_stack_to_back`, `R.anim.swipeback_stack_right_in` and `R.anim.swipeback_stack_right_out`.\n\n\nCustomization\n=============\n\nThe most important thing is the `SwipeBackTransformer`. This interface provides an API that will be called from the `SwipeBack` class. Here is where you implement frame by frame animation while the swipe back view will become open (by users swipe gesture). Additionally you can customize the SwipeBack position, the drag mode (drag content or drag window) and if it should be drawn as overlay or not (Type.BEHIND or Type.OVERLAY).\n\n```java\n    /**\n\t * Attaches the SwipeBack to the Activity.\n\t *\n\t * @param activity\n\t *            The activity the swipe back will be attached to.\n\t * @param type\n\t *            The {@link SwipeBack.Type} of the drawer.\n\t * @param position\n\t *            Where to position the swipe back.\n\t * @param dragMode\n\t *            The drag mode of the drawer. Can be either\n\t *            {@link SwipeBack#DRAG_CONTENT} or\n\t *            {@link SwipeBack#DRAG_WINDOW}.\n\t * @return The created SwipeBack instance.\n\t */\n\tpublic static SwipeBack attach(Activity activity, Type type, Position position, int dragMode, SwipeBackTransformer transformer)\n\n```\n\nYou can also draw a divider between the normal content view and the swipe back view and a overlay that will fade out while opening the swipe back view.\n\n```java\nSwipeBack.attach(this, Position.LEFT)\n\t\t.setDrawOverlay(true)\n\t\t.setDivider(drawable)\n\t\t.setDividerEnabled(true) // Must be called to enable, setDivider() is not enough\n\t\t.setSwipeBackTransformer(new SlideSwipeBackTransformer())\n\t\t.setContentView(R.layout.activity_simple)\n\t\t.setSwipeBackView(R.layout.swipeback_default);\n\n```\n\nViewPager\n=========\nTo distinguish a ViewPager swipe gesture from a SwipeBack swipe gesture you have to setup a `OnInterceptMoveEventListener`:\n\n```java\npublic class ViewPagerActivity extends FragmentActivity {\n\n\tprivate ViewPager mViewPager;\n\tprivate int mPagerPosition;\n\tprivate int mPagerOffsetPixels;\n\n\t@Override\n\tpublic void onCreate(Bundle savedInstanceState) {\n\t\tsuper.onCreate(savedInstanceState);\n\t\tSwipeBack.attach(this, Position.LEFT)\n\t\t.setContentView(R.layout.activity_view_pager)\n\t\t.setSwipeBackView(R.layout.swipeback_default)\n\t\t.setDividerAsSolidColor(Color.WHITE)\n\t\t.setDividerSize(2)\n\t\t.setOnInterceptMoveEventListener(\n\t\t\t\tnew OnInterceptMoveEventListener() {\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic boolean isViewDraggable(View v, int dx,\n\t\t\t\t\t\t\tint x, int y) {\n\t\t\t\t\t\tif (v == mViewPager) {\n\t\t\t\t\t\t\treturn !(mPagerPosition == 0 \u0026\u0026 mPagerOffsetPixels == 0)\n\t\t\t\t\t\t\t\t\t|| dx \u003c 0;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t});\n\n\n\t\tmViewPager = (ViewPager) findViewById(R.id.viewPager);\n\t\tmViewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager()));\n\n\t\tmViewPager.setOnPageChangeListener(new SimpleOnPageChangeListener(){\n\t\t\t@Override\n\t\t\tpublic void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {\n\t\t\t\tmPagerPosition = position;\n\t\t\t\tmPagerOffsetPixels = positionOffsetPixels;\n\t\t\t}\n\n\t\t});\n\t}\n\n\n}\n```\n\n\nWhy?\n====\nThe Samsung Galaxy Nexus was one of the first device without hardware buttons for \"back\", \"home\" and \"app switching (multitasking)\" but used the androids navigation bar on screen (introduced in Android 4.0). The navigation bar was at least in my opinion a big step forward, especially on screen rotation from landscape to portrait and vice versa. But I asked myself, do we really need a navigation bar? I mean the navigation bar takes ca. 10 % of the whole screen. Even at the home screen the \"back\" and \"home\" button is useless (because they do nothing). So I thought to myself: Why do we not use swipe gestures instead of a navigation bar? But maybe this idea is to futuristic and not suitable for all kind of android user. A few years later apple introduced the swipe back gesture in iOS 7. Why doesn't Android Apps use swipe gesture as alternative to the back button. Pinterest and Tumblr do so, but at least they use a single Activity and a ViewPager. The problem with this approach is:\n\n 1. You will lost a little bit the ability to jump to any screen by using intents. Take Pinterest as an example: If you get a push notification from Pinterest and you click on it you will see a loading dialog on screen. Internal the navigation stack is generated by adding Fragments to the ViewPager.\n\n 2. ActionBar: The ActionBar is as default not part of a fragment, but it's part of the activity. So you can not (by using a ViewPager) use the default ActionBar to swipe back to the previous Fragment, because the ActionBar will remain sticky. So you have to implement you own ActionBar and attach that to the fragments view.\n\nMy approach can be used for activities. It does pretty the same as the android menu drawers do. It adds an aditional layout and slides the content or the window to the side.\n\n\nThanks\n======\n * Simon Vig Therkildsen: The most code of handling swipe gestures has been taken from his [android-menudrawer](https://github.com/SimonVT/android-menudrawer) library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsockeqwe%2FSwipeBack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsockeqwe%2FSwipeBack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsockeqwe%2FSwipeBack/lists"}