Example usage for android.hardware Sensor TYPE_ACCELEROMETER

List of usage examples for android.hardware Sensor TYPE_ACCELEROMETER

Introduction

In this page you can find the example usage for android.hardware Sensor TYPE_ACCELEROMETER.

Prototype

int TYPE_ACCELEROMETER

To view the source code for android.hardware Sensor TYPE_ACCELEROMETER.

Click Source Link

Document

A constant describing an accelerometer sensor type.

Usage

From source file:com.nit.vicky.Reviewer.java

private void initLayout(Integer layout) {
    setContentView(layout);/*  ww w.j a  v a  2s .c  o m*/

    mMainLayout = findViewById(R.id.main_layout);
    Themes.setContentStyle(mMainLayout, Themes.CALLER_REVIEWER);

    mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame);
    setInAnimation(false);

    findViewById(R.id.top_bar).setOnClickListener(mCardStatisticsListener);

    mCardFrame = (FrameLayout) findViewById(R.id.flashcard);
    mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer);
    mTouchLayer.setOnTouchListener(mGestureListener);
    if (mPrefTextSelection && mLongClickWorkaround) {
        mTouchLayer.setOnLongClickListener(mLongClickListener);
    }
    if (mPrefTextSelection) {
        mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    }
    mCardFrame.removeAllViews();
    if (!mChangeBorderStyle) {
        ((View) findViewById(R.id.flashcard_border)).setVisibility(View.VISIBLE);
    }
    // hunt for input issue 720, like android issue 3341
    if (AnkiDroidApp.SDK_VERSION <= 7 && (mCard != null)) {
        mCard.setFocusableInTouchMode(true);
    }

    // Initialize swipe
    gestureDetector = new GestureDetector(new MyGestureDetector());

    mProgressBar = (ProgressBar) findViewById(R.id.flashcard_progressbar);

    // initialise shake detection
    if (mShakeEnabled) {
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
        mAccel = 0.00f;
        mAccelCurrent = SensorManager.GRAVITY_EARTH;
        mAccelLast = SensorManager.GRAVITY_EARTH;
    }

    Resources res = getResources();

    mEase1 = (Button) findViewById(R.id.ease1);
    mEase1.setTextColor(res.getColor(R.color.next_time_failed_color));
    mEase1Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease1);
    mEase1Layout.setOnClickListener(mSelectEaseHandler);

    mEase2 = (Button) findViewById(R.id.ease2);
    mEase2.setTextColor(res.getColor(R.color.next_time_usual_color));
    mEase2Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease2);
    mEase2Layout.setOnClickListener(mSelectEaseHandler);

    mEase3 = (Button) findViewById(R.id.ease3);
    mEase3Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease3);
    mEase3Layout.setOnClickListener(mSelectEaseHandler);

    mEase4 = (Button) findViewById(R.id.ease4);
    mEase4Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease4);
    mEase4Layout.setOnClickListener(mSelectEaseHandler);

    mNext1 = (TextView) findViewById(R.id.nextTime1);
    mNext2 = (TextView) findViewById(R.id.nextTime2);
    mNext3 = (TextView) findViewById(R.id.nextTime3);
    mNext4 = (TextView) findViewById(R.id.nextTime4);

    mNext1.setTextColor(res.getColor(R.color.next_time_failed_color));
    mNext2.setTextColor(res.getColor(R.color.next_time_usual_color));

    if (!mShowNextReviewTime) {
        ((TextView) findViewById(R.id.nextTimeflip)).setVisibility(View.GONE);
        mNext1.setVisibility(View.GONE);
        mNext2.setVisibility(View.GONE);
        mNext3.setVisibility(View.GONE);
        mNext4.setVisibility(View.GONE);
    }

    mFlipCard = (Button) findViewById(R.id.flip_card);
    mFlipCardLayout = (LinearLayout) findViewById(R.id.flashcard_layout_flip);
    mFlipCardLayout.setOnClickListener(mFlipCardListener);

    mTextBarRed = (TextView) findViewById(R.id.red_number);
    mTextBarBlack = (TextView) findViewById(R.id.black_number);
    mTextBarBlue = (TextView) findViewById(R.id.blue_number);

    if (!mShowRemainingCardCount) {
        mTextBarRed.setVisibility(View.GONE);
        mTextBarBlack.setVisibility(View.GONE);
        mTextBarBlue.setVisibility(View.GONE);
    }

    if (mShowProgressBars) {
        mSessionProgressTotalBar = (View) findViewById(R.id.daily_bar);
        mSessionProgressBar = (View) findViewById(R.id.session_progress);
        mProgressBars = (LinearLayout) findViewById(R.id.progress_bars);
    }

    mCardTimer = (Chronometer) findViewById(R.id.card_time);
    if (mShowProgressBars && mProgressBars.getVisibility() != View.VISIBLE) {
        switchVisibility(mProgressBars, View.VISIBLE);
    }

    mChosenAnswer = (TextView) findViewById(R.id.choosen_answer);

    if (mPrefWhiteboard) {
        mWhiteboard = new Whiteboard(this, mInvertedColors, mBlackWhiteboard);
        FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT);
        mWhiteboard.setLayoutParams(lp2);
        FrameLayout fl = (FrameLayout) findViewById(R.id.whiteboard);
        fl.addView(mWhiteboard);

        mWhiteboard.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (mShowWhiteboard) {
                    return false;
                }
                if (gestureDetector.onTouchEvent(event)) {
                    return true;
                }
                return false;
            }
        });
    }
    mAnswerField = (EditText) findViewById(R.id.answer_field);

    mNextTimeTextColor = getResources().getColor(R.color.next_time_usual_color);
    mNextTimeTextRecomColor = getResources().getColor(R.color.next_time_recommended_color);
    mForegroundColor = getResources().getColor(R.color.next_time_usual_color);
    if (mInvertedColors) {
        invertColors(true);
    }

    mLookUpIcon = findViewById(R.id.lookup_button);
    mLookUpIcon.setVisibility(View.GONE);
    mLookUpIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (clipboardHasText()) {
                lookUp();
            }
        }

    });
    initControls();
}

From source file:com.hichinaschool.flashcards.anki.Reviewer.java

private void initLayout(Integer layout) {
    setContentView(layout);/*  w  ww . j  a v a 2s .com*/

    mMainLayout = findViewById(R.id.main_layout);
    Themes.setContentStyle(mMainLayout, Themes.CALLER_REVIEWER);

    mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame);
    setInAnimation(false);

    findViewById(R.id.top_bar).setOnClickListener(mCardStatisticsListener);

    mCardFrame = (FrameLayout) findViewById(R.id.flashcard);
    mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer);
    mTouchLayer.setOnTouchListener(mGestureListener);
    if (mPrefTextSelection && mLongClickWorkaround) {
        mTouchLayer.setOnLongClickListener(mLongClickListener);
    }
    if (mPrefTextSelection) {
        mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    }
    mCardFrame.removeAllViews();
    if (!mChangeBorderStyle) {
        ((View) findViewById(R.id.flashcard_border)).setVisibility(View.VISIBLE);
    }
    // hunt for input issue 720, like android issue 3341
    if (AnkiDroidApp.SDK_VERSION <= 7 && (mCard != null)) {
        mCard.setFocusableInTouchMode(true);
    }

    // Initialize swipe
    gestureDetector = new GestureDetector(new MyGestureDetector());

    mProgressBar = (ProgressBar) findViewById(R.id.flashcard_progressbar);

    // initialise shake detection
    if (mShakeEnabled) {
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
        mAccel = 0.00f;
        mAccelCurrent = SensorManager.GRAVITY_EARTH;
        mAccelLast = SensorManager.GRAVITY_EARTH;
    }

    Resources res = getResources();

    mEase1 = (Button) findViewById(R.id.ease1);
    mEase1.setTextColor(res.getColor(R.color.next_time_failed_color));
    mEase1Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease1);
    mEase1Layout.setOnClickListener(mSelectEaseHandler);

    mEase2 = (Button) findViewById(R.id.ease2);
    mEase2.setTextColor(res.getColor(R.color.next_time_usual_color));
    mEase2Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease2);
    mEase2Layout.setOnClickListener(mSelectEaseHandler);

    mEase3 = (Button) findViewById(R.id.ease3);
    mEase3Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease3);
    mEase3Layout.setOnClickListener(mSelectEaseHandler);

    mEase4 = (Button) findViewById(R.id.ease4);
    mEase4Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease4);
    mEase4Layout.setOnClickListener(mSelectEaseHandler);

    mNext1 = (TextView) findViewById(R.id.nextTime1);
    mNext2 = (TextView) findViewById(R.id.nextTime2);
    mNext3 = (TextView) findViewById(R.id.nextTime3);
    mNext4 = (TextView) findViewById(R.id.nextTime4);

    mNext1.setTextColor(res.getColor(R.color.next_time_failed_color));
    mNext2.setTextColor(res.getColor(R.color.next_time_usual_color));

    if (!mShowNextReviewTime) {
        ((TextView) findViewById(R.id.nextTimeflip)).setVisibility(View.GONE);
        mNext1.setVisibility(View.GONE);
        mNext2.setVisibility(View.GONE);
        mNext3.setVisibility(View.GONE);
        mNext4.setVisibility(View.GONE);
    }

    mFlipCard = (Button) findViewById(R.id.flip_card);
    mFlipCardLayout = (LinearLayout) findViewById(R.id.flashcard_layout_flip);
    mFlipCardLayout.setOnClickListener(mFlipCardListener);

    mTextBarRed = (TextView) findViewById(R.id.red_number);
    mTextBarBlack = (TextView) findViewById(R.id.black_number);
    mTextBarBlue = (TextView) findViewById(R.id.blue_number);

    if (!mShowRemainingCardCount) {
        mTextBarRed.setVisibility(View.GONE);
        mTextBarBlack.setVisibility(View.GONE);
        mTextBarBlue.setVisibility(View.GONE);
    }

    if (mShowProgressBars) {
        mSessionProgressTotalBar = (View) findViewById(R.id.daily_bar);
        mSessionProgressBar = (View) findViewById(R.id.session_progress);
        mProgressBars = (LinearLayout) findViewById(R.id.progress_bars);
    }

    mCardTimer = (Chronometer) findViewById(R.id.card_time);
    if (mShowProgressBars && mProgressBars.getVisibility() != View.VISIBLE) {
        //            switchVisibility(mProgressBars, View.VISIBLE);
    }

    mChosenAnswer = (TextView) findViewById(R.id.choosen_answer);

    if (mPrefWhiteboard) {
        mWhiteboard = new Whiteboard(this, mInvertedColors, mBlackWhiteboard);
        FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT);
        mWhiteboard.setLayoutParams(lp2);
        FrameLayout fl = (FrameLayout) findViewById(R.id.whiteboard);
        fl.addView(mWhiteboard);

        mWhiteboard.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (mShowWhiteboard) {
                    return false;
                }
                if (gestureDetector.onTouchEvent(event)) {
                    return true;
                }
                return false;
            }
        });
    }
    mAnswerField = (EditText) findViewById(R.id.answer_field);

    mNextTimeTextColor = getResources().getColor(R.color.next_time_usual_color);
    mNextTimeTextRecomColor = getResources().getColor(R.color.next_time_recommended_color);
    mForegroundColor = getResources().getColor(R.color.next_time_usual_color);
    if (mInvertedColors) {
        invertColors(true);
    }

    mLookUpIcon = findViewById(R.id.lookup_button);
    mLookUpIcon.setVisibility(View.GONE);
    mLookUpIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (clipboardHasText()) {
                lookUp();
            }
        }

    });
    initControls();
}

From source file:com.example.sensingapp.SensingApp.java

private void UpdateSensorServiceRegistration() {
    //Register sensors according to the enable/disable status
    //       if (m_blnAcclEnabled) {
    //          m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION), m_nAcclMode);
    //          m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), m_nAcclMode);
    //       } else {
    //          m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION));
    //          m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
    //       }//from  www  . j a  va 2  s . c  om

    if (m_blnAcclEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                m_nAcclMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
    }

    if (m_blnLinearAcclEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
                m_nLinearAcclMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome,
                m_smSurScan.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION));
    }

    if (m_blnGravityEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GRAVITY),
                m_nGravityMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GRAVITY));
    }

    if (m_blnGyroEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GYROSCOPE),
                m_nGyroMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_GYROSCOPE));
    }

    if (m_blnMagnetEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                m_nMagnetMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD));
    }

    // Changed on 20150910
    //       if (m_blnOrientEnabled) {
    //         if (!m_blnAcclEnabled) { 
    //            m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), m_nOrientMode);
    //         }
    //         
    //         if (!m_blnMagnetEnabled) {
    //            m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), m_nOrientMode);
    //         }              
    //       } else {
    //          if (!m_blnAcclEnabled) {
    //             m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
    //          }
    //          
    //          if (!m_blnMagnetEnabled) {
    //             m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD));
    //          }
    //       }

    if (m_blnOrientEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR),
                m_nOrientMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR));
    }

    if (m_blnLightEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LIGHT), m_nLightMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_LIGHT));
    }

    if (m_blnBarometerEnabled) {
        m_smSurScan.registerListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_PRESSURE),
                m_nBarometerMode);
    } else {
        m_smSurScan.unregisterListener(m_actHome, m_smSurScan.getDefaultSensor(Sensor.TYPE_PRESSURE));
    }

}

From source file:com.thomasokken.free42.Free42Activity.java

public int shell_get_acceleration(DoubleHolder x, DoubleHolder y, DoubleHolder z) {
    if (!accel_inited) {
        accel_inited = true;//  ww  w . j av  a2  s.  c o m
        SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        Sensor s = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        if (s == null)
            return 0;
        boolean success = sm.registerListener(new SensorEventListener() {
            public void onAccuracyChanged(Sensor sensor, int accuracy) {
                // Don't care
            }

            public void onSensorChanged(SensorEvent event) {
                // Transform the measurements to conform to the iPhone
                // conventions. The conversion factor used here is the
                // 'standard gravity'.
                accel_x = event.values[0] / -9.80665;
                accel_y = event.values[1] / -9.80665;
                accel_z = event.values[2] / -9.80665;
            }
        }, s, SensorManager.SENSOR_DELAY_NORMAL);
        if (!success)
            return 0;
        accel_exists = true;
    }

    if (accel_exists) {
        x.value = accel_x;
        y.value = accel_y;
        z.value = accel_z;
        return 1;
    } else {
        return 0;
    }
}

From source file:com.example.sensingapp.SensingApp.java

private void checkSensorAvailability() {
    //List<Sensor> lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_ORIENTATION);
    List<Sensor> lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_ROTATION_VECTOR); //Changed on 20150910
    if (lstSensor.size() > 0) {
        m_blnOrientPresent = true;// ww  w .  j av a2  s  .  c  om
    } else {
        m_blnOrientPresent = false;
        m_blnOrientEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_GYROSCOPE);
    if (lstSensor.size() > 0) {
        m_blnGyroPresent = true;
    } else {
        m_blnGyroPresent = false;
        m_blnGyroEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_ACCELEROMETER);
    if (lstSensor.size() > 0) {
        m_blnAcclPresent = true;
    } else {
        m_blnAcclPresent = false;
        m_blnAcclEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_LINEAR_ACCELERATION);
    if (lstSensor.size() > 0) {
        m_blnLinearAcclPresent = true;
    } else {
        m_blnLinearAcclPresent = false;
        m_blnLinearAcclEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_GRAVITY);
    if (lstSensor.size() > 0) {
        m_blnGravityPresent = true;
    } else {
        m_blnGravityPresent = false;
        m_blnGravityEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
    if (lstSensor.size() > 0) {
        m_blnMagnetPresent = true;
    } else {
        m_blnMagnetPresent = false;
        m_blnMagnetEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_LIGHT);
    if (lstSensor.size() > 0) {
        m_blnLightPresent = true;
    } else {
        m_blnLightPresent = false;
        m_blnLightEnabled = false;
    }

    lstSensor = m_smSurScan.getSensorList(Sensor.TYPE_PRESSURE);
    if (lstSensor.size() > 0) {
        m_blnBarometerPresent = true;
    } else {
        m_blnBarometerPresent = false;
        m_blnBarometerEnabled = false;
    }

}

From source file:com.example.sensingapp.SensingApp.java

public void recordSensingInfo(SensorData senData) {
    String sRecordLine;/*from  w ww . j av a2s  .  c  om*/
    String sTimeField;
    Date dtCurDate;
    int i;
    long lStartTime = 0;
    long lCurrentTime = 0;
    SimpleDateFormat spdRecordTime, spdCurDateTime;
    final String DATE_FORMAT = "yyyyMMddHHmmss";
    final String DATE_FORMAT_S = "yyMMddHHmmssSSS"; //"yyyyMMddHHmmssSSS"
    int nSensorReadingType = SENSOR_EVENT_NULL;
    int nSensorDataType;

    if (m_blnRecordStatus == false) { //Stopped
        return;
    }

    dtCurDate = new Date();

    // Timestamp for the record
    spdRecordTime = new SimpleDateFormat(DATE_FORMAT_S);
    sTimeField = spdRecordTime.format(dtCurDate);

    nSensorDataType = senData.getSensorDataType();

    if (nSensorDataType == DATA_TYPE_SENSOR) {
        SensorEvent event;

        event = senData.getSensorEvent();

        synchronized (this) {
            switch (event.sensor.getType()) {

            case Sensor.TYPE_ACCELEROMETER:
                //X, Y, Z
                if (m_blnAcclEnabled) {
                    m_sAccl = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + ","
                            + Float.toString(event.values[2]) + ",";

                    nSensorReadingType = SENSOR_EVENT_ACCL;
                }

                //                   if (m_blnOrientEnabled) {
                //                      m_arrfAcclValues = event.values.clone();
                //                      
                //                      if (calculateOrientation()) {
                //                         //Azimuth (rotation around z-axis); Pitch (rotation around x-axis), Roll (rotation around y-axis)
                //                         m_sOrient = Float.toString(m_arrfOrientValues[0]) + "," + 
                //                                  Float.toString(m_arrfOrientValues[1]) + "," + 
                //                                  Float.toString(m_arrfOrientValues[2]) + ",";
                //                         
                //                         nSensorReadingType = SENSOR_EVENT_ORIENT;
                //                         
                //                      }
                //                   }
                break;

            case Sensor.TYPE_LINEAR_ACCELERATION:
                //X,Y,Z
                if (m_blnLinearAcclEnabled) {
                    m_sLinearAccl = Float.toString(event.values[0]) + "," + Float.toString(event.values[1])
                            + "," + Float.toString(event.values[2]) + ",";

                    nSensorReadingType = SENSOR_EVENT_LINEAR_ACCL;
                }

                break;

            case Sensor.TYPE_GRAVITY:
                //X,Y,Z
                if (m_blnGravityEnabled) {
                    m_sGravity = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + ","
                            + Float.toString(event.values[2]) + ",";

                    nSensorReadingType = SENSOR_EVENT_GRAVITY;
                }

                break;

            case Sensor.TYPE_GYROSCOPE:
                //X,Y,Z
                m_sGyro = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + ","
                        + Float.toString(event.values[2]) + ",";
                nSensorReadingType = SENSOR_EVENT_GYRO;
                break;

            case Sensor.TYPE_MAGNETIC_FIELD:
                // Values are in micro-Tesla (uT) and measure the ambient magnetic field 
                if (m_blnMagnetEnabled) {
                    m_sMagnet = Float.toString(event.values[0]) + "," + Float.toString(event.values[1]) + ","
                            + Float.toString(event.values[2]) + ",";

                    nSensorReadingType = SENSOR_EVENT_MAGNET;
                }

                //                   if (m_blnOrientEnabled) {
                //                      m_arrfMagnetValues = event.values.clone();
                //                      
                //                      if (calculateOrientation()) {
                //                         //Azimuth (rotation around z-axis); Pitch (rotation around x-axis), Roll (rotation around y-axis)
                //                         m_sOrient = Float.toString(m_arrfOrientValues[0]) + "," + 
                //                                  Float.toString(m_arrfOrientValues[1]) + "," + 
                //                                  Float.toString(m_arrfOrientValues[2]) + ",";
                //                                                  
                //                         if (nSensorReadingType != SENSOR_EVENT_MAGNET) {
                //                            nSensorReadingType = SENSOR_EVENT_ORIENT;
                //                         }
                //                      }
                //                   }

                break;

            case Sensor.TYPE_ROTATION_VECTOR: //Added on 20150910
                if (m_blnOrientEnabled) {
                    float[] arrfRotVal = new float[3];
                    float[] arrfR = new float[9];
                    float[] arrfValues = new float[3];

                    try {
                        System.arraycopy(event.values, 0, arrfRotVal, 0, event.values.length);
                    } catch (IllegalArgumentException e) {
                        //Hardcode the size to handle a bug on Samsung devices
                        System.arraycopy(event.values, 0, arrfRotVal, 0, 3);
                    }

                    SensorManager.getRotationMatrixFromVector(arrfR, arrfRotVal);
                    SensorManager.getOrientation(arrfR, arrfValues);

                    m_arrfOrientValues[0] = (float) Math.toDegrees(arrfValues[0]);
                    m_arrfOrientValues[1] = (float) Math.toDegrees(arrfValues[1]);
                    m_arrfOrientValues[2] = (float) Math.toDegrees(arrfValues[2]);

                    if (m_arrfOrientValues[0] < 0) {
                        m_arrfOrientValues[0] = m_arrfOrientValues[0] + 360; // Make Azimuth 0 ~ 360
                    }

                    //                      //Azimuth (rotation around z-axis); Pitch (rotation around x-axis), Roll (rotation around y-axis)
                    m_sOrient = Float.toString(m_arrfOrientValues[0]) + ","
                            + Float.toString(m_arrfOrientValues[1]) + ","
                            + Float.toString(m_arrfOrientValues[2]) + ",";

                    //m_tvGpsUp.setText(m_sOrient); //Show orientation
                    nSensorReadingType = SENSOR_EVENT_ORIENT;
                }

                break;

            case Sensor.TYPE_LIGHT:
                // Ambient light level in SI lux units 
                m_sLight = Float.toString(event.values[0]) + ",";
                nSensorReadingType = SENSOR_EVENT_LIGHT;
                break;

            case Sensor.TYPE_PRESSURE:
                // Atmospheric pressure in hPa (millibar)
                m_sBarometer = Float.toString(event.values[0]) + ",";
                nSensorReadingType = SENSOR_EVENT_BAROMETER;
                break;

            }
        }
    } else if (nSensorDataType == DATA_TYPE_GPS) {
        Location locationGps;
        locationGps = senData.getGpsLocation();

        if (locationGps != null) {

            m_location = new Location(locationGps);

            //Change from double to float
            m_sGPS = Float.valueOf((float) (locationGps.getLatitude())).toString() + ","
                    + Float.valueOf((float) (locationGps.getLongitude())).toString() + ",";
            if (locationGps.hasAltitude()) {
                m_sGPS = m_sGPS + Float.valueOf((float) (locationGps.getAltitude())).toString() + ",";
                GeomagneticField geoField = new GeomagneticField(
                        Double.valueOf(locationGps.getLatitude()).floatValue(),
                        Double.valueOf(locationGps.getLongitude()).floatValue(),
                        Double.valueOf(locationGps.getAltitude()).floatValue(), System.currentTimeMillis());
                // Append Declination, in Degree
                m_sGPS = m_sGPS + Float.valueOf((float) (geoField.getDeclination())).toString() + ","
                        + Float.valueOf((float) (geoField.getInclination())).toString() + ",";
            } else {
                m_sGPS = m_sGPS + ",,,";
                //m_sGPS = m_sGPS + ",";
            }

            //New add 201408270009
            if (locationGps.hasSpeed()) {
                m_sGPS = m_sGPS + Float.valueOf((float) (locationGps.getSpeed())).toString() + ",";
            } else {
                m_sGPS = m_sGPS + ",";
            }

            if (locationGps.hasBearing()) {
                m_sGPS = m_sGPS + Float.valueOf((float) (locationGps.getBearing())).toString() + ",";
            } else {
                m_sGPS = m_sGPS + ",";
            }

            nSensorReadingType = SENSOR_EVENT_GPS;

            m_blnGpsUp = true;
            show_screen5_GpsUp();
        } else {
            m_blnGpsUp = false;
            show_screen5_GpsUp();
        }
    } else if (nSensorDataType == DATA_TYPE_MIC) {
        double fSoundLevelDb;
        fSoundLevelDb = senData.getSoundLevelDb();
        m_sSouldLevel = new BigDecimal(fSoundLevelDb).setScale(0, BigDecimal.ROUND_HALF_UP) + ",";

        nSensorReadingType = SENSOR_EVENT_MIC;

    } else if (nSensorDataType == DATA_TYPE_CELLULAR) {
        int nCellId;
        nCellId = senData.getCellId();
        m_sCellId = Integer.valueOf(nCellId).toString() + ",";
        nSensorReadingType = SENSOR_EVENT_CELLULAR;

    } else if (nSensorDataType == DATA_TYPE_WIFI) {
        List<WifiData> lstWifiData = senData.getListWifiData();
        int nWifiCnt = Math.min(WIFI_COUNT, lstWifiData.size());
        m_sWifi = "";
        for (i = 0; i < nWifiCnt; i++) {
            //m_sWifi = m_sWifi + lstWifiData.get(i).getSSID() + "," + lstWifiData.get(i).getBSSID() + "," + lstWifiData.get(i).getSignalLevel() + ",";
            m_sWifi = m_sWifi + lstWifiData.get(i).getBSSID() + "," + lstWifiData.get(i).getSignalLevel() + ",";

        }

        for (i = 1; i <= WIFI_COUNT - nWifiCnt; i++) {
            //m_sWifi = m_sWifi + ",,,";
            m_sWifi = m_sWifi + ",,";
        }

        nSensorReadingType = SENSOR_EVENT_WIFI;
    }

    if (nSensorReadingType == SENSOR_EVENT_NULL) {
        return;
    }

    sRecordLine = sTimeField + ",";

    if (m_blnNoLabel == false) {
        sRecordLine = sRecordLine + m_sCurrentLabel + ",";
    }

    sRecordLine = sRecordLine + Integer.valueOf(nSensorReadingType) + ",";

    //New: Every field always there
    //Field in each line:
    /*
     *  1) Timestamp
     *  2) Label
     *  3) SensingEventType
     *  4-6) Accl
     *  7-9) Linear Accl
     *  10-12) Gravity
     *  13-15) Gyro
     *  16-18) Orientation
     *  19-21) Magnet
     *  22) Light
     *  23) Barometer
     *  24) Sould Level (Decibel)
     *  25) Cell ID
     *  26-32) GPS (Lat, Long, Alt, Declination, Inclination, Speed, Bearing)
     *  33-72) WiFi (<BSSID, Level>) 
     */
    //      sRecordLine = sRecordLine  + m_sAccl + m_sGyro + m_sOrient + m_sMagnet + 
    //                           m_sLight + m_sBarometer +  
    //                           m_sSouldLevel + m_sCellId +
    //                           m_sGPS + m_sWifi;

    sRecordLine = sRecordLine + m_sAccl + m_sLinearAccl + m_sGravity + m_sGyro + m_sOrient + m_sMagnet
            + m_sLight + m_sBarometer + m_sSouldLevel + m_sCellId + m_sGPS + m_sWifi;

    ////////////////////////////
    //      String sAngle = calculateRot(m_sAccl, m_sGravity);
    //      String sarrAngle[] = sAngle.split(",");
    //      String sShow = sarrAngle[0] + "\n" + sarrAngle[1];

    //      String sShow = "";

    //      if (m_sGravity.length() > 3) {
    //         String sarrAngle[] = m_sGravity.split(",");
    //         double fX = Double.valueOf(sarrAngle[0]).doubleValue();
    //         double fY = Double.valueOf(sarrAngle[1]).doubleValue();
    //         double fZ = Double.valueOf(sarrAngle[2]).doubleValue();
    //         
    //         double fTotal = Math.sqrt(fX*fX + fY*fY + fZ*fZ);
    //         
    //         double fAngleZ = Math.acos(fZ/fTotal)/Math.PI*180;
    //         double fAngleY = 90 - Math.acos(fY/fTotal)/Math.PI*180;
    //         double fAngleX = 90 - Math.acos(fX/fTotal)/Math.PI*180;
    //         
    //         sShow = "X:  " +  fAngleX + "\n";
    //         sShow = sShow + "Y:  " +  fAngleY + "\n";
    //         sShow = sShow + "Z:  " +  fAngleZ;
    //         
    //                     
    //      }

    //      if (m_sGravity.length() > 3) {
    //         String sarrAngle[] = m_sGravity.split(",");
    //         double fX = Double.valueOf(sarrAngle[0]).doubleValue();
    //         double fY = Double.valueOf(sarrAngle[1]).doubleValue();
    //         double fZ = Double.valueOf(sarrAngle[2]).doubleValue();
    //         
    //         int nSymbol = 0;
    //         if (fX < 0)  {
    //            sShow = sShow + "- X" + "\n";
    //         } else if (fX > 0) {
    //            sShow = sShow + "+ X" + "\n";
    //         }
    //         
    //         if (fY < 0)  {
    //            sShow = sShow + "- Y" + "\n";
    //         } else if (fY > 0) {
    //            sShow = sShow + "+ Y" + "\n";
    //         }
    //         
    //         if (fZ < 0)  {
    //            sShow = sShow + "- Z";
    //         } else if (fZ > 0) {
    //            sShow = sShow + "+ Z";
    //         }
    //                     
    //      }
    //      
    //      if (m_sGyro.length() > 3) {
    //         String sarrAngle[] = m_sGyro.split(",");
    //         double fX = Double.valueOf(sarrAngle[0]).doubleValue();
    //         double fY = Double.valueOf(sarrAngle[1]).doubleValue();
    //         double fZ = Double.valueOf(sarrAngle[2]).doubleValue();
    //         
    //         int nSymbol = 0;
    //         if (fX < 0)  {
    //            nSymbol = -1;
    //         } else if (fX > 0) {
    //            nSymbol = 1;
    //         }
    //         
    //         if (fY < 0)  {
    //            nSymbol = nSymbol + (-1);
    //         } else if (fY > 0) {
    //            nSymbol = nSymbol + 1;
    //         }
    //         
    //         if (fZ < 0)  {
    //            nSymbol = nSymbol + (-1);
    //         } else if (fZ > 0) {
    //            nSymbol = nSymbol + 1;
    //         }
    //            
    //         if (nSymbol < 0) {
    //            nSymbol = -1;
    //         } else if (nSymbol > 0) {
    //            nSymbol = 1;
    //         }
    //         
    //         sShow = sShow + "\n\n" + nSymbol + "";
    //      }

    //      m_tvSensingInfo.setText(sShow);
    ////////////////////////////

    sRecordLine = sRecordLine + System.getProperty("line.separator");

    if (m_fwSensorRecord != null) {
        //Write information into file
        //Compose information into recordLine
        try {
            m_fwSensorRecord.write(sRecordLine);
        } catch (IOException e) {

        }
    }

}

From source file:com.example.sensingapp.SensingApp.java

public void onAccuracyChanged(Sensor sensor, int accuracy) {
    switch (sensor.getType()) {
    case Sensor.TYPE_ACCELEROMETER:
        m_sSensorAccuracy = "1,"; //Accl
        break;//  ww  w  .j  ava2 s .com

    case Sensor.TYPE_LINEAR_ACCELERATION:
        m_sSensorAccuracy = "2,"; //LinearAccl
        break;

    case Sensor.TYPE_GYROSCOPE:
        m_sSensorAccuracy = "3,"; //Gyro
        break;

    case Sensor.TYPE_MAGNETIC_FIELD:
        m_sSensorAccuracy = "4,"; //Magnet
        break;

    case Sensor.TYPE_GRAVITY:
        m_sSensorAccuracy = "5,"; //Gravity      
        break;

    case Sensor.TYPE_PROXIMITY:
        m_sSensorAccuracy = "6,"; //Proxi
        break;

    case Sensor.TYPE_LIGHT:
        m_sSensorAccuracy = "7,"; //Light
        break;

    case Sensor.TYPE_PRESSURE:
        m_sSensorAccuracy = "8,"; //Barometer
        break;

    case Sensor.TYPE_RELATIVE_HUMIDITY:
        m_sSensorAccuracy = "9,"; //Humidity
        break;

    case Sensor.TYPE_AMBIENT_TEMPERATURE:
        m_sSensorAccuracy = "10,"; //Temperature
        break;

    default:
        m_sSensorAccuracy = "11,"; //Other
    }

    switch (accuracy) {
    case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
        m_sSensorAccuracy = m_sSensorAccuracy + "1,"; //H
        break;

    case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
        m_sSensorAccuracy = m_sSensorAccuracy + "2,"; //M
        break;

    case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
        m_sSensorAccuracy = m_sSensorAccuracy + "3,"; //L
        break;

    case SensorManager.SENSOR_STATUS_UNRELIABLE:
        m_sSensorAccuracy = m_sSensorAccuracy + "4,"; //U
        break;
    }
}