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 | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame^] | 26 | * The linear layout used strictly for the widget/wallpaper tab of the customization tray. |
| 27 | * To be deprecated. |
Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 28 | */ |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 29 | public class PagedViewExtendedLayout extends LinearLayout implements Page { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 30 | static final String TAG = "PagedViewExtendedLayout"; |
Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 31 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 32 | public PagedViewExtendedLayout(Context context) { |
Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 33 | this(context, null); |
| 34 | } |
| 35 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 36 | public PagedViewExtendedLayout(Context context, AttributeSet attrs) { |
Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 37 | this(context, attrs, 0); |
| 38 | } |
| 39 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 40 | public PagedViewExtendedLayout(Context context, AttributeSet attrs, int defStyle) { |
Winson Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 41 | super(context, attrs, defStyle); |
| 42 | } |
| 43 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 44 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 45 | if (LauncherApplication.isScreenXLarge()) { |
| 46 | 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 Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 60 | @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 Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 89 | |
| 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 Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 114 | |
| 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 Chung | 8e4ec31 | 2010-10-13 17:22:51 -0700 | [diff] [blame] | 121 | } |