blob: 57a60a95d05cd424fa0b6ba5d4693d79e8c2dbba [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;
Hyunyoung Songa97c64b2016-06-30 11:53:44 -070021import android.graphics.Color;
22import android.graphics.drawable.ColorDrawable;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080023import android.graphics.drawable.Drawable;
24import android.graphics.drawable.InsetDrawable;
Winson Chung94804152015-05-08 13:06:44 -070025import android.util.AttributeSet;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080026import android.view.View;
27import android.widget.FrameLayout;
Winson Chung94804152015-05-08 13:06:44 -070028
Hyunyoung Song645764e2016-06-06 14:19:02 -070029import com.android.launcher3.allapps.AllAppsContainerView;
30import com.android.launcher3.config.FeatureFlags;
31
Winson Chung94804152015-05-08 13:06:44 -070032/**
33 * A base container view, which supports resizing.
34 */
Sunny Goyal05c8c572016-03-17 11:57:24 -070035public abstract class BaseContainerView extends FrameLayout {
Winson Chung94804152015-05-08 13:06:44 -070036
Sunny Goyal05c8c572016-03-17 11:57:24 -070037 protected final int mHorizontalPadding;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080038
Hyunyoung Songe4be3b32016-07-18 16:35:10 -070039 private final InsetDrawable mRevealDrawable;
40 private final ColorDrawable mDrawable;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080041
42 private View mRevealView;
43 private View mContent;
Winson Chung94804152015-05-08 13:06:44 -070044
45 public BaseContainerView(Context context) {
46 this(context, null);
47 }
48
49 public BaseContainerView(Context context, AttributeSet attrs) {
50 this(context, attrs, 0);
51 }
52
53 public BaseContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
54 super(context, attrs, defStyleAttr);
Sunny Goyal05c8c572016-03-17 11:57:24 -070055
Andrew Sappersteinabef55a2016-06-19 12:49:00 -070056 Launcher launcher = Launcher.getLauncher(context);
57 int width = launcher.getDeviceProfile().availableWidthPx;
Hyunyoung Songa9a8a422016-06-15 16:45:48 -070058 if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP &&
Hyunyoung Songf7e5e372016-06-28 12:16:47 -070059 this instanceof AllAppsContainerView &&
60 !launcher.getDeviceProfile().isVerticalBarLayout()) {
Hyunyoung Song645764e2016-06-06 14:19:02 -070061 mHorizontalPadding = 0;
62 } else {
63 mHorizontalPadding = DeviceProfile.getContainerPadding(context, width);
64 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080065
Hyunyoung Songa97c64b2016-06-30 11:53:44 -070066 if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && this instanceof AllAppsContainerView) {
Hyunyoung Songe4be3b32016-07-18 16:35:10 -070067 mDrawable = new ColorDrawable();
68 mRevealDrawable = new InsetDrawable(mDrawable,
69 mHorizontalPadding, 0, mHorizontalPadding, 0);
Hyunyoung Songa97c64b2016-06-30 11:53:44 -070070 } else {
71 TypedArray a = context.obtainStyledAttributes(attrs,
72 R.styleable.BaseContainerView, defStyleAttr, 0);
73 mRevealDrawable = new InsetDrawable(
74 a.getDrawable(R.styleable.BaseContainerView_revealBackground),
75 mHorizontalPadding, 0, mHorizontalPadding, 0);
Hyunyoung Songe4be3b32016-07-18 16:35:10 -070076 mDrawable = null;
Hyunyoung Songa97c64b2016-06-30 11:53:44 -070077 a.recycle();
78 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080079 }
80
81 @Override
82 protected void onFinishInflate() {
83 super.onFinishInflate();
84
85 mContent = findViewById(R.id.main_content);
86 mRevealView = findViewById(R.id.reveal_view);
Winson Chung94804152015-05-08 13:06:44 -070087
Hyunyoung Songe4be3b32016-07-18 16:35:10 -070088 if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && this instanceof AllAppsContainerView) {
89 mRevealView.setBackground(mRevealDrawable);
90 } else {
91 mRevealView.setBackground(mRevealDrawable.getConstantState().newDrawable());
92 mContent.setBackground(mRevealDrawable);
93 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080094
Sunny Goyala6194d32016-02-19 09:34:09 -080095 // We let the content have a intent background, but still have full width.
96 // This allows the scroll bar to be used responsive outside the background bounds as well.
97 mContent.setPadding(0, 0, 0, 0);
Winson Chung73f0b9b2015-07-08 14:13:08 -070098 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080099
100 public final View getContentView() {
101 return mContent;
102 }
103
104 public final View getRevealView() {
105 return mRevealView;
106 }
Hyunyoung Songe4be3b32016-07-18 16:35:10 -0700107
108 public void setRevealDrawableColor(int color) {
109 mDrawable.setColor(color);
110 }
Andrew Sappersteinabef55a2016-06-19 12:49:00 -0700111}