RowContainerView.java revision 2f97594742886d045ca1ce409ebc6e6e780452f6
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14package android.support.v17.leanback.widget;
15
16import android.content.Context;
17import android.support.v17.leanback.R;
18import android.util.AttributeSet;
19import android.view.LayoutInflater;
20import android.view.View;
21import android.view.ViewGroup;
22import android.widget.LinearLayout;
23
24/**
25 * RowContainerView wraps header and user defined row view
26 */
27final class RowContainerView extends LinearLayout {
28
29    private ViewGroup mHeaderDock;
30
31    public RowContainerView(Context context) {
32        this(context, null, 0);
33    }
34
35    public RowContainerView(Context context, AttributeSet attrs) {
36        this(context, attrs, 0);
37    }
38
39    public RowContainerView(Context context, AttributeSet attrs, int defStyle) {
40        super(context, attrs, defStyle);
41        setOrientation(VERTICAL);
42        LayoutInflater inflater = LayoutInflater.from(context);
43        inflater.inflate(R.layout.lb_row_container, this);
44
45        mHeaderDock = (ViewGroup) findViewById(R.id.lb_row_container_header_dock);
46        setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
47    }
48
49    public void addHeaderView(View headerView) {
50        if (mHeaderDock.indexOfChild(headerView) < 0) {
51            mHeaderDock.addView(headerView, 0);
52        }
53    }
54
55    public void removeHeaderView(View headerView) {
56        if (mHeaderDock.indexOfChild(headerView) >= 0) {
57            mHeaderDock.removeView(headerView);
58        }
59    }
60
61    public void addRowView(View view) {
62        addView(view);
63    }
64
65    public void showHeader(boolean show) {
66        mHeaderDock.setVisibility(show ? View.VISIBLE : View.GONE);
67    }
68}
69