public class SmotionActivityNotification
extends java.lang.Object
import com.samsung.android.sdk.SsdkUnsupportedException; import com.samsung.android.sdk.motion.Smotion; import com.samsung.android.sdk.motion.SmotionActivityNotification; import com.samsung.android.sdk.motion.SmotionActivityNotification.ChangeListener; import com.samsung.android.sdk.motion.SmotionActivityNotification.Info; import com.samsung.android.sdk.motion.SmotionActivityNotification.InfoFilter; import android.app.Activity; import android.os.Bundle; import android.os.Looper; public class MainActivity extends Activity { private Smotion mSmotion; private SmotionActivityNotification mSmotionActivityNotification; private SmotionActivityNotification.InfoFilter mInfoFilter; @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_NOTIFICATION)) { mSmotionActivityNotification = new SmotionActivityNotification(Looper.getMainLooper(), mSmotion); mInfoFilter = new InfoFilter(); } } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); if (mSmotionActivityNotification .isActivitySupported(SmotionActivityNotification.Info.STATUS_STATIONARY)) { mInfoFilter.addActivity(SmotionActivityNotification.Info.STATUS_STATIONARY); } if (mSmotionActivityNotification .isActivitySupported(SmotionActivityNotification.Info.STATUS_WALK)) { mInfoFilter.addActivity(SmotionActivityNotification.Info.STATUS_WALK); } if (mSmotionActivityNotification .isActivitySupported(SmotionActivityNotification.Info.STATUS_RUN)) { mInfoFilter.addActivity(SmotionActivityNotification.Info.STATUS_RUN); } if (mSmotionActivityNotification .isActivitySupported(SmotionActivityNotification.Info.STATUS_VEHICLE)) { mInfoFilter.addActivity(SmotionActivityNotification.Info.STATUS_VEHICLE); } mSmotionActivityNotification.start(mInfoFilter, mChangeListener); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); mSmotionActivityNotification.stop(); } private ChangeListener mChangeListener = new ChangeListener() { @Override public void onChanged(Info info) { // TODO Auto-generated method stub long timestamp = info.getTimeStamp(); int status = info.getStatus(); int accuracy = info.getAccuracy(); } }; }
Modifier and Type | Class and Description |
---|---|
static interface |
SmotionActivityNotification.ChangeListener
This listener interface receives activity notification events.
|
static class |
SmotionActivityNotification.Info
This class contains the activity notification event information and
provides methods to access it.
|
static class |
SmotionActivityNotification.InfoFilter
This class provides specific activity notification actions.
|
Constructor and Description |
---|
SmotionActivityNotification(android.os.Looper looper,
Smotion motion)
Creates a SmotionActivityNotification instance with the specified looper
and Smotion instances.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isActivitySupported(int activity)
Check if the device supports activity type passed.
|
void |
start(SmotionActivityNotification.InfoFilter filter,
SmotionActivityNotification.ChangeListener listener)
Add the specified ChangeListener instance.
|
void |
stop()
Remove the ChangeListener instance.
|
public SmotionActivityNotification(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 SmotionActivityNotification instance.java.lang.IllegalStateException
- Thrown if the device does not support
SmotionActivityNotification.public void start(SmotionActivityNotification.InfoFilter filter, SmotionActivityNotification.ChangeListener listener)
filter
- The InfoFilter instance for creating activity notification
events.listener
- The ChangeListener instance for receiving activity
notification events.java.lang.IllegalStateException
- Thrown if a listener is already registered
or the device does not support SmotionActivityNotification.java.lang.IllegalArgumentException
- Thrown if the listener or InfoFilter
passed is null or if the InfoFilter passed is empty.public void stop()
java.lang.IllegalStateException
- Thrown when stop() is called before calling
the start() method.public boolean isActivitySupported(int activity)
activity
- checked activity for device support.java.lang.IllegalArgumentException
- Thrown if the activity passed is not
valid