ReverseLinearLayout.java revision a20818257e6927560a676d99dbc563a0394f74d8
1a20818257e6927560a676d99dbc563a0394f74d8Jason Monk/*
2a20818257e6927560a676d99dbc563a0394f74d8Jason Monk * Copyright (C) 2016 The Android Open Source Project
3a20818257e6927560a676d99dbc563a0394f74d8Jason Monk *
4a20818257e6927560a676d99dbc563a0394f74d8Jason Monk * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5a20818257e6927560a676d99dbc563a0394f74d8Jason Monk * except in compliance with the License. You may obtain a copy of the License at
6a20818257e6927560a676d99dbc563a0394f74d8Jason Monk *
7a20818257e6927560a676d99dbc563a0394f74d8Jason Monk *      http://www.apache.org/licenses/LICENSE-2.0
8a20818257e6927560a676d99dbc563a0394f74d8Jason Monk *
9a20818257e6927560a676d99dbc563a0394f74d8Jason Monk * Unless required by applicable law or agreed to in writing, software distributed under the
10a20818257e6927560a676d99dbc563a0394f74d8Jason Monk * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11a20818257e6927560a676d99dbc563a0394f74d8Jason Monk * KIND, either express or implied. See the License for the specific language governing
12a20818257e6927560a676d99dbc563a0394f74d8Jason Monk * permissions and limitations under the License.
13a20818257e6927560a676d99dbc563a0394f74d8Jason Monk */
14a20818257e6927560a676d99dbc563a0394f74d8Jason Monk
15a20818257e6927560a676d99dbc563a0394f74d8Jason Monkpackage com.android.systemui.statusbar.phone;
16a20818257e6927560a676d99dbc563a0394f74d8Jason Monk
17a20818257e6927560a676d99dbc563a0394f74d8Jason Monkimport android.annotation.Nullable;
18a20818257e6927560a676d99dbc563a0394f74d8Jason Monkimport android.content.Context;
19a20818257e6927560a676d99dbc563a0394f74d8Jason Monkimport android.util.AttributeSet;
20a20818257e6927560a676d99dbc563a0394f74d8Jason Monkimport android.view.View;
21a20818257e6927560a676d99dbc563a0394f74d8Jason Monkimport android.view.ViewGroup;
22a20818257e6927560a676d99dbc563a0394f74d8Jason Monkimport android.widget.LinearLayout;
23a20818257e6927560a676d99dbc563a0394f74d8Jason Monk
24a20818257e6927560a676d99dbc563a0394f74d8Jason Monk/**
25a20818257e6927560a676d99dbc563a0394f74d8Jason Monk * Automatically reverses the order of children as they are added.
26a20818257e6927560a676d99dbc563a0394f74d8Jason Monk * Also reverse the width and height values of layout params
27a20818257e6927560a676d99dbc563a0394f74d8Jason Monk */
28a20818257e6927560a676d99dbc563a0394f74d8Jason Monkpublic class ReverseLinearLayout extends LinearLayout {
29a20818257e6927560a676d99dbc563a0394f74d8Jason Monk
30a20818257e6927560a676d99dbc563a0394f74d8Jason Monk    public ReverseLinearLayout(Context context, @Nullable AttributeSet attrs) {
31a20818257e6927560a676d99dbc563a0394f74d8Jason Monk        super(context, attrs);
32a20818257e6927560a676d99dbc563a0394f74d8Jason Monk    }
33a20818257e6927560a676d99dbc563a0394f74d8Jason Monk
34a20818257e6927560a676d99dbc563a0394f74d8Jason Monk    @Override
35a20818257e6927560a676d99dbc563a0394f74d8Jason Monk    public void addView(View child) {
36a20818257e6927560a676d99dbc563a0394f74d8Jason Monk        reversParams(child.getLayoutParams());
37a20818257e6927560a676d99dbc563a0394f74d8Jason Monk        super.addView(child, 0);
38a20818257e6927560a676d99dbc563a0394f74d8Jason Monk    }
39a20818257e6927560a676d99dbc563a0394f74d8Jason Monk
40a20818257e6927560a676d99dbc563a0394f74d8Jason Monk    @Override
41a20818257e6927560a676d99dbc563a0394f74d8Jason Monk    public void addView(View child, ViewGroup.LayoutParams params) {
42a20818257e6927560a676d99dbc563a0394f74d8Jason Monk        reversParams(params);
43a20818257e6927560a676d99dbc563a0394f74d8Jason Monk        super.addView(child, 0, params);
44a20818257e6927560a676d99dbc563a0394f74d8Jason Monk    }
45a20818257e6927560a676d99dbc563a0394f74d8Jason Monk
46a20818257e6927560a676d99dbc563a0394f74d8Jason Monk    private void reversParams(ViewGroup.LayoutParams params) {
47a20818257e6927560a676d99dbc563a0394f74d8Jason Monk        if (params == null) {
48a20818257e6927560a676d99dbc563a0394f74d8Jason Monk            return;
49a20818257e6927560a676d99dbc563a0394f74d8Jason Monk        }
50a20818257e6927560a676d99dbc563a0394f74d8Jason Monk        int width = params.width;
51a20818257e6927560a676d99dbc563a0394f74d8Jason Monk        params.width = params.height;
52a20818257e6927560a676d99dbc563a0394f74d8Jason Monk        params.height = width;
53a20818257e6927560a676d99dbc563a0394f74d8Jason Monk    }
54a20818257e6927560a676d99dbc563a0394f74d8Jason Monk
55a20818257e6927560a676d99dbc563a0394f74d8Jason Monk}
56