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

Commit

Permalink
Merge pull request #51 from GGLabCenter/master
Browse files Browse the repository at this point in the history
New: added Fragment support and bug fix.
  • Loading branch information
r0adkll authored Dec 6, 2017
2 parents ba9935b + bb9aa16 commit f991bf8
Show file tree
Hide file tree
Showing 4 changed files with 1,467 additions and 1 deletion.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
Slidr
================

## Note 1 on this fork:
https://github.com/r0adkll/Slidr/issues/45 solved here. (When using Horizontal)

## Note 2 on this fork:
added the same behavior available to Fragments! Here is a quick how-to explanation:

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

```java
// This interface is needed to see if 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();
if(slidrInterface == null)
slidrInterface = Slidr.replace(getView().findViewById(R.id.content_container), new SlidrConfig.Builder().position(SlidrPosition.LEFT).build());
}
```
In the xml of the fragment's view, the root view must be a FrameLayout with the same background set to the activity before. Add a child viewgroup to it with the id content_container. E.g.:

```xml
<FrameLayout
android:id="@+id/main_container"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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.support.design.widget.CoordinatorLayout
android:id="@+id/content_container"
android:layout_width="match_parent"
android:layout_height="match_parent">

...other stuff

</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.




[![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)
Expand Down
77 changes: 77 additions & 0 deletions library/src/main/java/com/r0adkll/slidr/Slidr.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,82 @@ public void unlock() {
// Return the lock interface
return slidrInterface;
}

public static SlidrInterface replace(final View oldScreen, final SlidrConfig config){
ViewGroup parent = (ViewGroup) oldScreen.getParent();
ViewGroup.LayoutParams params = oldScreen.getLayoutParams();
parent.removeView(oldScreen);
// Setup the slider panel and attach it
final SliderPanel panel = new SliderPanel(oldScreen.getContext(), oldScreen, config);
panel.setId(R.id.slidable_panel);
oldScreen.setId(R.id.slidable_content);

panel.addView(oldScreen);
parent.addView(panel,0, params);

// Set the panel slide listener for when it becomes closed or opened
panel.setOnPanelSlideListener(new SliderPanel.OnPanelSlideListener() {

@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();
}
if(((AppCompatActivity)(oldScreen.getContext())).getSupportFragmentManager().getBackStackEntryCount()==0) {
((AppCompatActivity)(oldScreen.getContext())).finish();
((AppCompatActivity)(oldScreen.getContext())).overridePendingTransition(0, 0);
}else{
((AppCompatActivity)(oldScreen.getContext())).getSupportFragmentManager().popBackStack();
}
}

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

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onSlideChange(float percent) {
if(config.getListener() != null){
config.getListener().onSlideChange(percent);
}
}
});

// Setup the lock interface
SlidrInterface slidrInterface = new SlidrInterface() {
@Override
public void lock() {
panel.lock();
}

@Override
public void unlock() {
panel.unlock();
}

@Override
public void addViewToPanel(View v) {

}

@Override
public void removeViewToPanel(View v) {

}
};
// Return the lock interface
return slidrInterface;
}

}
Loading

0 comments on commit f991bf8

Please sign in to comment.