android.view.TouchDelegate Java Examples

The following examples show how to use android.view.TouchDelegate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContactFilterToolbar.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void expandTapArea(final View container, final View child) {
  final int padding = getResources().getDimensionPixelSize(R.dimen.contact_selection_actions_tap_area);

  container.post(new Runnable() {
    @Override
    public void run() {
      Rect rect = new Rect();
      child.getHitRect(rect);

      rect.top -= padding;
      rect.left -= padding;
      rect.right += padding;
      rect.bottom += padding;

      container.setTouchDelegate(new TouchDelegate(rect, child));
    }
  });
}
 
Example #2
Source File: GiphyActivityToolbar.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void expandTapArea(final View container, final View child) {
  final int padding = getResources().getDimensionPixelSize(R.dimen.contact_selection_actions_tap_area);

  container.post(new Runnable() {
    @Override
    public void run() {
      Rect rect = new Rect();
      child.getHitRect(rect);

      rect.top -= padding;
      rect.left -= padding;
      rect.right += padding;
      rect.bottom += padding;

      container.setTouchDelegate(new TouchDelegate(rect, child));
    }
  });
}
 
Example #3
Source File: AccessibilityUtils.java    From science-journal with Apache License 2.0 6 votes vote down vote up
/**
 * General-purpose function to increase the TouchDelegate size up to the minimum size needed for
 * accessibility, and centered around the existing center of the view.
 *
 * @param viewToDelegate The view whose touchable area needs to be increased by setting a
 *     TouchDelegate on its parent with a larger rect.
 */
public static void setTouchDelegateToMinAccessibleSize(final View viewToDelegate) {
  viewToDelegate.post(
      new Runnable() {
        @Override
        public void run() {
          if (viewToDelegate == null) {
            return;
          }
          int a11ySize =
              viewToDelegate
                  .getContext()
                  .getResources()
                  .getDimensionPixelSize(R.dimen.accessibility_touch_target_min_size);
          Rect rect = new Rect();
          viewToDelegate.getHitRect(rect);
          resizeRect(a11ySize, rect);
          ((View) viewToDelegate.getParent())
              .setTouchDelegate(new TouchDelegate(rect, viewToDelegate));
        }
      });
}
 
Example #4
Source File: ClickUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
public static void expandClickArea(@NonNull final View view,
                                   final int expandSizeTop,
                                   final int expandSizeLeft,
                                   final int expandSizeRight,
                                   final int expandSizeBottom) {
    final View parentView = (View) view.getParent();
    if (parentView == null) {
        Log.e("ClickUtils", "expandClickArea must have parent view.");
        return;
    }
    parentView.post(new Runnable() {
        @Override
        public void run() {
            final Rect rect = new Rect();
            view.getHitRect(rect);
            rect.top -= expandSizeTop;
            rect.bottom += expandSizeBottom;
            rect.left -= expandSizeLeft;
            rect.right += expandSizeRight;
            parentView.setTouchDelegate(new TouchDelegate(rect, view));
        }
    });
}
 
Example #5
Source File: ViewHelper.java    From DMusic with Apache License 2.0 6 votes vote down vote up
/**
 * 扩展点击区域的范围
 *
 * @param view       需要扩展的元素,此元素必需要有父级元素
 * @param expendSize 需要扩展的尺寸(以sp为单位的)
 */
public static void expendTouchArea(final View view, final int expendSize) {
    if (view != null) {
        final View parentView = (View) view.getParent();

        parentView.post(new Runnable() {
            @Override
            public void run() {
                Rect rect = new Rect();
                view.getHitRect(rect); //如果太早执行本函数,会获取rect失败,因为此时UI界面尚未开始绘制,无法获得正确的坐标
                rect.left -= expendSize;
                rect.top -= expendSize;
                rect.right += expendSize;
                rect.bottom += expendSize;
                parentView.setTouchDelegate(new TouchDelegate(rect, view));
            }
        });
    }
}
 
Example #6
Source File: ContactFilterToolbar.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
private void expandTapArea(final View container, final View child) {
  final int padding = getResources().getDimensionPixelSize(R.dimen.contact_selection_actions_tap_area);

  container.post(new Runnable() {
    @Override
    public void run() {
      Rect rect = new Rect();
      child.getHitRect(rect);

      rect.top -= padding;
      rect.left -= padding;
      rect.right += padding;
      rect.bottom += padding;

      container.setTouchDelegate(new TouchDelegate(rect, child));
    }
  });
}
 
Example #7
Source File: TopBarView.java    From browser with GNU General Public License v2.0 6 votes vote down vote up
private void doSetTouchDelegate() {
	final TextView middleBtn = mMiddleButton;
	post(new Runnable() {

		@Override
		public void run() {
			Rect rect = new Rect();
			rect.left = (middleBtn.getWidth() / 4);
			rect.right = (3 * middleBtn.getWidth() / 4);
			rect.top = 0;
			rect.bottom = middleBtn.getHeight();
			middleBtn.setTouchDelegate(new TouchDelegate(rect, /*
																 * TopBarView.
																 * this
																 */
					mMiddleSub));
		}
	});
}
 
Example #8
Source File: ViewUtils.java    From zone-sdk with MIT License 6 votes vote down vote up
/**
 * 扩大View的触摸和点击响应范围,最大不超过其父View范围
 *
 * @param view
 * @param top
 * @param bottom
 * @param left
 * @param right
 */
public static void expandViewTouchDelegate(final View view, final int top,
                                           final int bottom, final int left, final int right) {

    ((View) view.getParent()).post(new Runnable() {
        @Override
        public void run() {
            Rect bounds = new Rect();
            view.setEnabled(true);
            view.getHitRect(bounds);

            bounds.top -= top;
            bounds.bottom += bottom;
            bounds.left -= left;
            bounds.right += right;

            TouchDelegate touchDelegate = new TouchDelegate(bounds, view);

            if (View.class.isInstance(view.getParent())) {
                ((View) view.getParent()).setTouchDelegate(touchDelegate);
            }
        }
    });
}
 
Example #9
Source File: ContactSelectionActivity.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
private void expandTapArea(final View container, final View child, final int padding) {
  container.post(new Runnable() {
    @Override
    public void run() {
      Rect rect = new Rect();
      child.getHitRect(rect);

      rect.top    -= padding;
      rect.left   -= padding;
      rect.right  += padding;
      rect.bottom += padding;

      container.setTouchDelegate(new TouchDelegate(rect, child));
    }
  });
}
 
Example #10
Source File: AbstractViewQuery.java    From COCOQuery with Apache License 2.0 6 votes vote down vote up
/**
 * Increases the hit rect of a view. This should be used when an icon is small and cannot be easily tapped on.
 * Source: http://stackoverflow.com/a/1343796/5210
 *
 * @param top    The amount of dp's to be added to the top for hit purposes.
 * @param left   The amount of dp's to be added to the left for hit purposes.
 * @param bottom The amount of dp's to be added to the bottom for hit purposes.
 * @param right  The amount of dp's to be added to the right for hit purposes.
 */
public T increaseHitRect(final int top, final int left, final int bottom, final int right) {
    final View parent = (View) view.getParent();
    if (parent != null && view.getContext() != null) {
        parent.post(new Runnable() {
            // Post in the parent's message queue to make sure the parent
            // lays out its children before we call getHitRect()
            public void run() {
                final Rect r = new Rect();
                view.getHitRect(r);
                r.top -= dip2pixel(top);
                r.left -= dip2pixel(left);
                r.bottom += dip2pixel(bottom);
                r.right += dip2pixel(right);
                parent.setTouchDelegate(new TouchDelegate(r, view));
            }
        });
    }
    return self();
}
 
Example #11
Source File: IconPreference.java    From AppOpsXposed with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onBindView(View view)
{
	super.onBindView(view);
	mSpinner = (Spinner) view.findViewById(R.id.spinnerWidget);

	final ViewParent parent = mSpinner.getParent();
	if(parent instanceof View)
	{
		final Rect rect  = new Rect(0, 0, ((View) parent).getWidth(),
				((View) parent).getHeight());
		((View) parent).setTouchDelegate(new TouchDelegate(rect, (View) parent));

	}

	updateSpinner();
	mSpinner.setOnItemSelectedListener(this);
}
 
Example #12
Source File: ViewUtils.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a touch delegate to the views parent if the parent is of type View.
 * This method is posted back to the parent so that the hit area is applied *after* the parent lays out its children
 *
 * This is useful if you need to expand the hit area (eg: for onClick's to trigger) but don't want to, or can't, increase
 * the size/padding of the view.
 *
 * @param toThisView the View you want to increase the touch (hit) area for
 * @param leftPX the additional amount (negative increases, positive decreases) of the hit area
 * @param topPX the additional amount (negative increases, positive decreases) of the hit area
 * @param rightPX the additional amount (positive increases, negative decreases) of the hit area
 * @param bottomPX the additional amount (positive increases, negative decreases) of the hit area
 */
public static void increaseTouchArea(
      final View toThisView,
      final int leftPX,
      final int topPX,
      final int rightPX,
      final int bottomPX
) {
    if (toThisView == null || !View.class.isInstance(toThisView.getParent())) {
        return;
    }

    final View statementParent = (View) toThisView.getParent();
    statementParent.post(new Runnable() {
        @Override public void run() {
            Rect delegateArea = new Rect();
            toThisView.getHitRect(delegateArea);
            delegateArea.left += leftPX;
            delegateArea.top += topPX;
            delegateArea.right += rightPX;
            delegateArea.bottom += bottomPX;
            statementParent.setTouchDelegate(new TouchDelegate(delegateArea, toThisView));
        }
    });
}
 
Example #13
Source File: ViewHelper.java    From Common with Apache License 2.0 6 votes vote down vote up
/**
 * 扩展点击区域的范围
 *
 * @param view       需要扩展的元素,此元素必需要有父级元素
 * @param expendSize 需要扩展的尺寸(以sp为单位的)
 */
public static void expendTouchArea(final View view, final int expendSize) {
    if (view != null) {
        final View parentView = (View) view.getParent();

        parentView.post(new Runnable() {
            @Override
            public void run() {
                Rect rect = new Rect();
                view.getHitRect(rect); //如果太早执行本函数,会获取rect失败,因为此时UI界面尚未开始绘制,无法获得正确的坐标
                rect.left -= expendSize;
                rect.top -= expendSize;
                rect.right += expendSize;
                rect.bottom += expendSize;
                parentView.setTouchDelegate(new TouchDelegate(rect, view));
            }
        });
    }
}
 
Example #14
Source File: ViewUtils.java    From Android-utils with Apache License 2.0 6 votes vote down vote up
/**
 * 扩展点击区域的范围
 *
 * @param view       需要扩展的元素,此元素必需要有父级元素
 * @param expendSize 需要扩展的尺寸(以sp为单位的)
 */
public static void expendTouchArea(final View view, final int expendSize) {
    if (view != null) {
        final View parentView = (View) view.getParent();
        parentView.post(new Runnable() {
            @Override
            public void run() {
                Rect rect = new Rect();
                view.getHitRect(rect); // 如果太早执行本函数,会获取rect失败,因为此时UI界面尚未开始绘制,无法获得正确的坐标
                rect.left -= expendSize;
                rect.top -= expendSize;
                rect.right += expendSize;
                rect.bottom += expendSize;
                parentView.setTouchDelegate(new TouchDelegate(rect, view));
            }
        });
    }
}
 
Example #15
Source File: ViewUtil.java    From star-zone-android with Apache License 2.0 6 votes vote down vote up
/**
 * 还原View的触摸和点击响应范围,最小不小于View自身范围
 */
public static void restoreViewTouchDelegate(final View view) {
    if (view == null) {
        return;
    }

    if (view.getParent() != null) {

        ((View) view.getParent()).postDelayed(new Runnable() {
            @Override
            public void run() {
                Rect bounds = new Rect();
                bounds.setEmpty();
                TouchDelegate touchDelegate = new TouchDelegate(bounds, view);

                if (View.class.isInstance(view.getParent())) {
                    ((View) view.getParent()).setTouchDelegate(touchDelegate);
                }
            }
        }, 300);
    }
}
 
Example #16
Source File: TouchDelegateGroup.java    From FlowGeek with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
  if (!mEnabled) return false;

  TouchDelegate delegate = null;

  switch (event.getAction()) {
  case MotionEvent.ACTION_DOWN:
    for (int i = 0; i < mTouchDelegates.size(); i++) {
      TouchDelegate touchDelegate = mTouchDelegates.get(i);
      if (touchDelegate.onTouchEvent(event)) {
        mCurrentTouchDelegate = touchDelegate;
        return true;
      }
    }
    break;

  case MotionEvent.ACTION_MOVE:
    delegate = mCurrentTouchDelegate;
    break;

  case MotionEvent.ACTION_CANCEL:
  case MotionEvent.ACTION_UP:
    delegate = mCurrentTouchDelegate;
    mCurrentTouchDelegate = null;
    break;
  }

  return delegate != null && delegate.onTouchEvent(event);
}
 
Example #17
Source File: TouchDelegateGroup.java    From TvRemoteControl with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
  if (!mEnabled) return false;

  TouchDelegate delegate = null;

  switch (event.getAction()) {
  case MotionEvent.ACTION_DOWN:
    for (int i = 0; i < mTouchDelegates.size(); i++) {
      TouchDelegate touchDelegate = mTouchDelegates.get(i);
      if (touchDelegate.onTouchEvent(event)) {
        mCurrentTouchDelegate = touchDelegate;
        return true;
      }
    }
    break;

  case MotionEvent.ACTION_MOVE:
    delegate = mCurrentTouchDelegate;
    break;

  case MotionEvent.ACTION_CANCEL:
  case MotionEvent.ACTION_UP:
    delegate = mCurrentTouchDelegate;
    mCurrentTouchDelegate = null;
    break;
  }

  return delegate != null && delegate.onTouchEvent(event);
}
 
Example #18
Source File: TouchDelegateGroup.java    From android-chat-ui with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
  if (!mEnabled) return false;

  TouchDelegate delegate = null;

  switch (event.getAction()) {
  case MotionEvent.ACTION_DOWN:
    for (int i = 0; i < mTouchDelegates.size(); i++) {
      TouchDelegate touchDelegate = mTouchDelegates.get(i);
      if (touchDelegate.onTouchEvent(event)) {
        mCurrentTouchDelegate = touchDelegate;
        return true;
      }
    }
    break;

  case MotionEvent.ACTION_MOVE:
    delegate = mCurrentTouchDelegate;
    break;

  case MotionEvent.ACTION_CANCEL:
  case MotionEvent.ACTION_UP:
    delegate = mCurrentTouchDelegate;
    mCurrentTouchDelegate = null;
    break;
  }

  return delegate != null && delegate.onTouchEvent(event);
}
 
Example #19
Source File: TouchAreaActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.second);
	refreshButton = (ImageButton) findViewById(R.id.refresh);
	View parent = findViewById(R.id.layout);
	parent.post(new Runnable() {
		public void run() {
			// Post in the parent's message queue to make sure the parent
			// lays out its children before we call getHitRect()
			Rect delegateArea = new Rect();
			ImageButton delegate = refreshButton;
			delegate.getHitRect(delegateArea);
			delegateArea.top -= 600;
			delegateArea.bottom += 600;
			delegateArea.left -= 600;
			delegateArea.right += 600;
			TouchDelegate expandedArea = new TouchDelegate(delegateArea,
					delegate);
			// give the delegate to an ancestor of the view we're
			// delegating the
			// area to
			if (View.class.isInstance(delegate.getParent())) {
				((View) delegate.getParent())
						.setTouchDelegate(expandedArea);
			}
		};
	});
}
 
Example #20
Source File: MainActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);
	mButton = (Button) findViewById(R.id.delegated_button);
	View parent = findViewById(R.id.root);
	parent.post(new Runnable() {
		public void run() {
			// Post in the parent's message queue to make sure the parent
			// lays out its children before we call getHitRect()
			Rect delegateArea = new Rect();
			Button delegate = mButton;
			delegate.getHitRect(delegateArea);
			delegateArea.top -= 600;
			delegateArea.bottom += 600;
			delegateArea.left -= 600;
			delegateArea.right += 600;
			TouchDelegate expandedArea = new TouchDelegate(delegateArea,
					delegate);
			// give the delegate to an ancestor of the view we're
			// delegating the
			// area to
			if (View.class.isInstance(delegate.getParent())) {
				((View) delegate.getParent())
						.setTouchDelegate(expandedArea);
			}
		};
	});
}
 
Example #21
Source File: TouchAreaActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.second);
	refreshButton = (ImageButton) findViewById(R.id.refresh);
	View parent = findViewById(R.id.layout);
	parent.post(new Runnable() {
		public void run() {
			// Post in the parent's message queue to make sure the parent
			// lays out its children before we call getHitRect()
			Rect delegateArea = new Rect();
			ImageButton delegate = refreshButton;
			delegate.getHitRect(delegateArea);
			delegateArea.top -= 600;
			delegateArea.bottom += 600;
			delegateArea.left -= 600;
			delegateArea.right += 600;
			TouchDelegate expandedArea = new TouchDelegate(delegateArea,
					delegate);
			// give the delegate to an ancestor of the view we're
			// delegating the
			// area to
			if (View.class.isInstance(delegate.getParent())) {
				((View) delegate.getParent())
						.setTouchDelegate(expandedArea);
			}
		};
	});
}
 
Example #22
Source File: TouchDelegateGroup.java    From FloatingActionButton with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
  if (!mEnabled) return false;

  TouchDelegate delegate = null;

  switch (event.getAction()) {
  case MotionEvent.ACTION_DOWN:
    for (int i = 0; i < mTouchDelegates.size(); i++) {
      TouchDelegate touchDelegate = mTouchDelegates.get(i);
      if (touchDelegate.onTouchEvent(event)) {
        mCurrentTouchDelegate = touchDelegate;
        return true;
      }
    }
    break;

  case MotionEvent.ACTION_MOVE:
    delegate = mCurrentTouchDelegate;
    break;

  case MotionEvent.ACTION_CANCEL:
  case MotionEvent.ACTION_UP:
    delegate = mCurrentTouchDelegate;
    mCurrentTouchDelegate = null;
    break;
  }

  return delegate != null && delegate.onTouchEvent(event);
}
 
Example #23
Source File: DynamicDetailFragment.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private void a(View view, View view1)
{
    int i1 = (int)(30F * ChartUtil.getDensity());
    Rect rect = new Rect();
    view1.getHitRect(rect);
    rect.left = rect.left - i1;
    rect.top = rect.top - i1;
    rect.right = i1 + rect.right;
    rect.bottom = i1 + rect.bottom;
    view.setTouchDelegate(new TouchDelegate(rect, view1));
}
 
Example #24
Source File: DontPressWithParentCheckBox.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    ViewParent vp = getParent();
    if (vp instanceof ViewGroup && getVisibility() == View.VISIBLE) {
        ViewGroup vg = (ViewGroup) vp;
        Rect bounds = new Rect(vg.getWidth() - w - 2 * mTouchAddition, 0, vg.getWidth(), h);
        TouchDelegate delegate = new TouchDelegate(bounds, this);
        vg.setTouchDelegate(delegate);

    }
}
 
Example #25
Source File: TouchDelegateGroup.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
/**
 * Remove a previously added {@link TouchDelegate}.
 *
 * @param touchDelegate The {@link TouchDelegate} to remove in this
 *                      {@link TouchDelegateGroup}.
 */
public void removeTouchDelegate(TouchDelegate touchDelegate) {
    if (mTouchDelegates != null) {
        mTouchDelegates.remove(touchDelegate);
    }
    if (mTouchDelegates.isEmpty()) {
        mTouchDelegates = null;
    }
}
 
Example #26
Source File: TouchDelegateGroup.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {

    TouchDelegate delegate = null;

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            if (mTouchDelegates != null) {
                for (TouchDelegate touchDelegate : mTouchDelegates) {
                    if (touchDelegate != null) {
                        if (touchDelegate.onTouchEvent(event)) {
                            mCurrentTouchDelegate = touchDelegate;
                            return true;
                        }
                    }
                }
            }
            break;

        case MotionEvent.ACTION_MOVE:
            delegate = mCurrentTouchDelegate;
            break;

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            delegate = mCurrentTouchDelegate;
            mCurrentTouchDelegate = null;
            break;
    }

    return delegate == null ? false : delegate.onTouchEvent(event);
}
 
Example #27
Source File: TouchDelegateGroup.java    From android-floating-action-button with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
  if (!mEnabled) return false;

  TouchDelegate delegate = null;

  switch (event.getAction()) {
  case MotionEvent.ACTION_DOWN:
    for (int i = 0; i < mTouchDelegates.size(); i++) {
      TouchDelegate touchDelegate = mTouchDelegates.get(i);
      if (touchDelegate.onTouchEvent(event)) {
        mCurrentTouchDelegate = touchDelegate;
        return true;
      }
    }
    break;

  case MotionEvent.ACTION_MOVE:
    delegate = mCurrentTouchDelegate;
    break;

  case MotionEvent.ACTION_CANCEL:
  case MotionEvent.ACTION_UP:
    delegate = mCurrentTouchDelegate;
    mCurrentTouchDelegate = null;
    break;
  }

  return delegate != null && delegate.onTouchEvent(event);
}
 
Example #28
Source File: TouchDelegateFragment.java    From AndroidDigIn with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    delegateContainer = (TouchDelegateViewGroup) view.findViewById(R.id.delegate_container);
    rtn = (RadioButton) view.findViewById(R.id.rtn);
    Rect rect = new Rect(500, 500, 800, 800);
    delegateContainer.setDelegateAreaColor(Color.RED, rect);
    delegateContainer.setTouchDelegate(new TouchDelegate(rect, rtn));
    return view;
}
 
Example #29
Source File: TouchDelegateGroup.java    From FABsMenu with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    if (!mEnabled) return false;

    TouchDelegate delegate = null;

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            for (int i = 0; i < mTouchDelegates.size(); i++) {
                TouchDelegate touchDelegate = mTouchDelegates.get(i);
                if (touchDelegate.onTouchEvent(event)) {
                    mCurrentTouchDelegate = touchDelegate;
                    return true;
                }
            }
            break;

        case MotionEvent.ACTION_MOVE:
            delegate = mCurrentTouchDelegate;
            break;

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            delegate = mCurrentTouchDelegate;
            mCurrentTouchDelegate = null;
            break;
        default: // Do Nothing
            break;
    }

    return delegate != null && delegate.onTouchEvent(event);
}
 
Example #30
Source File: TouchDelegateGroup.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
        if (!mEnabled) return false;

        TouchDelegate delegate = null;

        switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                        for (int i = 0; i < mTouchDelegates.size(); i++) {
                                TouchDelegate touchDelegate = mTouchDelegates.get(i);
                                if (touchDelegate.onTouchEvent(event)) {
                                        mCurrentTouchDelegate = touchDelegate;
                                        return true;
                                }
                        }
                        break;

                case MotionEvent.ACTION_MOVE:
                        delegate = mCurrentTouchDelegate;
                        break;

                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_UP:
                        delegate = mCurrentTouchDelegate;
                        mCurrentTouchDelegate = null;
                        break;
        }

        return delegate != null && delegate.onTouchEvent(event);
}