protected boolean dispatchTouchEvent(MotionEvent event) {
   int x = (int) event.getX();
   int y = (int) event.getY();
   int action = event.getAction();
   if (mMotionTarget != null) {
     if (action == MotionEvent.ACTION_DOWN) {
       MotionEvent cancel = MotionEvent.obtain(event);
       cancel.setAction(MotionEvent.ACTION_CANCEL);
       dispatchTouchEvent(cancel, x, y, mMotionTarget, false);
       mMotionTarget = null;
     } else {
       dispatchTouchEvent(event, x, y, mMotionTarget, false);
       if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
         mMotionTarget = null;
       }
       return true;
     }
   }
   if (action == MotionEvent.ACTION_DOWN) {
     // in the reverse rendering order
     for (int i = getComponentCount() - 1; i >= 0; --i) {
       GLView component = getComponent(i);
       if (component.getVisibility() != GLView.VISIBLE) continue;
       if (dispatchTouchEvent(event, x, y, component, true)) {
         mMotionTarget = component;
         return true;
       }
     }
   }
   return onTouch(event);
 }
 @Override
 public void onSelectionModeChange(int mode) {
   switch (mode) {
     case SelectionManager.ENTER_SELECTION_MODE:
       {
         mActionBar.disableClusterMenu(true);
         mActionModeHandler.startActionMode();
         performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
         break;
       }
     case SelectionManager.LEAVE_SELECTION_MODE:
       {
         mActionModeHandler.finishActionMode();
         if (mShowClusterMenu) {
           mActionBar.enableClusterMenu(mSelectedAction, this);
         }
         mRootPane.invalidate();
         break;
       }
     case SelectionManager.SELECT_ALL_MODE:
       {
         mActionModeHandler.updateSupportedOperation();
         mRootPane.invalidate();
         break;
       }
   }
 }
 protected void onVisibilityChanged(int visibility) {
   for (int i = 0, n = getComponentCount(); i < n; ++i) {
     GLView child = getComponent(i);
     if (child.getVisibility() == GLView.VISIBLE) {
       child.onVisibilityChanged(visibility);
     }
   }
 }
 @Override
 public void onEyePositionChanged(float x, float y, float z) {
   mRootPane.lockRendering();
   mX = x;
   mY = y;
   mZ = z;
   mRootPane.unlockRendering();
   mRootPane.invalidate();
 }
 private void removeOneComponent(GLView component) {
   if (mMotionTarget == component) {
     long now = SystemClock.uptimeMillis();
     MotionEvent cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0, 0, 0);
     dispatchTouchEvent(cancelEvent);
     cancelEvent.recycle();
   }
   component.onDetachFromRoot();
   component.mParent = null;
 }
 // ********************************************************************
 // *                              MTK                                 *
 // ********************************************************************
 protected void dispatchKeyEvent(KeyEvent event) {
   for (int i = getComponentCount() - 1; i >= 0; --i) {
     GLView component = getComponent(i);
     if (component.getVisibility() != GLView.VISIBLE) {
       continue;
     }
     if (component != null) {
       component.onKeyEvent(event);
     }
   }
 }
 /** Gets the bounds of the given descendant that relative to this view. */
 public boolean getBoundsOf(GLView descendant, Rect out) {
   int xoffset = 0;
   int yoffset = 0;
   GLView view = descendant;
   while (view != this) {
     if (view == null) return false;
     Rect bounds = view.mBounds;
     xoffset += bounds.left;
     yoffset += bounds.top;
     view = view.mParent;
   }
   out.set(xoffset, yoffset, xoffset + descendant.getWidth(), yoffset + descendant.getHeight());
   return true;
 }
  // Adds a child to this GLView.
  public void addComponent(GLView component) {
    // Make sure the component doesn't have a parent currently.
    if (component.mParent != null) throw new IllegalStateException();

    // Build parent-child links
    if (mComponents == null) {
      mComponents = new ArrayList<GLView>();
    }
    mComponents.add(component);
    component.mParent = this;

    // If this is added after we have a root, tell the component.
    if (mRoot != null) {
      component.onAttachToRoot(mRoot);
    }
  }
 private void getSlotCenter(int slotIndex, int center[]) {
   Rect offset = new Rect();
   mRootPane.getBoundsOf(mSlotView, offset);
   Rect r = mSlotView.getSlotRect(slotIndex);
   int scrollX = mSlotView.getScrollX();
   int scrollY = mSlotView.getScrollY();
   center[0] = offset.left + (r.left + r.right) / 2 - scrollX;
   center[1] = offset.top + (r.top + r.bottom) / 2 - scrollY;
 }
 // Request re-layout of the view hierarchy.
 public void requestLayout() {
   mViewFlags |= FLAG_LAYOUT_REQUESTED;
   mLastHeightSpec = -1;
   mLastWidthSpec = -1;
   if (mParent != null) {
     mParent.requestLayout();
   } else {
     // Is this a content pane ?
     GLRoot root = getGLRoot();
     if (root != null) root.requestLayoutContentPane();
   }
 }
  protected void renderChild(GLCanvas canvas, GLView component) {
    if (component.getVisibility() != GLView.VISIBLE && component.mAnimation == null) return;

    int xoffset = component.mBounds.left - mScrollX;
    int yoffset = component.mBounds.top - mScrollY;

    canvas.translate(xoffset, yoffset);

    CanvasAnimation anim = component.mAnimation;
    if (anim != null) {
      canvas.save(anim.getCanvasSaveFlags());
      if (anim.calculate(AnimationTime.get())) {
        invalidate();
      } else {
        component.mAnimation = null;
      }
      anim.apply(canvas);
    }
    component.render(canvas);
    if (anim != null) canvas.restore();
    canvas.translate(-xoffset, -yoffset);
  }
 @Override
 public void onSelectionModeChange(int mode) {
   switch (mode) {
     case SelectionManager.ENTER_SELECTION_MODE:
       {
         mActionModeHandler.startActionMode();
         performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
         break;
       }
     case SelectionManager.LEAVE_SELECTION_MODE:
       {
         mActionModeHandler.finishActionMode();
         mRootPane.invalidate();
         break;
       }
     case SelectionManager.SELECT_ALL_MODE:
       {
         mActionModeHandler.updateSupportedOperation();
         mRootPane.invalidate();
         break;
       }
   }
 }
 protected boolean dispatchTouchEvent(
     MotionEvent event, int x, int y, GLView component, boolean checkBounds) {
   Rect rect = component.mBounds;
   int left = rect.left;
   int top = rect.top;
   if (!checkBounds || rect.contains(x, y)) {
     event.offsetLocation(-left, -top);
     if (component.dispatchTouchEvent(event)) {
       event.offsetLocation(left, top);
       return true;
     }
     event.offsetLocation(left, top);
   }
   return false;
 }
Exemple #14
0
  private void initializeViews() {
    mSelectionManager = new SelectionManager(mActivity, true);
    mSelectionManager.setSelectionListener(this);

    mConfig = Config.AlbumSetPage.get(mActivity);
    mSlotView = new SlotView(mActivity, mConfig.slotViewSpec);
    mAlbumSetView =
        new AlbumSetSlotRenderer(
            mActivity, mSelectionManager, mSlotView, mConfig.labelSpec, mConfig.placeholderColor);
    mSlotView.setSlotRenderer(mAlbumSetView);
    mSlotView.setListener(
        new SlotView.SimpleListener() {
          @Override
          public void onDown(int index) {
            AlbumSetPage.this.onDown(index);
          }

          @Override
          public void onUp(boolean followedByLongPress) {
            AlbumSetPage.this.onUp(followedByLongPress);
          }

          @Override
          public void onSingleTapUp(int slotIndex) {
            AlbumSetPage.this.onSingleTapUp(slotIndex);
          }

          @Override
          public void onLongTap(int slotIndex) {
            AlbumSetPage.this.onLongTap(slotIndex);
          }

          @Override
          public void onGestureLongTap(int slotIndex) {
            AlbumSetPage.this.onGestureLongTap(slotIndex);
          }
        });

    mActionModeHandler = new ActionModeHandler(mActivity, mSelectionManager);
    mActionModeHandler.setActionModeListener(
        new ActionModeListener() {
          @Override
          public boolean onActionItemClicked(MenuItem item) {
            return onItemSelected(item);
          }
        });
    mRootPane.addComponent(mSlotView);
  }
 protected void setMeasuredSize(int width, int height) {
   mComponent.setMeasuredSize(width, height);
 }
Exemple #16
0
 @Override
 public void removeComponent(Object obj) {
   if (obj instanceof MGLView) {
     mRootView.removeComponent((GLView) ((MGLView) obj).getComponent());
   }
 }
 public void measure(int widthSpec, int heightSpec) {
   Rect p = mComponent.getPaddings();
   setMeasuredSize(
       getLength(widthSpec, mPreferredWidth + p.left + p.right),
       getLength(heightSpec, mPreferredHeight + p.top + p.bottom));
 }