Android Open Source - NoiseBridge_General Teletype






From Project

Back to project page NoiseBridge_General.

License

The source code is released under:

GPLv3.txt

If you think the Android project NoiseBridge_General 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 com.metamage.noisegate;
//  ww w . j  a v  a  2 s.c  o m
import android.os.Handler;
import android.widget.TextView;


public final class Teletype
{
  
  private static final int blinkDelay = 500;
  
  private String text = "";
  
  private int mark = -1;
  
  private int inputDelay = 0;
  
  private TextView textView;
  
  private Handler inputHandler = new Handler();
  private Handler blinkHandler = new Handler();
  
  private int cursorState = -1;
  
  private Runnable input = new Runnable()
  {
    public void run()
    {
      if ( mark < 0 )
      {
        return;
      }
      
      int delay = inputDelay;
      
      inputDelay = 0;
      
      if ( delay == 0 )
      {
        final boolean newline = text.charAt( mark ) == '\n';
        
        delay = newline ? 1000 : 50;
        
        ++mark;
        
        update();
      }
      
      inputHandler.postDelayed( this, delay );
    }
  };
  
  private Runnable blink = new Runnable()
  {
    public void run()
    {
      if ( cursorState < 0 )
      {
        return;
      }
      
      cursorState = 1 - cursorState;
      
      update();
      
      blinkHandler.postDelayed( this, blinkDelay );
    }
  };
  
  Teletype( TextView tv )
  {
    textView = tv;
  }
  
  void update()
  {
    CharSequence newText = text;
    
    if ( mark >= text.length() )
    {
      mark = -1;
    }
    
    if ( mark >= 0 )
    {
      newText = text.subSequence( 0, mark );
    }
    
    if ( cursorState == 1 )
    {
      newText = newText + "\u2588";  // full block
    }
    
    textView.setText( newText );
  }
  
  void clear()
  {
    text = "";
    
    textView.setText( "" );
  }
  
  void setText( String s )
  {
    text = s;
    
    textView.setText( s );
    
    mark = -1;
  }
  
  void append( CharSequence chars )
  {
    text = text + chars;
    
    mark = -1;
    
    update();
  }
  
  void startBlinking()
  {
    if ( cursorState < 0 )
    {
      cursorState = 0;
      
      blinkHandler.post( blink );
    }
  }
  
  void stopBlinking()
  {
    cursorState = -1;
  }
  
  void startInput()
  {
    if ( mark < 0 )
    {
      mark = text.length();
      
      inputHandler.post( input );
    }
  }
  
  void stopInput()
  {
    mark = -1;
    
    update();
  }
  
  void delayInput( int delay )
  {
    inputDelay = delay;
  }
  
  void input( CharSequence chars )
  {
    startBlinking();
    startInput();
    
    text = text + chars;
    
    update();
  }
  
}




Java Source Code List

com.loopj.android.http.AsyncHttpClient.java
com.loopj.android.http.AsyncHttpRequest.java
com.loopj.android.http.AsyncHttpResponseHandler.java
com.loopj.android.http.BinaryHttpResponseHandler.java
com.loopj.android.http.JsonHttpResponseHandler.java
com.loopj.android.http.PersistentCookieStore.java
com.loopj.android.http.RequestParams.java
com.loopj.android.http.RetryHandler.java
com.loopj.android.http.SerializableCookie.java
com.loopj.android.http.SimpleMultipartEntity.java
com.loopj.android.http.SyncHttpClient.java
com.metamage.noisegate.Completion.java
com.metamage.noisegate.Data.java
com.metamage.noisegate.F.java
com.metamage.noisegate.GetAndDiscardUrlTask.java
com.metamage.noisegate.Key.java
com.metamage.noisegate.Noisegate.java
com.metamage.noisegate.Teletype.java
com.noysbrij.fragments.DatePickerFragment.java
com.noysbrij.fragments.JSInterface.java
com.noysbrij.fragments.ListViewFragment.java
com.noysbrij.fragments.NBWebViewFragment.java
com.noysbrij.fragments.TicketsArrayAdapter.java
com.noysbrij.fragments.TimePickerFragment.java
com.noysbrij.noisebridgeGeneral.NoiseBridgeGeneral.java
com.noysbrij.noisebridgeGeneral.ReadJson.java
com.noysbrij.noisebridgeGeneral.Ticket.java
com.noysbrij.noisebridgeGeneral.TicketsExpandableListAdapter.java
com.noysbrij.noisebridgeGeneral.Tickets.java