OSDN Git Service

Backup...
authorHiromitsu Shioya <hiroshica@gmail.com>
Sun, 13 Dec 2009 16:20:38 +0000 (01:20 +0900)
committerHiromitsu Shioya <hiroshica@gmail.com>
Sun, 13 Dec 2009 16:20:38 +0000 (01:20 +0900)
res/drawable/icon.png
res/layout/candidates.xml
src/com/hiroshica/android/input/nicownn2/TextCandidatesViewManager.java

index 7291363..3f08ddc 100644 (file)
Binary files a/res/drawable/icon.png and b/res/drawable/icon.png differ
index 45cfc15..2c5ebad 100644 (file)
@@ -1,19 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
- Copyright (C) 2008,2009  OMRON SOFTWARE Co., Ltd.
   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.
- You may obtain a copy of the License at
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
 
-      http://www.apache.org/licenses/LICENSE-2.0
+    http://www.apache.org/licenses/LICENSE-2.0
 
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
+  -->
 <!-- candidate list -->
 <FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
      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_width="fill_parent" 
+       android:layout_height="wrap_content"
+       android:background="@color/candidate_back"
        >
-      <LinearLayout 
-        android:id="@+id/candview_base"
-        android:orientation="vertical"
-        android:layout_width="fill_parent" 
-        android:layout_height="wrap_content"
-        android:background="@color/candidate_back"
-        >
-         <RelativeLayout 
-             android:id="@+id/candidates_2nd_view"
-             android:layout_width="fill_parent" 
-             android:layout_height="wrap_content"
-             android:background="@color/candidate_back"
-             />
-      </LinearLayout>
-    </HorizontalScrollView>
+      <!--
+         <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/candidates_1st_view"
+              android:layout_width="fill_parent" 
+              android:layout_height="wrap_content" 
+               android:background="@color/candidate_back"
+              >
+           </LinearLayout>
+         </HorizontalScrollView>
+         -->
+      <Gallery android:id="@+id/candidates_list"
+              android:layout_width="fill_parent"
+              android:layout_height="wrap_content"
+              android:background="@color/candidate_back"
+              />
+      <RelativeLayout 
+         android:id="@+id/candidates_2nd_view"
+         android:layout_width="fill_parent" 
+         android:layout_height="wrap_content"
+         android:background="@color/candidate_back"
+         />
+    </LinearLayout>
   </ScrollView>
 </FrameLayout>
index 3c63e3e..84a92a6 100644 (file)
@@ -50,6 +50,7 @@ import android.widget.TextView;
 import android.widget.EditText;
 import android.widget.RelativeLayout;
 import android.widget.ImageView;
+import android.widget.Gallery;
 import android.graphics.drawable.Drawable;
 
 /**
@@ -79,7 +80,8 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
     /** Body view of the candidates list */
     private ViewGroup  mViewBody;
     /** Scroller of {@code mViewBodyText} */
-    private ScrollView           mViewBodyScroll;
+    private ScrollView           mViewBodyVScroll;
+    private HorizontalScrollView mViewBodyHScroll;
 
        private boolean mIsScroll;
     /** Base of {@code mViewCandidateList1st}, {@code mViewCandidateList2nd} */
@@ -87,9 +89,10 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
     /** The view of the scaling up candidate */
     private View mViewScaleUp;
     /** Layout for the candidates list on normal view */
-    //private LinearLayout mViewCandidateList1st;
+    private LinearLayout  mViewCandidateList1st;
     /** Layout for the candidates list on full view */
     private RelativeLayout mViewCandidateList2nd;
+
     /** {@link NicoWnn} instance using this manager */
     private NicoWnn mWnn;
     /** View type (VIEW_TYPE_NORMAL or VIEW_TYPE_FULL or VIEW_TYPE_CLOSE) */
@@ -141,6 +144,8 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
 
        private boolean mIsCreateFullView = false;
 
+       private boolean mIsLockHScroll = false;
+
     /** The event object for "touch" */
     private MotionEvent mMotionEvent = null;
 
@@ -167,7 +172,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
     /** Number of lines in normal view */
     private int mNormalViewWordCountOfLine;
     /** general infomation about a display */
-    private final DisplayMetrics mMetrics = new DisplayMetrics();
+    private static final DisplayMetrics mMetrics = new DisplayMetrics();
 
        // docomo emoji hashmap
        private static final HashMap<String, Integer> DOCOMO_EMOJI_TABLE = new HashMap<String, Integer>() {{
@@ -346,15 +351,24 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
         LayoutInflater inflater = parent.getLayoutInflater();
         mViewBody = (ViewGroup)inflater.inflate(R.layout.candidates, null);
 
-        mViewBodyScroll = (ScrollView)mViewBody.findViewById(R.id.candview_scroll);
-        mViewBodyScroll.setOnTouchListener(mCandidateOnTouch);
+        mViewBodyVScroll = (ScrollView)mViewBody.findViewById(R.id.candview_scroll);
+        mViewBodyVScroll.setOnTouchListener(mCandidateOnTouch);
+
+        mViewBodyHScroll = (HorizontalScrollView)mViewBody.findViewById(R.id.candview_hscroll);
+        mViewBodyHScroll.setOnTouchListener(mCandidateOnTouch);
+               mIsLockHScroll = false;
 
         mViewCandidateBase = (ViewGroup)mViewBody.findViewById(R.id.candview_base);
 
+        mViewCandidateList1st = (LinearLayout)mViewBody.findViewById(R.id.candidates_1st_view);
+        mViewCandidateList1st.setOnTouchListener(mCandidateOnTouch);
+        mViewCandidateList1st.setOnClickListener(mCandidateOnClick);
+
         mViewCandidateList2nd = (RelativeLayout)mViewBody.findViewById(R.id.candidates_2nd_view);
         mViewCandidateList2nd.setOnTouchListener(mCandidateOnTouch);
         mViewCandidateList2nd.setOnClickListener(mCandidateOnClick);
 
+
                // create first textView
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(getCandidateMinimumWidth(), getCandidateMinimumHeight());
                params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
@@ -401,9 +415,26 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
     /** @see CandidatesViewManager#setViewType */
     public void setViewType(int type) {
         boolean readMore = setViewLayout(type);
-
+               
         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);
                                mIsCreateFullView = true;
                        }
@@ -441,19 +472,25 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
         switch (type) {
         case CandidatesViewManager.VIEW_TYPE_CLOSE:
             mViewCandidateBase.setMinimumHeight(-1);
+                       mIsLockHScroll = false;
             return false;
 
         case CandidatesViewManager.VIEW_TYPE_NORMAL:
                        clearNormalCandidates();
-            mViewBodyScroll.scrollTo(0, 0);
-            mViewCandidateList2nd.setVisibility(View.VISIBLE);
+            mViewBodyVScroll.scrollTo(0, 0);
+                       if (false == mIsLockHScroll) {
+                               mViewBodyHScroll.scrollTo(0, 0);
+                       }
+            mViewCandidateList1st.setVisibility(View.VISIBLE);
+            mViewCandidateList2nd.setVisibility(View.GONE);
             mViewCandidateBase.setMinimumHeight(-1);
             int line = (mPortrait) ? LINE_NUM_PORTRAIT : LINE_NUM_LANDSCAPE;
-            mViewCandidateList2nd.setMinimumHeight(getCandidateMinimumHeight() * line);
+            mViewCandidateList1st.setMinimumHeight(getCandidateMinimumHeight() * line);
             return false;
                        
         case CandidatesViewManager.VIEW_TYPE_FULL:
         default:
+            mViewCandidateList1st.setVisibility(View.GONE);
             mViewCandidateList2nd.setVisibility(View.VISIBLE);
             mViewCandidateList2nd.setMinimumHeight(mViewHeight);
             mViewCandidateBase.setMinimumHeight(mViewHeight);
@@ -485,6 +522,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
         mNormalViewWordCountOfLine = 0;
                mIsCreateFullView = false;
                mIsScroll = false;
+               mIsLockHScroll = false;
 
         clearCandidates();
         mConverter = converter;
@@ -493,7 +531,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
 
                setViewLayout(CandidatesViewManager.VIEW_TYPE_NORMAL);
 
-        displayCandidates(converter, true, getMaxLine());
+        //display1stCandidates(converter);
     }
        /*
         * 
@@ -508,6 +546,10 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                int indentWidth = mViewWidth / FULL_VIEW_DIV;
                int maxindex = DISPLAY_LINE_MAX_COUNT * FULL_VIEW_DIV;
 
+               CandidateAdapter  adapter = new CandidateAdapter(mWnn);
+               Gallery gallery = (Gallery)mViewBody.findViewById(R.id.candidates_list);
+               gallery.setAdapter(adapter);
+
                do {
                        result = converter.getNextCandidate();
             if (result == null) {
@@ -519,6 +561,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                        mWnnWordArray.add(index, result);
                        mWnnWordTextLength.add(index, textLength);
                        mWnnWordOccupyCount.add(index, occupyCount);
+                       adapter.addData(index, result, textLength, occupyCount);
                        index++;
                } while (index < maxindex);
        }
@@ -529,6 +572,44 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
         return maxLine;
     }
 
+
+       /*
+        *
+        */
+    synchronized private void display1stCandidates(WnnEngine converter) {
+        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 size = mWnnWordArray.size();
+               while (mWordCount < size) {
+                       result = mWnnWordArray.get(mWordCount);
+            set1stCandidate(result, mWnnWordTextLength.get(mWordCount), mWnnWordOccupyCount.get(mWordCount));
+        }
+        if (mWordCount < 1) { /* no candidates */
+            if (mAutoHideMode) {
+                mWnn.setCandidatesViewShown(false);
+                return;
+            } else {
+                mCanReadMore = false;
+                mIsFullView = false;
+                setViewLayout(CandidatesViewManager.VIEW_TYPE_NORMAL);
+            }
+        }
+               else{
+                       mCanReadMore = true;
+               }
+        if (!(mViewBody.isShown())) {
+            mWnn.setCandidatesViewShown(true);
+        }
+    }
     /**
      * Display the candidates.
      * 
@@ -582,6 +663,53 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
     }
 
     /**
+        * 
+     */
+    private void set1stCandidate(WnnWord word, int textLength, int occupyCount) {
+        int maxWidth = mViewWidth;
+
+        TextView textView;
+               int indentWidth = mViewWidth / FULL_VIEW_DIV;
+
+               LinearLayout layout = mViewCandidateList1st;
+
+               int width = indentWidth * occupyCount;
+               int height = getCandidateMinimumHeight();
+               //LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);
+
+               LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
+                                                                                                        ViewGroup.LayoutParams.WRAP_CONTENT);
+               params.weight = 0;
+               params.gravity = Gravity.RIGHT;
+
+               textView = (TextView) layout.getChildAt(mWordCount);
+               if (textView == null) {
+                       textView = createCandidateView();
+                       textView.setLayoutParams(params);
+                       
+                       mViewCandidateList1st.addView(textView);
+               } else {
+                       mViewCandidateList1st.updateViewLayout(textView, params);
+               }
+               int textId = mWordCount+1;
+
+        textView.setText(word.candidate);
+        textView.setTextColor(mTextColor);
+        textView.setId(textId);
+        textView.setVisibility(View.VISIBLE);
+        textView.setPressed(false);
+               textView.setEllipsize(TextUtils.TruncateAt.END);
+
+               textView.setOnClickListener(mCandidateOnClick);
+               textView.setOnLongClickListener(mCandidateOnLongClick);
+               textView.setBackgroundResource(R.drawable.cand_back);
+
+        textView.setOnTouchListener(mCandidateOnTouch);
+
+               checkImageSpan(textView, word);
+        mWordCount++;
+       }
+    /**
      * Add a candidate into the list.
      * @param word        A candidate word
      */
@@ -679,7 +807,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
         * @return the view
         */
        private TextView createCandidateView() {
-               TextView text = new TextView(mViewBodyScroll.getContext());
+               TextView text = new TextView(mViewBodyVScroll.getContext());
                text.setTextSize(20);
                text.setBackgroundResource(R.drawable.cand_back);
                text.setGravity(Gravity.CENTER);
@@ -695,10 +823,17 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
 
     /** @see CandidatesViewManager#clearCandidates */
     public void clearCandidates() {
-        RelativeLayout layout = mViewCandidateList2nd;
-        int size = layout.getChildCount();
+        LinearLayout layout1st = mViewCandidateList1st;
+        int size = layout1st.getChildCount();
         for (int i = 0; i < size; i++) {
-            View v = layout.getChildAt(i);
+            View v = layout1st.getChildAt(i);
+            v.setVisibility(View.GONE);
+        }
+
+        RelativeLayout layout2nd = mViewCandidateList2nd;
+               size = layout2nd.getChildCount();
+        for (int i = 0; i < size; i++) {
+            View v = layout2nd.getChildAt(i);
             v.setVisibility(View.GONE);
         }
     
@@ -728,12 +863,14 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                if (false == mIsCreateFullView) {
                        return;
                }
+               /*
         RelativeLayout layout = mViewCandidateList2nd;
         int size = layout.getChildCount();
         for (int i = mToplineLastId; i < size; i++) {
             View v = layout.getChildAt(i);
             v.setVisibility(View.GONE);
         }
+               */
                if (mTotalLastId > mToplineLastId) {
                        mCanReadMore = true;
                        mIsScroll    = false;
@@ -821,6 +958,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
             try { mSound.seekTo(0); mSound.start(); } catch (Exception ex) { }
         }
         mWnn.onEvent(new NicoWnnEvent(NicoWnnEvent.SELECT_CANDIDATE, word));
+               mIsLockHScroll = true;
     }
 
     /** @see android.view.GestureDetector.OnGestureListener#onDown */
@@ -836,7 +974,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
 
         boolean consumed = false;
         //if (arg1 != null && arg0 != null && arg1.getY() < arg0.getY()) {
-               if (arg3 < -CANDIDATE_MINIMUM_HEIGHT) {
+               if (arg3 < -(CANDIDATE_MINIMUM_HEIGHT * 3)) {
             if ((mViewType == CandidatesViewManager.VIEW_TYPE_NORMAL) && mCanReadMore) {
                 if (mVibrator != null) {
                     try { mVibrator.vibrate(30); } catch (Exception ex) { }
@@ -849,7 +987,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
                }
                //else if (arg1 != null && arg0 != null && arg1.getY() > arg0.getY()) {
                else if (arg3 > CANDIDATE_MINIMUM_HEIGHT) {
-            if (mViewBodyScroll.getScrollY() == 0) {
+            if (mViewBodyVScroll.getScrollY() == 0) {
                                if (true == mIsScroll) {
                                        mIsScroll = false;
                                        return false;
@@ -873,7 +1011,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
 
     /** @see android.view.GestureDetector.OnGestureListener#onScroll */
     public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) {
-               if (mViewBodyScroll.getScrollY() != 0) {
+               if (mViewBodyVScroll.getScrollY() != 0) {
                        mIsScroll = true;
                }
         return false;
@@ -912,6 +1050,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
         }
         if (up) {
             setViewLayout(CandidatesViewManager.VIEW_TYPE_NORMAL);
+            mViewCandidateList1st.setVisibility(View.GONE);
             mViewCandidateList2nd.setVisibility(View.GONE);
             mViewCandidateBase.setMinimumHeight(-1);
             mViewCandidateBase.addView(mViewScaleUp);
@@ -919,7 +1058,7 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
             text.setText(word.candidate);
                        checkImageSpan(text, word);
             if (!mPortrait) {
-                Resources r = mViewBodyScroll.getContext().getResources();
+                Resources r = mViewBodyVScroll.getContext().getResources();
                 text.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_delete_word_size_landscape));
             }
 
@@ -942,14 +1081,14 @@ public class TextCandidatesViewManager implements CandidatesViewManager, Gesture
     /**
      * @return the minimum width of a candidate view.
      */
-    private int getCandidateMinimumWidth() {
+    public static int getCandidateMinimumWidth() {
         return (int)(CANDIDATE_MINIMUM_WIDTH * mMetrics.density);
     }
 
     /**
      * @return the minimum height of a candidate view.
      */
-    private int getCandidateMinimumHeight() {
+    public static int getCandidateMinimumHeight() {
         return (int)(CANDIDATE_MINIMUM_HEIGHT * mMetrics.density);
     }