Commit 51efa8f7 authored by Vance Turnewitsch's avatar Vance Turnewitsch

Merge branch 'master' of github.com:mit-cml/app-inventor-private

parents 4bc7a174 d89d9325
......@@ -195,8 +195,10 @@ public final class YoungAndroidFormUpgrader {
// NOTE(lizlooney,user) - when a component changes, increment the component's version
// number in com.google.appinventor.components.common.YaVersion and add code here to upgrade
// properties as necessary.
if (componentType.equals("AccelerometerSensor")){
srcCompVersion = upgradeAccelerometerSensorProperties(componentProperties, srcCompVersion);
if (componentType.equals("ActivityStarter")) {
} else if (componentType.equals("ActivityStarter")) {
srcCompVersion = upgradeActivityStarterProperties(componentProperties, srcCompVersion);
} else if (componentType.equals("Ball")) {
......@@ -321,6 +323,16 @@ public final class YoungAndroidFormUpgrader {
}
}
private static int upgradeAccelerometerSensorProperties(Map<String, JSONValue> componentProperties,
int srcCompVersion) {
if (srcCompVersion < 2) {
// The AccelerometerSensor.MinimumInterval property was added.
// No properties need to be modified to upgrade to version 2.
srcCompVersion = 2;
}
return srcCompVersion;
}
private static int upgradeActivityStarterProperties(Map<String, JSONValue> componentProperties,
int srcCompVersion) {
if (srcCompVersion < 2) {
......
......@@ -382,7 +382,10 @@ public class BlockSaveFile {
// number in com.google.appinventor.components.common.YaVersion and add code here to upgrade blocks
// as necessary.
if (genus.equals("ActivityStarter")) {
if(genus.equals("AccelerometerSensor")){
blkCompVersion = upgradeAccelerometerSensorBlocks(blkCompVersion, componentName);
} else if (genus.equals("ActivityStarter")) {
blkCompVersion = upgradeActivityStarterBlocks(blkCompVersion, componentName);
} else if (genus.equals("Ball")) {
......@@ -495,6 +498,15 @@ public class BlockSaveFile {
}
}
private int upgradeAccelerometerSensorBlocks(int blkCompVersion, String componentName) {
if (blkCompVersion < 2) {
// The AccelerometerSensor.MinimumInterval property was added.
// No blocks need to be modified to upgrade to version 2.
blkCompVersion = 2;
}
return blkCompVersion;
}
private int upgradeActivityStarterBlocks(int blkCompVersion, String componentName) {
if (blkCompVersion < 2) {
// The ActivityStarter.DataType, ActivityStarter.ResultType, and ActivityStarter.ResultUri
......
......@@ -168,8 +168,10 @@ public class YaVersion {
// - IMAGEPICKER_COMPONENT_VERSION was incremented to 4.
// - LISTPICKER_COMPONENT_VERSION was incremented to 5.
// - PHONENUMBERPICKER_COMPONENT_VERSION was incremented to 4.
// For YOUNG_ANDROID_VERSION 55:
// - ACCELEROMETERSENSOR_COMPONENT_VERSION was incremented to 2.
public static final int YOUNG_ANDROID_VERSION = 54;
public static final int YOUNG_ANDROID_VERSION = 55;
// ............................... Blocks Language Version Number ...............................
......@@ -237,7 +239,11 @@ public class YaVersion {
// 4. Add code in openblocks.yacodeblocks.BlockSaveFile#upgradeComponentBlocks to
// upgrade the .blk file contents
public static final int ACCELEROMETERSENSOR_COMPONENT_VERSION = 1;
//For ACCELEROMETERSENSOR_COMPONENT_VERSION 2:
// - AccelerometerSensor.MinimumInterval property was added.
// - AccelerometerSensor.AccelerationChanged method was modified to wait for
// the minimum interval to elapse before calling a shaking event when necessary.
public static final int ACCELEROMETERSENSOR_COMPONENT_VERSION = 2;
// For ACTIVITYSTARTER_COMPONENT_VERSION 2:
// - The ActivityStarter.DataType, ActivityStarter.ResultType, and ActivityStarter.ResultUri
......
......@@ -87,6 +87,12 @@ public class AccelerometerSensor extends AndroidNonvisibleComponent
// Indicates whether the accelerometer should generate events
private boolean enabled;
//Specifies the minimum time interval between calls to Shaking()
private int minimumInterval;
//Specifies the time when Shaking() was last called
private long timeLastShook;
private Sensor accelerometerSensor;
/**
......@@ -103,6 +109,35 @@ public class AccelerometerSensor extends AndroidNonvisibleComponent
sensorManager = (SensorManager) container.$context().getSystemService(Context.SENSOR_SERVICE);
accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
startListening();
MinimumInterval(400);
}
/**
* Returns the minimum interval required between calls to Shaking(),
* in milliseconds.
* Once the phone starts being shaken, all further Shaking() calls will be ignored
* until the interval has elapsed.
* @return minimum interval in ms
*/
@SimpleProperty(
category = PropertyCategory.BEHAVIOR,
description = "The minimum interval between phone shakes")
public int MinimumInterval() {
return minimumInterval;
}
/**
* Specifies the minimum interval required between calls to Shaking(),
* in milliseconds.
* Once the phone starts being shaken, all further Shaking() calls will be ignored
* until the interval has elapsed.
* @param interval minimum interval in ms
*/
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER,
defaultValue = "400") //Default value derived by trial of 12 people on 3 different devices
@SimpleProperty
public void MinimumInterval(int interval) {
minimumInterval = interval;
}
/**
......@@ -118,7 +153,13 @@ public class AccelerometerSensor extends AndroidNonvisibleComponent
addToSensorCache(Y_CACHE, yAccel);
addToSensorCache(Z_CACHE, zAccel);
if (isShaking(X_CACHE, xAccel) || isShaking(Y_CACHE, yAccel) || isShaking(Z_CACHE, zAccel)) {
long currentTime = System.currentTimeMillis();
//Checks whether the phone is shaking and the minimum interval
//has elapsed since the last registered a shaking event.
if ((isShaking(X_CACHE, xAccel) || isShaking(Y_CACHE, yAccel) || isShaking(Z_CACHE, zAccel))
&& (timeLastShook == 0 || currentTime >= timeLastShook + minimumInterval)){
timeLastShook = currentTime;
Shaking();
}
......
......@@ -138,6 +138,20 @@
<dd>
Acceleration in the Z-dimension.
</dd>
<dt>
<code class="c2">
MinimumInterval
</code>
</dt>
<dd>
Minimum time interval between phone shakes.
<br/>
You may want to change the time interval depending on the activity you want to perform when the phone is shaken.
For example, you may want the phone to say "Stop shaking me" each time the user shakes the phone. At shorter time intervals, this
will produce an unwanted echo effect.
In another case, you may want a quick flick of the phone to be considered a single shake and perhaps increment a
counter each time the phone shakes. In cases such as this, a shorter time interval will be more appropriate to properly count the shakes.
</dd>
</dl>
<h3>
Events
......
# You can copy and/or modify this file to create your own .gitignore file.
# This keeps generated files from being added to source control management.
.gitignore
.classpath
.project
bin/
build/
reports/
.DS_Store*
# You can copy and/or modify this file to create your own .hgignore file.
# This keeps generated files from being added to source control management.
^\.hgignore
^appinventor/build/
^appinventor/reports/
^appinventor/appengine/build
^appinventor/appengine/reports
^appinventor/buildserver/build
^appinventor/buildserver/reports
^appinventor/blockseditor/build
^appinventor/blockseditor/reports
^appinventor/blockslib/build
^appinventor/blockslib/reports
^appinventor/common/build
^appinventor/common/reports
^appinventor/components/build
^appinventor/components/reports
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment