Skip to content

Instantly share code, notes, and snippets.

@RobertApikyan
Created November 17, 2023 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertApikyan/a937229471bb0dc572f0dad151c61a1b to your computer and use it in GitHub Desktop.
Save RobertApikyan/a937229471bb0dc572f0dad151c61a1b to your computer and use it in GitHub Desktop.
package com.hfh.wellbe.smartwatch.utils.sensors.accelerometer;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import com.eview.ecare.eCareServiceInterface;
public class MotionSample {
private static final String TAG = "MotionSample";
private static MotionSample instance;
private Context context;
private boolean motion;
private MotionSample() {
}
public static MotionSample getInstance(Context context) {
if (instance == null) {
instance = new MotionSample();
instance.context = context;
}
return instance;
}
private Handler mHandler = new Handler(Looper.getMainLooper()){
@Override
public void handleMessage(Message msg) {
int motion = msg.arg1;
onMotion(motion);
}
};
private void onMotion(int motion) {
Log.e(TAG,"motion --->" + motion);
}
/**
* 1、register motion state Listener
* @return
*/
public static boolean registerMotionState(){
Message message = Message.obtain(null, eCareServiceInterface.MSG_ECARE_REGISTER_MOTION);
message.arg1 = -1;
return eCareServiceInterface.getServiceInterface(instance.context).sendMessage(message);
}
/**
* 2、receive motion state
* @param motion 1 motion 0 no motion
*/
public void receiveMotionState(int motion){
Message message = mHandler.obtainMessage();
message.arg1 = motion;
mHandler.sendMessage(message);
}
/**
* query motion result
* @param motion
*/
public void motionStateResult(boolean motion){
Log.e(TAG,"motion = " + motion);
this.motion = motion;
}
/**
* query motion current state
*/
public void queryMotion(){
Message message = Message.obtain(null, eCareServiceInterface.MSG_ECARE_QUERY_MOTION);
eCareServiceInterface.getServiceInterface(instance.context).sendMessage(message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment