blob: a2ab7634c21024f56bdfb5871655944d5db370cb [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;
Winson Chung4e6a9762011-05-09 11:56:34 -070022import android.widget.FrameLayout;
Winson Chungfd3385f2011-06-15 19:51:24 -070023import android.widget.GridLayout;
Winson Chung4e6a9762011-05-09 11:56:34 -070024
25/**
26 * The grid based layout used strictly for the widget/wallpaper tab of the AppsCustomize pane
27 */
Winson Chungfd3385f2011-06-15 19:51:24 -070028public class PagedViewGridLayout extends GridLayout implements Page {
Winson Chung4e6a9762011-05-09 11:56:34 -070029 static final String TAG = "PagedViewGridLayout";
30
31 private int mCellCountX;
32 private int mCellCountY;
33
34 public PagedViewGridLayout(Context context, int cellCountX, int cellCountY) {
35 super(context, null, 0);
36 mCellCountX = cellCountX;
37 mCellCountY = cellCountY;
Winson Chungfd3385f2011-06-15 19:51:24 -070038 setColumnCount(mCellCountX);
Winson Chung4e6a9762011-05-09 11:56:34 -070039 }
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).
Winson Chungfd3385f2011-06-15 19:51:24 -070053 int widthSpecSize = Math.min(getSuggestedMinimumWidth(),
Winson Chung4e6a9762011-05-09 11:56:34 -070054 MeasureSpec.getSize(widthMeasureSpec));
Winson Chungfd3385f2011-06-15 19:51:24 -070055 int widthSpecMode = MeasureSpec.EXACTLY;
Winson Chung4e6a9762011-05-09 11:56:34 -070056 super.onMeasure(MeasureSpec.makeMeasureSpec(widthSpecSize, widthSpecMode),
57 heightMeasureSpec);
58 }
59
60 @Override
61 public boolean onTouchEvent(MotionEvent event) {
Winson Chungf0ea4d32011-06-06 14:27:16 -070062 boolean result = super.onTouchEvent(event);
63 int count = getPageChildCount();
64 if (count > 0) {
65 // We only intercept the touch if we are tapping in empty space after the final row
66 View child = getChildOnPageAt(count - 1);
67 int bottom = child.getBottom();
68 result = result || (event.getY() < bottom);
69 }
70 return result;
Winson Chung4e6a9762011-05-09 11:56:34 -070071 }
72
73 @Override
74 protected boolean onSetAlpha(int alpha) {
75 return true;
76 }
77
78 @Override
79 public void setAlpha(float alpha) {
80 setChildrenAlpha(alpha);
81 super.setAlpha(alpha);
82 }
83
84 private void setChildrenAlpha(float alpha) {
85 final int childCount = getChildCount();
86 for (int i = 0; i < childCount; i++) {
87 getChildAt(i).setAlpha(alpha);
88 }
89 }
90
91 @Override
92 public void removeAllViewsOnPage() {
93 removeAllViews();
94 }
95
96 @Override
97 public void removeViewOnPageAt(int index) {
98 removeViewAt(index);
99 }
100
101 @Override
102 public int getPageChildCount() {
103 return getChildCount();
104 }
105
106 @Override
107 public View getChildOnPageAt(int i) {
108 return getChildAt(i);
109 }
110
111 @Override
112 public int indexOfChildOnPage(View v) {
113 return indexOfChild(v);
114 }
115
116 public static class LayoutParams extends FrameLayout.LayoutParams {
117 public LayoutParams(int width, int height) {
118 super(width, height);
119 }
120 }
121}