List of usage examples for android.content Context SENSOR_SERVICE
String SENSOR_SERVICE
To view the source code for android.content Context SENSOR_SERVICE.
Click Source Link
From source file:org.mozilla.gecko.GeckoAppShell.java
public static void disableSensor(int aSensortype) { SensorManager sm = (SensorManager) GeckoApp.mAppContext.getSystemService(Context.SENSOR_SERVICE); switch (aSensortype) { case SENSOR_PROXIMITY: sm.unregisterListener(GeckoApp.mAppContext, gProximitySensor); break;/*from w w w . j a va 2 s .c om*/ } }
From source file:com.mycompany.myfirstindoorsapp.PagedActivity.java
public void positionUpdated(Coordinate userPosition, int accuracy) { /**// ww w . j a va 2 s. com * Is called each time the Indoors Library calculated a new position for the user * If Lat/Lon/Rotation of your building are set correctly you can calculate a * GeoCoordinate for your users current location in the building. */ // if first try, itialize list of zones if (connected == true && firstCall == false) // if first try { this.rotation = building.getRotation(); accel = new Accel(this, (SensorManager) getSystemService(Context.SENSOR_SERVICE), rotation); firstCall = true; } currentPosition = userPosition; if (kalman != null) { long time = SystemClock.uptimeMillis(); double[] coord = new double[2]; coord[0] = (double) userPosition.x; coord[1] = (double) userPosition.y; kalman.correct(new ArrayRealVector(coord)); double[] estimatedState; estimatedState = kalman.getStateEstimationVector().toArray(); data.addToFilter(time, new Coordinate((int) estimatedState[0], (int) estimatedState[1], FLOORLVL)); data.addToIndoors(time, userPosition); } }
From source file:com.cellbots.logger.LoggerActivity.java
private void setupSensors() { // initSensorUi(); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensors = mSensorManager.getSensorList(Sensor.TYPE_ALL); initSensorLogFiles();/*from w ww .j a v a 2s. c o m*/ // initBattery(); // *Note* This function deals with UI, not actual // readings. registerBattery(); // This is the actual function that deals with // receivers. initGps(); initWifi(); printSensors(); }
From source file:org.thecongers.mtpms.MainActivity.java
@SuppressLint("HandlerLeak") @Override/*from w ww . ja v a 2s. c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setTitle(R.string.app_name); layoutFront = (LinearLayout) findViewById(R.id.layoutFront); layoutRear = (LinearLayout) findViewById(R.id.layoutRear); txtFrontPressure = (TextView) findViewById(R.id.txtFrontPressure); txtFrontTemperature = (TextView) findViewById(R.id.txtFrontTemperature); txtFrontVoltage = (TextView) findViewById(R.id.txtFrontVoltage); txtRearPressure = (TextView) findViewById(R.id.txtRearPressure); txtRearTemperature = (TextView) findViewById(R.id.txtRearTemperature); txtRearVoltage = (TextView) findViewById(R.id.txtRearVoltage); txtOutput = (TextView) findViewById(R.id.txtOutput); View myView = findViewById(R.id.appLayout); root = myView.getRootView(); sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); // Keep screen on getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // Watch for Bluetooth Changes IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED); IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED); IntentFilter filter3 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED); this.registerReceiver(btReceiver, filter1); this.registerReceiver(btReceiver, filter2); this.registerReceiver(btReceiver, filter3); sensorDB = new SensorIdDatabase(this); // Backgrounds background = this.getResources().getDrawable(R.drawable.rectangle_bordered); redBackground = this.getResources().getDrawable(R.drawable.rectangle_bordered_red); backgroundDark = this.getResources().getDrawable(R.drawable.rectangle_bordered_dark); redBackgroundDark = this.getResources().getDrawable(R.drawable.rectangle_bordered_red_dark); txtOutBackground = this.getResources().getDrawable(R.drawable.rectangle); txtOutBackgroundDark = this.getResources().getDrawable(R.drawable.rectangle_dark); // Update textViews with select units String pressureFormat = sharedPrefs.getString("prefpressuref", "0"); String pressureUnit = "psi"; if (pressureFormat.contains("1")) { // KPa pressureUnit = "KPa"; } else if (pressureFormat.contains("2")) { // Kg-f pressureUnit = "Kg-f"; } else if (pressureFormat.contains("3")) { // Bar pressureUnit = "Bar"; } String temperatureUnit = "C"; if (sharedPrefs.getString("preftempf", "0").contains("0")) { // F temperatureUnit = "F"; } txtFrontPressure.setText("--- " + pressureUnit); txtFrontTemperature.setText("--- " + temperatureUnit); txtFrontVoltage.setText("--- V"); txtRearPressure.setText("--- " + pressureUnit); txtRearTemperature.setText("--- " + temperatureUnit); txtRearVoltage.setText("--- V"); // Set initial color scheme if (!sharedPrefs.getBoolean("prefNightMode", false)) { root.setBackgroundColor(getResources().getColor(android.R.color.white)); layoutFront.setBackground(background); layoutRear.setBackground(background); txtFrontPressure.setTextColor(getResources().getColor(android.R.color.black)); txtFrontTemperature.setTextColor(getResources().getColor(android.R.color.black)); txtFrontVoltage.setTextColor(getResources().getColor(android.R.color.black)); txtRearPressure.setTextColor(getResources().getColor(android.R.color.black)); txtRearTemperature.setTextColor(getResources().getColor(android.R.color.black)); txtRearVoltage.setTextColor(getResources().getColor(android.R.color.black)); txtOutput.setBackground(txtOutBackground); txtOutput.setTextColor(getResources().getColor(android.R.color.black)); } else { root.setBackgroundColor(getResources().getColor(android.R.color.black)); layoutFront.setBackground(backgroundDark); layoutRear.setBackground(backgroundDark); txtFrontPressure.setTextColor(getResources().getColor(android.R.color.white)); txtFrontTemperature.setTextColor(getResources().getColor(android.R.color.white)); txtFrontVoltage.setTextColor(getResources().getColor(android.R.color.white)); txtRearPressure.setTextColor(getResources().getColor(android.R.color.white)); txtRearTemperature.setTextColor(getResources().getColor(android.R.color.white)); txtRearVoltage.setTextColor(getResources().getColor(android.R.color.white)); txtOutput.setBackground(txtOutBackgroundDark); txtOutput.setTextColor(getResources().getColor(android.R.color.white)); } // Check if there are sensor to wheel mappings if (sharedPrefs.getString("prefFrontID", "").equals("") && sharedPrefs.getString("prefRearID", "").equals("")) { new AlertDialog.Builder(this).setTitle(R.string.alert_setup_title) .setMessage(R.string.alert_setup_message).setNeutralButton(R.string.alert_setup_button, null) .show(); } sensorMessages = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case RECEIVE_MESSAGE: // Message received Log.d(TAG, "Serial Message Received, Length: " + msg.arg1); // Check to see if message is the correct size if (msg.arg1 == 13) { byte[] readBuf = (byte[]) msg.obj; // Validate against checksum int calculatedCheckSum = readBuf[4] + readBuf[5] + readBuf[6] + readBuf[7] + readBuf[8] + readBuf[9] + readBuf[10]; if (calculatedCheckSum == readBuf[11]) { // Convert to hex String[] hexData = new String[13]; StringBuilder sbhex = new StringBuilder(); for (int i = 0; i < msg.arg1; i++) { hexData[i] = String.format("%02X", readBuf[i]); sbhex.append(hexData[i]); } // Get sensor position String position = hexData[3]; // Get sensor ID StringBuilder sensorID = new StringBuilder(); sensorID.append(hexData[4]); sensorID.append(hexData[5]); sensorID.append(hexData[6]); sensorID.append(hexData[7]); // Check if sensor ID is new boolean checkID = sensorDB.sensorIdExists(sensorID.toString()); if (!checkID) { // Add sensor ID to db sensorDB.addID(sensorID.toString()); Toast.makeText(MainActivity.this, getResources().getString(R.string.toast_newSensor) + " " + sensorID.toString(), Toast.LENGTH_LONG).show(); } // Only parse message if there is one or more sensor mappings String prefFrontID = sharedPrefs.getString("prefFrontID", ""); String prefRearID = sharedPrefs.getString("prefRearID", ""); if (!prefFrontID.equals("") || !prefRearID.equals("")) { try { // Get temperature int tempC = Integer.parseInt(hexData[8], 16) - 50; double temp = tempC; String temperatureUnit = "C"; // Get tire pressure int psi = Integer.parseInt(hexData[9], 16); double pressure = psi; String pressureUnit = "psi"; // Get battery voltage double voltage = Integer.parseInt(hexData[10], 16) / 50; // Get pressure thresholds int fLowPressure = Integer .parseInt(sharedPrefs.getString("prefFrontLowPressure", "30")); int fHighPressure = Integer .parseInt(sharedPrefs.getString("prefFrontHighPressure", "46")); int rLowPressure = Integer .parseInt(sharedPrefs.getString("prefRearLowPressure", "30")); int rHighPressure = Integer .parseInt(sharedPrefs.getString("prefRearHighPressure", "46")); if (sharedPrefs.getString("preftempf", "0").contains("0")) { // F temp = (9.0 / 5.0) * tempC + 32.0; temperatureUnit = "F"; } int formattedTemperature = (int) (temp + 0.5d); String pressureFormat = sharedPrefs.getString("prefpressuref", "0"); if (pressureFormat.contains("1")) { // KPa pressure = psi * 6.894757293168361; pressureUnit = "KPa"; } else if (pressureFormat.contains("2")) { // Kg-f pressure = psi * 0.070306957965539; pressureUnit = "Kg-f"; } else if (pressureFormat.contains("3")) { // Bar pressure = psi * 0.0689475729; pressureUnit = "Bar"; } int formattedPressure = (int) (pressure + 0.5d); // Get checksum String checksum = hexData[11]; Log.d(TAG, "Sensor ID: " + sensorID.toString() + ", Sensor Position: " + position + ", Temperature(" + temperatureUnit + "): " + String.valueOf(temp) + ", Pressure(" + pressureUnit + "): " + String.valueOf(pressure) + ", Voltage: " + String.valueOf(voltage) + ", Checksum: " + checksum + ", Data: " + sbhex.toString() + ", Bytes:" + msg.arg1); if (sensorID.toString().equals(prefFrontID)) { Log.d(TAG, "Front ID matched"); // Check for data logging enabled if (sharedPrefs.getBoolean("prefDataLogging", false)) { // Log data if (logger == null) { logger = new LogData(); } logger.write("front", String.valueOf(psi), String.valueOf(tempC), String.valueOf(voltage)); } // Set front tire status if (psi <= fLowPressure) { frontStatus = 1; } else if (psi >= fHighPressure) { frontStatus = 2; } else { frontStatus = 0; } txtFrontPressure .setText(String.valueOf(formattedPressure) + " " + pressureUnit); txtFrontTemperature.setText( String.valueOf(formattedTemperature) + " " + temperatureUnit); txtFrontVoltage.setText(String.format("%.2f", voltage) + " V"); } else if (sensorID.toString().equals(prefRearID)) { Log.d(TAG, "Rear ID matched"); // Check for data logging enabled if (sharedPrefs.getBoolean("prefDataLogging", false)) { // Log data if (logger == null) { logger = new LogData(); } logger.write("rear", String.valueOf(psi), String.valueOf(tempC), String.valueOf(voltage)); } // Set rear tire status if (psi <= rLowPressure) { rearStatus = 1; } else if (psi >= rHighPressure) { rearStatus = 2; } else { rearStatus = 0; } txtRearPressure .setText(String.valueOf(formattedPressure) + " " + pressureUnit); txtRearTemperature.setText( String.valueOf(formattedTemperature) + " " + temperatureUnit); txtRearVoltage.setText(String.format("%.2f", voltage) + " V"); } // Update txtOutput box and send notification if ((frontStatus == 0) && (rearStatus == 0)) { txtOutput.setText(""); if (notificationManager != null) { notificationManager.cancel(0); } } else if ((frontStatus == 1) && (rearStatus == 0)) { txtOutput .setText(getResources().getString(R.string.alert_lowFrontPressure)); Notify(getResources().getString(R.string.alert_lowFrontPressure)); } else if ((frontStatus == 2) && (rearStatus == 0)) { txtOutput.setText( getResources().getString(R.string.alert_highFrontPressure)); Notify(getResources().getString(R.string.alert_highFrontPressure)); } else if ((rearStatus == 1) && (frontStatus == 0)) { txtOutput.setText(getResources().getString(R.string.alert_lowRearPressure)); Notify(getResources().getString(R.string.alert_lowRearPressure)); } else if ((rearStatus == 2) && (frontStatus == 0)) { txtOutput .setText(getResources().getString(R.string.alert_highRearPressure)); Notify(getResources().getString(R.string.alert_highRearPressure)); } else if ((frontStatus == 1) && (rearStatus == 1)) { txtOutput.setText( getResources().getString(R.string.alert_lowFrontLowRearPressure)); Notify(getResources().getString(R.string.alert_lowFrontLowRearPressure)); } else if ((frontStatus == 2) && (rearStatus == 2)) { txtOutput.setText( getResources().getString(R.string.alert_highFrontHighRearPressure)); Notify(getResources().getString(R.string.alert_highFrontHighRearPressure)); } else if ((frontStatus == 1) && (rearStatus == 2)) { txtOutput.setText( getResources().getString(R.string.alert_lowFrontHighRearPressure)); Notify(getResources().getString(R.string.alert_lowFrontHighRearPressure)); } else if ((frontStatus == 2) && (rearStatus == 1)) { txtOutput.setText( getResources().getString(R.string.alert_highFrontLowRearPressure)); Notify(getResources().getString(R.string.alert_highFrontLowRearPressure)); } // Update color scheme if ((!itsDark) && (!sharedPrefs.getBoolean("prefNightMode", false))) { if (frontStatus == 0) { layoutFront.setBackground(background); } else { layoutFront.setBackground(redBackground); } if (rearStatus == 0) { layoutRear.setBackground(background); } else { layoutRear.setBackground(redBackground); } root.setBackgroundColor(getResources().getColor(android.R.color.white)); txtOutput.setBackground(txtOutBackground); txtOutput.setTextColor(getResources().getColor(android.R.color.black)); txtFrontPressure .setTextColor(getResources().getColor(android.R.color.black)); txtFrontTemperature .setTextColor(getResources().getColor(android.R.color.black)); txtFrontVoltage .setTextColor(getResources().getColor(android.R.color.black)); txtRearPressure .setTextColor(getResources().getColor(android.R.color.black)); txtRearTemperature .setTextColor(getResources().getColor(android.R.color.black)); txtRearVoltage.setTextColor(getResources().getColor(android.R.color.black)); } else { if (frontStatus == 0) { layoutFront.setBackground(backgroundDark); } else { layoutFront.setBackground(redBackgroundDark); } if (rearStatus == 0) { layoutRear.setBackground(backgroundDark); } else { layoutRear.setBackground(redBackgroundDark); } root.setBackgroundColor(getResources().getColor(android.R.color.black)); txtOutput.setBackground(txtOutBackgroundDark); txtOutput.setTextColor(getResources().getColor(android.R.color.white)); txtFrontPressure .setTextColor(getResources().getColor(android.R.color.white)); txtFrontTemperature .setTextColor(getResources().getColor(android.R.color.white)); txtFrontVoltage .setTextColor(getResources().getColor(android.R.color.white)); txtRearPressure .setTextColor(getResources().getColor(android.R.color.white)); txtRearTemperature .setTextColor(getResources().getColor(android.R.color.white)); txtRearVoltage.setTextColor(getResources().getColor(android.R.color.white)); } } catch (NumberFormatException e) { Log.d(TAG, "Malformed message, unexpected value"); } } } } else { Log.d(TAG, "Malformed message, message length: " + msg.arg1); } break; } } }; // Light Sensor Stuff SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); Sensor lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); if (lightSensor == null) { Log.d(TAG, "Light sensor not found"); } else { float max = lightSensor.getMaximumRange(); sensorManager.registerListener(lightSensorEventListener, lightSensor, SensorManager.SENSOR_DELAY_NORMAL); hasSensor = true; Log.d(TAG, "Light Sensor Max Value: " + max); } // Try to connect to iTPMSystem btConnect(); }
From source file:paulscode.android.mupen64plusae.game.GameActivity.java
@SuppressLint("InlinedApi") private void initControllers(View inputSource) { // By default, send Player 1 rumbles through phone vibrator final Vibrator vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE); CoreInterface.registerVibrator(1, vibrator); // Create the touchscreen controls if (mGamePrefs.isTouchscreenEnabled) { if (!mGamePrefs.sensorAxisX.isEmpty() || !mGamePrefs.sensorAxisY.isEmpty()) { // Create the sensor controller final SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensorController = new SensorController(sensorManager, mOverlay, mGamePrefs.sensorAxisX, mGamePrefs.sensorSensitivityX, mGamePrefs.sensorAngleX, mGamePrefs.sensorAxisY, mGamePrefs.sensorSensitivityY, mGamePrefs.sensorAngleY); mControllers.add(mSensorController); if (mGamePrefs.sensorActivateOnStart) { mSensorController.setSensorEnabled(true); mOverlay.onSensorEnabled(true); }/*from www . ja va 2 s . c om*/ } // Create the touchscreen controller final TouchController touchscreenController = new TouchController(mTouchscreenMap, inputSource, mOverlay, vibrator, mGlobalPrefs.touchscreenAutoHold, mGlobalPrefs.isTouchscreenFeedbackEnabled, mGamePrefs.touchscreenAutoHoldables, mSensorController); mControllers.add(touchscreenController); mDrawerLayout.setTouchMap(mTouchscreenMap); } //Check for controller configuration boolean needs1 = false; boolean needs2 = false; boolean needs3 = false; boolean needs4 = false; // Popup the multi-player dialog if necessary and abort if any players are unassigned final RomDatabase romDatabase = RomDatabase.getInstance(); if (!romDatabase.hasDatabaseFile()) { final AppData appData = new AppData(this); romDatabase.setDatabaseFile(appData.mupen64plus_ini); } final RomDetail romDetail = romDatabase.lookupByMd5WithFallback(mRomMd5, new File(mRomPath), mRomCrc); if (romDetail.players > 1 && mGamePrefs.playerMap.isEnabled() && mGlobalPrefs.getPlayerMapReminder()) { mGamePrefs.playerMap.removeUnavailableMappings(); needs1 = mGamePrefs.isControllerEnabled1 && !mGamePrefs.playerMap.isMapped(1); needs2 = mGamePrefs.isControllerEnabled2 && !mGamePrefs.playerMap.isMapped(2); needs3 = mGamePrefs.isControllerEnabled3 && !mGamePrefs.playerMap.isMapped(3) && romDetail.players > 2; needs4 = mGamePrefs.isControllerEnabled4 && !mGamePrefs.playerMap.isMapped(4) && romDetail.players > 3; if (needs1 || needs2 || needs3 || needs4) { // TODO FIXME // @SuppressWarnings( "deprecation" ) // PlayerMapPreference pref = (PlayerMapPreference) findPreference( "playerMap" ); // pref.show(); // return; Popups.showNeedsPlayerMap(this); } } // Create the input providers shared among all peripheral controllers mKeyProvider = new KeyProvider(inputSource, ImeFormula.DEFAULT, mGlobalPrefs.unmappableKeyCodes); final MogaProvider mogaProvider = new MogaProvider(mMogaController); final AbstractProvider axisProvider = new AxisProvider(inputSource); // Create the peripheral controls to handle key/stick presses if (mGamePrefs.isControllerEnabled1 && !needs1) { final ControllerProfile p = mGamePrefs.controllerProfile1; mControllers.add(new PeripheralController(1, mGamePrefs.playerMap, p.getMap(), p.getDeadzone(), p.getSensitivity(), mOverlay, mSensorController, mKeyProvider, axisProvider, mogaProvider)); } if (mGamePrefs.isControllerEnabled2 && !needs2) { final ControllerProfile p = mGamePrefs.controllerProfile2; mControllers.add(new PeripheralController(2, mGamePrefs.playerMap, p.getMap(), p.getDeadzone(), p.getSensitivity(), mOverlay, null, mKeyProvider, axisProvider, mogaProvider)); } if (mGamePrefs.isControllerEnabled3 && !needs3) { final ControllerProfile p = mGamePrefs.controllerProfile3; mControllers.add(new PeripheralController(3, mGamePrefs.playerMap, p.getMap(), p.getDeadzone(), p.getSensitivity(), mOverlay, null, mKeyProvider, axisProvider, mogaProvider)); } if (mGamePrefs.isControllerEnabled4 && !needs4) { final ControllerProfile p = mGamePrefs.controllerProfile4; mControllers.add(new PeripheralController(4, mGamePrefs.playerMap, p.getMap(), p.getDeadzone(), p.getSensitivity(), mOverlay, null, mKeyProvider, axisProvider, mogaProvider)); } }
From source file:org.uguess.android.sysinfo.SiragonManager.java
private int getSensorState() { SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); if (sm != null) { List<Sensor> ss = sm.getSensorList(Sensor.TYPE_ALL); int c = 0; if (ss != null) { c = ss.size();/* w ww . j a v a2 s . c o m*/ } return c; } return -1; }
From source file:sysnetlab.android.sdc.ui.CreateExperimentActivity.java
private void runExperiment() { if (mRunExperimentServiceBound) { SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mRunExperimentService.runExperimentInService(sensorManager, mExperiment); CharSequence text = "Started data collection for " + mExperiment.getSensors().size() + " Sensors"; Toast.makeText(this, text, Toast.LENGTH_LONG).show(); }/*w ww. j a v a 2s . c o m*/ }
From source file:sysnetlab.android.sdc.ui.CreateExperimentActivity.java
private void stopExperiment() { if (mRunExperimentServiceBound) { SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mRunExperimentService.stopExperimentInService(sensorManager, mExperiment); CharSequence text = "Stopped data collection for " + mExperiment.getSensors().size() + " Sensors"; Toast.makeText(this, text, Toast.LENGTH_LONG).show(); }/* w w w . j ava2s . co m*/ }
From source file:paulscode.android.mupen64plusae.game.GameFragment.java
@SuppressLint("InlinedApi") private void initControllers(View inputSource) { // By default, send Player 1 rumbles through phone vibrator final Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); mCoreFragment.registerVibrator(1, vibrator); // Create the touchscreen controls if (mGamePrefs.isTouchscreenEnabled) { if (!mGamePrefs.sensorAxisX.isEmpty() || !mGamePrefs.sensorAxisY.isEmpty()) { // Create the sensor controller final SensorManager sensorManager = (SensorManager) getActivity() .getSystemService(Context.SENSOR_SERVICE); mSensorController = new SensorController(mCoreFragment, sensorManager, mOverlay, mGamePrefs.sensorAxisX, mGamePrefs.sensorSensitivityX, mGamePrefs.sensorAngleX, mGamePrefs.sensorAxisY, mGamePrefs.sensorSensitivityY, mGamePrefs.sensorAngleY); if (mGamePrefs.sensorActivateOnStart) { mSensorController.setSensorEnabled(true); mOverlay.onSensorEnabled(true); }/*from w ww.ja v a 2 s. co m*/ } // Create the touchscreen controller mTouchscreenController = new TouchController(mCoreFragment, mTouchscreenMap, mOverlay, vibrator, mGamePrefs.touchscreenAutoHold, mGlobalPrefs.isTouchscreenFeedbackEnabled, mGamePrefs.touchscreenNotAutoHoldables, mSensorController, mGamePrefs.invertTouchXAxis, mGamePrefs.invertTouchYAxis); inputSource.setOnTouchListener(this); mDrawerLayout.setTouchMap(mTouchscreenMap); } //Check for controller configuration boolean needs1 = false; boolean needs2 = false; boolean needs3 = false; boolean needs4 = false; // Popup the multi-player dialog if necessary and abort if any players are unassigned final RomDatabase romDatabase = RomDatabase.getInstance(); if (!romDatabase.hasDatabaseFile()) { romDatabase.setDatabaseFile(mAppData.mupen64plus_ini); } final RomDetail romDetail = romDatabase.lookupByMd5WithFallback(mRomMd5, new File(mRomPath), mRomCrc); if (romDetail.players > 1 && mGamePrefs.playerMap.isEnabled() && mGlobalPrefs.getPlayerMapReminder()) { mGamePrefs.playerMap.removeUnavailableMappings(); needs1 = mGamePrefs.isControllerEnabled1 && !mGamePrefs.playerMap.isMapped(1); needs2 = mGamePrefs.isControllerEnabled2 && !mGamePrefs.playerMap.isMapped(2); needs3 = mGamePrefs.isControllerEnabled3 && !mGamePrefs.playerMap.isMapped(3) && romDetail.players > 2; needs4 = mGamePrefs.isControllerEnabled4 && !mGamePrefs.playerMap.isMapped(4) && romDetail.players > 3; if (needs1 || needs2 || needs3 || needs4) { Popups.showNeedsPlayerMap(getActivity()); } } // Create the input providers shared among all peripheral controllers mKeyProvider = new KeyProvider(inputSource, ImeFormula.DEFAULT, mGlobalPrefs.unmappableKeyCodes); final MogaProvider mogaProvider = new MogaProvider(mMogaController); mAxisProvider = new AxisProvider(); // Request focus for proper listening inputSource.requestFocus(); // Create the peripheral controls to handle key/stick presses if (mGamePrefs.isControllerEnabled1 && !needs1) { final ControllerProfile p = mGamePrefs.controllerProfile1; new PeripheralController(mCoreFragment, 1, mGamePrefs.playerMap, p.getMap(), p.getDeadzone(), p.getSensitivityX(), p.getSensitivityY(), mOverlay, this, mSensorController, mKeyProvider, mAxisProvider, mogaProvider); Log.i("GameFragment", "Player 1 has been enabled"); } if (mGamePrefs.isControllerEnabled2 && !needs2) { final ControllerProfile p = mGamePrefs.controllerProfile2; new PeripheralController(mCoreFragment, 2, mGamePrefs.playerMap, p.getMap(), p.getDeadzone(), p.getSensitivityX(), p.getSensitivityY(), mOverlay, this, null, mKeyProvider, mAxisProvider, mogaProvider); Log.i("GameFragment", "Player 2 has been enabled"); } if (mGamePrefs.isControllerEnabled3 && !needs3) { final ControllerProfile p = mGamePrefs.controllerProfile3; new PeripheralController(mCoreFragment, 3, mGamePrefs.playerMap, p.getMap(), p.getDeadzone(), p.getSensitivityX(), p.getSensitivityY(), mOverlay, this, null, mKeyProvider, mAxisProvider, mogaProvider); Log.i("GameFragment", "Player 3 has been enabled"); } if (mGamePrefs.isControllerEnabled4 && !needs4) { final ControllerProfile p = mGamePrefs.controllerProfile4; new PeripheralController(mCoreFragment, 4, mGamePrefs.playerMap, p.getMap(), p.getDeadzone(), p.getSensitivityX(), p.getSensitivityY(), mOverlay, this, null, mKeyProvider, mAxisProvider, mogaProvider); Log.i("GameFragment", "Player 4 has been enabled"); } }
From source file:com.coincide.alphafitness.ui.Fragment_Main.java
public void onSWatchStart() { if (isButtonStartPressed) { onSWatchStop();// ww w.j a v a 2s. c om // startStopService(); try { SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); sm.unregisterListener(this); } catch (Exception e) { e.printStackTrace(); } } else { // startStopService(); getActivity().startService(new Intent(getActivity(), SensorListener.class)); try { SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); sm.registerListener(this, sm.getDefaultSensor(Sensor.TYPE_STEP_COUNTER), SensorManager.SENSOR_DELAY_UI, 0); } catch (Exception e) { e.printStackTrace(); } isButtonStartPressed = true; startButton.setBackgroundResource(R.drawable.btn_stop_states); startButton.setText(R.string.btn_stop); getActivity().startService(new Intent(getActivity(), BroadcastService.class)); /*lapButton.setBackgroundResource(R.drawable.btn_lap_states); lapButton.setText(R.string.btn_lap); lapButton.setEnabled(true);*/ // setUpNotification(); /*timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { public void run() { currentTime += 1; // lapTime += 1; *//*manager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE); // update notification text builder.setContentText(TimeFormatUtil.toDisplayString(currentTime)); manager.notify(mId, builder.build());*//* // update ui tv_duration.setText(TimeFormatUtil.toDisplayString(currentTime)); } }); } }, 0, 100);*/ } }