public class SmotionActivity
extends java.lang.Object
import com.samsung.android.sdk.SsdkUnsupportedException; import com.samsung.android.sdk.motion.Smotion; import com.samsung.android.sdk.motion.SmotionActivity; import com.samsung.android.sdk.motion.SmotionActivity.ChangeListener; import com.samsung.android.sdk.motion.SmotionActivity.Info; import android.app.Activity; import android.os.Bundle; import android.os.Looper; public class MainActivity extends Activity { private Smotion mSmotion; private SmotionActivity mSmotionActivity; private int activityMode = SmotionActivity.Info.MODE_REALTIME; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSmotion = new Smotion(); try { mSmotion.initialize(getApplicationContext()); } catch (SsdkUnsupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (mSmotion.isFeatureEnabled(Smotion.TYPE_ACTIVITY)) { mSmotionActivity = new SmotionActivity(Looper.getMainLooper(), mSmotion); } } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); mSmotionActivity.start(activityMode, mChangeListener); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); mSmotionActivity.stop(); } private ChangeListener mChangeListener = new ChangeListener() { @Override public void onChanged(int mode, Info[] infoArray) { // TODO Auto-generated method stub if (mode == SmotionActivity.Info.MODE_REALTIME) { int status = infoArray[0].getStatus(); int accuracy = infoArray[0].getAccuracy(); long timestamp = infoArray[0].getTimeStamp(); } else if (mode == SmotionActivity.Info.MODE_BATCH) { for (int i = 0; i < infoArray.length; i++) { int status = infoArray[i].getStatus(); int accuracy = infoArray[i].getAccuracy(); long timestamp = infoArray[i].getTimeStamp(); } } } }; }
Modifier and Type | Class and Description |
---|---|
static interface |
SmotionActivity.ChangeListener
This listener interface receives activity events.
|
static class |
SmotionActivity.Info
This class contains the activity event information and provides methods
to access it.
|
Constructor and Description |
---|
SmotionActivity(android.os.Looper looper,
Smotion motion)
Creates a SmotionActivity instance with the specified looper and Smotion
instances.
|
Modifier and Type | Method and Description |
---|---|
SmotionActivity.Info |
getInfo()
Get the current activity information, such as status and accuracy.
|
boolean |
isActivitySupported(int activity)
Check if the device supports activity type passed.
|
boolean |
isUpdateInfoBatchModeSupport()
Check the device support updateInfo method in batch mode.
|
void |
start(int mode,
SmotionActivity.ChangeListener listener)
Add the specified ChangeListener instance.
|
void |
stop()
Remove the ChangeListener instance.
|
void |
updateInfo()
Update the activity information.
|
public SmotionActivity(android.os.Looper looper, Smotion motion)
looper
- The looper of the main thread in your application.motion
- The Smotion instance.java.lang.NullPointerException
- Thrown if the looper or Smotion object
passed is null.java.lang.IllegalArgumentException
- Thrown if the Context passed is null.
This can happen if you did not initialize the Motion package
before creating the SmotionActivity instance.java.lang.IllegalStateException
- Thrown if the device does not support
SmotionActivity.public void start(int mode, SmotionActivity.ChangeListener listener)
mode
- The mode for receiving activity events.listener
- The ChangeListener instance.java.lang.IllegalStateException
- Thrown if a listener is already registered
or if the device does not support SmotionActivity.java.lang.IllegalArgumentException
- Thrown if the mode passed is not valid
or the listener passed is null.public void stop()
java.lang.IllegalStateException
- Thrown when stop() is called before calling
the start() method.public SmotionActivity.Info getInfo()
java.lang.IllegalStateException
- - Thrown when getInfo() is called before
calling the start() method.public void updateInfo()
java.lang.IllegalStateException
- Thrown when the updateInfo() method is
called without calling start() method.public boolean isUpdateInfoBatchModeSupport()
public boolean isActivitySupported(int activity)
activity
- checked activity for device support.java.lang.IllegalArgumentException
- Thrown if the activity passed is not
valid