/*
- * Copyright (C) 2008,2009 OMRON SOFTWARE Co., Ltd.
+dis * Copyright (C) 2008,2009 OMRON SOFTWARE Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import android.content.res.Configuration;
import android.content.res.Resources;
import android.media.MediaPlayer;
+import android.os.AsyncTask;
import android.os.Vibrator;
import android.text.TextUtils;
import android.text.TextPaint;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.RelativeLayout;
-import android.widget.ImageView;
-import android.widget.Gallery;
-import android.widget.ListView;
import android.graphics.drawable.Drawable;
/**
private static final int CANDIDATE_MINIMUM_WIDTH = 48;
/** Height of the view */
private static final int CANDIDATE_MINIMUM_HEIGHT = 42;
- /** Align the candidate left if the width of the string exceeds this threshold */
- private static final int CANDIDATE_LEFT_ALIGN_THRESHOLD = 120;
/** Maximum number of displaying candidates par one line (full view mode) */
private static final int FULL_VIEW_DIV = 5;
/** Whether hide the view if there is no candidates */
private boolean mAutoHideMode;
/** The converter to be get candidates from and notice the selected candidate to. */
- private WnnEngine mConverter;
- /** Limitation of displaying candidates */
- private int mDisplayLimit;
-
+ public WnnEngine mConverter;
/** Vibrator for touch vibration */
private Vibrator mVibrator = null;
/** MediaPlayer for click sound */
private MediaPlayer mSound = null;
/** Number of candidates displaying */
- private int mWordCount;
- private int m1stWordCount;
- private int[] mWnnLineCount = new int[LINE_NUM_MAX];
- private int[] mWnnLineCountMax = new int[LINE_NUM_MAX];
+ int mWordCount;
+ int m1stWordCount;
+ int[] mWnnLineCount = new int[LINE_NUM_MAX];
+ int[] mWnnLineCountMax = new int[LINE_NUM_MAX];
private int[] mWnnLineOffset = new int[LINE_NUM_MAX];
/** portrait/landscape line */
- private static final HashMap<String, Integer> lineModeTable = new HashMap<String, Integer>() {{
+ private static final HashMap<String, Integer> lineModeTable = new HashMap<String, Integer>() {/**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ {
put("1_1", 0);
put("2_1", 1);
put("1_2", 2);
private GestureDetector mGestureDetector;
/** The word pressed */
private WnnWord mWord;
- /** Character width of the candidate area */
- private int mLineLength = 0;
/** Number of lines displayed */
private int mLineCount = 1;
/** The event object for "touch" */
private MotionEvent mMotionEvent = null;
- /** The offset when the candidates is flowed out the candidate window */
- private int mDisplayEndOffset = 0;
/** {@code true} if there are more candidates to display. */
private boolean mCanReadMore = false;
/** Width of {@code mReadMoreButton} */
private RelativeLayout.LayoutParams mFullViewPrevParams;
/** Whether all candidates is displayed */
private boolean mCreateCandidateDone;
- /** Number of lines in normal view */
- private int mNormalViewWordCountOfLine;
/** general infomation about a display */
private static final DisplayMetrics mMetrics = new DisplayMetrics();
+ /* asynctask */
+ private TextCandidateTask mCandidateTask = null;
+ private boolean mIsActiveTask = false;
+
// docomo emoji hashmap
- private static final HashMap<String, Integer> DOCOMO_EMOJI_TABLE = new HashMap<String, Integer>() {{
+ private static final HashMap<String, Integer> DOCOMO_EMOJI_TABLE = new HashMap<String, Integer>() {/**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ {
put("\uE63E", R.drawable.docomo_1); put("\uE63F", R.drawable.docomo_2); put("\uE640", R.drawable.docomo_3); put("\uE641", R.drawable.docomo_4);
put("\uE642", R.drawable.docomo_5); put("\uE643", R.drawable.docomo_6); put("\uE644", R.drawable.docomo_7); put("\uE645", R.drawable.docomo_8);
put("\uE646", R.drawable.docomo_9); put("\uE647", R.drawable.docomo_10); put("\uE648", R.drawable.docomo_11); put("\uE649", R.drawable.docomo_12);
* @param displayLimit The limit of display
*/
public TextCandidatesViewManager(int displayLimit) {
- this.mDisplayLimit = displayLimit;
this.mWnnWordArray = new ArrayList<WnnWord>();
this.mWnnWordTextLength = new ArrayList<Integer>();
this.mWnnWordOccupyCount = new ArrayList<Integer>();
this.mAutoHideMode = true;
+ this.mIsActiveTask = false;
mMetrics.setToDefaults();
}
if (readMore) {
if (false == mIsCreateFullView) {
mCanReadMore = false;
- mDisplayEndOffset = 0;
mFullViewWordCount = 0;
mFullViewOccupyCount = 0;
mFullViewPrevLineTopId = 0;
mCreateCandidateDone = false;
- mNormalViewWordCountOfLine = 0;
mIsScroll = false;
mLineCount = 1;
mWordCount = 0;
mToplineLastId = 0;
mTotalLastId = 0;
- mLineLength = 0;
-
mIsLockHScroll = false;
displayCandidates(this.mConverter, false, -1);
switch (type) {
case CandidatesViewManager.VIEW_TYPE_CLOSE:
+ checkCandidateTask();
mViewCandidateBase.setMinimumHeight(-1);
//mIsLockHScroll = false;
return false;
mNoSpace = pref.getBoolean("nospace_candidate", false);
mCanReadMore = false;
- mDisplayEndOffset = 0;
mIsFullView = false;
mFullViewWordCount = 0;
mFullViewOccupyCount = 0;
mFullViewPrevLineTopId = 0;
mCreateCandidateDone = false;
- mNormalViewWordCountOfLine = 0;
mIsCreateFullView = false;
mIsScroll = false;
createWnnWordArray();
setViewLayout(CandidatesViewManager.VIEW_TYPE_NORMAL);
-
- display1stCandidates(converter, mViewWidth * 3);
+ /* create normalview */
+ display1stCandidates(mConverter, mViewWidth);
mTargetScrollWidth = mViewWidth / 2;
-
- //if (false == mIsLockHScroll) {
mViewBodyHScroll.scrollTo(0, 0);
- //}
mIsLockHScroll = false;
+ /* create background normalview */
+ //int viewWidth = mViewWidth * 2;
+ int viewWidth = mViewWidth * 1000;
+ mCandidateTask = new TextCandidateTask(this);
+ if (null != mCandidateTask) {
+ mIsActiveTask = true;
+ mCandidateTask.execute(viewWidth);
+ }
+ }
+ /*
+ *
+ */
+ public void checkCandidateTask() {
+ if (null != mCandidateTask) {
+ AsyncTask.Status status = mCandidateTask.getStatus();
+ if (status == AsyncTask.Status.RUNNING) {
+ // canceled
+ mCandidateTask.cancel(true);
+ }
+ }
}
/*
*
}
/** @see CandidatesViewManager#getMaxLine */
- private int getMaxLine() {
+ int getMaxLine() {
//int maxLine = (mPortrait) ? LINE_NUM_PORTRAIT : LINE_NUM_LANDSCAPE;
int maxLine = (mPortrait) ? mPortraitLine : mLandscapeLine;
return maxLine;
if (converter == null) {
return;
}
- /* Concatenate the candidates already got and the last one in dispFirst mode */
- int displayLimit = mDisplayLimit;
-
- boolean isHistorySequence = false;
- boolean isBreak = false;
-
/* Get candidates */
WnnWord result = null;
int maxline = getMaxLine();
calcid = wordcount + offset;
result = mWnnWordArray.get(calcid);
calcwidth += mWnnWordTextLength.get(calcid);
- set1stCandidate(calcid, result, mWnnWordTextLength.get(calcid), mWnnWordOccupyCount.get(calcid), lineView);
+ set1stCandidate(wordcount, calcid, result, mWnnWordTextLength.get(calcid), mWnnWordOccupyCount.get(calcid), lineView);
wordcount++;
if (calcwidth >= width) {
break;
mWnn.setCandidatesViewShown(true);
}
}
+ /*
+ *
+ */
+ public boolean display1stCandidates(int line, int count) {
+ if (false == mIsActiveTask) {
+ return true;
+ }
+ boolean result = false;
+
+ int wordcount = 0;
+ int size = 0;
+ int offset = 0;
+ int calcid = 0;
+ wordcount = mWnnLineCount[line];
+ size = mWnnLineCountMax[line];
+ offset = mWnnLineOffset[line];
+ LinearLayout candidateList = mViewCandidateList1st;
+ LinearLayout lineView = (LinearLayout)candidateList.getChildAt(line);
+
+ for (int iI = 0; iI < count; ++iI) {
+ if (wordcount >= size) {
+ result = true;
+ break;
+ }
+ calcid = wordcount + offset;
+ WnnWord wnnword = null;
+ try {
+ wnnword = mWnnWordArray.get(calcid);
+ } catch (Exception e) {
+ mWnnLineCount[line] = mWnnLineCountMax[line];
+ return true;
+ }
+ set1stCandidate(wordcount, calcid, wnnword, mWnnWordTextLength.get(calcid), mWnnWordOccupyCount.get(calcid), lineView);
+ wordcount++;
+ }
+ mWnnLineCount[line] = wordcount;
+ return result;
+ }
+ public void invalidate1stView() {
+ mViewCandidateList1st.invalidate();
+ }
+ /*
+ *
+ */
+ public void display1stLastSetup() {
+ m1stWordCount = mWordCount;
+ /*
+ if (mWordCount < 1) { // no candidates
+ if (mAutoHideMode) {
+ mWnn.setCandidatesViewShown(false);
+ } else {
+ mCanReadMore = false;
+ mIsFullView = false;
+ setViewLayout(CandidatesViewManager.VIEW_TYPE_NORMAL);
+ }
+ }
+ else{
+ mCanReadMore = true;
+ }
+ if (!(mViewBody.isShown())) {
+ mWnn.setCandidatesViewShown(true);
+ }
+ mTargetScrollWidth = mViewWidth / 2;
+ mViewBodyHScroll.scrollTo(0, 0);
+ mIsLockHScroll = false;
+ */
+ mIsActiveTask = false;
+ }
/**
* Display the candidates.
*
if (converter == null) {
return;
}
- /* Concatenate the candidates already got and the last one in dispFirst mode */
- int displayLimit = mDisplayLimit;
-
- boolean isHistorySequence = false;
boolean isBreak = false;
/* Get candidates */
/**
*
*/
- private void set1stCandidate(int inid, WnnWord word, int textLength, int occupyCount, LinearLayout entryView) {
- int maxWidth = mViewWidth;
+ private void set1stCandidate(int viewindex, int inid, WnnWord word, int textLength, int occupyCount, LinearLayout lineView) {
TextView textView;
int indentWidth = mViewWidth / FULL_VIEW_DIV;
int width = indentWidth * occupyCount;
int height = getCandidateMinimumHeight();
- /*
- LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1.0f);
- */
- textView = (TextView) entryView.getChildAt(inid);
+ boolean iscreate = false;
+ textView = (TextView) lineView.getChildAt(viewindex);
if (textView == null) {
textView = createCandidateView();
- //textView.setLayoutParams(params);
- //textView.setGravity(Gravity.CENTER);
- //textView.setSingleLine();
-
- entryView.addView(textView);
- } else {
- //entryView.updateViewLayout(textView, params);
+ iscreate = true;
}
+
int textId = inid + 1;
-
textView.setWidth(width);
textView.setHeight(height);
textView.setText(word.candidate);
textView.setOnTouchListener(mCandidateOnTouch);
checkImageSpan(textView, word);
+ if (true == iscreate) {
+ lineView.addView(textView);
+ }
}
/**
* Add a candidate into the list.
* @param word A candidate word
*/
private void setCandidate(WnnWord word, int textLength, int occupyCount) {
- int maxWidth = mViewWidth;
-
TextView textView;
int indentWidth = mViewWidth / FULL_VIEW_DIV;
/** @see CandidatesViewManager#clearCandidates */
public void clearCandidates() {
int size = 0;
+ checkCandidateTask();
clearNormalViewCandidate();
RelativeLayout layout2nd = mViewCandidateList2nd;
mWnnWordTextLength.clear();
mWnnWordOccupyCount.clear();
- mLineLength = 0;
-
mIsFullView = false;
setViewLayout(CandidatesViewManager.VIEW_TYPE_NORMAL);
if (mAutoHideMode) {
mCanReadMore = false;
}
}
- /** clear FullCandidate */
- private void clearFullCandidates() {
- RelativeLayout layout = mViewCandidateList2nd;
- int size = layout.getChildCount();
- for (int i = 0; i < size; i++) {
- View v = layout.getChildAt(i);
- v.setVisibility(View.GONE);
- }
-
- mLineCount = 1;
- mWordCount = 0;
- mToplineLastId = 0;
- mTotalLastId = 0;
- mWnnWordArray.clear();
- mWnnWordTextLength.clear();
- mWnnWordOccupyCount.clear();
-
- mLineLength = 0;
-
- mCanReadMore = false;
- }
/** @see CandidatesViewManager#setPreferences */
public void setPreferences(SharedPreferences pref) {
try {
if (true == mIsFullView) {
return;
}
+ /*
+ if (true == mIsActiveTask) {
+ return;
+ }
boolean update = false;
int size = mWnnWordArray.size();
int getscroll = mViewBodyHScroll.getScrollX();
if (true == update) {
mViewCandidateList1st.invalidate();
}
+ */
}
/** @see android.view.GestureDetector.OnGestureListener#onShowPress */