aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/ToastHelperActivity.java
blob: a7997e9fd92497076d97def1ae0c3cc40c098c1a (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
package net.cbaines.suma;

import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;

public class ToastHelperActivity extends OrmLiteBaseActivity<DatabaseHelper> {

	private Toast toast;
	private View toastView;
	private TextView toastMessageTextView;
	private TextView toastSubMessageTextView;

	void makeToast(String message, int length) {
		makeToast(message, null, length);
	}

	void makeToast(String message, String subMessage, int length) {
		if (toastView == null) {
			toastView = (View) getLayoutInflater().inflate(R.layout.toast_view, null);
		}
		if (toast == null) {
			toast = new Toast(this);
		}

		toastMessageTextView = (TextView) toastView.findViewById(R.id.toastViewText);
		toastMessageTextView.setText(message);

		toastSubMessageTextView = (TextView) toastView.findViewById(R.id.toastViewSubMessage);
		if (subMessage != null) {
			toastSubMessageTextView.setText(subMessage);
			toastSubMessageTextView.setVisibility(View.VISIBLE);
		} else {
			toastSubMessageTextView.setText("");
			toastSubMessageTextView.setVisibility(View.GONE);
		}

		toast.setDuration(length);
		toast.setView(toastView);
		toast.show();
	}

}