blob: 51a97b91b69775b508e444a384ec87db792696a1 [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;
Winson Chung94804152015-05-08 13:06:44 -070021import android.graphics.Rect;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080022import android.graphics.drawable.Drawable;
23import android.graphics.drawable.InsetDrawable;
Winson Chung94804152015-05-08 13:06:44 -070024import android.util.AttributeSet;
Winson Chung73f0b9b2015-07-08 14:13:08 -070025import android.util.Log;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080026import android.view.View;
27import android.widget.FrameLayout;
Winson Chung94804152015-05-08 13:06:44 -070028
Sunny Goyal6c56c682015-07-16 14:09:05 -070029import com.android.launcher3.config.ProviderConfig;
30
Winson Chung94804152015-05-08 13:06:44 -070031/**
32 * A base container view, which supports resizing.
33 */
Sunny Goyal05c8c572016-03-17 11:57:24 -070034public abstract class BaseContainerView extends FrameLayout {
Winson Chung94804152015-05-08 13:06:44 -070035
Sunny Goyal05c8c572016-03-17 11:57:24 -070036 protected final int mHorizontalPadding;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080037
38 private final Drawable mRevealDrawable;
39
40 private View mRevealView;
41 private View mContent;
Winson Chung94804152015-05-08 13:06:44 -070042
43 public BaseContainerView(Context context) {
44 this(context, null);
45 }
46
47 public BaseContainerView(Context context, AttributeSet attrs) {
48 this(context, attrs, 0);
49 }
50
51 public BaseContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
52 super(context, attrs, defStyleAttr);
Sunny Goyal05c8c572016-03-17 11:57:24 -070053
54 int width = ((Launcher) context).getDeviceProfile().availableWidthPx;
55 mHorizontalPadding = Math.max(
56 getResources().getDimensionPixelSize(R.dimen.container_min_margin),
57 (int) getResources().getFraction(R.fraction.container_margin, width, 1));
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080058
59 TypedArray a = context.obtainStyledAttributes(attrs,
60 R.styleable.BaseContainerView, defStyleAttr, 0);
Sunny Goyal05c8c572016-03-17 11:57:24 -070061 mRevealDrawable = new InsetDrawable(
62 a.getDrawable(R.styleable.BaseContainerView_revealBackground),
63 mHorizontalPadding, 0, mHorizontalPadding, 0);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080064 a.recycle();
65 }
66
67 @Override
68 protected void onFinishInflate() {
69 super.onFinishInflate();
70
71 mContent = findViewById(R.id.main_content);
72 mRevealView = findViewById(R.id.reveal_view);
Winson Chung94804152015-05-08 13:06:44 -070073
Sunny Goyal05c8c572016-03-17 11:57:24 -070074 mRevealView.setBackground(mRevealDrawable.getConstantState().newDrawable());
75 mContent.setBackground(mRevealDrawable);
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080076
Sunny Goyala6194d32016-02-19 09:34:09 -080077 // We let the content have a intent background, but still have full width.
78 // This allows the scroll bar to be used responsive outside the background bounds as well.
79 mContent.setPadding(0, 0, 0, 0);
Winson Chung73f0b9b2015-07-08 14:13:08 -070080 }
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080081
82 public final View getContentView() {
83 return mContent;
84 }
85
86 public final View getRevealView() {
87 return mRevealView;
88 }
Winson Chung94804152015-05-08 13:06:44 -070089}