am ef8068f9: Merge "Add helper methods to convert flags to readable text"

* commit 'ef8068f9a85af5c402588662b3a7e98076e4c0dd':
  Add helper methods to convert flags to readable text
main
Tadashi G. Takaoka 2014-10-31 10:16:32 +00:00 committed by Android Git Automerger
commit 8c980ff45d
2 changed files with 39 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import java.util.ArrayList;
import java.util.Locale;
public final class CapsModeUtils {
@ -326,4 +327,31 @@ public final class CapsModeUtils {
// Here we arrived at the start of the line. This should behave exactly like whitespace.
return (START == state || LETTER == state) ? noCaps : caps;
}
/**
* Convert capitalize mode flags into human readable text.
*
* @param capsFlags The modes flags to be converted. It may be any combination of
* {@link TextUtils#CAP_MODE_CHARACTERS}, {@link TextUtils#CAP_MODE_WORDS}, and
* {@link TextUtils#CAP_MODE_SENTENCES}.
* @return the text that describe the <code>capsMode</code>.
*/
public static String flagsToString(final int capsFlags) {
final int capsFlagsMask = TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS
| TextUtils.CAP_MODE_SENTENCES;
if ((capsFlags & ~capsFlagsMask) != 0) {
return "unknown<0x" + Integer.toHexString(capsFlags) + ">";
}
final ArrayList<String> builder = new ArrayList<>();
if ((capsFlags & android.text.TextUtils.CAP_MODE_CHARACTERS) != 0) {
builder.add("characters");
}
if ((capsFlags & android.text.TextUtils.CAP_MODE_WORDS) != 0) {
builder.add("words");
}
if ((capsFlags & android.text.TextUtils.CAP_MODE_SENTENCES) != 0) {
builder.add("sentences");
}
return builder.isEmpty() ? "none" : TextUtils.join("|", builder);
}
}

View File

@ -51,6 +51,17 @@ public class RecapitalizeStatus {
}
}
public static String modeToString(final int recapitalizeMode) {
switch (recapitalizeMode) {
case NOT_A_RECAPITALIZE_MODE: return "undefined";
case CAPS_MODE_ORIGINAL_MIXED_CASE: return "mixedCase";
case CAPS_MODE_ALL_LOWER: return "allLower";
case CAPS_MODE_FIRST_WORD_UPPER: return "firstWordUpper";
case CAPS_MODE_ALL_UPPER: return "allUpper";
default: return "unknown<" + recapitalizeMode + ">";
}
}
/**
* We store the location of the cursor and the string that was there before the recapitalize
* action was done, and the location of the cursor and the string that was there after.