のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

DeadZone: consuming errant click:

com.android.systemui DeadZone: consuming errant click:

    107     public boolean onTouchEvent(MotionEvent event) {
    108         if (DEBUG) {
    109             Slog.v(TAG, this + " onTouch: " + MotionEvent.actionToString(event.getAction()));
    110         }
    111 
    112         final int action = event.getAction();
    113         if (action == MotionEvent.ACTION_OUTSIDE) {
    114             poke(event);
    115         } else if (action == MotionEvent.ACTION_DOWN) {
    116             if (DEBUG) {
    117                 Slog.v(TAG, this + " ACTION_DOWN: " + event.getX() + "," + event.getY());
    118             }
    119             int size = (int) getSize(event.getEventTime());
    120             if ((mVertical && event.getX() < size) || event.getY() < size) {
    121                 if (CHATTY) {
    122                     Slog.v(TAG, "consuming errant click: (" + event.getX() + "," + event.getY() + ")"); <=ここ
    123                 }
    124                 if (mShouldFlash) {
    125                     post(mDebugFlash);
    126                     postInvalidate();
    127                 }
    128                 return true; // ...but I eated it
    129             }
    130         }
    131         return false;
    132     }
 38     private static final boolean CHATTY = true; // print to logcat when we eat a click
     84     static float lerp(float a, float b, float f) {
     85         return (b - a) * f + a;
     86     }

     88     private float getSize(long now) {
     89         if (mSizeMax == 0)
     90             return 0;
     91         long dt = (now - mLastPokeTime);
     92         if (dt > mHold + mDecay)
     93             return mSizeMin;
     94         if (dt < mHold)
     95             return mSizeMax;
     96         return (int) lerp(mSizeMax, mSizeMin, (float) (dt - mHold) / mDecay);
     97     }

     62     public DeadZone(Context context, AttributeSet attrs, int defStyle) {
     63         super(context, attrs);
     64 
     65         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DeadZone,
     66                 defStyle, 0);
     67 
     68         mHold = a.getInteger(R.styleable.DeadZone_holdTime, 0);
     69         mDecay = a.getInteger(R.styleable.DeadZone_decayTime, 0);
     70 
     71         mSizeMin = a.getDimensionPixelSize(R.styleable.DeadZone_minSize, 0); <= mSizeMin
     72         mSizeMax = a.getDimensionPixelSize(R.styleable.DeadZone_maxSize, 0); <= mSizeMax
     73 
     74         int index = a.getInt(R.styleable.DeadZone_orientation, -1);
     75         mVertical = (index == VERTICAL);
     76 
     77         if (DEBUG)
     78             Slog.v(TAG, this + " size=[" + mSizeMin + "-" + mSizeMax + "] hold=" + mHold
     79                     + (mVertical ? " vertical" : " horizontal"));
     80 
     81         setFlashOnTouchCapture(context.getResources().getBoolean(R.bool.config_dead_zone_flash));
     82     }

38 <declare-styleable name="DeadZone">
39 <attr name="minSize" format="dimension" />
40 <attr name="maxSize" format="dimension" />
41 <attr name="holdTime" format="integer" />
42 <attr name="decayTime" format="integer" />
43 <attr name="orientation" />