De-duplicate a method

Change-Id: Ia1c80eeff00a55573bb311f07e1275da23bdcf98
main
Jean Chalard 2012-03-15 14:56:09 +09:00
parent e8ddfe4273
commit 042557b45b
3 changed files with 16 additions and 27 deletions

View File

@ -30,6 +30,8 @@ import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@ -454,4 +456,13 @@ public class Utils {
LatinImeLogger.logOnAutoCorrectionCancelled();
}
}
public static String getDebugInfo(final SuggestedWords suggestions, final int pos) {
if (!LatinImeLogger.sDBG) return null;
final SuggestedWordInfo wordInfo = suggestions.getInfo(pos);
if (wordInfo == null) return null;
final String info = wordInfo.getDebugString();
if (TextUtils.isEmpty(info)) return null;
return info;
}
}

View File

@ -19,7 +19,6 @@ package com.android.inputmethod.latin.suggestions;
import android.content.res.Resources;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
@ -29,7 +28,7 @@ import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.Utils;
public class MoreSuggestions extends Keyboard {
public static final int SUGGESTION_CODE_BASE = 1024;
@ -191,15 +190,6 @@ public class MoreSuggestions extends Keyboard {
return this;
}
private static String getDebugInfo(SuggestedWords suggestions, int pos) {
if (!DBG) return null;
final SuggestedWordInfo wordInfo = suggestions.getInfo(pos);
if (wordInfo == null) return null;
final String info = wordInfo.getDebugString();
if (TextUtils.isEmpty(info)) return null;
return info;
}
private static class Divider extends Key.Spacer {
private final Drawable mIcon;
@ -223,7 +213,7 @@ public class MoreSuggestions extends Keyboard {
final int y = params.getY(pos);
final int width = params.getWidth(pos);
final String word = mSuggestions.getWord(pos).toString();
final String info = getDebugInfo(mSuggestions, pos);
final String info = Utils.getDebugInfo(mSuggestions, pos);
final int index = pos + SUGGESTION_CODE_BASE;
final Key key = new Key(
params, word, info, KeyboardIconsSet.ICON_UNDEFINED, index, null, x, y,

View File

@ -63,6 +63,7 @@ import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
import com.android.inputmethod.latin.Suggest;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.Utils;
import java.util.ArrayList;
import java.util.List;
@ -404,8 +405,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
word, getSuggestionWeight(index), ViewGroup.LayoutParams.MATCH_PARENT);
x += word.getMeasuredWidth();
if (DBG) {
final CharSequence debugInfo = getDebugInfo(suggestedWords, pos);
if (DBG && pos < suggestedWords.size()) {
final CharSequence debugInfo = Utils.getDebugInfo(suggestedWords, pos);
if (debugInfo != null) {
final TextView info = mInfos.get(pos);
info.setText(debugInfo);
@ -500,19 +501,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
hintView, 1.0f - mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT);
}
private static String getDebugInfo(SuggestedWords suggestions, int pos) {
if (DBG && pos < suggestions.size()) {
final SuggestedWordInfo wordInfo = suggestions.getInfo(pos);
if (wordInfo != null) {
final String debugInfo = wordInfo.getDebugString();
if (!TextUtils.isEmpty(debugInfo)) {
return debugInfo;
}
}
}
return null;
}
private static void setLayoutWeight(View v, float weight, int height) {
final ViewGroup.LayoutParams lp = v.getLayoutParams();
if (lp instanceof LinearLayout.LayoutParams) {