public class SmotionPedometer
extends java.lang.Object
import com.samsung.android.sdk.SsdkUnsupportedException; import com.samsung.android.sdk.motion.Smotion; import com.samsung.android.sdk.motion.SmotionPedometer; import com.samsung.android.sdk.motion.SmotionPedometer.ChangeListener; import com.samsung.android.sdk.motion.SmotionPedometer.Info; import android.app.Activity; import android.os.Bundle; import android.os.Looper; public class MainActivity extends Activity { private Smotion mSmotion; private SmotionPedometer mSmotionPedometer; @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_PEDOMETER)) { mSmotionPedometer = new SmotionPedometer(Looper.getMainLooper(), mSmotion); } } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); mSmotionPedometer.start(mChangeListener); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); mSmotionPedometer.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(); long stepCount = info.getCount(SmotionPedometer.Info.COUNT_TOTAL); double distance = info.getDistance(); double speed = info.getSpeed(); double calorie = info.getCalorie(); } }; }
Modifier and Type | Class and Description |
---|---|
static interface |
SmotionPedometer.ChangeListener
This listener interface receives pedometer events.
|
static class |
SmotionPedometer.Info
This class contains the pedometer event information and provides methods
to access it.
|
Constructor and Description |
---|
SmotionPedometer(android.os.Looper looper,
Smotion motion)
Creates a SmotionPedometer instance with the specified looper and Smotion
instances.
|
Modifier and Type | Method and Description |
---|---|
SmotionPedometer.Info |
getInfo()
Get the pedometer information such as step count, calorie consumption,
distance, speed, and status.
|
void |
start(SmotionPedometer.ChangeListener listener)
Add the specified ChangeListener instance.
|
void |
stop()
Remove the ChangeListener instance.
|
void |
updateInfo()
Update the pedometer information when the screen is off.
|
public SmotionPedometer(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 SmotionPedometer instance.java.lang.IllegalStateException
- Thrown if the device does not support
SmotionPedometer.public void start(SmotionPedometer.ChangeListener listener)
listener
- The ChangeListener instance.java.lang.IllegalStateException
- Thrown if a listener is already registered
or the device does not support SmotionPedometer.java.lang.IllegalArgumentException
- Thrown if the listener passed is null.public void stop()
java.lang.IllegalStateException
- Thrown when stop() is called before calling
the start() method.public SmotionPedometer.Info getInfo()
java.lang.IllegalStateException
- Thrown when getInfo() is called before
calling the start() method.public void updateInfo()
java.lang.IllegalStateException
- Thrown when updateInfo() is called before
calling the start() method.