blob: 05760ae48d8b8157dd29ee436f6a6cc38b2840ef [file] [log] [blame]
Hyunyoung Song4b69f2c2015-05-11 14:55:07 -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.widget;
18
19import android.content.Context;
20import android.content.res.Resources;
21import android.util.AttributeSet;
22import android.widget.LinearLayout;
23
24
25import com.android.launcher3.DeviceProfile;
26import com.android.launcher3.DynamicGrid;
27import com.android.launcher3.LauncherAppState;
28
29/**
30 * Represents the individual cell of the widget inside the widget tray.
31 */
32public class WidgetRowView extends LinearLayout {
33
34 private static final int PRESET_INDENT_SIZE_TABLET = 56;
35
36 /** Widget row width is calculated by multiplying this factor to grid cell width. */
37 private static final float HEIGHT_SCALE = 2.8f;
38
39 static int sIndent = 0;
40 static int sHeight = 0;
41
42 public WidgetRowView(Context context) {
43 this(context, null);
44 }
45
46 public WidgetRowView(Context context, AttributeSet attrs) {
47 this(context, attrs, 0);
48 }
49
50 public WidgetRowView(Context context, AttributeSet attrs, int defStyle) {
51 super(context, attrs, defStyle);
52 setContainerHeight();
53 setWillNotDraw(false);
54 setClipToPadding(false);
55 setAccessibilityDelegate(LauncherAppState.getInstance().getAccessibilityDelegate());
56 }
57
58 /**
59 * Sets the widget cell container size based on the physical dimension of the device.
60 */
61 private void setContainerHeight() {
62 // Do nothing if already set
63 if (sHeight > 0) {
64 return;
65 }
66
67 Resources r = getResources();
68 DeviceProfile profile = LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile();
69 if (profile.isLargeTablet || profile.isTablet) {
70 sIndent = DynamicGrid.pxFromDp(PRESET_INDENT_SIZE_TABLET, r.getDisplayMetrics());
71 }
72 sHeight = (int) (profile.cellWidthPx * HEIGHT_SCALE);
73 }
74}