Add helper methods to convert flags to readable text
Change-Id: I23608927cef8a897ff4ad8c938560cc78093ddacmain
parent
04a492cb49
commit
9dc3ae84ee
|
@ -24,6 +24,7 @@ import com.android.inputmethod.latin.common.Constants;
|
||||||
import com.android.inputmethod.latin.common.StringUtils;
|
import com.android.inputmethod.latin.common.StringUtils;
|
||||||
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
|
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public final class CapsModeUtils {
|
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.
|
// Here we arrived at the start of the line. This should behave exactly like whitespace.
|
||||||
return (START == state || LETTER == state) ? noCaps : caps;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* 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.
|
* action was done, and the location of the cursor and the string that was there after.
|
||||||
|
|
Loading…
Reference in New Issue