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
Amith Yamasani 2010-01-27 17:29:35 -08:00
parent 4fc0193879
commit 7a722cbfc8
2 changed files with 37 additions and 24 deletions

View File

@ -13,5 +13,8 @@ LOCAL_JNI_SHARED_LIBRARIES := libjni_latinime
#LOCAL_AAPT_FLAGS := -0 .dict
#LOCAL_SDK_VERSION := current
LOCAL_STATIC_JAVA_LIBRARIES := google-common android-common
include $(BUILD_PACKAGE)
include $(LOCAL_PATH)/dictionary/Android.mk

View File

@ -139,7 +139,7 @@ public class CandidateView extends View {
@Override
public void onLongPress(MotionEvent me) {
if (mSuggestions.size() > 0) {
if (me.getX() + mScrollX < mWordWidth[0] && mScrollX < 10) {
if (me.getX() + getScrollX() < mWordWidth[0] && getScrollX() < 10) {
longPressFirstWord();
}
}
@ -150,14 +150,16 @@ public class CandidateView extends View {
float distanceX, float distanceY) {
final int width = getWidth();
mScrolled = true;
mScrollX += (int) distanceX;
if (mScrollX < 0) {
mScrollX = 0;
int scrollX = getScrollX();
scrollX += (int) distanceX;
if (scrollX < 0) {
scrollX = 0;
}
if (distanceX > 0 && mScrollX + width > mTotalWidth) {
mScrollX -= (int) distanceX;
if (distanceX > 0 && scrollX + width > mTotalWidth) {
scrollX -= (int) distanceX;
}
mTargetScrollX = mScrollX;
mTargetScrollX = scrollX;
scrollTo(scrollX, getScrollY());
hidePreview();
invalidate();
return true;
@ -167,7 +169,7 @@ public class CandidateView extends View {
setWillNotDraw(false);
setHorizontalScrollBarEnabled(false);
setVerticalScrollBarEnabled(false);
mScrollX = 0;
scrollTo(0, getScrollY());
}
/**
@ -210,7 +212,7 @@ public class CandidateView extends View {
final Rect bgPadding = mBgPadding;
final Paint paint = mPaint;
final int touchX = mTouchX;
final int scrollX = mScrollX;
final int scrollX = getScrollX();
final boolean scrolled = mScrolled;
final boolean typedWordValid = mTypedWordValid;
final int y = (int) (height + mPaint.getTextSize() - mDescent) / 2;
@ -261,23 +263,30 @@ public class CandidateView extends View {
x += wordWidth;
}
mTotalWidth = x;
if (mTargetScrollX != mScrollX) {
if (mTargetScrollX != scrollX) {
scrollToTarget();
}
}
private void scrollToTarget() {
if (mTargetScrollX > mScrollX) {
mScrollX += SCROLL_PIXELS;
if (mScrollX >= mTargetScrollX) {
mScrollX = mTargetScrollX;
int scrollX = getScrollX();
if (mTargetScrollX > scrollX) {
scrollX += SCROLL_PIXELS;
if (scrollX >= mTargetScrollX) {
scrollX = mTargetScrollX;
scrollTo(scrollX, getScrollY());
requestLayout();
} else {
scrollTo(scrollX, getScrollY());
}
} else {
mScrollX -= SCROLL_PIXELS;
if (mScrollX <= mTargetScrollX) {
mScrollX = mTargetScrollX;
scrollX -= SCROLL_PIXELS;
if (scrollX <= mTargetScrollX) {
scrollX = mTargetScrollX;
scrollTo(scrollX, getScrollY());
requestLayout();
} else {
scrollTo(scrollX, getScrollY());
}
}
invalidate();
@ -291,7 +300,7 @@ public class CandidateView extends View {
}
mShowingCompletions = completions;
mTypedWordValid = typedWordValid;
mScrollX = 0;
scrollTo(0, getScrollY());
mTargetScrollX = 0;
mHaveMinimalSuggestion = haveMinimalSuggestion;
// Compute the total width
@ -305,8 +314,8 @@ public class CandidateView extends View {
final int count = mSuggestions.size();
int firstItem = 0; // Actually just before the first item, if at the boundary
while (i < count) {
if (mWordX[i] < mScrollX
&& mWordX[i] + mWordWidth[i] >= mScrollX - 1) {
if (mWordX[i] < getScrollX()
&& mWordX[i] + mWordWidth[i] >= getScrollX() - 1) {
firstItem = i;
break;
}
@ -319,9 +328,10 @@ public class CandidateView extends View {
public void scrollNext() {
int i = 0;
int targetX = mScrollX;
int scrollX = getScrollX();
int targetX = scrollX;
final int count = mSuggestions.size();
int rightEdge = mScrollX + getWidth();
int rightEdge = scrollX + getWidth();
while (i < count) {
if (mWordX[i] <= rightEdge &&
mWordX[i] + mWordWidth[i] >= rightEdge) {
@ -334,7 +344,7 @@ public class CandidateView extends View {
}
private void updateScrollPosition(int targetX) {
if (targetX != mScrollX) {
if (targetX != getScrollX()) {
// TODO: Animate
mTargetScrollX = targetX;
requestLayout();
@ -452,7 +462,7 @@ public class CandidateView extends View {
+ mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight();
final int popupHeight = mPreviewText.getMeasuredHeight();
//mPreviewText.setVisibility(INVISIBLE);
mPopupPreviewX = mWordX[wordIndex] - mPreviewText.getPaddingLeft() - mScrollX;
mPopupPreviewX = mWordX[wordIndex] - mPreviewText.getPaddingLeft() - getScrollX();
mPopupPreviewY = - popupHeight;
mHandler.removeMessages(MSG_REMOVE_PREVIEW);
int [] offsetInWindow = new int[2];