Display suggested word info in debug mode

Bug: 4686782
Change-Id: I0e5bef33aa39c3d6f75edda7818524965aa40b79
main
Tadashi G. Takaoka 2011-06-24 14:19:59 +09:00
parent 703e7252ba
commit 2442e77985
6 changed files with 151 additions and 72 deletions

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2011, The Android Open Source Project
**
** 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
**
** 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.
*/
-->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="6sp"
android:textColor="@android:color/white"
android:visibility="gone"
style="?attr/suggestionBackgroundStyle" />

View File

@ -21,15 +21,35 @@
<merge <merge
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
>
<RelativeLayout
android:layout_weight="1.0"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
> >
<include <include
android:id="@+id/candidate_left" android:id="@+id/word_left"
layout="@layout/candidate" /> layout="@layout/candidate_word" />
<include
android:id="@+id/info_left"
layout="@layout/candidate_info" />
</RelativeLayout>
<include <include
layout="@layout/candidate_divider" /> layout="@layout/candidate_divider" />
<RelativeLayout
android:layout_weight="1.0"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
>
<include <include
android:id="@+id/candidate_center" android:id="@+id/word_center"
layout="@layout/candidate" /> layout="@layout/candidate_word" />
<include
android:id="@+id/info_center"
layout="@layout/candidate_info" />
</RelativeLayout>
<include <include
layout="@layout/candidate_divider" /> layout="@layout/candidate_divider" />
<LinearLayout <LinearLayout
@ -38,10 +58,20 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
>
<RelativeLayout
android:layout_weight="1.0"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
> >
<include <include
android:id="@+id/candidate_right" android:id="@+id/word_right"
layout="@layout/candidate" /> layout="@layout/candidate_word" />
<include
android:id="@+id/info_right"
layout="@layout/candidate_info" />
</RelativeLayout>
<!-- Image drawables are set in CandidateView constructor --> <!-- Image drawables are set in CandidateView constructor -->
<ImageButton <ImageButton
android:id="@+id/expand_candidates_pane" android:id="@+id/expand_candidates_pane"

View File

@ -16,6 +16,7 @@
package com.android.inputmethod.compat; package com.android.inputmethod.compat;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams; import android.view.ViewGroup.MarginLayoutParams;
import android.widget.FrameLayout; import android.widget.FrameLayout;
@ -49,4 +50,14 @@ public class FrameLayoutCompatUtils {
+ placer.getClass().getName()); + placer.getClass().getName());
} }
} }
public static void placeViewAt(View view, int x, int y, int w, int h) {
final ViewGroup.LayoutParams lp = view.getLayoutParams();
if (lp instanceof MarginLayoutParams) {
final MarginLayoutParams marginLayoutParams = (MarginLayoutParams)lp;
marginLayoutParams.width = w;
marginLayoutParams.height = h;
marginLayoutParams.setMargins(x, y, 0, 0);
}
}
} }

View File

@ -41,7 +41,6 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewConfiguration; import android.view.ViewConfiguration;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.widget.TextView; import android.widget.TextView;
@ -998,10 +997,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// Place the key preview. // Place the key preview.
// TODO: Adjust position of key previews which touch screen edges // TODO: Adjust position of key previews which touch screen edges
final MarginLayoutParams lp = (MarginLayoutParams)previewText.getLayoutParams(); FrameLayoutCompatUtils.placeViewAt(
lp.width = previewWidth; previewText, previewX, previewY, previewWidth, previewHeight);
lp.height = previewHeight;
lp.setMargins(previewX, previewY, 0, 0);
previewText.setVisibility(VISIBLE); previewText.setVisibility(VISIBLE);
} }

View File

@ -74,6 +74,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private ViewGroup mCandidatesPaneContainer; private ViewGroup mCandidatesPaneContainer;
private View mKeyboardView; private View mKeyboardView;
private final ArrayList<TextView> mWords = new ArrayList<TextView>(); private final ArrayList<TextView> mWords = new ArrayList<TextView>();
private final ArrayList<TextView> mInfos = new ArrayList<TextView>();
private final ArrayList<View> mDividers = new ArrayList<View>(); private final ArrayList<View> mDividers = new ArrayList<View>();
private final int mCandidatePadding; private final int mCandidatePadding;
private final int mCandidateStripHeight; private final int mCandidateStripHeight;
@ -177,29 +178,32 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
mCandidatePadding = res.getDimensionPixelOffset(R.dimen.candidate_padding); mCandidatePadding = res.getDimensionPixelOffset(R.dimen.candidate_padding);
mCandidateStripHeight = res.getDimensionPixelOffset(R.dimen.candidate_strip_height); mCandidateStripHeight = res.getDimensionPixelOffset(R.dimen.candidate_strip_height);
for (int i = 0; i < MAX_SUGGESTIONS; i++) { for (int i = 0; i < MAX_SUGGESTIONS; i++) {
final TextView tv; final TextView word, info;
switch (i) { switch (i) {
case 0: case 0:
tv = (TextView)findViewById(R.id.candidate_left); word = (TextView)findViewById(R.id.word_left);
tv.setPadding(mCandidatePadding, 0, 0, 0); word.setPadding(mCandidatePadding, 0, 0, 0);
info = (TextView)findViewById(R.id.info_left);
break; break;
case 1: case 1:
tv = (TextView)findViewById(R.id.candidate_center); word = (TextView)findViewById(R.id.word_center);
info = (TextView)findViewById(R.id.info_center);
break; break;
case 2: case 2:
tv = (TextView)findViewById(R.id.candidate_right); word = (TextView)findViewById(R.id.word_right);
info = (TextView)findViewById(R.id.info_right);
break; break;
default: default:
tv = (TextView)inflater.inflate(R.layout.candidate, null); word = (TextView)inflater.inflate(R.layout.candidate_word, null);
info = (TextView)inflater.inflate(R.layout.candidate_info, null);
break; break;
} }
if (i < NUM_CANDIDATES_IN_STRIP) word.setTag(i);
setLayoutWeight(tv, 1.0f); word.setOnClickListener(this);
tv.setTag(i);
tv.setOnClickListener(this);
if (i == 0) if (i == 0)
tv.setOnLongClickListener(this); word.setOnLongClickListener(this);
mWords.add(tv); mWords.add(word);
mInfos.add(info);
if (i > 0) { if (i > 0) {
final View divider = inflater.inflate(R.layout.candidate_divider, null); final View divider = inflater.inflate(R.layout.candidate_divider, null);
divider.measure(UNSPECIFIED_MEASURESPEC, UNSPECIFIED_MEASURESPEC); divider.measure(UNSPECIFIED_MEASURESPEC, UNSPECIFIED_MEASURESPEC);
@ -263,15 +267,6 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
} }
} }
private static void setLayoutWeight(View v, float weight) {
ViewGroup.LayoutParams lp = v.getLayoutParams();
if (lp instanceof LinearLayout.LayoutParams) {
LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams)lp;
llp.width = 0;
llp.weight = weight;
}
}
private CharSequence getStyledCandidateWord(CharSequence word, boolean isAutoCorrect) { private CharSequence getStyledCandidateWord(CharSequence word, boolean isAutoCorrect) {
if (!isAutoCorrect) if (!isAutoCorrect)
return word; return word;
@ -308,6 +303,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
clear(); clear();
final int paneWidth = getWidth(); final int paneWidth = getWidth();
final int dividerWidth = mDividers.get(0).getMeasuredWidth(); final int dividerWidth = mDividers.get(0).getMeasuredWidth();
final int dividerHeight = mDividers.get(0).getMeasuredHeight();
int x = 0; int x = 0;
int y = 0; int y = 0;
int fromIndex = NUM_CANDIDATES_IN_STRIP; int fromIndex = NUM_CANDIDATES_IN_STRIP;
@ -315,10 +311,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
closeCandidatesPane(); closeCandidatesPane();
mExpandCandidatesPane.setEnabled(count >= NUM_CANDIDATES_IN_STRIP); mExpandCandidatesPane.setEnabled(count >= NUM_CANDIDATES_IN_STRIP);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
final CharSequence word = suggestions.getWord(i); final CharSequence suggestion = suggestions.getWord(i);
if (word == null) continue; if (suggestion == null) continue;
final SuggestedWordInfo info = (suggestedWordInfoList != null) final SuggestedWordInfo suggestionInfo = (suggestedWordInfoList != null)
? suggestedWordInfoList.get(i) : null; ? suggestedWordInfoList.get(i) : null;
final boolean isAutoCorrect = suggestions.mHasMinimalSuggestion final boolean isAutoCorrect = suggestions.mHasMinimalSuggestion
&& ((i == 1 && !suggestions.mTypedWordValid) && ((i == 1 && !suggestions.mTypedWordValid)
@ -327,18 +323,37 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
// and there are multiple suggestions, such as the default punctuation list. // and there are multiple suggestions, such as the default punctuation list.
// TODO: Need to revisit this logic with bigram suggestions // TODO: Need to revisit this logic with bigram suggestions
final boolean isSuggestedCandidate = (i != 0); final boolean isSuggestedCandidate = (i != 0);
final boolean isPunctuationSuggestions = (word.length() == 1 && count > 1); final boolean isPunctuationSuggestions = (suggestion.length() == 1 && count > 1);
final TextView tv = mWords.get(i); final TextView word = mWords.get(i);
// TODO: Reorder candidates in strip as appropriate. The center candidate should hold // TODO: Reorder candidates in strip as appropriate. The center candidate should hold
// the word when space is typed (valid typed word or auto corrected word). // the word when space is typed (valid typed word or auto corrected word).
tv.setTextColor(getCandidateTextColor(isAutoCorrect, word.setTextColor(getCandidateTextColor(isAutoCorrect,
isSuggestedCandidate || isPunctuationSuggestions, info)); isSuggestedCandidate || isPunctuationSuggestions, suggestionInfo));
tv.setText(getStyledCandidateWord(word, isAutoCorrect)); word.setText(getStyledCandidateWord(suggestion, isAutoCorrect));
// TODO: call TextView.setTextScaleX() to fit the candidate in single line. // TODO: call TextView.setTextScaleX() to fit the candidate in single line.
if (i >= NUM_CANDIDATES_IN_STRIP) { word.measure(UNSPECIFIED_MEASURESPEC, UNSPECIFIED_MEASURESPEC);
tv.measure(UNSPECIFIED_MEASURESPEC, UNSPECIFIED_MEASURESPEC); final int width = word.getMeasuredWidth();
final int width = tv.getMeasuredWidth(); final int height = word.getMeasuredHeight();
final TextView info;
if (DBG && suggestionInfo != null
&& !TextUtils.isEmpty(suggestionInfo.getDebugString())) {
info = mInfos.get(i);
info.setText(suggestionInfo.getDebugString());
info.setVisibility(View.VISIBLE);
info.measure(UNSPECIFIED_MEASURESPEC, UNSPECIFIED_MEASURESPEC);
} else {
info = null;
}
if (i < NUM_CANDIDATES_IN_STRIP) {
if (info != null) {
final int infoWidth = info.getMeasuredWidth();
FrameLayoutCompatUtils.placeViewAt(
info, x + width - infoWidth, y, infoWidth, info.getMeasuredHeight());
}
} else {
// TODO: Handle overflow case. // TODO: Handle overflow case.
if (dividerWidth + x + width >= paneWidth) { if (dividerWidth + x + width >= paneWidth) {
centeringCandidates(fromIndex, i - 1, x, paneWidth); centeringCandidates(fromIndex, i - 1, x, paneWidth);
@ -348,22 +363,22 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
} }
if (x != 0) { if (x != 0) {
final View divider = mDividers.get(i - NUM_CANDIDATES_IN_STRIP); final View divider = mDividers.get(i - NUM_CANDIDATES_IN_STRIP);
addCandidateAt(divider, x, y); mCandidatesPane.addView(divider);
FrameLayoutCompatUtils.placeViewAt(
divider, x, y + (mCandidateStripHeight - dividerHeight) / 2,
dividerWidth, dividerHeight);
x += dividerWidth; x += dividerWidth;
} }
addCandidateAt(tv, x, y); mCandidatesPane.addView(word);
x += width; FrameLayoutCompatUtils.placeViewAt(
word, x, y + (mCandidateStripHeight - height) / 2, width, height);
if (info != null) {
mCandidatesPane.addView(info);
final int infoWidth = info.getMeasuredWidth();
FrameLayoutCompatUtils.placeViewAt(
info, x + width - infoWidth, y, infoWidth, info.getMeasuredHeight());
} }
x += width;
if (DBG && info != null) {
final TextView dv = new TextView(getContext(), null);
dv.setTextSize(10.0f);
dv.setTextColor(0xff808080);
dv.setText(info.getDebugString());
// TODO: debug view for candidate strip needed.
// mCandidatesPane.addView(dv);
// LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)dv.getLayoutParams();
// lp.gravity = Gravity.BOTTOM;
} }
} }
if (x != 0) { if (x != 0) {
@ -372,19 +387,15 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
} }
} }
private void addCandidateAt(View v, int x, int y) {
final int width = v.getMeasuredWidth();
final int height = v.getMeasuredHeight();
final MarginLayoutParams marginLayoutParams = FrameLayoutCompatUtils.newLayoutParam(
mCandidatesPane, width, height);
marginLayoutParams.setMargins(x, y + (mCandidateStripHeight - height) / 2, 0, 0);
mCandidatesPane.addView(v, marginLayoutParams);
}
private void centeringCandidates(int from, int to, int width, int paneWidth) { private void centeringCandidates(int from, int to, int width, int paneWidth) {
final ViewGroup pane = mCandidatesPane; final ViewGroup pane = mCandidatesPane;
final int fromIndex = pane.indexOfChild(mWords.get(from)); final int fromIndex = pane.indexOfChild(mWords.get(from));
final int toIndex = pane.indexOfChild(mWords.get(to)); final int toIndex;
if (mInfos.get(to).getParent() != null) {
toIndex = pane.indexOfChild(mInfos.get(to));
} else {
toIndex = pane.indexOfChild(mWords.get(to));
}
final int offset = (paneWidth - width) / 2; final int offset = (paneWidth - width) / 2;
for (int index = fromIndex; index <= toIndex; index++) { for (int index = fromIndex; index <= toIndex; index++) {
offsetMargin(pane.getChildAt(index), offset, 0); offsetMargin(pane.getChildAt(index), offset, 0);
@ -394,9 +405,9 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private static void offsetMargin(View v, int dx, int dy) { private static void offsetMargin(View v, int dx, int dy) {
if (v == null) if (v == null)
return; return;
ViewGroup.LayoutParams lp = v.getLayoutParams(); final ViewGroup.LayoutParams lp = v.getLayoutParams();
if (lp instanceof ViewGroup.MarginLayoutParams) { if (lp instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams)lp; final ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams)lp;
mlp.setMargins(mlp.leftMargin + dx, mlp.topMargin + dy, 0, 0); mlp.setMargins(mlp.leftMargin + dx, mlp.topMargin + dy, 0, 0);
} }
} }
@ -458,8 +469,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
public void clear() { public void clear() {
mShowingAddToDictionary = false; mShowingAddToDictionary = false;
mShowingAutoCorrectionInverted = false; mShowingAutoCorrectionInverted = false;
for (int i = 0; i < NUM_CANDIDATES_IN_STRIP; i++) for (int i = 0; i < NUM_CANDIDATES_IN_STRIP; i++) {
mWords.get(i).setText(null); mWords.get(i).setText(null);
mInfos.get(i).setVisibility(View.GONE);
}
mCandidatesPane.removeAllViews(); mCandidatesPane.removeAllViews();
} }