• Stars
    star
    234
  • Rank 171,630 (Top 4 %)
  • Language
    Java
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A View-based navigation stack for Android

Project Status

There are a million other libraries for this use case, and I have no reason to believe this one is the best. This started as a fun experiment and got a bunch of github stars after it got shared through various channels. It works and you're free to use it, but I have no plans for maintaining or improving it.

Pancakes

Pancakes is a View-based navigation stack library for Android. While it does aim to replace some of FragmentManager's functionality, its feature set is not one-to-one with that of FragmentManager, as Views and Fragments are inherently different. Unlike FragmentManager, it also supports the use of Animators for View transitions.

Download

compile 'me.mattlogan.pancakes:pancakes:4.0.0'

Usage

Create a ViewStack instance with a ViewGroup container and a ViewStackDelegate:

ViewStack viewStack = ViewStack.create(container, delegate);

Add a View to your container by pushing a layout id:

viewStack.push(R.layout.red_view);

Call pop() to go back one View:

viewStack.pop();

Or, use an AnimatorFactory along with pushWithAnimation(int, AnimatorFactory) and popWithAnimation(AnimatorFactory) to add remove a View with a transition animation.

public class CircularReveal implements AnimatorFactory {
    @Override
    public Animator createAnimator(View view) {
        int cx = view.getWidth() / 2;
        int cy = view.getHeight() / 2;

        int finalRadius = Math.max(view.getWidth(), view.getHeight());

        return ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
    }
}

You can also call peek() to get the View at the top of the navigation stack.

Add a StackChangedListener (or several) if you want to be notified of changes in the navigation stack:

viewStack.addStackChangedListener(listener);

You can also remove individual listeners with removeStackChangedListener(StackChangedListener) or remove all of them with clearStackChangedListeners().

Persist your navigation stack across configuration changes:

@Override
public void onSaveInstanceState(Bundle outState) {
    viewStack.saveToBundle(outState, STACK_TAG);
    super.onSaveInstanceState(outState);
}

Rebuild the stack from a Bundle:

viewStack.rebuildFromBundle(savedInstanceState, STACK_TAG);

Additionally, you may use View.onSaveInstanceState(Bundle) and View.onRestoreInstanceState(Bundle) to save the state of any View in the navigation stack so long as it has an ID.

Finally, implement ViewStackDelegate.finishStack() to take appropriate action when the stack is finished:

@Override
public void finishStack() {
    finish();
}

See the sample app for an example implementation.

Tests

Unit tests located in /library/src/androidTest/

License

The MIT License (MIT)

Copyright (c) 2015 Matthew Logan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

More Repositories

1

Artiste

Static factory methods for fancy Path objects
Java
188
star
2

RhymeCity

Sample Android app for aspiring lyricists
Java
139
star
3

auto-value-firebase

AutoValue extension for creating Firebase Realtime Database objects
Java
102
star
4

CircleMenu

Deprecated -- material design is better
Java
34
star
5

Twenty-seven

Android Experiments: https://experiments.withgoogle.com/twenty-seven
Java
16
star
6

ParallaxListView

Android ListView with parallaxed header
Java
16
star
7

AndroidImageResizer

A Node.js + ImageMagick script for resizing images for Android apps
JavaScript
15
star
8

StravaFlow

Simple master-detail Android app using Strava API. Retrofit + Otto + ButterKnife.
Java
12
star
9

NDKTest

Trivial NDK example for Android Studio adapted from Gradle samples
Groovy
11
star
10

SurgePriceWidget

Android widget for getting current Uber surge prices at your location -- Uber API + Retrofit + Otto
Java
10
star
11

LocationTracker

Demo app for test doubles talk: https://www.youtube.com/watch?v=_pCwcdNtxog
Java
9
star
12

ImageSearch

Sample Android app -- Google Image Search API + Picasso + Retrofit + Otto
Java
8
star
13

push-to-talk-android

A small sample app for saving voice recordings to the cloud. ViewModel + LiveData + Firebase cloud storage + unidirectional data flow etc.
Kotlin
7
star
14

RxJavaImageSearch

Google Instant style image search Android app -- Retrofit + RxJava (w/ PublishSubject) + Picasso
Java
6
star
15

SelectableMapFragment

Android MapFragment with draggable overlay box
Java
6
star
16

XapiClient

Android client for the OpenStreetMap (OSM) Extended API (Xapi)
Java
2
star
17

ReverseDrawerLayout

Modified Android DrawerLayout -- sliding content view on drawer, navigation menu underneath (just like SlidingMenu)
Java
1
star