Browse Source

UU运动初步调试备份

FANGLH 9 years ago
parent
commit
13b76fd182

+ 4 - 0
WeiChat/build.gradle

@@ -129,4 +129,8 @@ dependencies {
     compile project(':library-refreshlayout')
     compile files('src/main/jniLibs/pushservice-5.3.0.99.jar')
     compile 'com.github.TonicArtos:StickyGridHeaders:1.0.1'
+    compile files('libs/lite-orm-1.7.0.jar')
+
+//    compile fileTree(include: ['*.jar'], dir: 'libs')
+    testCompile 'junit:junit:4.12'
 }

BIN
WeiChat/libs/lite-orm-1.7.0.jar


+ 19 - 0
WeiChat/src/main/AndroidManifest.xml

@@ -105,6 +105,8 @@
     <uses-feature android:name="android.hardware.camera" />
     <!-- 使用照相机权限 -->
     <uses-feature android:name="android.hardware.camera.autofocus" />
+    <!--计步器用到-->
+    <uses-feature android:name="android.hardware.sensor.accelerometer" />
 
     <!-- 自动聚焦权限 -->
     <!-- 全局样式不要随意改动  @style/AppTheme -->
@@ -804,6 +806,23 @@
         <activity
             android:name=".ui.erp.activity.oa.MissionActivity"
             android:label="@string/activity_mission_plan" />
+        <activity android:name="basepedo.ui.MyPedometerActivity"
+            android:label="UU运动"/>
+        <service
+            android:name="basepedo.service.StepService"
+            android:process="com.base.basepedo.step"
+            android:priority="1000">
+            <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>

+ 10 - 0
WeiChat/src/main/java/basepedo/config/Constant.java

@@ -0,0 +1,10 @@
+package basepedo.config;
+
+/**
+ * Created by xf on 2016/1/30.
+ */
+public class Constant {
+    public static final int MSG_FROM_CLIENT = 0;
+    public static final int MSG_FROM_SERVER = 1;
+    public static final int REQUEST_SERVER = 2;
+}

+ 46 - 0
WeiChat/src/main/java/basepedo/pojo/StepData.java

@@ -0,0 +1,46 @@
+package basepedo.pojo;
+
+import com.litesuits.orm.db.annotation.Column;
+import com.litesuits.orm.db.annotation.PrimaryKey;
+import com.litesuits.orm.db.annotation.Table;
+import com.litesuits.orm.db.enums.AssignType;
+/**
+ * Created by xf on 2016/1/30.
+ */
+
+@Table("step")
+public class StepData {
+
+    // 指定自增,每个对象需要有一个主键
+    @PrimaryKey(AssignType.AUTO_INCREMENT)
+    private int id;
+
+    @Column("today")
+    private String today;
+    @Column("step")
+    private String step;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getToday() {
+        return today;
+    }
+
+    public void setToday(String today) {
+        this.today = today;
+    }
+
+    public String getStep() {
+        return step;
+    }
+
+    public void setStep(String step) {
+        this.step = step;
+    }
+}

+ 18 - 0
WeiChat/src/main/java/basepedo/service/BootCompleteReceiver.java

@@ -0,0 +1,18 @@
+package basepedo.service;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+/**
+ * 开机完成广播
+ *
+ * Created by xf on 2016/3/1.
+ */
+public class BootCompleteReceiver extends BroadcastReceiver {
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        Intent i = new Intent(context, StepService.class);
+        context.startService(i);
+    }
+}

+ 284 - 0
WeiChat/src/main/java/basepedo/service/StepDcretor.java

@@ -0,0 +1,284 @@
+package basepedo.service;
+
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.util.Log;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+import basepedo.utils.CountDownTimer;
+
+public class StepDcretor implements SensorEventListener {
+    private final String TAG = "StepDcretor";
+    //存放三轴数据
+    final int valueNum = 5;
+    //用于存放计算阈值的波峰波谷差值
+    float[] tempValue = new float[valueNum];
+    int tempCount = 0;
+    //是否上升的标志位
+    boolean isDirectionUp = false;
+    //持续上升次数
+    int continueUpCount = 0;
+    //上一点的持续上升的次数,为了记录波峰的上升次数
+    int continueUpFormerCount = 0;
+    //上一点的状态,上升还是下降
+    boolean lastStatus = false;
+    //波峰值
+    float peakOfWave = 0;
+    //波谷值
+    float valleyOfWave = 0;
+    //此次波峰的时间
+    long timeOfThisPeak = 0;
+    //上次波峰的时间
+    long timeOfLastPeak = 0;
+    //当前的时间
+    long timeOfNow = 0;
+    //当前传感器的值
+    float gravityNew = 0;
+    //上次传感器的值
+    float gravityOld = 0;
+    //动态阈值需要动态的数据,这个值用于这些动态数据的阈值
+    final float initialValue = (float) 1.7;
+    //初始阈值
+    float ThreadValue = (float) 2.0;
+
+    //初始范围
+    float minValue = 11f;
+    float maxValue = 19.6f;
+
+    /**
+     * 0-准备计时   1-计时中   2-正常计步中
+     */
+    private int CountTimeState = 0;
+    public static int CURRENT_SETP = 0;
+    public static int TEMP_STEP = 0;
+    private int lastStep = -1;
+    //用x、y、z轴三个维度算出的平均值
+    public static float average = 0;
+    private Timer timer;
+    // 倒计时3.5秒,3.5秒内不会显示计步,用于屏蔽细微波动
+    private long duration = 3500;
+    private TimeCount time;
+    OnSensorChangeListener onSensorChangeListener;
+
+    public interface OnSensorChangeListener {
+        void onChange();
+    }
+
+    public StepDcretor(Context context) {
+        super();
+    }
+
+    public void onAccuracyChanged(Sensor arg0, int arg1) {
+    }
+
+    public OnSensorChangeListener getOnSensorChangeListener() {
+        return onSensorChangeListener;
+    }
+
+    public void setOnSensorChangeListener(
+            OnSensorChangeListener onSensorChangeListener) {
+        this.onSensorChangeListener = onSensorChangeListener;
+    }
+
+    public void onSensorChanged(SensorEvent event) {
+        Sensor sensor = event.sensor;
+        synchronized (this) {
+            if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
+                calc_step(event);
+            }
+        }
+    }
+
+    synchronized private void calc_step(SensorEvent event) {
+        average = (float) Math.sqrt(Math.pow(event.values[0], 2)
+                + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2));
+        detectorNewStep(average);
+    }
+
+    /*
+     * 检测步子,并开始计步
+	 * 1.传入sersor中的数据
+	 * 2.如果检测到了波峰,并且符合时间差以及阈值的条件,则判定为1步
+	 * 3.符合时间差条件,波峰波谷差值大于initialValue,则将该差值纳入阈值的计算中
+	 * */
+    public void detectorNewStep(float values) {
+        if (gravityOld == 0) {
+            gravityOld = values;
+        } else {
+            if (DetectorPeak(values, gravityOld)) {
+                timeOfLastPeak = timeOfThisPeak;
+                timeOfNow = System.currentTimeMillis();
+
+                if (timeOfNow - timeOfLastPeak >= 200
+                        && (peakOfWave - valleyOfWave >= ThreadValue) && (timeOfNow - timeOfLastPeak) <= 2000) {
+                    timeOfThisPeak = timeOfNow;
+                    //更新界面的处理,不涉及到算法
+                    preStep();
+                }
+                if (timeOfNow - timeOfLastPeak >= 200
+                        && (peakOfWave - valleyOfWave >= initialValue)) {
+                    timeOfThisPeak = timeOfNow;
+                    ThreadValue = Peak_Valley_Thread(peakOfWave - valleyOfWave);
+                }
+            }
+        }
+        gravityOld = values;
+    }
+
+    private void preStep() {
+        if (CountTimeState == 0) {
+            // 开启计时器
+            time = new TimeCount(duration, 700);
+            time.start();
+            CountTimeState = 1;
+            Log.v(TAG, "开启计时器");
+        } else if (CountTimeState == 1) {
+            TEMP_STEP++;
+            Log.v(TAG, "计步中 TEMP_STEP:" + TEMP_STEP);
+        } else if (CountTimeState == 2) {
+            CURRENT_SETP++;
+            if (onSensorChangeListener != null) {
+                onSensorChangeListener.onChange();
+            }
+        }
+    }
+
+    /*
+     * 检测波峰
+     * 以下四个条件判断为波峰:
+     * 1.目前点为下降的趋势:isDirectionUp为false
+     * 2.之前的点为上升的趋势:lastStatus为true
+     * 3.到波峰为止,持续上升大于等于2次
+     * 4.波峰值大于1.2g,小于2g
+     * 记录波谷值
+     * 1.观察波形图,可以发现在出现步子的地方,波谷的下一个就是波峰,有比较明显的特征以及差值
+     * 2.所以要记录每次的波谷值,为了和下次的波峰做对比
+     * */
+    public boolean DetectorPeak(float newValue, float oldValue) {
+        lastStatus = isDirectionUp;
+        if (newValue >= oldValue) {
+            isDirectionUp = true;
+            continueUpCount++;
+        } else {
+            continueUpFormerCount = continueUpCount;
+            continueUpCount = 0;
+            isDirectionUp = false;
+        }
+
+        Log.v(TAG, "oldValue:" + oldValue);
+        if (!isDirectionUp && lastStatus
+                && (continueUpFormerCount >= 2 && (oldValue >= minValue && oldValue < maxValue))) {
+            peakOfWave = oldValue;
+            return true;
+        } else if (!lastStatus && isDirectionUp) {
+            valleyOfWave = oldValue;
+            return false;
+        } else {
+            return false;
+        }
+    }
+
+    /*
+     * 阈值的计算
+     * 1.通过波峰波谷的差值计算阈值
+     * 2.记录4个值,存入tempValue[]数组中
+     * 3.在将数组传入函数averageValue中计算阈值
+     * */
+    public float Peak_Valley_Thread(float value) {
+        float tempThread = ThreadValue;
+        if (tempCount < valueNum) {
+            tempValue[tempCount] = value;
+            tempCount++;
+        } else {
+            tempThread = averageValue(tempValue, valueNum);
+            for (int i = 1; i < valueNum; i++) {
+                tempValue[i - 1] = tempValue[i];
+            }
+            tempValue[valueNum - 1] = value;
+        }
+        return tempThread;
+
+    }
+
+    /*
+     * 梯度化阈值
+     * 1.计算数组的均值
+     * 2.通过均值将阈值梯度化在一个范围里
+     * */
+    public float averageValue(float value[], int n) {
+        float ave = 0;
+        for (int i = 0; i < n; i++) {
+            ave += value[i];
+        }
+        ave = ave / valueNum;
+        if (ave >= 8) {
+            Log.v(TAG, "超过8");
+            ave = (float) 4.3;
+        } else if (ave >= 7 && ave < 8) {
+            Log.v(TAG, "7-8");
+            ave = (float) 3.3;
+        } else if (ave >= 4 && ave < 7) {
+            Log.v(TAG, "4-7");
+            ave = (float) 2.3;
+        } else if (ave >= 3 && ave < 4) {
+            Log.v(TAG, "3-4");
+            ave = (float) 2.0;
+        } else {
+            Log.v(TAG, "else");
+            ave = (float) 1.7;
+        }
+        return ave;
+    }
+
+    class TimeCount extends CountDownTimer {
+        public TimeCount(long millisInFuture, long countDownInterval) {
+            super(millisInFuture, countDownInterval);
+        }
+
+        @Override
+        public void onFinish() {
+            // 如果计时器正常结束,则开始计步
+            time.cancel();
+            CURRENT_SETP += TEMP_STEP;
+            lastStep = -1;
+//            CountTimeState = 2;
+            Log.v(TAG, "计时正常结束");
+
+            timer = new Timer(true);
+            TimerTask task = new TimerTask() {
+                public void run() {
+                    if (lastStep == CURRENT_SETP) {
+                        timer.cancel();
+                        CountTimeState = 0;
+                        lastStep = -1;
+                        TEMP_STEP = 0;
+                        Log.v(TAG, "停止计步:" + CURRENT_SETP);
+                    } else {
+                        lastStep = CURRENT_SETP;
+                    }
+                }
+            };
+            timer.schedule(task, 0, 2000);
+            CountTimeState = 2;
+        }
+
+        @Override
+        public void onTick(long millisUntilFinished) {
+            if (lastStep == TEMP_STEP) {
+                Log.v(TAG, "onTick 计时停止");
+                time.cancel();
+                CountTimeState = 0;
+                lastStep = -1;
+                TEMP_STEP = 0;
+            } else {
+                lastStep = TEMP_STEP;
+            }
+        }
+
+    }
+
+}

+ 361 - 0
WeiChat/src/main/java/basepedo/service/StepService.java

@@ -0,0 +1,361 @@
+package basepedo.service;
+
+import android.annotation.TargetApi;
+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.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.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.PowerManager;
+import android.os.PowerManager.WakeLock;
+import android.os.RemoteException;
+import android.support.v7.app.NotificationCompat;
+import android.util.Log;
+
+import com.xzjmyk.pm.activity.R;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import basepedo.config.Constant;
+import basepedo.pojo.StepData;
+import basepedo.ui.MyPedometerActivity;
+import basepedo.utils.CountDownTimer;
+import basepedo.utils.DbUtils;
+
+@TargetApi(Build.VERSION_CODES.CUPCAKE)
+public class StepService extends Service implements SensorEventListener {
+    private final String TAG = "StepService";
+    //默认为10秒进行一次存储
+    private static int duration = 10000;
+    private static String CURRENTDATE = "";
+    private SensorManager sensorManager;
+    private StepDcretor stepDetector;
+    private NotificationManager nm;
+    private NotificationCompat.Builder builder;
+    private Messenger messenger = new Messenger(new MessenerHandler());
+    private BroadcastReceiver mBatInfoReceiver;
+    private WakeLock mWakeLock;
+    private TimeCount time;
+    //测试
+    private static int i = 0;
+    private String DB_NAME = "basepedo";
+
+    private static class MessenerHandler extends Handler {
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case Constant.MSG_FROM_CLIENT:
+                    try {
+                        Messenger messenger = msg.replyTo;
+                        Message replyMsg = Message.obtain(null, Constant.MSG_FROM_SERVER);
+                        Bundle bundle = new Bundle();
+                        bundle.putInt("step", StepDcretor.CURRENT_SETP);
+                        replyMsg.setData(bundle);
+                        messenger.send(replyMsg);
+                    } catch (RemoteException e) {
+                        e.printStackTrace();
+                    }
+                    break;
+                default:
+                    super.handleMessage(msg);
+            }
+        }
+    }
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        initBroadcastReceiver();
+        new Thread(new Runnable() {
+            public void run() {
+                startStepDetector();
+            }
+        }).start();
+        startTimeCount();
+    }
+
+    @Override
+    public void onStart(Intent intent, int startId) {
+        super.onStart(intent, startId);
+    }
+
+    @Override
+    public int onStartCommand(Intent intent, int flags, int startId) {
+        initTodayData();
+        updateNotification("今日步数:" + StepDcretor.CURRENT_SETP + " 步");
+        return START_STICKY;
+    }
+
+    private String getTodayDate() {
+        Date date = new Date(System.currentTimeMillis());
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.format(date);
+    }
+
+    private void initTodayData() {
+        CURRENTDATE = getTodayDate();
+        DbUtils.createDb(this, DB_NAME);
+        //获取当天的数据,用于展示
+        List<StepData> list = DbUtils.getQueryByWhere(StepData.class, "today", new String[]{CURRENTDATE});
+        if (list.size() == 0 || list.isEmpty()) {
+            StepDcretor.CURRENT_SETP = 0;
+        } else if (list.size() == 1) {
+            StepDcretor.CURRENT_SETP = Integer.parseInt(list.get(0).getStep());
+        } else {
+            Log.v(TAG, "出错了!");
+        }
+    }
+
+    private void initBroadcastReceiver() {
+        final IntentFilter filter = new IntentFilter();
+        // 屏幕灭屏广播
+        filter.addAction(Intent.ACTION_SCREEN_OFF);
+        //日期修改
+        filter.addAction(Intent.ACTION_TIME_CHANGED);
+        //关机广播
+        filter.addAction(Intent.ACTION_SHUTDOWN);
+        // 屏幕亮屏广播
+        filter.addAction(Intent.ACTION_SCREEN_ON);
+        // 屏幕解锁广播
+        filter.addAction(Intent.ACTION_USER_PRESENT);
+        // 当长按电源键弹出“关机”对话或者锁屏时系统会发出这个广播
+        // example:有时候会用到系统对话框,权限可能很高,会覆盖在锁屏界面或者“关机”对话框之上,
+        // 所以监听这个广播,当收到时就隐藏自己的对话,如点击pad右下角部分弹出的对话框
+        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
+
+        mBatInfoReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(final Context context, final Intent intent) {
+                String action = intent.getAction();
+
+                if (Intent.ACTION_SCREEN_ON.equals(action)) {
+                    Log.v(TAG, "screen on");
+                } else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
+                    Log.v(TAG, "screen off");
+                    //改为60秒一存储
+                    duration = 60000;
+                } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
+                    Log.v(TAG, "screen unlock");
+                    save();
+                    //改为10秒一存储
+                    duration = 10000;
+                } else if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
+                    Log.v(TAG, " receive Intent.ACTION_CLOSE_SYSTEM_DIALOGS");
+                    //保存一次
+                    save();
+                } else if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
+                    Log.v(TAG, " receive ACTION_SHUTDOWN");
+                    save();
+                } else if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) {
+                    Log.v(TAG, " receive ACTION_TIME_CHANGED");
+                    initTodayData();
+                    clearStepData();
+                }
+            }
+        };
+        registerReceiver(mBatInfoReceiver, filter);
+    }
+
+    private void clearStepData() {
+        i = 0;
+        StepService.CURRENTDATE = "0";
+    }
+
+    private void startTimeCount() {
+        time = new TimeCount(duration, 1000);
+        time.start();
+    }
+
+    /**
+     * 更新通知
+     */
+    private void updateNotification(String content) {
+        builder = new NotificationCompat.Builder(this);
+        builder.setPriority(Notification.PRIORITY_MIN);
+        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
+                new Intent(this, MyPedometerActivity.class), 0);
+        builder.setContentIntent(contentIntent);
+        builder.setSmallIcon(R.drawable.icon_crm_links);
+        builder.setTicker("UU运动");
+        builder.setContentTitle("UU运动");
+        //设置不可清除
+        builder.setOngoing(true);
+        builder.setContentText(content);
+        Notification notification = builder.build();
+
+        startForeground(0, notification);
+        nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+        nm.notify(R.string.app_name, notification);
+    }
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        return messenger.getBinder();
+    }
+
+    private void startStepDetector() {
+        if (sensorManager != null && stepDetector != null) {
+            sensorManager.unregisterListener(stepDetector);
+            sensorManager = null;
+            stepDetector = null;
+        }
+        sensorManager = (SensorManager) this
+                .getSystemService(SENSOR_SERVICE);
+        getLock(this);
+       // android4.4以后可以使用计步传感器
+        int VERSION_CODES = android.os.Build.VERSION.SDK_INT;
+        if (VERSION_CODES >= 19) {
+            addCountStepListener();
+        } else {
+            addBasePedoListener();
+        }
+
+        addBasePedoListener();
+        addCountStepListener();
+    }
+
+    private void addCountStepListener() {
+        Sensor detectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
+        Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
+        if (detectorSensor != null) {
+            sensorManager.registerListener(StepService.this, detectorSensor, SensorManager.SENSOR_DELAY_UI);
+        } else if (countSensor != null) {
+            sensorManager.registerListener(StepService.this, countSensor, SensorManager.SENSOR_DELAY_UI);
+            //        addBasePedoListener();
+        } else {
+            Log.v(TAG, "Count sensor not available!");
+        }
+    }
+
+    private void addBasePedoListener() {
+        stepDetector = new StepDcretor(this);
+        // 获得传感器的类型,这里获得的类型是加速度传感器
+        // 此方法用来注册,只有注册过才会生效,参数:SensorEventListener的实例,Sensor的实例,更新速率
+        Sensor sensor = sensorManager
+                .getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
+        // sensorManager.unregisterListener(stepDetector);
+        sensorManager.registerListener(stepDetector, sensor,
+                SensorManager.SENSOR_DELAY_UI);
+        stepDetector
+                .setOnSensorChangeListener(new StepDcretor.OnSensorChangeListener() {
+
+                    @Override
+                    public void onChange() {
+                        updateNotification("今日步数:" + StepDcretor.CURRENT_SETP + "," + i + " 步");
+                        //    updateNotification("今日步数:" + StepDcretor.CURRENT_SETP + " 步");
+                    }
+                });
+    }
+
+    @Override
+    public void onSensorChanged(SensorEvent event) {
+        i++;
+        //   StepDcretor.CURRENT_SETP++;
+        updateNotification("今日步数:" + StepDcretor.CURRENT_SETP + "," + i + " 步");
+    }
+
+    @Override
+    public void onAccuracyChanged(Sensor sensor, int accuracy) {
+    }
+
+    class TimeCount extends CountDownTimer {
+        public TimeCount(long millisInFuture, long countDownInterval) {
+            super(millisInFuture, countDownInterval);
+        }
+
+        @Override
+        public void onFinish() {
+            // 如果计时器正常结束,则开始计步
+            time.cancel();
+            save();
+            startTimeCount();
+        }
+
+        @Override
+        public void onTick(long millisUntilFinished) {
+        }
+    }
+
+    private void save() {
+        int tempStep = StepDcretor.CURRENT_SETP;
+        List<StepData> list = DbUtils.getQueryByWhere(StepData.class, "today", new String[]{CURRENTDATE});
+        if (list.size() == 0 || list.isEmpty()) {
+            StepData data = new StepData();
+            data.setToday(CURRENTDATE);
+            data.setStep(tempStep + "");
+            DbUtils.insert(data);
+        } else if (list.size() == 1) {
+            StepData data = list.get(0);
+            data.setStep(tempStep + "");
+            DbUtils.update(data);
+        } else {
+        }
+    }
+
+
+    @Override
+    public void onDestroy() {
+        //取消前台进程
+        stopForeground(true);
+        DbUtils.closeDb();
+        unregisterReceiver(mBatInfoReceiver);
+        Intent intent = new Intent(this, StepService.class);
+        startService(intent);
+        super.onDestroy();
+    }
+
+    @Override
+    public boolean onUnbind(Intent intent) {
+        return super.onUnbind(intent);
+    }
+
+//    private  void unlock(){
+//        setLockPatternEnabled(android.provider.Settings.Secure.LOCK_PATTERN_ENABLED,false);
+//    }
+//
+//    private void setLockPatternEnabled(String systemSettingKey, boolean enabled) {
+//        //推荐使用
+//        android.provider.Settings.Secure.putInt(getContentResolver(), systemSettingKey,enabled ? 1 : 0);
+//    }
+
+    synchronized private PowerManager.WakeLock getLock(Context context) {
+        if (mWakeLock != null) {
+            if (mWakeLock.isHeld())
+                mWakeLock.release();
+            mWakeLock = null;
+        }
+
+        if (mWakeLock == null) {
+            PowerManager mgr = (PowerManager) context
+                    .getSystemService(Context.POWER_SERVICE);
+            mWakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
+                    StepService.class.getName());
+            mWakeLock.setReferenceCounted(true);
+            Calendar c = Calendar.getInstance();
+            c.setTimeInMillis(System.currentTimeMillis());
+            int hour = c.get(Calendar.HOUR_OF_DAY);
+            if (hour >= 23 || hour <= 6) {
+                mWakeLock.acquire(5000);
+            } else {
+                mWakeLock.acquire(300000);
+            }
+        }
+        return (mWakeLock);
+    }
+}

+ 110 - 0
WeiChat/src/main/java/basepedo/ui/MyPedometerActivity.java

@@ -0,0 +1,110 @@
+package basepedo.ui;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+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.widget.TextView;
+
+import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.activity.ui.base.BaseActivity;
+
+import basepedo.config.Constant;
+import basepedo.service.StepService;
+
+
+public class MyPedometerActivity extends BaseActivity implements Handler.Callback {
+    //循环取当前时刻的步数中间的间隔时间
+    private long TIME_INTERVAL = 500;
+    private TextView text_step;
+    private Messenger messenger;
+    private Messenger mGetReplyMessenger = new Messenger(new Handler(this));
+    private Handler delayHandler;
+
+    ServiceConnection conn = new ServiceConnection() {
+        @Override
+        public void onServiceConnected(ComponentName name, IBinder service) {
+            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();
+            }
+        }
+
+        @Override
+        public void onServiceDisconnected(ComponentName name) {
+
+        }
+    };
+
+    @Override
+    public boolean handleMessage(Message msg) {
+        switch (msg.what) {
+            case Constant.MSG_FROM_SERVER:
+                // 更新界面上的步数
+                text_step.setText(msg.getData().getInt("step") + "");
+                delayHandler.sendEmptyMessageDelayed(Constant.REQUEST_SERVER, TIME_INTERVAL);
+                break;
+            case Constant.REQUEST_SERVER:
+                try {
+                    Message msg1 = Message.obtain(null, Constant.MSG_FROM_CLIENT);
+                    msg1.replyTo = mGetReplyMessenger;
+                    messenger.send(msg1);
+                } catch (RemoteException e) {
+                    e.printStackTrace();
+                }
+
+                break;
+        }
+        return false;
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_pedometer);
+        init();
+    }
+    private void init() {
+        text_step = (TextView) findViewById(R.id.text_step);
+        delayHandler = new Handler(this);
+    }
+
+    @Override
+    protected void onStart() {
+        super.onStart();
+        setupService();
+    }
+
+    private void setupService() {
+        Intent intent = new Intent(this, StepService.class);
+        bindService(intent, conn, Context.BIND_AUTO_CREATE);
+        startService(intent);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+    }
+
+    @Override
+    public void onBackPressed() {
+        moveTaskToBack(true);
+        super.onBackPressed();
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        unbindService(conn);
+    }
+}

+ 107 - 0
WeiChat/src/main/java/basepedo/utils/CountDownTimer.java

@@ -0,0 +1,107 @@
+package basepedo.utils;
+
+import android.os.Handler;
+import android.os.Message;
+import android.os.SystemClock;
+
+public abstract class CountDownTimer {
+	  
+    /**
+     * Millis since epoch when alarm should stop.
+     */
+    private final long mMillisInFuture;
+ 
+    /**
+     * The interval in millis that the user receives callbacks
+     */
+    private final long mCountdownInterval;
+ 
+    private long mStopTimeInFuture;
+ 
+    private boolean mCancelled = false;
+ 
+    /**
+     * @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 CountDownTimer(long millisInFuture, long countDownInterval) {
+        mMillisInFuture = millisInFuture;
+        mCountdownInterval = countDownInterval;
+    }
+ 
+    /**
+     * Cancel the countdown.
+     *
+     * Do not call it from inside CountDownTimer threads
+     */
+    public final void cancel() {
+        mHandler.removeMessages(MSG);
+        mCancelled = true;
+    }
+ 
+    /**
+     * Start the countdown.
+     */
+    public synchronized final CountDownTimer start() {
+        if (mMillisInFuture <= 0) {
+            onFinish();
+            return this;
+        }
+        mStopTimeInFuture = SystemClock.elapsedRealtime() + mMillisInFuture;
+        mHandler.sendMessage(mHandler.obtainMessage(MSG));
+        mCancelled = false;
+        return this;
+    }
+ 
+ 
+    /**
+     * Callback fired on regular interval.
+     * @param millisUntilFinished The amount of time until finished.
+     */
+    public abstract void onTick(long millisUntilFinished);
+ 
+    /**
+     * Callback fired when the time is up.
+     */
+    public abstract void onFinish();
+ 
+ 
+    private static final int MSG = 1;
+ 
+ 
+    // handles counting down
+    private Handler mHandler = new Handler() {
+ 
+        @Override
+        public void handleMessage(Message msg) {
+ 
+            synchronized (CountDownTimer.this) {
+                final long millisLeft = mStopTimeInFuture - SystemClock.elapsedRealtime();
+ 
+                if (millisLeft <= 0) {
+                    onFinish();
+                } else if (millisLeft < mCountdownInterval) {
+                    // no tick, just delay until done
+                    sendMessageDelayed(obtainMessage(MSG), millisLeft);
+                } else {
+                    long lastTickStart = SystemClock.elapsedRealtime();
+                    onTick(millisLeft);
+ 
+                    // take into account user's onTick taking time to execute
+                    long delay = lastTickStart + mCountdownInterval - SystemClock.elapsedRealtime();
+ 
+                    // special case: user's onTick took more than interval to
+                    // complete, skip to next interval
+                    while (delay < 0) delay += mCountdownInterval;
+ 
+                    if (!mCancelled) {
+                        sendMessageDelayed(obtainMessage(MSG), delay);
+                    }
+                }
+            }
+        }
+    };
+}

+ 122 - 0
WeiChat/src/main/java/basepedo/utils/DbUtils.java

@@ -0,0 +1,122 @@
+package basepedo.utils;
+
+import android.content.Context;
+
+import com.litesuits.orm.LiteOrm;
+import com.litesuits.orm.db.assit.QueryBuilder;
+import com.litesuits.orm.db.model.ConflictAlgorithm;
+
+import java.util.List;
+
+/**
+ * Created by xf on 2016/1/31.
+ */
+public class DbUtils {
+
+    public static String DB_NAME;
+    public static LiteOrm liteOrm;
+
+    public static void createDb(Context _activity, String DB_NAME) {
+        DB_NAME = DB_NAME + ".db";
+        if (liteOrm == null) {
+            liteOrm = LiteOrm.newCascadeInstance(_activity, DB_NAME);
+            liteOrm.setDebugged(true);
+        }
+    }
+
+    public static LiteOrm getLiteOrm() {
+        return liteOrm;
+    }
+
+    /**
+     * 插入一条记录
+     *
+     * @param t
+     */
+    public static <T> void insert(T t) {
+        liteOrm.save(t);
+    }
+
+    /**
+     * 插入所有记录
+     *
+     * @param list
+     */
+    public static <T> void insertAll(List<T> list) {
+        liteOrm.save(list);
+    }
+
+    /**
+     * 查询所有
+     *
+     * @param cla
+     * @return
+     */
+    public static <T> List<T> getQueryAll(Class<T> cla) {
+        return liteOrm.query(cla);
+    }
+
+    /**
+     * 查询  某字段 等于 Value的值
+     *
+     * @param cla
+     * @param field
+     * @param value
+     * @return
+     */
+    public static <T> List<T> getQueryByWhere(Class<T> cla, String field, String[] value) {
+        return liteOrm.<T>query(new QueryBuilder(cla).where(field + "=?", value));
+    }
+
+    /**
+     * 查询  某字段 等于 Value的值  可以指定从1-20,就是分页
+     *
+     * @param cla
+     * @param field
+     * @param value
+     * @param start
+     * @param length
+     * @return
+     */
+    public static <T> List<T> getQueryByWhereLength(Class<T> cla, String field, String[] value, int start, int length) {
+        return liteOrm.<T>query(new QueryBuilder(cla).where(field + "=?", value).limit(start, length));
+    }
+
+    /**
+     * 删除所有 某字段等于 Vlaue的值
+     * @param cla
+     * @param field
+     * @param value
+     */
+//        public static <T> void deleteWhere(Class<T> cla,String field,String [] value){
+//            liteOrm.delete(cla, WhereBuilder.create().where(field + "=?", value));
+//        }
+
+    /**
+     * 删除所有
+     *
+     * @param cla
+     */
+    public static <T> void deleteAll(Class<T> cla) {
+        liteOrm.deleteAll(cla);
+    }
+
+    /**
+     * 仅在以存在时更新
+     *
+     * @param t
+     */
+    public static <T> void update(T t) {
+        liteOrm.update(t, ConflictAlgorithm.Replace);
+    }
+
+
+    public static <T> void updateALL(List<T> list) {
+        liteOrm.update(list);
+    }
+
+    public static void closeDb(){
+        liteOrm.close();
+    }
+
+}

+ 1 - 1
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/fragment/WorksFragment.java

@@ -105,7 +105,7 @@ public class WorksFragment extends XutilsFragment implements View.OnClickListene
                 }
                 break;
             case R.id.my_data_rl:
-                ToastUtil.showToast(getActivity(), "抱歉,该功能尚未完善");
+//                ToastUtil.showToast(getActivity(), "抱歉,该功能尚未完善");
                 break;
             case R.id.goods_find:
                 ViewUtil.webLinks(ct, "http://mall.ubtob.com", "商品查询");

+ 10 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/me/MeFragment.java

@@ -56,6 +56,8 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import basepedo.ui.MyPedometerActivity;
+
 import static com.xzjmyk.pm.activity.R.id.my_friend_rl;
 
 
@@ -277,6 +279,14 @@ public class MeFragment extends EasyFragment implements View.OnClickListener {
             }
         });
 
+        //UU计步调试
+        findViewById(R.id.uu_sport_step).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                startActivity(new Intent(ct, MyPedometerActivity.class));
+            }
+        });
+
     }
 
     @Override

+ 25 - 0
WeiChat/src/main/res/layout/activity_pedometer.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin">
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="计步功能:暂时只测试了放在裤子口袋里计步。
+屏蔽功能:连续运动一定时间才开始计步,屏蔽细微移动或者驾车时震动所带来的干扰。
+停止运动超过5秒,便重新开启屏蔽功能。提示:10秒做一次数据存储"
+        />
+    <TextView
+        android:id="@+id/text_step"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textColor="#000000"
+        android:layout_centerInParent="true"
+        android:textSize="30sp" />
+
+</RelativeLayout>

+ 27 - 0
WeiChat/src/main/res/layout/fragment_me.xml

@@ -515,6 +515,33 @@
                 android:background="@drawable/oa_next"
                 android:contentDescription="@string/app_name" />
         </RelativeLayout>
+
+        <RelativeLayout
+            android:id="@+id/uu_sport_step"
+            style="@style/IMTbleLine_UP_Me"
+            android:layout_marginTop="7dp"
+            android:background="@drawable/selector_me_menu_item_bg"
+            >
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_centerVertical="true"
+                android:drawableLeft="@drawable/icon_uu_setting"
+                android:drawablePadding="10dp"
+                android:gravity="center"
+                android:text="UU运动"
+                android:textColor="@color/text_main"
+                android:textSize="@dimen/text_main" />
+
+            <ImageView
+                android:layout_width="@dimen/next_width"
+                android:layout_height="@dimen/next_height"
+                android:layout_alignParentRight="true"
+                android:layout_centerVertical="true"
+                android:layout_marginRight="8dp"
+                android:background="@drawable/oa_next"
+                android:contentDescription="@string/app_name" />
+        </RelativeLayout>
     </LinearLayout>
 
 </ScrollView>