136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley/*
236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * Copyright (C) 2017 The Android Open Source Project
336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *
436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * Licensed under the Apache License, Version 2.0 (the "License");
536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * you may not use this file except in compliance with the License.
636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * You may obtain a copy of the License at
736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *
836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *      http://www.apache.org/licenses/LICENSE-2.0
936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *
1036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * Unless required by applicable law or agreed to in writing, software
1136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * distributed under the License is distributed on an "AS IS" BASIS,
1236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * See the License for the specific language governing permissions and
1436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * limitations under the License.
1536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley */
1636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
1736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleypackage android.support.wear.widget.drawer;
1836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
1936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.annotation.TargetApi;
2036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.content.Context;
2136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.content.res.TypedArray;
2236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.graphics.drawable.Drawable;
2336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.os.Build;
2436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.support.annotation.IdRes;
2536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.support.annotation.IntDef;
2636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.support.annotation.Nullable;
2736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.support.annotation.RestrictTo;
2836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.support.annotation.RestrictTo.Scope;
2936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.support.annotation.StyleableRes;
3036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.support.v4.widget.ViewDragHelper;
3136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.support.wear.R;
3236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.util.AttributeSet;
3336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.view.Gravity;
3436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.view.LayoutInflater;
3536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.view.View;
3636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.view.ViewGroup;
3736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.widget.FrameLayout;
3836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport android.widget.ImageView;
3936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
4036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport java.lang.annotation.Retention;
4136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleyimport java.lang.annotation.RetentionPolicy;
4236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
4336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley/**
4436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * View that contains drawer content and a peeking view for use with {@link WearableDrawerLayout}.
4536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *
4636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * <p>This view provides the ability to set its main content as well as a view shown while peeking.
4736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * Specifying the peek view is entirely optional; a default is used if none are set. However, the
4836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * content must be provided.
4936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *
5036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * <p>There are two ways to specify the content and peek views: by invoking {@code setter} methods
516e7866f3a3fb65848d9ab46c1ffd7ed9b712244eSean Kelley * on the {@code WearableDrawerView}, or by specifying the {@code app:drawerContent} and {@code
526e7866f3a3fb65848d9ab46c1ffd7ed9b712244eSean Kelley * app:peekView} attributes. Examples:
5336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *
5436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * <pre>
5536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * // From Java:
5636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * drawerView.setDrawerContent(drawerContentView);
5736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * drawerView.setPeekContent(peekContentView);
5836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *
5936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * &lt;!-- From XML: --&gt;
6036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * &lt;android.support.wear.widget.drawer.WearableDrawerView
6136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *     android:layout_width="match_parent"
6236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *     android:layout_height="match_parent"
6336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *     android:layout_gravity="bottom"
6436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *     android:background="@color/red"
656e7866f3a3fb65848d9ab46c1ffd7ed9b712244eSean Kelley *     app:drawerContent="@+id/drawer_content"
666e7866f3a3fb65848d9ab46c1ffd7ed9b712244eSean Kelley *     app:peekView="@+id/peek_view"&gt;
6736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *
6836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *     &lt;FrameLayout
6936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *         android:id="@id/drawer_content"
7036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *         android:layout_width="match_parent"
7136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *         android:layout_height="match_parent" /&gt;
7236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *
7336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *     &lt;LinearLayout
7436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *         android:id="@id/peek_view"
7536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *         android:layout_width="wrap_content"
7636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *         android:layout_height="wrap_content"
7736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *         android:layout_gravity="center_horizontal"
7836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *         android:orientation="horizontal"&gt;
7936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *         &lt;ImageView
8036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *             android:layout_width="wrap_content"
8136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *             android:layout_height="wrap_content"
8236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *             android:src="@android:drawable/ic_media_play" /&gt;
8336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *         &lt;ImageView
8436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *             android:layout_width="wrap_content"
8536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *             android:layout_height="wrap_content"
8636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *             android:src="@android:drawable/ic_media_pause" /&gt;
8736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley *     &lt;/LinearLayout&gt;
8836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley * &lt;/android.support.wear.widget.drawer.WearableDrawerView&gt;</pre>
8936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley */
9036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley@TargetApi(Build.VERSION_CODES.M)
9136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelleypublic class WearableDrawerView extends FrameLayout {
9236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
9336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Indicates that the drawer is in an idle, settled state. No animation is in progress.
9436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
9536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public static final int STATE_IDLE = ViewDragHelper.STATE_IDLE;
9636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
9736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
9836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Indicates that the drawer is currently being dragged by the user.
9936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
10036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public static final int STATE_DRAGGING = ViewDragHelper.STATE_DRAGGING;
10136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
10236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
10336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Indicates that the drawer is in the process of settling to a final position.
10436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
10536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public static final int STATE_SETTLING = ViewDragHelper.STATE_SETTLING;
10636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
10736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
10836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Enumeration of possible drawer states.
10936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * @hide
11036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
11136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    @Retention(RetentionPolicy.SOURCE)
11236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    @RestrictTo(Scope.LIBRARY_GROUP)
11336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    @IntDef({STATE_IDLE, STATE_DRAGGING, STATE_SETTLING})
11436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public @interface DrawerState {}
11536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
11636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private final ViewGroup mPeekContainer;
11736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private final ImageView mPeekIcon;
11836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private View mContent;
11936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private WearableDrawerController mController;
12036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
12136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Vertical offset of the drawer. Ranges from 0 (closed) to 1 (opened)
12236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
12336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private float mOpenedPercent;
12436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
12536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * True if the drawer's position cannot be modified by the user. This includes edge dragging,
12636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * view dragging, and scroll based auto-peeking.
12736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
12836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private boolean mIsLocked = false;
12936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private boolean mCanAutoPeek = true;
13036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private boolean mLockWhenClosed = false;
13136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private boolean mOpenOnlyAtTop = false;
13236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private boolean mPeekOnScrollDown = false;
13336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private boolean mIsPeeking;
13436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    @DrawerState private int mDrawerState;
13536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    @IdRes private int mPeekResId = 0;
13636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    @IdRes private int mContentResId = 0;
13736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public WearableDrawerView(Context context) {
13836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        this(context, null);
13936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
14036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
14136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public WearableDrawerView(Context context, AttributeSet attrs) {
14236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        this(context, attrs, 0);
14336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
14436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
14536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public WearableDrawerView(Context context, AttributeSet attrs, int defStyleAttr) {
14636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        this(context, attrs, defStyleAttr, 0);
14736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
14836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
14936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public WearableDrawerView(
15036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
15136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        super(context, attrs, defStyleAttr, defStyleRes);
15297f7aa4e4dd8f5c1f14d93d3f67540c72a5bbe57Aga Madurska        LayoutInflater.from(context).inflate(R.layout.ws_wearable_drawer_view, this, true);
15336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
15436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        setClickable(true);
15597f7aa4e4dd8f5c1f14d93d3f67540c72a5bbe57Aga Madurska        setElevation(context.getResources()
15697f7aa4e4dd8f5c1f14d93d3f67540c72a5bbe57Aga Madurska                .getDimension(R.dimen.ws_wearable_drawer_view_elevation));
15736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
15897f7aa4e4dd8f5c1f14d93d3f67540c72a5bbe57Aga Madurska        mPeekContainer = (ViewGroup) findViewById(R.id.ws_drawer_view_peek_container);
15997f7aa4e4dd8f5c1f14d93d3f67540c72a5bbe57Aga Madurska        mPeekIcon = (ImageView) findViewById(R.id.ws_drawer_view_peek_icon);
16036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
16136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mPeekContainer.setOnClickListener(
16236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                new OnClickListener() {
16336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                    @Override
16436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                    public void onClick(View v) {
16536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                        onPeekContainerClicked(v);
16636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                    }
16736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                });
16836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
16936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        parseAttributes(context, attrs, defStyleAttr, defStyleRes);
17036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
17136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
17236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private static Drawable getDrawable(
17336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            Context context, TypedArray typedArray, @StyleableRes int index) {
17436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        Drawable background;
17536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        int backgroundResId =
17636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                typedArray.getResourceId(index, 0);
17736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        if (backgroundResId == 0) {
17836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            background = typedArray.getDrawable(index);
17936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        } else {
18036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            background = context.getDrawable(backgroundResId);
18136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        }
18236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return background;
18336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
18436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
18536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    @Override
18636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    protected void onFinishInflate() {
18736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        super.onFinishInflate();
18836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
18936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        // Drawer content is added after the peek view, so we need to bring the peek view
19036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        // to the front so it shows on top of the content.
19136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mPeekContainer.bringToFront();
19236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
19336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
19436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
19536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Called when anything within the peek container is clicked. However, if a custom peek view is
19636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * supplied and it handles the click, then this may not be called. The default behavior is to
19736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * open the drawer.
19836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
19936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void onPeekContainerClicked(View v) {
20036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mController.openDrawer();
20136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
20236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
20336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    @Override
20436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    protected void onAttachedToWindow() {
20536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        super.onAttachedToWindow();
20636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
20736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        // The peek view has a layout gravity of bottom for the top drawer, and a layout gravity
20836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        // of top for the bottom drawer. This is required so that the peek view shows. On the top
20936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        // drawer, the bottom peeks from the top, and on the bottom drawer, the top peeks.
21036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        // LayoutParams are not guaranteed to return a non-null value until a child is attached to
21136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        // the window.
21236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        LayoutParams peekParams = (LayoutParams) mPeekContainer.getLayoutParams();
21336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        if (!Gravity.isVertical(peekParams.gravity)) {
21436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            final boolean isTopDrawer =
21536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                    (((LayoutParams) getLayoutParams()).gravity & Gravity.VERTICAL_GRAVITY_MASK)
21636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                            == Gravity.TOP;
21736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            if (isTopDrawer) {
21836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                peekParams.gravity = Gravity.BOTTOM;
21997f7aa4e4dd8f5c1f14d93d3f67540c72a5bbe57Aga Madurska                mPeekIcon.setImageResource(R.drawable.ws_ic_more_horiz_24dp_wht);
22036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            } else {
22136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                peekParams.gravity = Gravity.TOP;
22297f7aa4e4dd8f5c1f14d93d3f67540c72a5bbe57Aga Madurska                mPeekIcon.setImageResource(R.drawable.ws_ic_more_vert_24dp_wht);
22336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            }
22436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            mPeekContainer.setLayoutParams(peekParams);
22536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        }
22636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
22736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
22836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    @Override
22936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void addView(View child, int index, ViewGroup.LayoutParams params) {
23036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        @IdRes int childId = child.getId();
23136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        if (childId != 0) {
23236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            if (childId == mPeekResId) {
23336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                setPeekContent(child, index, params);
23436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                return;
23536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            }
23636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            if (childId == mContentResId && !setDrawerContentWithoutAdding(child)) {
23736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                return;
23836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            }
23936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        }
24036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
24136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        super.addView(child, index, params);
24236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
24336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
24436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    int preferGravity() {
24536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return Gravity.NO_GRAVITY;
24636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
24736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
24836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    ViewGroup getPeekContainer() {
24936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mPeekContainer;
25036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
25136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
25236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    void setDrawerController(WearableDrawerController controller) {
25336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mController = controller;
25436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
25536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
25636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
25736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Returns the drawer content view.
25836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
25936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    @Nullable
26036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public View getDrawerContent() {
26136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mContent;
26236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
26336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
26436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
26536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Set the drawer content view.
26636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     *
26736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * @param content The view to show when the drawer is open, or {@code null} if it should not
26836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * open.
26936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
27036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void setDrawerContent(@Nullable View content) {
27136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        if (setDrawerContentWithoutAdding(content)) {
27236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            addView(content);
27336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        }
27436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
27536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
27636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
27736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Set the peek content view.
27836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     *
27936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * @param content The view to show when the drawer peeks.
28036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
28136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void setPeekContent(View content) {
28236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        ViewGroup.LayoutParams layoutParams = content.getLayoutParams();
28336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        setPeekContent(
28436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                content,
28536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                -1 /* index */,
28636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                layoutParams != null ? layoutParams : generateDefaultLayoutParams());
28736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
28836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
28936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
29036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Called when the drawer has settled in a completely open state. The drawer is interactive at
29136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * this point. This is analogous to {@link
29236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * WearableDrawerLayout.DrawerStateCallback#onDrawerOpened}.
29336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
29436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void onDrawerOpened() {}
29536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
29636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
29736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Called when the drawer has settled in a completely closed state. This is analogous to {@link
29836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * WearableDrawerLayout.DrawerStateCallback#onDrawerClosed}.
29936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
30036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void onDrawerClosed() {}
30136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
30236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
30336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Called when the drawer state changes. This is analogous to {@link
30436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * WearableDrawerLayout.DrawerStateCallback#onDrawerStateChanged}.
30536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     *
30636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * @param state one of {@link #STATE_DRAGGING}, {@link #STATE_SETTLING}, or {@link #STATE_IDLE}
30736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
30836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void onDrawerStateChanged(@DrawerState int state) {}
30936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
31036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
31136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Only allow the user to open this drawer when at the top of the scrolling content. If there is
31236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * no scrolling content, then this has no effect. Defaults to {@code false}.
31336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
31436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void setOpenOnlyAtTopEnabled(boolean openOnlyAtTop) {
31536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mOpenOnlyAtTop = openOnlyAtTop;
31636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
31736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
31836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
31936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Returns whether this drawer may only be opened by the user when at the top of the scrolling
32036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * content. If there is no scrolling content, then this has no effect. Defaults to {@code
32136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * false}.
32236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
32336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public boolean isOpenOnlyAtTopEnabled() {
32436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mOpenOnlyAtTop;
32536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
32636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
32736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
32836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Sets whether or not this drawer should peek while scrolling down. This is currently only
32936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * supported for bottom drawers. Defaults to {@code false}.
33036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
33136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void setPeekOnScrollDownEnabled(boolean peekOnScrollDown) {
33236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mPeekOnScrollDown = peekOnScrollDown;
33336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
33436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
33536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
33636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Gets whether or not this drawer should peek while scrolling down. This is currently only
33736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * supported for bottom drawers. Defaults to {@code false}.
33836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
33936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public boolean isPeekOnScrollDownEnabled() {
34036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mPeekOnScrollDown;
34136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
34236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
34336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
34436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Sets whether this drawer should be locked when the user cannot see it.
34536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * @see #isLocked
34636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
34736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void setLockedWhenClosed(boolean locked) {
34836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mLockWhenClosed = locked;
34936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
35036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
35136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
35236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Returns true if this drawer should be locked when the user cannot see it.
35336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * @see #isLocked
35436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
35536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public boolean isLockedWhenClosed() {
35636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mLockWhenClosed;
35736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
35836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
35936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
36036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Returns the current drawer state, which will be one of {@link #STATE_DRAGGING}, {@link
36136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * #STATE_SETTLING}, or {@link #STATE_IDLE}
36236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
36336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    @DrawerState
36436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public int getDrawerState() {
36536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mDrawerState;
36636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
36736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
36836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
36936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Sets the {@link DrawerState}.
37036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
37136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    void setDrawerState(@DrawerState int drawerState) {
37236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mDrawerState = drawerState;
37336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
37436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
37536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
37636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Returns whether the drawer is either peeking or the peek view is animating open.
37736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
37836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public boolean isPeeking() {
37936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mIsPeeking;
38036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
38136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
38236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
38336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Returns true if this drawer has auto-peeking enabled. This will always return {@code false}
38436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * for a locked drawer.
38536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
38636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public boolean isAutoPeekEnabled() {
38736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mCanAutoPeek && !mIsLocked;
38836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
38936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
39036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
39136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Sets whether or not the drawer can automatically adjust its peek state. Note that locked
39236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * drawers will never auto-peek, but their {@code isAutoPeekEnabled} state will be maintained
39336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * through a lock/unlock cycle.
39436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
39536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void setIsAutoPeekEnabled(boolean canAutoPeek) {
39636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mCanAutoPeek = canAutoPeek;
39736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
39836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
39936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
40036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Returns true if the position of the drawer cannot be modified by user interaction.
40136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Specifically, a drawer cannot be opened, closed, or automatically peeked by {@link
40236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * WearableDrawerLayout}. However, it can be explicitly opened, closed, and peeked by the
40336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * developer. A drawer may be considered locked if the drawer is locked open, locked closed, or
40436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * is closed and {@link #isLockedWhenClosed} returns true.
40536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
40636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public boolean isLocked() {
40736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mIsLocked || (isLockedWhenClosed() && mOpenedPercent <= 0);
40836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
40936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
41036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
41136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Sets whether or not the position of the drawer can be modified by user interaction.
41236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * @see #isLocked
41336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
41436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public void setIsLocked(boolean locked) {
41536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mIsLocked = locked;
41636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
41736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
41836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
41936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Returns true if the drawer is fully open.
42036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
42136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public boolean isOpened() {
42236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mOpenedPercent == 1;
42336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
42436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
42536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
42636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Returns true if the drawer is fully closed.
42736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
42836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public boolean isClosed() {
42936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mOpenedPercent == 0;
43036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
43136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
43236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
43336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Returns the {@link WearableDrawerController} associated with this {@link WearableDrawerView}.
43436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * This will only be valid after this {@code View} has been added to its parent.
43536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
43636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    public WearableDrawerController getController() {
43736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mController;
43836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
43936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
44036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
44136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Sets whether the drawer is either peeking or the peek view is animating open.
44236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
44336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    void setIsPeeking(boolean isPeeking) {
44436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mIsPeeking = isPeeking;
44536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
44636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
44736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
44836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Returns the percent the drawer is open, from 0 (fully closed) to 1 (fully open).
44936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
45036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    float getOpenedPercent() {
45136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mOpenedPercent;
45236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
45336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
45436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
45536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * Sets the percent the drawer is open, from 0 (fully closed) to 1 (fully open).
45636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
45736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    void setOpenedPercent(float openedPercent) {
45836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mOpenedPercent = openedPercent;
45936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
46036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
46136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private void parseAttributes(
46236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
46336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        if (attrs == null) {
46436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            return;
46536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        }
46636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
46736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        TypedArray typedArray =
46836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                context.obtainStyledAttributes(
46936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                        attrs, R.styleable.WearableDrawerView, defStyleAttr,
47097f7aa4e4dd8f5c1f14d93d3f67540c72a5bbe57Aga Madurska                        R.style.Widget_Wear_WearableDrawerView);
47136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
47236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        Drawable background =
47336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                getDrawable(context, typedArray, R.styleable.WearableDrawerView_android_background);
47436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        int elevation = typedArray
47536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                .getDimensionPixelSize(R.styleable.WearableDrawerView_android_elevation, 0);
47636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        setBackground(background);
47736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        setElevation(elevation);
47836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
47936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mContentResId = typedArray.getResourceId(R.styleable.WearableDrawerView_drawerContent, 0);
48036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mPeekResId = typedArray.getResourceId(R.styleable.WearableDrawerView_peekView, 0);
48136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mCanAutoPeek =
48236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley                typedArray.getBoolean(R.styleable.WearableDrawerView_enableAutoPeek, mCanAutoPeek);
48336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        typedArray.recycle();
48436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
48536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
48636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private void setPeekContent(View content, int index, ViewGroup.LayoutParams params) {
48736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        if (content == null) {
48836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            return;
48936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        }
49036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        if (mPeekContainer.getChildCount() > 0) {
49136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            mPeekContainer.removeAllViews();
49236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        }
49336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mPeekContainer.addView(content, index, params);
49436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
49536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
49636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    /**
49736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     * @return {@code true} if this is a new and valid {@code content}.
49836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley     */
49936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    private boolean setDrawerContentWithoutAdding(View content) {
50036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        if (content == mContent) {
50136545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            return false;
50236545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        }
50336545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        if (mContent != null) {
50436545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley            removeView(mContent);
50536545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        }
50636545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley
50736545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        mContent = content;
50836545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley        return mContent != null;
50936545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley    }
51036545bb3f2b12af352e550c278cff9026a18ca54Sean Kelley}
511