blob: 81f14982f15fd916dfb7feb75801a4bc34df400a [file] [log] [blame]
Winson Chung8e4ec312010-10-13 17:22:51 -07001/*
2 * Copyright (C) 2010 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.util.AttributeSet;
21import android.view.MotionEvent;
Michael Jurka8245a862011-02-01 17:53:59 -080022import android.view.View;
Winson Chung8e4ec312010-10-13 17:22:51 -070023import android.widget.LinearLayout;
24
25/**
Winson Chung45e1d6e2010-11-09 17:19:49 -080026 * The linear layout used strictly for the widget/wallpaper tab of the customization tray
Winson Chung8e4ec312010-10-13 17:22:51 -070027 */
Michael Jurka8245a862011-02-01 17:53:59 -080028public class PagedViewExtendedLayout extends LinearLayout implements Page {
Winson Chung97d85d22011-04-13 11:27:36 -070029 static final String TAG = "PagedViewExtendedLayout";
Winson Chung8e4ec312010-10-13 17:22:51 -070030
Winson Chung45e1d6e2010-11-09 17:19:49 -080031 public PagedViewExtendedLayout(Context context) {
Winson Chung8e4ec312010-10-13 17:22:51 -070032 this(context, null);
33 }
34
Winson Chung45e1d6e2010-11-09 17:19:49 -080035 public PagedViewExtendedLayout(Context context, AttributeSet attrs) {
Winson Chung8e4ec312010-10-13 17:22:51 -070036 this(context, attrs, 0);
37 }
38
Winson Chung45e1d6e2010-11-09 17:19:49 -080039 public PagedViewExtendedLayout(Context context, AttributeSet attrs, int defStyle) {
Winson Chung8e4ec312010-10-13 17:22:51 -070040 super(context, attrs, defStyle);
41 }
42
43 @Override
44 public boolean onTouchEvent(MotionEvent event) {
45 // We eat up the touch events here, since the PagedView (which uses the same swiping
46 // touch code as Workspace previously) uses onInterceptTouchEvent() to determine when
47 // the user is scrolling between pages. This means that if the pages themselves don't
48 // handle touch events, it gets forwarded up to PagedView itself, and it's own
49 // onTouchEvent() handling will prevent further intercept touch events from being called
50 // (it's the same view in that case). This is not ideal, but to prevent more changes,
51 // we just always mark the touch event as handled.
52 return super.onTouchEvent(event) || true;
53 }
54
55 @Override
56 protected boolean onSetAlpha(int alpha) {
57 return true;
58 }
59
60 @Override
61 public void setAlpha(float alpha) {
62 setChildrenAlpha(alpha);
63 super.setAlpha(alpha);
64 }
65
66 private void setChildrenAlpha(float alpha) {
67 final int childCount = getChildCount();
68 for (int i = 0; i < childCount; i++) {
69 getChildAt(i).setAlpha(alpha);
70 }
71 }
Michael Jurka8245a862011-02-01 17:53:59 -080072
73 @Override
74 public void removeAllViewsOnPage() {
75 removeAllViews();
76 }
77
78 @Override
79 public void removeViewOnPageAt(int index) {
80 removeViewAt(index);
81 }
82
83 @Override
84 public int getPageChildCount() {
85 return getChildCount();
86 }
87
88 @Override
89 public View getChildOnPageAt(int i) {
90 return getChildAt(i);
91 }
92
93 @Override
94 public int indexOfChildOnPage(View v) {
95 return indexOfChild(v);
96 }
Winson Chung8e4ec312010-10-13 17:22:51 -070097}