blob: d7dec6e0b6104f32c09fecd805928dfa016e41d4 [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 &&
Andrew Sappersteinabef55a2016-06-19 12:49:00 -070056 this instanceof AllAppsContainerView && launcher.getDeviceProfile().isLandscape) {
Hyunyoung Song645764e2016-06-06 14:19:02 -070057 mHorizontalPadding = 0;
58 } else {
59 mHorizontalPadding = DeviceProfile.getContainerPadding(context, width);
60 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080061
62 TypedArray a = context.obtainStyledAttributes(attrs,
63 R.styleable.BaseContainerView, defStyleAttr, 0);
Sunny Goyal05c8c572016-03-17 11:57:24 -070064 mRevealDrawable = new InsetDrawable(
65 a.getDrawable(R.styleable.BaseContainerView_revealBackground),
66 mHorizontalPadding, 0, mHorizontalPadding, 0);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080067 a.recycle();
68 }
69
70 @Override
71 protected void onFinishInflate() {
72 super.onFinishInflate();
73
74 mContent = findViewById(R.id.main_content);
75 mRevealView = findViewById(R.id.reveal_view);
Winson Chung94804152015-05-08 13:06:44 -070076
Sunny Goyal05c8c572016-03-17 11:57:24 -070077 mRevealView.setBackground(mRevealDrawable.getConstantState().newDrawable());
78 mContent.setBackground(mRevealDrawable);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080079
Sunny Goyala6194d32016-02-19 09:34:09 -080080 // We let the content have a intent background, but still have full width.
81 // This allows the scroll bar to be used responsive outside the background bounds as well.
82 mContent.setPadding(0, 0, 0, 0);
Winson Chung73f0b9b2015-07-08 14:13:08 -070083 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080084
85 public final View getContentView() {
86 return mContent;
87 }
88
89 public final View getRevealView() {
90 return mRevealView;
91 }
Andrew Sappersteinabef55a2016-06-19 12:49:00 -070092}