GithubHelp home page GithubHelp logo

eddieringle / android-undergarment Goto Github PK

View Code? Open in Web Editor NEW
343.0 40.0 124.0 186 KB

A slide-out navigation (a.k.a. "Drawer") implementation for Android applications

License: BSD 2-Clause "Simplified" License

Java 100.00%

android-undergarment's Introduction

Undergarment

NOTE: Undergarment is deprecated. Please use the official DrawerLayout implementation located in the v4 Support Library.


A slide-out navigation (a.k.a. "Drawer") implementation for Android applications.

The slide-out navigation pattern has been popping up in all sorts of places in the Android ecosystem lately in all sorts of shapes and sizes. Undergarment initially started with me mimicking the experience found in the Prixing application, as documented by Cyril Mottier in his series of three blog posts on the subject.

Just recently (August 2012), the Android team updated their Design site specifically with a new pattern documenting the slide-out navigation every developer and their dog had been playing around with to that date. Thusly, the "Drawer" pattern was born. You can find the Android team's documentation regarding the Drawer pattern under the "View Controls" section of the Action Bar patterns page.

Now, as the Prixing implementation dealt with sliding the entire window (Action Bar and all) over to the side in order to reveal the "drawer" while the pattern on the Android Design site used the YouTube app as a reference, which slides only the content portion over and keeps the Action Bar stationary, my implementation was a bit lacking. So, I added support for sliding just the content portion over, moved the implementation into a standalone Android Library project, and put it on GitHub. That's the story of how Undergarment was born.

Using & Such

I'm a fan of git submodules (and IntelliJ), so in order to use this library I recommend adding this repository as a submodule of your encompassing project's repository:

git submodule add git://github.com/eddieringle/android-undergarment contrib/android-undergarment

Now add the Undergarment library as a module in IntelliJ and add that module as a dependency of your project. You're then ready to start using Undergarment!

Integrating Undergarment is fairly straightforward. In the onCreate of the Activity hosting the Undergarment (a.k.a. "Drawer") do a little something like this:

mDrawerGarment = new DrawerGarment(this, R.layout.dashboard);

The constructor takes two arguments, the first being the Activity that hosts the Undergarment and the second being a resource identifier to the layout that will define the drawer contents.

By default, Undergarment is set to slide the entire window over, Action Bar and all. If you wish to switch to the YouTube-style of only sliding over the content then you can set it like so:

mDrawerGarment.setSlideTarget(DrawerGarment.SLIDE_TARGET_CONTENT);

When the drawer is first attached to the view hierarchy, Undergarment sets the background color of the content view to Color.WHITE. The reason it is not transparent (or left alone) is because the drawer would otherwise show through to the content view, making things look messy and such. If a white background won't work and, for instance, red is more your style, you can change it like so:

mDrawerGarment.setDecorContentBackgroundColor(Color.RED);
mDrawerGarment.reconfigureViewHierarchy();

To open and close the drawer, call the openDrawer() and closeDrawer() methods, respectively. You can also toggle the drawer state with the toggleDrawer() method. The user will also be able to control the drawer by bezel swiping from the left side of the screen to open the drawer and doing the same from the right to close it. If you want to prevent this touch functionality, you can call setDrawerEnabled(false).

Finally, you can provide callbacks to the drawer that will fire when the drawer is opened or closed, which allows you to do useful things such as modifying the state of the Action Bar. To set the callbacks, implement the DrawerGarment.IDrawerCallbacks interface and add them to the drawer with setDrawerCallbacks(callbacks).

android-undergarment's People

Contributors

eddieringle avatar laurencedawson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-undergarment's Issues

Configure drawer menu slide width, instead of the right maring

Actual state of Undergarment drawer menu slides drawer menu always to the right edge of the screen with respect of the little margin (48dp, not configurable).

While for narrow screens it's ok, for wide screens (phones in landscape orientations, tablets) - this becomes not so good. Drawer menu usually doesn't require so much space.

So I suggest to make drawer menu width configurable. This will be more convenient that configurable margin.

Add feature to populate drawer with XML resource

Typical drawer menu implementation usually has a list of menu items.
So it would be great to have some bundled helpers to populate drawer with XML resource that describes desired drawer menu items. This will quicken development by obviating necessity of creating custom drawer layout, Adapter, layout for list item, etc.

True, that some drawer menus (e.g. in YouTube, Evernote apps) have complex custom layout also. So, to support both cases there can be API to set menu resource to inflate and custom view also. By the way, similar approach is implemented in FlyInMenu library by Alex Curran:
https://github.com/Espiandev/FlyInMenu

It populates menu items (icon+label) from XML menu resource with content like this:
https://github.com/Espiandev/FlyInMenu/blob/master/sample/res/menu/ribbon_menu.xml

Also it has API to add custom view also:
<getFlyInMenu().setCustomView(..)>

Don't break color or make it configurable

Undergarment component sets it's own color (white) as a background color.
Which sometimes leads to undesired results. E.g. if app uses ActionBarSherlock there will be applied theme with a lot of transparent places. So white color from Undergarment component will make action bar white! :-)

Suggestions:
set no color if it's possible (to don't force user set some specific color to match his brand colors)
or, if some color is required, make it configurable.

Sometimes drawer menu opens ignoring right margin

Sometimes drawer menu opens ignoring right margin, i.e. entire screen width will be occupied with drawer menu. It's happens not often and not always (probably it depends on type of the underlying main content) .
I've met that behavior when opening drawer menu with a really fast and intensive swipe gesture over the ViewPager components with Fragments.

DecorContent is still active when the drawer is open

When the drawer is open, I don't think the DecorContent should be active.

For example clicking a button in the DecorContent will still work AND close the drawer. The button should not be clickable at all and all touch events should simply close the drawer.

Versions compatibility

Is this compatible with Android versions 2.2 and 2.3? I tried implementing a content view fragment, in Android 2.2 it doesn't show, in Android 2.3 it doesn't receive touch events, but in Android 4 it works fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.