List of usage examples for android.hardware Sensor TYPE_GYROSCOPE
int TYPE_GYROSCOPE
To view the source code for android.hardware Sensor TYPE_GYROSCOPE.
Click Source Link
From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java
/** * ????????./* w w w.ja v a 2s . com*/ * * @param sensorEvent . */ public void onSensorChanged(final SensorEvent sensorEvent) { if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { mAccellX = sensorEvent.values[0]; mAccellY = sensorEvent.values[1]; mAccellZ = sensorEvent.values[2]; Bundle orientation = new Bundle(); Bundle a1 = new Bundle(); a1.putDouble(DeviceOrientationProfile.PARAM_X, 0.0); a1.putDouble(DeviceOrientationProfile.PARAM_Y, 0.0); a1.putDouble(DeviceOrientationProfile.PARAM_Z, 0.0); Bundle a2 = new Bundle(); a2.putDouble(DeviceOrientationProfile.PARAM_X, mAccellX); a2.putDouble(DeviceOrientationProfile.PARAM_Y, mAccellY); a2.putDouble(DeviceOrientationProfile.PARAM_Z, mAccellZ); Bundle r = new Bundle(); r.putDouble(DeviceOrientationProfile.PARAM_ALPHA, mGyroX); r.putDouble(DeviceOrientationProfile.PARAM_BETA, mGyroY); r.putDouble(DeviceOrientationProfile.PARAM_GAMMA, mGyroZ); orientation.putBundle(DeviceOrientationProfile.PARAM_ACCELERATION, a1); orientation.putBundle(DeviceOrientationProfile.PARAM_ACCELERATION_INCLUDING_GRAVITY, a2); orientation.putBundle(DeviceOrientationProfile.PARAM_ROTATION_RATE, r); orientation.putLong(DeviceOrientationProfile.PARAM_INTERVAL, 0); DeviceOrientationProfile.setInterval(orientation, INTERVAL_TIME); List<Event> events = EventManager.INSTANCE.getEventList(mDeviceId, DeviceOrientationProfile.PROFILE_NAME, null, DeviceOrientationProfile.ATTRIBUTE_ON_DEVICE_ORIENTATION); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent intent = EventManager.createEventMessage(event); intent.putExtra(DeviceOrientationProfile.PARAM_ORIENTATION, orientation); getContext().sendBroadcast(intent); } } else if (sensorEvent.sensor.getType() == Sensor.TYPE_GYROSCOPE) { mGyroX = sensorEvent.values[0]; mGyroY = sensorEvent.values[1]; mGyroZ = sensorEvent.values[2]; } }
From source file:com.vonglasow.michael.satstat.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { Context c = getApplicationContext(); File dumpDir = c.getExternalFilesDir(null); DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.ROOT); fmt.setTimeZone(TimeZone.getTimeZone("UTC")); String fileName = String.format("satstat-%s.log", fmt.format(new Date(System.currentTimeMillis()))); File dumpFile = new File(dumpDir, fileName); PrintStream s;/*ww w. j a v a 2 s .com*/ try { InputStream buildInStream = getResources().openRawResource(R.raw.build); s = new PrintStream(dumpFile); s.append("SatStat build: "); int i; try { i = buildInStream.read(); while (i != -1) { s.write(i); i = buildInStream.read(); } buildInStream.close(); } catch (IOException e1) { e1.printStackTrace(); } s.append("\n\n"); e.printStackTrace(s); s.flush(); s.close(); Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri contentUri = Uri.fromFile(dumpFile); mediaScanIntent.setData(contentUri); c.sendBroadcast(mediaScanIntent); } catch (FileNotFoundException e2) { e2.printStackTrace(); } defaultUEH.uncaughtException(t, e); } }); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mSharedPreferences.registerOnSharedPreferenceChangeListener(this); prefUnitType = mSharedPreferences.getBoolean(Const.KEY_PREF_UNIT_TYPE, prefUnitType); prefKnots = mSharedPreferences.getBoolean(Const.KEY_PREF_KNOTS, prefKnots); prefCoord = Integer .valueOf(mSharedPreferences.getString(Const.KEY_PREF_COORD, Integer.toString(prefCoord))); prefUtc = mSharedPreferences.getBoolean(Const.KEY_PREF_UTC, prefUtc); prefCid = mSharedPreferences.getBoolean(Const.KEY_PREF_CID, prefCid); prefCid2 = mSharedPreferences.getBoolean(Const.KEY_PREF_CID2, prefCid2); prefWifiSort = Integer .valueOf(mSharedPreferences.getString(Const.KEY_PREF_WIFI_SORT, Integer.toString(prefWifiSort))); prefMapOffline = mSharedPreferences.getBoolean(Const.KEY_PREF_MAP_OFFLINE, prefMapOffline); prefMapPath = mSharedPreferences.getString(Const.KEY_PREF_MAP_PATH, prefMapPath); ActionBar actionBar = getSupportActionBar(); setContentView(R.layout.activity_main); // Find out default screen orientation Configuration config = getResources().getConfiguration(); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); int rot = wm.getDefaultDisplay().getRotation(); isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180) || config.orientation == Configuration.ORIENTATION_PORTRAIT && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270)); Log.d(TAG, "isWideScreen=" + Boolean.toString(isWideScreen)); // Create the adapter that will return a fragment for each of the // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); Context ctx = new ContextThemeWrapper(getApplication(), R.style.AppTheme); mTabLayout = new TabLayout(ctx); LinearLayout.LayoutParams mTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); mTabLayout.setLayoutParams(mTabLayoutParams); for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { TabLayout.Tab newTab = mTabLayout.newTab(); newTab.setIcon(mSectionsPagerAdapter.getPageIcon(i)); mTabLayout.addTab(newTab); } actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(mTabLayout); mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager)); mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout)); // This is needed by the mapsforge library. AndroidGraphicFactory.createInstance(this.getApplication()); // Get system services for event delivery locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mOrSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); mAccSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mGyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mMagSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mLightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); mProximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mPressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); mHumiditySensor = sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); mTempSensor = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); }
From source file:it.unime.mobility4ckan.MainActivity.java
void sendTask(final boolean shouldUpdateCountdown) { if (!isDeviceCurrentSensorsRegistered && !isRegistering) { new RegisterDevice(this).execute(datasetName); isRegistering = true;/*from ww w . j a v a 2s .com*/ return; } if (!isDeviceCurrentSensorsRegistered || !isGPSReady) { return; } String currentSpeedValue = "" + mySensor.getCurrentSpeed(); getSensorDataToSend("speedDatastoreUUID", "Speed", currentSpeedValue); lastSpeedValue = currentSpeedValue; for (int k = 0; k < sensorList.size(); k++) { switch (sensorList.get(k).getType()) { case Sensor.TYPE_AMBIENT_TEMPERATURE: // Gradi Celsius (C) String currentTempValue = "" + mySensor.getCurrentTemp(); getSensorDataToSend("temperatureDatastoreUUID", "Temperature", currentTempValue); lastTempValue = currentTempValue; break; case Sensor.TYPE_PRESSURE: String currentPressureValue = "" + mySensor.getCurrentPressure(); getSensorDataToSend("pressureDatastoreUUID", "Pressure", currentPressureValue); lastPressureValue = currentPressureValue; break; case Sensor.TYPE_LIGHT: // lx String currentLightValue = "" + mySensor.getCurrentLight(); getSensorDataToSend("lightDatastoreUUID", "Light", currentLightValue); lastLightValue = currentLightValue; break; case Sensor.TYPE_ACCELEROMETER: // m/s2 String currentAccelerationValue = mySensor.getCurrentAcceleration(); getSensorDataToSend("accelerometerDatastoreUUID", "Accelerometer", currentAccelerationValue); lastAccelerationValue = currentAccelerationValue; break; case Sensor.TYPE_GYROSCOPE: // rad/s String currentGyroscopeValue = mySensor.getCurrentGyroscope(); getSensorDataToSend("gyroscopeDatastoreUUID", "Gyroscope", currentGyroscopeValue); lastGyroscopeValue = currentGyroscopeValue; break; case Sensor.TYPE_MAGNETIC_FIELD: // T String currentMagneticValue = mySensor.getCurrentMagnetic(); getSensorDataToSend("magneticFieldDatastoreUUID", "MagneticField", currentMagneticValue); lastMagneticValue = currentMagneticValue; break; case Sensor.TYPE_PROXIMITY: // cm String currentProximityValue = "" + mySensor.getCurrentProximity(); getSensorDataToSend("proximityDatastoreUUID", "Proximity", currentProximityValue); lastProximityValue = currentProximityValue; break; case Sensor.TYPE_ROTATION_VECTOR: // unita di misura sconosciuta String currentRotationValue = mySensor.getCurrentRotation(); getSensorDataToSend("rotationVector", "RotationVector", currentRotationValue); lastRotationValue = currentRotationValue; break; case Sensor.TYPE_GRAVITY: // m/s2 String currentGravityValue = mySensor.getCurrentGravity(); getSensorDataToSend("gravity", "Gravity", currentGravityValue); lastGravityValue = currentGravityValue; break; case Sensor.TYPE_LINEAR_ACCELERATION: // m/s2 String currentLinearAccelerationValue = mySensor.getCurrentLinearAcceleration(); getSensorDataToSend("linearAcceleration", "LinearAcceleration", currentLinearAccelerationValue); lastLinearAccelerationValue = currentLinearAccelerationValue; break; case Sensor.TYPE_RELATIVE_HUMIDITY: // % String currentRelativeHumidity = "" + mySensor.getCurrentHumidity(); getSensorDataToSend("relativeHumidity", "RelativeHumidity", currentRelativeHumidity); lastRelativeHumidity = currentRelativeHumidity; break; default: break; } } runOnUiThread(new Runnable() { @Override public void run() { if (shouldUpdateCountdown) { new CountDownTimer(countdown, 1000) { public void onTick(long millisUntilFinished) { countdownText.setText("" + millisUntilFinished / 1000); } public void onFinish() { } }.start(); } } }); }
From source file:org.godotengine.godot.Godot.java
@Override public void onSensorChanged(SensorEvent event) { Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); int displayRotation = display.getRotation(); float[] adjustedValues = new float[3]; final int axisSwap[][] = { { 1, -1, 0, 1 }, // ROTATION_0 { -1, -1, 1, 0 }, // ROTATION_90 { -1, 1, 0, 1 }, // ROTATION_180 { 1, 1, 1, 0 } }; // ROTATION_270 final int[] as = axisSwap[displayRotation]; adjustedValues[0] = (float) as[0] * event.values[as[2]]; adjustedValues[1] = (float) as[1] * event.values[as[3]]; adjustedValues[2] = event.values[2]; final float x = adjustedValues[0]; final float y = adjustedValues[1]; final float z = adjustedValues[2]; final int typeOfSensor = event.sensor.getType(); if (mView != null) { mView.queueEvent(new Runnable() { @Override//w w w . j a v a 2s. c o m public void run() { if (typeOfSensor == Sensor.TYPE_ACCELEROMETER) { GodotLib.accelerometer(-x, y, -z); } if (typeOfSensor == Sensor.TYPE_GRAVITY) { GodotLib.gravity(-x, y, -z); } if (typeOfSensor == Sensor.TYPE_MAGNETIC_FIELD) { GodotLib.magnetometer(-x, y, -z); } if (typeOfSensor == Sensor.TYPE_GYROSCOPE) { GodotLib.gyroscope(x, -y, z); } } }); } }
From source file:com.vonglasow.michael.satstat.ui.MainActivity.java
/** * Called when a sensor's reading changes. Updates sensor display and rotates sky plot according * to bearing./*www . j a va 2 s.co m*/ */ public void onSensorChanged(SensorEvent event) { //to enforce sensor rate boolean isRateElapsed = false; switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: isRateElapsed = (event.timestamp / 1000) - mAccLast >= iSensorRate; // if Z acceleration is greater than X/Y combined, lock rotation, else unlock if (Math.pow(event.values[2], 2) > Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2)) { // workaround (SCREEN_ORIENTATION_LOCK is unsupported on API < 18) if (isWideScreen) setRequestedOrientation( OR_FROM_ROT_WIDE[this.getWindowManager().getDefaultDisplay().getRotation()]); else setRequestedOrientation( OR_FROM_ROT_TALL[this.getWindowManager().getDefaultDisplay().getRotation()]); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } break; case Sensor.TYPE_ORIENTATION: isRateElapsed = (event.timestamp / 1000) - mOrLast >= iSensorRate; break; case Sensor.TYPE_GYROSCOPE: isRateElapsed = (event.timestamp / 1000) - mGyroLast >= iSensorRate; break; case Sensor.TYPE_MAGNETIC_FIELD: isRateElapsed = (event.timestamp / 1000) - mMagLast >= iSensorRate; break; case Sensor.TYPE_LIGHT: isRateElapsed = (event.timestamp / 1000) - mLightLast >= iSensorRate; break; case Sensor.TYPE_PROXIMITY: isRateElapsed = (event.timestamp / 1000) - mProximityLast >= iSensorRate; break; case Sensor.TYPE_PRESSURE: isRateElapsed = (event.timestamp / 1000) - mPressureLast >= iSensorRate; break; case Sensor.TYPE_RELATIVE_HUMIDITY: isRateElapsed = (event.timestamp / 1000) - mHumidityLast >= iSensorRate; break; case Sensor.TYPE_AMBIENT_TEMPERATURE: isRateElapsed = (event.timestamp / 1000) - mTempLast >= iSensorRate; break; } if (!isRateElapsed) return; switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: mAccLast = event.timestamp / 1000; break; case Sensor.TYPE_ORIENTATION: mOrLast = event.timestamp / 1000; break; case Sensor.TYPE_GYROSCOPE: mGyroLast = event.timestamp / 1000; break; case Sensor.TYPE_MAGNETIC_FIELD: mMagLast = event.timestamp / 1000; break; case Sensor.TYPE_LIGHT: mLightLast = event.timestamp / 1000; break; case Sensor.TYPE_PROXIMITY: mProximityLast = event.timestamp / 1000; break; case Sensor.TYPE_PRESSURE: mPressureLast = event.timestamp / 1000; break; case Sensor.TYPE_RELATIVE_HUMIDITY: mHumidityLast = event.timestamp / 1000; break; case Sensor.TYPE_AMBIENT_TEMPERATURE: mTempLast = event.timestamp / 1000; break; } if (sensorSectionFragment != null) { sensorSectionFragment.onSensorChanged(event); } if (gpsSectionFragment != null) { gpsSectionFragment.onSensorChanged(event); } }
From source file:com.cellbots.logger.LoggerActivity.java
private void updateSensorUi(int sensorType, int accuracy, float[] values) { // IMPORTANT: DO NOT UPDATE THE CONTENTS INSIDE A DRAWER IF IT IS BEING // ANIMATED VIA A CALL TO animateOpen/animateClose!!! // Updating anything inside will stop the animation from running. // Note that this does not seem to affect the animation if it had been // triggered by dragging the drawer instead of being called // programatically. if (mDataDrawer.isMoving()) { return;/* w ww. j a v a 2 s .co m*/ } TextView xTextView; TextView yTextView; TextView zTextView; if (sensorType == Sensor.TYPE_ACCELEROMETER) { xTextView = mAccelXTextView; yTextView = mAccelYTextView; zTextView = mAccelZTextView; } else if (sensorType == Sensor.TYPE_GYROSCOPE) { xTextView = mGyroXTextView; yTextView = mGyroYTextView; zTextView = mGyroZTextView; } else if (sensorType == Sensor.TYPE_MAGNETIC_FIELD) { xTextView = mMagXTextView; yTextView = mMagYTextView; zTextView = mMagZTextView; } else { return; } int textColor = Color.WHITE; String prefix = ""; switch (accuracy) { case SensorManager.SENSOR_STATUS_ACCURACY_HIGH: prefix = " "; break; case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM: prefix = " *"; break; case SensorManager.SENSOR_STATUS_ACCURACY_LOW: prefix = " **"; break; case SensorManager.SENSOR_STATUS_UNRELIABLE: prefix = " ***"; break; } xTextView.setTextColor(textColor); yTextView.setTextColor(textColor); zTextView.setTextColor(textColor); xTextView.setText(prefix + numberDisplayFormatter(values[0])); yTextView.setText(prefix + numberDisplayFormatter(values[1])); zTextView.setText(prefix + numberDisplayFormatter(values[2])); }
From source file:org.mixare.MixViewActivity.java
public void onSensorChanged(SensorEvent evt) { try {// www . j ava 2 s . com if (getMixViewData().getSensorGyro() != null) { if (evt.sensor.getType() == Sensor.TYPE_GYROSCOPE) { getMixViewData().setGyro(evt.values); } if (evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { getMixViewData().setGrav( getMixViewData().getGravFilter().lowPassFilter(evt.values, getMixViewData().getGrav())); } else if (evt.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { getMixViewData().setMag( getMixViewData().getMagFilter().lowPassFilter(evt.values, getMixViewData().getMag())); } getMixViewData().setAngle(getMixViewData().getMagFilter().complementaryFilter( getMixViewData().getGrav(), getMixViewData().getGyro(), 30, getMixViewData().getAngle())); SensorManager.getRotationMatrix(getMixViewData().getRTmp(), getMixViewData().getI(), getMixViewData().getGrav(), getMixViewData().getMag()); } else { if (evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { getMixViewData().setGrav(evt.values); } else if (evt.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { getMixViewData().setMag(evt.values); } SensorManager.getRotationMatrix(getMixViewData().getRTmp(), getMixViewData().getI(), getMixViewData().getGrav(), getMixViewData().getMag()); } // augmentedView.postInvalidate(); hudView.postInvalidate(); projectedMapView.postInvalidate(); int rotation = Compatibility.getRotation(this); if (rotation == 1) { SensorManager.remapCoordinateSystem(getMixViewData().getRTmp(), SensorManager.AXIS_X, SensorManager.AXIS_MINUS_Z, getMixViewData().getRot()); } else { SensorManager.remapCoordinateSystem(getMixViewData().getRTmp(), SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_Z, getMixViewData().getRot()); } getMixViewData().getTempR().set(getMixViewData().getRot()[0], getMixViewData().getRot()[1], getMixViewData().getRot()[2], getMixViewData().getRot()[3], getMixViewData().getRot()[4], getMixViewData().getRot()[5], getMixViewData().getRot()[6], getMixViewData().getRot()[7], getMixViewData().getRot()[8]); getMixViewData().getFinalR().toIdentity(); getMixViewData().getFinalR().prod(getMixViewData().getM4()); getMixViewData().getFinalR().prod(getMixViewData().getM1()); getMixViewData().getFinalR().prod(getMixViewData().getTempR()); getMixViewData().getFinalR().prod(getMixViewData().getM3()); getMixViewData().getFinalR().prod(getMixViewData().getM2()); getMixViewData().getFinalR().invert(); getMixViewData().getHistR()[getMixViewData().getrHistIdx()].set(getMixViewData().getFinalR()); int histRLenght = getMixViewData().getHistR().length; getMixViewData().setrHistIdx(getMixViewData().getrHistIdx() + 1); if (getMixViewData().getrHistIdx() >= histRLenght) getMixViewData().setrHistIdx(0); getMixViewData().getSmoothR().set(0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f); for (int i = 0; i < histRLenght; i++) { getMixViewData().getSmoothR().add(getMixViewData().getHistR()[i]); } getMixViewData().getSmoothR().mult(1 / (float) histRLenght); MixContext.getInstance().updateSmoothRotation(getMixViewData().getSmoothR()); // float[] orientation = new float[3]; // float[] rTemp = getMixViewData().getRTmp(); // SensorManager.getOrientation(rTemp, orientation); // Log.d("PROJECT_MAP", "Sensor Angles"); // Log.d("PROJECT_MAP", orientation[0] + ", " + orientation[1] + ", " + orientation[2]); // Log.d("PROJECT_MAP", "Rotation Matrix Before Smoothing"); // Log.d("PROJECT_MAP", rTemp[0] + ", " + rTemp[1] + ", " + rTemp[2]); // Log.d("PROJECT_MAP", rTemp[3] + ", " + rTemp[4] + ", " + rTemp[5]); // Log.d("PROJECT_MAP", rTemp[6] + ", " + rTemp[7] + ", " + rTemp[8]); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.vonglasow.michael.satstat.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { Context c = getApplicationContext(); File dumpDir = c.getExternalFilesDir(null); File dumpFile = new File(dumpDir, "satstat-" + System.currentTimeMillis() + ".log"); PrintStream s;/* w w w .j av a 2 s . c o m*/ try { InputStream buildInStream = getResources().openRawResource(R.raw.build); s = new PrintStream(dumpFile); s.append("SatStat build: "); int i; try { i = buildInStream.read(); while (i != -1) { s.write(i); i = buildInStream.read(); } buildInStream.close(); } catch (IOException e1) { e1.printStackTrace(); } s.append("\n\n"); e.printStackTrace(s); s.flush(); s.close(); } catch (FileNotFoundException e2) { e2.printStackTrace(); } defaultUEH.uncaughtException(t, e); } }); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mSharedPreferences.registerOnSharedPreferenceChangeListener(this); final ActionBar actionBar = getActionBar(); setContentView(R.layout.activity_main); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Find out default screen orientation Configuration config = getResources().getConfiguration(); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); int rot = wm.getDefaultDisplay().getRotation(); isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180) || config.orientation == Configuration.ORIENTATION_PORTRAIT && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270)); Log.d("MainActivity", "isWideScreen=" + Boolean.toString(isWideScreen)); // compact action bar int dpX = (int) (this.getResources().getDisplayMetrics().widthPixels / this.getResources().getDisplayMetrics().density); /* * This is a crude way to ensure a one-line action bar with tabs * (not a drop-down list) and home (incon) and title only if there * is space, depending on screen width: * divide screen in units of 64 dp * each tab requires 1 unit, home and menu require slightly less, * title takes up approx. 2.5 units in portrait, * home and title are about 2 units wide in landscape */ if (dpX < 192) { // just enough space for drop-down list and menu actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); } else if (dpX < 320) { // not enough space for four tabs, but home will fit next to list actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(false); } else if (dpX < 384) { // just enough space for four tabs actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); } else if ((dpX < 448) || ((config.orientation == Configuration.ORIENTATION_PORTRAIT) && (dpX < 544))) { // space for four tabs and home, but not title actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(false); } else { // ample space for home, title and all four tabs actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(true); } setEmbeddedTabs(actionBar, true); providerLocations = new HashMap<String, Location>(); mAvailableProviderStyles = new ArrayList<String>(Arrays.asList(LOCATION_PROVIDER_STYLES)); providerStyles = new HashMap<String, String>(); providerAppliedStyles = new HashMap<String, String>(); providerInvalidationHandler = new Handler(); providerInvalidators = new HashMap<String, Runnable>(); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener(this); // Add tabs, specifying the tab's text and TabListener for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { actionBar.addTab(actionBar.newTab() //.setText(mSectionsPagerAdapter.getPageTitle(i)) .setIcon(mSectionsPagerAdapter.getPageIcon(i)).setTabListener(this)); } // This is needed by the mapsforge library. AndroidGraphicFactory.createInstance(this.getApplication()); // Get system services for event delivery mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mOrSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mMagSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mPressureSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); mHumiditySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); mTempSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); mAccSensorRes = getSensorDecimals(mAccSensor, mAccSensorRes); mGyroSensorRes = getSensorDecimals(mGyroSensor, mGyroSensorRes); mMagSensorRes = getSensorDecimals(mMagSensor, mMagSensorRes); mLightSensorRes = getSensorDecimals(mLightSensor, mLightSensorRes); mProximitySensorRes = getSensorDecimals(mProximitySensor, mProximitySensorRes); mPressureSensorRes = getSensorDecimals(mPressureSensor, mPressureSensorRes); mHumiditySensorRes = getSensorDecimals(mHumiditySensor, mHumiditySensorRes); mTempSensorRes = getSensorDecimals(mTempSensor, mTempSensorRes); networkTimehandler = new Handler(); networkTimeRunnable = new Runnable() { @Override public void run() { int newNetworkType = mTelephonyManager.getNetworkType(); if (getNetworkGeneration(newNetworkType) != mLastNetworkGen) onNetworkTypeChanged(newNetworkType); else networkTimehandler.postDelayed(this, NETWORK_REFRESH_DELAY); } }; wifiTimehandler = new Handler(); wifiTimeRunnable = new Runnable() { @Override public void run() { mWifiManager.startScan(); wifiTimehandler.postDelayed(this, WIFI_REFRESH_DELAY); } }; updateLocationProviderStyles(); }
From source file:com.aware.Aware_Preferences.java
/** * Gyroscope module settings UI//from ww w. ja va 2 s . co m */ private void gyroscope() { final PreferenceScreen gyro_pref = (PreferenceScreen) findPreference("gyroscope"); Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_GYROSCOPE); if (temp != null) { gyro_pref.setSummary( gyro_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA")); } else { gyro_pref.setSummary(gyro_pref.getSummary().toString().replace("*", "")); } final CheckBoxPreference gyroscope = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_GYROSCOPE); gyroscope.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_GYROSCOPE).equals("true")); gyroscope.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (mSensorMgr.getDefaultSensor(Sensor.TYPE_GYROSCOPE) == null) { showDialog(DIALOG_ERROR_MISSING_SENSOR); gyroscope.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_GYROSCOPE, false); return false; } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_GYROSCOPE, gyroscope.isChecked()); if (gyroscope.isChecked()) { framework.startGyroscope(); } else { framework.stopGyroscope(); } return true; } }); final EditTextPreference frequency_gyroscope = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_GYROSCOPE); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_GYROSCOPE).length() > 0) { frequency_gyroscope .setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_GYROSCOPE) + " microseconds"); } frequency_gyroscope .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_GYROSCOPE)); frequency_gyroscope.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_GYROSCOPE, (String) newValue); frequency_gyroscope.setSummary((String) newValue + " microseconds"); framework.startGyroscope(); return true; } }); }
From source file:com.vonglasow.michael.satstat.MainActivity.java
/** * Called when a sensor's reading changes. Updates sensor display. *//*from www. j a va 2 s . c o m*/ public void onSensorChanged(SensorEvent event) { //to enforce sensor rate boolean isRateElapsed = false; switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: isRateElapsed = (event.timestamp / 1000) - mAccLast >= iSensorRate; // if Z acceleration is greater than X/Y combined, lock rotation, else unlock if (Math.pow(event.values[2], 2) > Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2)) { // workaround (SCREEN_ORIENTATION_LOCK is unsupported on API < 18) if (isWideScreen) setRequestedOrientation( OR_FROM_ROT_WIDE[this.getWindowManager().getDefaultDisplay().getRotation()]); else setRequestedOrientation( OR_FROM_ROT_TALL[this.getWindowManager().getDefaultDisplay().getRotation()]); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } break; case Sensor.TYPE_ORIENTATION: isRateElapsed = (event.timestamp / 1000) - mOrLast >= iSensorRate; break; case Sensor.TYPE_GYROSCOPE: isRateElapsed = (event.timestamp / 1000) - mGyroLast >= iSensorRate; break; case Sensor.TYPE_MAGNETIC_FIELD: isRateElapsed = (event.timestamp / 1000) - mMagLast >= iSensorRate; break; case Sensor.TYPE_LIGHT: isRateElapsed = (event.timestamp / 1000) - mLightLast >= iSensorRate; break; case Sensor.TYPE_PROXIMITY: isRateElapsed = (event.timestamp / 1000) - mProximityLast >= iSensorRate; break; case Sensor.TYPE_PRESSURE: isRateElapsed = (event.timestamp / 1000) - mPressureLast >= iSensorRate; break; case Sensor.TYPE_RELATIVE_HUMIDITY: isRateElapsed = (event.timestamp / 1000) - mHumidityLast >= iSensorRate; break; case Sensor.TYPE_AMBIENT_TEMPERATURE: isRateElapsed = (event.timestamp / 1000) - mTempLast >= iSensorRate; break; } if (isSensorViewReady && isRateElapsed) { switch (event.sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: mAccLast = event.timestamp / 1000; accX.setText(String.format("%." + mAccSensorRes + "f", event.values[0])); accY.setText(String.format("%." + mAccSensorRes + "f", event.values[1])); accZ.setText(String.format("%." + mAccSensorRes + "f", event.values[2])); accTotal.setText(String.format("%." + mAccSensorRes + "f", Math.sqrt(Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2)))); accStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_ORIENTATION: mOrLast = event.timestamp / 1000; orAzimuth.setText(String.format("%.0f%s", event.values[0], getString(R.string.unit_degree))); orAziText.setText(formatOrientation(event.values[0])); orPitch.setText(String.format("%.0f%s", event.values[1], getString(R.string.unit_degree))); orRoll.setText(String.format("%.0f%s", event.values[2], getString(R.string.unit_degree))); orStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_GYROSCOPE: mGyroLast = event.timestamp / 1000; rotX.setText(String.format("%." + mGyroSensorRes + "f", event.values[0])); rotY.setText(String.format("%." + mGyroSensorRes + "f", event.values[1])); rotZ.setText(String.format("%." + mGyroSensorRes + "f", event.values[2])); rotTotal.setText(String.format("%." + mGyroSensorRes + "f", Math.sqrt(Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2)))); rotStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_MAGNETIC_FIELD: mMagLast = event.timestamp / 1000; magX.setText(String.format("%." + mMagSensorRes + "f", event.values[0])); magY.setText(String.format("%." + mMagSensorRes + "f", event.values[1])); magZ.setText(String.format("%." + mMagSensorRes + "f", event.values[2])); magTotal.setText(String.format("%." + mMagSensorRes + "f", Math.sqrt(Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2)))); magStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_LIGHT: mLightLast = event.timestamp / 1000; light.setText(String.format("%." + mLightSensorRes + "f", event.values[0])); lightStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_PROXIMITY: mProximityLast = event.timestamp / 1000; proximity.setText(String.format("%." + mProximitySensorRes + "f", event.values[0])); proximityStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_PRESSURE: mPressureLast = event.timestamp / 1000; metPressure.setText(String.format("%." + mPressureSensorRes + "f", event.values[0])); pressureStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_RELATIVE_HUMIDITY: mHumidityLast = event.timestamp / 1000; metHumid.setText(String.format("%." + mHumiditySensorRes + "f", event.values[0])); humidStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; case Sensor.TYPE_AMBIENT_TEMPERATURE: mTempLast = event.timestamp / 1000; metTemp.setText(String.format("%." + mTempSensorRes + "f", event.values[0])); tempStatus.setTextColor(getResources().getColor(accuracyToColor(event.accuracy))); break; } } if (isGpsViewReady && isRateElapsed) { switch (event.sensor.getType()) { case Sensor.TYPE_ORIENTATION: gpsStatusView.setYaw(event.values[0]); break; } } }