Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.launcher3; |
| 18 | |
| 19 | import android.content.Context; |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 20 | import android.content.res.TypedArray; |
Hyunyoung Song | a97c64b | 2016-06-30 11:53:44 -0700 | [diff] [blame^] | 21 | import android.graphics.Color; |
| 22 | import android.graphics.drawable.ColorDrawable; |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 23 | import android.graphics.drawable.Drawable; |
| 24 | import android.graphics.drawable.InsetDrawable; |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 25 | import android.util.AttributeSet; |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 26 | import android.view.View; |
| 27 | import android.widget.FrameLayout; |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 28 | |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 29 | import com.android.launcher3.allapps.AllAppsContainerView; |
| 30 | import com.android.launcher3.config.FeatureFlags; |
| 31 | |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 32 | /** |
| 33 | * A base container view, which supports resizing. |
| 34 | */ |
Sunny Goyal | 05c8c57 | 2016-03-17 11:57:24 -0700 | [diff] [blame] | 35 | public abstract class BaseContainerView extends FrameLayout { |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 36 | |
Sunny Goyal | 05c8c57 | 2016-03-17 11:57:24 -0700 | [diff] [blame] | 37 | protected final int mHorizontalPadding; |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 38 | |
| 39 | private final Drawable mRevealDrawable; |
| 40 | |
| 41 | private View mRevealView; |
| 42 | private View mContent; |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 43 | |
| 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 Goyal | 05c8c57 | 2016-03-17 11:57:24 -0700 | [diff] [blame] | 54 | |
Andrew Sapperstein | abef55a | 2016-06-19 12:49:00 -0700 | [diff] [blame] | 55 | Launcher launcher = Launcher.getLauncher(context); |
| 56 | int width = launcher.getDeviceProfile().availableWidthPx; |
Hyunyoung Song | a9a8a42 | 2016-06-15 16:45:48 -0700 | [diff] [blame] | 57 | if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && |
Hyunyoung Song | f7e5e37 | 2016-06-28 12:16:47 -0700 | [diff] [blame] | 58 | this instanceof AllAppsContainerView && |
| 59 | !launcher.getDeviceProfile().isVerticalBarLayout()) { |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 60 | mHorizontalPadding = 0; |
| 61 | } else { |
| 62 | mHorizontalPadding = DeviceProfile.getContainerPadding(context, width); |
| 63 | } |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 64 | |
Hyunyoung Song | a97c64b | 2016-06-30 11:53:44 -0700 | [diff] [blame^] | 65 | 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 Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 76 | } |
| 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 Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 84 | |
Sunny Goyal | 05c8c57 | 2016-03-17 11:57:24 -0700 | [diff] [blame] | 85 | mRevealView.setBackground(mRevealDrawable.getConstantState().newDrawable()); |
| 86 | mContent.setBackground(mRevealDrawable); |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 87 | |
Sunny Goyal | a6194d3 | 2016-02-19 09:34:09 -0800 | [diff] [blame] | 88 | // 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 Chung | 73f0b9b | 2015-07-08 14:13:08 -0700 | [diff] [blame] | 91 | } |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 92 | |
| 93 | public final View getContentView() { |
| 94 | return mContent; |
| 95 | } |
| 96 | |
| 97 | public final View getRevealView() { |
| 98 | return mRevealView; |
| 99 | } |
Andrew Sapperstein | abef55a | 2016-06-19 12:49:00 -0700 | [diff] [blame] | 100 | } |