PlaybackControlsRowView.java revision b682c5a20aa0a383ea2b3e7d639e51b3e7771bcd
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package android.support.v17.leanback.widget;
18
19import android.content.Context;
20import android.graphics.Rect;
21import android.util.AttributeSet;
22import android.view.View;
23import android.widget.LinearLayout;
24
25/**
26 * A LinearLayout that preserves the focused child view.
27 * @hide
28 */
29class PlaybackControlsRowView extends LinearLayout {
30    public PlaybackControlsRowView(Context context, AttributeSet attrs) {
31        super(context, attrs);
32    }
33
34    public PlaybackControlsRowView(Context context, AttributeSet attrs, int defStyle) {
35        super(context, attrs, defStyle);
36    }
37
38    @Override
39    protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
40        final View focused = findFocus();
41        if (focused != null && focused.requestFocus(direction, previouslyFocusedRect)) {
42            return true;
43        }
44        return super.onRequestFocusInDescendants(direction, previouslyFocusedRect);
45    }
46}
47