AI 143780: am: CL 143728 Fix # 1743137: Suggestion bubble doesn't go away after empty space on right end of suggestion strip is tapped.
The empty space on right end sometimes registers as the word at the left end. Fixed this by checking for -1. Also fixed a bug where the strip moves in the wrong direction on drag, when it shouldn't move at all. Original author: yamasani Merged from: //branches/cupcake/... Automated import of CL 143780main
parent
f2965b89f1
commit
6ec55a1599
|
@ -148,16 +148,17 @@ public class CandidateView extends View {
|
||||||
@Override
|
@Override
|
||||||
public boolean onScroll(MotionEvent e1, MotionEvent e2,
|
public boolean onScroll(MotionEvent e1, MotionEvent e2,
|
||||||
float distanceX, float distanceY) {
|
float distanceX, float distanceY) {
|
||||||
|
final int width = getWidth();
|
||||||
mScrolled = true;
|
mScrolled = true;
|
||||||
mScrollX += distanceX;
|
mScrollX += (int) distanceX;
|
||||||
if (mScrollX < 0) {
|
if (mScrollX < 0) {
|
||||||
mScrollX = 0;
|
mScrollX = 0;
|
||||||
}
|
}
|
||||||
if (mScrollX + getWidth() > mTotalWidth) {
|
if (distanceX > 0 && mScrollX + width > mTotalWidth) {
|
||||||
mScrollX -= distanceX;
|
mScrollX -= (int) distanceX;
|
||||||
}
|
}
|
||||||
mTargetScrollX = mScrollX;
|
mTargetScrollX = mScrollX;
|
||||||
showPreview(OUT_OF_BOUNDS, null);
|
hidePreview();
|
||||||
invalidate();
|
invalidate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -236,7 +237,8 @@ public class CandidateView extends View {
|
||||||
|
|
||||||
mWordX[i] = x;
|
mWordX[i] = x;
|
||||||
|
|
||||||
if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) {
|
if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled &&
|
||||||
|
touchX != OUT_OF_BOUNDS) {
|
||||||
if (canvas != null) {
|
if (canvas != null) {
|
||||||
canvas.translate(x, 0);
|
canvas.translate(x, 0);
|
||||||
mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height);
|
mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height);
|
||||||
|
@ -399,7 +401,7 @@ public class CandidateView extends View {
|
||||||
mSelectedString = null;
|
mSelectedString = null;
|
||||||
mSelectedIndex = -1;
|
mSelectedIndex = -1;
|
||||||
removeHighlight();
|
removeHighlight();
|
||||||
showPreview(OUT_OF_BOUNDS, null);
|
hidePreview();
|
||||||
requestLayout();
|
requestLayout();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -425,16 +427,21 @@ public class CandidateView extends View {
|
||||||
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_REMOVE_THROUGH_PREVIEW), 200);
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_REMOVE_THROUGH_PREVIEW), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void hidePreview() {
|
||||||
|
mCurrentWordIndex = OUT_OF_BOUNDS;
|
||||||
|
if (mPreviewPopup.isShowing()) {
|
||||||
|
mHandler.sendMessageDelayed(mHandler
|
||||||
|
.obtainMessage(MSG_REMOVE_PREVIEW), 60);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void showPreview(int wordIndex, String altText) {
|
private void showPreview(int wordIndex, String altText) {
|
||||||
int oldWordIndex = mCurrentWordIndex;
|
int oldWordIndex = mCurrentWordIndex;
|
||||||
mCurrentWordIndex = wordIndex;
|
mCurrentWordIndex = wordIndex;
|
||||||
// If index changed or changing text
|
// If index changed or changing text
|
||||||
if (oldWordIndex != mCurrentWordIndex || altText != null) {
|
if (oldWordIndex != mCurrentWordIndex || altText != null) {
|
||||||
if (wordIndex == OUT_OF_BOUNDS) {
|
if (wordIndex == OUT_OF_BOUNDS) {
|
||||||
if (mPreviewPopup.isShowing()) {
|
hidePreview();
|
||||||
mHandler.sendMessageDelayed(mHandler
|
|
||||||
.obtainMessage(MSG_REMOVE_PREVIEW), 60);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
CharSequence word = altText != null? altText : mSuggestions.get(wordIndex);
|
CharSequence word = altText != null? altText : mSuggestions.get(wordIndex);
|
||||||
mPreviewText.setText(word);
|
mPreviewText.setText(word);
|
||||||
|
@ -475,4 +482,10 @@ public class CandidateView extends View {
|
||||||
showPreview(0, getContext().getResources().getString(R.string.added_word, word));
|
showPreview(0, getContext().getResources().getString(R.string.added_word, word));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
hidePreview();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue