當前位置: 首頁>>代碼示例>>Java>>正文


Java Sensor.getType方法代碼示例

本文整理匯總了Java中android.hardware.Sensor.getType方法的典型用法代碼示例。如果您正苦於以下問題:Java Sensor.getType方法的具體用法?Java Sensor.getType怎麽用?Java Sensor.getType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.hardware.Sensor的用法示例。


在下文中一共展示了Sensor.getType方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import android.hardware.Sensor; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    //assim como em LocationManager a gente pega um tipo de provider (GPS_PROVIDER)
    //com sensores, não há APIs dedicadas para sensores, usamos o SensorManager
    //os sensores são identificados por nomes (TYPE_LINEAR_ACCELERATION)

    //existem sensores e tipos de sensores
    //abaixo, estamos pedindo todos os sensores, de todos os tipos
    List<Sensor> allSensors = new ArrayList<>(sensorManager.getSensorList(Sensor.TYPE_ALL));
    List<Sensor> sensors = new ArrayList<>();

    //removendo trigger sensors, que entregam apenas uma única leitura
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        for (Sensor s : allSensors) {
            boolean triggerSensor = s.getType() == Sensor.TYPE_SIGNIFICANT_MOTION ||
                    s.getType() == Sensor.TYPE_STEP_COUNTER ||
                    s.getType() == Sensor.TYPE_STEP_DETECTOR;

            if (!triggerSensor) {
                sensors.add(s);
            }
        }
    }
    else {
        sensors = allSensors;
    }

    adapter=new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, sensors);
    setListAdapter(adapter);
}
 
開發者ID:if710,項目名稱:2017.2-codigo,代碼行數:35,代碼來源:SensorListActivity.java

示例2: onSensorChanged

import android.hardware.Sensor; //導入方法依賴的package包/類
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    Sensor mySensor = sensorEvent.sensor;

    Log.i(TAG, "onSensorChanged");



    if (mySensor.getType() == Sensor.TYPE_STEP_COUNTER) {
        WritableMap map = Arguments.createMap();

        long curTime = System.currentTimeMillis();
        //i++;
        if ((curTime - lastUpdate) > delay) {
            final Object o = sensorEvent.values[0];
            Log.i("History", "Data point:" + sensorEvent.values[0]);

            map.putDouble("steps", sensorEvent.values[0]);
            sendEvent(this.mReactContext, "StepSensorChangedEvent", map);

            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(mReactContext.getApplicationContext(), "" + o, Toast.LENGTH_SHORT).show();
                }
            });
            lastUpdate = curTime;
        }
    }
}
 
開發者ID:StasDoskalenko,項目名稱:react-native-google-fit,代碼行數:31,代碼來源:StepSensor.java

示例3: onSensorChanged

import android.hardware.Sensor; //導入方法依賴的package包/類
public void onSensorChanged(SensorEvent event) {
    Sensor sensor = event.sensor;
    synchronized (this) {
        if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            calc_step(event);
        }
    }
}
 
開發者ID:SailFlorve,項目名稱:RunHDU,代碼行數:9,代碼來源:StepSensorAcceleration.java

示例4: isXYZ

import android.hardware.Sensor; //導入方法依賴的package包/類
private boolean isXYZ(Sensor s) {
    switch (s.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
        case Sensor.TYPE_GRAVITY:
        case Sensor.TYPE_GYROSCOPE:
        case Sensor.TYPE_LINEAR_ACCELERATION:
        case Sensor.TYPE_MAGNETIC_FIELD:
        case Sensor.TYPE_ROTATION_VECTOR:
            return true;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (s.getType() == Sensor.TYPE_GAME_ROTATION_VECTOR
                || s.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED
                || s.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
            return true;
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (s.getType() == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR) {
            return true;
        }
    }

    return false;
}
 
開發者ID:if710,項目名稱:2017.2-codigo,代碼行數:28,代碼來源:SensorListActivity.java

示例5: onAccuracyChanged

import android.hardware.Sensor; //導入方法依賴的package包/類
/**
 * Used to handle change of accuracy from the sensors. We will only check pulse accuracy
 * @param sensor
 * @param i
 */
@Override
public void onAccuracyChanged(Sensor sensor, int i) {
    //set the accuracy of the pulse snsors
    if (sensor.getType()==Sensor.TYPE_HEART_RATE)
    {
        accuracySensorPulse=i;
    }
}
 
開發者ID:kflauri2312lffds,項目名稱:Android_watch_magpie,代碼行數:14,代碼來源:HomeActivity.java

示例6: onSensorChanged

import android.hardware.Sensor; //導入方法依賴的package包/類
@Override
public void onSensorChanged(SensorEvent event) {
    Sensor evtSensor = event.sensor;

    if(evtSensor.getType()==Sensor.TYPE_ACCELEROMETER)
    {
        double x = event.values[0];
        double y = event.values[1];

        double maxValue = Math.sqrt(x*x+y*y);

        double xDiv = x/maxValue;
        double yDiv = y/maxValue;

        // Calculates new falling angle
        double angle = Math.atan(yDiv/xDiv) + (x < 0 ? Math.PI : 0);

        float accY = accG*(float)Math.sin(angle);
        float accX = -accG*(float)Math.cos(angle);

        // Push new angle data to RS
        if(scriptMain != null) {
            scriptMain.set_accY((float) accY);
            scriptMain.set_accX((float) accX);
        }

    }
}
 
開發者ID:csarron,項目名稱:renderscript_examples,代碼行數:29,代碼來源:MainActivity.java

示例7: onSensorChanged

import android.hardware.Sensor; //導入方法依賴的package包/類
@Override
public void onSensorChanged(SensorEvent event) {
    Sensor mySensor = event.sensor;
    float x = 0;
    float y = 0;
    float z = 0;

    if (mySensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        x = event.values[0];
        y = event.values[1];
        z = event.values[2];
    }


    if ((Math.sqrt(x*x + y*y + z*z) < FREEFALL_THRESHOLD) && !firstTimeAlert){



        if(am.isMicrophoneMute()){
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

                    am.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_UNMUTE, 0);
            }
            else {
                // Note that this must be the same instance of audioManager that mutes
                // http://stackoverflow.com/questions/7908962/setstreammute-never-unmutes?rq=1
                am.setStreamMute(AudioManager.STREAM_ALARM, false);
            }
        }

        mediaPlayer.setLooping(true);
        mediaPlayer.start();
        firstTimeAlert = true;
        mediaPlayerOncePlayed = true;

        this.startService(mLocationSendServiceIntent);
    }
}
 
開發者ID:sommukhopadhyay,項目名稱:nirbhaya,代碼行數:39,代碼來源:PhoneLocatorService.java


注:本文中的android.hardware.Sensor.getType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。