Example usage for android.hardware Sensor TYPE_ALL

List of usage examples for android.hardware Sensor TYPE_ALL

Introduction

In this page you can find the example usage for android.hardware Sensor TYPE_ALL.

Prototype

int TYPE_ALL

To view the source code for android.hardware Sensor TYPE_ALL.

Click Source Link

Document

A constant describing all sensor types.

Usage

From source file:alaindc.crowdroid.SensorsIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (action.equals(Constants.INTENT_START_SENSORS)) {

            // Init throughput taken
            SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putBoolean(Constants.THROUGHPUT_TAKEN, false);
            editor.commit();/*w w w.  java  2  s .  co m*/

            // Configure sensors and eventlistener
            mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
            List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
            for (Sensor sensor : sensorList) {
                if (Constants.isInMonitoredSensors(sensor.getType()))
                    mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
            }

            // TODO STUB: Comment this in release
            for (int type : Constants.STUBBED_MONITORED_SENSORS) {
                stub_onSensorChanged(type);
            }

        }

        if (action.equals(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE)) {
            // Configure amplitude and start TEST
            amplitudeTask = new GetAmplitudeTask(this);
            amplitudeTask.getData();
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_AMBIENT_TEMPERATURE)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_PRESSURE)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_RELATIVE_HUMIDITY)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_RECEIVED_AMPLITUDE)) {
            double amplitude = intent.getDoubleExtra(Constants.EXTRA_AMPLITUDE, -1);

            if (amplitude > 0) {
                SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putString(Constants.PREF_SENSOR_ + Constants.TYPE_AMPLITUDE, Double.toString(amplitude));
                editor.commit();

                // Update view
                Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS);
                senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA,
                        "Sensor " + Constants.getNameOfSensor(Constants.TYPE_AMPLITUDE) + " value: "
                                + Double.toString(amplitude));
                LocalBroadcastManager.getInstance(this).sendBroadcast(senseintent);
            }

            int index = Constants.getIndexAlarmForSensor(Constants.TYPE_AMPLITUDE);

            // Set the alarms for next sensing of amplitude
            alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
            Intent intentAlarm = new Intent(getApplicationContext(), SensorsIntentService.class);
            intentAlarm.setAction(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE);
            alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0);

            // TIMEOUT for another monitoring of audio
            int seconds = 30; // TODO: De-hardcode this
            alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000,
                    alarmIntent);

        }
    }
}

From source file:com.mrchandler.disableprox.ui.SensorSettingsActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sensor_setting_activity_layout);
    SensorManager manager = (SensorManager) getSystemService(SENSOR_SERVICE);
    //getSensorList returns an unmodifiable list
    fullSensorList = new ArrayList<>(manager.getSensorList(Sensor.TYPE_ALL));

    Collections.sort(fullSensorList, new Comparator<Sensor>() {
        @Override/*from   w ww  .ja v a  2 s  . co m*/
        public int compare(Sensor lhs, Sensor rhs) {
            String lhsName = SensorUtil.getHumanStringType(lhs);
            String rhsName = SensorUtil.getHumanStringType(rhs);
            if (lhsName == null) {
                lhsName = lhs.getName();
            }
            if (rhsName == null) {
                rhsName = rhs.getName();
            }
            return lhsName.compareTo(rhsName);
        }
    });

    //Set sorted sensor list for the SensorListFragment
    ((SensorListFragment) getSupportFragmentManager().findFragmentById(R.id.sensor_list_fragment))
            .setSensors(fullSensorList);

    if (findViewById(R.id.drawer_layout) != null) {
        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        toggle = new ActionBarDrawerToggle(this, (DrawerLayout) findViewById(R.id.drawer_layout),
                android.R.string.yes, android.R.string.no);
        drawer.setDrawerListener(toggle);
        drawer.setScrimColor(getResources().getColor(android.R.color.background_dark));

        if (getActionBar() != null) {
            getActionBar().setDisplayHomeAsUpEnabled(true);
            getActionBar().setHomeButtonEnabled(true);
            getActionBar().setDisplayShowHomeEnabled(false);
        }
        toggle.syncState();
    }
    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (currentFragment != null) {
                currentFragment.saveSettings();
            }
        }
    });
    ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scrollView);
    fab.attachToScrollView(scrollView);
    fab.hide(false);

    if (savedInstanceState != null) {
        SensorSettingsFragment fragment = (SensorSettingsFragment) getSupportFragmentManager()
                .getFragment(savedInstanceState, CURRENT_FRAGMENT);
        if (fragment != null) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment_container, fragment, CURRENT_FRAGMENT).commit();
            String sensorTitle = SensorUtil.getHumanStringType(fragment.sensor);
            if (sensorTitle == null) {
                sensorTitle = fragment.sensor.getName();
            }
            setTitle(sensorTitle);
        }
    }

    //Has to be done to access with XSharedPreferences.
    prefs = getSharedPreferences(Constants.PREFS_FILE_NAME, MODE_WORLD_READABLE);

    helper = new IabHelper(this, getString(R.string.google_billing_public_key));
    //Has the user purchased the Pro IAP?
    if (!ProUtil.isPro(this)) {
        helper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            @Override
            public void onIabSetupFinished(IabResult result) {
                if (!result.isSuccess()) {
                    Log.d(TAG, "Unable to get up In-App Billing. Oh well.");
                    ProUtil.setFreeloadStatus(SensorSettingsActivity.this, true);
                    return;
                }
                helper.queryInventoryAsync(new IabHelper.QueryInventoryFinishedListener() {
                    @Override
                    public void onQueryInventoryFinished(IabResult result, Inventory inv) {
                        if (result.isFailure()) {
                            ProUtil.setProStatus(SensorSettingsActivity.this, false);
                            return;
                        }
                        if (inv.hasPurchase(Constants.SKU_TASKER)) {
                            ProUtil.setProStatus(SensorSettingsActivity.this, true);
                        } else {
                            ProUtil.setProStatus(SensorSettingsActivity.this, false);
                        }
                    }
                });
            }
        });
    }
}

From source file:com.flat20.fingerplay.FingerPlayActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    // Init needs to be done first!
    mSettingsModel = SettingsModel.getInstance();
    mSettingsModel.init(this);

    mMidiControllerManager = MidiControllerManager.getInstance();

    super.onCreate(savedInstanceState);

    Runtime r = Runtime.getRuntime();
    r.gc();//  w  ww .  j a  v a 2s .com

    Toast info = Toast.makeText(this, "Go to http://goddchen.github.io/Fingerplay-Midi/ for help.",
            Toast.LENGTH_LONG);
    info.show();

    // Sensor code
    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    sensors = new ArrayList<Sensor>(sensorManager.getSensorList(Sensor.TYPE_ALL));
    startSensors();

    // Simple splash animation

    Splash navSplash = new Splash(mNavigationOverlay, 64, 30, mWidth, mNavigationOverlay.x);
    mNavigationOverlay.x = mWidth;
    AnimationManager.getInstance().add(navSplash);

    Splash mwcSplash = new Splash(mMidiWidgetsContainer, 64, 40, -mWidth, mMidiWidgetsContainer.x);
    mMidiWidgetsContainer.x = -mWidth;
    AnimationManager.getInstance().add(mwcSplash);

    if (BuildConfig.DEBUG) {
        if (TextUtils.isEmpty(PreferenceManager.getDefaultSharedPreferences(this)
                .getString("settings_server_address", null))) {
            Toast.makeText(this, R.string.toast_server_not_setup, Toast.LENGTH_SHORT).show();
            startActivity(new Intent(getApplicationContext(), SettingsView.class));
        }
    } else {
        boolean result = bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
                mBillingServiceConnection, Context.BIND_AUTO_CREATE);
        if (!result) {
            unableToVerifyLicense(getString(R.string.billing_error_init), false);
        }
    }
}

From source file:com.example.android.wearable.runtimepermissions.IncomingRequestWearService.java

private void respondWithSensorInformation() {
    Log.d(TAG, "respondWithSensorInformation()");

    boolean sensorPermissionApproved = ActivityCompat.checkSelfPermission(this,
            Manifest.permission.BODY_SENSORS) == PackageManager.PERMISSION_GRANTED;

    if (!sensorPermissionApproved) {
        DataMap dataMap = new DataMap();
        dataMap.putInt(Constants.KEY_COMM_TYPE, Constants.COMM_TYPE_RESPONSE_PERMISSION_REQUIRED);
        sendMessage(dataMap);/*from   w ww  .j a v  a  2s  .  co m*/
    } else {
        /* To keep the sample simple, we are only displaying the number of sensors. You could do
         * something much more complicated.
         */
        SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
        int numberOfSensorsOnDevice = sensorList.size();

        String sensorSummary = numberOfSensorsOnDevice + " sensors on wear device(s)!";
        DataMap dataMap = new DataMap();
        dataMap.putInt(Constants.KEY_COMM_TYPE, Constants.COMM_TYPE_RESPONSE_DATA);
        dataMap.putString(Constants.KEY_PAYLOAD, sensorSummary);
        sendMessage(dataMap);
    }
}

From source file:de.da_sense.moses.client.abstraction.HardwareAbstraction.java

/**
 * Get all available sensors from the operating system.
 * //from   www. j av  a 2s .  c  o  m
 * @return All available sensors on this device
 */
public static List<Sensor> getSensors() {
    if (MosesService.getInstance() != null) {
        List<Sensor> sensors = new ArrayList<Sensor>();
        SensorManager s = (SensorManager) MosesService.getInstance().getSystemService(Context.SENSOR_SERVICE);
        for (Sensor sen : s.getSensorList(Sensor.TYPE_ALL))
            sensors.add(sen);
        return sensors;
    } else {
        return null;
    }
}

From source file:com.example.android.networkconnect.BureauFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Before initializing the textView, check if any arguments were provided via setArguments.

    mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    // List of Sensors Available
    List<Sensor> msensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);

    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mMagneticField = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    //mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
    //mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    //mLinearAcceleration = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
    //mRotationVector = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
    //mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);

    // float m_result[]=mSensorManager.getOrientation(m_rotationMatrix,m_orientation);

    //Log.i(TAG,"azimuth: "+m_result[0]);
    //Log.i(TAG,"pith: "+m_result[1]);
    //Log.i(TAG,"roll_angle: "+m_result[2]);

    //mMagneticField = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    //mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    //mPressure = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
    //mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);

    for (int k = 0; k < msensorList.size(); k++) {
        Log.i(TAG, "Sensor: " + msensorList.get(k).getName());
    }// w  w  w .  j  a  va  2s .c om
    //Log.i (TAG, "Sensor CreateView String: "+mOrientation.getStringType());
    //Log.i (TAG, "azimuth_angle: "+event.values[0]);
    //Log.i (TAG, "pitch_angle: "+event.values[1]);
    //Log.i (TAG, "roll_angle: "+event.values[2])

    processArguments();
    fa = super.getActivity();

    View layout = inflater.inflate(R.layout.bureaulayout, container, false);

    // final ImageButton mImageButton= (ImageButton) layout.findViewById(R.id.lauchscan);

    //   mImageButton.setOnClickListener(new View.OnClickListener() {
    // @Override
    //   public void onClick(View v) {
    //         Toast toast3 = Toast.makeText(getActivity(), "click", Toast.LENGTH_LONG);
    //           toast3.show();
    //SimpleTextFragment bureauFragment = (SimpleTextFragment) getFragmentManager().findFragmentById(R.id.bureau_fragment);
    // this.showFragment();
    //   }
    //   });

    if (mText != null) {
        mTextView.setText(mText);
        Log.i("SimpleTextFragment", mText);
    }
    //return inflater.inflate(R.layout.bureaulayout,container,false);
    //return mDrawableView;
    return layout;
}

From source file:com.configurer.easyscreenlock.service.ForegroundSensorService.java

public void showAvailableSensors() {
    try {/* ww  w.j  a  v a 2  s . c o  m*/

        List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_ALL);
        if (list != null) {
            Log.i(TAG, list.size() + " Available Sensors");

            for (Sensor s : list) {
                Log.i(TAG, "Name : " + s.getName() + ", Type : " + s.getType());
            }
            System.out.println("-done-");
        } else {
            Log.w(TAG, "You have no sensors");
        }

    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
}

From source file:com.fallahpoor.infocenter.fragments.SensorsFragment.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public ArrayList<String> getSubItemsArrayList() {

    HashMap<Integer, String> sensorsHashMap = new HashMap<>();
    ArrayList<String> subItems = new ArrayList<>();
    Iterator<Integer> iterator;
    String supported = getString(R.string.supported);
    String unsupported = getString(R.string.unsupported);
    ArrayList<Integer> sensorTypes = new ArrayList<>(Arrays.asList(new Integer[] { Sensor.TYPE_ACCELEROMETER,
            Sensor.TYPE_AMBIENT_TEMPERATURE, Sensor.TYPE_GRAVITY, Sensor.TYPE_GYROSCOPE, Sensor.TYPE_LIGHT,
            Sensor.TYPE_LINEAR_ACCELERATION, Sensor.TYPE_MAGNETIC_FIELD, Sensor.TYPE_PRESSURE,
            Sensor.TYPE_PROXIMITY, Sensor.TYPE_RELATIVE_HUMIDITY, Sensor.TYPE_ROTATION_VECTOR }));

    if (mIsApiAtLeast18) {
        sensorTypes.add(Sensor.TYPE_GAME_ROTATION_VECTOR);
        sensorTypes.add(Sensor.TYPE_SIGNIFICANT_MOTION);
    }/*from   w ww .  j  a v a  2  s.c o m*/

    if (mIsApiAtLeast19) {
        sensorTypes.add(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR);
        sensorTypes.add(Sensor.TYPE_STEP_COUNTER);
        sensorTypes.add(Sensor.TYPE_STEP_DETECTOR);
    }

    SensorManager sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    // Get the list of all available sensors of the device
    List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);

    iterator = sensorTypes.iterator();

    // Assume all sensor types are unsupported
    while (iterator.hasNext()) {
        sensorsHashMap.put(iterator.next(), unsupported);
    }

    /*
     * For each sensor type that is in sensors change its status from
     * "unsupported" to "supported".
     */
    for (Sensor sensor : sensors) {
        sensorsHashMap.put(sensor.getType(), supported);
    }

    iterator = sensorTypes.iterator();

    while (iterator.hasNext()) {
        subItems.add(sensorsHashMap.get(iterator.next()));
    }

    return subItems;

}

From source file:it.durip_app.SensorPlot.java

/** Called when the activity is first created. */
@Override//from   w w w . j a  v a2s. c  o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sensors);
    managerSensor = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
    textCharge = (TextView) findViewById(R.id.textvalueConsumption);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    actionBar.setHomeButtonEnabled(true);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    managerSensor = (SensorManager) this.getSystemService(SENSOR_SERVICE);
    List<Sensor> list = managerSensor.getSensorList(Sensor.TYPE_ALL);
    for (Sensor sensor : list) {
        System.out.println("NAME " + sensor.getName());
    }

    // For each of the sections in the app, add a tab to the action bar.
    for (int ii = 1; ii <= mAppSectionsPagerAdapter.getCount(); ii++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(ii)).setTabListener(this));

    }
    // Show the Up button in the action bar.        

    //        System.out.println("OnCreate \n");

}

From source file:com.example.android.wearable.runtimepermissions.MainWearActivity.java

public void onClickWearBodySensors(View view) {

    if (mWearBodySensorsPermissionApproved) {

        // To keep the sample simple, we are only displaying the number of sensors.
        SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
        int numberOfSensorsOnDevice = sensorList.size();

        logToUi(numberOfSensorsOnDevice + " sensors on device(s)!");

    } else {/*from  w  ww .ja v a 2s.c  o m*/
        logToUi("Requested local permission.");
        // On 23+ (M+) devices, GPS permission not granted. Request permission.
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.BODY_SENSORS },
                PERMISSION_REQUEST_READ_BODY_SENSORS);
    }
}