am c6fc20a9: Merge "Fix bug #5262565 Need to remove CharCount TextDirectionHeuristics"

* commit 'c6fc20a91bdf6f5d8cd8784324a55e39bcb7077c':
  Fix bug #5262565 Need to remove CharCount TextDirectionHeuristics
This commit is contained in:
Fabrice Di Meglio
2011-09-06 15:14:26 -07:00
committed by Android Git Automerger
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

@@ -11291,10 +11291,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;

View File

@@ -197,40 +197,6 @@ public class TextViewTest extends ActivityInstrumentationTestCase2<TextViewTestA
assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection());
}
@SmallTest
public void testCharCountHeuristic() {
LinearLayout ll = new LinearLayout(getActivity());
ll.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
TextView tv = new TextView(getActivity());
ll.addView(tv);
tv.setTextDirection(View.TEXT_DIRECTION_CHAR_COUNT);
tv.setText("this is a test");
assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection());
// resetResolvedTextDirection is not part of the public API so simply use setTextDirection
tv.setTextDirection(View.TEXT_DIRECTION_LTR);
tv.setTextDirection(View.TEXT_DIRECTION_CHAR_COUNT);
tv.setText("\u05DD\u05DE"); // hebrew
assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection());
tv.setTextDirection(View.TEXT_DIRECTION_LTR);
tv.setTextDirection(View.TEXT_DIRECTION_CHAR_COUNT);
tv.setText("this is a test \u05DD\u05DE"); // latin more than 60% + hebrew
assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection());
tv.setTextDirection(View.TEXT_DIRECTION_LTR);
tv.setTextDirection(View.TEXT_DIRECTION_CHAR_COUNT);
tv.setText("t \u05DD\u05DE"); // latin + hebrew more than 60%
assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection());
tv.setTextDirection(View.TEXT_DIRECTION_LTR);
tv.setTextDirection(View.TEXT_DIRECTION_CHAR_COUNT);
tv.setText("ab \u05DD\u05DE"); // latin + hebrew at 50% each
assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection());
}
@SmallTest
public void testResetTextDirection() {
final TextViewTestActivity activity = getActivity();