Android Open Source - bard-droid Main Activity






From Project

Back to project page bard-droid.

License

The source code is released under:

GNU General Public License

If you think the Android project bard-droid 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 in.co.praveenkumar.bard.activities;
//from   ww w.  j av  a  2  s . c  o  m
import in.co.praveenkumar.bard.R;
import in.co.praveenkumar.bard.graphics.Frame;
import in.co.praveenkumar.bard.graphics.FrameSettings;
import in.co.praveenkumar.bard.io.USBControl;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;

public class MainActivity extends Activity {
  final String DEBUG_TAG = "BARD";
  final String IDENT_MANUFACTURER = "BeagleBone";
  final String USB_PERMISSION = "in.co.praveenkumar.bard.activities.MainActivity.USBPERMISSION";

  ImageView remoteScreen;
  Bitmap bitmap = Bitmap.createBitmap(1024, 768, Bitmap.Config.RGB_565);

  // Handler, Threads
  private Handler UIHandler = new Handler();

  // Activity Lifecycle
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    remoteScreen = (ImageView) findViewById(R.id.remote_screen);

    setupUSB();

    // Start Frame updater thread
    frameUpdate();

  }

  public void updateImage() {
    System.out.println("setUpImage called");

    /*
     * -TODO- - Some strange thing here. Sometimes copyPixelsFromBuffer is
     * reading outside the buffer range - A possible race condition with
     * position being of Frame being set from reader thread.
     */
    try {
      Frame.frameBuffer.position(0);
      bitmap.copyPixelsFromBuffer(Frame.frameBuffer);
      remoteScreen.setImageBitmap(bitmap);
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Exception with copyPixelsFromBuffer");
    }

  }

  private void setupUSB() {

    System.out.println("Starting USB...");
    new USBControlServer(UIHandler);
    System.out.println("Done\n");
  }

  public class USBControlServer extends USBControl {

    public USBControlServer(Handler ui) {
      super(getApplicationContext(), ui);
    }

    @Override
    public void onReceive(byte[] msg) {

    }

    @Override
    public void onNotify(String msg) {
      // console(msg);
    }

    @Override
    public void onConnected() {
      // usb.enable();
    }

    @Override
    public void onDisconnected() {
      // usb.pause();
      finish();
    }

  }

  private void frameUpdate() {
    updateImage();

    // Wait before doing next frame update
    Handler myHandler = new Handler();
    myHandler.postDelayed(frameUpdater, 1000 / FrameSettings.FPS);
  }

  private Runnable frameUpdater = new Runnable() {
    @Override
    public void run() {
      frameUpdate();
    }
  };

}




Java Source Code List

in.co.praveenkumar.bard.activities.BardReceiver.java
in.co.praveenkumar.bard.activities.MainActivity.java
in.co.praveenkumar.bard.graphics.FrameSettings.java
in.co.praveenkumar.bard.graphics.Frame.java
in.co.praveenkumar.bard.io.USBControl.java