Skip to content

Commit

Permalink
Merge pull request #12 from jaggernod/master
Browse files Browse the repository at this point in the history
Do not clear the log when buffer is filled
  • Loading branch information
quiqueqs committed Dec 10, 2014
2 parents 104a3b2 + bc82ef2 commit 57a4216
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/main/java/com/inaka/galgo/GalgoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@
import android.os.IBinder;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.BackgroundColorSpan;
import android.view.WindowManager;
import android.widget.TextView;

import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Queue;

public class GalgoService extends Service {

private final IBinder mBinder = new LocalBinder();
private TextView mTextView;
private GalgoOptions mOptions;
private final Queue<String> mLines = new ArrayDeque<>();

public class LocalBinder extends Binder {
public GalgoService getService() {
Expand Down Expand Up @@ -61,20 +67,23 @@ public void onCreate() {
}

public void displayText(String text) {

Spannable spannable = new SpannableString(text);
spannable.setSpan(new BackgroundColorSpan(mOptions.backgroundColor),0, text.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

if(mTextView.getLineCount() > mOptions.numberOfLines) {
mTextView.setText(spannable);
} else {
mTextView.append(spannable);
mLines.add(text);
if (mLines.size() > mOptions.numberOfLines) {
mLines.poll();
}

redraw(mLines);
}

private void redraw(Collection<String> texts) {
mTextView.setTextSize(mOptions.textSize);
mTextView.setTextColor(mOptions.textColor);
mTextView.append("\n");

Spannable spannable = new SpannableString(TextUtils.join("\n", texts));
spannable.setSpan(new BackgroundColorSpan(mOptions.backgroundColor), 0, spannable.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

mTextView.setText(spannable);
}

@Override
Expand Down

0 comments on commit 57a4216

Please sign in to comment.