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; |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 21 | import android.graphics.drawable.Drawable; |
| 22 | import android.graphics.drawable.InsetDrawable; |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 23 | import android.util.AttributeSet; |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 24 | import android.view.View; |
| 25 | import android.widget.FrameLayout; |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * A base container view, which supports resizing. |
| 29 | */ |
Sunny Goyal | 05c8c57 | 2016-03-17 11:57:24 -0700 | [diff] [blame] | 30 | public abstract class BaseContainerView extends FrameLayout { |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 31 | |
Sunny Goyal | 05c8c57 | 2016-03-17 11:57:24 -0700 | [diff] [blame] | 32 | protected final int mHorizontalPadding; |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 33 | |
| 34 | private final Drawable mRevealDrawable; |
| 35 | |
| 36 | private View mRevealView; |
| 37 | private View mContent; |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 38 | |
| 39 | public BaseContainerView(Context context) { |
| 40 | this(context, null); |
| 41 | } |
| 42 | |
| 43 | public BaseContainerView(Context context, AttributeSet attrs) { |
| 44 | this(context, attrs, 0); |
| 45 | } |
| 46 | |
| 47 | public BaseContainerView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 48 | super(context, attrs, defStyleAttr); |
Sunny Goyal | 05c8c57 | 2016-03-17 11:57:24 -0700 | [diff] [blame] | 49 | |
| 50 | int width = ((Launcher) context).getDeviceProfile().availableWidthPx; |
Sunny Goyal | e27815e | 2016-04-04 17:51:04 -0700 | [diff] [blame] | 51 | mHorizontalPadding = DeviceProfile.getContainerPadding(context, width); |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 52 | |
| 53 | TypedArray a = context.obtainStyledAttributes(attrs, |
| 54 | R.styleable.BaseContainerView, defStyleAttr, 0); |
Sunny Goyal | 05c8c57 | 2016-03-17 11:57:24 -0700 | [diff] [blame] | 55 | mRevealDrawable = new InsetDrawable( |
| 56 | a.getDrawable(R.styleable.BaseContainerView_revealBackground), |
| 57 | mHorizontalPadding, 0, mHorizontalPadding, 0); |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 58 | a.recycle(); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | protected void onFinishInflate() { |
| 63 | super.onFinishInflate(); |
| 64 | |
| 65 | mContent = findViewById(R.id.main_content); |
| 66 | mRevealView = findViewById(R.id.reveal_view); |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 67 | |
Sunny Goyal | 05c8c57 | 2016-03-17 11:57:24 -0700 | [diff] [blame] | 68 | mRevealView.setBackground(mRevealDrawable.getConstantState().newDrawable()); |
| 69 | mContent.setBackground(mRevealDrawable); |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 70 | |
Sunny Goyal | a6194d3 | 2016-02-19 09:34:09 -0800 | [diff] [blame] | 71 | // We let the content have a intent background, but still have full width. |
| 72 | // This allows the scroll bar to be used responsive outside the background bounds as well. |
| 73 | mContent.setPadding(0, 0, 0, 0); |
Winson Chung | 73f0b9b | 2015-07-08 14:13:08 -0700 | [diff] [blame] | 74 | } |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 75 | |
| 76 | public final View getContentView() { |
| 77 | return mContent; |
| 78 | } |
| 79 | |
| 80 | public final View getRevealView() { |
| 81 | return mRevealView; |
| 82 | } |
Winson Chung | 9480415 | 2015-05-08 13:06:44 -0700 | [diff] [blame] | 83 | } |