Skip to content
tkgktyk edited this page Nov 29, 2014 · 4 revisions

Quick Start Guide for ReleaseActionLayout


Setup Library

Import "Github - tkgktyk/ReleaseAction/ReleaseAction" as a library.

Layout

Wrap your layout in ReleaseActionLayout or SimpleReleaseActionLayout.

<jp.tkgktyk.releaseaction.SimpleReleaseActionLayout
    android:id="@+id/release_action"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- your original layout is here -->
    <!-- for example -->
    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</jp.tkgktyk.releaseaction.SimpleReleaseActionLayout>

Register listener and indicator views

You use ReleaseActionLayout#setLeft/Top/Right/BottomView to register indicator view. If you use SimpleReleaseActionLayout, use setLeft/Top/Right/BottomTextView.

mReleaseAction.setTopTextView(android.R.drawable.ic_menu_delete);
mReleaseAction.setBottomTextView(android.R.drawable.ic_menu_add);
mReleaseAction.setOnReleaseActionListener(new SimpleOnReleaseActionListener() {
        @Override
        public void onReleaseAction(ReleaseActionLayout v) {
            Flag flag = v.getActionFlag();
            if (flag.has(ReleaseActionLayout.ACTION_LEFT)) {
                // fire action at left
            }
            if (flag.has(ReleaseActionLayout.ACTION_TOP)) {
                // fire action at top
            }
            if (flag.has(ReleaseActionLayout.ACTION_RIGHT)) {
                // fire action at right
            }
            if (flag.has(ReleaseActionLayout.ACTION_BOTTOM)) {
                // fire action at bottom
            }

        @Override
        public CharSequence getEnabledText(int action) {
            int res = 0;
            switch (action) {
            case ReleaseActionLayout.ACTION_TOP:
                res = R.string.release_delete;
                break;
            case ReleaseActionLayout.ACTION_BOTTOM:
                res = R.string.release_add;
                break;
            }
            if (res == 0) {
                return null;
            }
            return getText(res);
        }
    });