當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。