blob: 776b99faba1633cf09cd9bd598a08a186e338133 [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
Winson Chung785d2eb2011-04-14 16:08:02 -070043 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
44 if (LauncherApplication.isScreenXLarge()) {
45 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
46 } else {
47 // PagedView currently has issues with different-sized pages since it calculates the
48 // offset of each page to scroll to before it updates the actual size of each page
49 // (which canchange depending on the content if the contains aren't a fixed size).
50 // We work around this by having a minimum size on each widget page).
51 int widthSpecSize = Math.max(getSuggestedMinimumWidth(),
52 MeasureSpec.getSize(widthMeasureSpec));
53 int widthSpecMode = MeasureSpec.AT_MOST;
54 super.onMeasure(MeasureSpec.makeMeasureSpec(widthSpecSize, widthSpecMode),
55 heightMeasureSpec);
56 }
57 }
58
Winson Chung8e4ec312010-10-13 17:22:51 -070059 @Override
60 public boolean onTouchEvent(MotionEvent event) {
61 // We eat up the touch events here, since the PagedView (which uses the same swiping
62 // touch code as Workspace previously) uses onInterceptTouchEvent() to determine when
63 // the user is scrolling between pages. This means that if the pages themselves don't
64 // handle touch events, it gets forwarded up to PagedView itself, and it's own
65 // onTouchEvent() handling will prevent further intercept touch events from being called
66 // (it's the same view in that case). This is not ideal, but to prevent more changes,
67 // we just always mark the touch event as handled.
68 return super.onTouchEvent(event) || true;
69 }
70
71 @Override
72 protected boolean onSetAlpha(int alpha) {
73 return true;
74 }
75
76 @Override
77 public void setAlpha(float alpha) {
78 setChildrenAlpha(alpha);
79 super.setAlpha(alpha);
80 }
81
82 private void setChildrenAlpha(float alpha) {
83 final int childCount = getChildCount();
84 for (int i = 0; i < childCount; i++) {
85 getChildAt(i).setAlpha(alpha);
86 }
87 }
Michael Jurka8245a862011-02-01 17:53:59 -080088
89 @Override
90 public void removeAllViewsOnPage() {
91 removeAllViews();
92 }
93
94 @Override
95 public void removeViewOnPageAt(int index) {
96 removeViewAt(index);
97 }
98
99 @Override
100 public int getPageChildCount() {
101 return getChildCount();
102 }
103
104 @Override
105 public View getChildOnPageAt(int i) {
106 return getChildAt(i);
107 }
108
109 @Override
110 public int indexOfChildOnPage(View v) {
111 return indexOfChild(v);
112 }
Winson Chung785d2eb2011-04-14 16:08:02 -0700113
114 public static class LayoutParams extends LinearLayout.LayoutParams {
115 public LayoutParams() {
116 super(LinearLayout.LayoutParams.WRAP_CONTENT,
117 LinearLayout.LayoutParams.MATCH_PARENT);
118 }
119 }
Winson Chung8e4ec312010-10-13 17:22:51 -0700120}