blob: 45d0b5243b4dadfebe40f0553e4742aec62052db [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
Andrew Sappersteinabef55a2016-06-19 12:49:00 -070053 Launcher launcher = Launcher.getLauncher(context);
54 int width = launcher.getDeviceProfile().availableWidthPx;
Hyunyoung Songa9a8a422016-06-15 16:45:48 -070055 if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP &&
Hyunyoung Songf7e5e372016-06-28 12:16:47 -070056 this instanceof AllAppsContainerView &&
57 !launcher.getDeviceProfile().isVerticalBarLayout()) {
Hyunyoung Song645764e2016-06-06 14:19:02 -070058 mHorizontalPadding = 0;
59 } else {
60 mHorizontalPadding = DeviceProfile.getContainerPadding(context, width);
61 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080062
63 TypedArray a = context.obtainStyledAttributes(attrs,
64 R.styleable.BaseContainerView, defStyleAttr, 0);
Sunny Goyal05c8c572016-03-17 11:57:24 -070065 mRevealDrawable = new InsetDrawable(
66 a.getDrawable(R.styleable.BaseContainerView_revealBackground),
67 mHorizontalPadding, 0, mHorizontalPadding, 0);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080068 a.recycle();
69 }
70
71 @Override
72 protected void onFinishInflate() {
73 super.onFinishInflate();
74
75 mContent = findViewById(R.id.main_content);
76 mRevealView = findViewById(R.id.reveal_view);
Winson Chung94804152015-05-08 13:06:44 -070077
Sunny Goyal05c8c572016-03-17 11:57:24 -070078 mRevealView.setBackground(mRevealDrawable.getConstantState().newDrawable());
79 mContent.setBackground(mRevealDrawable);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080080
Sunny Goyala6194d32016-02-19 09:34:09 -080081 // We let the content have a intent background, but still have full width.
82 // This allows the scroll bar to be used responsive outside the background bounds as well.
83 mContent.setPadding(0, 0, 0, 0);
Winson Chung73f0b9b2015-07-08 14:13:08 -070084 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080085
86 public final View getContentView() {
87 return mContent;
88 }
89
90 public final View getRevealView() {
91 return mRevealView;
92 }
Andrew Sappersteinabef55a2016-06-19 12:49:00 -070093}