1/*
2 * Copyright (C) 2010 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.videoeditor.widgets;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.View;
22import android.view.ViewGroup;
23import android.widget.RelativeLayout;
24
25/**
26 * The RelativeLayout which is the container for the timeline layout
27 */
28public class TimelineRelativeLayout extends RelativeLayout {
29    // Instance variables
30    private LayoutCallback mLayoutCallback;
31
32    /**
33     * Layout complete callback interface
34     */
35    public interface LayoutCallback {
36        /**
37         * This method is invoked when the layout completes after a call
38         * to requestLayout(LayoutCallback)
39         */
40        public void onLayoutComplete();
41    }
42
43    public TimelineRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
44        super(context, attrs, defStyle);
45
46        setMotionEventSplittingEnabled(false);
47    }
48
49    public TimelineRelativeLayout(Context context, AttributeSet attrs) {
50        this(context, attrs, 0);
51    }
52
53    public TimelineRelativeLayout(Context context) {
54        this(context, null, 0);
55    }
56
57    /**
58     * Request a layout and get a callback when the layout completes
59     *
60     * @param callback The layout callback
61     */
62    public void requestLayout(LayoutCallback callback) {
63        mLayoutCallback = callback;
64
65        requestLayout();
66    }
67
68    @Override
69    public void onLayout(boolean changed, int l, int t, int r, int b) {
70        super.onLayout(changed, l, t, r, b);
71
72        if (mLayoutCallback != null) {
73            mLayoutCallback.onLayoutComplete();
74            mLayoutCallback = null;
75        }
76    }
77
78    @Override
79    public void setSelected(boolean selected) {
80        final int childrenCount = getChildCount();
81        for (int i = 0; i < childrenCount; i++) {
82            final View childView = getChildAt(i);
83            if (childView instanceof ViewGroup) {
84                childView.setSelected(selected);
85            }
86        }
87    }
88}
89