An android library that helps you to finish activity with slide gesture, never stuck with a bunch of activities openning.
Please download the latest release apk via Download APK.
You can download the dependency from JitPack using Gradle for AndroidX.
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation "com.github.phantomVK:SlideBack:latest.release"
}
Add <item name="android:windowIsTranslucent">true</item>
to your ActivityTheme in styles.xml, such as
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
....
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>
Extends the class named SlideActivity using your Activity, set the edge which is going to track after setContentView(View).
public class MainActivity extends SlideActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!slideManager.isSlideDisable()) {
overridePendingTransition(R.anim.slide_in_right, 0);
}
}
// Optional, set tracking edge after content changed.
// Default edge is ViewDragHelper.EDGE_LEFT.
@Override
public void onContentChanged() {
super.onContentChanged();
slideManager.getSlideLayout().setTrackingEdge(ViewDragHelper.EDGE_RIGHT);
}
@Override
public void finish() {
super.finish();
if (!slideManager.isSlideDisable()) {
overridePendingTransition(0, R.anim.slide_out_right);
}
}
// Optional, provide a custom SlideManager instance to SlideActivity.
@NonNull
@Override
protected SlideManager slideManagerProvider() {
return new SlideManager(this, new CustomAdapter(this));
}
}
Totally disable the slide function, nothing inside SlideManager will be initialized, re-initialize is illegal either.
public class MainActivity extends SlideActivity implements SlideManager.Conductor{
@Override
public boolean isSlideBackDisabled() {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT;
}
}
To temporarily disable the slide action, or enable again whenever you want, see the method below.
slideManager comes from SlideActivity the super class you extended. What slideManager.getSlideLayout() returns is null if slide action has been totally disabled, see method mentioned above named isSlideBackDisabled() for more details.
public class MainActivity extends SlideActivity {
@Override
protected void onResume() {
super.onResume();
slideManager.getSlideLayout().setEnable(false);
}
}
- Minimum Android SDK: SlideBack requires a minimum API level of 14.
- Compile Android SDK: SlideBack requires you to compile against API 28 or later.
- Both AndroidX and Android Support are supported by using different dependencies.
Copyright 2019 WenKang Tan(phantomVK)
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.