Fix bug #5262565 Need to remove CharCount TextDirectionHeuristics

- update unit tests too

Change-Id: I7c518f58a9f17cb679bc3913bdd38243f7ad2195
This commit is contained in:
Fabrice Di Meglio
2011-09-06 11:08:45 -07:00
parent 373a4f44e4
commit e3bf88da23
4 changed files with 2 additions and 124 deletions

View File

@ -61,24 +61,6 @@ public class TextDirectionHeuristics {
public static final TextDirectionHeuristic ANYRTL_LTR =
new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_RTL, false);
/**
* Examines only the strong directional non-format characters, and if either
* left to right or right to left characters are 60% or more of this total,
* determines that the direction follows the majority of characters. Falls
* back to left to right if neither direction meets this threshold.
*/
public static final TextDirectionHeuristic CHARCOUNT_LTR =
new TextDirectionHeuristicInternal(CharCount.INSTANCE_DEFAULT, false);
/**
* Examines only the strong directional non-format characters, and if either
* left to right or right to left characters are 60% or more of this total,
* determines that the direction follows the majority of characters. Falls
* back to right to left if neither direction meets this threshold.
*/
public static final TextDirectionHeuristic CHARCOUNT_RTL =
new TextDirectionHeuristicInternal(CharCount.INSTANCE_DEFAULT, true);
/**
* Force the paragraph direction to the Locale direction. Falls back to left to right.
*/
@ -254,62 +236,6 @@ public class TextDirectionHeuristics {
public static final AnyStrong INSTANCE_LTR = new AnyStrong(false);
}
/**
* Algorithm that uses the relative proportion of strong directional
* characters (excluding LRE, LRO, RLE, RLO) to determine the direction
* of the paragraph, if the proportion exceeds a given threshold.
*
* @hide
*/
public static class CharCount implements TextDirectionAlgorithm {
private final float mThreshold;
@Override
public TriState checkRtl(char[] text, int start, int count) {
int countLtr = 0;
int countRtl = 0;
for(int i = start, e = start + count; i < e; ++i) {
switch (isRtlText(Character.getDirectionality(text[i]))) {
case TRUE:
++countLtr;
break;
case FALSE:
++countRtl;
break;
default:
break;
}
}
int limit = (int)((countLtr + countRtl) * mThreshold);
if (limit > 0) {
if (countLtr > limit) {
return TriState.FALSE;
}
if (countRtl > limit) {
return TriState.TRUE;
}
}
return TriState.UNKNOWN;
}
private CharCount(float threshold) {
mThreshold = threshold;
}
public static CharCount withThreshold(float threshold) {
if (threshold < 0 || threshold > 1) {
throw new IllegalArgumentException();
}
if (threshold == DEFAULT_THRESHOLD) {
return INSTANCE_DEFAULT;
}
return new CharCount(threshold);
}
public static final float DEFAULT_THRESHOLD = 0.6f;
public static final CharCount INSTANCE_DEFAULT = new CharCount(DEFAULT_THRESHOLD);
}
/**
* Algorithm that uses the Locale direction to force the direction of a paragraph.
*/

View File

@ -2567,27 +2567,19 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
*/
public static final int TEXT_DIRECTION_ANY_RTL = 2;
/**
* Text direction is the same as the one held by a 60% majority of the characters. If there is
* no majority then the paragraph direction is the resolved layout direction of the View.
*
* @hide
*/
public static final int TEXT_DIRECTION_CHAR_COUNT = 3;
/**
* Text direction is forced to LTR.
*
* @hide
*/
public static final int TEXT_DIRECTION_LTR = 4;
public static final int TEXT_DIRECTION_LTR = 3;
/**
* Text direction is forced to RTL.
*
* @hide
*/
public static final int TEXT_DIRECTION_RTL = 5;
public static final int TEXT_DIRECTION_RTL = 4;
/**
* Default text direction is inherited
@ -2603,7 +2595,6 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
@ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_CHAR_COUNT, to = "CHAR_COUNT"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL")
})
@ -2621,7 +2612,6 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
@ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_CHAR_COUNT, to = "CHAR_COUNT"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL")
})

View File

@ -11244,10 +11244,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
case TEXT_DIRECTION_ANY_RTL:
mTextDir = TextDirectionHeuristics.ANYRTL_LTR;
break;
case TEXT_DIRECTION_CHAR_COUNT:
mTextDir = (defaultIsRtl ? TextDirectionHeuristics.CHARCOUNT_RTL:
TextDirectionHeuristics.CHARCOUNT_LTR);
break;
case TEXT_DIRECTION_LTR:
mTextDir = TextDirectionHeuristics.LTR;
break;