FileDocCategorySizeDatePackage
BalloonHint.javaAPI DocAndroid 1.5 API16469Wed May 06 22:42:48 BST 2009com.android.inputmethod.pinyin

BalloonHint

public class BalloonHint extends android.widget.PopupWindow
Subclass of PopupWindow used as the feedback when user presses on a soft key or a candidate.

Fields Summary
public static final int
TIME_DELAY_SHOW
Delayed time to show the balloon hint.
public static final int
TIME_DELAY_DISMISS
Delayed time to dismiss the balloon hint.
private android.graphics.Rect
mPaddingRect
The padding information of the balloon. Because PopupWindow's background can not be changed unless it is dismissed and shown again, we set the real background drawable to the content view, and make the PopupWindow's background transparent. So actually this padding information is for the content view.
private android.content.Context
mContext
The context used to create this balloon hint object.
private android.view.View
mParent
Parent used to show the balloon window.
BalloonView
mBalloonView
The content view of the balloon.
private int
mMeasureSpecMode
The measuring specification used to determine its size. Key-press balloons and candidates balloons have different measuring specifications.
private boolean
mForceDismiss
Used to indicate whether the balloon needs to be dismissed forcibly.
private BalloonTimer
mBalloonTimer
Timer used to show/dismiss the balloon window with some time delay.
private int[]
mParentLocationInWindow
Constructors Summary
public BalloonHint(android.content.Context context, android.view.View parent, int measureSpecMode)


           
        super(context);
        mParent = parent;
        mMeasureSpecMode = measureSpecMode;

        setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
        setTouchable(false);
        setBackgroundDrawable(new ColorDrawable(0));

        mBalloonView = new BalloonView(context);
        mBalloonView.setClickable(false);
        setContentView(mBalloonView);

        mBalloonTimer = new BalloonTimer();
    
Methods Summary
public voiddelayedDismiss(long delay)

        if (mBalloonTimer.isPending()) {
            mBalloonTimer.removeTimer();
            int pendingAction = mBalloonTimer.getAction();
            if (0 != delay && BalloonTimer.ACTION_HIDE != pendingAction) {
                mBalloonTimer.run();
            }
        }
        if (delay <= 0) {
            dismiss();
        } else {
            mBalloonTimer.startTimer(delay, BalloonTimer.ACTION_HIDE, null, -1,
                    -1);
        }
    
public voiddelayedShow(long delay, int[] locationInParent)

        if (mBalloonTimer.isPending()) {
            mBalloonTimer.removeTimer();
        }
        if (delay <= 0) {
            mParent.getLocationInWindow(mParentLocationInWindow);
            showAtLocation(mParent, Gravity.LEFT | Gravity.TOP,
                    locationInParent[0], locationInParent[1]
                            + mParentLocationInWindow[1]);
        } else {
            mBalloonTimer.startTimer(delay, BalloonTimer.ACTION_SHOW,
                    locationInParent, -1, -1);
        }
    
public voiddelayedUpdate(long delay, int[] locationInParent, int width, int height)

        mBalloonView.invalidate();
        if (mBalloonTimer.isPending()) {
            mBalloonTimer.removeTimer();
        }
        if (delay <= 0) {
            mParent.getLocationInWindow(mParentLocationInWindow);
            update(locationInParent[0], locationInParent[1]
                    + mParentLocationInWindow[1], width, height);
        } else {
            mBalloonTimer.startTimer(delay, BalloonTimer.ACTION_UPDATE,
                    locationInParent, width, height);
        }
    
public android.content.ContextgetContext()

        return mContext;
    
public android.graphics.RectgetPadding()

        return mPaddingRect;
    
public intgetPaddingBottom()

        return mPaddingRect.bottom;
    
public intgetPaddingLeft()

        return mPaddingRect.left;
    
public intgetPaddingRight()

        return mPaddingRect.right;
    
public intgetPaddingTop()

        return mPaddingRect.top;
    
public booleanneedForceDismiss()

        return mForceDismiss;
    
public voidremoveTimer()

        if (mBalloonTimer.isPending()) {
            mBalloonTimer.removeTimer();
        }
    
public voidsetBalloonBackground(android.graphics.drawable.Drawable drawable)

        // We usually pick up a background from a soft keyboard template,
        // and the object may has been set to this balloon before.
        if (mBalloonView.getBackground() == drawable) return;
        mBalloonView.setBackgroundDrawable(drawable);

        if (null != drawable) {
            drawable.getPadding(mPaddingRect);
        } else {
            mPaddingRect.set(0, 0, 0, 0);
        }
    
public voidsetBalloonConfig(java.lang.String label, float textSize, boolean textBold, int textColor, int width, int height)
Set configurations to show text label in this balloon.

param
label The text label to show in the balloon.
param
textSize The text size used to show label.
param
textBold Used to indicate whether the label should be bold.
param
textColor The text color used to show label.
param
width The desired width of the balloon. The real width is determined by the desired width and balloon's measuring specification.
param
height The desired width of the balloon. The real width is determined by the desired width and balloon's measuring specification.

        mBalloonView.setTextConfig(label, textSize, textBold, textColor);
        setBalloonSize(width, height);
    
public voidsetBalloonConfig(android.graphics.drawable.Drawable icon, int width, int height)
Set configurations to show text label in this balloon.

param
icon The icon used to shown in this balloon.
param
width The desired width of the balloon. The real width is determined by the desired width and balloon's measuring specification.
param
height The desired width of the balloon. The real width is determined by the desired width and balloon's measuring specification.

        mBalloonView.setIcon(icon);
        setBalloonSize(width, height);
    
private voidsetBalloonSize(int width, int height)

        int widthMeasureSpec = MeasureSpec.makeMeasureSpec(width,
                mMeasureSpecMode);
        int heightMeasureSpec = MeasureSpec.makeMeasureSpec(height,
                mMeasureSpecMode);
        mBalloonView.measure(widthMeasureSpec, heightMeasureSpec);

        int oldWidth = getWidth();
        int oldHeight = getHeight();
        int newWidth = mBalloonView.getMeasuredWidth() + getPaddingLeft()
                + getPaddingRight();
        int newHeight = mBalloonView.getMeasuredHeight() + getPaddingTop()
                + getPaddingBottom();
        setWidth(newWidth);
        setHeight(newHeight);

        // If update() is called to update both size and position, the system
        // will first MOVE the PopupWindow to the new position, and then
        // perform a size-updating operation, so there will be a flash in
        // PopupWindow if user presses a key and moves finger to next one whose
        // size is different.
        // PopupWindow will handle the updating issue in one go in the future,
        // but before that, if we find the size is changed, a mandatory dismiss
        // operation is required. In our UI design, normal QWERTY keys' width
        // can be different in 1-pixel, and we do not dismiss the balloon when
        // user move between QWERTY keys.
        mForceDismiss = false;
        if (isShowing()) {
            mForceDismiss = oldWidth - newWidth > 1 || newWidth - oldWidth > 1;
        }