public class MainActivity extends AppCompatActivity {
private static String TAG = "MainActivity";
private static final int REFRESH_STEP_WHAT = 0;
//循环取当前时刻的步数中间的间隔时间
private long TIME_INTERVAL_REFRESH = 500;
private Handler mDelayHandler = new Handler(new TodayStepCounterCall());
private int mStepSum;
private ISportStepInterface iSportStepInterface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this, VitalityStepService.class);
startService(intent);
bindService(intent, new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
iSportStepInterface = ISportStepInterface.Stub.asInterface(service);
try {
mStepSum = iSportStepInterface.getCurrTimeSportStep();
updateStepCount();
} catch (RemoteException e) {
e.printStackTrace();
}
mDelayHandler.sendEmptyMessageDelayed(REFRESH_STEP_WHAT, TIME_INTERVAL_REFRESH);
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
}, Context.BIND_AUTO_CREATE);
}
class TodayStepCounterCall implements Handler.Callback{
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case REFRESH_STEP_WHAT: {
if (null != iSportStepInterface) {
int step = 0;
try {
step = iSportStepInterface.getCurrTimeSportStep();
} catch (RemoteException e) {
e.printStackTrace();
}
if (mStepSum != step) {
mStepSum = step;
updateStepCount();
}
}
mDelayHandler.sendEmptyMessageDelayed(REFRESH_STEP_WHAT, TIME_INTERVAL_REFRESH);
break;
}
}
return false;
}
}
private void updateStepCount() {
Log.e(TAG,"updateStepCount : " + mStepSum);
TextView stepTextView = (TextView)findViewById(R.id.stepTextView);
stepTextView.setText(mStepSum + "步");
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有