1/*
2 * Copyright (C) 2011 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 com.android.camera.ui;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.View;
22import android.view.ViewGroup;
23
24// A layout designed to make the children same size as the first child.
25public class StackLayout extends ViewGroup {
26    private static final String TAG = "StackLayout";
27
28    public StackLayout(Context context, AttributeSet attrs) {
29        super(context, attrs);
30    }
31
32    @Override
33    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
34        final int count = getChildCount();
35
36        // Measure only the first child.
37        final View child = getChildAt(0);
38        measureChild(child, widthMeasureSpec, heightMeasureSpec);
39
40        // Ignore the paddings.
41        int width = child.getMeasuredWidth();
42        int height = child.getMeasuredHeight();
43
44        setMeasuredDimension(resolveSize(width, widthMeasureSpec),
45                resolveSize(height, heightMeasureSpec));
46    }
47
48    @Override
49    protected void onLayout(boolean changed, int l, int t, int r, int b) {
50        final int count = super.getChildCount();
51
52        for (int i = 0; i < count; i++) {
53            final View child = getChildAt(i);
54            if (child.getVisibility() != View.GONE) {
55                child.layout(0, 0, r - l, b - t);
56            }
57        }
58    }
59}
60