Workspace.java revision 2bc6b7c2b8b651dde0a65c64c127f5b85c1290d2
1/* 2 * Copyright (C) 2008 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.app.WallpaperManager; 20import android.content.Context; 21import android.content.Intent; 22import android.content.ComponentName; 23import android.content.res.TypedArray; 24import android.content.pm.PackageManager; 25import android.graphics.Canvas; 26import android.graphics.RectF; 27import android.graphics.Rect; 28import android.graphics.drawable.Drawable; 29import android.util.AttributeSet; 30import android.view.MotionEvent; 31import android.view.VelocityTracker; 32import android.view.View; 33import android.view.ViewConfiguration; 34import android.view.ViewGroup; 35import android.view.ViewParent; 36import android.widget.Scroller; 37import android.widget.TextView; 38import android.os.Parcelable; 39import android.os.Parcel; 40 41import java.util.ArrayList; 42 43/** 44 * The workspace is a wide area with a wallpaper and a finite number of screens. Each 45 * screen contains a number of icons, folders or widgets the user can interact with. 46 * A workspace is meant to be used with a fixed width only. 47 */ 48public class Workspace extends ViewGroup implements DropTarget, DragSource, DragScroller { 49 private static final String TAG = "Launcher.Workspace"; 50 private static final int INVALID_SCREEN = -1; 51 52 /** 53 * The velocity at which a fling gesture will cause us to snap to the next screen 54 */ 55 private static final int SNAP_VELOCITY = 1000; 56 57 private final WallpaperManager mWallpaperManager; 58 59 private int mDefaultScreen; 60 61 private boolean mFirstLayout = true; 62 63 private int mCurrentScreen; 64 private int mNextScreen = INVALID_SCREEN; 65 private Scroller mScroller; 66 private VelocityTracker mVelocityTracker; 67 68 /** 69 * CellInfo for the cell that is currently being dragged 70 */ 71 private CellLayout.CellInfo mDragInfo; 72 73 /** 74 * Target drop area calculated during last acceptDrop call. 75 */ 76 private int[] mTargetCell = null; 77 78 private float mLastMotionX; 79 private float mLastMotionY; 80 81 private final static int TOUCH_STATE_REST = 0; 82 private final static int TOUCH_STATE_SCROLLING = 1; 83 84 private int mTouchState = TOUCH_STATE_REST; 85 86 private OnLongClickListener mLongClickListener; 87 88 private Launcher mLauncher; 89 private DragController mDragController; 90 91 /** 92 * Cache of vacant cells, used during drag events and invalidated as needed. 93 */ 94 private CellLayout.CellInfo mVacantCache = null; 95 96 private int[] mTempCell = new int[2]; 97 private int[] mTempEstimate = new int[2]; 98 99 private boolean mAllowLongPress = true; 100 101 private int mTouchSlop; 102 private int mMaximumVelocity; 103 104 final Rect mDrawerBounds = new Rect(); 105 final Rect mClipBounds = new Rect(); 106 int mDrawerContentHeight; 107 int mDrawerContentWidth; 108 109 /** 110 * Used to inflate the Workspace from XML. 111 * 112 * @param context The application's context. 113 * @param attrs The attribtues set containing the Workspace's customization values. 114 */ 115 public Workspace(Context context, AttributeSet attrs) { 116 this(context, attrs, 0); 117 } 118 119 /** 120 * Used to inflate the Workspace from XML. 121 * 122 * @param context The application's context. 123 * @param attrs The attribtues set containing the Workspace's customization values. 124 * @param defStyle Unused. 125 */ 126 public Workspace(Context context, AttributeSet attrs, int defStyle) { 127 super(context, attrs, defStyle); 128 129 mWallpaperManager = WallpaperManager.getInstance(context); 130 131 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0); 132 mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 1); 133 a.recycle(); 134 135 initWorkspace(); 136 } 137 138 /** 139 * Initializes various states for this workspace. 140 */ 141 private void initWorkspace() { 142 mScroller = new Scroller(getContext()); 143 mCurrentScreen = mDefaultScreen; 144 Launcher.setScreen(mCurrentScreen); 145 146 final ViewConfiguration configuration = ViewConfiguration.get(getContext()); 147 mTouchSlop = configuration.getScaledTouchSlop(); 148 mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); 149 } 150 151 @Override 152 public void addView(View child, int index, LayoutParams params) { 153 if (!(child instanceof CellLayout)) { 154 throw new IllegalArgumentException("A Workspace can only have CellLayout children."); 155 } 156 super.addView(child, index, params); 157 } 158 159 @Override 160 public void addView(View child) { 161 if (!(child instanceof CellLayout)) { 162 throw new IllegalArgumentException("A Workspace can only have CellLayout children."); 163 } 164 super.addView(child); 165 } 166 167 @Override 168 public void addView(View child, int index) { 169 if (!(child instanceof CellLayout)) { 170 throw new IllegalArgumentException("A Workspace can only have CellLayout children."); 171 } 172 super.addView(child, index); 173 } 174 175 @Override 176 public void addView(View child, int width, int height) { 177 if (!(child instanceof CellLayout)) { 178 throw new IllegalArgumentException("A Workspace can only have CellLayout children."); 179 } 180 super.addView(child, width, height); 181 } 182 183 @Override 184 public void addView(View child, LayoutParams params) { 185 if (!(child instanceof CellLayout)) { 186 throw new IllegalArgumentException("A Workspace can only have CellLayout children."); 187 } 188 super.addView(child, params); 189 } 190 191 /** 192 * @return The open folder on the current screen, or null if there is none 193 */ 194 Folder getOpenFolder() { 195 CellLayout currentScreen = (CellLayout) getChildAt(mCurrentScreen); 196 int count = currentScreen.getChildCount(); 197 for (int i = 0; i < count; i++) { 198 View child = currentScreen.getChildAt(i); 199 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); 200 if (lp.cellHSpan == 4 && lp.cellVSpan == 4 && child instanceof Folder) { 201 return (Folder) child; 202 } 203 } 204 return null; 205 } 206 207 ArrayList<Folder> getOpenFolders() { 208 final int screens = getChildCount(); 209 ArrayList<Folder> folders = new ArrayList<Folder>(screens); 210 211 for (int screen = 0; screen < screens; screen++) { 212 CellLayout currentScreen = (CellLayout) getChildAt(screen); 213 int count = currentScreen.getChildCount(); 214 for (int i = 0; i < count; i++) { 215 View child = currentScreen.getChildAt(i); 216 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); 217 if (lp.cellHSpan == 4 && lp.cellVSpan == 4 && child instanceof Folder) { 218 folders.add((Folder) child); 219 break; 220 } 221 } 222 } 223 224 return folders; 225 } 226 227 boolean isDefaultScreenShowing() { 228 return mCurrentScreen == mDefaultScreen; 229 } 230 231 /** 232 * Returns the index of the currently displayed screen. 233 * 234 * @return The index of the currently displayed screen. 235 */ 236 int getCurrentScreen() { 237 return mCurrentScreen; 238 } 239 240 /** 241 * Returns how many screens there are. 242 */ 243 int getScreenCount() { 244 return getChildCount(); 245 } 246 247 /** 248 * Computes a bounding rectangle for a range of cells 249 * 250 * @param cellX X coordinate of upper left corner expressed as a cell position 251 * @param cellY Y coordinate of upper left corner expressed as a cell position 252 * @param cellHSpan Width in cells 253 * @param cellVSpan Height in cells 254 * @param rect Rectnagle into which to put the results 255 */ 256 public void cellToRect(int cellX, int cellY, int cellHSpan, int cellVSpan, RectF rect) { 257 ((CellLayout)getChildAt(mCurrentScreen)).cellToRect(cellX, cellY, 258 cellHSpan, cellVSpan, rect); 259 } 260 261 /** 262 * Sets the current screen. 263 * 264 * @param currentScreen 265 */ 266 void setCurrentScreen(int currentScreen) { 267 clearVacantCache(); 268 mCurrentScreen = Math.max(0, Math.min(currentScreen, getChildCount() - 1)); 269 scrollTo(mCurrentScreen * getWidth(), 0); 270 invalidate(); 271 } 272 273 /** 274 * Adds the specified child in the current screen. The position and dimension of 275 * the child are defined by x, y, spanX and spanY. 276 * 277 * @param child The child to add in one of the workspace's screens. 278 * @param x The X position of the child in the screen's grid. 279 * @param y The Y position of the child in the screen's grid. 280 * @param spanX The number of cells spanned horizontally by the child. 281 * @param spanY The number of cells spanned vertically by the child. 282 */ 283 void addInCurrentScreen(View child, int x, int y, int spanX, int spanY) { 284 addInScreen(child, mCurrentScreen, x, y, spanX, spanY, false); 285 } 286 287 /** 288 * Adds the specified child in the current screen. The position and dimension of 289 * the child are defined by x, y, spanX and spanY. 290 * 291 * @param child The child to add in one of the workspace's screens. 292 * @param x The X position of the child in the screen's grid. 293 * @param y The Y position of the child in the screen's grid. 294 * @param spanX The number of cells spanned horizontally by the child. 295 * @param spanY The number of cells spanned vertically by the child. 296 * @param insert When true, the child is inserted at the beginning of the children list. 297 */ 298 void addInCurrentScreen(View child, int x, int y, int spanX, int spanY, boolean insert) { 299 addInScreen(child, mCurrentScreen, x, y, spanX, spanY, insert); 300 } 301 302 /** 303 * Adds the specified child in the specified screen. The position and dimension of 304 * the child are defined by x, y, spanX and spanY. 305 * 306 * @param child The child to add in one of the workspace's screens. 307 * @param screen The screen in which to add the child. 308 * @param x The X position of the child in the screen's grid. 309 * @param y The Y position of the child in the screen's grid. 310 * @param spanX The number of cells spanned horizontally by the child. 311 * @param spanY The number of cells spanned vertically by the child. 312 */ 313 void addInScreen(View child, int screen, int x, int y, int spanX, int spanY) { 314 addInScreen(child, screen, x, y, spanX, spanY, false); 315 } 316 317 /** 318 * Adds the specified child in the specified screen. The position and dimension of 319 * the child are defined by x, y, spanX and spanY. 320 * 321 * @param child The child to add in one of the workspace's screens. 322 * @param screen The screen in which to add the child. 323 * @param x The X position of the child in the screen's grid. 324 * @param y The Y position of the child in the screen's grid. 325 * @param spanX The number of cells spanned horizontally by the child. 326 * @param spanY The number of cells spanned vertically by the child. 327 * @param insert When true, the child is inserted at the beginning of the children list. 328 */ 329 void addInScreen(View child, int screen, int x, int y, int spanX, int spanY, boolean insert) { 330 if (screen < 0 || screen >= getChildCount()) { 331 throw new IllegalStateException("The screen must be >= 0 and < " + getChildCount()); 332 } 333 334 clearVacantCache(); 335 336 final CellLayout group = (CellLayout) getChildAt(screen); 337 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); 338 if (lp == null) { 339 lp = new CellLayout.LayoutParams(x, y, spanX, spanY); 340 } else { 341 lp.cellX = x; 342 lp.cellY = y; 343 lp.cellHSpan = spanX; 344 lp.cellVSpan = spanY; 345 } 346 group.addView(child, insert ? 0 : -1, lp); 347 if (!(child instanceof Folder)) { 348 child.setOnLongClickListener(mLongClickListener); 349 } 350 if (child instanceof DropTarget) { 351 mDragController.addDropTarget((DropTarget)child); 352 } 353 } 354 355 void addWidget(View view, Widget widget) { 356 addInScreen(view, widget.screen, widget.cellX, widget.cellY, widget.spanX, 357 widget.spanY, false); 358 } 359 360 void addWidget(View view, Widget widget, boolean insert) { 361 addInScreen(view, widget.screen, widget.cellX, widget.cellY, widget.spanX, 362 widget.spanY, insert); 363 } 364 365 CellLayout.CellInfo findAllVacantCells(boolean[] occupied) { 366 CellLayout group = (CellLayout) getChildAt(mCurrentScreen); 367 if (group != null) { 368 return group.findAllVacantCells(occupied, null); 369 } 370 return null; 371 } 372 373 private void clearVacantCache() { 374 if (mVacantCache != null) { 375 mVacantCache.clearVacantCells(); 376 mVacantCache = null; 377 } 378 } 379 380 /** 381 * Returns the coordinate of a vacant cell for the current screen. 382 */ 383 boolean getVacantCell(int[] vacant, int spanX, int spanY) { 384 CellLayout group = (CellLayout) getChildAt(mCurrentScreen); 385 if (group != null) { 386 return group.getVacantCell(vacant, spanX, spanY); 387 } 388 return false; 389 } 390 391 /** 392 * Adds the specified child in the current screen. The position and dimension of 393 * the child are defined by x, y, spanX and spanY. 394 * 395 * @param child The child to add in one of the workspace's screens. 396 * @param spanX The number of cells spanned horizontally by the child. 397 * @param spanY The number of cells spanned vertically by the child. 398 */ 399 void fitInCurrentScreen(View child, int spanX, int spanY) { 400 fitInScreen(child, mCurrentScreen, spanX, spanY); 401 } 402 403 /** 404 * Adds the specified child in the specified screen. The position and dimension of 405 * the child are defined by x, y, spanX and spanY. 406 * 407 * @param child The child to add in one of the workspace's screens. 408 * @param screen The screen in which to add the child. 409 * @param spanX The number of cells spanned horizontally by the child. 410 * @param spanY The number of cells spanned vertically by the child. 411 */ 412 void fitInScreen(View child, int screen, int spanX, int spanY) { 413 if (screen < 0 || screen >= getChildCount()) { 414 throw new IllegalStateException("The screen must be >= 0 and < " + getChildCount()); 415 } 416 417 final CellLayout group = (CellLayout) getChildAt(screen); 418 boolean vacant = group.getVacantCell(mTempCell, spanX, spanY); 419 if (vacant) { 420 group.addView(child, 421 new CellLayout.LayoutParams(mTempCell[0], mTempCell[1], spanX, spanY)); 422 child.setOnLongClickListener(mLongClickListener); 423 if (!(child instanceof Folder)) { 424 child.setOnLongClickListener(mLongClickListener); 425 } 426 if (child instanceof DropTarget) { 427 mDragController.addDropTarget((DropTarget)child); 428 } 429 } 430 } 431 432 /** 433 * Registers the specified listener on each screen contained in this workspace. 434 * 435 * @param l The listener used to respond to long clicks. 436 */ 437 @Override 438 public void setOnLongClickListener(OnLongClickListener l) { 439 mLongClickListener = l; 440 final int count = getChildCount(); 441 for (int i = 0; i < count; i++) { 442 getChildAt(i).setOnLongClickListener(l); 443 } 444 } 445 446 private void updateWallpaperOffset() { 447 updateWallpaperOffset(getChildAt(getChildCount() - 1).getRight() - (mRight - mLeft)); 448 } 449 450 private void updateWallpaperOffset(int scrollRange) { 451 mWallpaperManager.setWallpaperOffsets(getWindowToken(), mScrollX / (float) scrollRange, 0); 452 } 453 454 @Override 455 public void computeScroll() { 456 if (mScroller.computeScrollOffset()) { 457 mScrollX = mScroller.getCurrX(); 458 mScrollY = mScroller.getCurrY(); 459 updateWallpaperOffset(); 460 postInvalidate(); 461 } else if (mNextScreen != INVALID_SCREEN) { 462 mCurrentScreen = Math.max(0, Math.min(mNextScreen, getChildCount() - 1)); 463 Launcher.setScreen(mCurrentScreen); 464 mNextScreen = INVALID_SCREEN; 465 clearChildrenCache(); 466 } 467 } 468 469 @Override 470 protected void dispatchDraw(Canvas canvas) { 471 boolean restore = false; 472 int restoreCount = 0; 473 474 // For the fade. If view gets setAlpha(), use that instead. 475 float scale = mScale; 476 if (scale < 0.999f) { 477 int sx = mScrollX; 478 479 int alpha = (scale < 0.5f) ? (int)(255 * 2 * scale) : 255; 480 481 restoreCount = canvas.saveLayerAlpha(sx, 0, sx+getWidth(), getHeight(), alpha, 482 Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); 483 restore = true; 484 485 if (scale < 0.999f) { 486 int w = getWidth(); 487 w += 2 * mCurrentScreen * w; 488 int dx = w/2; 489 int h = getHeight(); 490 int dy = (h/2) - (h/4); 491 canvas.translate(dx, dy); 492 canvas.scale(scale, scale); 493 canvas.translate(-dx, -dy); 494 } 495 } 496 497 // ViewGroup.dispatchDraw() supports many features we don't need: 498 // clip to padding, layout animation, animation listener, disappearing 499 // children, etc. The following implementation attempts to fast-track 500 // the drawing dispatch by drawing only what we know needs to be drawn. 501 502 boolean fastDraw = mTouchState != TOUCH_STATE_SCROLLING && mNextScreen == INVALID_SCREEN 503 && scale > 0.999f; 504 // If we are not scrolling or flinging, draw only the current screen 505 if (fastDraw) { 506 drawChild(canvas, getChildAt(mCurrentScreen), getDrawingTime()); 507 } else { 508 final long drawingTime = getDrawingTime(); 509 // If we are flinging, draw only the current screen and the target screen 510 if (mNextScreen >= 0 && mNextScreen < getChildCount() && 511 Math.abs(mCurrentScreen - mNextScreen) == 1) { 512 drawChild(canvas, getChildAt(mCurrentScreen), drawingTime); 513 drawChild(canvas, getChildAt(mNextScreen), drawingTime); 514 } else { 515 // If we are scrolling, draw all of our children 516 final int count = getChildCount(); 517 for (int i = 0; i < count; i++) { 518 drawChild(canvas, getChildAt(i), drawingTime); 519 } 520 } 521 } 522 523 if (restore) { 524 canvas.restoreToCount(restoreCount); 525 } 526 } 527 528 private float mScale = 1.0f; 529 public void setScale(float scale) { 530 mScale = scale; 531 invalidate(); 532 } 533 534 protected void onAttachedToWindow() { 535 super.onAttachedToWindow(); 536 mDragController.setWindowToken(getWindowToken()); 537 } 538 539 @Override 540 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 541 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 542 543 final int width = MeasureSpec.getSize(widthMeasureSpec); 544 final int widthMode = MeasureSpec.getMode(widthMeasureSpec); 545 if (widthMode != MeasureSpec.EXACTLY) { 546 throw new IllegalStateException("Workspace can only be used in EXACTLY mode."); 547 } 548 549 final int heightMode = MeasureSpec.getMode(heightMeasureSpec); 550 if (heightMode != MeasureSpec.EXACTLY) { 551 throw new IllegalStateException("Workspace can only be used in EXACTLY mode."); 552 } 553 554 // The children are given the same width and height as the workspace 555 final int count = getChildCount(); 556 for (int i = 0; i < count; i++) { 557 getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec); 558 } 559 560 if (mFirstLayout) { 561 scrollTo(mCurrentScreen * width, 0); 562 updateWallpaperOffset(width * (getChildCount() - 1)); 563 mFirstLayout = false; 564 } 565 } 566 567 @Override 568 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 569 int childLeft = 0; 570 571 final int count = getChildCount(); 572 for (int i = 0; i < count; i++) { 573 final View child = getChildAt(i); 574 if (child.getVisibility() != View.GONE) { 575 final int childWidth = child.getMeasuredWidth(); 576 child.layout(childLeft, 0, childLeft + childWidth, child.getMeasuredHeight()); 577 childLeft += childWidth; 578 } 579 } 580 } 581 582 @Override 583 public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { 584 int screen = indexOfChild(child); 585 if (screen != mCurrentScreen || !mScroller.isFinished()) { 586 if (!mLauncher.isWorkspaceLocked()) { 587 snapToScreen(screen); 588 } 589 return true; 590 } 591 return false; 592 } 593 594 @Override 595 protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { 596 if (!mLauncher.isAllAppsVisible()) { 597 final Folder openFolder = getOpenFolder(); 598 if (openFolder != null) { 599 return openFolder.requestFocus(direction, previouslyFocusedRect); 600 } else { 601 int focusableScreen; 602 if (mNextScreen != INVALID_SCREEN) { 603 focusableScreen = mNextScreen; 604 } else { 605 focusableScreen = mCurrentScreen; 606 } 607 getChildAt(focusableScreen).requestFocus(direction, previouslyFocusedRect); 608 } 609 } 610 return false; 611 } 612 613 @Override 614 public boolean dispatchUnhandledMove(View focused, int direction) { 615 if (direction == View.FOCUS_LEFT) { 616 if (getCurrentScreen() > 0) { 617 snapToScreen(getCurrentScreen() - 1); 618 return true; 619 } 620 } else if (direction == View.FOCUS_RIGHT) { 621 if (getCurrentScreen() < getChildCount() - 1) { 622 snapToScreen(getCurrentScreen() + 1); 623 return true; 624 } 625 } 626 return super.dispatchUnhandledMove(focused, direction); 627 } 628 629 @Override 630 public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { 631 if (!mLauncher.isAllAppsVisible()) { 632 final Folder openFolder = getOpenFolder(); 633 if (openFolder == null) { 634 getChildAt(mCurrentScreen).addFocusables(views, direction); 635 if (direction == View.FOCUS_LEFT) { 636 if (mCurrentScreen > 0) { 637 getChildAt(mCurrentScreen - 1).addFocusables(views, direction); 638 } 639 } else if (direction == View.FOCUS_RIGHT){ 640 if (mCurrentScreen < getChildCount() - 1) { 641 getChildAt(mCurrentScreen + 1).addFocusables(views, direction); 642 } 643 } 644 } else { 645 openFolder.addFocusables(views, direction); 646 } 647 } 648 } 649 650 @Override 651 public boolean dispatchTouchEvent(MotionEvent ev) { 652 if (ev.getAction() == MotionEvent.ACTION_DOWN) { 653 if (mLauncher.isWorkspaceLocked() || mLauncher.isAllAppsVisible()) { 654 return false; 655 } 656 } 657 return super.dispatchTouchEvent(ev); 658 } 659 660 @Override 661 public boolean onInterceptTouchEvent(MotionEvent ev) { 662 if (mLauncher.isWorkspaceLocked() || mLauncher.isAllAppsVisible()) { 663 return false; // We don't want the events. Let them fall through to the all apps view. 664 } 665 666 /* 667 * This method JUST determines whether we want to intercept the motion. 668 * If we return true, onTouchEvent will be called and we do the actual 669 * scrolling there. 670 */ 671 672 /* 673 * Shortcut the most recurring case: the user is in the dragging 674 * state and he is moving his finger. We want to intercept this 675 * motion. 676 */ 677 final int action = ev.getAction(); 678 if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) { 679 return true; 680 } 681 682 final float x = ev.getX(); 683 final float y = ev.getY(); 684 685 switch (action) { 686 case MotionEvent.ACTION_MOVE: 687 /* 688 * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check 689 * whether the user has moved far enough from his original down touch. 690 */ 691 692 /* 693 * Locally do absolute value. mLastMotionX is set to the y value 694 * of the down event. 695 */ 696 final int xDiff = (int) Math.abs(x - mLastMotionX); 697 final int yDiff = (int) Math.abs(y - mLastMotionY); 698 699 final int touchSlop = mTouchSlop; 700 boolean xMoved = xDiff > touchSlop; 701 boolean yMoved = yDiff > touchSlop; 702 703 if (xMoved || yMoved) { 704 705 if (xMoved) { 706 // Scroll if the user moved far enough along the X axis 707 mTouchState = TOUCH_STATE_SCROLLING; 708 enableChildrenCache(); 709 } 710 // Either way, cancel any pending longpress 711 if (mAllowLongPress) { 712 mAllowLongPress = false; 713 // Try canceling the long press. It could also have been scheduled 714 // by a distant descendant, so use the mAllowLongPress flag to block 715 // everything 716 final View currentScreen = getChildAt(mCurrentScreen); 717 currentScreen.cancelLongPress(); 718 } 719 } 720 break; 721 722 case MotionEvent.ACTION_DOWN: 723 // Remember location of down touch 724 mLastMotionX = x; 725 mLastMotionY = y; 726 mAllowLongPress = true; 727 728 /* 729 * If being flinged and user touches the screen, initiate drag; 730 * otherwise don't. mScroller.isFinished should be false when 731 * being flinged. 732 */ 733 mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING; 734 break; 735 736 case MotionEvent.ACTION_CANCEL: 737 case MotionEvent.ACTION_UP: 738 // Release the drag 739 clearChildrenCache(); 740 mTouchState = TOUCH_STATE_REST; 741 mAllowLongPress = false; 742 break; 743 } 744 745 /* 746 * The only time we want to intercept motion events is if we are in the 747 * drag mode. 748 */ 749 return mTouchState != TOUCH_STATE_REST; 750 } 751 752 void enableChildrenCache() { 753 final int count = getChildCount(); 754 for (int i = 0; i < count; i++) { 755 final CellLayout layout = (CellLayout) getChildAt(i); 756 layout.setChildrenDrawnWithCacheEnabled(true); 757 layout.setChildrenDrawingCacheEnabled(true); 758 } 759 } 760 761 void clearChildrenCache() { 762 final int count = getChildCount(); 763 for (int i = 0; i < count; i++) { 764 final CellLayout layout = (CellLayout) getChildAt(i); 765 layout.setChildrenDrawnWithCacheEnabled(false); 766 } 767 } 768 769 @Override 770 public boolean onTouchEvent(MotionEvent ev) { 771 772 if (mLauncher.isWorkspaceLocked()) { 773 return false; // We don't want the events. Let them fall through to the all apps view. 774 } 775 if (mLauncher.isAllAppsVisible()) { 776 // Cancel any scrolling that is in progress. 777 if (!mScroller.isFinished()) { 778 mScroller.abortAnimation(); 779 } 780 snapToScreen(mCurrentScreen); 781 return false; // We don't want the events. Let them fall through to the all apps view. 782 } 783 784 if (mVelocityTracker == null) { 785 mVelocityTracker = VelocityTracker.obtain(); 786 } 787 mVelocityTracker.addMovement(ev); 788 789 final int action = ev.getAction(); 790 final float x = ev.getX(); 791 792 switch (action) { 793 case MotionEvent.ACTION_DOWN: 794 /* 795 * If being flinged and user touches, stop the fling. isFinished 796 * will be false if being flinged. 797 */ 798 if (!mScroller.isFinished()) { 799 mScroller.abortAnimation(); 800 } 801 802 // Remember where the motion event started 803 mLastMotionX = x; 804 break; 805 case MotionEvent.ACTION_MOVE: 806 if (mTouchState == TOUCH_STATE_SCROLLING) { 807 // Scroll to follow the motion event 808 final int deltaX = (int) (mLastMotionX - x); 809 mLastMotionX = x; 810 811 if (deltaX < 0) { 812 if (mScrollX > 0) { 813 scrollBy(Math.max(-mScrollX, deltaX), 0); 814 updateWallpaperOffset(); 815 } 816 } else if (deltaX > 0) { 817 final int availableToScroll = getChildAt(getChildCount() - 1).getRight() - 818 mScrollX - getWidth(); 819 if (availableToScroll > 0) { 820 scrollBy(Math.min(availableToScroll, deltaX), 0); 821 updateWallpaperOffset(); 822 } 823 } 824 } 825 break; 826 case MotionEvent.ACTION_UP: 827 if (mTouchState == TOUCH_STATE_SCROLLING) { 828 final VelocityTracker velocityTracker = mVelocityTracker; 829 velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); 830 int velocityX = (int) velocityTracker.getXVelocity(); 831 832 if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) { 833 // Fling hard enough to move left 834 snapToScreen(mCurrentScreen - 1); 835 } else if (velocityX < -SNAP_VELOCITY && mCurrentScreen < getChildCount() - 1) { 836 // Fling hard enough to move right 837 snapToScreen(mCurrentScreen + 1); 838 } else { 839 snapToDestination(); 840 } 841 842 if (mVelocityTracker != null) { 843 mVelocityTracker.recycle(); 844 mVelocityTracker = null; 845 } 846 } 847 mTouchState = TOUCH_STATE_REST; 848 break; 849 case MotionEvent.ACTION_CANCEL: 850 mTouchState = TOUCH_STATE_REST; 851 } 852 853 return true; 854 } 855 856 private void snapToDestination() { 857 final int screenWidth = getWidth(); 858 final int whichScreen = (mScrollX + (screenWidth / 2)) / screenWidth; 859 860 snapToScreen(whichScreen); 861 } 862 863 void snapToScreen(int whichScreen) { 864 if (!mScroller.isFinished()) return; 865 866 clearVacantCache(); 867 enableChildrenCache(); 868 869 whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1)); 870 boolean changingScreens = whichScreen != mCurrentScreen; 871 872 mNextScreen = whichScreen; 873 874 View focusedChild = getFocusedChild(); 875 if (focusedChild != null && changingScreens && focusedChild == getChildAt(mCurrentScreen)) { 876 focusedChild.clearFocus(); 877 } 878 879 final int newX = whichScreen * getWidth(); 880 final int delta = newX - mScrollX; 881 mScroller.startScroll(mScrollX, 0, delta, 0, Math.abs(delta) * 2); 882 invalidate(); 883 } 884 885 void startDrag(CellLayout.CellInfo cellInfo) { 886 View child = cellInfo.cell; 887 888 // Make sure the drag was started by a long press as opposed to a long click. 889 // Note that Search takes focus when clicked rather than entering touch mode 890 if (!child.isInTouchMode() && !(child instanceof Search)) { 891 return; 892 } 893 894 mDragInfo = cellInfo; 895 mDragInfo.screen = mCurrentScreen; 896 897 CellLayout current = ((CellLayout) getChildAt(mCurrentScreen)); 898 899 current.onDragChild(child); 900 mDragController.startDrag(child, this, child.getTag(), DragController.DRAG_ACTION_MOVE); 901 invalidate(); 902 } 903 904 @Override 905 protected Parcelable onSaveInstanceState() { 906 final SavedState state = new SavedState(super.onSaveInstanceState()); 907 state.currentScreen = mCurrentScreen; 908 return state; 909 } 910 911 @Override 912 protected void onRestoreInstanceState(Parcelable state) { 913 SavedState savedState = (SavedState) state; 914 super.onRestoreInstanceState(savedState.getSuperState()); 915 if (savedState.currentScreen != -1) { 916 mCurrentScreen = savedState.currentScreen; 917 Launcher.setScreen(mCurrentScreen); 918 } 919 } 920 921 void addApplicationShortcut(ApplicationInfo info, CellLayout.CellInfo cellInfo) { 922 addApplicationShortcut(info, cellInfo, false); 923 } 924 925 void addApplicationShortcut(ApplicationInfo info, CellLayout.CellInfo cellInfo, 926 boolean insertAtFirst) { 927 final CellLayout layout = (CellLayout) getChildAt(cellInfo.screen); 928 final int[] result = new int[2]; 929 930 layout.cellToPoint(cellInfo.cellX, cellInfo.cellY, result); 931 onDropExternal(result[0], result[1], info, layout, insertAtFirst); 932 } 933 934 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, 935 DragView dragView, Object dragInfo) { 936 final CellLayout cellLayout = getCurrentDropLayout(); 937 if (source != this) { 938 onDropExternal(x - xOffset, y - yOffset, dragInfo, cellLayout); 939 } else { 940 // Move internally 941 if (mDragInfo != null) { 942 final View cell = mDragInfo.cell; 943 int index = mScroller.isFinished() ? mCurrentScreen : mNextScreen; 944 if (index != mDragInfo.screen) { 945 final CellLayout originalCellLayout = (CellLayout) getChildAt(mDragInfo.screen); 946 originalCellLayout.removeView(cell); 947 cellLayout.addView(cell); 948 } 949 mTargetCell = estimateDropCell(x - xOffset, y - yOffset, 950 mDragInfo.spanX, mDragInfo.spanY, cell, cellLayout, mTargetCell); 951 cellLayout.onDropChild(cell, mTargetCell); 952 953 final ItemInfo info = (ItemInfo)cell.getTag(); 954 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams(); 955 LauncherModel.moveItemInDatabase(mLauncher, info, 956 LauncherSettings.Favorites.CONTAINER_DESKTOP, index, lp.cellX, lp.cellY); 957 } 958 } 959 } 960 961 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, 962 DragView dragView, Object dragInfo) { 963 clearVacantCache(); 964 } 965 966 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, 967 DragView dragView, Object dragInfo) { 968 } 969 970 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, 971 DragView dragView, Object dragInfo) { 972 clearVacantCache(); 973 } 974 975 private void onDropExternal(int x, int y, Object dragInfo, CellLayout cellLayout) { 976 onDropExternal(x, y, dragInfo, cellLayout, false); 977 } 978 979 private void onDropExternal(int x, int y, Object dragInfo, CellLayout cellLayout, 980 boolean insertAtFirst) { 981 // Drag from somewhere else 982 ItemInfo info = (ItemInfo) dragInfo; 983 984 View view; 985 986 switch (info.itemType) { 987 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: 988 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: 989 if (info.container == NO_ID) { 990 // Came from all apps -- make a copy 991 info = new ApplicationInfo((ApplicationInfo) info); 992 } 993 view = mLauncher.createShortcut(R.layout.application, cellLayout, 994 (ApplicationInfo) info); 995 break; 996 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: 997 view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher, 998 (ViewGroup) getChildAt(mCurrentScreen), ((UserFolderInfo) info)); 999 break; 1000 default: 1001 throw new IllegalStateException("Unknown item type: " + info.itemType); 1002 } 1003 1004 cellLayout.addView(view, insertAtFirst ? 0 : -1); 1005 view.setOnLongClickListener(mLongClickListener); 1006 if (view instanceof DropTarget) { 1007 mDragController.addDropTarget((DropTarget) view); 1008 } 1009 1010 mTargetCell = estimateDropCell(x, y, 1, 1, view, cellLayout, mTargetCell); 1011 cellLayout.onDropChild(view, mTargetCell); 1012 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams(); 1013 1014 LauncherModel.addOrMoveItemInDatabase(mLauncher, info, 1015 LauncherSettings.Favorites.CONTAINER_DESKTOP, mCurrentScreen, lp.cellX, lp.cellY); 1016 } 1017 1018 /** 1019 * Return the current {@link CellLayout}, correctly picking the destination 1020 * screen while a scroll is in progress. 1021 */ 1022 private CellLayout getCurrentDropLayout() { 1023 int index = mScroller.isFinished() ? mCurrentScreen : mNextScreen; 1024 return (CellLayout) getChildAt(index); 1025 } 1026 1027 /** 1028 * {@inheritDoc} 1029 */ 1030 public boolean acceptDrop(DragSource source, int x, int y, 1031 int xOffset, int yOffset, DragView dragView, Object dragInfo) { 1032 final CellLayout layout = getCurrentDropLayout(); 1033 final CellLayout.CellInfo cellInfo = mDragInfo; 1034 final int spanX = cellInfo == null ? 1 : cellInfo.spanX; 1035 final int spanY = cellInfo == null ? 1 : cellInfo.spanY; 1036 1037 if (mVacantCache == null) { 1038 final View ignoreView = cellInfo == null ? null : cellInfo.cell; 1039 mVacantCache = layout.findAllVacantCells(null, ignoreView); 1040 } 1041 1042 return mVacantCache.findCellForSpan(mTempEstimate, spanX, spanY, false); 1043 } 1044 1045 /** 1046 * {@inheritDoc} 1047 */ 1048 public Rect estimateDropLocation(DragSource source, int x, int y, 1049 int xOffset, int yOffset, DragView dragView, Object dragInfo, Rect recycle) { 1050 final CellLayout layout = getCurrentDropLayout(); 1051 1052 final CellLayout.CellInfo cellInfo = mDragInfo; 1053 final int spanX = cellInfo == null ? 1 : cellInfo.spanX; 1054 final int spanY = cellInfo == null ? 1 : cellInfo.spanY; 1055 final View ignoreView = cellInfo == null ? null : cellInfo.cell; 1056 1057 final Rect location = recycle != null ? recycle : new Rect(); 1058 1059 // Find drop cell and convert into rectangle 1060 int[] dropCell = estimateDropCell(x - xOffset, y - yOffset, 1061 spanX, spanY, ignoreView, layout, mTempCell); 1062 1063 if (dropCell == null) { 1064 return null; 1065 } 1066 1067 layout.cellToPoint(dropCell[0], dropCell[1], mTempEstimate); 1068 location.left = mTempEstimate[0]; 1069 location.top = mTempEstimate[1]; 1070 1071 layout.cellToPoint(dropCell[0] + spanX, dropCell[1] + spanY, mTempEstimate); 1072 location.right = mTempEstimate[0]; 1073 location.bottom = mTempEstimate[1]; 1074 1075 return location; 1076 } 1077 1078 /** 1079 * Calculate the nearest cell where the given object would be dropped. 1080 */ 1081 private int[] estimateDropCell(int pixelX, int pixelY, 1082 int spanX, int spanY, View ignoreView, CellLayout layout, int[] recycle) { 1083 // Create vacant cell cache if none exists 1084 if (mVacantCache == null) { 1085 mVacantCache = layout.findAllVacantCells(null, ignoreView); 1086 } 1087 1088 // Find the best target drop location 1089 return layout.findNearestVacantArea(pixelX, pixelY, 1090 spanX, spanY, mVacantCache, recycle); 1091 } 1092 1093 void setLauncher(Launcher launcher) { 1094 mLauncher = launcher; 1095 } 1096 1097 public void setDragController(DragController dragController) { 1098 mDragController = dragController; 1099 } 1100 1101 public void onDropCompleted(View target, boolean success) { 1102 clearVacantCache(); 1103 1104 if (success){ 1105 if (target != this && mDragInfo != null) { 1106 final CellLayout cellLayout = (CellLayout) getChildAt(mDragInfo.screen); 1107 cellLayout.removeView(mDragInfo.cell); 1108 if (mDragInfo.cell instanceof DropTarget) { 1109 mDragController.removeDropTarget((DropTarget)mDragInfo.cell); 1110 } 1111 //final Object tag = mDragInfo.cell.getTag(); 1112 } 1113 } else { 1114 if (mDragInfo != null) { 1115 final CellLayout cellLayout = (CellLayout) getChildAt(mDragInfo.screen); 1116 cellLayout.onDropAborted(mDragInfo.cell); 1117 } 1118 } 1119 1120 mDragInfo = null; 1121 } 1122 1123 public void scrollLeft() { 1124 clearVacantCache(); 1125 if (mNextScreen == INVALID_SCREEN && mCurrentScreen > 0 && mScroller.isFinished()) { 1126 snapToScreen(mCurrentScreen - 1); 1127 } 1128 } 1129 1130 public void scrollRight() { 1131 clearVacantCache(); 1132 if (mNextScreen == INVALID_SCREEN && mCurrentScreen < getChildCount() -1 && 1133 mScroller.isFinished()) { 1134 snapToScreen(mCurrentScreen + 1); 1135 } 1136 } 1137 1138 public int getScreenForView(View v) { 1139 int result = -1; 1140 if (v != null) { 1141 ViewParent vp = v.getParent(); 1142 int count = getChildCount(); 1143 for (int i = 0; i < count; i++) { 1144 if (vp == getChildAt(i)) { 1145 return i; 1146 } 1147 } 1148 } 1149 return result; 1150 } 1151 1152 /** 1153 * Find a search widget on the given screen 1154 */ 1155 private Search findSearchWidget(CellLayout screen) { 1156 final int count = screen.getChildCount(); 1157 for (int i = 0; i < count; i++) { 1158 View v = screen.getChildAt(i); 1159 if (v instanceof Search) { 1160 return (Search) v; 1161 } 1162 } 1163 return null; 1164 } 1165 1166 /** 1167 * Gets the first search widget on the current screen, if there is one. 1168 * Returns <code>null</code> otherwise. 1169 */ 1170 public Search findSearchWidgetOnCurrentScreen() { 1171 CellLayout currentScreen = (CellLayout)getChildAt(mCurrentScreen); 1172 return findSearchWidget(currentScreen); 1173 } 1174 1175 public Folder getFolderForTag(Object tag) { 1176 int screenCount = getChildCount(); 1177 for (int screen = 0; screen < screenCount; screen++) { 1178 CellLayout currentScreen = ((CellLayout) getChildAt(screen)); 1179 int count = currentScreen.getChildCount(); 1180 for (int i = 0; i < count; i++) { 1181 View child = currentScreen.getChildAt(i); 1182 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); 1183 if (lp.cellHSpan == 4 && lp.cellVSpan == 4 && child instanceof Folder) { 1184 Folder f = (Folder) child; 1185 if (f.getInfo() == tag) { 1186 return f; 1187 } 1188 } 1189 } 1190 } 1191 return null; 1192 } 1193 1194 public View getViewForTag(Object tag) { 1195 int screenCount = getChildCount(); 1196 for (int screen = 0; screen < screenCount; screen++) { 1197 CellLayout currentScreen = ((CellLayout) getChildAt(screen)); 1198 int count = currentScreen.getChildCount(); 1199 for (int i = 0; i < count; i++) { 1200 View child = currentScreen.getChildAt(i); 1201 if (child.getTag() == tag) { 1202 return child; 1203 } 1204 } 1205 } 1206 return null; 1207 } 1208 1209 /** 1210 * @return True is long presses are still allowed for the current touch 1211 */ 1212 public boolean allowLongPress() { 1213 return mAllowLongPress; 1214 } 1215 1216 /** 1217 * Set true to allow long-press events to be triggered, usually checked by 1218 * {@link Launcher} to accept or block dpad-initiated long-presses. 1219 */ 1220 public void setAllowLongPress(boolean allowLongPress) { 1221 mAllowLongPress = allowLongPress; 1222 } 1223 1224 void removeShortcutsForPackage(String packageName) { 1225 final ArrayList<View> childrenToRemove = new ArrayList<View>(); 1226 final int count = getChildCount(); 1227 1228 for (int i = 0; i < count; i++) { 1229 final CellLayout layout = (CellLayout) getChildAt(i); 1230 int childCount = layout.getChildCount(); 1231 1232 childrenToRemove.clear(); 1233 1234 for (int j = 0; j < childCount; j++) { 1235 final View view = layout.getChildAt(j); 1236 Object tag = view.getTag(); 1237 1238 if (tag instanceof ApplicationInfo) { 1239 final ApplicationInfo info = (ApplicationInfo) tag; 1240 // We need to check for ACTION_MAIN otherwise getComponent() might 1241 // return null for some shortcuts (for instance, for shortcuts to 1242 // web pages.) 1243 final Intent intent = info.intent; 1244 final ComponentName name = intent.getComponent(); 1245 1246 if (Intent.ACTION_MAIN.equals(intent.getAction()) && 1247 name != null && packageName.equals(name.getPackageName())) { 1248 LauncherModel.deleteItemFromDatabase(mLauncher, info); 1249 childrenToRemove.add(view); 1250 } 1251 } else if (tag instanceof UserFolderInfo) { 1252 final UserFolderInfo info = (UserFolderInfo) tag; 1253 final ArrayList<ApplicationInfo> contents = info.contents; 1254 final ArrayList<ApplicationInfo> toRemove = new ArrayList<ApplicationInfo>(1); 1255 final int contentsCount = contents.size(); 1256 boolean removedFromFolder = false; 1257 1258 for (int k = 0; k < contentsCount; k++) { 1259 final ApplicationInfo appInfo = contents.get(k); 1260 final Intent intent = appInfo.intent; 1261 final ComponentName name = intent.getComponent(); 1262 1263 if (Intent.ACTION_MAIN.equals(intent.getAction()) && 1264 name != null && packageName.equals(name.getPackageName())) { 1265 toRemove.add(appInfo); 1266 LauncherModel.deleteItemFromDatabase(mLauncher, appInfo); 1267 removedFromFolder = true; 1268 } 1269 } 1270 1271 contents.removeAll(toRemove); 1272 if (removedFromFolder) { 1273 final Folder folder = getOpenFolder(); 1274 if (folder != null) folder.notifyDataSetChanged(); 1275 } 1276 } 1277 } 1278 1279 childCount = childrenToRemove.size(); 1280 for (int j = 0; j < childCount; j++) { 1281 View child = childrenToRemove.get(j); 1282 layout.removeViewInLayout(child); 1283 if (child instanceof DropTarget) { 1284 mDragController.removeDropTarget((DropTarget)child); 1285 } 1286 } 1287 1288 if (childCount > 0) { 1289 layout.requestLayout(); 1290 layout.invalidate(); 1291 } 1292 } 1293 } 1294 1295 void updateShortcutsForPackage(String packageName) { 1296 final PackageManager pm = mLauncher.getPackageManager(); 1297 1298 final int count = getChildCount(); 1299 for (int i = 0; i < count; i++) { 1300 final CellLayout layout = (CellLayout) getChildAt(i); 1301 int childCount = layout.getChildCount(); 1302 for (int j = 0; j < childCount; j++) { 1303 final View view = layout.getChildAt(j); 1304 Object tag = view.getTag(); 1305 if (tag instanceof ApplicationInfo) { 1306 ApplicationInfo info = (ApplicationInfo) tag; 1307 // We need to check for ACTION_MAIN otherwise getComponent() might 1308 // return null for some shortcuts (for instance, for shortcuts to 1309 // web pages.) 1310 final Intent intent = info.intent; 1311 final ComponentName name = intent.getComponent(); 1312 if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && 1313 Intent.ACTION_MAIN.equals(intent.getAction()) && name != null && 1314 packageName.equals(name.getPackageName())) { 1315 1316 final Drawable icon = AppInfoCache.getIconDrawable(pm, info); 1317 if (icon != null && icon != info.icon) { 1318 info.icon.setCallback(null); 1319 info.icon = Utilities.createIconThumbnail(icon, mContext); 1320 info.filtered = true; 1321 ((TextView) view).setCompoundDrawablesWithIntrinsicBounds(null, 1322 info.icon, null, null); 1323 } 1324 } 1325 } 1326 } 1327 } 1328 } 1329 1330 void moveToDefaultScreen() { 1331 snapToScreen(mDefaultScreen); 1332 getChildAt(mDefaultScreen).requestFocus(); 1333 } 1334 1335 public static class SavedState extends BaseSavedState { 1336 int currentScreen = -1; 1337 1338 SavedState(Parcelable superState) { 1339 super(superState); 1340 } 1341 1342 private SavedState(Parcel in) { 1343 super(in); 1344 currentScreen = in.readInt(); 1345 } 1346 1347 @Override 1348 public void writeToParcel(Parcel out, int flags) { 1349 super.writeToParcel(out, flags); 1350 out.writeInt(currentScreen); 1351 } 1352 1353 public static final Parcelable.Creator<SavedState> CREATOR = 1354 new Parcelable.Creator<SavedState>() { 1355 public SavedState createFromParcel(Parcel in) { 1356 return new SavedState(in); 1357 } 1358 1359 public SavedState[] newArray(int size) { 1360 return new SavedState[size]; 1361 } 1362 }; 1363 } 1364 1365 void show() { 1366 setVisibility(VISIBLE); 1367 } 1368 1369 void hide() { 1370 } 1371} 1372