Android Open Source - Android_CommandlineLikeDisplay C L D Message






From Project

Back to project page Android_CommandlineLikeDisplay.

License

The source code is released under:

Copyright (c) 2011, Jerome Schneider All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met...

If you think the Android project Android_CommandlineLikeDisplay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package cld.CommandlineLikeDisplay;
//w  w  w  .j  a  v a2s  . com
import java.util.LinkedList;
import java.util.Queue;

import android.os.Handler;
import android.util.Log;

public class CLDMessage {
  
  private static final String TAG = "CLDMessage";
  private static Handler myHandler;
  private static Queue <String> input_queue;
  
  //Constructor
  CLDMessage(Handler a_Handler){
    myHandler = a_Handler;
    input_queue = new LinkedList <String>();
  }
  
  public synchronized void clearQueue(){
    input_queue.clear();
  }

  //Get a line of text from the input
  public synchronized void getLineFromInput(String input){
    input_queue.add(input);
    this.notifyAll();
  }
  
  //GetLine is a blocking call, we notfiy so it will wake up
  //from sleep
  public synchronized void notifyGetLine()
  {
    this.notifyAll();
  }
  
  //Return the next element of the input queue
  //or wait for user input
  public String getLine(){
    while(input_queue.size() == 0){
      synchronized(this){
        try {
          wait();
        } catch (InterruptedException e) {
          return null;
        }
      }
    }
    return input_queue.remove();
  }
  
  //Print a debug message
  public void print_debug(String outString) {
    String debugString = "(Debug) " + outString;
    byte[] buffer = debugString.getBytes();

    myHandler.obtainMessage(Constants.MSG_DEBUG, buffer.length, -1, buffer)
        .sendToTarget();
  }

  //Print a normal message
  public void print_normal(String outString) {
    byte[] buffer = outString.getBytes();

    myHandler.obtainMessage(Constants.MSG_NORMAL, buffer.length, -1, buffer)
        .sendToTarget();
  }
}




Java Source Code List

cld.CommandlineLikeDisplay.CLDMessage.java
cld.CommandlineLikeDisplay.CommandlineLikeDisplayActivity.java
cld.CommandlineLikeDisplay.Constants.java
cld.CommandlineLikeDisplay.ExampleService.java