Unbundling phase 1.
Removed dependency on mScrollX which is a hidden field. Added some required static libraries. TODO: When BackupManager is ready, make sure we don't use any private APIs from there.main
parent
4fc0193879
commit
7a722cbfc8
|
@ -13,5 +13,8 @@ LOCAL_JNI_SHARED_LIBRARIES := libjni_latinime
|
||||||
|
|
||||||
#LOCAL_AAPT_FLAGS := -0 .dict
|
#LOCAL_AAPT_FLAGS := -0 .dict
|
||||||
|
|
||||||
|
#LOCAL_SDK_VERSION := current
|
||||||
|
|
||||||
|
LOCAL_STATIC_JAVA_LIBRARIES := google-common android-common
|
||||||
include $(BUILD_PACKAGE)
|
include $(BUILD_PACKAGE)
|
||||||
include $(LOCAL_PATH)/dictionary/Android.mk
|
include $(LOCAL_PATH)/dictionary/Android.mk
|
||||||
|
|
|
@ -139,7 +139,7 @@ public class CandidateView extends View {
|
||||||
@Override
|
@Override
|
||||||
public void onLongPress(MotionEvent me) {
|
public void onLongPress(MotionEvent me) {
|
||||||
if (mSuggestions.size() > 0) {
|
if (mSuggestions.size() > 0) {
|
||||||
if (me.getX() + mScrollX < mWordWidth[0] && mScrollX < 10) {
|
if (me.getX() + getScrollX() < mWordWidth[0] && getScrollX() < 10) {
|
||||||
longPressFirstWord();
|
longPressFirstWord();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,14 +150,16 @@ public class CandidateView extends View {
|
||||||
float distanceX, float distanceY) {
|
float distanceX, float distanceY) {
|
||||||
final int width = getWidth();
|
final int width = getWidth();
|
||||||
mScrolled = true;
|
mScrolled = true;
|
||||||
mScrollX += (int) distanceX;
|
int scrollX = getScrollX();
|
||||||
if (mScrollX < 0) {
|
scrollX += (int) distanceX;
|
||||||
mScrollX = 0;
|
if (scrollX < 0) {
|
||||||
|
scrollX = 0;
|
||||||
}
|
}
|
||||||
if (distanceX > 0 && mScrollX + width > mTotalWidth) {
|
if (distanceX > 0 && scrollX + width > mTotalWidth) {
|
||||||
mScrollX -= (int) distanceX;
|
scrollX -= (int) distanceX;
|
||||||
}
|
}
|
||||||
mTargetScrollX = mScrollX;
|
mTargetScrollX = scrollX;
|
||||||
|
scrollTo(scrollX, getScrollY());
|
||||||
hidePreview();
|
hidePreview();
|
||||||
invalidate();
|
invalidate();
|
||||||
return true;
|
return true;
|
||||||
|
@ -167,7 +169,7 @@ public class CandidateView extends View {
|
||||||
setWillNotDraw(false);
|
setWillNotDraw(false);
|
||||||
setHorizontalScrollBarEnabled(false);
|
setHorizontalScrollBarEnabled(false);
|
||||||
setVerticalScrollBarEnabled(false);
|
setVerticalScrollBarEnabled(false);
|
||||||
mScrollX = 0;
|
scrollTo(0, getScrollY());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -210,7 +212,7 @@ public class CandidateView extends View {
|
||||||
final Rect bgPadding = mBgPadding;
|
final Rect bgPadding = mBgPadding;
|
||||||
final Paint paint = mPaint;
|
final Paint paint = mPaint;
|
||||||
final int touchX = mTouchX;
|
final int touchX = mTouchX;
|
||||||
final int scrollX = mScrollX;
|
final int scrollX = getScrollX();
|
||||||
final boolean scrolled = mScrolled;
|
final boolean scrolled = mScrolled;
|
||||||
final boolean typedWordValid = mTypedWordValid;
|
final boolean typedWordValid = mTypedWordValid;
|
||||||
final int y = (int) (height + mPaint.getTextSize() - mDescent) / 2;
|
final int y = (int) (height + mPaint.getTextSize() - mDescent) / 2;
|
||||||
|
@ -261,23 +263,30 @@ public class CandidateView extends View {
|
||||||
x += wordWidth;
|
x += wordWidth;
|
||||||
}
|
}
|
||||||
mTotalWidth = x;
|
mTotalWidth = x;
|
||||||
if (mTargetScrollX != mScrollX) {
|
if (mTargetScrollX != scrollX) {
|
||||||
scrollToTarget();
|
scrollToTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollToTarget() {
|
private void scrollToTarget() {
|
||||||
if (mTargetScrollX > mScrollX) {
|
int scrollX = getScrollX();
|
||||||
mScrollX += SCROLL_PIXELS;
|
if (mTargetScrollX > scrollX) {
|
||||||
if (mScrollX >= mTargetScrollX) {
|
scrollX += SCROLL_PIXELS;
|
||||||
mScrollX = mTargetScrollX;
|
if (scrollX >= mTargetScrollX) {
|
||||||
|
scrollX = mTargetScrollX;
|
||||||
|
scrollTo(scrollX, getScrollY());
|
||||||
requestLayout();
|
requestLayout();
|
||||||
|
} else {
|
||||||
|
scrollTo(scrollX, getScrollY());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mScrollX -= SCROLL_PIXELS;
|
scrollX -= SCROLL_PIXELS;
|
||||||
if (mScrollX <= mTargetScrollX) {
|
if (scrollX <= mTargetScrollX) {
|
||||||
mScrollX = mTargetScrollX;
|
scrollX = mTargetScrollX;
|
||||||
|
scrollTo(scrollX, getScrollY());
|
||||||
requestLayout();
|
requestLayout();
|
||||||
|
} else {
|
||||||
|
scrollTo(scrollX, getScrollY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
invalidate();
|
invalidate();
|
||||||
|
@ -291,7 +300,7 @@ public class CandidateView extends View {
|
||||||
}
|
}
|
||||||
mShowingCompletions = completions;
|
mShowingCompletions = completions;
|
||||||
mTypedWordValid = typedWordValid;
|
mTypedWordValid = typedWordValid;
|
||||||
mScrollX = 0;
|
scrollTo(0, getScrollY());
|
||||||
mTargetScrollX = 0;
|
mTargetScrollX = 0;
|
||||||
mHaveMinimalSuggestion = haveMinimalSuggestion;
|
mHaveMinimalSuggestion = haveMinimalSuggestion;
|
||||||
// Compute the total width
|
// Compute the total width
|
||||||
|
@ -305,8 +314,8 @@ public class CandidateView extends View {
|
||||||
final int count = mSuggestions.size();
|
final int count = mSuggestions.size();
|
||||||
int firstItem = 0; // Actually just before the first item, if at the boundary
|
int firstItem = 0; // Actually just before the first item, if at the boundary
|
||||||
while (i < count) {
|
while (i < count) {
|
||||||
if (mWordX[i] < mScrollX
|
if (mWordX[i] < getScrollX()
|
||||||
&& mWordX[i] + mWordWidth[i] >= mScrollX - 1) {
|
&& mWordX[i] + mWordWidth[i] >= getScrollX() - 1) {
|
||||||
firstItem = i;
|
firstItem = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -319,9 +328,10 @@ public class CandidateView extends View {
|
||||||
|
|
||||||
public void scrollNext() {
|
public void scrollNext() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int targetX = mScrollX;
|
int scrollX = getScrollX();
|
||||||
|
int targetX = scrollX;
|
||||||
final int count = mSuggestions.size();
|
final int count = mSuggestions.size();
|
||||||
int rightEdge = mScrollX + getWidth();
|
int rightEdge = scrollX + getWidth();
|
||||||
while (i < count) {
|
while (i < count) {
|
||||||
if (mWordX[i] <= rightEdge &&
|
if (mWordX[i] <= rightEdge &&
|
||||||
mWordX[i] + mWordWidth[i] >= rightEdge) {
|
mWordX[i] + mWordWidth[i] >= rightEdge) {
|
||||||
|
@ -334,7 +344,7 @@ public class CandidateView extends View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateScrollPosition(int targetX) {
|
private void updateScrollPosition(int targetX) {
|
||||||
if (targetX != mScrollX) {
|
if (targetX != getScrollX()) {
|
||||||
// TODO: Animate
|
// TODO: Animate
|
||||||
mTargetScrollX = targetX;
|
mTargetScrollX = targetX;
|
||||||
requestLayout();
|
requestLayout();
|
||||||
|
@ -452,7 +462,7 @@ public class CandidateView extends View {
|
||||||
+ mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight();
|
+ mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight();
|
||||||
final int popupHeight = mPreviewText.getMeasuredHeight();
|
final int popupHeight = mPreviewText.getMeasuredHeight();
|
||||||
//mPreviewText.setVisibility(INVISIBLE);
|
//mPreviewText.setVisibility(INVISIBLE);
|
||||||
mPopupPreviewX = mWordX[wordIndex] - mPreviewText.getPaddingLeft() - mScrollX;
|
mPopupPreviewX = mWordX[wordIndex] - mPreviewText.getPaddingLeft() - getScrollX();
|
||||||
mPopupPreviewY = - popupHeight;
|
mPopupPreviewY = - popupHeight;
|
||||||
mHandler.removeMessages(MSG_REMOVE_PREVIEW);
|
mHandler.removeMessages(MSG_REMOVE_PREVIEW);
|
||||||
int [] offsetInWindow = new int[2];
|
int [] offsetInWindow = new int[2];
|
||||||
|
|
Loading…
Reference in New Issue