1cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu/*
2cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu * Copyright (C) 2014 The Android Open Source Project
3cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu *
4cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu * in compliance with the License. You may obtain a copy of the License at
6cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu *
7cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu * http://www.apache.org/licenses/LICENSE-2.0
8cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu *
9cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu * Unless required by applicable law or agreed to in writing, software distributed under the License
10cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu * or implied. See the License for the specific language governing permissions and limitations under
12cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu * the License.
13cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu */
14ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikaspackage androidx.leanback.widget;
15cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu
16ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
178e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas
18cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Guimport android.content.Context;
19cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Guimport android.util.AttributeSet;
20cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Guimport android.view.View;
21cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Guimport android.widget.FrameLayout;
22cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu
238619e0ef7062b6a714f22af993e4b440fae7ef08Aurimas Liutikasimport androidx.annotation.RestrictTo;
248619e0ef7062b6a714f22af993e4b440fae7ef08Aurimas Liutikas
25cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu/**
26cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu * Customized FrameLayout excludes margin of child from calculating the child size.
27cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu * So we can change left margin of rows while keep the width of rows unchanged without
28cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu * using hardcoded DIPS.
295d00775a5d3ce3c1fc06c4de0945d1b8f03aadc4Dake Gu * @hide
30cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu */
318e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas@RestrictTo(LIBRARY_GROUP)
325d00775a5d3ce3c1fc06c4de0945d1b8f03aadc4Dake Gupublic class BrowseRowsFrameLayout extends FrameLayout {
33cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu
34cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu    public BrowseRowsFrameLayout(Context context) {
35cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu        this(context ,null);
36cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu    }
37cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu
38cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu    public BrowseRowsFrameLayout(Context context, AttributeSet attrs) {
39cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu        this(context, attrs, 0);
40cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu    }
41cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu
42cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu    public BrowseRowsFrameLayout(Context context, AttributeSet attrs,
43cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu            int defStyle) {
44cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu        super(context, attrs, defStyle);
45cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu    }
46cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu
47cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu    @Override
48cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu    protected void measureChildWithMargins(View child,
49cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu            int parentWidthMeasureSpec, int widthUsed,
50cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu            int parentHeightMeasureSpec, int heightUsed) {
51cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu        final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
52cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu        final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec,
53cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu                getPaddingLeft() + getPaddingRight() + widthUsed, lp.width);
54cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu        final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec,
55cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu                getPaddingTop() + getPaddingBottom() + heightUsed, lp.height);
56cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu        child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
57cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu    }
58cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu
59cfc50bafd5437b4f6396d60ebc258c76599ba52bDake Gu}
60