コード例 #1
0
  @Override
  public void onDrag(float dx, float dy) {

    DraweeView<GenericDraweeHierarchy> draweeView = getDraweeView();

    if (draweeView != null && !mScaleDragDetector.isScaling()) {
      mMatrix.postTranslate(dx, dy);
      checkMatrixAndInvalidate();

      ViewParent parent = draweeView.getParent();
      if (parent == null) {
        return;
      }

      if (mAllowParentInterceptOnEdge
          && !mScaleDragDetector.isScaling()
          && !mBlockParentIntercept) {
        if (mScrollEdge == EDGE_BOTH
            || (mScrollEdge == EDGE_LEFT && dx >= 1f)
            || (mScrollEdge == EDGE_RIGHT && dx <= -1f)) {
          parent.requestDisallowInterceptTouchEvent(false);
        }
      } else {
        parent.requestDisallowInterceptTouchEvent(true);
      }
    }
  }
コード例 #2
0
  @Override
  public void onDrag(float dx, float dy) {
    if (mScaleDragDetector.isScaling()) {
      return; // Do not drag if we are already scaling
    }

    if (DEBUG) {
      LogManager.getLogger().d(LOG_TAG, String.format("onDrag: dx: %.2f. dy: %.2f", dx, dy));
    }

    ImageView imageView = getImageView();
    mSuppMatrix.postTranslate(dx, dy);
    checkAndDisplayMatrix();

    /**
     * Here we decide whether to let the ImageView's parent to start taking over the touch event.
     *
     * <p>First we check whether this function is enabled. We never want the parent to take over if
     * we're scaling. We then check the edge we're on, and the direction of the scroll (i.e. if
     * we're pulling against the edge, aka 'overscrolling', let the parent take over).
     */
    ViewParent parent = imageView.getParent();
    if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) {
      if (mScrollEdge == EDGE_BOTH
          || (mScrollEdge == EDGE_LEFT && dx >= 1f)
          || (mScrollEdge == EDGE_RIGHT && dx <= -1f)) {
        if (null != parent) parent.requestDisallowInterceptTouchEvent(false);
      }
    } else {
      if (null != parent) {
        parent.requestDisallowInterceptTouchEvent(true);
      }
    }
  }
コード例 #3
0
 /** Private helper to get the parent TabHost in the view hiearchy. */
 private static TabHost findTabHostParent(View v) {
   ViewParent p = v.getParent();
   while (p != null && !(p instanceof TabHost)) {
     p = p.getParent();
   }
   return (TabHost) p;
 }
コード例 #4
0
  /**
   * Sends the specified text to the {@link AccessibilityManager} to be spoken.
   *
   * @param view The source view.
   * @param text The text to speak.
   */
  public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
      Log.e(TAG, "Attempted to speak when accessibility was disabled!");
      return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
      event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
      Log.e(TAG, "Failed to obtain ViewParent in announceForAccessibility");
      return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
  }
コード例 #5
0
  /**
   * calls either #connect or #disconnect on the binder, depending on the view state. Call this
   * after a change to the view state.
   */
  private void evalBinder() {
    if (liftedRxLifecycleBinder.isClosed()) {
      // abort; already done
      return;
    }

    boolean connect;
    if (View.VISIBLE == getWindowVisibility()) {
      if (View.VISIBLE == getVisibility()) {
        boolean visible = true;
        for (ViewParent p = getParent(); visible && p instanceof View; p = p.getParent()) {
          visible &= View.VISIBLE == ((View) p).getVisibility();
        }
        connect = visible;
      } else {
        connect = false;
      }
    } else {
      connect = false;
    }
    if (connect) {
      liftedRxLifecycleBinder.connect(this);
    } else {
      liftedRxLifecycleBinder.disconnect();
    }
  }
コード例 #6
0
 public boolean onTouchEvent(MotionEvent ev) {
   int action = ev.getActionMasked();
   ViewParent parent = getParent(); // LinearLayout
   gestureDetector.onTouchEvent(ev);
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       this.mDragHelper.processTouchEvent(ev);
       parent.requestDisallowInterceptTouchEvent(true);
       sX = ev.getRawX();
       sY = ev.getRawY();
       return true;
     case MotionEvent.ACTION_MOVE:
       float distanceX = ev.getRawX() - sX;
       float distanceY = ev.getRawY() - sY;
       sX = ev.getRawX();
       sY = ev.getRawY();
       float angle = Math.abs(distanceY / distanceX);
       angle = (float) Math.toDegrees(Math.atan(angle));
       if (angle > 30) {
         parent.requestDisallowInterceptTouchEvent(false);
         return false;
       }
       parent.requestDisallowInterceptTouchEvent(true);
       mDragHelper.processTouchEvent(ev);
       break;
     case MotionEvent.ACTION_UP:
     case MotionEvent.ACTION_CANCEL:
     default:
       parent.requestDisallowInterceptTouchEvent(true);
       mDragHelper.processTouchEvent(ev);
   }
   return true; // 必须返回true,表示已经正确处理touch事件,才能继续后续的拖动*/
 }
コード例 #7
0
  @SuppressLint("ClickableViewAccessibility")
  @Override
  public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
      ViewParent parent = v.getParent();
      switch (ev.getAction()) {
        case ACTION_DOWN:
          // First, disable the Parent from intercepting the touch
          // event
          if (null != parent) {
            parent.requestDisallowInterceptTouchEvent(true);
          } else {
            LogManager.getLogger().i(LOG_TAG, "onTouch getParent() returned null");
          }

          // If we're flinging, and the user presses down, cancel
          // fling
          cancelFling();
          break;

        case ACTION_CANCEL:
        case ACTION_UP:
          // If the user has zoomed less than min scale, zoom back
          // to min scale
          if (getScale() < mMinScale) {
            RectF rect = getDisplayRect();
            if (null != rect) {
              v.post(
                  new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
              handled = true;
            }
          }
          break;
      }

      // Try the Scale/Drag detector
      if (null != mScaleDragDetector) {
        boolean wasScaling = mScaleDragDetector.isScaling();
        boolean wasDragging = mScaleDragDetector.isDragging();

        handled = mScaleDragDetector.onTouchEvent(ev);

        boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
        boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();

        mBlockParentIntercept = didntScale && didntDrag;
      }

      // Check to see if the user double tapped
      if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
        handled = true;
      }
    }

    return handled;
  }
コード例 #8
0
 @Override
 public boolean onInterceptTouchEvent(MotionEvent event) {
   // FIXME: 应该只反拦截水平方向的手式
   ViewParent parent = getParent();
   if (parent != null) {
     parent.requestDisallowInterceptTouchEvent(true);
   }
   return super.onInterceptTouchEvent(event);
 }
コード例 #9
0
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
      ViewParent p = getParent();
      if (p != null) p.requestDisallowInterceptTouchEvent(true);
    }

    return false;
  }
コード例 #10
0
 private void propagateClicked() {
   ViewParent parent = getParent();
   while (parent != null && parent instanceof View) {
     if (((View) parent).isClickable()) {
       ((View) parent).performClick();
       break;
     }
     parent = parent.getParent();
   }
 }
コード例 #11
0
 private boolean isInScrollingContainer() {
   ViewParent p = getParent();
   while (p != null && p instanceof ViewGroup) {
     if (((ViewGroup) p).shouldDelayChildPressedState()) {
       return true;
     }
     p = p.getParent();
   }
   return false;
 }
コード例 #12
0
 @Override
 public void run() {
   ViewParent parent = getParent();
   while (parent != null && !(parent instanceof NavigationBarView)) {
     parent = parent.getParent();
   }
   if (parent != null) {
     ((NavigationBarView) parent).onNavButtonTouched();
   }
 }
コード例 #13
0
 private void _propagatePressed(boolean pressed) {
   ViewParent parent = getParent();
   while (parent != null && parent instanceof View) {
     if (((View) parent).isClickable()) {
       ((View) parent).setPressed(pressed);
       break;
     }
     parent = parent.getParent();
   }
 }
コード例 #14
0
ファイル: SwipeLayout.java プロジェクト: SNXJ/working
 private AdapterView getAdapterView() {
   ViewParent t = getParent();
   while (t != null) {
     if (t instanceof AdapterView) {
       return (AdapterView) t;
     }
     t = t.getParent();
   }
   return null;
 }
コード例 #15
0
  @Override
  public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
    switch (ev.getAction()) {
      case MotionEvent.ACTION_MOVE:
        float deltaX = prevX - ev.getX();

        if (!drag && Math.abs(deltaX) > mTouchSlop) {
          final ViewParent parent = getParent();
          if (parent != null) {
            parent.requestDisallowInterceptTouchEvent(true);
          }
          drag = true;
          if (deltaX > 0) {
            deltaX -= mTouchSlop;
          } else {
            deltaX += mTouchSlop;
          }
        }
        if (drag) {
          final int oldX = getScrollX();
          final int range = getScrollRange();
          boolean canOverscroll =
              overscrollMode == OVER_SCROLL_ALWAYS
                  || (overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0);

          if (canOverscroll) {
            float pulledToY = oldX + deltaX;
            if (pulledToY < 0) {
              leftGlow.onPull(deltaX / getWidth(), 1.f - ev.getY() / getHeight());
              if (!rightGlow.isFinished()) rightGlow.onRelease();
            } else if (pulledToY > range) {
              rightGlow.onPull(deltaX / getWidth(), ev.getY() / getHeight());
              if (!leftGlow.isFinished()) leftGlow.onRelease();
            }
            if (leftGlow != null && (!leftGlow.isFinished() || !rightGlow.isFinished()))
              postInvalidate();
          }
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (drag) {
          drag = false;

          if (leftGlow != null) {
            leftGlow.onRelease();
            rightGlow.onRelease();
          }
        }
        break;
    }
    prevX = ev.getX();

    return super.dispatchTouchEvent(ev);
  }
コード例 #16
0
 /** hide all internal children (i.e., actual tabs) */
 @Override
 public boolean hides(View view) {
   android.view.ViewParent parent = view.getParent();
   while (parent != null) {
     if (parent.getClass().getName().contains("TabWidget")) {
       return true;
     }
     parent = parent.getParent();
   }
   return super.hides(view);
 }
コード例 #17
0
ファイル: PlayerSeekbar.java プロジェクト: HKMOpen/SoundWaves
  private void requestParentTouchRecursive(
      @NonNull ViewParent argThisParent, boolean argDisallowTouch) {
    argThisParent.requestDisallowInterceptTouchEvent(argDisallowTouch);

    ViewParent nextParent = argThisParent.getParent();

    if (nextParent != null) {
      // Log.d("PlayerSeekbar", nextParent.toString() + " -> " + argDisallowTouch);
      requestParentTouchRecursive(nextParent, argDisallowTouch);
    }
  }
コード例 #18
0
 @Override
 protected void onAttachedToWindow() {
   super.onAttachedToWindow();
   ViewParent parent = this.getParent();
   while (parent != null) {
     if (parent instanceof ScrollDownLayout) {
       ((ScrollDownLayout) parent).setAssociatedScrollView(this);
       break;
     }
     parent = parent.getParent();
   }
 }
コード例 #19
0
  protected boolean isViewDescendant(View v) {
    ViewParent parent = v.getParent();
    while (parent != null) {
      if (parent == this) {
        return true;
      }

      parent = parent.getParent();
    }

    return false;
  }
コード例 #20
0
ファイル: PhotoViewAttacher.java プロジェクト: keqizwl/volley
  private void getViewParentsFromImageView(View v) {
    ViewParent tmp = v.getParent();
    if (tmp == null) {
      return;
    }

    viewParents.add(tmp);
    while (tmp.getParent() != null) {
      tmp = tmp.getParent();
      viewParents.add(tmp);
    }
  }
コード例 #21
0
 @SuppressLint("NewApi")
 public boolean isInScrollingContainer() {
   ViewParent p = getParent();
   while (p != null && p instanceof ViewGroup) {
     if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH
         && ((ViewGroup) p).shouldDelayChildPressedState()) {
       return true;
     }
     p = p.getParent();
   }
   return false;
 }
コード例 #22
0
  @Override
  public void setZoomable(boolean zoomable) {
    mZoomEnabled = zoomable;
    update();

    View v = getImageView();

    if (!zoomable && v != null) {
      ViewParent parent = v.getParent();
      if (parent != null) {
        parent.requestDisallowInterceptTouchEvent(false);
      }
    }
  }
コード例 #23
0
ファイル: SwipeLayout.java プロジェクト: SNXJ/working
 private void performAdapterViewItemClick(MotionEvent e) {
   ViewParent t = getParent();
   while (t != null) {
     if (t instanceof AdapterView) {
       AdapterView view = (AdapterView) t;
       int p = view.getPositionForView(SwipeLayout.this);
       if (p != AdapterView.INVALID_POSITION
           && view.performItemClick(view.getChildAt(p), p, view.getAdapter().getItemId(p))) return;
     } else {
       if (t instanceof View && ((View) t).performClick()) return;
     }
     t = t.getParent();
   }
 }
  @Override
  public final boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
      ViewParent parent = v.getParent();
      switch (ev.getAction()) {
        case ACTION_DOWN:
          // First, disable the Parent from intercepting the touch
          // event
          if (null != parent) parent.requestDisallowInterceptTouchEvent(true);
          else Log.i(LOG_TAG, "onTouch getParent() returned null");

          // If we're flinging, and the user presses down, cancel
          // fling
          cancelFling();
          break;

        case ACTION_CANCEL:
        case ACTION_UP:
          // If the user has zoomed less than min scale, zoom back
          // to min scale
          if (getScale() < mMinScale) {
            RectF rect = getDisplayRect();
            if (null != rect) {
              v.post(
                  new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
              handled = true;
            }
          }
          break;
      }

      // Check to see if the user double tapped
      if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
        handled = true;
      }

      if (!handled && null != parent) {
        parent.requestDisallowInterceptTouchEvent(false);
      }

      // Finally, try the Scale/Drag detector
      if (null != mScaleDragDetector && mScaleDragDetector.onTouchEvent(ev)) {
        handled = true;
      }
    }

    return handled;
  }
コード例 #25
0
ファイル: UISwitchButton.java プロジェクト: freemsly/AiSouYun
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   int action = event.getAction();
   float x = event.getX();
   float y = event.getY();
   float deltaX = Math.abs(x - mFirstDownX);
   float deltaY = Math.abs(y - mFirstDownY);
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       ViewParent mParent = getParent();
       if (mParent != null) {
         // 通知父控件不要拦截本view的触摸事件
         mParent.requestDisallowInterceptTouchEvent(true);
       }
       mFirstDownX = x;
       mFirstDownY = y;
       bmCurBtnPic = bmBtnPressed;
       startBtnPos = mChecked ? onBtnPos : offBtnPos;
       break;
     case MotionEvent.ACTION_MOVE:
       float time = event.getEventTime() - event.getDownTime();
       curBtnPos = startBtnPos + event.getX() - mFirstDownX;
       if (curBtnPos >= onBtnPos) {
         curBtnPos = onBtnPos;
       }
       if (curBtnPos <= offBtnPos) {
         curBtnPos = offBtnPos;
       }
       mTurningOn = curBtnPos > bgWidth / 2 - btnWidth / 2;
       break;
     case MotionEvent.ACTION_UP:
       bmCurBtnPic = bmBtnNormal;
       time = event.getEventTime() - event.getDownTime();
       if (deltaY < mTouchSlop && deltaX < mTouchSlop && time < mClickTimeout) {
         if (mPerformClick == null) {
           mPerformClick = new PerformClick();
         }
         if (!post(mPerformClick)) {
           performClick();
         }
       } else {
         startAnimation(mTurningOn);
       }
       break;
   }
   invalidate();
   return isEnabled();
 }
コード例 #26
0
 private void a(View paramView, CoordinatorLayout paramCoordinatorLayout)
 {
   g = paramCoordinatorLayout.findViewById(f);
   if (g != null)
   {
     View localView = g;
     for (ViewParent localViewParent = g.getParent(); (localViewParent != paramCoordinatorLayout) && (localViewParent != null); localViewParent = localViewParent.getParent())
     {
       if (localViewParent == paramView)
       {
         if (paramCoordinatorLayout.isInEditMode())
         {
           h = null;
           g = null;
           return;
         }
         throw new IllegalStateException("Anchor must not be a descendant of the anchored view");
       }
       if ((localViewParent instanceof View)) {
         localView = (View)localViewParent;
       }
     }
     h = localView;
     return;
   }
   if (paramCoordinatorLayout.isInEditMode())
   {
     h = null;
     g = null;
     return;
   }
   throw new IllegalStateException("Could not find CoordinatorLayout descendant view with id " + paramCoordinatorLayout.getResources().getResourceName(f) + " to anchor view " + paramView);
 }
コード例 #27
0
 /**
  * 通知父类不要拦截touch事件 Tries to claim the user's drag motion, and requests disallowing any ancestors
  * from stealing events in the drag.
  */
 private void attemptClaimDrag() {
   mParent = getParent();
   if (mParent != null) {
     // 通知父类不要拦截touch事件
     mParent.requestDisallowInterceptTouchEvent(true);
   }
 }
コード例 #28
0
  /**
   * @param arg0
   * @return
   */
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // TODO Auto-generated method stub
    ViewParent viewParent = getParent();

    switch (event.getAction()) {
      case MotionEvent.ACTION_MOVE:
        viewParent.requestDisallowInterceptTouchEvent(true);
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        viewParent.requestDisallowInterceptTouchEvent(false);
        break;
    }
    return super.onTouchEvent(event);
  }
コード例 #29
0
ファイル: ProxyDroid.java プロジェクト: kunal15595/proxydroid
 private LinearLayout getLayout(ViewParent parent) {
   if (parent instanceof LinearLayout) return (LinearLayout) parent;
   if (parent != null) {
     return getLayout(parent.getParent());
   } else {
     return null;
   }
 }
コード例 #30
0
 private AdapterView findParentAdapterView() {
   if (parentAdapter != null) {
     return parentAdapter;
   }
   ViewParent current = getParent();
   while (true) {
     if (current instanceof AdapterView) {
       parentAdapter = (AdapterView) current;
       return parentAdapter;
     } else {
       try {
         current = current.getParent();
       } catch (NullPointerException npe) {
         throw new RuntimeException("Could not find EventBusInstance parent AdapterView");
       }
     }
   }
 }