FileDocCategorySizeDatePackage
PanelSwitcher.javaAPI DocAndroid 1.5 API4645Wed May 06 22:42:42 BST 2009com.android.calculator2

PanelSwitcher

public class PanelSwitcher extends android.widget.FrameLayout

Fields Summary
private static final int
MAJOR_MOVE
private static final int
ANIM_DURATION
private android.view.GestureDetector
mGestureDetector
private int
mCurrentView
private android.view.View
mChild
private android.view.View
mHistoryView
private android.view.View[]
children
private int
mWidth
private android.view.animation.TranslateAnimation
inLeft
private android.view.animation.TranslateAnimation
outLeft
private android.view.animation.TranslateAnimation
inRight
private android.view.animation.TranslateAnimation
outRight
private static final int
NONE
private static final int
LEFT
private static final int
RIGHT
private int
mPreviousMove
Constructors Summary
public PanelSwitcher(android.content.Context context, android.util.AttributeSet attrs)


         
        super(context, attrs);
        mCurrentView = 0;
        mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                                       float velocityY) {
                    int dx = (int) (e2.getX() - e1.getX());

                    // don't accept the fling if it's too short
                    // as it may conflict with a button push
                    if (Math.abs(dx) > MAJOR_MOVE && Math.abs(velocityX) > Math.abs(velocityY)) {
                        if (velocityX > 0) {
                            moveRight();
                        } else {
                            moveLeft();
                        }
                        return true;
                    } else {
                        return false;
                    }
                }
            });
    
Methods Summary
intgetCurrentIndex()

        return mCurrentView;
    
voidmoveLeft()

        //  <--
        if (mCurrentView < children.length - 1 && mPreviousMove != LEFT) {
            children[mCurrentView+1].setVisibility(View.VISIBLE);
            children[mCurrentView+1].startAnimation(inLeft);
            children[mCurrentView].startAnimation(outLeft);
            children[mCurrentView].setVisibility(View.GONE);

            mCurrentView++;
            mPreviousMove = LEFT;
        }
    
voidmoveRight()

        //  -->
        if (mCurrentView > 0 && mPreviousMove != RIGHT) {
            children[mCurrentView-1].setVisibility(View.VISIBLE);
            children[mCurrentView-1].startAnimation(inRight);
            children[mCurrentView].startAnimation(outRight);
            children[mCurrentView].setVisibility(View.GONE);

            mCurrentView--;
            mPreviousMove = RIGHT;
        }
    
protected voidonFinishInflate()

        int count = getChildCount();
        children = new View[count];
        for (int i = 0; i < count; ++i) {
            children[i] = getChildAt(i);
            if (i != mCurrentView) {
                children[i].setVisibility(View.GONE);
            }
        }
    
public booleanonInterceptTouchEvent(android.view.MotionEvent event)

        return mGestureDetector.onTouchEvent(event);
    
public voidonSizeChanged(int w, int h, int oldW, int oldH)

        mWidth = w;
        inLeft   = new TranslateAnimation(mWidth, 0, 0, 0);
        outLeft  = new TranslateAnimation(0, -mWidth, 0, 0);        
        inRight  = new TranslateAnimation(-mWidth, 0, 0, 0);
        outRight = new TranslateAnimation(0, mWidth, 0, 0);

        inLeft.setDuration(ANIM_DURATION);
        outLeft.setDuration(ANIM_DURATION);
        inRight.setDuration(ANIM_DURATION);
        outRight.setDuration(ANIM_DURATION);
    
public booleanonTouchEvent(android.view.MotionEvent event)

        mGestureDetector.onTouchEvent(event);
        return true;