Exemplo n.º 1
0
 @Override
 public void onDraw(Canvas canvas) {
   final boolean keyboardChanged = mKeyboardChanged;
   super.onDraw(canvas);
   // switching animation
   if (mAnimationLevel != AnimationsLevel.None && keyboardChanged && (mInAnimation != null)) {
     startAnimation(mInAnimation);
     mInAnimation = null;
   }
   // text pop out animation
   if (mPopOutText != null && mAnimationLevel != AnimationsLevel.None) {
     final int maxVerticalTravel = getHeight() / 2;
     final long animationDuration = 1200;
     final long currentAnimationTime = SystemClock.elapsedRealtime() - mPopOutTime;
     if (currentAnimationTime > animationDuration) {
       mPopOutText = null;
     } else {
       final float animationProgress =
           ((float) currentAnimationTime) / ((float) animationDuration);
       final float animationFactoredProgress = getPopOutAnimationInterpolator(animationProgress);
       final int y = mPopOutStartPoint.y - (int) (maxVerticalTravel * animationFactoredProgress);
       final int x = mPopOutStartPoint.x;
       final int alpha = 255 - (int) (255 * animationProgress);
       if (FeaturesSet.DEBUG_LOG)
         Log.d(
             TAG,
             "Drawing text popout '"
                 + mPopOutText
                 + "' at "
                 + x
                 + ","
                 + y
                 + " with alpha "
                 + alpha
                 + ". Animation progress is "
                 + animationProgress
                 + ", and factor progress is "
                 + animationFactoredProgress);
       // drawing
       setPaintToKeyText(mPaint);
       // will disappear over time
       mPaint.setAlpha(alpha);
       mPaint.setShadowLayer(5, 0, 0, Color.BLACK);
       // will grow over time
       mPaint.setTextSize(mPaint.getTextSize() * (1.0f + animationFactoredProgress));
       canvas.translate(x, y);
       canvas.drawText(mPopOutText, 0, mPopOutText.length(), 0, 0, mPaint);
       canvas.translate(-x, -y);
       // next frame
       postInvalidateDelayed(1000 / 50); // doing 50 frames per second;
     }
   }
 }