Created
November 17, 2023 12:45
-
-
Save RobertApikyan/a937229471bb0dc572f0dad151c61a1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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