Android Open Source - android_bluetooth Demo Module






From Project

Back to project page android_bluetooth.

License

The source code is released under:

MIT License

If you think the Android project android_bluetooth 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.smartdevices.smartqwatchdemo;
/* w w w .  j  a va 2s .  co m*/
import android.content.Context;
import android.media.AudioTrack;
import android.os.Handler;
import android.os.Message;
import android.os.ParcelUuid;
import android.util.Log;
import cn.ingenic.indroidsync.services.SyncData;
import cn.ingenic.indroidsync.services.SyncModule;

/**
 * 
 * ??SyncModule??????SyncModule??????????????????? ???? SyncData
 * data???Bundle?,??????????????? ????????? ?DemoModule.send(SyncData data); ??????
 * ?DemoModule.onRetrive(SyncData data) ???????
 * 
 */
public class DemoModule extends SyncModule {
  private static final String TAG = "DemoModule";
  public static final String MODULE = "DemoModule";

  private boolean mIsWatch = false;

  private AudioTrack mTrack = null;
  private Handler mHandler;

  public DemoModule(Context context) {
    super(MODULE, context);
  }

  public DemoModule(Context context, boolean isWatch) {
    super(MODULE, context);
    mIsWatch = isWatch;
  }
  
  public void setHandler(Handler handler){
    mHandler = handler;
  }

  @Override
  protected void onCreate() {
    Log.d(TAG, "onCreate......");

    if (!mIsWatch) {
      mTrack = DemoUtil.findAudioTrack();
      if (mTrack != null)
        mTrack.play();
    }
  }

  /*
   * ?????????????
   */
  @Override
  protected void onChannelCreateComplete(ParcelUuid uuid, boolean success,
      boolean local) {
    super.onChannelCreateComplete(uuid, success, local);
    Log.d(TAG, "onChannelCreateComplete......");
  }

  /* 
   * 
   */
  @Override
  protected void onChannelRetrive(ParcelUuid uuid, SyncData data) {
    super.onChannelRetrive(uuid, data);
    Log.d(TAG, "onChannelRetrive......");
  }

  /* 
   * mode:SAVING_POWER_MODE = 0;RIGHT_NOW_MODE = 1;??????????????
   */
  @Override
  protected void onModeChanged(int mode) {
    super.onModeChanged(mode);
    Log.d(TAG, "onModeChanged......");
  }

  /* 
   * ??????????????????
   */
  @Override
  protected void onRetrive(SyncData data) {
    super.onRetrive(data);
    Log.d(TAG, "onRetrive......");

    if (mIsWatch) {
      handleRetriveDataOnWatch(data);
    } else {
      handleRetriveDataOnPhone(data);
    }
  }

  private void handleRetriveDataOnWatch(SyncData data) {

  }

  /*
   * data: ??????????????????? ???????????????
   */
  private void handleRetriveDataOnPhone(SyncData data) {
    String connectCmd = data.getString(DemoUtil.KEY_CONNECT);

    if (connectCmd != null) {
      Log.d(TAG, "handleRetriveDataOnPhone connect cmd:" + connectCmd);
    } else {
      Message msg = mHandler.obtainMessage(MainActivity.UPDATE_VIEW_PHONE_RECORD);
      msg.obj = data;
      mHandler.sendMessage(msg);
    }

    // if(mTrack != null)
    // mTrack.write(bytes, 0, bytes.length);
  }

  @Override
  protected void onChannelDestroy(ParcelUuid uuid) {
    super.onChannelDestroy(uuid);
    Log.d(TAG, "onChannelDestroy......");
  }

  @Override
  protected void onClear(String address) {
    super.onClear(address);
    Log.d(TAG, "onClear......");
  }

  /*
   * ???????????????????????????connect=false????????????????????????
   */
  @Override
  protected void onConnectionStateChanged(boolean connect) {
    super.onConnectionStateChanged(connect);
    Log.d(TAG, "onConnectionStateChanged......" + connect);
  }

  /* 
   * ???????????
   */
  @Override
  protected void onFileRetriveComplete(String fileName, boolean success) {
    super.onFileRetriveComplete(fileName, success);
    Log.d(TAG, "onFileRetriveComplete......");
  }

  /* 
   * ??????????????
   */
  @Override
  protected void onFileSendComplete(String fileName, boolean success) {
    super.onFileSendComplete(fileName, success);
    Log.d(TAG, "onFileSendComplete......");
  }

  @Override
  protected void onInit() {
    super.onInit();
    Log.d(TAG, "onInit......");
  }
}




Java Source Code List

com.jayin.bluetooth.BaseActivity.java
com.jayin.bluetooth.Main.java
com.jayin.service.ConnectService.java
com.jayin.utils.Common.java
com.smartdevices.smartqwatchdemo.DemoModule.java
com.smartdevices.smartqwatchdemo.DemoUtil.java
com.smartdevices.smartqwatchdemo.MainActivity.java
com.smartdevices.smartqwatchdemo.WatchFaceClockProvider.java
com.smartdevices.smartqwatchdemo.WatchFaceDigitalClockProvider.java