Demo entry 2778686

ActionBarDrawerToggle

   

Submitted by Esau Garcia on Sep 29, 2015 at 20:13
Language: Java. Code size: 1.9 kB.

package io.egalabs.nxtremotecontroller.widget;

import android.app.Activity;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.Toolbar;
import android.view.View;

/*
 * Extended version of the drawer toggle.
 */
public class ActionBarDrawerToggle extends android.support.v7.app.ActionBarDrawerToggle {

	/*
	 * Interface for drawer closing event.
	 */
	public interface OnDrawerClosedListener {
		void onDrawerClosed (View drawer);
	}

	/*
	 * Interface for drawer opening event.
	 */
	public interface OnDrawerOpenedListener {
		void onDrawerOpened (View drawer);
	}

	/*
	 * Listeners.
	 */
	protected OnDrawerClosedListener closeListener;
	protected OnDrawerOpenedListener openListener;

	/*
	 * The activity.
	 */
	protected Activity mActivity;

	/*
	 * Constructor.
	 */
	public ActionBarDrawerToggle (Activity activity, DrawerLayout drawerLayout, Toolbar toolbar, int openDrawerDes, int closeDrawerDes) {
		super(activity, drawerLayout, toolbar, openDrawerDes, closeDrawerDes);
		mActivity = activity;
	}

	/*
	 * Setter for the drawer closing listener.
	 */
	public void setOnDrawerClosedListener (OnDrawerClosedListener listener) {
		closeListener = listener;
	}

	/*
	 * Setter for the drawer opening listener.
	 */
	public void setOnDrawerOpenedListener (OnDrawerOpenedListener listener) {
		openListener = listener;
	}

	/*
	 * The default closing event that execute our custom closing event.
	 */
	@Override
	public void onDrawerClosed (View drawer) {
		super.onDrawerClosed(drawer);
		if (closeListener != null) {
			closeListener.onDrawerClosed(drawer);
		}
		mActivity.invalidateOptionsMenu();
	}

	/*
	 * The default opening event that execute our custom opening event.
	 */
	@Override
	public void onDrawerOpened (View drawer) {
		super.onDrawerOpened(drawer);
		if (openListener != null) {
			openListener.onDrawerOpened(drawer);
		}
		mActivity.invalidateOptionsMenu();
	}

}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).