- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
public static String ellipsizeText(String text, Context cnt) {
int COUNT_OF_CHARACTERS_LDPI = 10;
int COUNT_OF_CHARACTERS_MDPI = 20;
int COUNT_OF_CHARACTERS_HDPI = 30;
String ellipsizeT = "...";
String newText = text;
switch (cnt.getResources().getDisplayMetrics().densityDpi) {
case DisplayMetrics.DENSITY_LOW:
if (text.length() > COUNT_OF_CHARACTERS_LDPI) {
newText = text.substring(0, COUNT_OF_CHARACTERS_LDPI) + ellipsizeT;
}
break;
case DisplayMetrics.DENSITY_MEDIUM:
if (text.length() > COUNT_OF_CHARACTERS_MDPI) {
newText = text.substring(0, COUNT_OF_CHARACTERS_MDPI) + ellipsizeT;
}
break;
case DisplayMetrics.DENSITY_HIGH:
if (text.length() > COUNT_OF_CHARACTERS_HDPI) {
newText = text.substring(0, COUNT_OF_CHARACTERS_HDPI) + ellipsizeT;
}
break;
}
return newText;
}