|
|
@@ -1,5 +1,6 @@
|
|
|
package basepedo.ui;
|
|
|
|
|
|
+import android.app.ActivityManager;
|
|
|
import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
@@ -15,6 +16,7 @@ import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
import com.xzjmyk.pm.activity.ui.MainActivity;
|
|
|
@@ -59,12 +61,12 @@ public class MyPedometerActivity extends BaseActivity implements Handler.Callbac
|
|
|
case Constant.MSG_FROM_SERVER:
|
|
|
// 更新界面上的步数
|
|
|
int step_num = msg.getData().getInt("step");
|
|
|
- if (step_num < 9000){
|
|
|
- text_step.setText("今天的你已经走了"+ step_num + "\t步,继续努力!");
|
|
|
- }else if (step_num < 10000 && step_num >= 9000){
|
|
|
- text_step.setText("今天的你已经走了"+ step_num + "\t步,加油,快到10000步了!");
|
|
|
- }else if (step_num > 10000 && step_num <=20000){
|
|
|
- text_step.setText("今天的你已经走了"+ step_num + "\t步,真棒!");
|
|
|
+ if (step_num < 3000){
|
|
|
+ text_step.setText("今天的你已经走了"+ step_num + "\t步,还不错!继续努力!");
|
|
|
+ }else if (step_num < 6000 && step_num >= 3000){
|
|
|
+ text_step.setText("今天的你已经走了"+ step_num + "\t步,加油!快到6000步了!");
|
|
|
+ }else if (step_num > 6000 && step_num <=10000){
|
|
|
+ text_step.setText("今天的你已经走了"+ step_num + "\t步,真!,快到10000步了!!");
|
|
|
}else {
|
|
|
text_step.setText("今天的你已经走了"+ step_num + "\t步,太棒了!天呐,你一定是用了洪荒之力吧,注意休息哦!");
|
|
|
}
|
|
|
@@ -95,10 +97,24 @@ public class MyPedometerActivity extends BaseActivity implements Handler.Callbac
|
|
|
text_step = (TextView) findViewById(R.id.text_step);
|
|
|
close_step = (Button) findViewById(R.id.close_uu_step_bt);
|
|
|
open_step = (Button) findViewById(R.id.open_uu_step_bt);
|
|
|
+
|
|
|
+ if (isServiceRunning() == true){
|
|
|
+ setupService();
|
|
|
+ open_step.setVisibility(View.GONE);
|
|
|
+ close_step.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ open_step.setVisibility(View.VISIBLE);
|
|
|
+ close_step.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
open_step.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
-
|
|
|
+ Intent intent = new Intent(mContext, StepService.class);
|
|
|
+ bindService(intent, conn, Context.BIND_AUTO_CREATE);
|
|
|
+ startService(intent);
|
|
|
+ Toast.makeText(MyPedometerActivity.this, "您已开启UU运动,UU将记录您的运动步数并显示在通知栏", Toast.LENGTH_LONG).show();
|
|
|
+ open_step.setVisibility(View.GONE);
|
|
|
+ close_step.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
});
|
|
|
delayHandler = new Handler(this);
|
|
|
@@ -106,20 +122,20 @@ public class MyPedometerActivity extends BaseActivity implements Handler.Callbac
|
|
|
close_step.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
-// stopService(new Intent(mContext, StepService.class));
|
|
|
-// onDestroy();
|
|
|
-// Toast.makeText(MyPedometerActivity.this, "您已关闭UU运动,消息栏将不再显示您的运动步数", Toast.LENGTH_LONG).show();
|
|
|
- ToastMessage("该功能尚未完善");
|
|
|
+ unbindService(conn);
|
|
|
+ stopService(new Intent(mContext, StepService.class));
|
|
|
+ Toast.makeText(MyPedometerActivity.this, "您已关闭UU运动,通知栏将不再显示您的运动步数", Toast.LENGTH_LONG).show();
|
|
|
+ finish();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected void onStart() {
|
|
|
- super.onStart();
|
|
|
- setupService();
|
|
|
- }
|
|
|
-
|
|
|
+// @Override
|
|
|
+// protected void onStart() {
|
|
|
+// super.onStart();
|
|
|
+// setupService();
|
|
|
+// }
|
|
|
+//
|
|
|
private void setupService() {
|
|
|
Intent intent = new Intent(this, StepService.class);
|
|
|
bindService(intent, conn, Context.BIND_AUTO_CREATE);
|
|
|
@@ -137,12 +153,12 @@ public class MyPedometerActivity extends BaseActivity implements Handler.Callbac
|
|
|
// super.onBackPressed();
|
|
|
// }
|
|
|
|
|
|
- @Override
|
|
|
- protected void onDestroy() {
|
|
|
- super.onDestroy();
|
|
|
- unbindService(conn);
|
|
|
- finish();
|
|
|
- }
|
|
|
+// @Override
|
|
|
+// protected void onDestroy() {
|
|
|
+// super.onDestroy();
|
|
|
+// unbindService(conn);
|
|
|
+// finish();
|
|
|
+// }
|
|
|
|
|
|
@Override
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
@@ -164,4 +180,13 @@ public class MyPedometerActivity extends BaseActivity implements Handler.Callbac
|
|
|
super.onBackPressed();
|
|
|
finish();
|
|
|
}
|
|
|
+ private boolean isServiceRunning() { //判断UU运动服务是否已经运行
|
|
|
+ ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
|
|
|
+ for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
|
|
+ if ("basepedo.service.StepService".equals(service.service.getClassName())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|