public SimulationView (Context context, SensorManager sensorManager, IWindowManager window) : base (context) { Bounds = new PointF (); // Get an accelorometer sensor sensor_manager = sensorManager; accel_sensor = sensor_manager.GetDefaultSensor (SensorType.Accelerometer); // Calculate screen size and dpi var metrics = new DisplayMetrics (); window.DefaultDisplay.GetMetrics (metrics); meters_to_pixels_x = metrics.Xdpi / 0.0254f; meters_to_pixels_y = metrics.Ydpi / 0.0254f; // Rescale the ball so it's about 0.5 cm on screen var ball = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Ball); var dest_w = (int)(BALL_DIAMETER * meters_to_pixels_x + 0.5f); var dest_h = (int)(BALL_DIAMETER * meters_to_pixels_y + 0.5f); ball_bitmap = Bitmap.CreateScaledBitmap (ball, dest_w, dest_h, true); // Load the wood background texture var opts = new BitmapFactory.Options (); opts.InDither = true; opts.InPreferredConfig = Bitmap.Config.Rgb565; wood_bitmap = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Wood, opts); wood_bitmap2 = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Wood, opts); display = window.DefaultDisplay; particles = new ParticleSystem (this); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); illuminationView = FindViewById <TextView> (Resource.Id.Illumination); historyView = FindViewById <TextView> (Resource.Id.History); manager = (SensorManager)GetSystemService(SensorService); lightSensor = manager.GetDefaultSensor(SensorType.Light); var executeButton = FindViewById <Button> (Resource.Id.Execute); executeButton.Click += (sender, e) => { detectable = !detectable; executeButton.Text = detectable ? "停止" : "開始"; if (detectable) { RegisterLightListener(); } else { UnRegisterLightListener(); } }; var clearButton = FindViewById <Button> (Resource.Id.Clear); clearButton.Click += (sender, e) => historyView.Text = ""; }
public override void Initialize() { base.Initialize(); var viewListener = new ViewListener(this); gameView = Game.Context.Control; gameView.SetOnTouchListener(viewListener); gameView.SetOnKeyListener(viewListener); gameView.Resize += GameViewOnResize; GameViewOnResize(null, EventArgs.Empty); // Get the android sensors sensorManager = (SensorManager)PlatformAndroid.Context.GetSystemService(Context.SensorService); androidAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); androidGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); androidUserAcceleration = sensorManager.GetDefaultSensor(SensorType.LinearAcceleration); androidGravity = sensorManager.GetDefaultSensor(SensorType.Gravity); androidRotationVector = sensorManager.GetDefaultSensor(SensorType.RotationVector); // Determine which sensor is available on the device Accelerometer.IsSupported = androidAccelerometer != null; Compass.IsSupported = androidRotationVector != null; Gyroscope.IsSupported = androidGyroscope != null; UserAcceleration.IsSupported = androidUserAcceleration != null; Gravity.IsSupported = androidGravity != null; Orientation.IsSupported = androidRotationVector != null; }
public void Initialize() { _sensorManager = (SensusServiceHelper.Get() as AndroidSensusServiceHelper).Service.GetSystemService(global::Android.Content.Context.SensorService) as SensorManager; _sensor = _sensorManager.GetDefaultSensor(_sensorType); if (_sensor == null) throw new Exception("No sensors present for sensor type " + _sensorType); }
partial void Start() { this.sensorManager = Application.Context.GetSystemService(Context.SensorService) as SensorManager; this.accelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); this.sensorManager.RegisterListener(this, accelerometer, this.delay); }
partial void Start() { this.sensorManager = Application.Context.GetSystemService(Context.SensorService) as SensorManager; this.gyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); this.sensorManager.RegisterListener(this, this.gyroscope, this.delay); }
public void StartListening() { var sensors = sensorManager.GetSensorList(SensorType.Accelerometer); if (sensors.Count > 0) { sensor = sensors[0]; IsListening = sensorManager.RegisterListener(eventListener, sensor, SensorDelay.Game); } }
public void Stop() { if (_accelerometer == null) { throw new MvxException("Accelerometer not started"); } _sensorManager.UnregisterListener(this); _sensorManager = null; _accelerometer = null; }
public static void SetupAccelerometer() { _sensorManger = (SensorManager)Game.Activity.GetSystemService(Context.SensorService); _sensor = _sensorManger.GetDefaultSensor(SensorType.Accelerometer); if (_sensor != null) { _state = new AccelerometerState { IsConnected = true }; } else _state = new AccelerometerState { IsConnected = false }; }
public static void SetupAccelerometer() { _sensorManger = (SensorManager)Game.contextInstance.GetSystemService(Context.SensorService); _sensor = _sensorManger.GetDefaultSensor(SensorType.Accelerometer); if (_sensor != null) { _state = new AccelerometerState { IsConnected = true }; _sensorManger.RegisterListener(new SensorListener(), _sensor, SensorDelay.Game); } else _state = new AccelerometerState { IsConnected = false }; }
public void StartUpdatingHeading () { if (_manager == null) { _manager = (SensorManager) Forms.Context.GetSystemService (Context.SensorService); } if (_compass == null) { _compass = _manager.GetDefaultSensor (SensorType.Orientation); } _manager.RegisterListener (this, _compass, SensorDelay.Normal); }
public SensorReadingTest() { sensorManager = (SensorManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.SensorService); sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField); sensorGravity = sensorManager.GetDefaultSensor(SensorType.Gravity); sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); sensorStatus = new Dictionary<SensorType, bool>() { { SensorType.Accelerometer, false}, { SensorType.MagneticField, false}, { SensorType.Gravity, false}, { SensorType.Gyroscope, false} }; }
/// <summary> /// Initializes a new instance of the DeviceMotionImplementation class. /// </summary> public DeviceMotionImplementation() : base() { sensorManager = (SensorManager)Application.Context.GetSystemService(Context.SensorService); sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField); sensorCompass = sensorManager.GetDefaultSensor(SensorType.Orientation); sensorStatus = new Dictionary<MotionSensorType, bool>(){ { MotionSensorType.Accelerometer, false}, { MotionSensorType.Gyroscope, false}, { MotionSensorType.Magnetometer, false}, { MotionSensorType.Compass,false} }; }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Sensors); trackButton = FindViewById<Button> (Resource.Id.trackButton); stepCount = FindViewById<TextView> (Resource.Id.stepCount); // create a sensor manager to schedule batches of sensor data senMgr = (SensorManager) GetSystemService (SensorService); // update state from orientation change if (bundle != null) { count = bundle.GetFloat ("step_count", 0); if (bundle.GetBoolean ("visible", false)) { visible = true; stepCount.Text = count.ToString (); } Log.Debug(GetType().FullName, "Recovered instance state"); } // This button gets the user's step count since the last time the device was rebooted trackButton.Click += (o, e) => { // get the step counter sensor via the SensorManager counter = senMgr.GetDefaultSensor (SensorType.StepCounter); // button's been clicked, so counter visibility gets set to true visible = true; // This sensor is only available on Nexus 5 and Moto X at time of writing // The following line will check if the sensor is available explicitly: bool counterAvailabe = PackageManager.HasSystemFeature(PackageManager.FeatureSensorStepCounter); Log.Info("SensorManager", "Counter available"); if (counterAvailabe && counter != null) { // Set sensor delay to normal, the default rate for batching sensor data senMgr.RegisterListener(this, counter, SensorDelay.Normal); Toast.MakeText(this,"Count sensor started",ToastLength.Long).Show(); } else { Toast.MakeText(this, "Count sensor unavailable", ToastLength.Long).Show(); } }; }
public Implementation() { sensorManager = (SensorManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.SensorService); sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); sensorGravimeter = sensorManager.GetDefaultSensor(SensorType.Gravity); sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField); sensorOrientation = sensorManager.GetDefaultSensor(SensorType.Orientation); sensorStatus = new Dictionary<DeviceSensorType, bool>() { { DeviceSensorType.Accelerometer, false}, { DeviceSensorType.Gravimeter, false}, { DeviceSensorType.Gyroscope, false}, { DeviceSensorType.Magnetometer, false}, { DeviceSensorType.Orientation, false } }; }
public Implementation() { sensorManager = (SensorManager)Android.App.Application.Context.GetSystemService(Context.SensorService); sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); sensorGravimeter = sensorManager.GetDefaultSensor(SensorType.Gravity); sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope); sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField); sensorOrientation = sensorManager.GetDefaultSensor(SensorType.Orientation); //Instead of using raw data from the orientation sensor, we recommend that you use the getRotationMatrix() method in conjunction with the getOrientation() method to compute orientation values.You can also use the remapCoordinateSystem() method to translate the orientation values to your application's frame of reference. sensorStatus = new Dictionary<DeviceSensorType, bool>() { { DeviceSensorType.Accelerometer, false}, { DeviceSensorType.Gravimeter, false}, { DeviceSensorType.Gyroscope, false}, { DeviceSensorType.Magnetometer, false}, { DeviceSensorType.Orientation, false }, { DeviceSensorType.OrientationRaw, false} }; isOrientationRawActivated = false; }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App()); mSensorManager = GetSystemService(Android.Content.Context.SensorService) as Android.Hardware.SensorManager; mRotationVectorSensor = mSensorManager.GetDefaultSensor(Android.Hardware.SensorType.RotationVector); mGeomagneticRotationVectorSensor = mSensorManager.GetDefaultSensor(SensorType.GeomagneticRotationVector); mAccelerometerSensor = mSensorManager.GetDefaultSensor(SensorType.Accelerometer); mMagneticFieldSensor = mSensorManager.GetDefaultSensor(SensorType.MagneticField); mSensorManager.RegisterListener(this, mRotationVectorSensor, SensorDelay.Normal); mSensorManager.RegisterListener(this, mGeomagneticRotationVectorSensor, SensorDelay.Normal); mSensorManager.RegisterListener(this, mAccelerometerSensor, SensorDelay.Normal); mSensorManager.RegisterListener(this, mMagneticFieldSensor, SensorDelay.Normal); }
public void Start() { if (_accelerometer != null) { throw new MvxException("Accelerometer already started"); } var globals = Mvx.Resolve<IMvxAndroidGlobals>(); _sensorManager = (SensorManager) globals.ApplicationContext.GetSystemService(Context.SensorService); if (_sensorManager == null) throw new MvxException("Failed to find SensorManager"); _accelerometer = _sensorManager.GetDefaultSensor(SensorType.Accelerometer); if (_accelerometer == null) throw new MvxException("Failed to find Accelerometer"); // It is not necessary to get accelerometer events at a very high // rate, by using a slower rate (SENSOR_DELAY_UI), we get an // automatic low-pass filter, which "extracts" the gravity component // of the acceleration. As an added benefit, we use less power and // CPU resources. _sensorManager.RegisterListener(this, _accelerometer, SensorDelay.Ui); }
public void OnAccuracyChanged(Sensor sensor, int accuracy) { // Do nothing }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.AccelerometerMain); //Normal Accelerometer (Pure Hardware) accelStatus = (TextView)FindViewById(Resource.Id.accelStatus); accelStrength = (TextView)FindViewById(Resource.Id.accelStrength); accelX = (TextView)FindViewById(Resource.Id.accelX); accelY = (TextView)FindViewById(Resource.Id.accelY); accelZ = (TextView)FindViewById(Resource.Id.accelZ); //Linear Accelerometer (Software Adjusted) linearStatus = (TextView)FindViewById(Resource.Id.linearStatus); linearStrength = (TextView)FindViewById(Resource.Id.linearStrength); linearX = (TextView)FindViewById(Resource.Id.linearX); linearY = (TextView)FindViewById(Resource.Id.linearY); linearZ = (TextView)FindViewById(Resource.Id.linearZ); //GPS gpsStatus = (TextView)FindViewById(Resource.Id.gpsStatus); gpsProvider = (TextView)FindViewById(Resource.Id.gpsProvider); gpsLatitude = (TextView)FindViewById(Resource.Id.gpsLatitude); gpsLongitude = (TextView)FindViewById(Resource.Id.gpsLongitude); gpsSpeed = (TextView)FindViewById(Resource.Id.gpsSpeed); InitalizeLocationManager(); //List<Sensor> deviceSensors = new List<Sensor>(mSensorManager.GetSensorList(SensorType.All)); //Sensor Initializations mSensorManager = (SensorManager)GetSystemService(Context.SensorService); if(mSensorManager.GetDefaultSensor(SensorType.Accelerometer) != null) { accelStatus.Text = "EXISTS"; mSensor = mSensorManager.GetDefaultSensor(SensorType.Accelerometer); } else { accelStatus.Text = "NOT AVAILABLE"; } if (mSensorManager.GetDefaultSensor(SensorType.LinearAcceleration) != null) { linearStatus.Text = "EXISTS"; mLinearSensor = mSensorManager.GetDefaultSensor(SensorType.LinearAcceleration); } else { linearStatus.Text = "NOT AVAILABLE"; } }
public void OnAccuracyChanged(Sensor Sensor, SensorStatus accuracy) { accelStrength = (TextView)FindViewById(Resource.Id.accelStrength); //Correlate to ENUMS later... for now just display strong... }
public void OnAccuracyChanged(Sensor sensor, SensorStatus accuracy) { // ignored }
public void OnAccuracyChanged(Sensor sensor, int accuracy) { // TODO Auto-generated method stub }
public AndroidSensorListener(SensorType sensorType) { sensorManager = (SensorManager)PlatformAndroid.Context.GetSystemService(Context.SensorService); sensor = sensorManager.GetDefaultSensor(sensorType); }
public void OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy) { }
public void OnAccuracyChanged(Sensor sensor, int int32) { }
public void OnAccuracyChanged(Sensor sensor, SensorStatus accuracy) { // We don't want to do anything here. }
public void OnAccuracyChanged(Android.Hardware.Sensor sensor, Android.Hardware.SensorStatus accuracy) { }
public SimulationView(AccelerometerPlayActivity context) : base(context) { activity = context; mParticleSystem = new ParticleSystem(this); mAccelerometer = activity.mSensorManager.GetDefaultSensor(Sensor.TYPE_ACCELEROMETER); var metrics = new DisplayMetrics(); activity.WindowManager.GetDefaultDisplay().GetMetrics(metrics); mXDpi = metrics.Xdpi; mYDpi = metrics.Ydpi; mMetersToPixelsX = mXDpi / 0.0254f; mMetersToPixelsY = mYDpi / 0.0254f; // rescale the ball so it's about 0.5 cm on screen var ball = BitmapFactory.DecodeResource(Resources, R.Drawables.ball); var dstWidth = (int)(sBallDiameter * mMetersToPixelsX + 0.5f); var dstHeight = (int)(sBallDiameter * mMetersToPixelsY + 0.5f); mBitmap = Bitmap.CreateScaledBitmap(ball, dstWidth, dstHeight, true); var opts = new BitmapFactory.Options(); opts.InDither = true; opts.InPreferredConfig = Bitmap.Config.RGB_565; mWood = BitmapFactory.DecodeResource(Resources, R.Drawables.wood, opts); }
public void OnAccuracyChanged(Sensor sensor, SensorStatus status) { }
public LocListener(LocationManager lm, SensorManager sm) : base() { // Get LocationManager locManager = lm; var locationCriteria = new Criteria () { Accuracy = global::Android.Locations.Accuracy.Fine, AltitudeRequired = true, PowerRequirement = Power.Low }; locationProvider = locManager.GetBestProvider(locationCriteria, true); if (locationProvider == null) throw new Exception("No location provider found"); List<String> providers = locManager.GetProviders(true) as List<String>; // Loop over the array backwards, and if you get an accurate location, then break out the loop Location loc = null; if (providers != null) { for (int i = providers.Count - 1; i >= 0; i--) { loc = locManager.GetLastKnownLocation(providers[i]); if (loc != null) break; } } if (loc != null) { lat = loc.Latitude; lon = loc.Longitude; alt = loc.Altitude; accuracy = loc.Accuracy; } sensorManager = sm; accelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer); magnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField); }
/// <summary> /// Starts this instance. /// </summary> partial void Start() { this.sensorManager = Application.Context.GetSystemService(Context.SensorService) as SensorManager; if (this.sensorManager == null) { throw new NotSupportedException("Sensor Manager not supported"); } this.accelerometer = this.sensorManager.GetDefaultSensor(SensorType.Accelerometer); this.sensorManager.RegisterListener(this, this.accelerometer, this.delay); }
public void OnAccuracyChanged(Sensor sensor, int accuracy) { }
/// <summary> /// Stops this instance. /// </summary> partial void Stop() { if (this.sensorManager == null) return; this.sensorManager.UnregisterListener(this); this.sensorManager.Dispose(); this.sensorManager = null; this.accelerometer.Dispose(); this.accelerometer = null; }