Skip to content
This repository was archived by the owner on Jan 22, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.jakewharton.behavior.drawer;

import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.SystemClock;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.GravityCompat;
Expand All @@ -26,6 +28,7 @@
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.accessibility.AccessibilityEvent;

import static android.view.View.INVISIBLE;
Expand All @@ -38,6 +41,7 @@ final class BehaviorDelegate extends ViewDragHelper.Callback {
private static final int FLAG_IS_OPENING = 0x2;
private static final int FLAG_IS_CLOSING = 0x4;
private static final int DEFAULT_SCRIM_COLOR = 0x99000000;
private static final String BEHAVIOR_STATE = "behavior_state";

private final CoordinatorLayout parent;
private final View child;
Expand Down Expand Up @@ -325,8 +329,7 @@ private void updateChildrenImportantForAccessibility(View drawerView, boolean is
}
}

@Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
@Override public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
int childWidth = changedView.getWidth();

// This reverses the positioning shown in onLayout.
Expand Down Expand Up @@ -456,4 +459,31 @@ boolean onLayoutChild() {
}
return true;
}

public Parcelable onSaveInstanceState() {
Bundle outState = new Bundle();
outState.putInt(BEHAVIOR_STATE, openState);
return outState;
}

public void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle savedState = (Bundle) state;
openState = savedState.getInt(BEHAVIOR_STATE);
// Check if the drawer was open according to the previous state -
// TODO call isDrawerOpen() and reset openState after
child.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override public void onGlobalLayout() {
//TODO call openDrawer() here
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
child.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
//noinspection deprecation
child.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcelable;
import android.support.annotation.Keep;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.util.SimpleArrayMap;
Expand Down Expand Up @@ -80,4 +81,13 @@ public boolean onInterceptTouchEvent(CoordinatorLayout parent, View child, Motio
@Override public boolean onTouchEvent(CoordinatorLayout parent, View child, MotionEvent ev) {
return delegate(parent, child).onTouchEvent(ev);
}

@Override public Parcelable onSaveInstanceState(CoordinatorLayout parent, View child) {
return delegate(parent, child).onSaveInstanceState();
}

@Override
public void onRestoreInstanceState(CoordinatorLayout parent, View child, Parcelable state) {
delegate(parent,child).onRestoreInstanceState(state);
}
}
2 changes: 2 additions & 0 deletions sample/src/main/res/layout/drawer_behavior.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#feee"
>
<View
android:id="@+id/drawerView"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
Expand Down