Browse Source

新的计步方式完成,备份

FANGLH 9 years ago
parent
commit
22fc6f4bbf
22 changed files with 1786 additions and 13 deletions
  1. 20 1
      WeiChat/src/main/AndroidManifest.xml
  2. 3 3
      WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/MainActivity.java
  3. 9 8
      WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/me/SettingActivity.java
  4. 46 0
      WeiChat/src/main/java/com/xzjmyk/pm/newpedo/bean/StepEntity.java
  5. 107 0
      WeiChat/src/main/java/com/xzjmyk/pm/newpedo/calendar/BeforeOrAfterCalendarView.java
  6. 119 0
      WeiChat/src/main/java/com/xzjmyk/pm/newpedo/calendar/RecordsCalenderItemView.java
  7. 13 0
      WeiChat/src/main/java/com/xzjmyk/pm/newpedo/constant/Constant.java
  8. 37 0
      WeiChat/src/main/java/com/xzjmyk/pm/newpedo/db/DBOpenHelper.java
  9. 119 0
      WeiChat/src/main/java/com/xzjmyk/pm/newpedo/db/StepDataDao.java
  10. 390 0
      WeiChat/src/main/java/com/xzjmyk/pm/newpedo/service/StepService.java
  11. 48 0
      WeiChat/src/main/java/com/xzjmyk/pm/newpedo/utils/StepCountCheckUtil.java
  12. 166 0
      WeiChat/src/main/java/com/xzjmyk/pm/newpedo/utils/TimeUtil.java
  13. 285 0
      WeiChat/src/main/java/com/xzjmyk/pm/newpedo/view/NewStepActivity.java
  14. 96 0
      WeiChat/src/main/java/com/xzjmyk/pm/newpedo/view/NewStepListActivity.java
  15. BIN
      WeiChat/src/main/res/drawable-xhdpi/ic_blue_round_bg.png
  16. BIN
      WeiChat/src/main/res/drawable-xhdpi/ic_small_blue_rectangular.png
  17. 205 0
      WeiChat/src/main/res/layout/activity_newstep.xml
  18. 1 1
      WeiChat/src/main/res/layout/activity_setting.xml
  19. 14 0
      WeiChat/src/main/res/layout/before_or_after_calendar_layout.xml
  20. 44 0
      WeiChat/src/main/res/layout/newstep_data.xml
  21. 58 0
      WeiChat/src/main/res/layout/records_calender_item_view.xml
  22. 6 0
      WeiChat/src/main/res/values/colors.xml

+ 20 - 1
WeiChat/src/main/AndroidManifest.xml

@@ -913,7 +913,26 @@
             android:name=".ui.erp.activity.oa.NavigationActivity"
             android:label="导航" />
         <activity android:name=".ui.erp.activity.oa.NavigationWebActivity"/>
-
+        <activity android:name="com.xzjmyk.pm.newpedo.view.NewStepActivity"
+            android:label="UU运动"/>
+        <activity android:name="com.xzjmyk.pm.newpedo.view.NewStepListActivity"
+            android:label="更多历史记录"/>
+        <!-- 计步功能 -->
+        <service
+            android:name="com.xzjmyk.pm.newpedo.service.StepService"
+            android:priority="1000"
+            android:process="com.spring.stepcount.service">
+            <intent-filter>
+                <!-- 系统启动完成后会调用-->
+                <action android:name="android.intent.action.BOOT_COMPLETED" />
+                <action android:name="android.intent.action.DATE_CHANGED" />
+                <action android:name="android.intent.action.MEDIA_MOUNTED" />
+                <action android:name="android.intent.action.USER_PRESENT" />
+                <action android:name="android.intent.action.ACTION_TIME_TICK" />
+                <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
+                <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
+            </intent-filter>
+        </service>
     </application>
 
 </manifest>

+ 3 - 3
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/MainActivity.java

@@ -66,7 +66,7 @@ import com.xzjmyk.pm.activity.xmpp.ListenerManager;
 import com.xzjmyk.pm.activity.xmpp.listener.AuthStateListener;
 import com.xzjmyk.pm.basepedo.config.Constant;
 import com.xzjmyk.pm.basepedo.service.StepService;
-import com.xzjmyk.pm.basepedo.ui.MyPedometerActivity;
+import com.xzjmyk.pm.newpedo.view.NewStepActivity;
 
 import java.util.HashMap;
 import java.util.List;
@@ -420,8 +420,8 @@ public class MainActivity extends BaseActivity implements NetWorkObservable.NetW
         // TODO 判断上一个状态UU运动是否预关闭
         int isUUStep = PreferenceUtils.getInt(MyApplication.getInstance(), MainActivity.UU_STEP);
         if (isUUStep == 1) {
-            startService(new Intent(mContext, StepService.class));
-            PreferenceUtils.putInt(MyPedometerActivity.UU_STEP_NOTICE, 1);
+            startService(new Intent(mContext, com.xzjmyk.pm.newpedo.service.StepService.class));
+            PreferenceUtils.putInt(NewStepActivity.UU_STEP_NOTICE, 1);
             PushManager.resumeWork(MyApplication.getInstance());
         }
         //TODO 发布版本关闭

+ 9 - 8
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/me/SettingActivity.java

@@ -47,7 +47,7 @@ import com.xzjmyk.pm.activity.util.GetFileSizeUtil;
 import com.xzjmyk.pm.activity.util.PreferenceUtils;
 import com.xzjmyk.pm.activity.util.TimeUtils;
 import com.xzjmyk.pm.activity.util.ToastUtil;
-import com.xzjmyk.pm.basepedo.ui.MyPedometerActivity;
+import com.xzjmyk.pm.newpedo.view.NewStepActivity;
 
 import java.io.File;
 
@@ -84,6 +84,7 @@ public class SettingActivity extends ActionBackActivity implements View.OnClickL
     private ProgressDialog dialog;
     private RelativeLayout share_rl;
     private String uustep_service_name = "com.xzjmyk.pm.basepedo.service.StepService";
+    private String newStep_service_name = "com.xzjmyk.pm.newpedo.service.StepService";
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -97,7 +98,7 @@ public class SettingActivity extends ActionBackActivity implements View.OnClickL
 
     private void initView() {
         new_step_rl.setOnClickListener(this);
-        new_step_rl.setVisibility(View.GONE);
+//        new_step_rl.setVisibility(View.GONE);
 
         dialog = new ProgressDialog(this);
         dialog.setIndeterminate(true);
@@ -149,8 +150,8 @@ public class SettingActivity extends ActionBackActivity implements View.OnClickL
 
         //UU开关的 根据StepService是否开启显示状态
         int isStep = PreferenceUtils.getInt(MyApplication.getInstance(), MainActivity.UU_STEP);
-         boolean sbb = isServiceRunning(uustep_service_name);
-        if (isServiceRunning(uustep_service_name)&&(isStep == -1 || isStep == 1)){
+         boolean sbb = isServiceRunning(newStep_service_name);
+        if (isServiceRunning(newStep_service_name)&&(isStep == -1 || isStep == 1)){
             uu_step_reply.setChecked(true);
         }else {
             speech_recognition_rl.setVisibility(View.GONE);
@@ -164,7 +165,7 @@ public class SettingActivity extends ActionBackActivity implements View.OnClickL
                     PreferenceUtils.putInt(MainActivity.UU_STEP, 1);
                     PushManager.resumeWork(MyApplication.getInstance());
                     Toast.makeText(mContext, "您已开启UU运动", Toast.LENGTH_LONG).show();
-                    startActivity(new Intent(mContext, MyPedometerActivity.class));
+                    startActivity(new Intent(mContext, NewStepActivity.class));
                 } else {
                     PushManager.stopWork(MyApplication.getInstance());
                     PreferenceUtils.putInt(MainActivity.UU_STEP, 0);
@@ -178,8 +179,8 @@ public class SettingActivity extends ActionBackActivity implements View.OnClickL
             @Override
             public void onClick(View v) {
                 int last_isStep = PreferenceUtils.getInt(MyApplication.getInstance(), MainActivity.UU_STEP);
-                if (isServiceRunning(uustep_service_name) && last_isStep == 1) {
-                    startActivity(new Intent(mContext, MyPedometerActivity.class));
+                if (isServiceRunning(newStep_service_name) && last_isStep == 1) {
+                    startActivity(new Intent(mContext, NewStepActivity.class));
                 } else {
                     Toast.makeText(mContext, "尚未开启UU运动,或已预关闭", Toast.LENGTH_SHORT).show();
                 }
@@ -188,7 +189,7 @@ public class SettingActivity extends ActionBackActivity implements View.OnClickL
         new_step_rl.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                startActivity(new Intent(mContext, MyPedometerActivity.class));
+                startActivity(new Intent(mContext, NewStepActivity.class));
             }
         });
         //长按UU运动栏会显示语音识别界面

+ 46 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/bean/StepEntity.java

@@ -0,0 +1,46 @@
+package com.xzjmyk.pm.newpedo.bean;
+
+/**
+ * Created by FANGLH
+ * Date : 2017/4/13
+ * To do :
+ */
+
+public class StepEntity {
+
+    private String curDate; //当天的日期
+    private String steps;   //当天的步数
+
+    public StepEntity() {
+    }
+
+    public StepEntity(String curDate, String steps) {
+        this.curDate = curDate;
+        this.steps = steps;
+    }
+
+    public String getCurDate() {
+        return curDate;
+    }
+
+    public void setCurDate(String curDate) {
+        this.curDate = curDate;
+    }
+
+    public String getSteps() {
+        return steps;
+    }
+
+    public void setSteps(String steps) {
+        this.steps = steps;
+    }
+
+
+    @Override
+    public String toString() {
+        return "StepEntity{" +
+                "curDate='" + curDate + '\'' +
+                ", steps=" + steps +
+                '}';
+    }
+}

+ 107 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/calendar/BeforeOrAfterCalendarView.java

@@ -0,0 +1,107 @@
+package com.xzjmyk.pm.newpedo.calendar;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+
+import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.newpedo.utils.TimeUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by FANGLH
+ * Date : 2017/4/13
+ * To do :查看当前日期前七天或后七天日历
+ */
+
+public class BeforeOrAfterCalendarView extends RelativeLayout {
+
+    private List<Integer> dayList = new ArrayList<>();
+    private List<String> dateList = new ArrayList<>();
+
+    protected List<RecordsCalenderItemView> itemViewList = new ArrayList<>();
+    protected Context mContext;
+    protected LinearLayout calenderViewLl;
+    protected int curPosition;
+
+    public BeforeOrAfterCalendarView(Context context) {
+        super(context);
+        this.mContext = context;
+        init();
+    }
+
+    private void init() {
+        View view = LayoutInflater.from(mContext).inflate(R.layout.before_or_after_calendar_layout, this);
+
+        calenderViewLl = (LinearLayout) view.findViewById(R.id.boa_calender_view_ll);
+
+        setBeforeDateViews();
+
+        initItemViews();
+    }
+
+    /**
+     * 设置之前的日期显示
+     */
+    private void setBeforeDateViews() {
+        //获取日期列表
+        dateList.addAll(TimeUtil.getBeforeDateListByNow());
+        dayList.addAll(TimeUtil.dateListToDayList(dateList));
+    }
+
+    private void initItemViews() {
+        for (int i = 0; i < dateList.size(); i++) {
+            int day = dayList.get(i);
+            String curItemDate = dateList.get(i);
+            final RecordsCalenderItemView itemView;
+            if(day == TimeUtil.getCurrentDay()){
+                itemView = new RecordsCalenderItemView(mContext, "今天", String.valueOf(day), i, curItemDate);
+            }else{
+                itemView = new RecordsCalenderItemView(mContext, TimeUtil.getCurWeekDay(curItemDate), String.valueOf(day), i, curItemDate);
+            }
+
+            itemViewList.add(itemView);
+            calenderViewLl.addView(itemView);
+
+            itemView.setOnCalenderItemClick(new RecordsCalenderItemView.OnCalenderItemClick() {
+                @Override
+                public void onCalenderItemClick() {
+                    curPosition = itemView.getPosition();
+                    switchPositionView(curPosition);
+
+                    //点击事件
+                    if (calenderClickListener != null) {
+                        calenderClickListener.onClickToRefresh(curPosition,dateList.get(curPosition));
+                    }
+                }
+            });
+        }
+
+        switchPositionView(6);
+
+    }
+
+    private void switchPositionView(int position) {
+        for (int i = 0; i < itemViewList.size(); i++) {
+            if (position == i) {
+                itemViewList.get(i).setChecked(true);
+            } else {
+                itemViewList.get(i).setChecked(false);
+            }
+        }
+    }
+
+    private BoaCalenderClickListener calenderClickListener;
+
+    public interface BoaCalenderClickListener {
+        void onClickToRefresh(int position, String curDate);
+    }
+
+    public void setOnBoaCalenderClickListener(BoaCalenderClickListener calenderClickListener) {
+        this.calenderClickListener = calenderClickListener;
+    }
+}

+ 119 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/calendar/RecordsCalenderItemView.java

@@ -0,0 +1,119 @@
+package com.xzjmyk.pm.newpedo.calendar;
+
+import android.content.Context;
+import android.graphics.Color;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.newpedo.view.NewStepActivity;
+
+
+/**
+ * 查看一周内每天的历史纪录日历Item布局
+ */
+
+public class RecordsCalenderItemView extends RelativeLayout {
+    private static final String TAG = "RecordsCalenderItemView";
+
+    private Context mContext;
+
+    private LinearLayout itemLl;
+    private View lineView;
+    private TextView weekTv;
+    private RelativeLayout dateRl;
+    private TextView dateTv;
+    //日期时间
+    private String weekStr, dateStr;
+    private int position;
+
+    //当前item 的时间  ,如   2017年02月07日 ,  用以判断当前item是否可以被点击
+    protected String curItemDate;
+
+
+    OnCalenderItemClick itemClick = null;
+
+    public interface OnCalenderItemClick {
+        public void onCalenderItemClick();
+    }
+
+    public void setOnCalenderItemClick(OnCalenderItemClick itemClick) {
+        this.itemClick = itemClick;
+    }
+
+
+    public RecordsCalenderItemView(Context context, String week, String date, int position, String curItemDate) {
+        super(context);
+        this.mContext = context;
+        this.weekStr = week;
+        this.dateStr = date;
+        this.position = position;
+        this.curItemDate = curItemDate;
+        init();
+    }
+
+    private void init() {
+        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        final View itemView = inflater.inflate(R.layout.records_calender_item_view, this);
+        itemLl = (LinearLayout) itemView.findViewById(R.id.records_calender_item_ll);
+        weekTv = (TextView) itemView.findViewById(R.id.records_calender_item_week_tv);
+        lineView = itemView.findViewById(R.id.calendar_item_line_view);
+        dateRl = (RelativeLayout) itemView.findViewById(R.id.records_calender_item_date_rl);
+        dateTv = (TextView) itemView.findViewById(R.id.records_calender_item_date_tv);
+
+        //如果日期是今天的话设为选中  目前有BUG
+
+//        if(curItemDate.equals(TimeUtil.getCurrentDate())){
+//            dateTv.setBackgroundResource(R.drawable.ic_blue_round_border_bg);
+//            dateTv.getBackground().setAlpha(255);
+//        }else{
+//            if(dateTv.getBackground() != null){
+//                dateTv.getBackground().setAlpha(0);
+//            }
+//        }
+
+
+        weekTv.setTextSize(15);
+        lineView.setVisibility(GONE);
+
+        weekTv.setText(weekStr);
+        dateTv.setText(dateStr);
+
+        itemView.setLayoutParams(new LayoutParams((NewStepActivity.screenWidth) / 7,
+                ViewGroup.LayoutParams.MATCH_PARENT));
+
+        itemView.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                itemClick.onCalenderItemClick();
+            }
+        });
+
+    }
+
+    //返回当前项的id
+    public int getPosition() {
+        return position;
+    }
+
+    public void setChecked(boolean checkedFlag) {
+
+        if (checkedFlag) {
+            //当前item被选中后样式
+            weekTv.setTextColor(getResources().getColor(R.color.main_text_color));
+            dateTv.setTextColor(getResources().getColor(R.color.white));
+            dateRl.setBackgroundResource(R.drawable.ic_blue_round_bg);
+        } else {
+            //当前item未被选中样式
+            weekTv.setTextColor(getResources().getColor(R.color.gray_default_dark));
+            dateTv.setTextColor(getResources().getColor(R.color.gray_default_dark));
+            //设置背景透明
+            dateRl.setBackgroundColor(Color.TRANSPARENT);
+        }
+
+    }
+}

+ 13 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/constant/Constant.java

@@ -0,0 +1,13 @@
+package com.xzjmyk.pm.newpedo.constant;
+
+/**
+ * Created by FANGLH
+ * Date : 2017/3/24
+ * To do :
+ */
+
+public class Constant {
+    public static final int MSG_FROM_CLIENT = 0;
+    public static final int MSG_FROM_SERVER = 1;
+
+}

+ 37 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/db/DBOpenHelper.java

@@ -0,0 +1,37 @@
+package com.xzjmyk.pm.newpedo.db;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+
+/**
+ * Created by FANGLH
+ * Date : 2017/4/13
+ * To do :
+ */
+
+public class DBOpenHelper extends SQLiteOpenHelper {
+    private static final String DB_NAME = "StepCounter.db"; //数据库名称
+    private static final int DB_VERSION = 1;//数据库版本,大于0
+
+    //用于创建Banner表
+    private static final String CREATE_BANNER = "create table step ("
+            + "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+            + "curDate TEXT, "
+            + "totalSteps TEXT)";
+
+
+    public DBOpenHelper(Context context) {
+        super(context, DB_NAME, null,DB_VERSION);
+    }
+
+    @Override
+    public void onCreate(SQLiteDatabase db) {
+        db.execSQL(CREATE_BANNER);//执行有更改的sql语句
+    }
+
+    @Override
+    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+
+    }
+}

+ 119 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/db/StepDataDao.java

@@ -0,0 +1,119 @@
+package com.xzjmyk.pm.newpedo.db;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+
+import com.xzjmyk.pm.newpedo.bean.StepEntity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by FANGLH
+ * Date : 2017/4/13
+ * To do :
+ */
+
+public class StepDataDao {
+    private DBOpenHelper stepHelper;
+    private SQLiteDatabase stepDb;
+
+    public StepDataDao(Context context) {
+        stepHelper = new DBOpenHelper(context);
+    }
+
+    /**
+     * 添加一条新记录
+     *
+     * @param stepEntity
+     */
+    public void addNewData(StepEntity stepEntity) {
+        stepDb = stepHelper.getReadableDatabase();
+
+        ContentValues values = new ContentValues();
+        values.put("curDate", stepEntity.getCurDate());
+        values.put("totalSteps", stepEntity.getSteps());
+        stepDb.insert("step", null, values);
+
+        stepDb.close();
+    }
+
+    /**
+     * 根据日期查询记录
+     *
+     * @param curDate
+     * @return
+     */
+    public StepEntity getCurDataByDate(String curDate) {
+        stepDb = stepHelper.getReadableDatabase();
+        StepEntity stepEntity = null;
+        Cursor cursor = stepDb.query("step", null, null, null, null, null, null);
+        while (cursor.moveToNext()) {
+            String date = cursor.getString(cursor.getColumnIndexOrThrow("curDate"));
+            if (curDate.equals(date)) {
+                String steps = cursor.getString(cursor.getColumnIndexOrThrow("totalSteps"));
+                stepEntity = new StepEntity(date, steps);
+                //跳出循环
+                break;
+            }
+        }
+        //关闭
+        stepDb.close();
+        cursor.close();
+        return stepEntity;
+    }
+
+    /**
+     * 查询所有的记录
+     *
+     * @return
+     */
+    public List<StepEntity> getAllDatas() {
+        List<StepEntity> dataList = new ArrayList<>();
+        stepDb = stepHelper.getReadableDatabase();
+        Cursor cursor = stepDb.rawQuery("select * from step", null);
+
+        while (cursor.moveToNext()) {
+            String curDate = cursor.getString(cursor.getColumnIndex("curDate"));
+            String totalSteps = cursor.getString(cursor.getColumnIndex("totalSteps"));
+            StepEntity entity = new StepEntity(curDate, totalSteps);
+            dataList.add(entity);
+        }
+
+        //关闭数据库
+        stepDb.close();
+        cursor.close();
+        return dataList;
+    }
+
+    /**
+     * 更新数据
+     * @param stepEntity
+     */
+    public void updateCurData(StepEntity stepEntity) {
+        stepDb = stepHelper.getReadableDatabase();
+
+        ContentValues values = new ContentValues();
+        values.put("curDate",stepEntity.getCurDate());
+        values.put("totalSteps", stepEntity.getSteps());
+        stepDb.update("step", values, "curDate=?", new String[]{stepEntity.getCurDate()});
+
+        stepDb.close();
+    }
+
+
+    /**
+     * 删除指定日期的记录
+     *
+     * @param curDate
+     */
+    public void deleteCurData(String curDate) {
+        stepDb = stepHelper.getReadableDatabase();
+
+        if (stepDb.isOpen())
+            stepDb.delete("step", "curDate", new String[]{curDate});
+        stepDb.close();
+    }
+}

+ 390 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/service/StepService.java

@@ -0,0 +1,390 @@
+package com.xzjmyk.pm.newpedo.service;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.graphics.BitmapFactory;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.CountDownTimer;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.RemoteException;
+import android.support.annotation.Nullable;
+
+import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.newpedo.bean.StepEntity;
+import com.xzjmyk.pm.newpedo.constant.Constant;
+import com.xzjmyk.pm.newpedo.db.StepDataDao;
+import com.xzjmyk.pm.newpedo.utils.TimeUtil;
+import com.xzjmyk.pm.newpedo.view.NewStepActivity;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Created by FANGLH
+ * Date : 2017/4/13
+ * To do :
+ */
+
+public class StepService extends Service implements SensorEventListener {
+    public static final String TAG = "StepService";
+
+    //当前日期
+    private static String CURRENT_DATE;
+    //当前步数
+    private int CURRENT_STEP;
+    //3秒进行一次存储
+    private static int saveDuration = 3000;
+    //传感器
+    private SensorManager sensorManager;
+    //数据库
+    private StepDataDao stepDataDao;
+    //计步传感器类型 0-counter 1-detector
+    private static int stepSensor = -1;
+    //广播接收
+    private BroadcastReceiver mInfoReceiver;
+    //自定义简易计时器
+    private TimeCount timeCount;
+    //发送消息,用来和Service之间传递步数
+    private Messenger messenger = new Messenger(new MessengerHandler());
+    //是否有当天的记录
+    private boolean hasRecord;
+    //未记录之前的步数
+    private int hasStepCount;
+    //下次记录之前的步数
+    private int previousStepCount;
+    private Notification.Builder builder;
+
+    private NotificationManager notificationManager;
+    private Intent nfIntent;
+
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        initBroadcastReceiver();
+        new Thread(new Runnable() {
+            public void run() {
+                getStepDetector();
+            }
+        }).start();
+        startTimeCount();
+        initTodayData();
+    }
+
+    @Nullable
+    @Override
+    public IBinder onBind(Intent intent) {
+        return messenger.getBinder();
+    }
+
+
+    @Override
+    public int onStartCommand(Intent intent, int flags, int startId) {
+        /**
+         * 此处设将Service为前台,不然当APP结束以后很容易被GC给干掉,这也就是大多数音乐播放器会在状态栏设置一个
+         * 原理大都是相通的
+         */
+        notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+        //获取一个Notification构造器
+        builder = new Notification.Builder(this.getApplicationContext());
+        /**
+         * 设置点击通知栏打开的界面,此处需要注意了,如果你的计步界面不在主界面,则需要判断app是否已经启动,
+         * 再来确定跳转页面,这里面太多坑,(别问我为什么知道 - -)
+         * 总之有需要的可以和我交流
+         */
+        nfIntent = new Intent(this, NewStepActivity.class);
+        builder.setContentIntent(PendingIntent.getActivity(this, 0, nfIntent, 0)) // 设置PendingIntent
+                .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.uuu)) // 设置下拉列表中的图标(大图标)
+                .setContentTitle("UU运动") // 设置下拉列表里的标题
+                .setSmallIcon(R.drawable.uuu) // 设置状态栏内的小图标
+                .setContentText("今日步数:"+CURRENT_STEP+"步"); // 设置上下文内容
+        // 获取构建好的Notification
+        Notification stepNotification = builder.build();
+
+        notificationManager.notify(110,stepNotification);
+        // 参数一:唯一的通知标识;参数二:通知消息。
+        startForeground(110, stepNotification);// 开始前台服务
+
+        return START_STICKY;
+    }
+
+    /**
+     * 自定义handler
+     */
+    private class MessengerHandler extends Handler {
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case Constant.MSG_FROM_CLIENT:
+                    try {
+                        //这里负责将当前的步数发送出去,可以在界面或者其他地方获取,我这里是在MainActivity中获取来更新界面
+                        Messenger messenger = msg.replyTo;
+                        Message replyMsg = Message.obtain(null, Constant.MSG_FROM_SERVER);
+                        Bundle bundle = new Bundle();
+                        bundle.putInt("steps", CURRENT_STEP);
+                        replyMsg.setData(bundle);
+                        messenger.send(replyMsg);
+                    } catch (RemoteException e) {
+                        e.printStackTrace();
+                    }
+                    break;
+                default:
+                    super.handleMessage(msg);
+            }
+        }
+    }
+
+
+    /**
+     * 初始化广播
+     */
+    private void initBroadcastReceiver() {
+        final IntentFilter filter = new IntentFilter();
+        // 屏幕灭屏广播
+        filter.addAction(Intent.ACTION_SCREEN_OFF);
+        //关机广播
+        filter.addAction(Intent.ACTION_SHUTDOWN);
+        // 屏幕解锁广播
+        filter.addAction(Intent.ACTION_USER_PRESENT);
+        // 当长按电源键弹出“关机”对话或者锁屏时系统会发出这个广播
+        // example:有时候会用到系统对话框,权限可能很高,会覆盖在锁屏界面或者“关机”对话框之上,
+        // 所以监听这个广播,当收到时就隐藏自己的对话,如点击pad右下角部分弹出的对话框
+        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
+        //监听日期变化
+        filter.addAction(Intent.ACTION_DATE_CHANGED);
+        filter.addAction(Intent.ACTION_TIME_CHANGED);
+        filter.addAction(Intent.ACTION_TIME_TICK);
+
+        mInfoReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                String action = intent.getAction();
+                switch (action) {
+                    // 屏幕灭屏广播
+                    case Intent.ACTION_SCREEN_OFF:
+                        //屏幕熄灭改为10秒一存储
+                        saveDuration = 10000;
+                        break;
+                    //关机广播,保存好当前数据
+                    case Intent.ACTION_SHUTDOWN:
+                        saveStepData();
+                        break;
+                    // 屏幕解锁广播
+                    case Intent.ACTION_USER_PRESENT:
+                        saveDuration = 3000;
+                        break;
+                    // 当长按电源键弹出“关机”对话或者锁屏时系统会发出这个广播
+                    // example:有时候会用到系统对话框,权限可能很高,会覆盖在锁屏界面或者“关机”对话框之上,
+                    // 所以监听这个广播,当收到时就隐藏自己的对话,如点击pad右下角部分弹出的对话框
+                    case Intent.ACTION_CLOSE_SYSTEM_DIALOGS:
+                        saveStepData();
+                        break;
+                    //监听日期变化
+                    case Intent.ACTION_DATE_CHANGED:
+                    case Intent.ACTION_TIME_CHANGED:
+                    case Intent.ACTION_TIME_TICK:
+                        saveStepData();
+                        isNewDay();
+                        break;
+                    default:
+                        break;
+                }
+            }
+        };
+        //注册广播
+        registerReceiver(mInfoReceiver, filter);
+    }
+
+    /**
+     * 初始化当天数据
+     */
+    private void initTodayData() {
+        //获取当前时间
+        CURRENT_DATE = TimeUtil.getCurrentDate();
+        //获取数据库
+        stepDataDao = new StepDataDao(getApplicationContext());
+        //获取当天的数据,用于展示
+        StepEntity entity = stepDataDao.getCurDataByDate(CURRENT_DATE);
+        //为空则说明还没有该天的数据,有则说明已经开始当天的计步了
+        if (entity == null) {
+            CURRENT_STEP = 0;
+        } else {
+            CURRENT_STEP = Integer.parseInt(entity.getSteps());
+        }
+    }
+
+
+    /**
+     * 监听晚上0点变化初始化数据
+     */
+    private void isNewDay() {
+        String time = "00:00";
+        if (time.equals(new SimpleDateFormat("HH:mm").format(new Date())) ||
+                !CURRENT_DATE.equals(TimeUtil.getCurrentDate())) {
+            initTodayData();
+        }
+    }
+
+
+    /**
+     * 获取传感器实例
+     */
+    private void getStepDetector() {
+        if (sensorManager != null) {
+            sensorManager = null;
+        }
+        // 获取传感器管理器的实例
+        sensorManager = (SensorManager) this
+                .getSystemService(SENSOR_SERVICE);
+        //android4.4以后可以使用计步传感器
+        int VERSION_CODES = Build.VERSION.SDK_INT;
+        if (VERSION_CODES >= 19) {
+            addCountStepListener();
+        }
+    }
+
+
+    /**
+     * 添加传感器监听
+     */
+    private void addCountStepListener() {
+        Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
+        Sensor detectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
+        if (countSensor != null) {
+            stepSensor = 0;
+            sensorManager.registerListener(StepService.this, countSensor, SensorManager.SENSOR_DELAY_NORMAL);
+        } else if (detectorSensor != null) {
+            stepSensor = 1;
+            sensorManager.registerListener(StepService.this, detectorSensor, SensorManager.SENSOR_DELAY_NORMAL);
+        }
+    }
+
+
+    /**
+     * 由传感器记录当前用户运动步数,注意:该传感器只在4.4及以后才有,并且该传感器记录的数据是从设备开机以后不断累加,
+     * 只有当用户关机以后,该数据才会清空,所以需要做数据保护
+     *
+     * @param event
+     */
+    @Override
+    public void onSensorChanged(SensorEvent event) {
+        if (stepSensor == 0) {
+            int tempStep = (int) event.values[0];
+            if (!hasRecord) {
+                hasRecord = true;
+                hasStepCount = tempStep;
+            } else {
+                int thisStepCount = tempStep - hasStepCount;
+                CURRENT_STEP += (thisStepCount - previousStepCount);
+                previousStepCount = thisStepCount;
+            }
+        } else if (stepSensor == 1) {
+            if (event.values[0] == 1.0) {
+                CURRENT_STEP++;
+            }
+        }
+    }
+
+    @Override
+    public void onAccuracyChanged(Sensor sensor, int accuracy) {
+
+    }
+
+
+    /**
+     * 开始倒计时,去存储步数到数据库中
+     */
+    private void startTimeCount() {
+        timeCount = new TimeCount(saveDuration, 1000);
+        timeCount.start();
+    }
+
+
+    private class TimeCount extends CountDownTimer {
+        /**
+         * @param millisInFuture    The number of millis in the future from the call
+         *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
+         *                          is called.
+         * @param countDownInterval The interval along the way to receive
+         *                          {@link #onTick(long)} callbacks.
+         */
+        public TimeCount(long millisInFuture, long countDownInterval) {
+            super(millisInFuture, countDownInterval);
+        }
+
+        @Override
+        public void onTick(long millisUntilFinished) {
+
+        }
+
+        @Override
+        public void onFinish() {
+            // 如果计时器正常结束,则每隔三秒存储步数到数据库
+            timeCount.cancel();
+            saveStepData();
+            startTimeCount();
+        }
+    }
+
+
+    /**
+     * 保存当天的数据到数据库中,并去刷新通知栏
+     */
+    private void saveStepData() {
+        //查询数据库中的数据
+        StepEntity entity = stepDataDao.getCurDataByDate(CURRENT_DATE);
+        //为空则说明还没有该天的数据,有则说明已经开始当天的计步了
+        if (entity == null) {
+            //没有则新建一条数据
+            entity = new StepEntity();
+            entity.setCurDate(CURRENT_DATE);
+            entity.setSteps(String.valueOf(CURRENT_STEP));
+
+            stepDataDao.addNewData(entity);
+        } else {
+            //有则更新当前的数据
+            entity.setSteps(String.valueOf(CURRENT_STEP));
+
+            stepDataDao.updateCurData(entity);
+        }
+
+        builder.setContentIntent(PendingIntent.getActivity(this, 0, nfIntent, 0)) // 设置PendingIntent
+                .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.uuu)) // 设置下拉列表中的图标(大图标)
+                .setContentTitle("今日步数"+CURRENT_STEP+"步") // 设置下拉列表里的标题
+                .setSmallIcon(R.drawable.uuu) // 设置状态栏内的小图标
+                .setContentText("加油,要记得勤加运动"); // 设置上下文内容 
+
+        // 获取构建好的Notification
+        Notification stepNotification = builder.build();
+        //调用更新
+        notificationManager.notify(110,stepNotification);
+    }
+
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        //主界面中需要手动调用stop方法service才会结束
+        stopForeground(true);
+        unregisterReceiver(mInfoReceiver);
+    }
+
+    @Override
+    public boolean onUnbind(Intent intent) {
+        return super.onUnbind(intent);
+    }
+}

+ 48 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/utils/StepCountCheckUtil.java

@@ -0,0 +1,48 @@
+package com.xzjmyk.pm.newpedo.utils;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.os.Build;
+
+/**
+ * Created by FANGLH
+ * Date : 2017/4/13
+ * To do :检测手机是否支持计步工具类
+ */
+
+public class StepCountCheckUtil {
+
+    private Context context;
+    //是否有传感器
+    private boolean hasSensor;
+
+    public StepCountCheckUtil(Context context) {
+        this.context = context;
+        hasSensor = isSupportStepCountSensor();
+    }
+
+    @TargetApi(Build.VERSION_CODES.KITKAT)
+    public boolean isSupportStepCountSensor() {
+        return context.getPackageManager()
+                .hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER);
+    }
+
+    /**
+     * 判断该设备是否支持计歩
+     *
+     * @param context
+     * @return
+     */
+    @TargetApi(Build.VERSION_CODES.KITKAT)
+    public static boolean isSupportStepCountSensor(Context context) {
+        // 获取传感器管理器的实例
+        SensorManager sensorManager = (SensorManager) context
+                .getSystemService(context.SENSOR_SERVICE);
+        Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
+        Sensor detectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
+        return countSensor != null || detectorSensor != null;
+    }
+}

+ 166 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/utils/TimeUtil.java

@@ -0,0 +1,166 @@
+package com.xzjmyk.pm.newpedo.utils;
+
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 时间工具类
+ */
+
+public class TimeUtil {
+    private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日");
+    private static Calendar mCalendar = Calendar.getInstance();
+    private static String[] weekStrings = new String[]{"日","一", "二", "三", "四", "五", "六"};
+    private static String[] rWeekStrings = new String[]{"周日","周一", "周二", "周三", "周四", "周五", "周六"};
+
+
+    /**
+     * 改变日期格式
+     * @param date  2017年02月09日
+     * @return 2017-02-09
+     */
+    public static String changeFormatDate(String date){
+        SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd");
+        String curDate = null;
+        try {
+            Date dt = dateFormat.parse(date);
+            curDate = dFormat.format(dt);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return curDate;
+    }
+
+    /**
+     * 返回当前的时间
+     * @return  今天 09:48
+     */
+    public static String getCurTime(){
+        SimpleDateFormat dFormat = new SimpleDateFormat("HH:mm");
+        String time = "今天 "+dFormat.format(System.currentTimeMillis());
+        return time;
+    }
+
+    /**
+     * 获取运动记录是周几,今天则返回具体时间,其他则返回具体周几
+     * @param dateStr
+     * @return
+     */
+    public static String getWeekStr(String dateStr){
+
+        String todayStr = dateFormat.format(mCalendar.getTime());
+
+        if(todayStr.equals(dateStr)){
+            return getCurTime();
+        }
+
+        Calendar preCalendar = Calendar.getInstance();
+        preCalendar.add(Calendar.DATE, -1);
+        String yesterdayStr = dateFormat.format(preCalendar.getTime());
+        if(yesterdayStr.equals(dateStr)){
+            return "昨天";
+        }
+
+        int w = 0;
+        try {
+            Date date = dateFormat.parse(dateStr);
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(date);
+            w = calendar.get(Calendar.DAY_OF_WEEK) - 1;
+            if (w < 0){
+                w = 0;
+            }
+
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return rWeekStrings[w];
+    }
+
+
+    /**
+     * 获取是几号
+     *
+     * @return dd
+     */
+    public static int getCurrentDay() {
+        return mCalendar.get(Calendar.DATE);
+    }
+
+    /**
+     * 获取当前的日期
+     *
+     * @return yyyy年MM月dd日
+     */
+    public static String getCurrentDate() {
+        String currentDateStr = dateFormat.format(mCalendar.getTime());
+        return currentDateStr;
+    }
+
+
+    /**
+     * 根据date列表获取day列表
+     *
+     * @param dateList
+     * @return
+     */
+    public static List<Integer> dateListToDayList(List<String> dateList) {
+        Calendar calendar = Calendar.getInstance();
+        List<Integer> dayList = new ArrayList<>();
+        for (String date : dateList) {
+            try {
+                calendar.setTime(dateFormat.parse(date));
+                int day = calendar.get(Calendar.DATE);
+                dayList.add(day);
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+        }
+        return dayList;
+    }
+
+
+    /**
+     * 根据当前日期获取以含当天的前一周日期
+     * @return [2017年02月21日, 2017年02月22日, 2017年02月23日, 2017年02月24日, 2017年02月25日, 2017年02月26日, 2017年02月27日]
+     */
+    public static List<String> getBeforeDateListByNow(){
+        List<String> weekList = new ArrayList<>();
+
+        for (int i = -6; i <= 0; i++) {
+            //以周日为一周的第一天
+            Calendar calendar = Calendar.getInstance();
+            calendar.add(Calendar.DATE, i);
+            String date = dateFormat.format(calendar.getTime());
+            weekList.add(date);
+        }
+        return weekList;
+    }
+
+    /**
+     * 判断当前日期是周几
+     * @param curDate
+     * @return
+     */
+    public static String getCurWeekDay(String curDate){
+        int w = 0;
+        try {
+            Date date = dateFormat.parse(curDate);
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(date);
+            w = calendar.get(Calendar.DAY_OF_WEEK) - 1;
+            if (w < 0){
+                w = 0;
+            }
+
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return weekStrings[w];
+    }
+}

+ 285 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/view/NewStepActivity.java

@@ -0,0 +1,285 @@
+package com.xzjmyk.pm.newpedo.view;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.graphics.Paint;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.Display;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.baidu.android.pushservice.PushManager;
+import com.xzjmyk.pm.activity.MyApplication;
+import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.activity.ui.base.BaseActivity;
+import com.xzjmyk.pm.activity.util.PreferenceUtils;
+import com.xzjmyk.pm.newpedo.bean.StepEntity;
+import com.xzjmyk.pm.newpedo.calendar.BeforeOrAfterCalendarView;
+import com.xzjmyk.pm.newpedo.constant.Constant;
+import com.xzjmyk.pm.newpedo.db.StepDataDao;
+import com.xzjmyk.pm.newpedo.service.StepService;
+import com.xzjmyk.pm.newpedo.utils.StepCountCheckUtil;
+import com.xzjmyk.pm.newpedo.utils.TimeUtil;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class NewStepActivity extends BaseActivity implements Handler.Callback {
+    private LinearLayout movementCalenderLl;
+    private TextView kmTimeTv;
+    private TextView totalKmTv;
+    private TextView stepsTimeTv;
+    private TextView totalStepsTv;
+    private TextView supportTv;
+    public static String UU_STEP_NOTICE = "UUSTEPNOTICE";
+    /**
+     * 屏幕长度和宽度
+     */
+    public static int screenWidth, screenHeight;
+
+    private BeforeOrAfterCalendarView calenderView;
+
+    private String curSelDate;
+    private DecimalFormat df = new DecimalFormat("#.##");
+    private List<StepEntity> stepEntityList = new ArrayList<>();
+    private StepDataDao stepDataDao;
+    private LinearLayout steps_history_ll;
+    private TextView steps_history_tv;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_newstep);
+
+        initView();
+        initData();
+        initListener();
+    }
+
+
+    private void initView() {
+        movementCalenderLl = (LinearLayout) findViewById(R.id.movement_records_calender_ll);
+        kmTimeTv = (TextView) findViewById(R.id.movement_total_km_time_tv);
+        totalKmTv = (TextView) findViewById(R.id.movement_total_km_tv);
+        stepsTimeTv = (TextView) findViewById(R.id.movement_total_steps_time_tv);
+        totalStepsTv = (TextView) findViewById(R.id.movement_total_steps_tv);
+        supportTv = (TextView) findViewById(R.id.is_support_tv);
+        steps_history_ll = (LinearLayout) findViewById(R.id.steps_history_ll);
+        steps_history_tv = (TextView) findViewById(R.id.steps_history_tv);
+        steps_history_tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
+        curSelDate = TimeUtil.getCurrentDate();
+
+    }
+
+    private void initData() {
+        WindowManager windowManager = getWindowManager();
+        Display display = windowManager.getDefaultDisplay();
+        screenWidth = display.getWidth();
+        screenHeight = display.getHeight();
+
+        //放到获取宽度之后
+        calenderView = new BeforeOrAfterCalendarView(this);
+        movementCalenderLl.addView(calenderView);
+        /**
+         * 这里判断当前设备是否支持计步
+         */
+        if (StepCountCheckUtil.isSupportStepCountSensor(this)) {
+            getRecordList();
+            supportTv.setVisibility(View.GONE);
+            setDatas();
+            setupService();
+
+            PreferenceUtils.putInt(NewStepActivity.UU_STEP_NOTICE, 0);
+            PushManager.resumeWork(MyApplication.getInstance());
+
+            ToastMessage("小提示:UU在关闭后无法继续统计您的步数数据");
+        } else {
+            totalStepsTv.setText("0");
+            supportTv.setVisibility(View.VISIBLE);
+        }
+    }
+
+
+    private void initListener() {
+        calenderView.setOnBoaCalenderClickListener(new BeforeOrAfterCalendarView.BoaCalenderClickListener() {
+            @Override
+            public void onClickToRefresh(int position, String curDate) {
+                //获取当前选中的时间
+                curSelDate = curDate;
+                //根据日期去取数据
+                setDatas();
+            }
+        });
+
+        steps_history_ll.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+//                Log.i("stepEntity",stepEntity+"");
+                startActivity(new Intent(getApplicationContext(),NewStepListActivity.class));
+            }
+        });
+    }
+
+
+    private boolean isBind = false;
+    private Messenger mGetReplyMessenger = new Messenger(new Handler(this));
+    private Messenger messenger;
+
+    /**
+     * 开启计步服务
+     */
+    private void setupService() {
+        Intent intent = new Intent(this, StepService.class);
+        isBind = bindService(intent, conn, Context.BIND_AUTO_CREATE);
+        startService(intent);
+        Log.i("StepService","StepService开启了");
+    }
+
+    /**
+     * 定时任务
+     */
+    private TimerTask timerTask;
+    private Timer timer;
+    /**
+     * 用于查询应用服务(application Service)的状态的一种interface,
+     * 更详细的信息可以参考Service 和 context.bindService()中的描述,
+     * 和许多来自系统的回调方式一样,ServiceConnection的方法都是进程的主线程中调用的。
+     */
+    private ServiceConnection conn = new ServiceConnection() {
+        /**
+         * 在建立起于Service的连接时会调用该方法,目前Android是通过IBind机制实现与服务的连接。
+         * @param name 实际所连接到的Service组件名称
+         * @param service 服务的通信信道的IBind,可以通过Service访问对应服务
+         */
+        @Override
+        public void onServiceConnected(ComponentName name, final IBinder service) {
+            /**
+             * 设置定时器,每个三秒钟去更新一次运动步数
+             */
+            timerTask = new TimerTask() {
+                @Override
+                public void run() {
+                    try {
+                        messenger = new Messenger(service);
+                        Message msg = Message.obtain(null, Constant.MSG_FROM_CLIENT);
+                        msg.replyTo = mGetReplyMessenger;
+                        messenger.send(msg);
+                    } catch (RemoteException e) {
+                        e.printStackTrace();
+                    }
+                }
+            };
+            timer = new Timer();
+            timer.schedule(timerTask, 0, 3000);
+        }
+
+        /**
+         * 当与Service之间的连接丢失的时候会调用该方法,
+         * 这种情况经常发生在Service所在的进程崩溃或者被Kill的时候调用,
+         * 此方法不会移除与Service的连接,当服务重新启动的时候仍然会调用 onServiceConnected()。
+         * @param name 丢失连接的组件名称
+         */
+        @Override
+        public void onServiceDisconnected(ComponentName name) {
+
+        }
+    };
+
+
+    /**
+     * 设置记录数据
+     *
+     */
+    private void setDatas() {
+        StepEntity stepEntity = stepDataDao.getCurDataByDate(curSelDate);
+
+        if (stepEntity != null) {
+            int steps = Integer.parseInt(stepEntity.getSteps());
+
+            //获取全局的步数
+            totalStepsTv.setText(String.valueOf(steps));
+            //计算总公里数
+            totalKmTv.setText(countTotalKM(steps));
+        } else {
+            //获取全局的步数
+            totalStepsTv.setText("0");
+            //计算总公里数
+            totalKmTv.setText("0");
+        }
+
+        //设置时间
+        String time = TimeUtil.getWeekStr(curSelDate);
+        kmTimeTv.setText(time);
+        stepsTimeTv.setText(time);
+    }
+
+    /**
+     * 简易计算公里数,假设一步大约有0.7米
+     *
+     * @param steps 用户当前步数
+     * @return
+     */
+    private String countTotalKM(int steps) {
+        double totalMeters = steps * 0.7;
+        //保留两位有效数字
+        return df.format(totalMeters / 1000);
+    }
+
+
+    /**
+     * 获取全部运动历史纪录
+     */
+    private void getRecordList() {
+        //获取数据库
+        stepDataDao = new StepDataDao(this);
+        stepEntityList.clear();
+        stepEntityList.addAll(stepDataDao.getAllDatas());
+        // TODO: 在这里获取历史记录条数,当条数达到7条或以上时,显示更多历史记录
+        if (stepEntityList.size() >= 7) {
+            steps_history_ll.setVisibility(View.VISIBLE);
+        }else {
+            steps_history_ll.setVisibility(View.GONE);
+        }
+        Log.i("stepEntityList", stepEntityList +"");
+    }
+
+    @Override
+    public boolean handleMessage(Message msg) {
+        switch (msg.what) {
+            //这里用来获取到Service发来的数据
+            case Constant.MSG_FROM_SERVER:
+
+                //如果是今天则更新数据
+                if (curSelDate.equals(TimeUtil.getCurrentDate())) {
+                    //记录运动步数
+                    int steps = msg.getData().getInt("steps");
+                    //设置的步数
+                    totalStepsTv.setText(String.valueOf(steps));
+                    //计算总公里数
+                    totalKmTv.setText(countTotalKM(steps));
+                }
+                break;
+        }
+        return false;
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        //记得解绑Service,不然多次绑定Service会异常
+        if (isBind) this.unbindService(conn);
+    }
+}

+ 96 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/view/NewStepListActivity.java

@@ -0,0 +1,96 @@
+package com.xzjmyk.pm.newpedo.view;
+
+import android.graphics.Paint;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.activity.ui.base.BaseActivity;
+import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
+import com.xzjmyk.pm.activity.view.MyListView;
+import com.xzjmyk.pm.newpedo.bean.StepEntity;
+import com.xzjmyk.pm.newpedo.db.StepDataDao;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by FANGlh on 2017/4/13.
+ * function:
+ */
+public class NewStepListActivity extends BaseActivity {
+    private UuStepNumAdapter muuStepNumAdapter;
+    private StepDataDao stepDataDao;
+    private List<StepEntity> stepEntityList;
+    private MyListView step_num_lv;
+    private TextView steps_history_tv;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.newstep_data);
+        initView();
+        initData();
+    }
+    private void initView() {
+        muuStepNumAdapter = new UuStepNumAdapter();
+        stepEntityList = new ArrayList<>();
+        step_num_lv = (MyListView) findViewById(R.id.step_num_lv);
+        steps_history_tv = (TextView) findViewById(R.id.steps_history_tv);
+        steps_history_tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
+    }
+    private void initData() {
+        //获取数据库
+        stepDataDao = new StepDataDao(this);
+        stepEntityList.clear();
+        stepEntityList.addAll(stepDataDao.getAllDatas());
+        Log.i("stepEntityList", stepEntityList + "");
+
+        if (!ListUtils.isEmpty(stepEntityList)){
+            muuStepNumAdapter.setStepEntityList(stepEntityList);
+            step_num_lv.setAdapter(muuStepNumAdapter);
+        }
+    }
+    public class UuStepNumAdapter extends BaseAdapter {
+        private List<StepEntity> stepEntityList;
+        public List<StepEntity> getStepEntityList() {return stepEntityList;}
+        public void setStepEntityList(List<StepEntity> stepEntityList) {this.stepEntityList = stepEntityList;}
+        @Override
+        public int getCount() {
+            return stepEntityList == null ? 0 : stepEntityList.size();
+        }
+        @Override
+        public Object getItem(int position) {
+            return stepEntityList.get(position);
+        }
+        @Override
+        public long getItemId(int position) {
+            return position;
+        }
+        @Override
+        public View getView(int position, View convertView, ViewGroup parent) {
+            ViewHolder viewHolder = null;
+            if (convertView == null){
+                viewHolder = new ViewHolder();
+                convertView =  View.inflate(mContext, R.layout.item_uustep_nums,null);
+                viewHolder.docmainmsg_list = (TextView) convertView.findViewById(R.id.item_comdoc_am_list_tv);
+                viewHolder.docmainmsg_value = (TextView) convertView.findViewById(R.id.item_comdoc_am_value_tv);
+                convertView.setTag(viewHolder);
+
+            }else {
+                viewHolder = (ViewHolder) convertView.getTag();
+            }
+            viewHolder.docmainmsg_list.setText(stepEntityList.get(getCount() - position - 1).getCurDate());
+            viewHolder.docmainmsg_value.setText(stepEntityList.get(getCount() - position - 1).getSteps());
+            return convertView;
+        }
+        class ViewHolder{
+            TextView docmainmsg_list;
+            TextView docmainmsg_value;
+        }
+    }
+}

BIN
WeiChat/src/main/res/drawable-xhdpi/ic_blue_round_bg.png


BIN
WeiChat/src/main/res/drawable-xhdpi/ic_small_blue_rectangular.png


+ 205 - 0
WeiChat/src/main/res/layout/activity_newstep.xml

@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/activity_main"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".view.NewStepActivity">
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:id="@+id/movement_records_calender_ll"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+    </LinearLayout>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1dp"
+        android:background="@color/light_blue"/>
+
+    <LinearLayout
+        android:layout_marginLeft="20dp"
+        android:layout_marginRight="20dp"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textSize="15sp"
+            android:layout_marginTop="15dp"
+            android:layout_marginBottom="15dp"
+            android:textColor="@color/main_text_color"
+            android:text="运动记录"/>
+
+        <RelativeLayout
+            android:background="@drawable/ic_small_blue_rectangular"
+            android:layout_width="match_parent"
+            android:layout_height="100dp">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textColor="@color/white"
+                android:textSize="18sp"
+                android:layout_margin="10dp"
+                android:text="步行+跑步距离(估算)"/>
+
+            <LinearLayout
+                android:layout_margin="10dp"
+                android:layout_alignParentRight="true"
+                android:layout_alignParentBottom="true"
+                android:orientation="vertical"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content">
+
+                <LinearLayout
+                    android:layout_gravity="end"
+                    android:orientation="horizontal"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content">
+
+                    <TextView
+                        android:id="@+id/movement_total_km_tv"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:textSize="30sp"
+                        android:layout_marginLeft="10dp"
+                        android:layout_marginRight="10dp"
+                        android:textColor="@color/white" />
+
+                    <TextView
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:textSize="16sp"
+                        android:textColor="@color/white"
+                        android:text="公里"/>
+
+                </LinearLayout>
+
+                <LinearLayout
+                    android:layout_gravity="end"
+                    android:orientation="horizontal"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content">
+
+                    <TextView
+                        android:id="@+id/movement_total_km_time_tv"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_gravity="end"
+                        android:textSize="12sp"
+                        android:textColor="@color/white"
+                        android:layout_marginLeft="10dp"
+                        android:layout_marginRight="10dp" />
+
+
+                </LinearLayout>
+            </LinearLayout>
+        </RelativeLayout>
+
+        <RelativeLayout
+            android:layout_marginTop="10dp"
+            android:background="@drawable/ic_small_blue_rectangular"
+            android:layout_width="match_parent"
+            android:layout_height="100dp">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textColor="@color/white"
+                android:textSize="18sp"
+                android:layout_margin="10dp"
+                android:text="今日步数"/>
+
+            <LinearLayout
+                android:layout_margin="10dp"
+                android:layout_alignParentRight="true"
+                android:layout_alignParentBottom="true"
+                android:orientation="vertical"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content">
+
+                <LinearLayout
+                    android:layout_gravity="end"
+                    android:orientation="horizontal"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content">
+
+                    <TextView
+                        android:id="@+id/movement_total_steps_tv"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:textSize="30sp"
+                        android:layout_marginLeft="5dp"
+                        android:layout_marginRight="5dp"
+                        android:textColor="@color/white"/>
+
+                    <TextView
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:textSize="16sp"
+                        android:textColor="@color/white"
+                        android:text="步"/>
+
+                </LinearLayout>
+
+                <LinearLayout
+                    android:layout_gravity="end"
+                    android:orientation="horizontal"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content">
+
+                    <TextView
+                        android:id="@+id/movement_total_steps_time_tv"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_gravity="end"
+                        android:textSize="12sp"
+                        android:textColor="@color/white"
+                        android:layout_marginLeft="5dp"
+                        android:layout_marginRight="5dp" />
+
+                </LinearLayout>
+            </LinearLayout>
+        </RelativeLayout>
+
+        <TextView
+            android:id="@+id/is_support_tv"
+            android:textSize="15sp"
+            android:layout_marginTop="15dp"
+            android:layout_gravity="center_horizontal"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="该设备不支持计步"
+            android:textColor="@color/red"/>
+
+    </LinearLayout>
+    <LinearLayout
+        android:id="@+id/steps_history_ll"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:layout_marginTop="100dp"
+        android:layout_marginBottom="40dp"
+        >
+        <ImageView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:src="@drawable/uustephistory"/>
+
+        <TextView
+            android:id="@+id/steps_history_tv"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:text="更多历史记录"
+            android:textColor="#288af8"
+            android:textSize="16sp"
+            android:layout_marginLeft="10dp"
+            />
+    </LinearLayout>
+</LinearLayout>

+ 1 - 1
WeiChat/src/main/res/layout/activity_setting.xml

@@ -80,7 +80,7 @@
                 android:id="@+id/new_step_rl"
                 style="@style/IMTbleLine"
                 android:background="@drawable/selector_me_menu_item_bg"
-                android:visibility="visible">
+                android:visibility="gone">
 
                 <TextView
                     android:layout_width="wrap_content"

+ 14 - 0
WeiChat/src/main/res/layout/before_or_after_calendar_layout.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="horizontal"
+    android:layout_width="match_parent"
+    android:layout_height="80dp">
+
+    <LinearLayout
+        android:id="@+id/boa_calender_view_ll"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:orientation="horizontal">
+    </LinearLayout>
+
+</LinearLayout>

+ 44 - 0
WeiChat/src/main/res/layout/newstep_data.xml

@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:background="@drawable/for_dyy"
+    xmlns:android="http://schemas.android.com/apk/res/android">
+    <LinearLayout
+        android:id="@+id/steps_history_ll"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:layout_marginTop="10dp"
+        android:layout_marginBottom="20dp"
+        >
+        <ImageView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:src="@drawable/uustephistory"/>
+
+        <TextView
+            android:id="@+id/steps_history_tv"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:text="更多历史记录"
+            android:textColor="#288af8"
+            android:textSize="16sp"
+            android:layout_marginLeft="10dp"
+            />
+    </LinearLayout>
+    <ScrollView
+        android:layout_marginLeft="35dp"
+        android:layout_marginRight="35dp"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+        <com.xzjmyk.pm.activity.view.MyListView
+            android:id="@+id/step_num_lv"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:background="@drawable/selector_me_menu_item_bg">
+        </com.xzjmyk.pm.activity.view.MyListView>
+    </ScrollView>
+</LinearLayout>

+ 58 - 0
WeiChat/src/main/res/layout/records_calender_item_view.xml

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical" android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <LinearLayout
+        android:gravity="center_horizontal"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <LinearLayout
+            android:id="@+id/records_calender_item_ll"
+            android:paddingTop="15dp"
+            android:gravity="center"
+            android:layout_marginBottom="10dp"
+            android:orientation="vertical"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content">
+
+            <TextView
+                android:id="@+id/records_calender_item_week_tv"
+                android:gravity="center"
+                android:textSize="15sp"
+                android:layout_marginBottom="2dp"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"/>
+
+            <View
+                android:id="@+id/calendar_item_line_view"
+                android:layout_width="match_parent"
+                android:layout_height="1px"
+                android:visibility="gone"
+                android:background="@color/gray_default_dark"/>
+
+            <RelativeLayout
+                android:layout_marginTop="5dp"
+                android:id="@+id/records_calender_item_date_rl"
+                android:layout_gravity="center"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content">
+
+                <TextView
+                    android:id="@+id/records_calender_item_date_tv"
+                    android:padding="3dp"
+                    android:textSize="16sp"
+                    android:gravity="center"
+                    android:layout_centerInParent="true"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"/>
+
+            </RelativeLayout>
+
+        </LinearLayout>
+
+    </LinearLayout>
+
+</LinearLayout>

+ 6 - 0
WeiChat/src/main/res/values/colors.xml

@@ -312,4 +312,10 @@
     <color name="orange_text">#f17e21</color>
     <color name="oa_bg">#EBE9E9</color>
     <color name="oa_item_bg">#f9f9f9</color>
+    <color name="colorPrimary">#3F51B5</color>
+    <color name="colorPrimaryDark">#303F9F</color>
+    <color name="colorAccent">#FF4081</color>
+    <color name="light_blue">#44CDC5</color>
+    <color name="main_text_color">#333333</color>
+    <color name="gray_default_dark">#666666</color>
 </resources>