blob: a0c8b526d3d46933973d3bfa23969ab8610d647a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package cgeo.geocaching.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
/**
* Jelly beans can crash when calculating the layout of a textview.
*
* https://code.google.com/p/android/issues/detail?id=35466
*
*/
public class IndexOutOfBoundsAvoidingTextView extends TextView {
public IndexOutOfBoundsAvoidingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public IndexOutOfBoundsAvoidingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public IndexOutOfBoundsAvoidingTextView(Context context) {
super(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
try{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
} catch (IndexOutOfBoundsException e) {
setText(getText().toString());
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
@Override
public void setGravity(int gravity){
try{
super.setGravity(gravity);
} catch (IndexOutOfBoundsException e) {
setText(getText().toString());
super.setGravity(gravity);
}
}
@Override
public void setText(CharSequence text, BufferType type) {
try{
super.setText(text, type);
} catch (IndexOutOfBoundsException e) {
setText(text.toString());
}
}
}
|