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:info.alni.comete.android.Comete.java

/** Called when the activity is first created. */
@Override/* w  w  w . j av a 2  s .co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_views);

    setConnectionPrefs(getSharedPreferences("connection", MODE_PRIVATE));

    sm = (SensorManager) getSystemService(SENSOR_SERVICE);
    mAccelSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mOrienSensor = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION);

    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setOnTouchListener(this);
    mAdapter = new PanelsAdapter(getSupportFragmentManager(), this);
    mPager.setOffscreenPageLimit(mAdapter.getCount() - 1);
    mPager.setAdapter(mAdapter);

    // mTvDiag = (TextView) findViewById(R.id.tvDiag);

    //

    // ((FGToggleButton)
    // findViewById(R.id.gear)).setFgProp("/controls/gear/gear-down");

    // trueFalseChecks.put((FGToggleButton)
    // findViewById(R.id.gear),"/controls/gear/gear-down");
    // trueFalseChecks.put((FGToggleButton)
    // findViewById(R.id.gear2),"/controls/gear/gear-down");
    // trueFalseChecks.put((FGToggleButton)
    // findViewById(R.id.autoCoordination),"/sim/auto-coordination");

    // for (CompoundButton c:trueFalseChecks.keySet() ) {
    // c.setOnCheckedChangeListener(onCheckedListener);
    // }

    //

    // radioButton = (Button) findViewById(R.id.radioButton);

    //
    //

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    Handler handler = new MyHandler();
    thrGetAirspeed = new PropertyGetterThread(handler);

    airspeedKey = sharedPreferences.getString("airspeedKey", getString(R.string.prop_airspeed));
    directionKey = sharedPreferences.getString("directionKey", getString(R.string.prop_direction));
    nav1FreqKey = sharedPreferences.getString("nav1FreqKey", getString(R.string.prop_nav1Freq));
    nav1RadKey = sharedPreferences.getString("nav1RadKey", getString(R.string.prop_nav1Rad));
    nav2FreqKey = sharedPreferences.getString("nav2FreqKey", getString(R.string.prop_nav2Freq));
    nav2RadKey = sharedPreferences.getString("nav2RadKey", getString(R.string.prop_nav2Rad));
    adf1FreqKey = sharedPreferences.getString("adf1FreqKey", getString(R.string.prop_adf1Freq));
    com1FreqKey = sharedPreferences.getString("com1FreqKey", getString(R.string.prop_com1Freq));

    fgViewKey = sharedPreferences.getString("fgViewKey", getString(R.string.prop_fgView));

    thrGetAirspeed.addProp(airspeedKey, getString(R.string.prop_airspeed_format));
    thrGetAirspeed.addProp(directionKey, getString(R.string.prop_direction_format));

    thrGetAirspeed.addProp("tas", getString(R.string.prop_airspeed_format));
    thrGetAirspeed.addProp("hdg", getString(R.string.prop_direction_format));

    thrGetAirspeed.setEnabled(sharedPreferences.getBoolean("enableGetting", true));
    thrGetAirspeed.start();

}

From source file:com.sorin.cloudcog.car.obd2.SilverBluetoothChatActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (D)//from   w w  w  . ja  v  a 2  s  . co  m
        Log.e(TAG, "+++ ON CREATE +++");

    // Set up the window layout
    setContentView(R.layout.car_pager_main_silver);
    // toast message at begining of activity start
    Toast.makeText(this, "Silver Light Style OBD2 data console", Toast.LENGTH_SHORT).show();
    mSilverAdapter = new CarTabFragmentHandlerSilver(getSupportFragmentManager());
    mSilverPager = (ViewPager) findViewById(R.id.pager_silver);
    mSilverPager.setAdapter(mSilverAdapter);

    mSilverIndicator = (TitlePageIndicator) findViewById(R.id.indicator_silver);
    mSilverIndicator.setViewPager(mSilverPager);

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    // When shacked it will return to main activity initialization
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mShakeDetector = new ShakeDetectorActivity();
    mShakeDetector.setOnShakeListener(new OnShakeListener() {
        // shake handler
        @Override
        public void onShake(int count) {

            SilverBluetoothChatActivity.this.finish();

        }
    });
}

From source file:io.github.msc42.masterthemaze.GameActivity.java

private boolean checkIfSensorForMotionControlIsAvailableAndInitMotionControlParameter() {
    if (mMotion) {
        SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        Sensor accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

        if (accelerometer == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.error).setMessage(R.string.noAccelerometerExisting).setCancelable(false)
                    .setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            finish();/*from  ww  w  . j a  v  a  2s .co  m*/
                        }
                    });

            builder.create().show();
            return false;
        }

        mSensitivity = mIntent.getFloatExtra(Constants.EXTRA_MESSAGE_SENSITIVITY,
                Constants.DEFAULT_SENSOR_SENSITIVITY);
        mSpeed = mIntent.getIntExtra(Constants.EXTRA_MESSAGE_SPEED, Constants.DEFAULT_SPEED);

        mRotation = getWindowManager().getDefaultDisplay().getRotation();
    }

    return true;
}

From source file:com.kircherelectronics.accelerationexplorer.activity.NoiseActivity.java

@Override
public void onResume() {
    super.onResume();

    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_FASTEST);

    lpf.setTimeConstant(getPrefLpfSmoothingTimeConstant());

    meanFilter.setTimeConstant(getPrefMeanFilterSmoothingTimeConstant());

    medianFilter.setTimeConstant(getPrefMedianFilterSmoothingTimeConstant());

    handler.post(runable);//ww  w  . j  a va 2s . co m
}

From source file:com.example.haber.ui.activity.TabbedActivity.java

private void iniSystemService() {
    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    if (sensorManager == null)
        return;/*  w w w .java  2  s.  c o  m*/
    sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
}

From source file:step.StepService.java

public void registerDetector() {
    if (mSensorManager != null && mStepDetector != null) {
        mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mSensorManager.registerListener(mStepDetector, mSensor, SensorManager.SENSOR_DELAY_FASTEST);

        // Step Detector
        mSensorManager.registerListener(mStepDetector2,
                mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER), SensorManager.SENSOR_DELAY_UI);
    }//  www. j  a  v a2s .  co  m

}

From source file:com.spoiledmilk.ibikecph.navigation.SMRouteNavigationMapFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    currentlyRouting = false;/*ww w  .  j  a  v  a 2  s.  c  o  m*/

    pathOverlay = new PathOverlay(getRouteColor(), getActivity());

    if (getActivity().getIntent().getExtras() != null) {
        startLocation = Util.locationFromCoordinates(
                getActivity().getIntent().getExtras().getDouble("start_lat"),
                getActivity().getIntent().getExtras().getDouble("start_lng"));
        endLocation = Util.locationFromCoordinates(getActivity().getIntent().getExtras().getDouble("end_lat"),
                getActivity().getIntent().getExtras().getDouble("end_lng"));
        if (getActivity().getIntent().getExtras().containsKey("json_root"))
            jsonRoot = Util.stringToJsonNode(getActivity().getIntent().getExtras().getString("json_root"));
        source = getActivity().getIntent().getExtras().getString("source");
        destination = getActivity().getIntent().getExtras().getString("destination");
    }

    getMapActivity().stopTrackingUser();
    if (getActivity().getIntent().getExtras().containsKey("start_name"))
        this.startName = getActivity().getIntent().getExtras().getString("start_name");
    if (getActivity().getIntent().getExtras().containsKey("end_name"))
        this.endName = getActivity().getIntent().getExtras().getString("end_name");
    start(startLocation, endLocation, jsonRoot, startName, endName);
    mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    textA = new TextView(getActivity());
    textA.setBackgroundResource(R.drawable.rounded_rectangle_22);
    textA.setTypeface(IbikeApplication.getNormalFont());
    textA.setTextColor(Color.BLACK);
    textA.setGravity(Gravity.CENTER);
    textA.setPadding(Util.dp2px(5), Util.dp2px(5), Util.dp2px(5), Util.dp2px(5));
    textA.setVisibility(View.GONE);
    textA.setTextSize(16);
    textA.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            textA.setVisibility(View.GONE);
        }
    });
    mapView.addView(textA);
    textB = new TextView(getActivity());
    textB.setBackgroundResource(R.drawable.rounded_rectangle_22);
    textB.setTypeface(IbikeApplication.getNormalFont());
    textB.setTextColor(Color.BLACK);
    textB.setGravity(Gravity.CENTER);
    textB.setPadding(Util.dp2px(5), Util.dp2px(5), Util.dp2px(5), Util.dp2px(5));
    textB.setVisibility(View.GONE);
    textB.setTextSize(16);
    textB.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            textB.setVisibility(View.GONE);
        }
    });
    mapView.addView(textB);

    locationOverlay.setMapFragment(this);

    mapView.directionShown = true;
    mapView.isNavigation = true;

}

From source file:com.metinkale.prayerapp.compass.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mRefresh == item) {
        mOnlyNew = true;/* w  ww  .  jav a 2  s  .c  om*/
        if (PermissionUtils.get(this).pLocation) {
            LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

            locMan.removeUpdates(this);
            List<String> providers = locMan.getProviders(true);
            for (String provider : providers) {
                locMan.requestLocationUpdates(provider, 0, 0, this);
            }
        }
    } else if (mSwitch == item) {
        if (mMode == Mode.Map) {
            mSensorManager.registerListener(mMagAccel,
                    mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                    SensorManager.SENSOR_DELAY_GAME);
            mSensorManager.registerListener(mMagAccel,
                    mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                    SensorManager.SENSOR_DELAY_GAME);

            updateFrag(Mode.TwoDim);

            mSwitch.setIcon(MaterialDrawableBuilder.with(this).setIcon(MaterialDrawableBuilder.IconValue.MAP)
                    .setColor(Color.WHITE).setToActionbarSize().build());
        } else if (PermissionUtils.get(this).pLocation) {
            mSensorManager.unregisterListener(mMagAccel);
            updateFrag(Mode.Map);
            mSwitch.setIcon(MaterialDrawableBuilder.with(this)
                    .setIcon(MaterialDrawableBuilder.IconValue.COMPASS_OUTLINE).setColor(Color.WHITE)
                    .setToActionbarSize().build());
        } else {
            Toast.makeText(this, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.nextgis.firereporter.SendReportActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.report);/*from  w w w .  j ava  2s. c o  m*/

    //add fragment
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    frCompass = (CompassFragment) getSupportFragmentManager().findFragmentByTag("COMPASS");
    if (frCompass == null) {
        frCompass = new CompassFragment();
        fragmentTransaction.add(R.id.compass_fragment_container, frCompass, "COMPASS").commit();
    }

    getSupportFragmentManager().executePendingTransactions();

    getSupportActionBar().setHomeButtonEnabled(true);

    edLatitude = (EditText) findViewById(R.id.edLatitude);
    edLongitude = (EditText) findViewById(R.id.edLongitude);
    edAzimuth = (EditText) findViewById(R.id.edAzimuth);
    edDistance = (EditText) findViewById(R.id.edDistance);
    edComment = (EditText) findViewById(R.id.edComment);

    edDistance.setText("100");

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (mLocationManager != null) {

        for (String aProvider : mLocationManager.getProviders(false)) {
            if (aProvider.equals(LocationManager.GPS_PROVIDER)) {
                gpsAvailable = true;
            }
        }

        if (gpsAvailable) {
            Location location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

            if (location != null) {
                float lat = (float) (location.getLatitude());
                float lon = (float) (location.getLongitude());
                edLatitude.setText(Float.toString(lat));
                edLongitude.setText(Float.toString(lon));
            } else {
                edLatitude.setText(getString(R.string.noLocation));
                edLongitude.setText(getString(R.string.noLocation));
            }

            mLocationListener = new LocationListener() {
                public void onStatusChanged(String provider, int status, Bundle extras) {
                    switch (status) {
                    case LocationProvider.OUT_OF_SERVICE:
                        break;
                    case LocationProvider.TEMPORARILY_UNAVAILABLE:
                        break;
                    case LocationProvider.AVAILABLE:
                        break;
                    }
                }

                public void onProviderEnabled(String provider) {
                }

                public void onProviderDisabled(String provider) {
                }

                public void onLocationChanged(Location location) {
                    float lat = (float) (location.getLatitude());
                    float lon = (float) (location.getLongitude());
                    edLatitude.setText(Float.toString(lat));
                    edLongitude.setText(Float.toString(lon));

                    // FIXME: also need to calculate declination?
                }
            }; // location listener
        } else {
            edLatitude.setText(getString(R.string.noGPS));
            edLongitude.setText(getString(R.string.noGPS));
            edLatitude.setEnabled(false);
            edLongitude.setEnabled(false);
        }
    }

    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    boolean accelerometerAvailable = false;
    boolean magnetometerAvailable = false;
    for (Sensor aSensor : mSensorManager.getSensorList(Sensor.TYPE_ALL)) {
        if (aSensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            accelerometerAvailable = true;
        } else if (aSensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
            magnetometerAvailable = true;
        }
    }

    compassAvailable = accelerometerAvailable && magnetometerAvailable;
    if (compassAvailable) {
        //frCompass = (CompassFragment) getSupportFragmentManager().findFragmentByTag("COMPASS");
        if (frCompass != null) {
            frCompass.SetAzimuthCtrl(edAzimuth);
        }
    } else {
        edAzimuth.setText(getString(R.string.noCompass));
        edAzimuth.setEnabled(false);
    }
}

From source file:com.microsoft.band.sdksample.SensorsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_sensors, container, false);

    senSensorManager1 = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    senSensorManager2 = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    senGyroscope = senSensorManager1.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    senSensorManager1.registerListener(this, senGyroscope, SensorManager.SENSOR_DELAY_NORMAL);

    senAccelerometer = senSensorManager2.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    senSensorManager2.registerListener(this, senAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);

    mTableAcc = (TableLayout) rootView.findViewById(R.id.tableAcc);
    mTableAcc.setVisibility(View.GONE);

    mTextAccX = (TextView) rootView.findViewById(R.id.textAccX);
    mTextAccY = (TextView) rootView.findViewById(R.id.textAccY);
    mTextAccZ = (TextView) rootView.findViewById(R.id.textAccZ);
    mTextAngX = (TextView) rootView.findViewById(R.id.textPAngX);
    mTextAngY = (TextView) rootView.findViewById(R.id.textPAngY);
    mTextAngZ = (TextView) rootView.findViewById(R.id.textPAngZ);

    mTextLong = (TextView) rootView.findViewById(R.id.textLong);
    mTextLat = (TextView) rootView.findViewById(R.id.textLat);

    mTextTime = (TextView) rootView.findViewById(R.id.textTime);

    temp_list = new double[14];

    c = 0;//from  ww  w .  j a  v a  2  s  .  co m
    // Acquire a reference to the system Location Manager
    LocationManager locationManager = (LocationManager) getActivity()
            .getSystemService(Context.LOCATION_SERVICE);

    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            // Called when a new location is found by the network location provider.
            temp_list[12] = location.getLongitude();
            temp_list[13] = location.getLatitude();
            mTextLong.setText(Double.toString(temp_list[12]));
            mTextLat.setText(Double.toString(temp_list[13]));
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onProviderDisabled(String provider) {
        }
    };

    // Register the listener with the Location Manager to receive location updates
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

    runnable.run();

    //
    // Gyro setup
    //
    mTableGyro = (TableLayout) rootView.findViewById(R.id.tableGyro);
    mTableGyro.setVisibility(View.GONE);

    mTextGyroAccX = (TextView) rootView.findViewById(R.id.textGyroAccX);
    mTextGyroAccY = (TextView) rootView.findViewById(R.id.textGyroAccY);
    mTextGyroAccZ = (TextView) rootView.findViewById(R.id.textGyroAccZ);
    mTextGyroAngX = (TextView) rootView.findViewById(R.id.textAngX);
    mTextGyroAngY = (TextView) rootView.findViewById(R.id.textAngY);
    mTextGyroAngZ = (TextView) rootView.findViewById(R.id.textAngZ);

    //
    // Contact setup
    //
    mTableContact = (TableLayout) rootView.findViewById(R.id.tableContact);
    mTableContact.setVisibility(View.GONE);
    mTextContact = (TextView) rootView.findViewById(R.id.textContact);

    turnOnSensors();

    return rootView;
}