LogView.java 1.02 KB
Newer Older
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
package com.theta.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;
import android.widget.TextView;

/**
 * View for log display
 */
public class LogView extends ScrollView {

	private TextView textView;
	private static final String LINE_SEPARATOR = System.getProperty("line.separator");

    /**
     * Constructor
     * @param context Context
     * @param attrs Argument for resource
     */
	public LogView(Context context, AttributeSet attrs) {
		super(context, attrs);

		setFillViewport(true);
		textView = new TextView(context);
		textView.setBackgroundResource(android.R.color.darker_gray);
		textView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
		this.addView(textView);
	}

    /**
     * Log output request method
     * @param newLine Output log
     */
	public void append(CharSequence newLine) {
		textView.append(newLine);
		textView.append(LINE_SEPARATOR);
		fullScroll(FOCUS_DOWN);
	}
}