blob: 64d50b7d0191df5efd5d73675651ab5395de0581 [file] [log] [blame]
Winson Chung94804152015-05-08 13:06:44 -07001/*
2 * Copyright (C) 2015 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.launcher3;
18
19import android.content.Context;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080020import android.content.res.TypedArray;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080021import android.graphics.drawable.Drawable;
22import android.graphics.drawable.InsetDrawable;
Winson Chung94804152015-05-08 13:06:44 -070023import android.util.AttributeSet;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080024import android.view.View;
25import android.widget.FrameLayout;
Winson Chung94804152015-05-08 13:06:44 -070026
27/**
28 * A base container view, which supports resizing.
29 */
Sunny Goyal05c8c572016-03-17 11:57:24 -070030public abstract class BaseContainerView extends FrameLayout {
Winson Chung94804152015-05-08 13:06:44 -070031
Sunny Goyal05c8c572016-03-17 11:57:24 -070032 protected final int mHorizontalPadding;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080033
34 private final Drawable mRevealDrawable;
35
36 private View mRevealView;
37 private View mContent;
Winson Chung94804152015-05-08 13:06:44 -070038
39 public BaseContainerView(Context context) {
40 this(context, null);
41 }
42
43 public BaseContainerView(Context context, AttributeSet attrs) {
44 this(context, attrs, 0);
45 }
46
47 public BaseContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
48 super(context, attrs, defStyleAttr);
Sunny Goyal05c8c572016-03-17 11:57:24 -070049
50 int width = ((Launcher) context).getDeviceProfile().availableWidthPx;
Sunny Goyal13178ac2016-04-04 16:35:22 -070051 mHorizontalPadding = DeviceProfile.getMaxContainerWidth(context, width);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080052
53 TypedArray a = context.obtainStyledAttributes(attrs,
54 R.styleable.BaseContainerView, defStyleAttr, 0);
Sunny Goyal05c8c572016-03-17 11:57:24 -070055 mRevealDrawable = new InsetDrawable(
56 a.getDrawable(R.styleable.BaseContainerView_revealBackground),
57 mHorizontalPadding, 0, mHorizontalPadding, 0);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080058 a.recycle();
59 }
60
61 @Override
62 protected void onFinishInflate() {
63 super.onFinishInflate();
64
65 mContent = findViewById(R.id.main_content);
66 mRevealView = findViewById(R.id.reveal_view);
Winson Chung94804152015-05-08 13:06:44 -070067
Sunny Goyal05c8c572016-03-17 11:57:24 -070068 mRevealView.setBackground(mRevealDrawable.getConstantState().newDrawable());
69 mContent.setBackground(mRevealDrawable);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080070
Sunny Goyala6194d32016-02-19 09:34:09 -080071 // We let the content have a intent background, but still have full width.
72 // This allows the scroll bar to be used responsive outside the background bounds as well.
73 mContent.setPadding(0, 0, 0, 0);
Winson Chung73f0b9b2015-07-08 14:13:08 -070074 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080075
76 public final View getContentView() {
77 return mContent;
78 }
79
80 public final View getRevealView() {
81 return mRevealView;
82 }
Winson Chung94804152015-05-08 13:06:44 -070083}