Android Open Source - MakeWithMotoSampleApp Activity B T






From Project

Back to project page MakeWithMotoSampleApp.

License

The source code is released under:

GNU General Public License

If you think the Android project MakeWithMotoSampleApp 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.makewithmoto.example;
//w  w w . ja v a  2s.  com
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.FrameLayout;

import com.makewithmoto.bt.SimpleBT;
import com.makewithmoto.bt.SimpleBT.SimpleBTListener;
import com.makewithmoto.fragments.DebugFragment;
import com.makewithmoto.views.PlotView;
import com.makewithmoto.views.PlotView.Plot;

/*
 * Example using a normal Bluetooth module 
 * 
 * 
 */

@SuppressLint("NewApi")
public class ActivityBT extends FragmentActivity {

  private static final String TAG = "ExAPP";
  private DebugFragment df;
  private boolean f2V = true;


  ActionBar actionBar;
  
  SimpleBT simpleBT; 



  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bt);


    actionBar = getActionBar();
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setLogo(null);
    actionBar.setTitle("MakeWithMoto");

    df = new DebugFragment();
    addFragment(df, R.id.f1);

    final PlotView graphView = (PlotView) findViewById(R.id.plotView1);
    final Plot p1 = graphView.new Plot(Color.RED);
    graphView.addPlot(p1); 
    
    
    simpleBT = new SimpleBT(this);
    simpleBT.startDeviceListActivity();
    simpleBT.addListener(new SimpleBTListener() {
      
      @Override
      public void onRawDataReceived(byte[] buffer, int size) {

      }
      
      @Override
      public void onConnected() {
        simpleBT.send("hello");  
        
      }
      
      @Override
      public void onMessageReceived(String cmd, String value) {
        
        df.adapter.addRightItem(cmd + " " + value);
        float val = Float.parseFloat(value);
        graphView.setValue(p1, val);

      }
    }); 
    
  }

  @Override
  public void onSaveInstanceState(Bundle state) {
    super.onSaveInstanceState(state);
  }

  @Override
  protected void onResume() {
    super.onResume();
  }

  @Override
  protected void onPause() {
    super.onPause();
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    simpleBT.destroy();

  }

  public void addFragment(Fragment f, int fragmentPosition) {

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.add(fragmentPosition, f);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.commit();

  }

  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    FrameLayout layout = (FrameLayout) findViewById(R.id.f2);

    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {

      if (f2V) {
        layout.setVisibility(View.GONE);
        f2V = false;
      } else {
        layout.setVisibility(View.VISIBLE);
        f2V = true;
      }
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {

    }

    return super.onKeyDown(keyCode, event);
  }


  @Override
  public void onStart() {
    super.onStart();
    simpleBT.start();
  }



  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "onActivityResult " + resultCode);
    simpleBT.result(requestCode, resultCode, data);
  }

}




Java Source Code List

android_serialport_api.SerialPort.java
com.makewithmoto.boards.MAKr.java
com.makewithmoto.boards.MIOIOListener.java
com.makewithmoto.bt.BluetoothSerialService.java
com.makewithmoto.bt.BluetoothViewer.java
com.makewithmoto.bt.DeviceListActivity.java
com.makewithmoto.bt.SimpleBT.java
com.makewithmoto.example.ActivityBT.java
com.makewithmoto.example.ActivityMAKr.java
com.makewithmoto.example.ActivityMOIO.java
com.makewithmoto.example.Application.java
com.makewithmoto.example.LauncherActivity.java
com.makewithmoto.extras.AccelerometerManager.java
com.makewithmoto.extras.CustomSensorListener.java
com.makewithmoto.extras.CustomSensorManager.java
com.makewithmoto.extras.WhatIsRunningInterface.java
com.makewithmoto.extras.WhatIsRunning.java
com.makewithmoto.fragments.CameraFragment.java
com.makewithmoto.fragments.DebugFragment.java
com.makewithmoto.fragments.EmptyFragment.java
com.makewithmoto.fragments.GraphFragment.java
com.makewithmoto.fragments.ImageFragment.java
com.makewithmoto.fragments.Utils.java
com.makewithmoto.fragments.VideoPlayerFragment.java
com.makewithmoto.fragments.VideoTextureFragment.java
com.makewithmoto.views.CanvasUtils.java
com.makewithmoto.views.PlotView.java