blob: cedf71c5bc35b2e58903dfe8c7c89c762322e963 [file] [log] [blame]
Winson Chung4e6a9762011-05-09 11:56:34 -07001/*
2 * Copyright (C) 2011 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.launcher2;
18
19import android.content.Context;
20import android.view.MotionEvent;
21import android.view.View;
22import android.view.View.MeasureSpec;
23import android.widget.FrameLayout;
24import android.widget.LinearLayout;
25
26/**
27 * The grid based layout used strictly for the widget/wallpaper tab of the AppsCustomize pane
28 */
29public class PagedViewGridLayout extends FrameLayout implements Page {
30 static final String TAG = "PagedViewGridLayout";
31
32 private int mCellCountX;
33 private int mCellCountY;
34
35 public PagedViewGridLayout(Context context, int cellCountX, int cellCountY) {
36 super(context, null, 0);
37 mCellCountX = cellCountX;
38 mCellCountY = cellCountY;
39 }
40
41 int getCellCountX() {
42 return mCellCountX;
43 }
44 int getCellCountY() {
45 return mCellCountY;
46 }
47
48 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
49 // PagedView currently has issues with different-sized pages since it calculates the
50 // offset of each page to scroll to before it updates the actual size of each page
51 // (which can change depending on the content if the contents aren't a fixed size).
52 // We work around this by having a minimum size on each widget page).
53 int widthSpecSize = Math.max(getSuggestedMinimumWidth(),
54 MeasureSpec.getSize(widthMeasureSpec));
55 int widthSpecMode = MeasureSpec.AT_MOST;
56 super.onMeasure(MeasureSpec.makeMeasureSpec(widthSpecSize, widthSpecMode),
57 heightMeasureSpec);
58 }
59
60 @Override
61 public boolean onTouchEvent(MotionEvent event) {
62 // We eat up the touch events here, since the PagedView (which uses the same swiping
63 // touch code as Workspace previously) uses onInterceptTouchEvent() to determine when
64 // the user is scrolling between pages. This means that if the pages themselves don't
65 // handle touch events, it gets forwarded up to PagedView itself, and it's own
66 // onTouchEvent() handling will prevent further intercept touch events from being called
67 // (it's the same view in that case). This is not ideal, but to prevent more changes,
68 // we just always mark the touch event as handled.
69 return super.onTouchEvent(event) || true;
70 }
71
72 @Override
73 protected boolean onSetAlpha(int alpha) {
74 return true;
75 }
76
77 @Override
78 public void setAlpha(float alpha) {
79 setChildrenAlpha(alpha);
80 super.setAlpha(alpha);
81 }
82
83 private void setChildrenAlpha(float alpha) {
84 final int childCount = getChildCount();
85 for (int i = 0; i < childCount; i++) {
86 getChildAt(i).setAlpha(alpha);
87 }
88 }
89
90 @Override
91 public void removeAllViewsOnPage() {
92 removeAllViews();
93 }
94
95 @Override
96 public void removeViewOnPageAt(int index) {
97 removeViewAt(index);
98 }
99
100 @Override
101 public int getPageChildCount() {
102 return getChildCount();
103 }
104
105 @Override
106 public View getChildOnPageAt(int i) {
107 return getChildAt(i);
108 }
109
110 @Override
111 public int indexOfChildOnPage(View v) {
112 return indexOfChild(v);
113 }
114
115 public static class LayoutParams extends FrameLayout.LayoutParams {
116 public LayoutParams(int width, int height) {
117 super(width, height);
118 }
119 }
120}