aboutsummaryrefslogtreecommitdiff
path: root/src/org/happysanta/gd/Menu/TextMenuElement.java
blob: 7485389453e32d0f98bd3e151838acd7aae2a734 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package org.happysanta.gd.Menu;

// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

import android.content.Context;
import android.text.Html;
import android.text.Spanned;
import android.text.SpannedString;
import android.text.util.Linkify;
import android.view.View;
import android.view.ViewGroup;
import org.happysanta.gd.Menu.Views.MenuTextView;

import static org.happysanta.gd.Helpers.getGDActivity;

public class TextMenuElement
		implements MenuElement {

	protected static final int TEXT_SIZE = 15;
	protected static final int TEXT_COLOR = 0xff000000;

	protected Spanned spanned;
	protected MenuTextView textView;

	public TextMenuElement(String text) {
		this.spanned = SpannedString.valueOf(text);
		textView = createTextView();
	}

	public TextMenuElement(Spanned text) {
		this.spanned = text;
		textView = createTextView();
	}

	protected MenuTextView createTextView() {
		Context activity = getGDActivity();

		MenuTextView textView = new MenuTextView(activity);
		textView.setText(spanned);
		textView.setTextColor(TEXT_COLOR);
		textView.setTextSize(TEXT_SIZE);
		textView.setLineSpacing(0f, 1.5f);
		textView.setLayoutParams(new ViewGroup.LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT
		));

		Linkify.addLinks(textView, Linkify.WEB_URLS);
		textView.setLinksClickable(true);

		return textView;
	}

	@Override
	public View getView() {
		return textView;
	}

	public String getText() {
		return spanned.toString();
	}

	@Override
	public void setText(String text) {
		this.spanned = Html.fromHtml(text);
		textView.setTextOnUiThread(spanned);
	}

	@Override
	public boolean isSelectable() {
		return false;
	}

	@Override
	public void performAction(int k) {
	}

}