<?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>
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.ImageView;
+import android.widget.Gallery;
import android.graphics.drawable.Drawable;
/**
/** 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} */
/** 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) */
private boolean mIsCreateFullView = false;
+ private boolean mIsLockHScroll = false;
+
/** The event object for "touch" */
private MotionEvent mMotionEvent = null;
/** 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>() {{
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);
/** @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;
}
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);
mNormalViewWordCountOfLine = 0;
mIsCreateFullView = false;
mIsScroll = false;
+ mIsLockHScroll = false;
clearCandidates();
mConverter = converter;
setViewLayout(CandidatesViewManager.VIEW_TYPE_NORMAL);
- displayCandidates(converter, true, getMaxLine());
+ //display1stCandidates(converter);
}
/*
*
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) {
mWnnWordArray.add(index, result);
mWnnWordTextLength.add(index, textLength);
mWnnWordOccupyCount.add(index, occupyCount);
+ adapter.addData(index, result, textLength, occupyCount);
index++;
} while (index < maxindex);
}
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.
*
}
/**
+ *
+ */
+ 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
*/
* @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);
/** @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);
}
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;
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 */
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) { }
}
//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;
/** @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;
}
if (up) {
setViewLayout(CandidatesViewManager.VIEW_TYPE_NORMAL);
+ mViewCandidateList1st.setVisibility(View.GONE);
mViewCandidateList2nd.setVisibility(View.GONE);
mViewCandidateBase.setMinimumHeight(-1);
mViewCandidateBase.addView(mViewScaleUp);
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));
}
/**
* @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);
}