Java Code Examples for android.hardware.Sensor#getName()

The following examples show how to use android.hardware.Sensor#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeviceSensor.java    From Sensor-Data-Logger with Apache License 2.0 6 votes vote down vote up
public DeviceSensor(Sensor sensor) {
    name = sensor.getName();
    vendor = sensor.getVendor();
    version = sensor.getVersion();
    type = sensor.getType();
    resolution = sensor.getResolution();
    power = sensor.getPower();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        stringType = sensor.getStringType();
    } else {
        stringType = "SENSOR_TYPE_" + type;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        reportingMode = sensor.getReportingMode();
        isWakeUpSensor = sensor.isWakeUpSensor();
    } else {
        reportingMode = 0;
        isWakeUpSensor = sensor.getName().toLowerCase().contains("wake_up");
    }
}
 
Example 2
Source File: Sensors.java    From batteryhub with Apache License 2.0 6 votes vote down vote up
private static SensorDetails extractSensorDetails(Sensor sensor) {
    SensorDetails details = null;
    if ((details = sensorsMap.get(sensor.getName())) == null) {
        details = new SensorDetails();
        sensorsMap.put(sensor.getName(), details);
    }
    details.codeType = sensor.getType();
    details.fifoMaxEventCount = sensor.getFifoMaxEventCount();
    details.fifoReservedEventCount = sensor.getFifoReservedEventCount();
    getAttributesNewVersion(sensor, details);
    details.isWakeUpSensor = sensor.isWakeUpSensor();
    details.maxDelay = sensor.getMaxDelay();
    details.maximumRange = sensor.getMaximumRange();
    details.minDelay = sensor.getMinDelay();
    details.name = sensor.getName();
    details.power = sensor.getPower();
    details.reportingMode = sensor.getReportingMode();
    details.resolution = sensor.getResolution();
    details.stringType = sensor.getStringType();
    details.vendor = sensor.getVendor();
    details.version = sensor.getVersion();
    return details;
}
 
Example 3
Source File: TaskerSensorSettingsActivity.java    From Sensor-Disabler with MIT License 6 votes vote down vote up
@Override
public void onSensorClicked(Sensor sensor) {
    TaskerSensorSettingsFragment fragment = TaskerSensorSettingsFragment.newInstance(sensor);
    getSupportFragmentManager().beginTransaction()
            .replace(R.id.fragment_container, fragment, CURRENT_FRAGMENT)
            .commit();
    String sensorTitle = SensorUtil.getHumanStringType(sensor);
    if (sensorTitle == null) {
        sensorTitle = sensor.getName();
    }
    setTitle(sensorTitle);
    currentFragment = fragment;
    if (drawer != null) {
        drawer.closeDrawer(GravityCompat.START);
    }
    if (currentFragment == null) {
        fab.hide();
    } else {
        fab.show();
    }
}
 
Example 4
Source File: SensorSettingsActivity.java    From Sensor-Disabler with MIT License 6 votes vote down vote up
@Override
public void onSensorClicked(Sensor sensor) {
    SensorSettingsFragment fragment = SensorSettingsFragment.newInstance(sensor);
    getSupportFragmentManager().beginTransaction()
            .replace(R.id.fragment_container, fragment, CURRENT_FRAGMENT)
            .commit();
    String sensorTitle = SensorUtil.getHumanStringType(sensor);
    if (sensorTitle == null) {
        sensorTitle = sensor.getName();
    }
    setTitle(sensorTitle);
    currentFragment = fragment;
    if (drawer != null) {
        drawer.closeDrawer(GravityCompat.START);
    }
    if (currentFragment == null) {
        fab.hide();
    } else {
        fab.show();
    }
}
 
Example 5
Source File: SensorDataManager.java    From Sensor-Data-Logger with Apache License 2.0 5 votes vote down vote up
private DataBatch createDataBatch(int sensorType) {
    Sensor sensor = sensorManager.getDefaultSensor(sensorType);
    if (sensor == null) {
        return null;
    }
    String sensorName = sensor.getName();
    DataBatch dataBatch = new DataBatch(sensorName);
    dataBatch.setType(sensorType);
    return dataBatch;
}
 
Example 6
Source File: SensorUtil.java    From Sensor-Disabler with MIT License 5 votes vote down vote up
public static String generateUniqueSensorKey(Sensor sensor) {
    //TODO Maybe use Sensor.toString?
    return sensor.getName()
            + SENSOR_SEPARATOR
            + sensor.getVendor()
            + SENSOR_SEPARATOR
            + sensor.getVersion()
            + SENSOR_SEPARATOR
            + sensor.getType();
}
 
Example 7
Source File: AllNativeSensorProvider.java    From science-journal with Apache License 2.0 4 votes vote down vote up
private List<AdvertisedSensor> buildSensors() {
  List<AdvertisedSensor> sensors = new ArrayList<>();
  final List<Sensor> deviceSensors = getSensorManager().getSensorList(Sensor.TYPE_ALL);
  for (final Sensor sensor : deviceSensors) {
    final SensorAppearanceResources appearance = new SensorAppearanceResources();
    String name = sensor.getName();

    final SensorBehavior behavior = new SensorBehavior();
    behavior.loggingId = name;
    behavior.settingsIntent =
        DeviceSettingsPopupActivity.getPendingIntent(AllNativeSensorProvider.this, sensor);

    final int sensorType = sensor.getType();
    if (sensorType == Sensor.TYPE_ACCELEROMETER) {
      appearance.iconId = android.R.drawable.ic_media_ff;
      appearance.units = "ms/2";
      appearance.shortDescription = "Not really a 3-axis accelerometer";
      behavior.shouldShowSettingsOnConnect = true;
    }

    if (isTemperature(sensorType)) {
      appearance.iconId = android.R.drawable.star_on;
      String unitString =
          TemperatureSettingsPopupActivity.getUnitString(AllNativeSensorProvider.this);
      appearance.units = unitString;
      appearance.shortDescription = "Ambient temperature (settings to change units!)";
      behavior.settingsIntent =
          TemperatureSettingsPopupActivity.getPendingIntent(AllNativeSensorProvider.this, sensor);
    }

    String sensorAddress = "" + sensorType;
    sensors.add(
        new AdvertisedSensor(sensorAddress, name) {
          private SensorEventListener mSensorEventListener;

          @Override
          protected SensorAppearanceResources getAppearance() {
            return appearance;
          }

          @Override
          protected SensorBehavior getBehavior() {
            return behavior;
          }

          @Override
          protected boolean connect() throws Exception {
            unregister();
            return true;
          }

          @Override
          protected void streamData(final DataConsumer c) {
            final int index =
                DeviceSettingsPopupActivity.getIndexForSensorType(
                    sensorType, AllNativeSensorProvider.this);
            mSensorEventListener = new HardwareEventListener(sensorType, index, c);
            getSensorManager()
                .registerListener(mSensorEventListener, sensor, SensorManager.SENSOR_DELAY_UI);
          }

          @Override
          protected void disconnect() {
            unregister();
          }

          private void unregister() {
            if (mSensorEventListener != null) {
              getSensorManager().unregisterListener(mSensorEventListener);
              mSensorEventListener = null;
            }
          }
        });
  }

  return sensors;
}
 
Example 8
Source File: TaskerSensorSettingsActivity.java    From Sensor-Disabler with MIT License 4 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    BundleScrubber.scrub(getIntent());
    final Bundle localeBundle = getIntent().getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);
    BundleScrubber.scrub(localeBundle);

    if (null == savedInstanceState) {
        if (PluginBundleManager.isBundleValid(localeBundle)) {
            String sensorStatusKey = localeBundle.getString(PluginBundleManager.BUNDLE_EXTRA_SENSOR_STATUS_KEY);
            int sensorStatusValue = localeBundle.getInt(PluginBundleManager.BUNDLE_EXTRA_SENSOR_STATUS_VALUE);
            float[] sensorMockValues = localeBundle.getFloatArray(PluginBundleManager.BUNDLE_EXTRA_SENSOR_MOCK_VALUES_VALUES);
            Sensor sensor = SensorUtil.getSensorFromUniqueSensorKey(this, sensorStatusKey);
            TaskerSensorSettingsFragment fragment = TaskerSensorSettingsFragment.newInstance(sensorStatusKey, sensorStatusValue, sensorMockValues);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment_container, fragment, CURRENT_FRAGMENT)
                    .commit();
            String sensorTitle = SensorUtil.getHumanStringType(sensor);
            if (sensorTitle == null) {
                sensorTitle = sensor.getName();
                //Probably won't really return null but who knows...
                if (sensorTitle == null) {
                    sensorTitle = "Unknown Sensor";
                }
            }
            setTitle(sensorTitle);
            currentFragment = fragment;
            if (drawer != null) {
                drawer.closeDrawer(GravityCompat.START);
            }
            if (currentFragment == null) {
                fab.hide();
            } else {
                fab.show();
            }
        }
    }
    initInAppBilling();
    fab.setImageResource(R.drawable.ic_check_white_24dp);
}