OSDN Git Service

WnnWordのcacheを行って全画面への移行処理を若干軽減してみた
authorHiromitsu Shioya <hiroshica@gmail.com>
Sat, 12 Dec 2009 18:56:15 +0000 (03:56 +0900)
committerHiromitsu Shioya <hiroshica@gmail.com>
Sat, 12 Dec 2009 18:56:15 +0000 (03:56 +0900)
res/layout/candidates.xml
src/com/hiroshica/android/input/nicownn2/TextCandidatesViewManager.java

index 31634e5..45cfc15 100644 (file)
      android:fadingEdgeLength="0dip"
      android:scrollbars="vertical"
      >
+    <HorizontalScrollView
+       android:id="@+id/candview_hscroll"
+       android:layout_width="wrap_content"
+       android:layout_height="fill_parent"
+       android:fadingEdgeLength="0dip"
+       android:scrollbars="horizontal"
+       >
       <LinearLayout 
         android:id="@+id/candview_base"
         android:orientation="vertical"
         android:layout_height="wrap_content"
         android:background="@color/candidate_back"
         >
-       <HorizontalScrollView
-          android:id="@+id/candview_scroll"
-          android:layout_width="fill_parent"
-          android:layout_height="wrap_content"
-          android:fadingEdgeLength="0dip"
-          android:scrollbars="vertical"
-          >
          <RelativeLayout 
              android:id="@+id/candidates_2nd_view"
              android:layout_width="fill_parent" 
              android:layout_height="wrap_content"
              android:background="@color/candidate_back"
              />
-       </HorizontalScrollView>
       </LinearLayout>
+    </HorizontalScrollView>
   </ScrollView>
 </FrameLayout>
index 805c89c..3c63e3e 100644 (file)
@@ -45,6 +45,7 @@ import android.view.LayoutInflater;
 import android.widget.Button;
 import android.widget.LinearLayout;
 import android.widget.ScrollView;
+import android.widget.HorizontalScrollView;
 import android.widget.TextView;
 import android.widget.EditText;
 import android.widget.RelativeLayout;
@@ -69,7 +70,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
     /** Width of the view */
     private static final int CANDIDATE_MINIMUM_WIDTH = 48;
     /** Height of the view */
-    private static final int CANDIDATE_MINIMUM_HEIGHT = 35;
+    private static final int CANDIDATE_MINIMUM_HEIGHT = 44;
     /** 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) */
@@ -78,7 +79,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
     /** Body view of the candidates list */
     private ViewGroup  mViewBody;
     /** Scroller of {@code mViewBodyText} */
-    private ScrollView mViewBodyScroll;
+    private ScrollView           mViewBodyScroll;
 
        private boolean mIsScroll;
     /** Base of {@code mViewCandidateList1st}, {@code mViewCandidateList2nd} */
@@ -120,6 +121,8 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
        private int mTotalLastId;
     /** List of candidates */
     private ArrayList<WnnWord> mWnnWordArray;
+       private ArrayList<Integer> mWnnWordTextLength;
+       private ArrayList<Integer> mWnnWordOccupyCount;
 
     /** Gesture detector */
     private GestureDetector mGestureDetector;
@@ -315,6 +318,8 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
     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;
         mMetrics.setToDefaults();
     }
@@ -408,10 +413,12 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
         } else { 
             if (type == CandidatesViewManager.VIEW_TYPE_NORMAL) {
                 mIsFullView = false;
-                if (mDisplayEndOffset > 0) {
-                    int maxLine = getMaxLine();
-                    displayCandidates(this.mConverter, false, maxLine);
-                }
+                               /*
+                                 if (mDisplayEndOffset > 0) {
+                                 int maxLine = getMaxLine();
+                                 displayCandidates(this.mConverter, false, maxLine);
+                                 }
+                               */
             } else {
                                mIsFullView = true;
                 if (mViewBody.isShown()) {
@@ -481,11 +488,40 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
 
         clearCandidates();
         mConverter = converter;
+               
+               createWnnWordArray();
 
                setViewLayout(CandidatesViewManager.VIEW_TYPE_NORMAL);
 
         displayCandidates(converter, true, getMaxLine());
     }
+       /*
+        * 
+        */
+       private void createWnnWordArray() {
+        WnnEngine converter = mConverter;
+               if (null == converter) {
+                       return;
+               }
+        WnnWord result = null;
+               int index = 0;
+               int indentWidth = mViewWidth / FULL_VIEW_DIV;
+               int maxindex = DISPLAY_LINE_MAX_COUNT * FULL_VIEW_DIV;
+
+               do {
+                       result = converter.getNextCandidate();
+            if (result == null) {
+                break;
+            }
+                       Integer textLength  = measureText(result.candidate, 0, result.candidate.length());
+                       Integer occupyCount = Math.min((textLength + indentWidth) / indentWidth, FULL_VIEW_DIV);
+
+                       mWnnWordArray.add(index, result);
+                       mWnnWordTextLength.add(index, textLength);
+                       mWnnWordOccupyCount.add(index, occupyCount);
+                       index++;
+               } while (index < maxindex);
+       }
 
     /** @see CandidatesViewManager#getMaxLine */
     private int getMaxLine() {
@@ -504,7 +540,6 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
         if (converter == null) {
             return;
         }
-
         /* Concatenate the candidates already got and the last one in dispFirst mode */
         int displayLimit = mDisplayLimit;
 
@@ -513,14 +548,10 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
 
         /* Get candidates */
         WnnWord result = null;
-        while ((displayLimit == -1 || mWordCount < displayLimit)) {
-                       result = converter.getNextCandidate();
-            if (result == null) {
-                break;
-            }
-
-            setCandidate(result);
-
+               int size = mWnnWordArray.size();
+               while (mWordCount < size) {
+                       result = mWnnWordArray.get(mWordCount);
+            setCandidate(result, mWnnWordTextLength.get(mWordCount), mWnnWordOccupyCount.get(mWordCount));
             if (dispFirst && (maxLine < mLineCount)) {
                 mCanReadMore = true;
                 isBreak = true;
@@ -554,13 +585,11 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
      * Add a candidate into the list.
      * @param word        A candidate word
      */
-    private void setCandidate(WnnWord word) {
-        int textLength = measureText(word.candidate, 0, word.candidate.length());
+    private void setCandidate(WnnWord word, int textLength, int occupyCount) {
         int maxWidth = mViewWidth;
 
         TextView textView;
                int indentWidth = mViewWidth / FULL_VIEW_DIV;
-               int occupyCount = Math.min((textLength + indentWidth) / indentWidth, FULL_VIEW_DIV);
 
                RelativeLayout layout = mViewCandidateList2nd;
 
@@ -573,7 +602,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                } else {
                        params.addRule(RelativeLayout.BELOW, mFullViewPrevLineTopId);
                }
-            
+
                if (mFullViewOccupyCount == 0) {
                        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                } else {
@@ -601,6 +630,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
         textView.setId(textId);
         textView.setVisibility(View.VISIBLE);
         textView.setPressed(false);
+               textView.setEllipsize(TextUtils.TruncateAt.END);
 
                textView.setOnClickListener(mCandidateOnClick);
                textView.setOnLongClickListener(mCandidateOnLongClick);
@@ -608,13 +638,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
 
         textView.setOnTouchListener(mCandidateOnTouch);
 
-        if (maxWidth < textLength) {
-            textView.setEllipsize(TextUtils.TruncateAt.END);
-        } else {
-            textView.setEllipsize(null);
-        }
                checkImageSpan(textView, word);
-        mWnnWordArray.add(mWordCount, word);
         mWordCount++;
                mTotalLastId = textId;
 
@@ -683,6 +707,8 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                mToplineLastId = 0;
                mTotalLastId   = 0;
         mWnnWordArray.clear();
+               mWnnWordTextLength.clear();
+               mWnnWordOccupyCount.clear();
 
         mLineLength = 0;
 
@@ -745,6 +771,8 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                mToplineLastId = 0;
                mTotalLastId   = 0;
         mWnnWordArray.clear();
+               mWnnWordTextLength.clear();
+               mWnnWordOccupyCount.clear();
 
         mLineLength = 0;