blob: 94890d8ce88bd979d1e5cc6c06deacded54b629b [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 Chung4e6a9762011-05-09 11:56:34 -070026 * The linear layout used strictly for the widget/wallpaper tab of the customization tray.
27 * To be deprecated.
Winson Chung8e4ec312010-10-13 17:22:51 -070028 */
Michael Jurka8245a862011-02-01 17:53:59 -080029public class PagedViewExtendedLayout extends LinearLayout implements Page {
Winson Chung97d85d22011-04-13 11:27:36 -070030 static final String TAG = "PagedViewExtendedLayout";
Winson Chung8e4ec312010-10-13 17:22:51 -070031
Winson Chung45e1d6e2010-11-09 17:19:49 -080032 public PagedViewExtendedLayout(Context context) {
Winson Chung8e4ec312010-10-13 17:22:51 -070033 this(context, null);
34 }
35
Winson Chung45e1d6e2010-11-09 17:19:49 -080036 public PagedViewExtendedLayout(Context context, AttributeSet attrs) {
Winson Chung8e4ec312010-10-13 17:22:51 -070037 this(context, attrs, 0);
38 }
39
Winson Chung45e1d6e2010-11-09 17:19:49 -080040 public PagedViewExtendedLayout(Context context, AttributeSet attrs, int defStyle) {
Winson Chung8e4ec312010-10-13 17:22:51 -070041 super(context, attrs, defStyle);
42 }
43
Winson Chung785d2eb2011-04-14 16:08:02 -070044 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Michael Jurkaa2eb1702011-05-12 14:57:05 -070045 if (LauncherApplication.isScreenLarge()) {
Winson Chung785d2eb2011-04-14 16:08:02 -070046 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
47 } else {
48 // PagedView currently has issues with different-sized pages since it calculates the
49 // offset of each page to scroll to before it updates the actual size of each page
50 // (which canchange depending on the content if the contains aren't a fixed size).
51 // We work around this by having a minimum size on each widget page).
52 int widthSpecSize = Math.max(getSuggestedMinimumWidth(),
53 MeasureSpec.getSize(widthMeasureSpec));
54 int widthSpecMode = MeasureSpec.AT_MOST;
55 super.onMeasure(MeasureSpec.makeMeasureSpec(widthSpecSize, widthSpecMode),
56 heightMeasureSpec);
57 }
58 }
59
Winson Chung8e4ec312010-10-13 17:22:51 -070060 @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 }
Michael Jurka8245a862011-02-01 17:53:59 -080089
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 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700114
115 public static class LayoutParams extends LinearLayout.LayoutParams {
116 public LayoutParams() {
117 super(LinearLayout.LayoutParams.WRAP_CONTENT,
118 LinearLayout.LayoutParams.MATCH_PARENT);
119 }
120 }
Winson Chung8e4ec312010-10-13 17:22:51 -0700121}