blob: a9ef43dbfdd4838d5b26c4e27a5487eedb2b661f [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
Hyunyoung Song645764e2016-06-06 14:19:02 -070027import com.android.launcher3.allapps.AllAppsContainerView;
28import com.android.launcher3.config.FeatureFlags;
29
Winson Chung94804152015-05-08 13:06:44 -070030/**
31 * A base container view, which supports resizing.
32 */
Sunny Goyal05c8c572016-03-17 11:57:24 -070033public abstract class BaseContainerView extends FrameLayout {
Winson Chung94804152015-05-08 13:06:44 -070034
Sunny Goyal05c8c572016-03-17 11:57:24 -070035 protected final int mHorizontalPadding;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080036
37 private final Drawable mRevealDrawable;
38
39 private View mRevealView;
40 private View mContent;
Winson Chung94804152015-05-08 13:06:44 -070041
42 public BaseContainerView(Context context) {
43 this(context, null);
44 }
45
46 public BaseContainerView(Context context, AttributeSet attrs) {
47 this(context, attrs, 0);
48 }
49
50 public BaseContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
51 super(context, attrs, defStyleAttr);
Sunny Goyal05c8c572016-03-17 11:57:24 -070052
53 int width = ((Launcher) context).getDeviceProfile().availableWidthPx;
Hyunyoung Song645764e2016-06-06 14:19:02 -070054 if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && (this instanceof AllAppsContainerView)) {
55 mHorizontalPadding = 0;
56 } else {
57 mHorizontalPadding = DeviceProfile.getContainerPadding(context, width);
58 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080059
60 TypedArray a = context.obtainStyledAttributes(attrs,
61 R.styleable.BaseContainerView, defStyleAttr, 0);
Sunny Goyal05c8c572016-03-17 11:57:24 -070062 mRevealDrawable = new InsetDrawable(
63 a.getDrawable(R.styleable.BaseContainerView_revealBackground),
64 mHorizontalPadding, 0, mHorizontalPadding, 0);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080065 a.recycle();
66 }
67
68 @Override
69 protected void onFinishInflate() {
70 super.onFinishInflate();
71
72 mContent = findViewById(R.id.main_content);
73 mRevealView = findViewById(R.id.reveal_view);
Winson Chung94804152015-05-08 13:06:44 -070074
Sunny Goyal05c8c572016-03-17 11:57:24 -070075 mRevealView.setBackground(mRevealDrawable.getConstantState().newDrawable());
76 mContent.setBackground(mRevealDrawable);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080077
Sunny Goyala6194d32016-02-19 09:34:09 -080078 // We let the content have a intent background, but still have full width.
79 // This allows the scroll bar to be used responsive outside the background bounds as well.
80 mContent.setPadding(0, 0, 0, 0);
Winson Chung73f0b9b2015-07-08 14:13:08 -070081 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080082
83 public final View getContentView() {
84 return mContent;
85 }
86
87 public final View getRevealView() {
88 return mRevealView;
89 }
Winson Chung94804152015-05-08 13:06:44 -070090}