示例#1
0
  @Override
  public boolean commitText(CharSequence text, int newCursorPosition) {

    nativeCommitText(text.toString(), newCursorPosition);

    return super.commitText(text, newCursorPosition);
  }
示例#2
0
  @Override
  public boolean setComposingText(CharSequence text, int newCursorPosition) {

    nativeSetComposingText(text.toString(), newCursorPosition);

    return super.setComposingText(text, newCursorPosition);
  }
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   int radius = 0;
   int shadowColor = changeColorAlpha(mShadowColor, MIN_SHADOW_COLOR_ALPHA);
   long elapsed = System.currentTimeMillis() - mStartTime;
   switch (mState) {
     case StateNormal:
       shadowColor = changeColorAlpha(mShadowColor, MIN_SHADOW_COLOR_ALPHA);
       break;
     case StateTouchDown:
       ripplePaint.setAlpha(255);
       if (elapsed < ANIMATION_DURATION) {
         radius = Math.round(elapsed * getWidth() / 2 / ANIMATION_DURATION);
         float shadowAlpha =
             (MAX_SHADOW_COLOR_ALPHA - MIN_SHADOW_COLOR_ALPHA) * elapsed / ANIMATION_DURATION
                 + MIN_SHADOW_COLOR_ALPHA;
         shadowColor = changeColorAlpha(mShadowColor, shadowAlpha);
       } else {
         radius = getWidth() / 2;
         shadowColor = changeColorAlpha(mShadowColor, MAX_SHADOW_COLOR_ALPHA);
       }
       postInvalidate();
       break;
     case StateTouchUp:
       if (elapsed < ANIMATION_DURATION) {
         int alpha = Math.round((ANIMATION_DURATION - elapsed) * 255 / ANIMATION_DURATION);
         ripplePaint.setAlpha(alpha);
         radius = getWidth() / 2 + Math.round(elapsed * getWidth() / 2 / ANIMATION_DURATION);
         float shadowAlpha =
             (MAX_SHADOW_COLOR_ALPHA - MIN_SHADOW_COLOR_ALPHA)
                     * (ANIMATION_DURATION - elapsed)
                     / ANIMATION_DURATION
                 + MIN_SHADOW_COLOR_ALPHA;
         shadowColor = changeColorAlpha(mShadowColor, shadowAlpha);
       } else {
         mState = StateNormal;
         radius = 0;
         ripplePaint.setAlpha(0);
         shadowColor = changeColorAlpha(mShadowColor, MIN_SHADOW_COLOR_ALPHA);
       }
       postInvalidate();
       break;
   }
   backgroundPaint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, shadowColor);
   canvas.drawRoundRect(getRectF(), mCornerRadius, mCornerRadius, backgroundPaint);
   canvas.save();
   if (mState == StateTouchDown || mState == StateTouchUp) {
     if (rippleClipPath == null) {
       rippleClipPath = new Path();
       rippleClipPath.addRoundRect(getRectF(), mCornerRadius, mCornerRadius, Path.Direction.CW);
     }
     canvas.clipPath(rippleClipPath);
   }
   canvas.drawCircle(mTouchPoint.x, mTouchPoint.y, radius, ripplePaint);
   canvas.restore();
   if (mText != null && mText.length() > 0) {
     int y = (int) (getHeight() / 2 - ((textPaint.descent() + textPaint.ascent()) / 2));
     canvas.drawText(mText.toString(), getWidth() / 2, y, textPaint);
   }
 }