blob: f69fa562d46bcb910b8537a1cc0297b0a30b4552 [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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Winson Chung4e6a9762011-05-09 11:56:34 -070018
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;
Michael Jurka038f9d82011-11-03 13:50:45 -070033 private Runnable mOnLayoutListener;
Winson Chung4e6a9762011-05-09 11:56:34 -070034
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 }
Adam Cohen22f823d2011-09-01 17:22:18 -070044
Winson Chung4e6a9762011-05-09 11:56:34 -070045 int getCellCountY() {
46 return mCellCountY;
47 }
48
Winson Chungc6f10b92011-11-14 11:39:07 -080049 /**
50 * Clears all the key listeners for the individual widgets.
51 */
52 public void resetChildrenOnKeyListeners() {
53 int childCount = getChildCount();
54 for (int j = 0; j < childCount; ++j) {
55 getChildAt(j).setOnKeyListener(null);
56 }
57 }
58
Michael Jurkae326f182011-11-21 14:05:46 -080059 @Override
60 protected void onDetachedFromWindow() {
61 super.onDetachedFromWindow();
62 mOnLayoutListener = null;
63 }
64
Michael Jurka038f9d82011-11-03 13:50:45 -070065 public void setOnLayoutListener(Runnable r) {
66 mOnLayoutListener = r;
67 }
68
69 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
70 super.onLayout(changed, left, top, right, bottom);
71 if (mOnLayoutListener != null) {
72 mOnLayoutListener.run();
73 }
74 }
75
Winson Chung4e6a9762011-05-09 11:56:34 -070076 @Override
77 public boolean onTouchEvent(MotionEvent event) {
Winson Chungf0ea4d32011-06-06 14:27:16 -070078 boolean result = super.onTouchEvent(event);
79 int count = getPageChildCount();
80 if (count > 0) {
81 // We only intercept the touch if we are tapping in empty space after the final row
82 View child = getChildOnPageAt(count - 1);
83 int bottom = child.getBottom();
84 result = result || (event.getY() < bottom);
85 }
86 return result;
Winson Chung4e6a9762011-05-09 11:56:34 -070087 }
88
Winson Chung4e6a9762011-05-09 11:56:34 -070089 @Override
90 public void removeAllViewsOnPage() {
91 removeAllViews();
Michael Jurka2a4b1a82011-12-07 14:00:02 -080092 mOnLayoutListener = null;
Michael Jurka47639b92013-01-14 12:42:27 +010093 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung4e6a9762011-05-09 11:56:34 -070094 }
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}