aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui/IndexOutOfBoundsAvoidingTextView.java
blob: 4727bf952f4c5fe6cba539312d2e3b4e5fc1eabc (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(final Context context, final AttributeSet attrs, final int defStyle) {
		super(context, attrs, defStyle);
	}

	public IndexOutOfBoundsAvoidingTextView(final Context context, final AttributeSet attrs) {
		super(context, attrs);
	}

	public IndexOutOfBoundsAvoidingTextView(final Context context) {
		super(context);
	}

	@Override
	protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
		try{
			super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        } catch (final IndexOutOfBoundsException ignored) {
			setText(getText().toString());
			super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		}
	}

	@Override
	public void setGravity(final int gravity){
		try{
			super.setGravity(gravity);
        } catch (final IndexOutOfBoundsException ignored) {
			setText(getText().toString());
			super.setGravity(gravity);
		}
	}

	@Override
	public void setText(final CharSequence text, final BufferType type) {
		try{
			super.setText(text, type);
        } catch (final IndexOutOfBoundsException ignored) {
			setText(text.toString());
		}
	}
}