Example usage for android.hardware Sensor TYPE_GYROSCOPE

List of usage examples for android.hardware Sensor TYPE_GYROSCOPE

Introduction

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

Prototype

int TYPE_GYROSCOPE

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

Click Source Link

Document

A constant describing a gyroscope sensor type.

Usage

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.InternalSensorService.java

@Override
public void onSensorChanged(SensorEvent event) {
    if (pref == null)
        pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    int mSensorType = event.sensor.getType();
    if (mSensorType == Sensor.TYPE_ACCELEROMETER) {

        int x = Math.round(event.values[0]);
        int y = Math.round(event.values[1]);
        int z = Math.round(event.values[2]);

        // using ACCELEROMETER_KNEE only as a demonstration,
        // in practice new event can be created
        AccDeviceSensorEvent accEvt = new AccDeviceSensorEvent("eventID", getTimestamp(), "producerID",
                SensorReadingEvent.ACCELEROMETER_ON_DEVICE, getTimestamp(), x, y, z, x, y, z);

        sendToChannel(accEvt, AbstractChannel.RECEIVER); // for external
        // apps/*from  w w  w .j  a va  2  s .co  m*/
        // subscription
        gotAccEvent(getTimestamp(), Sensor.TYPE_ACCELEROMETER, x, y, z); // for
        // on device
        // graphViews
        // using
    }

    else if (mSensorType == Sensor.TYPE_LIGHT) {

        float x = event.values[0];

        // using ambientLightEvent only as a demonstration,
        // in practice new event can be created
        AmbientLightEvent lightEvnt = new AmbientLightEvent("eventID", getTimestamp(), "producerID",
                SensorReadingEvent.AMBIENT_LIGHT, getTimestamp(), "location", "object", x,
                AmbientLightEvent.UNIT_LUX);
        sendToChannel(lightEvnt, AbstractChannel.RECEIVER);
        gotLightEvent(getTimestamp(), Sensor.TYPE_LIGHT, x);

    }

    else if (mSensorType == Sensor.TYPE_PRESSURE) {
        float x = event.values[0];
        AmbientPressureEvent temEvnt = new AmbientPressureEvent("eventID", getTimestamp(), "producerID",
                SensorReadingEvent.AMBIENT_PRESSURE, getTimestamp(), "location", "object", x,
                AmbientPressureEvent.UNIT_HPA);
        sendToChannel(temEvnt, AbstractChannel.RECEIVER);
        gotLightEvent(getTimestamp(), Sensor.TYPE_PRESSURE, x);
    }

    else if (mSensorType == Sensor.TYPE_PROXIMITY) {
        float x = event.values[0];
        ProximityEvent evnt = new ProximityEvent("eventID", getTimestamp(), "producerID",
                SensorReadingEvent.PROXIMITY, getTimestamp(), "location", "object", x, "");
        sendToChannel(evnt, AbstractChannel.RECEIVER);
        gotLightEvent(getTimestamp(), Sensor.TYPE_PROXIMITY, x);
    }

    else if (mSensorType == Sensor.TYPE_AMBIENT_TEMPERATURE) {
        float x = event.values[0];
        TemperatureEvent evnt = new TemperatureEvent("eventID", getTimestamp(), "producerID",
                SensorReadingEvent.ROOM_TEMPERATURE, getTimestamp(), "location", "object", x,
                TemperatureEvent.UNIT_CELSIUS);
        sendToChannel(evnt, AbstractChannel.RECEIVER);
        gotLightEvent(getTimestamp(), Sensor.TYPE_AMBIENT_TEMPERATURE, x);
    }

    else if (mSensorType == Sensor.TYPE_RELATIVE_HUMIDITY) {
        float x = event.values[0];
        HumidityEvent evnt = new HumidityEvent("eventID", getTimestamp(), "producerID",
                SensorReadingEvent.HUMIDITY, getTimestamp(), "location", "object", x);
        sendToChannel(evnt, AbstractChannel.RECEIVER);
        gotLightEvent(getTimestamp(), Sensor.TYPE_RELATIVE_HUMIDITY, x);
    }

    else if (mSensorType == Sensor.TYPE_GYROSCOPE) {

        int x = Math.round(event.values[0]);
        int y = Math.round(event.values[1]);
        int z = Math.round(event.values[2]);

        GyroscopeSensorEvent gSEvnt = new GyroscopeSensorEvent("eventID", getTimestamp(), "producerID",
                SensorReadingEvent.GYROSCOPE, getTimestamp(), x, y, z, x, y, z);
        sendToChannel(gSEvnt, AbstractChannel.RECEIVER);
        gotAccEvent(getTimestamp(), Sensor.TYPE_GYROSCOPE, x, y, z);

    }

    else if (mSensorType == Sensor.TYPE_MAGNETIC_FIELD) {
        int x = Math.round(event.values[0]);
        int y = Math.round(event.values[1]);
        int z = Math.round(event.values[2]);

        MagneticSensorEvent gSEvnt = new MagneticSensorEvent("eventID", getTimestamp(), "producerID",
                SensorReadingEvent.MAGNETIC_FIELD, getTimestamp(), x, y, z, x, y, z);
        sendToChannel(gSEvnt, AbstractChannel.RECEIVER);
        gotAccEvent(getTimestamp(), Sensor.TYPE_MAGNETIC_FIELD, x, y, z);

    }

    else if (mSensorType == Sensor.TYPE_LINEAR_ACCELERATION) {
        int x = Math.round(event.values[0]);
        int y = Math.round(event.values[1]);
        int z = Math.round(event.values[2]);

        // using ACCELEROMETER_KNEE only as a demonstration,
        // in practice new event can be created
        AccDeviceSensorEvent accEvt = new AccDeviceSensorEvent("eventID", getTimestamp(), "producerID",
                SensorReadingEvent.ACCELEROMETER_ON_DEVICE, getTimestamp(), x, y, z, x, y, z);

        sendToChannel(accEvt, AbstractChannel.RECEIVER);
        gotAccEvent(getTimestamp(), Sensor.TYPE_LINEAR_ACCELERATION, x, y, z);
    }

}

From source file:fr.bde_eseo.eseomega.GantierActivity.java

@Override
public void onSensorChanged(SensorEvent event) {
    /*//  w  w  w .  ja va2  s.  c  o m
    Sensor mySensor = event.sensor;
            
    if (mySensor.getType() == Sensor.TYPE_GYROSCOPE) {
    float x = event.values[0];
    float y = event.values[1];
    float z = event.values[2];
            
    if (view != null && view.getThread() != null)
        if (Math.abs(x) > 0.2)
            view.getThread().moveSprite_x(-x);
            
    //mView.setBall_y(screen_y);
    }*/

    switch (event.sensor.getType()) {
    case Sensor.TYPE_ACCELEROMETER:
        // copy new accelerometer data into accel array
        // then calculate new orientation
        System.arraycopy(event.values, 0, accel, 0, 3);
        calculateAccMagOrientation();
        break;

    case Sensor.TYPE_GYROSCOPE:
        // process gyro data
        gyroFunction(event);
        break;

    case Sensor.TYPE_MAGNETIC_FIELD:
        // copy new magnetometer data into magnet array
        System.arraycopy(event.values, 0, magnet, 0, 3);
        break;
    }
}

From source file:kr.ac.kpu.wheeling.blackbox.Camera2VideoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    sensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    return inflater.inflate(kr.ac.kpu.wheeling.R.layout.fragment_camera2_video, container, false);
}

From source file:net.sourceforge.fidocadj.FidoMain.java

/**
 * Activate the sensors (gyroscope) which will then be used for actions such
 * as rotating and mirroring components.
 *//* w  w w.j a  v  a  2 s  .c o m*/
public void activateSensors() {
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
}

From source file:io.authme.sdk.widget.LockPatternView.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LockPatternView(Context context, AttributeSet attrs) {
    super(context, attrs);
    senSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    senAccelerometer = senSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
    if (senAccelerometer == null) {
        senAccelerometer = senSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    }/* ww w .j a va  2  s  .c o m*/

    senSensorManager.registerListener(this, senAccelerometer, SensorManager.SENSOR_DELAY_GAME);

    sensGyro = senSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);

    if (sensGyro != null) {
        senSensorManager.registerListener(this, sensGyro, SensorManager.SENSOR_DELAY_GAME);
    }

    senMagnetometer = senSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    if (senMagnetometer != null) {
        senSensorManager.registerListener(this, senMagnetometer, SensorManager.SENSOR_DELAY_GAME);
    }

    accelList = new ArrayList<>();
    magnetics = new ArrayList<>();
    gyrolist = new ArrayList<>();
    rawXYList = new ArrayList<>();
    velocityList = new ArrayList<>();
    orientationArrayList = new ArrayList<>();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Alp_42447968_LockPatternView);

    final String aspect = a.getString(R.styleable.Alp_42447968_LockPatternView_alp_42447968_aspect);

    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;
    } else if ("lock_width".equals(aspect)) {
        mAspect = ASPECT_LOCK_WIDTH;
    } else if ("lock_height".equals(aspect)) {
        mAspect = ASPECT_LOCK_HEIGHT;
    } else {
        mAspect = ASPECT_SQUARE;
    }

    setClickable(true);

    mPathPaint.setAntiAlias(true);
    mPathPaint.setDither(true);

    mRegularColor = getResources().getColor(
            ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_regular));
    mErrorColor = getResources().getColor(
            ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_error));
    mSuccessColor = getResources().getColor(
            ResourceUtils.resolveAttribute(getContext(), R.attr.alp_42447968_color_lock_pattern_view_success));

    mRegularColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_regularColor,
            mRegularColor);
    mErrorColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_successColor,
            mSuccessColor);

    int pathColor = a.getColor(R.styleable.Alp_42447968_LockPatternView_alp_42447968_pathColor, mRegularColor);
    mPathPaint.setColor(pathColor);

    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);

    mPathWidth = getResources().getDimensionPixelSize(R.dimen.alp_42447968_lock_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);

    mDotSize = getResources().getDimensionPixelSize(R.dimen.alp_42447968_lock_pattern_dot_size);
    mDotSizeActivated = getResources()
            .getDimensionPixelSize(R.dimen.alp_42447968_lock_pattern_dot_size_activated);

    mPaint.setAntiAlias(true);
    mPaint.setDither(true);

    mCellStates = new CellState[MATRIX_WIDTH][MATRIX_WIDTH];
    for (int i = 0; i < MATRIX_WIDTH; i++) {
        for (int j = 0; j < MATRIX_WIDTH; j++) {
            mCellStates[i][j] = new CellState();
            mCellStates[i][j].size = mDotSize;
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !isInEditMode()) {
        mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                android.R.interpolator.fast_out_slow_in);
        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                android.R.interpolator.linear_out_slow_in);
    } // if
}

From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java

/**
 * Device Orientation Profile<br>// ww  w  .j a v a2 s  .  c  o  m
 * ?.
 * 
 * @param response ?
 * @param deviceId ?ID
 * @param sessionKey 
 */
public void registerDeviceOrientationEvent(final Intent response, final String deviceId,
        final String sessionKey) {

    mDeviceId = deviceId;
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    List<Sensor> sensors = mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);

    if (sensors.size() > 0) {
        Sensor sensor = sensors.get(0);
        mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
    }

    sensors = mSensorManager.getSensorList(Sensor.TYPE_GYROSCOPE);

    if (sensors.size() > 0) {
        Sensor sensor = sensors.get(0);
        mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
    }

    response.putExtra(DConnectMessage.EXTRA_RESULT, DConnectMessage.RESULT_OK);
    response.putExtra(DConnectMessage.EXTRA_VALUE, "Register OnDeviceOrientation event");
    sendBroadcast(response);
}

From source file:org.mixare.MixViewActivity.java

/**
 * Part of Android LifeCycle that gets called when "MixViewActivity" resumes.
 * <br/>//w ww  .  ja v a  2 s.  co  m
 * Does:
 * - Acquire Screen Lock
 * - Refreshes Data and Downloads
 * - Initiate four Matrixes that holds user's rotation markerRenderer.
 * - Re-register Sensors. {@link android.hardware.SensorManager SensorManager}
 * - Re-register Location Manager. {@link org.mixare.mgr.location.LocationFinder LocationFinder}
 * - Switch on Download Thread. {@link org.mixare.mgr.downloader.DownloadManager DownloadManager}
 * - restart markerRenderer refresh Timer.
 * <br/>
 * {@inheritDoc}
 */
@Override
protected void onResume() {
    super.onResume();
    if (cubeView != null) {
        //mRenderer.start();
        cubeView.onResume();
    }
    mSensorManager.registerListener(cubeView, mOrienation, SensorManager.SENSOR_DELAY_NORMAL);

    try {
        killOnError();
        MixContext.setActualMixViewActivity(this);
        HttpTools.setContext(MixContext.getInstance());

        //repaint(); //repaint when requested
        getMarkerRenderer().doStart();
        getMarkerRenderer().clearEvents();
        MixContext.getInstance().getNotificationManager().setEnabled(true);
        refreshDownload();

        MixContext.getInstance().getDataSourceManager().refreshDataSources();

        float angleX, angleY;

        int marker_orientation = -90;

        int rotation = Compatibility.getRotation(this);

        // display text from left to right and keep it horizontal
        angleX = (float) Math.toRadians(marker_orientation);
        getMixViewData().getM1().set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f,
                (float) Math.sin(angleX), (float) Math.cos(angleX));
        angleX = (float) Math.toRadians(marker_orientation);
        angleY = (float) Math.toRadians(marker_orientation);
        if (rotation == 1) {
            getMixViewData().getM2().set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX),
                    0f, (float) Math.sin(angleX), (float) Math.cos(angleX));
            getMixViewData().getM3().set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f,
                    (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY));
        } else {
            getMixViewData().getM2().set((float) Math.cos(angleX), 0f, (float) Math.sin(angleX), 0f, 1f, 0f,
                    (float) -Math.sin(angleX), 0f, (float) Math.cos(angleX));
            getMixViewData().getM3().set(1f, 0f, 0f, 0f, (float) Math.cos(angleY), (float) -Math.sin(angleY),
                    0f, (float) Math.sin(angleY), (float) Math.cos(angleY));

        }

        getMixViewData().getM4().toIdentity();

        for (int i = 0; i < getMixViewData().getHistR().length; i++) {
            getMixViewData().getHistR()[i] = new Matrix();
        }

        getMixViewData()
                .addListSensors(getMixViewData().getSensorMgr().getSensorList(Sensor.TYPE_ACCELEROMETER));
        if (getMixViewData().getSensor(0).getType() == Sensor.TYPE_ACCELEROMETER) {
            getMixViewData().setSensorGrav(getMixViewData().getSensor(0));
        } //else report error (unsupported hardware)

        getMixViewData()
                .addListSensors(getMixViewData().getSensorMgr().getSensorList(Sensor.TYPE_MAGNETIC_FIELD));
        if (getMixViewData().getSensor(1).getType() == Sensor.TYPE_MAGNETIC_FIELD) {
            getMixViewData().setSensorMag(getMixViewData().getSensor(1));
        } //else report error (unsupported hardware)

        if (!getMixViewData().getSensorMgr().getSensorList(Sensor.TYPE_GYROSCOPE).isEmpty()) {
            getMixViewData()
                    .addListSensors(getMixViewData().getSensorMgr().getSensorList(Sensor.TYPE_GYROSCOPE));
            if (getMixViewData().getSensor(2).getType() == Sensor.TYPE_GYROSCOPE) {
                getMixViewData().setSensorGyro(getMixViewData().getSensor(2));
            }
            getMixViewData().getSensorMgr().registerListener(this, getMixViewData().getSensorGyro(),
                    SENSOR_DELAY_GAME);
        }

        getMixViewData().getSensorMgr().registerListener(this, getMixViewData().getSensorGrav(),
                SENSOR_DELAY_GAME);
        getMixViewData().getSensorMgr().registerListener(this, getMixViewData().getSensorMag(),
                SENSOR_DELAY_GAME);

        try {
            GeomagneticField gmf = MixContext.getInstance().getLocationFinder().getGeomagneticField();
            angleY = (float) Math.toRadians(-gmf.getDeclination());
            getMixViewData().getM4().set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f,
                    (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY));
        } catch (Exception ex) {
            doError(ex, GPS_ERROR);
        }

        if (!isNetworkAvailable()) {
            Log.d(Config.TAG, "no network");
            doError(null, NO_NETWORK_ERROR);
        } else {
            Log.d(Config.TAG, "network");
        }

        MixContext.getInstance().getDownloadManager().switchOn();
        MixContext.getInstance().getLocationFinder().switchOn();
    } catch (Exception ex) {
        doError(ex, GENERAL_ERROR);
        try {
            if (getMixViewData().getSensorMgr() != null) {
                getMixViewData().getSensorMgr().unregisterListener(this, getMixViewData().getSensorGrav());
                getMixViewData().getSensorMgr().unregisterListener(this, getMixViewData().getSensorMag());
                getMixViewData().getSensorMgr().unregisterListener(this, getMixViewData().getSensorGyro());
                getMixViewData().setSensorMgr(null);
            }

            if (MixContext.getInstance() != null) {
                MixContext.getInstance().getLocationFinder().switchOff();
                MixContext.getInstance().getDownloadManager().switchOff();
            }
        } catch (Exception ignore) {
        }
    } finally {
        //This does not conflict with registered sensors (sensorMag, sensorGrav)
        //This is a place holder to API returned listed of sensors, we registered
        //what we need, the rest is unnecessary.
        getMixViewData().clearAllSensors();
    }

    Log.d(Config.TAG, "resume");
    if (getMarkerRenderer() == null) {
        return;
    }
    if (getMarkerRenderer().isFrozen() && getMixViewData().getSearchNotificationTxt() == null) {
        getMixViewData().setSearchNotificationTxt(new TextView(this));
        getMixViewData().getSearchNotificationTxt().setWidth(getPaintScreen().getWidth());
        getMixViewData().getSearchNotificationTxt().setPadding(10, 2, 0, 0);
        getMixViewData().getSearchNotificationTxt().setText(getString(R.string.search_active_1) + " "
                + DataSourceList.getDataSourcesStringList() + getString(R.string.search_active_2));
        ;
        getMixViewData().getSearchNotificationTxt().setBackgroundColor(Color.DKGRAY);
        getMixViewData().getSearchNotificationTxt().setTextColor(Color.WHITE);

        getMixViewData().getSearchNotificationTxt().setOnTouchListener(this);
        addContentView(getMixViewData().getSearchNotificationTxt(),
                new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    } else if (!getMarkerRenderer().isFrozen() && getMixViewData().getSearchNotificationTxt() != null) {
        getMixViewData().getSearchNotificationTxt().setVisibility(View.GONE);
        getMixViewData().setSearchNotificationTxt(null);
    }
}

From source file:org.godotengine.godot.Godot.java

private void initializeGodot() {

    if (expansion_pack_path != null) {

        String[] new_cmdline;
        int cll = 0;
        if (command_line != null) {
            new_cmdline = new String[command_line.length + 2];
            cll = command_line.length;/*from  w ww.j  a v  a2s. c o  m*/
            for (int i = 0; i < command_line.length; i++) {
                new_cmdline[i] = command_line[i];
            }
        } else {
            new_cmdline = new String[2];
        }

        new_cmdline[cll] = "--main-pack";
        new_cmdline[cll + 1] = expansion_pack_path;
        command_line = new_cmdline;
    }

    io = new GodotIO(this);
    io.unique_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    GodotLib.io = io;
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
    mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
    mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);
    mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
    mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);

    GodotLib.initialize(this, getAssets(), use_apk_expansion);

    result_callback = null;

    mPaymentsManager = PaymentsManager.createManager(this).initService();

    godot_initialized = true;
}

From source file:com.thousandthoughts.tutorials.SensorFusionActivity.java

public void initListeners() {
    mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_FASTEST);

    mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE),
            SensorManager.SENSOR_DELAY_FASTEST);

    mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
            SensorManager.SENSOR_DELAY_FASTEST);
}

From source file:com.thousandthoughts.tutorials.SensorFusionActivity.java

@Override
public void onSensorChanged(SensorEvent event) {
    switch (event.sensor.getType()) {
    case Sensor.TYPE_ACCELEROMETER:
        // copy new accelerometer data into accel array and calculate orientation
        System.arraycopy(event.values, 0, accel, 0, 3);
        calculateAccMagOrientation();//from   w  ww .ja  va  2 s.com
        break;

    case Sensor.TYPE_GYROSCOPE:
        // process gyro data
        gyroFunction(event);
        break;

    case Sensor.TYPE_MAGNETIC_FIELD:
        // copy new magnetometer data into magnet array
        System.arraycopy(event.values, 0, magnet, 0, 3);
        break;
    }
}