Position trigger
This commit is contained in:
parent
81d6ab7b5f
commit
a9bd7b9561
@ -263,6 +263,11 @@ public class ActivityManageRule extends Activity
|
||||
wifiEditor.putExtra("wifiName", selectedTrigger.getTriggerParameter2());
|
||||
startActivityForResult(wifiEditor, requestCodeTriggerWifiEdit);
|
||||
break;
|
||||
case devicePosition:
|
||||
Intent devicePositionEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerDevicePosition.class);
|
||||
devicePositionEditor.putExtra(ActivityManageTriggerDevicePosition.vectorFieldName, selectedTrigger.getTriggerParameter2());
|
||||
startActivityForResult(devicePositionEditor, requestCodeTriggerDevicePositionEdit);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1354,6 +1359,28 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerDevicePositionAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
// newTrigger.setTriggerParameter(data.getBooleanExtra("wifiState", false));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageTriggerDevicePosition.vectorFieldName));
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerDevicePositionEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
Trigger editedTrigger = new Trigger();
|
||||
editedTrigger.setTriggerType(Trigger_Enum.devicePosition);
|
||||
// newTrigger.setTriggerParameter(data.getBooleanExtra("wifiState", false));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageTriggerDevicePosition.vectorFieldName));
|
||||
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Dialog getActionTypeDialog()
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputFilter;
|
||||
import android.text.Spanned;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
@ -17,57 +20,61 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageTriggerDevicePosition extends Activity
|
||||
{
|
||||
TextView currentOrientationX, currentOrientationY, currentOrientationZ, tvAppliesX, tvAppliesY, tvAppliesZ;
|
||||
TextView currentAzimuth, currentPitch, currentRoll, tvAppliesAzimuth, tvAppliesPitch, tvAppliesRoll;
|
||||
Button bApplyPositionValues, bSavePositionValues;
|
||||
EditText etDesiredPositionX, etDesiredPositionXTolerance, etDesiredPositionY, etDesiredPositionYTolerance, etDesiredPositionZ, etDesiredPositionZTolerance;
|
||||
EditText etDesiredAzimuth, etDesiredAzimuthTolerance, etDesiredPitch, etDesiredPitchTolerance, etDesiredRoll, etDesiredRollTolerance;
|
||||
|
||||
float desiredX, desiredY, desiredZ, desiredXTolerance, desiredYTolerance, desiredZTolerance;
|
||||
public static String vectorFieldName = "deviceVector";
|
||||
|
||||
public void updateFields(float x, float y, float z)
|
||||
boolean editMode = false;
|
||||
|
||||
float desiredAzimuth, desiredPitch, desiredRoll, desiredAzimuthTolerance, desiredPitchTolerance, desiredRollTolerance;
|
||||
|
||||
public void updateFields(float azimuth, float pitch, float roll)
|
||||
{
|
||||
currentOrientationX.setText(Float.toString(x));
|
||||
currentOrientationY.setText(Float.toString(y));
|
||||
currentOrientationZ.setText(Float.toString(z));
|
||||
currentAzimuth.setText(Float.toString(azimuth));
|
||||
currentPitch.setText(Float.toString(pitch));
|
||||
currentRoll.setText(Float.toString(roll));
|
||||
|
||||
if(checkInputs())
|
||||
{
|
||||
desiredX = Float.parseFloat(etDesiredPositionX.getText().toString());
|
||||
desiredXTolerance = Float.parseFloat(etDesiredPositionXTolerance.getText().toString());
|
||||
if(x >= desiredX - desiredXTolerance || x <= desiredX + desiredXTolerance)
|
||||
desiredAzimuth = Float.parseFloat(etDesiredAzimuth.getText().toString());
|
||||
desiredAzimuthTolerance = Float.parseFloat(etDesiredAzimuthTolerance.getText().toString());
|
||||
if(Math.abs(azimuth) <= Math.abs(desiredAzimuth - desiredAzimuthTolerance) || Math.abs(azimuth) <= desiredAzimuth + desiredAzimuthTolerance)
|
||||
{
|
||||
tvAppliesX.setText(getResources().getString(R.string.yes));
|
||||
tvAppliesX.setTextColor(Color.GREEN);
|
||||
tvAppliesAzimuth.setText(getResources().getString(R.string.yes));
|
||||
tvAppliesAzimuth.setTextColor(Color.GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
tvAppliesX.setText(getResources().getString(R.string.no));
|
||||
tvAppliesX.setTextColor(Color.RED);
|
||||
tvAppliesAzimuth.setText(getResources().getString(R.string.no));
|
||||
tvAppliesAzimuth.setTextColor(Color.RED);
|
||||
}
|
||||
|
||||
desiredY = Float.parseFloat(etDesiredPositionY.getText().toString());
|
||||
desiredYTolerance = Float.parseFloat(etDesiredPositionYTolerance.getText().toString());
|
||||
if(y >= desiredY - desiredYTolerance || y <= desiredY + desiredYTolerance)
|
||||
desiredPitch = Float.parseFloat(etDesiredPitch.getText().toString());
|
||||
desiredPitchTolerance = Float.parseFloat(etDesiredPitchTolerance.getText().toString());
|
||||
if(Math.abs(pitch) <= Math.abs(desiredPitch - desiredPitchTolerance) || Math.abs(pitch) <= desiredPitch + desiredPitchTolerance)
|
||||
{
|
||||
tvAppliesY.setText(getResources().getString(R.string.yes));
|
||||
tvAppliesY.setTextColor(Color.GREEN);
|
||||
tvAppliesPitch.setText(getResources().getString(R.string.yes));
|
||||
tvAppliesPitch.setTextColor(Color.GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
tvAppliesY.setText(getResources().getString(R.string.no));
|
||||
tvAppliesY.setTextColor(Color.RED);
|
||||
tvAppliesPitch.setText(getResources().getString(R.string.no));
|
||||
tvAppliesPitch.setTextColor(Color.RED);
|
||||
}
|
||||
|
||||
desiredZ = Float.parseFloat(etDesiredPositionZ.getText().toString());
|
||||
desiredZTolerance = Float.parseFloat(etDesiredPositionZTolerance.getText().toString());
|
||||
if(z >= desiredZ - desiredZTolerance || z <= desiredZ + desiredZTolerance)
|
||||
desiredRoll = Float.parseFloat(etDesiredRoll.getText().toString());
|
||||
desiredRollTolerance = Float.parseFloat(etDesiredRollTolerance.getText().toString());
|
||||
if(Math.abs(roll) <= Math.abs(desiredRoll - desiredRollTolerance) || Math.abs(roll) <= desiredRoll + desiredRollTolerance)
|
||||
{
|
||||
tvAppliesZ.setText(getResources().getString(R.string.yes));
|
||||
tvAppliesZ.setTextColor(Color.GREEN);
|
||||
tvAppliesRoll.setText(getResources().getString(R.string.yes));
|
||||
tvAppliesRoll.setTextColor(Color.GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
tvAppliesZ.setText(getResources().getString(R.string.no));
|
||||
tvAppliesZ.setTextColor(Color.RED);
|
||||
tvAppliesRoll.setText(getResources().getString(R.string.no));
|
||||
tvAppliesRoll.setTextColor(Color.RED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,36 +85,55 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_manage_trigger_device_position);
|
||||
|
||||
currentOrientationX = (TextView) findViewById(R.id.currentOrientationX);
|
||||
currentOrientationY = (TextView) findViewById(R.id.currentOrientationY);
|
||||
currentOrientationZ = (TextView) findViewById(R.id.currentOrientationZ);
|
||||
tvAppliesX = (TextView) findViewById(R.id.tvAppliesX);
|
||||
tvAppliesY = (TextView) findViewById(R.id.tvAppliesY);
|
||||
tvAppliesZ = (TextView) findViewById(R.id.tvAppliesZ);
|
||||
currentAzimuth = (TextView) findViewById(R.id.tvCurrentAzimuth);
|
||||
currentPitch = (TextView) findViewById(R.id.tvCurrentOrientationPitch);
|
||||
currentRoll = (TextView) findViewById(R.id.tvCurrentRoll);
|
||||
tvAppliesAzimuth = (TextView) findViewById(R.id.tvAppliesAzimuth);
|
||||
tvAppliesPitch = (TextView) findViewById(R.id.tvAppliesPitch);
|
||||
tvAppliesRoll = (TextView) findViewById(R.id.tvAppliesRoll);
|
||||
|
||||
bApplyPositionValues = (Button) findViewById(R.id.bApplyPositionValues);
|
||||
bSavePositionValues = (Button) findViewById(R.id.bSavePositionValues);
|
||||
|
||||
etDesiredPositionX = (EditText) findViewById(R.id.etDesiredPositionX);
|
||||
etDesiredPositionXTolerance = (EditText) findViewById(R.id.etDesiredPositionXTolerance);
|
||||
etDesiredPositionY = (EditText) findViewById(R.id.etDesiredPositionY);
|
||||
etDesiredPositionYTolerance = (EditText) findViewById(R.id.etDesiredPositionYTolerance);
|
||||
etDesiredPositionZ = (EditText) findViewById(R.id.etDesiredPositionZ);
|
||||
etDesiredPositionZTolerance = (EditText) findViewById(R.id.etDesiredPositionZTolerance);
|
||||
etDesiredAzimuth = (EditText) findViewById(R.id.etDesiredAzimuth);
|
||||
etDesiredAzimuthTolerance = (EditText) findViewById(R.id.etDesiredAzimuthTolerance);
|
||||
etDesiredPitch = (EditText) findViewById(R.id.etDesiredPitch);
|
||||
etDesiredPitchTolerance = (EditText) findViewById(R.id.etDesiredPitchTolerance);
|
||||
etDesiredRoll = (EditText) findViewById(R.id.etDesiredRoll);
|
||||
etDesiredRollTolerance = (EditText) findViewById(R.id.etDesiredRollTolerance);
|
||||
|
||||
// etDesiredAzimuth.setFilters(new InputFilter[]{new InputFilterMinMax(-180, 180)});
|
||||
// etDesiredPitch.setFilters(new InputFilter[]{new InputFilterMinMax(-180, 180)});
|
||||
// etDesiredRoll.setFilters(new InputFilter[]{new InputFilterMinMax(-180, 180)});
|
||||
etDesiredAzimuthTolerance.setFilters(new InputFilter[]{new InputFilterMinMax(0, 359)});
|
||||
etDesiredPitchTolerance.setFilters(new InputFilter[]{new InputFilterMinMax(0, 359)});
|
||||
etDesiredRollTolerance.setFilters(new InputFilter[]{new InputFilterMinMax(0, 359)});
|
||||
|
||||
if(getIntent().hasExtra(vectorFieldName))
|
||||
{
|
||||
editMode = true;
|
||||
String values[] = getIntent().getStringExtra(vectorFieldName).split(Trigger.triggerParameter2Split);
|
||||
etDesiredAzimuth.setText(values[0]);
|
||||
etDesiredAzimuthTolerance.setText(values[1]);
|
||||
etDesiredPitch.setText(values[2]);
|
||||
etDesiredPitchTolerance.setText(values[3]);
|
||||
etDesiredRoll.setText(values[4]);
|
||||
etDesiredRollTolerance.setText(values[5]);
|
||||
}
|
||||
|
||||
bApplyPositionValues.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if(!StringUtils.isEmpty(currentOrientationX.getText()))
|
||||
etDesiredPositionX.setText(currentOrientationX.getText());
|
||||
if(!StringUtils.isEmpty(currentAzimuth.getText()))
|
||||
etDesiredAzimuth.setText(currentAzimuth.getText());
|
||||
|
||||
if(!StringUtils.isEmpty(currentOrientationY.getText()))
|
||||
etDesiredPositionY.setText(currentOrientationY.getText());
|
||||
if(!StringUtils.isEmpty(currentPitch.getText()))
|
||||
etDesiredPitch.setText(currentPitch.getText());
|
||||
|
||||
if(!StringUtils.isEmpty(currentOrientationZ.getText()))
|
||||
etDesiredPositionZ.setText(currentOrientationZ.getText());
|
||||
if(!StringUtils.isEmpty(currentRoll.getText()))
|
||||
etDesiredRoll.setText(currentRoll.getText());
|
||||
}
|
||||
});
|
||||
|
||||
@ -116,13 +142,24 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if(checkInputs())
|
||||
if(!checkInputs())
|
||||
{
|
||||
Toast.makeText(ActivityManageTriggerDevicePosition.this, getResources().getString(R.string.enterValidNumbersIntoAllFields), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save
|
||||
Intent returnData = new Intent();
|
||||
returnData.putExtra(vectorFieldName,
|
||||
etDesiredAzimuth.getText().toString() + Trigger.triggerParameter2Split +
|
||||
etDesiredAzimuthTolerance.getText().toString() + Trigger.triggerParameter2Split +
|
||||
etDesiredPitch.getText().toString() + Trigger.triggerParameter2Split +
|
||||
etDesiredPitchTolerance.getText().toString() + Trigger.triggerParameter2Split +
|
||||
etDesiredRoll.getText().toString() + Trigger.triggerParameter2Split +
|
||||
etDesiredRollTolerance.getText().toString());
|
||||
|
||||
setResult(RESULT_OK, returnData);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -130,19 +167,29 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
|
||||
boolean checkInputs()
|
||||
{
|
||||
return(
|
||||
!StringUtils.isEmpty(etDesiredPositionX.getText().toString()) && Miscellaneous.isNumeric(etDesiredPositionX.getText().toString())
|
||||
if(
|
||||
!StringUtils.isEmpty(etDesiredAzimuth.getText().toString()) && Miscellaneous.isNumeric(etDesiredAzimuth.getText().toString())
|
||||
&&
|
||||
!StringUtils.isEmpty(etDesiredPositionXTolerance.getText().toString()) && Miscellaneous.isNumeric(etDesiredPositionXTolerance.getText().toString())
|
||||
!StringUtils.isEmpty(etDesiredAzimuthTolerance.getText().toString()) && Miscellaneous.isNumeric(etDesiredAzimuthTolerance.getText().toString())
|
||||
&&
|
||||
!StringUtils.isEmpty(etDesiredPositionY.getText().toString()) && Miscellaneous.isNumeric(etDesiredPositionY.getText().toString())
|
||||
!StringUtils.isEmpty(etDesiredPitch.getText().toString()) && Miscellaneous.isNumeric(etDesiredPitch.getText().toString())
|
||||
&&
|
||||
!StringUtils.isEmpty(etDesiredPositionYTolerance.getText().toString()) && Miscellaneous.isNumeric(etDesiredPositionYTolerance.getText().toString())
|
||||
!StringUtils.isEmpty(etDesiredPitchTolerance.getText().toString()) && Miscellaneous.isNumeric(etDesiredPitchTolerance.getText().toString())
|
||||
&&
|
||||
!StringUtils.isEmpty(etDesiredPositionZ.getText().toString()) && Miscellaneous.isNumeric(etDesiredPositionZ.getText().toString())
|
||||
!StringUtils.isEmpty(etDesiredRoll.getText().toString()) && Miscellaneous.isNumeric(etDesiredRoll.getText().toString())
|
||||
&&
|
||||
!StringUtils.isEmpty(etDesiredPositionZTolerance.getText().toString()) && Miscellaneous.isNumeric(etDesiredPositionZTolerance.getText().toString())
|
||||
);
|
||||
!StringUtils.isEmpty(etDesiredRollTolerance.getText().toString()) && Miscellaneous.isNumeric(etDesiredRollTolerance.getText().toString())
|
||||
)
|
||||
{
|
||||
float da = Float.parseFloat(etDesiredAzimuth.getText().toString());
|
||||
float dp = Float.parseFloat(etDesiredPitch.getText().toString());
|
||||
float dr = Float.parseFloat(etDesiredRoll.getText().toString());
|
||||
|
||||
if(Math.abs(da) <= 180 || Math.abs(dp) <= 180 || Math.abs(dr) <= 180)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,4 +205,36 @@ public class ActivityManageTriggerDevicePosition extends Activity
|
||||
super.onPause();
|
||||
DevicePositionListener.getInstance().stopSensor();
|
||||
}
|
||||
|
||||
public class InputFilterMinMax implements InputFilter
|
||||
{
|
||||
private float minimumValue;
|
||||
private float maximumValue;
|
||||
|
||||
public InputFilterMinMax(float minimumValue, float maximumValue)
|
||||
{
|
||||
this.minimumValue = minimumValue;
|
||||
this.maximumValue = maximumValue;
|
||||
}
|
||||
|
||||
private boolean isInRange(float a, float b, float c)
|
||||
{
|
||||
return b > a ? c >= a && c <= b : c >= b && c <= a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
|
||||
{
|
||||
try
|
||||
{
|
||||
int input = Integer.parseInt(dest.subSequence(0, dstart).toString() + source + dest.subSequence(dend, dest.length()));
|
||||
if (isInRange(minimumValue, maximumValue, input))
|
||||
return null;
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
@ -833,6 +833,9 @@ public class Trigger
|
||||
setTriggerParameter2("-1" + triggerParameter2Split + directionEquals + triggerParameter2Split + triggerParameter2Split + directionEquals + triggerParameter2Split + triggerParameter2Split);
|
||||
}
|
||||
break;
|
||||
case devicePosition:
|
||||
returnString.append(Miscellaneous.getAnyContext().getString(R.string.deviceIsInCertainPosition));
|
||||
break;
|
||||
default:
|
||||
returnString.append("error");
|
||||
break;
|
||||
|
@ -22,22 +22,49 @@ public class DevicePositionListener implements SensorEventListener
|
||||
private SensorManager sManager;
|
||||
static DevicePositionListener instance = null;
|
||||
|
||||
// Gravity rotational data
|
||||
private float gravity[];
|
||||
// Magnetic rotational data
|
||||
private float magnetic[]; //for magnetic rotational data
|
||||
private float accels[] = new float[3];
|
||||
private float mags[] = new float[3];
|
||||
private float[] values = new float[3];
|
||||
|
||||
// azimuth, pitch and roll
|
||||
private float azimuth;
|
||||
private float pitch;
|
||||
private float roll;
|
||||
|
||||
public static DevicePositionListener getInstance()
|
||||
{
|
||||
if(instance == null)
|
||||
if (instance == null)
|
||||
instance = new DevicePositionListener();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*
|
||||
Computes the device's orientation based on the rotation matrix.
|
||||
When it returns, the array values are as follows:
|
||||
values[0]: Azimuth, angle of rotation about the -z axis. This value represents the angle between the device's y axis and the magnetic north pole. When facing north, this angle is 0, when facing south, this angle is π. Likewise, when facing east, this angle is π/2, and when facing west, this angle is -π/2. The range of values is -π to π.
|
||||
values[1]: Pitch, angle of rotation about the x axis. This value represents the angle between a plane parallel to the device's screen and a plane parallel to the ground. Assuming that the bottom edge of the device faces the user and that the screen is face-up, tilting the top edge of the device toward the ground creates a positive pitch angle. The range of values is -π to π.
|
||||
values[2]: Roll, angle of rotation about the y axis. This value represents the angle between a plane perpendicular to the device's screen and a plane perpendicular to the ground. Assuming that the bottom edge of the device faces the user and that the screen is face-up, tilting the left edge of the device toward the ground creates a positive roll angle. The range of values is -π/2 to π/2.
|
||||
Applying these three rotations in the azimuth, pitch, roll order transforms an identity matrix to the rotation matrix passed into this method. Also, note that all three orientation angles are expressed in radians.
|
||||
*/
|
||||
|
||||
public void startSensor(Context context, ActivityManageTriggerDevicePosition activityManageTriggerDevicePositionInstance)
|
||||
{
|
||||
|
||||
this.activityManageTriggerDevicePositionInstance = activityManageTriggerDevicePositionInstance;
|
||||
sManager = (SensorManager) context.getSystemService(SENSOR_SERVICE);
|
||||
/*register the sensor listener to listen to the gyroscope sensor, use the
|
||||
callbacks defined in this class, and gather the sensor information as quick
|
||||
as possible*/
|
||||
sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),SensorManager.SENSOR_DELAY_FASTEST);
|
||||
|
||||
sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
|
||||
sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_NORMAL);
|
||||
|
||||
// SensorManager.getOrientation()
|
||||
}
|
||||
|
||||
public void stopSensor()
|
||||
@ -55,37 +82,58 @@ public class DevicePositionListener implements SensorEventListener
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event)
|
||||
{
|
||||
//if sensor is unreliable, return void
|
||||
if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE)
|
||||
switch (event.sensor.getType())
|
||||
{
|
||||
return;
|
||||
case Sensor.TYPE_MAGNETIC_FIELD:
|
||||
mags = event.values.clone();
|
||||
break;
|
||||
case Sensor.TYPE_ACCELEROMETER:
|
||||
accels = event.values.clone();
|
||||
break;
|
||||
}
|
||||
|
||||
if (mags != null && accels != null)
|
||||
{
|
||||
gravity = new float[9];
|
||||
magnetic = new float[9];
|
||||
SensorManager.getRotationMatrix(gravity, magnetic, accels, mags);
|
||||
float[] outGravity = new float[9];
|
||||
SensorManager.remapCoordinateSystem(gravity, SensorManager.AXIS_X, SensorManager.AXIS_Z, outGravity);
|
||||
SensorManager.getOrientation(outGravity, values);
|
||||
|
||||
azimuth = values[0] * 57.2957795f;
|
||||
pitch = values[1] * 57.2957795f;
|
||||
roll = values[2] * 57.2957795f;
|
||||
mags = null;
|
||||
accels = null;
|
||||
}
|
||||
|
||||
//else it will output the Roll, Pitch and Yawn values
|
||||
activityManageTriggerDevicePositionInstance.updateFields(event.values[2], event.values[1], event.values[0]);
|
||||
activityManageTriggerDevicePositionInstance.updateFields(azimuth, pitch, roll);
|
||||
|
||||
// tvToUpdate.setText("Orientation X (Roll) :"+ Float.toString(event.values[2]) +"\n"+
|
||||
// "Orientation Y (Pitch) :"+ Float.toString(event.values[1]) +"\n"+
|
||||
// "Orientation Z (Yaw) :"+ Float.toString(event.values[0]));
|
||||
|
||||
|
||||
/*
|
||||
Azimuth (degrees of rotation about the -z axis).
|
||||
This is the angle between the device's current compass direction and magnetic north. If the top edge of the
|
||||
device faces magnetic north, the azimuth is 0 degrees; if the top edge faces south, the azimuth is 180 degrees.
|
||||
Similarly, if the top edge faces east, the azimuth is 90 degrees, and if the top edge faces west, the azimuth is 270 degrees.
|
||||
|
||||
Pitch (degrees of rotation about the x axis).
|
||||
This is the angle between a plane parallel to the device's screen and a plane parallel to the ground. If you hold the device
|
||||
parallel to the ground with the bottom edge closest to you and tilt the top edge of the device toward the ground, the pitch
|
||||
angle becomes positive. Tilting in the opposite direction— moving the top edge of the device away from the ground—causes
|
||||
the pitch angle to become negative. The range of values is -180 degrees to 180 degrees.
|
||||
|
||||
Roll (degrees of rotation about the y axis).
|
||||
This is the angle between a plane perpendicular to the device's screen and a plane perpendicular to the ground.
|
||||
If you hold the device parallel to the ground with the bottom edge closest to you and tilt the left edge of the
|
||||
device toward the ground, the roll angle becomes positive. Tilting in the opposite direction—moving the right
|
||||
edge of the device toward the ground— causes the roll angle to become negative. The range of values is -90 degrees
|
||||
to 90 degrees.
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
Azimuth (degrees of rotation about the -z axis).
|
||||
This is the angle between the device's current compass direction and magnetic north. If the top edge of the
|
||||
device faces magnetic north, the azimuth is 0 degrees; if the top edge faces south, the azimuth is 180 degrees.
|
||||
Similarly, if the top edge faces east, the azimuth is 90 degrees, and if the top edge faces west, the azimuth is 270 degrees.
|
||||
|
||||
Pitch (degrees of rotation about the x axis).
|
||||
This is the angle between a plane parallel to the device's screen and a plane parallel to the ground. If you hold the device
|
||||
parallel to the ground with the bottom edge closest to you and tilt the top edge of the device toward the ground, the pitch
|
||||
angle becomes positive. Tilting in the opposite direction— moving the top edge of the device away from the ground—causes
|
||||
the pitch angle to become negative. The range of values is -180 degrees to 180 degrees.
|
||||
|
||||
Roll (degrees of rotation about the y axis).
|
||||
This is the angle between a plane perpendicular to the device's screen and a plane perpendicular to the ground.
|
||||
If you hold the device parallel to the ground with the bottom edge closest to you and tilt the left edge of the
|
||||
device toward the ground, the roll angle becomes positive. Tilting in the opposite direction—moving the right
|
||||
edge of the device toward the ground— causes the roll angle to become negative. The range of values is -90 degrees
|
||||
to 90 degrees.
|
||||
*/
|
||||
}
|
@ -25,12 +25,12 @@
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:text="@string/orientationX"
|
||||
android:text="@string/orientationAzimuth"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/currentOrientationX"
|
||||
android:id="@+id/tvCurrentAzimuth"
|
||||
android:layout_marginLeft="@dimen/default_margin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
@ -42,12 +42,12 @@
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:text="@string/orientationY"
|
||||
android:text="@string/orientationPitch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/currentOrientationY"
|
||||
android:id="@+id/tvCurrentOrientationPitch"
|
||||
android:layout_marginLeft="@dimen/default_margin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
@ -59,12 +59,12 @@
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:text="@string/orientationZ"
|
||||
android:text="@string/orientationRoll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/currentOrientationZ"
|
||||
android:id="@+id/tvCurrentRoll"
|
||||
android:layout_marginLeft="@dimen/default_margin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
@ -82,10 +82,12 @@
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
android:layout_height="wrap_content"
|
||||
android:shrinkColumns="0"
|
||||
android:stretchColumns="1">
|
||||
|
||||
<TableRow
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
@ -108,6 +110,9 @@
|
||||
|
||||
<TextView
|
||||
android:text="@string/wouldCurrentlyApply"
|
||||
android:singleLine="false"
|
||||
android:maxLines="2"
|
||||
android:lines="2"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
@ -115,31 +120,32 @@
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:text="x"
|
||||
android:text="@string/orientationAzimuth"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="@dimen/default_margin" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etDesiredPositionX"
|
||||
android:id="@+id/etDesiredAzimuth"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"
|
||||
android:minWidth="100dp"/>
|
||||
android:minWidth="50dp"
|
||||
android:enabled="false"
|
||||
android:inputType="number" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etDesiredPositionXTolerance"
|
||||
android:id="@+id/etDesiredAzimuthTolerance"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:minWidth="100dp"/>
|
||||
android:minWidth="50dp"
|
||||
android:inputType="number" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAppliesX"
|
||||
android:id="@+id/tvAppliesAzimuth"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
@ -150,27 +156,28 @@
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:text="y"
|
||||
android:text="@string/orientationPitch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="@dimen/default_margin" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etDesiredPositionY"
|
||||
android:id="@+id/etDesiredPitch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"
|
||||
android:minWidth="100dp"/>
|
||||
android:minWidth="50dp"
|
||||
android:enabled="false"
|
||||
android:inputType="number" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etDesiredPositionYTolerance"
|
||||
android:id="@+id/etDesiredPitchTolerance"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:minWidth="100dp"/>
|
||||
android:minWidth="50dp"
|
||||
android:inputType="number" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAppliesY"
|
||||
android:id="@+id/tvAppliesPitch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
@ -181,27 +188,28 @@
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:text="z"
|
||||
android:text="@string/orientationRoll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="@dimen/default_margin" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etDesiredPositionZ"
|
||||
android:id="@+id/etDesiredRoll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"
|
||||
android:minWidth="100dp"/>
|
||||
android:minWidth="50dp"
|
||||
android:enabled="false"
|
||||
android:inputType="number" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etDesiredPositionZTolerance"
|
||||
android:id="@+id/etDesiredRollTolerance"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:minWidth="100dp"/>
|
||||
android:minWidth="50dp"
|
||||
android:inputType="number" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAppliesZ"
|
||||
android:id="@+id/tvAppliesRoll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
|
@ -715,10 +715,11 @@
|
||||
<string name="notice">Notice</string>
|
||||
<string name="devicePosition">Device position (Gyroscope)</string>
|
||||
<string name="tolerance">Tolerance</string>
|
||||
<string name="orientationX">Orientation X (Roll):</string>
|
||||
<string name="orientationY">Orientation Y (Pitch):</string>
|
||||
<string name="orientationZ">Orientation Z (Yaw):</string>
|
||||
<string name="orientationAzimuth">Azimuth:</string>
|
||||
<string name="orientationPitch">Pitch:</string>
|
||||
<string name="orientationRoll">Roll:</string>
|
||||
<string name="enterValidNumbersIntoAllFields">Enter valid numbers in all fields.</string>
|
||||
<string name="devicePositionExplanation">When you move your device the below numbers should update. What you can see there, is the current \"position\" of your device. If it is in the desired position, click the apply button to copy the current values to the desired fields.\nBecause you will probably not be able to reach this exact position ever again, enter a tolerance. The is amount to which the position can deviate in one direction or the other.</string>
|
||||
<string name="wouldCurrentlyApply">Would currently apply?</string>
|
||||
<string name="deviceIsInCertainPosition">the device is in a certain position</string>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user