Guest User

TouchDisableView.java

a guest
Dec 29th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. package com.androidmkab.residemenu;
  2.  
  3.  
  4.  
  5. import android.content.Context;
  6. import android.util.AttributeSet;
  7. import android.view.MotionEvent;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10.  
  11. /**
  12.  * Created by thonguyen on 15/4/14.
  13.  */
  14. class TouchDisableView extends ViewGroup {
  15.  
  16.     private View mContent;
  17.  
  18.     //  private int mMode;
  19.     private boolean mTouchDisabled = false;
  20.  
  21.     public TouchDisableView(Context context) {
  22.         this(context, null);
  23.     }
  24.  
  25.     public TouchDisableView(Context context, AttributeSet attrs) {
  26.         super(context, attrs);
  27.     }
  28.  
  29.     public void setContent(View v) {
  30.         if (mContent != null) {
  31.             this.removeView(mContent);
  32.         }
  33.         mContent = v;
  34.         addView(mContent);
  35.     }
  36.  
  37.     public View getContent() {
  38.         return mContent;
  39.     }
  40.  
  41.     @Override
  42.     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  43.  
  44.         int width = getDefaultSize(0, widthMeasureSpec);
  45.         int height = getDefaultSize(0, heightMeasureSpec);
  46.         setMeasuredDimension(width, height);
  47.  
  48.         final int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width);
  49.         final int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height);
  50.         mContent.measure(contentWidth, contentHeight);
  51.     }
  52.  
  53.     @Override
  54.     protected void onLayout(boolean changed, int l, int t, int r, int b) {
  55.         final int width = r - l;
  56.         final int height = b - t;
  57.         mContent.layout(0, 0, width, height);
  58.     }
  59.  
  60.     @Override
  61.     public boolean onInterceptTouchEvent(MotionEvent ev) {
  62.         return mTouchDisabled;
  63.     }
  64.  
  65.     void setTouchDisable(boolean disableTouch) {
  66.         mTouchDisabled = disableTouch;
  67.     }
  68.  
  69.     boolean isTouchDisabled() {
  70.         return mTouchDisabled;
  71.     }
  72. }
Add Comment
Please, Sign In to add comment