Skip to content
This repository was archived by the owner on Apr 10, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.TextView;

import java.util.List;
import static com.symbol.kitchensinksample.R.id.listViewSensor;

public class SensorActivity extends Activity implements SensorEventListener
{
Expand All @@ -30,23 +32,21 @@ public class SensorActivity extends Activity implements SensorEventListener
private Sensor sensor_proximity;
private Sensor sensor_temperature;
private Sensor sensor_pressure;
private TextView txtAzmiuth;
private TextView txtRoll;
private TextView txtPitch;
private TextView txtProximity;
private TextView txtPressure;
private TextView txtTemperature;
private ListView listSensorInfo;
private final int UI_AZIMUTH = 0;
private final int UI_ROLL = 1;
private final int UI_PITCH = 2;
private final int UI_PROXIMITY = 3;
private final int UI_PRESSURE = 4;
private final int UI_TEMP = 5;
private final int UI_SENSOR_LIST = 6;
private InfoList info_list[];
private KeyValueViewAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sensor);
txtAzmiuth = (TextView)findViewById(R.id.valueAzimith);
txtRoll = (TextView)findViewById(R.id.valueRoll);
txtPitch = (TextView)findViewById(R.id.valuePitch);
txtProximity = (TextView)findViewById(R.id.valueProximity);
txtPressure = (TextView)findViewById(R.id.valuePressure);
txtTemperature = (TextView)findViewById(R.id.valueTemperature);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
maximumProximitySensorRange = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY).getMaximumRange();
sensor_accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
Expand All @@ -69,25 +69,31 @@ protected void onCreate(Bundle savedInstanceState) {

// Find available sensors
List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
TextView txtAvailableSensors = (TextView)findViewById(R.id.valueSensors);
String szAvailableSensors = "";
info_list = new InfoList[UI_SENSOR_LIST + sensorList.size() + 1];
info_list[UI_AZIMUTH] = new InfoList(getString(R.string.sensor_azimuth), "Not Supported");
info_list[UI_ROLL] = new InfoList(getString(R.string.sensor_roll), "Not Supported");
info_list[UI_PITCH] = new InfoList(getString(R.string.sensor_pitch), "Not Supported");
info_list[UI_PROXIMITY] = new InfoList(getString(R.string.sensor_proximity), "Not Supported");
info_list[UI_PRESSURE] = new InfoList(getString(R.string.sensor_pressure), "Not Supported");
info_list[UI_TEMP] = new InfoList(getString(R.string.sensor_temperature), "Not Supported");
info_list[UI_SENSOR_LIST] = new InfoList(getString(R.string.sensor_list), "");
for (int i = 0; i < sensorList.size(); i++)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
String sensorName = sensorList.get(i).getStringType() + " (" + sensorList.get(i).getName() + ")";
Log.i(LOG_TAG, "Sensor: " + sensorName);
szAvailableSensors += sensorName;
szAvailableSensors += "\n";
info_list[UI_SENSOR_LIST + 1 + i] = new InfoList(sensorList.get(i).getStringType().replace(".", "\n"), sensorList.get(i).getName());
}
else
{
String sensorName = sensorList.get(i).getName();
Log.i(LOG_TAG, "Sensor: " + sensorName);
szAvailableSensors += sensorName;
szAvailableSensors += "\n";
info_list[UI_SENSOR_LIST + 1 + i] = new InfoList("Sensor: ", sensorList.get(i).getName());
}
}
txtAvailableSensors.setText(szAvailableSensors);
adapter = new KeyValueViewAdapter(this, R.layout.listview_item_key_value, info_list);
listSensorInfo = (ListView) findViewById(listViewSensor);
listSensorInfo.setAdapter(adapter);
}

@Override
Expand All @@ -108,21 +114,24 @@ else if (sensorType == Sensor.TYPE_PROXIMITY) {
float distance = event.values[0];
if (distance >= maximumProximitySensorRange) {
Log.d(LOG_TAG, "Proximity: Far");
txtProximity.setText("Far");
info_list[UI_PROXIMITY].value = "Far";
} else {
Log.d(LOG_TAG, "Proximity: Near");
txtProximity.setText("Near");
info_list[UI_PROXIMITY].value = "Near";
}
adapter.notifyDataSetChanged();
}
else if (sensorType == Sensor.TYPE_AMBIENT_TEMPERATURE) {
float temperature = event.values[0];
Log.d(LOG_TAG, "Temperature (C): " + temperature);
txtTemperature.setText("" + temperature + " C");
info_list[UI_TEMP].value = "" + temperature + " C";
adapter.notifyDataSetChanged();
}
else if (sensorType == Sensor.TYPE_PRESSURE) {
float atmospheric_pressure_milibar = event.values[0];
Log.d(LOG_TAG, "Pressure (hPa): " + atmospheric_pressure_milibar);
txtPressure.setText("" + atmospheric_pressure_milibar + " hPa");
info_list[UI_PRESSURE].value = "" + atmospheric_pressure_milibar + " hPa";
adapter.notifyDataSetChanged();
}

}
Expand All @@ -145,19 +154,19 @@ protected void onResume() {
// readings again.
if (sensor_accelerometer != null)
mSensorManager.registerListener(this, sensor_accelerometer,
SensorManager.SENSOR_DELAY_NORMAL, SensorManager.SENSOR_DELAY_UI);
SensorManager.SENSOR_DELAY_UI);
if (sensor_magnetic_field != null)
mSensorManager.registerListener(this, sensor_magnetic_field,
SensorManager.SENSOR_DELAY_NORMAL, SensorManager.SENSOR_DELAY_UI);
SensorManager.SENSOR_DELAY_UI);
if (sensor_proximity != null)
mSensorManager.registerListener(this, sensor_proximity,
SensorManager.SENSOR_DELAY_NORMAL, SensorManager.SENSOR_DELAY_UI);
SensorManager.SENSOR_DELAY_UI, SensorManager.SENSOR_DELAY_UI);
if (sensor_temperature != null)
mSensorManager.registerListener(this, sensor_temperature,
SensorManager.SENSOR_DELAY_NORMAL, SensorManager.SENSOR_DELAY_UI);
SensorManager.SENSOR_DELAY_UI, SensorManager.SENSOR_DELAY_UI);
if (sensor_pressure != null)
mSensorManager.registerListener(this, sensor_pressure,
SensorManager.SENSOR_DELAY_NORMAL, SensorManager.SENSOR_DELAY_UI);
SensorManager.SENSOR_DELAY_UI, SensorManager.SENSOR_DELAY_UI);
}

@Override
Expand Down Expand Up @@ -185,15 +194,16 @@ public void updateOrientationAngles() {
//Log.d(LOG_TAG, "Orientation Roll (Z) = " + RadiansToDegrees(mOrientationAngles[2]));
if (mCompassSupported)
{
txtAzmiuth.setText("" + RadiansToDegrees(mOrientationAngles[0]));
txtPitch.setText("" + RadiansToDegrees(mOrientationAngles[1]));
txtRoll.setText("" + RadiansToDegrees(mOrientationAngles[2]));
info_list[UI_AZIMUTH].value = "" + RadiansToDegrees(mOrientationAngles[0]);
info_list[UI_PITCH].value = "" + RadiansToDegrees(mOrientationAngles[1]);
info_list[UI_ROLL].value = "" + RadiansToDegrees(mOrientationAngles[2]);
adapter.notifyDataSetChanged();
}
}

private double RadiansToDegrees(float radians)
{
return radians * (180.0f / Math.PI);
return Math.floor((radians * (180.0f / Math.PI)) * 100000) / 100000;
}

private void compassNotSupported() {
Expand Down
152 changes: 4 additions & 148 deletions KitchenSinkSample/app/src/main/res/layout/activity_sensor.xml
Original file line number Diff line number Diff line change
@@ -1,162 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp">
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.symbol.kitchensinksample.SensorActivity">

<TextView
android:id="@+id/lblAzimuth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="Azmiuth: "
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="8dp" />

<TextView
android:id="@+id/lblRoll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Roll: "
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/lblAzimuth"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginStart="8dp" />

<TextView
android:id="@+id/lblPitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pitch: "
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/lblRoll"
android:layout_marginStart="8dp" />

<TextView
android:id="@+id/lblProximity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Proximity: "
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/lblPitch"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginStart="8dp" />

<TextView
android:id="@+id/lblPressure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pressure: "
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/lblProximity"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginStart="8dp" />

<TextView
android:id="@+id/lblSensors"
android:layout_width="wrap_content"
<ListView
android:id="@+id/listViewSensor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="7dp"
android:text="Available sensors: "
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lblTemperature"
android:layout_marginStart="8dp" />

<TextView
android:id="@+id/lblTemperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="Ambient Temperature: "
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lblPressure"
android:layout_marginStart="8dp" />

<TextView
android:id="@+id/valuePressure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Supported on device"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/valueProximity"
app:layout_constraintLeft_toLeftOf="@+id/valueTemperature"
android:layout_marginLeft="0dp" />

<TextView
android:id="@+id/valueSensors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sensor1\nSensor2\nSensor3"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/lblSensors"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginStart="8dp" />

<TextView
android:id="@+id/valueTemperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Supported on device"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/valuePressure"
app:layout_constraintLeft_toRightOf="@+id/lblTemperature"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp" />

<TextView
android:id="@+id/valuePitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Supported on device"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/valueRoll"
app:layout_constraintLeft_toLeftOf="@+id/valueProximity"
android:layout_marginLeft="0dp" />

<TextView
android:id="@+id/valueProximity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Supported on device"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/valuePitch"
app:layout_constraintLeft_toLeftOf="@+id/valuePressure" />
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/valueRoll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Supported on device"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/valueAzimith"
app:layout_constraintLeft_toLeftOf="@+id/valuePitch" />

<TextView
android:id="@+id/valueAzimith"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Not Supported on device"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/valueRoll" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
7 changes: 7 additions & 0 deletions KitchenSinkSample/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@
This application uses DataWedge Profile0(default). Disabling Profile0, the application would not work. </string>
<string name="trigger_press">Press the scan trigger/button to scan the barcode.</string>

<string name="sensor_azimuth">Azimuth</string>
<string name="sensor_roll">Roll</string>
<string name="sensor_pitch">Pitch</string>
<string name="sensor_proximity">Proximity</string>
<string name="sensor_pressure">Pressure</string>
<string name="sensor_temperature">Ambient Temperature</string>
<string name="sensor_list">Sensors</string>

</resources>