Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.launcher2; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.util.AttributeSet; |
| 21 | import android.view.MotionEvent; |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 22 | import android.view.View; |
Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 23 | import android.widget.LinearLayout; |
| 24 | |
| 25 | /** |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 26 | * The linear layout used strictly for the widget/wallpaper tab of the customization tray |
Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 27 | */ |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 28 | public class PagedViewExtendedLayout extends LinearLayout implements Page { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 29 | static final String TAG = "PagedViewExtendedLayout"; |
Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 30 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 31 | public PagedViewExtendedLayout(Context context) { |
Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 32 | this(context, null); |
| 33 | } |
| 34 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 35 | public PagedViewExtendedLayout(Context context, AttributeSet attrs) { |
Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 36 | this(context, attrs, 0); |
| 37 | } |
| 38 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 39 | public PagedViewExtendedLayout(Context context, AttributeSet attrs, int defStyle) { |
Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 40 | super(context, attrs, defStyle); |
| 41 | } |
| 42 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame^] | 43 | 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 Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 59 | @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 Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 88 | |
| 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 Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame^] | 113 | |
| 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 Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 120 | } |