Example #1
0
void WaveView::WaveUpdateFrame(
    /* [in] */ Float mouseX,
    /* [in] */ Float mouseY,
    /* [in] */ Boolean fingerDown)
{
    Double distX = mouseX - mLockCenterX;
    Double distY = mouseY - mLockCenterY;
    Int32 dragDistance = (Int32) Elastos::Core::Math::Ceil(Elastos::Core::Math::Hypot(distX, distY));
    Double touchA = Elastos::Core::Math::Atan2(distX, distY);
    Float ringX = (Float) (mLockCenterX + mRingRadius * Elastos::Core::Math::Sin(touchA));
    Float ringY = (Float) (mLockCenterY + mRingRadius * Elastos::Core::Math::Cos(touchA));
    String strX("x");
    String strY("y");
    String alpha("alpha");
    String scaleX("scaleX");
    String scaleY("scaleY");
    AutoPtr <IObjectAnimator> res;
    switch (mLockState) {
        case STATE_RESET_LOCK:
        {
            if (DBG) Logger::V(TAG, "State RESET_LOCK");
            mWaveTimerDelay = WAVE_DELAY;
            for (UInt32 i = 0; i < mLightWaves.GetSize(); i++) {
                AutoPtr<IDrawableHolder> holder = mLightWaves[i];
                holder->AddAnimTo(300, 0, alpha, 0.0f, FALSE, (IObjectAnimator**)&res);
                res = NULL;
            }
            for (UInt32 i = 0; i < mLightWaves.GetSize(); i++) {
                mLightWaves[i]->StartAnimations(
                        (IAnimatorUpdateListener*)this->Probe(EIID_IAnimatorUpdateListener));
            }

            mUnlockRing->AddAnimTo(DURATION, 0, strX, mLockCenterX, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockRing->AddAnimTo(DURATION, 0, strY, mLockCenterY, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockRing->AddAnimTo(DURATION, 0, scaleX, 0.1f, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockRing->AddAnimTo(DURATION, 0, scaleY, 0.1f, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockRing->AddAnimTo(DURATION, 0, alpha, 0.0f, TRUE, (IObjectAnimator**)&res);
            res = NULL;

            mUnlockDefault->RemoveAnimationFor(strX);
            mUnlockDefault->RemoveAnimationFor(strY);
            mUnlockDefault->RemoveAnimationFor(scaleX);
            mUnlockDefault->RemoveAnimationFor(scaleY);
            mUnlockDefault->RemoveAnimationFor(alpha);
            mUnlockDefault->SetX(mLockCenterX);
            mUnlockDefault->SetY(mLockCenterY);
            mUnlockDefault->SetScaleX(0.1f);
            mUnlockDefault->SetScaleY(0.1f);
            mUnlockDefault->SetAlpha(0.0f);
            mUnlockDefault->AddAnimTo(DURATION, SHORT_DELAY, scaleX, 1.0f, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockDefault->AddAnimTo(DURATION, SHORT_DELAY, scaleY, 1.0f, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockDefault->AddAnimTo(DURATION, SHORT_DELAY, alpha, 1.0f, TRUE, (IObjectAnimator**)&res);
            res = NULL;

            mUnlockHalo->RemoveAnimationFor(strX);
            mUnlockHalo->RemoveAnimationFor(strY);
            mUnlockHalo->RemoveAnimationFor(scaleX);
            mUnlockHalo->RemoveAnimationFor(scaleY);
            mUnlockHalo->RemoveAnimationFor(alpha);
            mUnlockHalo->SetX(mLockCenterX);
            mUnlockHalo->SetY(mLockCenterY);
            mUnlockHalo->SetScaleX(0.1f);
            mUnlockHalo->SetScaleY(0.1f);
            mUnlockHalo->SetAlpha(0.0f);
            mUnlockHalo->AddAnimTo(DURATION, SHORT_DELAY, strX, mLockCenterX, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockHalo->AddAnimTo(DURATION, SHORT_DELAY, strY, mLockCenterY, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockHalo->AddAnimTo(DURATION, SHORT_DELAY, scaleX, 1.0f, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockHalo->AddAnimTo(DURATION, SHORT_DELAY, scaleY, 1.0f, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockHalo->AddAnimTo(DURATION, SHORT_DELAY, alpha, 1.0f, TRUE, (IObjectAnimator**)&res);
            res = NULL;

            RemoveCallbacks(mLockTimerActions);

            mLockState = STATE_READY;
            break;
        }
        case STATE_READY:
        {
            if (DBG) Logger::V(TAG, "State READY");
            mWaveTimerDelay = WAVE_DELAY;
            break;
        }
        case STATE_START_ATTEMPT:
        {
            if (DBG) Logger::V(TAG, "State START_ATTEMPT");
            mUnlockDefault->RemoveAnimationFor(strX);
            mUnlockDefault->RemoveAnimationFor(strY);
            mUnlockDefault->RemoveAnimationFor(scaleX);
            mUnlockDefault->RemoveAnimationFor(scaleY);
            mUnlockDefault->RemoveAnimationFor(alpha);
            mUnlockDefault->SetX(mLockCenterX + 182);
            mUnlockDefault->SetY(mLockCenterY);
            mUnlockDefault->SetScaleX(0.1f);
            mUnlockDefault->SetScaleY(0.1f);
            mUnlockDefault->SetAlpha(0.0f);

            mUnlockDefault->AddAnimTo(DURATION, SHORT_DELAY, scaleX, 1.0f, FALSE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockDefault->AddAnimTo(DURATION, SHORT_DELAY, scaleY, 1.0f, FALSE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockDefault->AddAnimTo(DURATION, SHORT_DELAY, alpha, 1.0f, FALSE, (IObjectAnimator**)&res);
            res = NULL;

            mUnlockRing->AddAnimTo(DURATION, 0, scaleX, 1.0f, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockRing->AddAnimTo(DURATION, 0, scaleY, 1.0f, TRUE, (IObjectAnimator**)&res);
            res = NULL;
            mUnlockRing->AddAnimTo(DURATION, 0, alpha, 1.0f, TRUE, (IObjectAnimator**)&res);
            res = NULL;

            mLockState = STATE_ATTEMPTING;
            break;
        }
        case STATE_ATTEMPTING:
        {
            String sfingerDown = StringUtils::BooleanToString(fingerDown);

            if (DBG) Logger::V(TAG,
                String("State ATTEMPTING (fingerDown = ") + sfingerDown + ")");
            if (dragDistance > mSnapRadius) {
                mFinishWaves = TRUE; // don't start any more waves.
                if (fingerDown) {
                    res = NULL;
                    mUnlockHalo->AddAnimTo(0, 0, strX, ringX, TRUE, (IObjectAnimator**)&res);
                    res = NULL;
                    mUnlockHalo->AddAnimTo(0, 0, strY, ringY, TRUE, (IObjectAnimator**)&res);
                    res = NULL;
                    mUnlockHalo->AddAnimTo(0, 0, scaleX, 1.0f, TRUE, (IObjectAnimator**)&res);
                    res = NULL;
                    mUnlockHalo->AddAnimTo(0, 0, scaleY, 1.0f, TRUE, (IObjectAnimator**)&res);
                    res = NULL;
                    mUnlockHalo->AddAnimTo(0, 0, alpha, 1.0f, TRUE, (IObjectAnimator**)&res);
                    res = NULL;
                }  else {
                    if (DBG) Logger::V(TAG, "up detected, moving to STATE_UNLOCK_ATTEMPT");
                    mLockState = STATE_UNLOCK_ATTEMPT;
                }
            } else {
                // If waves have stopped, we need to kick them off again...
                if (!mWavesRunning) {
                    mWavesRunning = TRUE;
                    mFinishWaves = FALSE;
                    // mWaveTimerDelay = WAVE_DELAY;
                    PostDelayed(mAddWaveAction, mWaveTimerDelay);
                }
                res = NULL;
                mUnlockHalo->AddAnimTo(0, 0, strX, mouseX, TRUE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockHalo->AddAnimTo(0, 0, strY, mouseY, TRUE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockHalo->AddAnimTo(0, 0, scaleX, 1.0f, TRUE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockHalo->AddAnimTo(0, 0, scaleY, 1.0f, TRUE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockHalo->AddAnimTo(0, 0, alpha, 1.0f, TRUE, (IObjectAnimator**)&res);
                res = NULL;
            }
            break;
        }

        case STATE_UNLOCK_ATTEMPT:
        {
            if (DBG) Logger::V(TAG, "State UNLOCK_ATTEMPT");
            if (dragDistance > mSnapRadius) {
                for (UInt32 n = 0; n < mLightWaves.GetSize(); n++) {
                    AutoPtr<IDrawableHolder> wave;
                    wave = mLightWaves[n];
                    Int64 delay = 1000L*(6 + n - mCurrentWave)/10L;
                    res = NULL;
                    wave->AddAnimTo(FINAL_DURATION, delay, strX, ringX, TRUE, (IObjectAnimator**)&res);
                    res = NULL;
                    wave->AddAnimTo(FINAL_DURATION, delay, strY, ringY, TRUE, (IObjectAnimator**)&res);
                    res = NULL;
                    wave->AddAnimTo(FINAL_DURATION, delay, scaleX, 0.1f, TRUE, (IObjectAnimator**)&res);
                    res = NULL;
                    wave->AddAnimTo(FINAL_DURATION, delay, scaleY, 0.1f, TRUE, (IObjectAnimator**)&res);
                    res = NULL;
                    wave->AddAnimTo(FINAL_DURATION, delay, alpha, 0.0f, TRUE, (IObjectAnimator**)&res);
                    res = NULL;
                }
                for (UInt32 i = 0; i < mLightWaves.GetSize(); i++) {
                    mLightWaves[i]->StartAnimations(
                            (IAnimatorUpdateListener*)this->Probe(EIID_IAnimatorUpdateListener));
                }
                res = NULL;
                mUnlockRing->AddAnimTo(FINAL_DURATION, 0, strX, ringX, FALSE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockRing->AddAnimTo(FINAL_DURATION, 0, strY, ringY, FALSE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockRing->AddAnimTo(FINAL_DURATION, 0, scaleX, 0.1f, FALSE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockRing->AddAnimTo(FINAL_DURATION, 0, scaleY, 0.1f, FALSE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockRing->AddAnimTo(FINAL_DURATION, 0, alpha, 0.0f, FALSE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockRing->AddAnimTo(FINAL_DURATION, FINAL_DELAY, alpha, 0.0f, FALSE, (IObjectAnimator**)&res);
                res = NULL;

                mUnlockDefault->RemoveAnimationFor(strX);
                mUnlockDefault->RemoveAnimationFor(strY);
                mUnlockDefault->RemoveAnimationFor(scaleX);
                mUnlockDefault->RemoveAnimationFor(scaleY);
                mUnlockDefault->RemoveAnimationFor(alpha);
                mUnlockDefault->SetX(ringX);
                mUnlockDefault->SetY(ringY);
                mUnlockDefault->SetScaleX(0.1f);
                mUnlockDefault->SetScaleY(0.1f);
                mUnlockDefault->SetAlpha(0.0f);

                mUnlockDefault->AddAnimTo(FINAL_DURATION, 0, strX, ringX, TRUE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockDefault->AddAnimTo(FINAL_DURATION, 0, strY, ringY, TRUE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockDefault->AddAnimTo(FINAL_DURATION, 0, scaleX, 1.0f, TRUE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockDefault->AddAnimTo(FINAL_DURATION, 0, scaleY, 1.0f, TRUE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockDefault->AddAnimTo(FINAL_DURATION, 0, alpha, 1.0f, TRUE, (IObjectAnimator**)&res);
                res = NULL;

                mUnlockDefault->AddAnimTo(FINAL_DURATION, FINAL_DELAY, scaleX, 3.0f, FALSE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockDefault->AddAnimTo(FINAL_DURATION, FINAL_DELAY, scaleY, 3.0f, FALSE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockDefault->AddAnimTo(FINAL_DURATION, FINAL_DELAY, alpha, 0.0f, FALSE, (IObjectAnimator**)&res);
                res = NULL;

                mUnlockHalo->AddAnimTo(FINAL_DURATION, 0, strX, ringX, FALSE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockHalo->AddAnimTo(FINAL_DURATION, 0, strY, ringY, FALSE, (IObjectAnimator**)&res);
                res = NULL;

                mUnlockHalo->AddAnimTo(FINAL_DURATION, FINAL_DELAY, scaleX, 3.0f, FALSE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockHalo->AddAnimTo(FINAL_DURATION, FINAL_DELAY, scaleY, 3.0f, FALSE, (IObjectAnimator**)&res);
                res = NULL;
                mUnlockHalo->AddAnimTo(FINAL_DURATION, FINAL_DELAY, alpha, 0.0f, FALSE, (IObjectAnimator**)&res);
                res = NULL;

                RemoveCallbacks(mLockTimerActions);

                PostDelayed(mLockTimerActions, RESET_TIMEOUT);

                DispatchTriggerEvent(IWaveViewOnTriggerListener::CENTER_HANDLE);
                mLockState = STATE_UNLOCK_SUCCESS;
            } else {
                mLockState = STATE_RESET_LOCK;
            }
            break;
        }
        case STATE_UNLOCK_SUCCESS:
        {
            if (DBG) Logger::V(TAG, "State UNLOCK_SUCCESS");
            RemoveCallbacks(mAddWaveAction);
            break;
        }

        default:
        {
            if (DBG) Logger::V(TAG, String("Unknown state ") + StringUtils::Int32ToString(mLockState));
            break;
        }
    }
    mUnlockDefault->StartAnimations(THIS_PROBE(IAnimatorUpdateListener));
    mUnlockHalo->StartAnimations(THIS_PROBE(IAnimatorUpdateListener));
    mUnlockRing->StartAnimations(THIS_PROBE(IAnimatorUpdateListener));
}