Example usage for android.content Context SENSOR_SERVICE

List of usage examples for android.content Context SENSOR_SERVICE

Introduction

In this page you can find the example usage for android.content Context SENSOR_SERVICE.

Prototype

String SENSOR_SERVICE

To view the source code for android.content Context SENSOR_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.hardware.SensorManager for accessing sensors.

Usage

From source file:com.acrr.acdisplay.services.activemode.ActiveModeService.java

public static boolean isSupported(@NonNull Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    return sensorManager.getSensorList(Sensor.TYPE_PROXIMITY).size() > 0;
}

From source file:com.kircherelectronics.accelerationexplorer.activity.NoiseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.layout_noise);

    textViewXAxis = (TextView) findViewById(R.id.value_x_axis);
    textViewYAxis = (TextView) findViewById(R.id.value_y_axis);
    textViewZAxis = (TextView) findViewById(R.id.value_z_axis);

    XYPlot noiseLevelsPlot = (XYPlot) findViewById(R.id.plot_noise);
    noiseLevelsPlot.setTitle("Noise");

    barPlot = new DynamicBarPlot(noiseLevelsPlot, "Sensor Noise", this);

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

    lpf = new LowPassFilterSmoothing();
    meanFilter = new MeanFilterSmoothing();
    medianFilter = new MedianFilterSmoothing();

    initStatistics();// ww w. ja va  2 s.c o m

    handler = new Handler();

    runable = new Runnable() {
        @Override
        public void run() {
            handler.postDelayed(this, 100);

            updateBarPlot();
            updateAccelerationText();
        }
    };
}

From source file:com.nextgis.mobile.forms.CompassFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // reference to vibrator service
    vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);

    // vibrate or not?
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    vibrationOn = prefs.getBoolean("compass_vibration", true);

    if (mCurrentLocation == null) {
        LocationManager locationManager = (LocationManager) getActivity()
                .getSystemService(Context.LOCATION_SERVICE);
        mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (mCurrentLocation == null) {
            mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }//from w ww. j  a  v  a  2s  .c om
    }
    mDeclination = 0;

    if (mCurrentLocation != null) {
        mDeclination = getDeclination(mCurrentLocation, System.currentTimeMillis());
    }

    sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
            SensorManager.SENSOR_DELAY_NORMAL);

    getActivity().registerReceiver(compassBroadcastReceiver, new IntentFilter(ACTION_COMPASS_UPDATES));

    Log.d(TAG, "CompassActivity: onCreate");
}

From source file:fr.bde_eseo.eseomega.GantierActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    view = new GPGameSurfaceView(this);
    setContentView(view);/*from ww w. java  2  s. c o m*/

    gyroOrientation[0] = 0.0f;
    gyroOrientation[1] = 0.0f;
    gyroOrientation[2] = 0.0f;

    // initialise gyroMatrix with identity matrix
    gyroMatrix[0] = 1.0f;
    gyroMatrix[1] = 0.0f;
    gyroMatrix[2] = 0.0f;
    gyroMatrix[3] = 0.0f;
    gyroMatrix[4] = 1.0f;
    gyroMatrix[5] = 0.0f;
    gyroMatrix[6] = 0.0f;
    gyroMatrix[7] = 0.0f;
    gyroMatrix[8] = 1.0f;

    senSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    profile = new UserProfile();
    profile.readProfilePromPrefs(this);

    // Create media player only if not playing
    if (mediaPlayer == null)
        mediaPlayer = new MediaPlayer();
}

From source file:com.allthingsgeek.celljoust.MainActivity.java

/** Called when the activity is first created. */
@Override/*from   w  w  w. jav a2  s  .  c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ServoOn");
    // wl.acquire();
    // wl.release();

    wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();

    noise = PulseGenerator.getInstance();
    mover = Movement.getInstance();

    loadPrefs();

    mTorchMode = false;

    out = new ByteArrayOutputStream();

    setContentView(R.layout.main);

    if (sensorManager == null) {
        sensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);
    }

    startListening();

    mPreview = (SurfaceView) findViewById(R.id.preview);
    mHolder = mPreview.getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    noise.pause();

}

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);
    }//  www.  ja  v  a  2s .  co  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:il.ac.shenkar.todos.view.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // disable the window title
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);/*  w  ww. j a  v a  2 s.c  om*/

    taskListModel = TaskList.getSingletonObject(this);
    mediaPlayer = new MediaPlayerHandler(this);
    shakeGestures = true;

    expandableListView = (ExpandableListView) findViewById(R.id.listV_main);
    adapter = new ItemListBaseAdapter(this);
    // set our custom adapter for the listView
    expandableListView.setAdapter(adapter);

    titleTextField = (EditText) findViewById(R.id.edit_message);
    Button addButton = (Button) findViewById(R.id.btnAdd);
    addButton.setOnClickListener(this);
    mainLayout = (RelativeLayout) findViewById(R.id.layout_main);
    mainLayout.setOnTouchListener(this);
    viewContainer = findViewById(R.id.undobar);
    myInstance = GoogleAnalytics.getInstance(getApplicationContext());
    taskToUndo = new Task();
    noTasksImage = (ImageView) findViewById(R.id.no_tasks_image);
    noTasksImage.setVisibility(View.GONE);
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mSensorListener = new ShakeEventListener();

    // Placeholder tracking ID.
    myTracker = myInstance.getTracker(Utils.GOOGLE_ANALYTICS_CODE);
    // Set newTracker as the default tracker globally.
    myInstance.setDefaultTracker(myTracker);
    // prints actions to the logcat
    myInstance.setDebug(true);
    taskListModel.getDataBase().open();

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
            new IntentFilter("dataSetChanged"));

    mSensorListener.setOnShakeListener(new ShakeEventListener.OnShakeListener() {
        public void onShake() {
            if (shakeGestures == true) {
                shakeGestures = false;
                alertDialog = new AlertDialogs();
                alertDialog.setArguments(
                        getArguments(Utils.DIALOG_YES_NO_MESSAGE, currentPosition, Utils.DELETE_ALL_ALERT));
                alertDialog.show(getFragmentManager(), "ShowAlertDialog");
                adapter.notifyDataSetChanged();
            }
        }
    });
    // Create a ListView-specific touch listener.
    SwipeListViewTouchListener touchListener = new SwipeListViewTouchListener(expandableListView,
            new SwipeListViewTouchListener.OnSwipeCallback() {
                // when the user swipes a list view item
                @Override
                public void onSwipeLeft(ListView listView, int[] reverseSortedPositions) {
                    // Intentionally empty
                }

                @Override
                public void onSwipeRight(ListView listView, int[] reverseSortedPositions) {
                    for (int position : reverseSortedPositions) {
                        try {
                            taskToUndo = taskListModel.getTaskAt(position);
                            taskListModel.removeTask(position);
                            taskAlarms.disableTaskAlerts(taskToUndo);
                            mediaPlayer.playAudio(Utils.DELETE_SOUND);
                            adapter.notifyDataSetChanged();
                            showUndo(viewContainer);
                        } catch (IndexOutOfBoundsException e) {
                            // intentionally empty
                        }
                    }
                }
            });

    expandableListView.setOnTouchListener(touchListener);
    // Setting this scroll listener is required to ensure that during ListView scrolling,
    // we don't look for swipes.
    expandableListView.setOnScrollListener(touchListener.makeScrollListener());
    registerForContextMenu(expandableListView);
    // retrieve all the application data stored in the data base 
    taskListModel.retrieveData();
    // add software menu button support
    Utils.addLegacyOverflowButton(this.getWindow());
    // show/hide no tasks image
    Utils.checkAlertImageTrigger(taskListModel.getTasks().size());
    // check for first activation of the application
    if (isFirstActivation()) {
        startActivity(new Intent(this, HelpScreenActivity.class));
        savePreferences(Utils.LANGUAGE, true);
        savePreferences(Utils.LOUD_SOUND, true);
    }
    // set application language 
    Utils.ENGLISH_LANGUAGE = loadPreferences(Utils.LANGUAGE);
    Utils.IS_DEFAULT_SOUND = loadPreferences(Utils.LOUD_SOUND);

    if (Utils.ENGLISH_LANGUAGE == false) {
        titleTextField.setHint(Utils.HEBREW_TITLE_ENTER);
    }
}

From source file:com.example.administrator.myapplication2._5_Group._5_Group.RightFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout._5_community_right, container, false);
    switchBtn = (Switch) rootView.findViewById(R.id.switchBtn);

    SharedPreferences myPrefs = this.getActivity().getSharedPreferences("switch", Context.MODE_PRIVATE);
    if ((myPrefs != null) && (myPrefs.contains("switch"))) {
        switchbool = myPrefs.getBoolean("switch", false);
    }/*from   w w w.  j a va2  s.c  o  m*/

    switchBtn.setChecked(switchbool);
    listItem = new ArrayList<HashMap<String, String>>();

    switchBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences myPrefs = getActivity().getSharedPreferences("switch", Context.MODE_PRIVATE);
            SharedPreferences.Editor myEditor = myPrefs.edit();
            if (isChecked == true) {
                /*switch  ?*/
                myEditor.putBoolean("switch", true);
                myEditor.commit();
                /*??*/
            } else if (isChecked == false) {
                setGpsNull();
                myEditor.putBoolean("switch", false);
                myEditor.commit();
            }
        }

    });

    SharedPreferences myPrefs2 = this.getActivity().getSharedPreferences("login", Context.MODE_PRIVATE);
    if ((myPrefs2 != null) && (myPrefs2.contains("id"))) {
        id = myPrefs2.getString("id", "");
        name = myPrefs2.getString("name", "");
    }

    getGroupName();

    // ? ? 
    map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map2)).getMap();
    map.setMyLocationEnabled(true);
    map.setOnMarkerClickListener(onMarkerClickedListener); // ? 
    /*gps*/
    //  ? ?  -   
    mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    if (switchbool == true) {
        //  ?   
        startLocationService();
    }

    return rootView;
}

From source file:com.stillnojetpacks.huffr.activities.MainActivity.java

@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
    Log.i(TAG, "SOUNDPOOL LOAD COMPLETE for sampleId:" + sampleId);

    loaded.put(sampleId, Boolean.TRUE);

    if (allSoundsLoaded()) {

        Log.i(TAG, "ALL SOUNDS LOADED! registering sensorManager");
        sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

        Sensor accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        if (accelerometer == null) {
            Log.i(TAG, "accelerometer is null");
        } else {//from w w w. j  a  v  a2  s  .  c  o m
            sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
        }

        sprayButton.setEnabled(true);
        capOff();
    }
}

From source file:com.pseudosurface.levels.template.SimulatorActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create a GLSurfaceView instance and set it
    // as the ContentView for this Activity
    //        mGLView.setPreserveEGLContextOnPause(false);

    this.victoryCallback = new VictoryInterface() {

        @Override/*  ww  w  . ja va  2  s  .c om*/
        public void victoryCallback(int stars, long time) {
            // TODO Auto-generated method stub
            int level = getIntent().getExtras().getInt("level");
            LevelCompletionFragment.showLevelCompletionFragment(level, stars, time, SimulatorActivity.this);
        }
    };

    /////////////////////

    mGLView = new MyGLSurfaceView(this, this);
    setContentView(mGLView);

    /////////////////////

    //        RelativeLayout rLayout = new RelativeLayout(this);
    //        LayoutParams rlParams = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT); 
    //        rLayout.setLayoutParams(rlParams);
    //
    //        RelativeLayout.LayoutParams tParams = new RelativeLayout.LayoutParams
    //                (LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    //        tParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    //        tParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    //        TextView text=new TextView(this); 
    //        text.setText("GOLDEN Gate"); 
    //        text.setTextColor(Color.WHITE);                            
    //        text.setTypeface(Typeface.DEFAULT_BOLD);
    //        text.setLayoutParams(tParams);
    //
    //        mGLView = new MyGLSurfaceView(this, this);
    //        rLayout.addView(mGLView);
    //        rLayout.addView(text);
    //        setContentView(rLayout);

    /////////////////////

    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    gravitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}