FileDocCategorySizeDatePackage
DTMFTwelveKeyDialerView.javaAPI DocAndroid 1.5 API4781Wed May 06 22:42:46 BST 2009com.android.phone

DTMFTwelveKeyDialerView

public class DTMFTwelveKeyDialerView extends android.widget.LinearLayout
DTMFTwelveKeyDialerView is the view logic that the DTMFDialer uses. This is really a thin wrapper around Linear Layout that intercepts some user interactions to provide the correct UI behaviour for the dialer.

Fields Summary
private static final String
LOG_TAG
private static final boolean
DBG
private DTMFTwelveKeyDialer
mDialer
Constructors Summary
public DTMFTwelveKeyDialerView(android.content.Context context)

    
        
        super(context);
    
public DTMFTwelveKeyDialerView(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
    
Methods Summary
public booleandispatchKeyEvent(android.view.KeyEvent event)
Normally we ignore everything except for the BACK and CALL keys. For those, we pass them to the model (and then the InCallScreen).

        if (DBG) log("dispatchKeyEvent(" + event + ")...");

        int keyCode = event.getKeyCode();
        if (mDialer != null) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                case KeyEvent.KEYCODE_CALL:
                    return event.isDown() ? mDialer.onKeyDown(keyCode, event) : 
                        mDialer.onKeyUp(keyCode, event); 
            }
        }

        if (DBG) log("==> dispatchKeyEvent: forwarding event to the DTMFDialer");
        return super.dispatchKeyEvent(event);
    
public booleandispatchTouchEvent(android.view.MotionEvent event)

        
        int x = (int)event.getX();
        int y = (int)event.getY();
        int closestDeltaX = 0;
        int closestDeltaY = 0;
        
        ArrayList<View> touchables = getTouchables();
        int minDistance = Integer.MAX_VALUE;
        View closest = null;

        final int numTouchables = touchables.size();
        
        Rect closestBounds = new Rect();
        Rect touchableBounds = new Rect();
        
        for (int i = 0; i < numTouchables; i++) {
            View touchable = touchables.get(i);

            // get visible bounds of other view in same coordinate system
            touchable.getDrawingRect(touchableBounds);
            
            offsetDescendantRectToMyCoords(touchable, touchableBounds);

            if (touchableBounds.contains(x, y)) {
                return super.dispatchTouchEvent(event);
            } 
            
            int deltaX;
            if (x > touchableBounds.right) {
                deltaX = touchableBounds.right - 1 - x;
            } else if (x < touchableBounds.left) {
                deltaX = touchableBounds.left + 1 - x;
            } else {
                deltaX = 0;
            }
            
            int deltaY;
            if (y > touchableBounds.bottom) {
                deltaY = touchableBounds.bottom - 1 - y;
            } else if (y < touchableBounds.top) {
                deltaY = touchableBounds.top + 1 - y;
            } else {
                deltaY = 0;
            }
            
            final int distanceSquared = (deltaX * deltaX) + (deltaY * deltaY);
            if (distanceSquared < minDistance) {
                minDistance = distanceSquared;
                closest = touchable;
                closestDeltaX = deltaX;
                closestDeltaY = deltaY;
            }
        }
        
        
        if (closest != null) {
            event.offsetLocation(closestDeltaX, closestDeltaY);
            return super.dispatchTouchEvent(event);
        } else {
            return super.dispatchTouchEvent(event);
        }
    
private voidlog(java.lang.String msg)

        Log.d(LOG_TAG, msg);
    
voidsetDialer(DTMFTwelveKeyDialer dialer)

        mDialer = dialer;