blob: f9c2407d4641ed03cd7ba655e61f654018720d8d [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
39 private final Drawable mRevealDrawable;
40
41 private View mRevealView;
42 private View mContent;
Winson Chung94804152015-05-08 13:06:44 -070043
44 public BaseContainerView(Context context) {
45 this(context, null);
46 }
47
48 public BaseContainerView(Context context, AttributeSet attrs) {
49 this(context, attrs, 0);
50 }
51
52 public BaseContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
53 super(context, attrs, defStyleAttr);
Sunny Goyal05c8c572016-03-17 11:57:24 -070054
Andrew Sappersteinabef55a2016-06-19 12:49:00 -070055 Launcher launcher = Launcher.getLauncher(context);
56 int width = launcher.getDeviceProfile().availableWidthPx;
Hyunyoung Songa9a8a422016-06-15 16:45:48 -070057 if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP &&
Hyunyoung Songf7e5e372016-06-28 12:16:47 -070058 this instanceof AllAppsContainerView &&
59 !launcher.getDeviceProfile().isVerticalBarLayout()) {
Hyunyoung Song645764e2016-06-06 14:19:02 -070060 mHorizontalPadding = 0;
61 } else {
62 mHorizontalPadding = DeviceProfile.getContainerPadding(context, width);
63 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080064
Hyunyoung Songa97c64b2016-06-30 11:53:44 -070065 if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && this instanceof AllAppsContainerView) {
66 mRevealDrawable = new InsetDrawable(new ColorDrawable(Color.WHITE), mHorizontalPadding,
67 0, mHorizontalPadding, 0);
68 } else {
69 TypedArray a = context.obtainStyledAttributes(attrs,
70 R.styleable.BaseContainerView, defStyleAttr, 0);
71 mRevealDrawable = new InsetDrawable(
72 a.getDrawable(R.styleable.BaseContainerView_revealBackground),
73 mHorizontalPadding, 0, mHorizontalPadding, 0);
74 a.recycle();
75 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080076 }
77
78 @Override
79 protected void onFinishInflate() {
80 super.onFinishInflate();
81
82 mContent = findViewById(R.id.main_content);
83 mRevealView = findViewById(R.id.reveal_view);
Winson Chung94804152015-05-08 13:06:44 -070084
Sunny Goyal05c8c572016-03-17 11:57:24 -070085 mRevealView.setBackground(mRevealDrawable.getConstantState().newDrawable());
86 mContent.setBackground(mRevealDrawable);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080087
Sunny Goyala6194d32016-02-19 09:34:09 -080088 // We let the content have a intent background, but still have full width.
89 // This allows the scroll bar to be used responsive outside the background bounds as well.
90 mContent.setPadding(0, 0, 0, 0);
Winson Chung73f0b9b2015-07-08 14:13:08 -070091 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080092
93 public final View getContentView() {
94 return mContent;
95 }
96
97 public final View getRevealView() {
98 return mRevealView;
99 }
Andrew Sappersteinabef55a2016-06-19 12:49:00 -0700100}