Android Open Source - watcher Watch






From Project

Back to project page watcher.

License

The source code is released under:

CC0 1.0 Universal Statement of Purpose The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent...

If you think the Android project watcher 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.appspot.staffordbears.watcher;
//w ww.  jav a  2s  . co m
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;
import android.widget.TextView;
import android.os.Bundle;
import android.os.Handler;
import java.util.Queue;
import java.util.LinkedList;

public class Watch extends Activity {

    private static final String TAG = "watcher.Watch";

    private Hermit mApp;
    private TextView mOutput;
    private Handler mHandler;

    // thread-safe way to output a message
    // to the text view
    private class Con implements Runnable {
  String mData;
  Con(String data) {
      mData = data;
  }
  @Override
  public void run() {
      mOutput.append(mData);
      mOutput.append("\n");
  }
    }

    public void consoleOut(String message) {
  Con task = new Con(message);
  mHandler.post(task);
    }

    @Override
    public void onCreate(Bundle bundle) {
  super.onCreate(bundle);
  Log.i(TAG, "***** ACTIVITY START");

  mApp = (Hermit) getApplicationContext();
  mApp.mAct = this;
  mHandler = new Handler();

    }

    @Override
    public void onDestroy() {
  mApp.mAct = null;
  super.onDestroy();
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
  Log.i(TAG, "***** CREATE OPTIONS MENU");

  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.primary, menu);

        // Inflate our UI from its XML layout description.
        setContentView(R.layout.primary);

        // Find the text view inside the layout, because we
        // want to send tect to it.
        mOutput = (TextView) findViewById(R.id.output);
  mOutput.setMovementMethod(new ScrollingMovementMethod());
  return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
  Intent myIntent;
  switch (item.getItemId()) {
        case R.id.start:
      myIntent = new Intent(this, CommLink.class);
      myIntent.putExtra("extraData", "somedata");
      startService(myIntent);      
            return true;

        case R.id.stop:
      myIntent = new Intent(this, CommLink.class);
      myIntent.putExtra("extraData", "somedata");
      stopService(myIntent);
            return true;

        case R.id.check_link:
      if (mApp.mService != null) {
    mOutput.append(getText(R.string.service_up));
    mOutput.append("\n");
    if (mApp.mService.connected()) {
      mOutput.append(getText(R.string.link_up));
      mOutput.append("\n");
    } else {
        mOutput.append(getText(R.string.link_down));
        mOutput.append("\n");
    }
      } else {
    mOutput.append(getText(R.string.service_down));
    mOutput.append("\n");
      }
            return true;

  case R.id.show_msg:
      mOutput.setText("");
      mOutput.append(mApp.summary());      
      return true;

        default:
            return super.onOptionsItemSelected(item);
  }
    }

}




Java Source Code List

com.appspot.staffordbears.watcher.CommLink.java
com.appspot.staffordbears.watcher.Hermit.java
com.appspot.staffordbears.watcher.SerialProtocol.java
com.appspot.staffordbears.watcher.SmsReceiver.java
com.appspot.staffordbears.watcher.Snap.java
com.appspot.staffordbears.watcher.Watch.java