Android sensor code example understanding -
i'm new android development , have code make shake event, not understand last_x used for?
if understand correctly last_x detecting last x-axis value of when last shaking event happened. how works, when last_x = x , x event.values[0].
private float last_x; public void onsensorchanged(sensorevent event) { sensor mysensor = event.sensor; if (mysensor.gettype() == sensor.type_accelerometer) { float x = event.values[0]; //x value if (math.abs(last_x - x) > 2) { mmap.addmarker(new markeroptions() .position(new latlng(55.654929, 12.139613)) .icon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_orange)) .title("hey moved x axis on")); } last_x = x; } }
Comments
Post a Comment