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 | |
Hyunyoung Song | e4be3b3 | 2016-07-18 16:35:10 -0700 | [diff] [blame^] | 39 | private final InsetDrawable mRevealDrawable; |
| 40 | private final ColorDrawable mDrawable; |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 41 | |
| 42 | private View mRevealView; |
| 43 | private View mContent; |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 44 | |
| 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 Goyal | 05c8c57 | 2016-03-17 11:57:24 -0700 | [diff] [blame] | 55 | |
Andrew Sapperstein | abef55a | 2016-06-19 12:49:00 -0700 | [diff] [blame] | 56 | Launcher launcher = Launcher.getLauncher(context); |
| 57 | int width = launcher.getDeviceProfile().availableWidthPx; |
Hyunyoung Song | a9a8a42 | 2016-06-15 16:45:48 -0700 | [diff] [blame] | 58 | if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && |
Hyunyoung Song | f7e5e37 | 2016-06-28 12:16:47 -0700 | [diff] [blame] | 59 | this instanceof AllAppsContainerView && |
| 60 | !launcher.getDeviceProfile().isVerticalBarLayout()) { |
Hyunyoung Song | 645764e | 2016-06-06 14:19:02 -0700 | [diff] [blame] | 61 | mHorizontalPadding = 0; |
| 62 | } else { |
| 63 | mHorizontalPadding = DeviceProfile.getContainerPadding(context, width); |
| 64 | } |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 65 | |
Hyunyoung Song | a97c64b | 2016-06-30 11:53:44 -0700 | [diff] [blame] | 66 | if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && this instanceof AllAppsContainerView) { |
Hyunyoung Song | e4be3b3 | 2016-07-18 16:35:10 -0700 | [diff] [blame^] | 67 | mDrawable = new ColorDrawable(); |
| 68 | mRevealDrawable = new InsetDrawable(mDrawable, |
| 69 | mHorizontalPadding, 0, mHorizontalPadding, 0); |
Hyunyoung Song | a97c64b | 2016-06-30 11:53:44 -0700 | [diff] [blame] | 70 | } 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 Song | e4be3b3 | 2016-07-18 16:35:10 -0700 | [diff] [blame^] | 76 | mDrawable = null; |
Hyunyoung Song | a97c64b | 2016-06-30 11:53:44 -0700 | [diff] [blame] | 77 | a.recycle(); |
| 78 | } |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 79 | } |
| 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 Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 87 | |
Hyunyoung Song | e4be3b3 | 2016-07-18 16:35:10 -0700 | [diff] [blame^] | 88 | 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 Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 94 | |
Sunny Goyal | a6194d3 | 2016-02-19 09:34:09 -0800 | [diff] [blame] | 95 | // 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 Chung | 73f0b9b | 2015-07-08 14:13:08 -0700 | [diff] [blame] | 98 | } |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 99 | |
| 100 | public final View getContentView() { |
| 101 | return mContent; |
| 102 | } |
| 103 | |
| 104 | public final View getRevealView() { |
| 105 | return mRevealView; |
| 106 | } |
Hyunyoung Song | e4be3b3 | 2016-07-18 16:35:10 -0700 | [diff] [blame^] | 107 | |
| 108 | public void setRevealDrawableColor(int color) { |
| 109 | mDrawable.setColor(color); |
| 110 | } |
Andrew Sapperstein | abef55a | 2016-06-19 12:49:00 -0700 | [diff] [blame] | 111 | } |