当前位置: 首页>>代码示例>>Java>>正文


Java TouchDelegate类代码示例

本文整理汇总了Java中android.view.TouchDelegate的典型用法代码示例。如果您正苦于以下问题:Java TouchDelegate类的具体用法?Java TouchDelegate怎么用?Java TouchDelegate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TouchDelegate类属于android.view包,在下文中一共展示了TouchDelegate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: expandTapArea

import android.view.TouchDelegate; //导入依赖的package包/类
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));
    }
  });
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:19,代码来源:GiphyActivityToolbar.java

示例2: doSetTouchDelegate

import android.view.TouchDelegate; //导入依赖的package包/类
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));
		}
	});
}
 
开发者ID:NewCasino,项目名称:browser,代码行数:20,代码来源:TopBarView.java

示例3: expendTouchArea

import android.view.TouchDelegate; //导入依赖的package包/类
/**
 * 扩展点击区域的范围
 *
 * @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));
            }
        });
    }
}
 
开发者ID:coopese,项目名称:qmui,代码行数:25,代码来源:QMUIViewHelper.java

示例4: onLayout

import android.view.TouchDelegate; //导入依赖的package包/类
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    if (changed) {
        //mTouchAreaLargerRatio
        float largedSize = (bottom - top) * mTouchAreaLargerRatio;
        int deltaY = (int) (largedSize - (bottom - top));
        int deltaX = largedSize > (right - left) ? (int) (largedSize - (right - left)) : 0;
        ViewGroup vg = (ViewGroup) getParent();
        //如果设定的半径大于固有的半径,就按设定的,如果没有大于就按固有的
        Rect rect = new Rect(left - deltaX, top - deltaY, right + deltaX, bottom + deltaY);
        vg.setTouchDelegate(new TouchDelegate(
                rect,
                this));
    }
}
 
开发者ID:halohoop,项目名称:UsoppBubble,代码行数:17,代码来源:UsoppBubble.java

示例5: restoreViewTouchRegion

import android.view.TouchDelegate; //导入依赖的package包/类
/**
 * 恢复View的触摸和点击范围,最小不小于View自身范围
 *
 * @param view
 */
public void restoreViewTouchRegion(final View view) {

    if (view == null) {
        throw new RuntimeException("view cannot be null.");
    }

    final ViewGroup viewGroup = (ViewGroup) view.getParent();
    if (viewGroup != null) {
        viewGroup.post(new Runnable() {
            @Override
            public void run() {
                Rect bounds = new Rect();
                bounds.setEmpty();
                touchDelegateGroup.addTouchDelegate(new TouchDelegate(bounds, view));

                if (View.class.isInstance(viewGroup)) {
                    viewGroup.setTouchDelegate(touchDelegateGroup);
                }
            }
        });
    }

}
 
开发者ID:venshine,项目名称:TouchRegion,代码行数:29,代码来源:TouchRegion.java

示例6: setTouchDelegateToMinAccessibleSize

import android.view.TouchDelegate; //导入依赖的package包/类
/**
 * 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));
        }
    });
}
 
开发者ID:google,项目名称:science-journal,代码行数:25,代码来源:AccessibilityUtils.java

示例7: increaseClickingArea

import android.view.TouchDelegate; //导入依赖的package包/类
@BindingAdapter("increaseClickingArea")
public static void increaseClickingArea(TextView textView, float size) {
    // fork from http://stackoverflow.com/a/1343796
    View parent = (View) textView.getParent();
    // post in the parent's message queue to make sure the parent
    // lays out its children before we call View#getHitRect()
    parent.post(() -> {
        final int halfSize = (int) (size / 2 + 0.5);
        Rect rect = new Rect();
        textView.getHitRect(rect);
        rect.top -= halfSize;
        rect.right += halfSize;
        rect.bottom += halfSize;
        rect.left -= halfSize;
        // use TouchDelegate to increase count's clicking area
        parent.setTouchDelegate(new TouchDelegate(rect, textView));
    });
}
 
开发者ID:ykrank,项目名称:S1-Next,代码行数:19,代码来源:TextViewBindingAdapter.java

示例8: restoreViewTouchDelegate

import android.view.TouchDelegate; //导入依赖的package包/类
/**
 * 还原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);
    }
}
 
开发者ID:razerdp,项目名称:FriendCircle,代码行数:25,代码来源:ViewUtil.java

示例9: setupSlidebar

import android.view.TouchDelegate; //导入依赖的package包/类
private void setupSlidebar(View view){
    SlideButton seekBar = (SlideButton) view.findViewById(R.id.lock_screen_slider);
    seekBar.setSlideButtonListener(new SlideButtonListener() {
        @Override
        public void handleSlide() {
            showUnlockScreen();
        }
    });
    // Increases the vertical touch hitbox
    Rect delegateArea = new Rect();
    seekBar.getHitRect(delegateArea);
    delegateArea.top -= 600;
    delegateArea.bottom += 600;
    TouchDelegate expandedArea = new TouchDelegate(delegateArea, seekBar);
    if (View.class.isInstance(seekBar.getParent())) {
        ((View) seekBar.getParent()).setTouchDelegate(expandedArea);
    }
}
 
开发者ID:AlstonLin,项目名称:TheLearningLock,代码行数:19,代码来源:LockScreen.java

示例10: expandViewTouchDelegate

import android.view.TouchDelegate; //导入依赖的package包/类
/**
 * 扩大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);
            }
        }
    });
}
 
开发者ID:luhaoaimama1,项目名称:zone-sdk,代码行数:33,代码来源:ViewUtils.java

示例11: ensureMinimumTouchTargetSize

import android.view.TouchDelegate; //导入依赖的package包/类
public static void ensureMinimumTouchTargetSize(View paramView, Rect paramRect1, Rect paramRect2, int paramInt)
{
  ViewParent localViewParent = paramView.getParent();
  if (!(localViewParent instanceof View)) {}
  View localView;
  do
  {
    return;
    localView = (View)localViewParent;
    if ((paramView.getVisibility() != 0) || ((paramView.getWidth() >= paramInt) && (paramView.getHeight() >= paramInt)))
    {
      paramRect1.setEmpty();
      localView.setTouchDelegate(null);
      return;
    }
    getTouchTarget(paramView, paramRect1, paramInt, paramInt);
  } while (paramRect1.equals(paramRect2));
  paramRect2.set(paramRect1);
  localView.setTouchDelegate(new TouchDelegate(paramRect1, paramView));
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:21,代码来源:UiUtils.java

示例12: increaseHitRectBy

import android.view.TouchDelegate; //导入依赖的package包/类
/**
 * 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.
 * @param delegate The view that needs to have its hit rect increased.
 */
public static void increaseHitRectBy(final int top, final int left, final int bottom, final int right, final View delegate) {
  final View parent = (View) delegate.getParent();
  if (parent != null && delegate.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 float densityDpi = delegate.getContext().getResources().getDisplayMetrics().densityDpi;
        final Rect r = new Rect();
        delegate.getHitRect(r);
        r.top -= transformToDensityPixel(top, densityDpi);
        r.left -= transformToDensityPixel(left, densityDpi);
        r.bottom += transformToDensityPixel(bottom, densityDpi);
        r.right += transformToDensityPixel(right, densityDpi);
        parent.setTouchDelegate(new TouchDelegate(r, delegate));
      }
    });
  }
}
 
开发者ID:pagesjaunes,项目名称:androidMobileDeviceManager,代码行数:29,代码来源:ViewUtils.java

示例13: enlargeTouchArea

import android.view.TouchDelegate; //导入依赖的package包/类
/**
 * Enlarges the Touchable area of a view
 * @param root The root view of the param viewToExpand
 * @param viewToExpand The view that needs a larger touch area
 * @param padding The amount of padding that will be applied to the view
 */
public static void enlargeTouchArea(View root, final View viewToExpand, final int padding) {
    root.post(new Runnable() {
        @Override
        public void run() {
            Rect delegateArea = new Rect();
            View delegate = viewToExpand;

            delegate.getHitRect(delegateArea);
            delegateArea.top -= padding;
            delegateArea.bottom += padding;
            delegateArea.left -= padding;
            delegateArea.right += padding;

            TouchDelegate expandedArea = new TouchDelegate(delegateArea, delegate);

            if(View.class.isInstance(delegate.getParent())){
                ((View)delegate.getParent()).setTouchDelegate(expandedArea);
            }

        }
    });
}
 
开发者ID:SNiels,项目名称:Multi-Mania-app,代码行数:29,代码来源:Utility.java

示例14: extendTouchAreaToMatchParent

import android.view.TouchDelegate; //导入依赖的package包/类
private void extendTouchAreaToMatchParent(int id) {
    final View button = findViewById(id);
    final View parent = (View) button.getParent();

    parent.post(new Runnable() {
        @Override
        public void run() {
            Rect parentRect = new Rect();
            parent.getHitRect(parentRect);
            Rect buttonRect = new Rect();
            button.getHitRect(buttonRect);

            int widthDiff = parentRect.width() - buttonRect.width();
            int heightDiff = parentRect.height() - buttonRect.height();

            buttonRect.left -= widthDiff/2;
            buttonRect.right += widthDiff/2;
            buttonRect.top -= heightDiff/2;
            buttonRect.bottom += heightDiff/2;

            parent.setTouchDelegate(new TouchDelegate(buttonRect, button));
        }
    });
}
 
开发者ID:jameliu,项目名称:Camera2,代码行数:25,代码来源:BottomBar.java

示例15: expandTapArea

import android.view.TouchDelegate; //导入依赖的package包/类
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));
    }
  });
}
 
开发者ID:SilenceIM,项目名称:Silence,代码行数:17,代码来源:ContactSelectionActivity.java


注:本文中的android.view.TouchDelegate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。