BalloonHintpublic 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_SHOWDelayed time to show the balloon hint. | public static final int | TIME_DELAY_DISMISSDelayed time to dismiss the balloon hint. | private android.graphics.Rect | mPaddingRectThe 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 | mContextThe context used to create this balloon hint object. | private android.view.View | mParentParent used to show the balloon window. | BalloonView | mBalloonViewThe content view of the balloon. | private int | mMeasureSpecModeThe measuring specification used to determine its size. Key-press
balloons and candidates balloons have different measuring specifications. | private boolean | mForceDismissUsed to indicate whether the balloon needs to be dismissed forcibly. | private BalloonTimer | mBalloonTimerTimer 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 void | delayedDismiss(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 void | delayedShow(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 void | delayedUpdate(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.Context | getContext()
return mContext;
| public android.graphics.Rect | getPadding()
return mPaddingRect;
| public int | getPaddingBottom()
return mPaddingRect.bottom;
| public int | getPaddingLeft()
return mPaddingRect.left;
| public int | getPaddingRight()
return mPaddingRect.right;
| public int | getPaddingTop()
return mPaddingRect.top;
| public boolean | needForceDismiss()
return mForceDismiss;
| public void | removeTimer()
if (mBalloonTimer.isPending()) {
mBalloonTimer.removeTimer();
}
| public void | setBalloonBackground(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 void | setBalloonConfig(java.lang.String label, float textSize, boolean textBold, int textColor, int width, int height)Set configurations to show text label in this balloon.
mBalloonView.setTextConfig(label, textSize, textBold, textColor);
setBalloonSize(width, height);
| public void | setBalloonConfig(android.graphics.drawable.Drawable icon, int width, int height)Set configurations to show text label in this balloon.
mBalloonView.setIcon(icon);
setBalloonSize(width, height);
| private void | setBalloonSize(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;
}
|
|