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:ngoc.com.pedometer.ui.Fragment_Overview.java
private void startCountOrPause() { SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); if (getActivity().getSharedPreferences("pedometer", Context.MODE_PRIVATE).contains("pauseCount")) { // currently paused -> now resumed sm.registerListener(this, sm.getDefaultSensor(Sensor.TYPE_STEP_COUNTER), SensorManager.SENSOR_DELAY_UI, 0);/*from ww w. j a v a 2 s. co m*/ } else { sm.unregisterListener(this); } getActivity().startService( new Intent(getActivity(), SensorListener.class).putExtra("action", SensorListener.ACTION_PAUSE)); }
From source file:com.google.android.apps.santatracker.dasherdancer.DasherDancerActivity.java
@Override public void onResume() { super.onResume(); SensorManager manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); Sensor accel = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); manager.registerListener(this, accel, SensorManager.SENSOR_DELAY_NORMAL); mDetector.start(manager);/*from w w w . ja v a2 s . c o m*/ if (mInitialized) { //Start the animation for the first character. mPager.postDelayed(new Runnable() { @Override public void run() { loadAnimation(true, sCharacters[mPager.getCurrentItem()].getDuration(Character.ANIM_IDLE), sCharacters[mPager.getCurrentItem()].getFrameIndices(Character.ANIM_IDLE), sCharacters[mPager.getCurrentItem()].getFrames(Character.ANIM_IDLE)); } }, 300); } else { if (mLoadAllBitmapsTask != null) { mLoadAllBitmapsTask.cancel(true); } mLoadAllBitmapsTask = new LoadAllBitmapsTask(); mLoadAllBitmapsTask.execute(sCharacters[mPager.getCurrentItem()]); } }
From source file:com.android.cts.verifier.sensors.SignificantMotionTestActivity.java
@Override protected void activitySetUp() { mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE); mSensorSignificantMotion = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION); if (mSensorSignificantMotion == null) { throw new SensorNotSupportedException(Sensor.TYPE_SIGNIFICANT_MOTION); }//from www. j av a 2 s. c o m mScreenManipulator = new SensorTestScreenManipulator(this); try { mScreenManipulator.initialize(this); } catch (InterruptedException e) { } PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); LocalBroadcastManager.getInstance(this).registerReceiver(myBroadCastReceiver, new IntentFilter(ACTION_ALARM)); }
From source file:org.osm.keypadmapper2.KeypadMapper2Activity.java
/** Called when the activity is first created. */ @Override// w w w. j ava 2s .c o m public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "create"); if (KeypadMapperApplication.getInstance().getSettings().isLayoutOptimizationEnabled()) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); uiOptimizationEnabled = true; } super.onCreate(savedInstanceState); if (KeypadMapperApplication.getInstance().getSettings().isCompassAvailable()) { sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); gsensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); msensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); } updateLocale(); setContentView(R.layout.main); menu = new KeypadMapperMenu(findViewById(R.id.menu)); menu.setMenuListener(this); gestureDetector = new GestureDetector(this, new MyGestureDetector()); // check for external storage String extStorageState = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(extStorageState)) { // We can read and write the media } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) { // We can only read the media showDialogFatalError(localizer.getString("errorStorageRO")); } else { // Something else is wrong. It may be one of many other states, but // all we need to know is we can neither read nor write showDialogFatalError(localizer.getString("errorStorageUnavailable")); } File kpmFolder = KeypadMapperApplication.getInstance().getKeypadMapperDirectory(); if (!kpmFolder.exists()) { if (!kpmFolder.mkdir()) { showDialogFatalError(localizer.getString("FolderCreationFailed")); } } if (savedInstanceState == null) { savedInstanceState = getIntent().getExtras(); } duplicates = new StringBuffer(); allData = new StringBuffer(); if (savedInstanceState == null) { // first start state = State.keypad; // only on first run automatically start GPS recording if (KeypadMapperApplication.getInstance().getSettings().isFirstRun()) { KeypadMapperApplication.getInstance().getSettings().clearFirstRun(); KeypadMapperApplication.getInstance().startGpsRecording(); // always start when app starts } } else { // restart state = State.values()[savedInstanceState.getInt("state", State.keypad.ordinal())]; satteliteInfoVisible = savedInstanceState.getBoolean("sat_info"); extendedAddressActive = savedInstanceState.getBoolean("extended_address"); if (savedInstanceState.getBoolean("debug_dialog_on")) { duplicates.append(savedInstanceState.getString("duplicates")); allData.append(savedInstanceState.getString("allData")); showTestScreenDialog(); } } keypadFragment = (KeypadFragment) getSupportFragmentManager().findFragmentByTag("keypad"); Log.d("Keypad", "isTablet = " + getResources().getBoolean(R.bool.is_tablet)); if (!getResources().getBoolean(R.bool.is_tablet)) { extendedAddressFragment = (ExtendedAddressFragment) getSupportFragmentManager() .findFragmentByTag("extended_address"); } else { extendedAddressFragment = (ExtendedAddressFragment) getSupportFragmentManager() .findFragmentById(R.id.fragment_extended_address_tablet); } Log.d("Keypad", "extended address fragment = " + extendedAddressFragment); satelliteInfo = (SatelliteInfoFragment) getSupportFragmentManager().findFragmentByTag("satellite"); satInfoView = findViewById(R.id.satellite_view); extendedAddressView = findViewById(R.id.extended_address_view); keypadView = findViewById(R.id.keypad_view); if (keypadView == null && extendedAddressView == null) { state = State.both; } btnTestVersion = (Button) keypadView.findViewById(R.id.btnTestVersion); /* btnTestVersion.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(); i.setClass(KeypadMapper2Activity.this, SettingsActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(i); // show debug screen with all registered addresses and locations //showTestScreenDialog(); } });*/ if (satteliteInfoVisible) { showSatteliteInfo(); } else { showKeypad(); } locationProvider.refreshReferenceToGps(); }
From source file:org.openchaos.android.fooping.service.PingService.java
@Override protected void onHandleIntent(Intent intent) { String clientID = prefs.getString("ClientID", "unknown"); long ts = System.currentTimeMillis(); Log.d(tag, "onHandleIntent()"); // always send ping if (true) {/*from w w w. j a v a 2s . co m*/ try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "ping"); json.put("ts", ts); sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } // http://developer.android.com/training/monitoring-device-state/battery-monitoring.html // http://developer.android.com/reference/android/os/BatteryManager.html if (prefs.getBoolean("UseBattery", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "battery"); json.put("ts", ts); Intent batteryStatus = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (batteryStatus != null) { JSONObject bat_data = new JSONObject(); int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); if (level >= 0 && scale > 0) { bat_data.put("pct", roundValue(((double) level / (double) scale) * 100, 2)); } else { Log.w(tag, "Battery level unknown"); bat_data.put("pct", -1); } bat_data.put("health", batteryStatus.getIntExtra(BatteryManager.EXTRA_HEALTH, -1)); bat_data.put("status", batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1)); bat_data.put("plug", batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)); bat_data.put("volt", batteryStatus.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1)); bat_data.put("temp", batteryStatus.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1)); bat_data.put("tech", batteryStatus.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY)); // bat_data.put("present", batteryStatus.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)); json.put("battery", bat_data); } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } // http://developer.android.com/guide/topics/location/strategies.html // http://developer.android.com/reference/android/location/LocationManager.html if (prefs.getBoolean("UseGPS", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "loc_gps"); json.put("ts", ts); if (lm == null) { lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); } Location last_loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (last_loc != null) { JSONObject loc_data = new JSONObject(); loc_data.put("ts", last_loc.getTime()); loc_data.put("lat", last_loc.getLatitude()); loc_data.put("lon", last_loc.getLongitude()); if (last_loc.hasAltitude()) loc_data.put("alt", roundValue(last_loc.getAltitude(), 4)); if (last_loc.hasAccuracy()) loc_data.put("acc", roundValue(last_loc.getAccuracy(), 4)); if (last_loc.hasSpeed()) loc_data.put("speed", roundValue(last_loc.getSpeed(), 4)); if (last_loc.hasBearing()) loc_data.put("bearing", roundValue(last_loc.getBearing(), 4)); json.put("loc_gps", loc_data); } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } if (prefs.getBoolean("UseNetwork", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "loc_net"); json.put("ts", ts); if (lm == null) { lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); } Location last_loc = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (last_loc != null) { JSONObject loc_data = new JSONObject(); loc_data.put("ts", last_loc.getTime()); loc_data.put("lat", last_loc.getLatitude()); loc_data.put("lon", last_loc.getLongitude()); if (last_loc.hasAltitude()) loc_data.put("alt", roundValue(last_loc.getAltitude(), 4)); if (last_loc.hasAccuracy()) loc_data.put("acc", roundValue(last_loc.getAccuracy(), 4)); if (last_loc.hasSpeed()) loc_data.put("speed", roundValue(last_loc.getSpeed(), 4)); if (last_loc.hasBearing()) loc_data.put("bearing", roundValue(last_loc.getBearing(), 4)); json.put("loc_net", loc_data); } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } // http://developer.android.com/reference/android/net/wifi/WifiManager.html if (prefs.getBoolean("UseWIFI", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "wifi"); json.put("ts", ts); if (wm == null) { wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); } List<ScanResult> wifiScan = wm.getScanResults(); if (wifiScan != null) { JSONArray wifi_list = new JSONArray(); for (ScanResult wifi : wifiScan) { JSONObject wifi_data = new JSONObject(); wifi_data.put("BSSID", wifi.BSSID); wifi_data.put("SSID", wifi.SSID); wifi_data.put("freq", wifi.frequency); wifi_data.put("level", wifi.level); // wifi_data.put("cap", wifi.capabilities); // wifi_data.put("ts", wifi.timestamp); wifi_list.put(wifi_data); } json.put("wifi", wifi_list); } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } // TODO: cannot poll sensors. register receiver to cache sensor data // http://developer.android.com/guide/topics/sensors/sensors_overview.html // http://developer.android.com/reference/android/hardware/SensorManager.html if (prefs.getBoolean("UseSensors", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "sensors"); json.put("ts", ts); if (sm == null) { sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE); } List<Sensor> sensors = sm.getSensorList(Sensor.TYPE_ALL); if (sensors != null) { JSONArray sensor_list = new JSONArray(); for (Sensor sensor : sensors) { JSONObject sensor_info = new JSONObject(); sensor_info.put("name", sensor.getName()); sensor_info.put("type", sensor.getType()); sensor_info.put("vendor", sensor.getVendor()); sensor_info.put("version", sensor.getVersion()); sensor_info.put("power", roundValue(sensor.getPower(), 4)); sensor_info.put("resolution", roundValue(sensor.getResolution(), 4)); sensor_info.put("range", roundValue(sensor.getMaximumRange(), 4)); sensor_list.put(sensor_info); } json.put("sensors", sensor_list); } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } // http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html // http://developer.android.com/reference/android/net/ConnectivityManager.html if (prefs.getBoolean("UseConn", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "conn"); json.put("ts", ts); if (cm == null) { cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); } // TODO: add active/all preferences below UseConn if (prefs.getBoolean("UseConnActive", true)) { NetworkInfo net = cm.getActiveNetworkInfo(); if (net != null) { JSONObject net_data = new JSONObject(); net_data.put("type", net.getTypeName()); net_data.put("subtype", net.getSubtypeName()); net_data.put("connected", net.isConnected()); net_data.put("available", net.isAvailable()); net_data.put("roaming", net.isRoaming()); net_data.put("failover", net.isFailover()); if (net.getReason() != null) net_data.put("reason", net.getReason()); if (net.getExtraInfo() != null) net_data.put("extra", net.getExtraInfo()); json.put("conn_active", net_data); } } if (prefs.getBoolean("UseConnAll", false)) { NetworkInfo[] nets = cm.getAllNetworkInfo(); if (nets != null) { JSONArray net_list = new JSONArray(); for (NetworkInfo net : nets) { JSONObject net_data = new JSONObject(); net_data.put("type", net.getTypeName()); net_data.put("subtype", net.getSubtypeName()); net_data.put("connected", net.isConnected()); net_data.put("available", net.isAvailable()); net_data.put("roaming", net.isRoaming()); net_data.put("failover", net.isFailover()); if (net.getReason() != null) net_data.put("reason", net.getReason()); if (net.getExtraInfo() != null) net_data.put("extra", net.getExtraInfo()); net_list.put(net_data); } json.put("conn_all", net_list); } } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } if (!PingServiceReceiver.completeWakefulIntent(intent)) { Log.w(tag, "completeWakefulIntent() failed. no active wake lock?"); } }
From source file:com.google.android.apps.santatracker.doodles.tilt.SwimmingFragment.java
@Override protected void firstPassLoadOnUiThread() { final FrameLayout.LayoutParams wrapperLP = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);//from ww w . j av a2s. c o m final SwimmingFragment that = this; scoreView = getScoreView(); pauseView = getPauseView(); int diveViewBottomMargin = (int) context.getResources().getDimension(R.dimen.dive_margin_bottom); int diveViewStartMargin = (int) context.getResources().getDimension(R.dimen.dive_margin_left); int diveViewSize = (int) context.getResources().getDimension(R.dimen.dive_image_size); FrameLayout.LayoutParams diveViewLP = new LayoutParams(diveViewSize, diveViewSize); diveViewLP.setMargins(diveViewStartMargin, 0, 0, diveViewBottomMargin); diveViewLP.gravity = Gravity.BOTTOM | Gravity.LEFT; if (VERSION.SDK_INT >= 17) { diveViewLP.setMarginStart(diveViewStartMargin); } diveView = new DiveView(context); countdownView = new TextView(context); countdownView.setGravity(Gravity.CENTER); countdownView.setTextColor(context.getResources().getColor(R.color.ui_text_yellow)); countdownView.setTypeface(Typeface.DEFAULT_BOLD); countdownView.setText("0"); countdownView.setVisibility(View.INVISIBLE); Locale locale = context.getResources().getConfiguration().locale; countdownView.setText(NumberFormat.getInstance(locale).format(3)); Point screenDimens = AndroidUtils.getScreenSize(); UIUtil.fitToBounds(countdownView, screenDimens.x / 10, screenDimens.y / 10); LinearLayout gameView = new LinearLayout(context); gameView.setOrientation(LinearLayout.VERTICAL); // Add game view. swimmingView = new SwimmingView(context); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 7); gameView.addView(swimmingView, lp); if (editorMode) { LinearLayout buttonWrapper = new LinearLayout(context); buttonWrapper.setOrientation(LinearLayout.HORIZONTAL); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1); gameView.addView(buttonWrapper, lp); resetButton = getButton(R.string.reset_level, new OnClickListener() { @Override public void onClick(View v) { SwimmingModel level = levelManager.loadDefaultLevel(); initializeLevel(level, false); getActivity().getSharedPreferences(context.getString(R.string.swimming), Context.MODE_PRIVATE) .edit().putString(CURRENT_LEVEL_KEY, null).commit(); } }); deleteButton = getButton(R.string.delete_levels, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new DeleteLevelDialogFragment(); dialogFragment.show(getActivity().getFragmentManager(), "delete"); } }); loadButton = getButton(R.string.load_level, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new LoadLevelDialogFragment(that); dialogFragment.show(getActivity().getFragmentManager(), "load"); } }); saveButton = getButton(R.string.save_level, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new SaveLevelDialogFragment(that); dialogFragment.show(getActivity().getFragmentManager(), "save"); } }); collisionModeButton = new ToggleButton(context); collisionModeButton.setText(R.string.scenery_mode); collisionModeButton.setTextOff(context.getString(R.string.scenery_mode)); collisionModeButton.setTextOn(context.getString(R.string.collision_mode)); collisionModeButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.collisionMode = isChecked; } }); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1); buttonWrapper.addView(deleteButton, lp); buttonWrapper.addView(resetButton, lp); buttonWrapper.addView(loadButton, lp); buttonWrapper.addView(saveButton, lp); buttonWrapper.addView(collisionModeButton, lp); } sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (accelerometerSensor == null) { // TODO: The game won't be playable without this, so what should we do? Log.d(TAG, "Accelerometer sensor is null"); } displayRotation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay() .getRotation(); wrapper.addView(gameView, 0, wrapperLP); wrapper.addView(countdownView, 1); wrapper.addView(diveView, 2, diveViewLP); wrapper.addView(scoreView, 3); wrapper.addView(pauseView, 4); }
From source file:com.google.android.apps.santatracker.dasherdancer.DasherDancerActivity.java
@Override public void onPause() { super.onPause(); mDetector.stop();/*from www . j a va 2 s . c om*/ SensorManager manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); manager.unregisterListener(this); ; if (mAnimator != null) { mAnimator.cancel(); } FrameAnimationView character = (FrameAnimationView) mPager.findViewWithTag(mPager.getCurrentItem()); if (character != null) { character.setImageDrawable(null); } }
From source file:edu.sfsu.csc780.chathub.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DesignUtils.applyColorfulTheme(this); setContentView(R.layout.activity_main); final Context context = this; soundPreference = this.getString(R.string.play_sounds); mSentSound = MediaPlayer.create(context, R.raw.sentmessage); mStartRecordSound = MediaPlayer.create(context, R.raw.recording_beep); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Set default username is anonymous. mUsername = ANONYMOUS;// w w w .j av a 2s. co m //Initialize Auth mAuth = FirebaseAuth.getInstance(); mUser = mAuth.getCurrentUser(); if (mUser == null) { startActivity(new Intent(this, SignInActivity.class)); finish(); return; } else { mUsername = mUser.getDisplayName(); if (mUser.getPhotoUrl() != null) { mPhotoUrl = mUser.getPhotoUrl().toString(); } } mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API).build(); // Initialize ProgressBar and RecyclerView. mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView); mLinearLayoutManager = new LinearLayoutManager(this); mLinearLayoutManager.setStackFromEnd(true); mMessageRecyclerView.setLayoutManager(mLinearLayoutManager); mFirebaseAdapter = MessageUtil.getFirebaseAdapter(this, this, /* MessageLoadListener */ mLinearLayoutManager, mMessageRecyclerView, mImageClickListener); mMessageRecyclerView.setAdapter(mFirebaseAdapter); mProgressBar.setVisibility(ProgressBar.INVISIBLE); DesignUtils.setBackground(this); mMessageEditText = (EditText) findViewById(R.id.messageEditText); mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(MSG_LENGTH_LIMIT) }); mMessageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (charSequence.toString().trim().length() > 0) { mSendButton.setEnabled(true); } else { mSendButton.setEnabled(false); } } @Override public void afterTextChanged(Editable editable) { } }); mSendButton = (FloatingActionButton) findViewById(R.id.sendButton); mSendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Send messages on click. //mMessageRecyclerView.scrollToPosition(0); ChatMessage chatMessage = new ChatMessage(mMessageEditText.getText().toString(), mUsername, mPhotoUrl); MessageUtil.send(chatMessage); if (mSharedPreferences.getBoolean(soundPreference, true)) { mSentSound.start(); } mMessageEditText.setText(""); } }); mImageButton = (ImageButton) findViewById(R.id.shareImageButton); mImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pickImage(); } }); mLocationButton = (ImageButton) findViewById(R.id.locationButton); mLocationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //mLocationButton.setEnabled(false); featureFlag = 1; loadMap(); } }); mCameraButton = (ImageButton) findViewById(R.id.cameraButton); mCameraButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dispatchTakePhotoIntent(); } }); mVideoButton = (ImageButton) findViewById(R.id.videoButton); mVideoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dispatchRecordVideoIntent(); } }); mVoiceMessageButton = (ImageButton) findViewById(R.id.shareVoiceMessage); mVoiceMessageButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (mSharedPreferences.getBoolean(soundPreference, true)) { mStartRecordSound.start(); } while (mStartRecordSound.isPlaying()) ; startRecording(); break; case MotionEvent.ACTION_UP: stopRecording(); if (mSharedPreferences.getBoolean(soundPreference, true)) { mSentSound.start(); } break; } return false; } }); //Initialize the Accelerometer for Shake function mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); // Use the accelerometer. mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mShakeDetector = new ShakeDetector(); shakePreference = this.getString(R.string.shake_change_background); if (mSharedPreferences.getBoolean(shakePreference, true)) { //Shake to change bg mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI); mShakeDetector.setOnShakeListener(new ShakeDetector.OnShakeListener() { @Override public void onShake(int count) { // if(count > 2) DesignUtils.setRandomBackground(context); } }); } }
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:de.da_sense.moses.client.abstraction.HardwareAbstraction.java
/** * This method reads the sensors currently chosen by the user * @return the actual Hardwareinfo//from w w w . ja v a2 s . co m */ private HardwareInfo retrieveHardwareParameters() { // *** SENDING SET_HARDWARE_PARAMETERS REQUEST TO SERVER ***// LinkedList<Integer> sensors = new LinkedList<Integer>(); SensorManager s = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); for (Sensor sen : s.getSensorList(Sensor.TYPE_ALL)) { sensors.add(sen.getType()); } return new HardwareInfo(extractDeviceIdFromSharedPreferences(), extractDeviceNameFromSharedPreferences(), Build.MANUFACTURER, Build.MODEL, Build.VERSION.SDK_INT, sensors); }