• 大小: 9KB
    文件类型: .java
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: Java
  • 标签: Android  

资源简介

获取加速度传感器 绘制曲线 并存储 能使用简单的代码实现

资源截图

代码片段和文件信息

/*
 * Copyright 2012 Greg Milette and Adam Stroud
 * 
 * Licensed under the Apache License Version 2.0 (the “License“);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *  http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing software
 * distributed under the License is distributed on an “AS IS“ BASIS
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package root.gast.playground.sensor.movement;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

import android.graphics.Color;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.os.SystemClock;
import android.speech.tts.TextToSpeech;
import android.util.Log;

import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.LineAndPointRenderer;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYPlot;

/**
 * Receives accelerometer events and writes them to CSV files and plots them on a graph.
 * 
 * @author Adam Stroud <adam.stroud@gmail.com>
 */
public class AccelerationEventListener implements SensorEventListener
{
    private static final String TAG = “AccelerationEventListener“;
    private static final char CSV_DELIM = ‘‘;
    private static final int THRESHHOLD = 2;
    private static final String CSV_HEADER =
            “X AxisY AxisZ AxisAccelerationTime“;
    private static final float ALPHA = 0.8f;
    private static final int HIGH_PASS_MINIMUM = 10;
    private static final int MAX_SERIES_SIZE = 30;
    private static final int CHART_REFRESH = 125;
    
    private PrintWriter printWriter;
    private long startTime;
    private float[] gravity;
    private int highPassCount;
    private SimpleXYSeries xAxisSeries;
    private SimpleXYSeries yAxisSeries;
    private SimpleXYSeries zAxisSeries;
    private SimpleXYSeries accelerationSeries;
    private XYPlot xyPlot;
    private long lastChartRefresh;
    private boolean useHighPassFilter;
    private TextToSpeech tts;
    private HashMap ttsParams;
    private String movementText;

    public AccelerationEventListener(XYPlot xyPlot
                                     boolean useHighPassFilter
                                     File dataFile
                                     TextToSpeech tts
                                     HashMap ttsParams
                                     String movementText)
    {
        this.xyPlot = xyPlot;
        this.useHighPassFilter = useHighPassFilter;
        this.tts = tts;
        this.ttsParams = ttsParams;
        this.movementTex

评论

共有 条评论