Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Cleaned up changes that resolve #45 & resolve #42
Browse files Browse the repository at this point in the history
Added documentation
Updated README for proper formatting of new features
  • Loading branch information
r0adkll committed Dec 6, 2017
1 parent 64324a3 commit 4637b7c
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 259 deletions.
102 changes: 50 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
Slidr
================
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.r0adkll/slidableactivity/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.r0adkll/slidableactivity) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Slidr-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1364)
[![Stories in Ready](https://badge.waffle.io/r0adkll/Slidr.png?label=ready&title=Ready)](https://waffle.io/r0adkll/Slidr)
[![Build Status](https://travis-ci.org/r0adkll/Slidr.svg?branch=master)](https://travis-ci.org/r0adkll/Slidr)

Easily add slide-to-dismiss functionality to your Activity by calling `Slidr.attach(this)` in your `onCreate(..)` method.

![Slidr Example](images/slidr_gif.gif "Gif Example")

## Usage

An example usage:

## Note 1 on this fork:
https://github.com/r0adkll/Slidr/issues/45 solved here. (When using Horizontal)
```java
public class ExampleActivity extends <Activity|FragmentActivity|ActionBarActivity> {

## Note 2 on this fork:
added the same behavior available to Fragments! Here is a quick how-to explanation:
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
int primary = getResources().getColor(R.color.primaryDark);
int secondary = getResources().getColor(R.color.secondaryDark);
Slidr.attach(this, primary, secondary);
}

The activity must extend AppCompatActivity.
}
```

or

```java
public class ExampleActivity extends <Activity|FragmentActivity|ActionBarActivity> {

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
Slidr.attach(this);
}

}
```

## Fragments
The activity must extend FragmentActivity.
Set the background to the main container of the activity in the xml `background="@android:color/transparent"`.
Add the following code to the Fragment:

Expand All @@ -16,6 +52,7 @@ Add the following code to the Fragment:
// is resuming after creation (Slidr to be attached) or
// simply from the background (app was paused before).
SlidrInterface slidrInterface;

@Override
public void onResume() {
super.onResume();
Expand All @@ -33,7 +70,8 @@ In the xml of the fragment's view, the root view must be a FrameLayout with the
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent" >
android:background="@android:color/transparent">

<android.support.design.widget.CoordinatorLayout
android:id="@+id/content_container"
android:layout_width="match_parent"
Expand All @@ -44,56 +82,16 @@ In the xml of the fragment's view, the root view must be a FrameLayout with the
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
```
Remember: you have to add new Fragments with:
```java
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, YourFragmentClass.newInstance()).commit();
```
where fragment_container is the id of a FrameLayout inside the activity's xml.
Remember: you have to add new Fragments with:




[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.r0adkll/slidableactivity/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.r0adkll/slidableactivity) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Slidr-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1364)
[![Stories in Ready](https://badge.waffle.io/r0adkll/Slidr.png?label=ready&title=Ready)](https://waffle.io/r0adkll/Slidr)
[![Build Status](https://travis-ci.org/r0adkll/Slidr.svg?branch=master)](https://travis-ci.org/r0adkll/Slidr)

Easily add slide-to-dismiss functionality to your Activity by calling `Slidr.attach(this)` in your `onCreate(..)` method.

![Slidr Example](images/slidr_gif.gif "Gif Example")

## Usage

An example usage:

```java
public class ExampleActivity extends <Activity|FragmentActivity|ActionBarActivity> {

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
int primary = getResources().getColor(R.color.primaryDark);
int secondary = getResources().getColor(R.color.secondaryDark);
Slidr.attach(this, primary, secondary);
}

}
```java
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, YourFragmentClass.newInstance())
.commit();
```

or

```java
public class ExampleActivity extends <Activity|FragmentActivity|ActionBarActivity> {

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
Slidr.attach(this);
}
where fragment_container is the id of a FrameLayout inside the activity's xml.

}
```

## Configuring

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext {
compileSdk = 26
targetSdk = 26
minSdk = 14
buildTools = '26.0.0'
buildTools = '27.0.1'
supportLibrary = '25.4.0'
ftKit = '0.5.1'

Expand Down
4 changes: 2 additions & 2 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
compile supportDependencies.kitCore

compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
compile 'com.github.bumptech.glide:glide:3.8.0'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.google.code.gson:gson:2.8.2'
}
2 changes: 1 addition & 1 deletion example/example.iml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="com.52inc:52Kit-core-0.5.1" level="project" />
<orderEntry type="library" name="com.google.code.gson:gson:2.8.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:animated-vector-drawable-25.4.0" level="project" />
<orderEntry type="library" name="com.jakewharton:butterknife-8.6.0" level="project" />
<orderEntry type="library" name="com.android.support:cardview-v7-25.4.0" level="project" />
Expand All @@ -127,6 +126,7 @@
<orderEntry type="library" name="com.android.support:support-v4-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:support-vector-drawable-25.4.0" level="project" />
<orderEntry type="library" name="com.jakewharton:butterknife-annotations:8.6.0@jar" level="project" />
<orderEntry type="library" name="com.google.code.gson:gson:2.8.2@jar" level="project" />
<orderEntry type="library" name="io.reactivex:rxjava:1.2.10@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-fragment-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:recyclerview-v7-25.4.0" level="project" />
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
VERSION_NAME=2.0.6-SNAPSHOT
VERSION_NAME=2.0.6
VERSION_CODE=10
GROUP=com.r0adkll

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.r0adkll.slidr;


import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.view.View;

import com.r0adkll.slidr.model.SlidrConfig;
import com.r0adkll.slidr.widget.SliderPanel;


class FragmentPanelSlideListener implements SliderPanel.OnPanelSlideListener {

private final View view;
private final SlidrConfig config;


FragmentPanelSlideListener(@NonNull View view, @NonNull SlidrConfig config) {
this.view = view;
this.config = config;
}


@Override
public void onStateChanged(int state) {
if (config.getListener() != null) {
config.getListener().onSlideStateChanged(state);
}
}


@Override
public void onClosed() {
if (config.getListener() != null) {
config.getListener().onSlideClosed();
}

// Ensure that we are attached to a FragmentActivity
if (view.getContext() instanceof FragmentActivity) {
final FragmentActivity activity = (FragmentActivity) view.getContext();
if (activity.getSupportFragmentManager().getBackStackEntryCount() == 0) {
activity.finish();
activity.overridePendingTransition(0, 0);
} else {
activity.getSupportFragmentManager().popBackStack();
}
}
}

@Override
public void onOpened() {
if (config.getListener() != null) {
config.getListener().onSlideOpened();
}
}


@Override
public void onSlideChange(float percent) {
if (config.getListener() != null) {
config.getListener().onSlideChange(percent);
}
}
}
Loading

0 comments on commit 4637b7c

Please sign in to comment.