OSDN Git Service

TextCandidateの更新方法を変更
authorHiromitsu Shioya <hiroshica@gmail.com>
Sat, 23 Jan 2010 11:25:08 +0000 (20:25 +0900)
committerHiromitsu Shioya <hiroshica@gmail.com>
Sat, 23 Jan 2010 11:25:08 +0000 (20:25 +0900)
src/com/hiroshica/android/input/nicownn2/CandidatesViewManager.java
src/com/hiroshica/android/input/nicownn2/NicoWnnJAJP.java
src/com/hiroshica/android/input/nicownn2/TextCandidatesViewManager.java

index 130c6a6..606cbda 100644 (file)
@@ -111,4 +111,7 @@ public interface CandidatesViewManager {
      * @param pref    The preferences
      */
     public void setPreferences(SharedPreferences pref);
+    
+
+       public void checkCandidateTask();
 }
index ced2758..b64be39 100644 (file)
@@ -1479,6 +1479,7 @@ public class NicoWnnJAJP extends NicoWnn {
                        return true;
                }
 
+               mCandidatesViewManager.checkCandidateTask();
                if (mConverter != null) {
                        /* initialize the converter */
                        mConverter.init();
index 9610bee..d4a12ad 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -25,6 +25,7 @@ import android.preference.PreferenceManager;
 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;
@@ -50,9 +51,6 @@ import android.widget.HorizontalScrollView;
 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;
 
 /**
@@ -79,8 +77,6 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
        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;
 
@@ -114,24 +110,26 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
        /** 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);
@@ -157,8 +155,6 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
        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;
 
@@ -177,8 +173,6 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
        /** 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} */
@@ -197,13 +191,20 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
        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);
@@ -349,11 +350,11 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
         * @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();
        }
 
@@ -485,20 +486,16 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                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);
@@ -537,6 +534,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
 
                switch (type) {
                case CandidatesViewManager.VIEW_TYPE_CLOSE:
+                       checkCandidateTask();
                        mViewCandidateBase.setMinimumHeight(-1);
                        //mIsLockHScroll = false;
                        return false;
@@ -619,13 +617,11 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                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;
 
@@ -635,14 +631,31 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                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);
+                       }
+               }
        }
        /*
         * 
@@ -691,7 +704,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
        }
 
        /** @see CandidatesViewManager#getMaxLine */
-       private int getMaxLine() {
+       int getMaxLine() {
                //int maxLine = (mPortrait) ? LINE_NUM_PORTRAIT : LINE_NUM_LANDSCAPE;
                int maxLine = (mPortrait) ? mPortraitLine : mLandscapeLine;
                return maxLine;
@@ -704,12 +717,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;
-
-               boolean isHistorySequence = false;
-               boolean isBreak = false;
-
                /* Get candidates */
                WnnWord result = null;
                int maxline = getMaxLine();
@@ -732,7 +739,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                                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;
@@ -760,6 +767,74 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                        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.
         * 
@@ -772,10 +847,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;
-
-               boolean isHistorySequence = false;
                boolean isBreak = false;
 
                /* Get candidates */
@@ -816,31 +887,20 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
        /**
         * 
         */
-       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);
@@ -857,14 +917,15 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                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;
 
@@ -989,6 +1050,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
        /** @see CandidatesViewManager#clearCandidates */
        public void clearCandidates() {
                int size = 0;
+               checkCandidateTask();
         clearNormalViewCandidate();
 
                RelativeLayout layout2nd = mViewCandidateList2nd;
@@ -1007,8 +1069,6 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                mWnnWordTextLength.clear();
                mWnnWordOccupyCount.clear();
 
-               mLineLength = 0;
-
                mIsFullView = false;
                setViewLayout(CandidatesViewManager.VIEW_TYPE_NORMAL);
                if (mAutoHideMode) {
@@ -1048,27 +1108,6 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                        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 {
@@ -1194,6 +1233,10 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                if (true == mIsFullView) {
                        return;
                }
+               /*
+               if (true == mIsActiveTask) {
+                       return;
+               }
                boolean update = false;
                int size       = mWnnWordArray.size();
                int getscroll  = mViewBodyHScroll.getScrollX();
@@ -1206,6 +1249,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                if (true == update) {
                        mViewCandidateList1st.invalidate();
                }
+               */
        }
 
        /** @see android.view.GestureDetector.OnGestureListener#onShowPress */