Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
51a68e13
Commit
51a68e13
authored
Jun 06, 2012
by
Karishma Chadha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debounces successfully, internally, 300ms
parent
775ed41c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
appinventor/components/src/com/google/appinventor/components/runtime/AccelerometerSensor.java
...e/appinventor/components/runtime/AccelerometerSensor.java
+18
-3
No files found.
appinventor/components/src/com/google/appinventor/components/runtime/AccelerometerSensor.java
View file @
51a68e13
...
...
@@ -86,6 +86,12 @@ public class AccelerometerSensor extends AndroidNonvisibleComponent
// Indicates whether the accelerometer should generate events
private
boolean
enabled
;
//Specifies the time interval between firing of accelerometer events //KARISHMA
private
static
final
int
MINIMUM_INTERVAL
=
300
;
//Specifies the last time the phone shook.//KARISHMA
private
long
timeLastShook
;
private
Sensor
accelerometerSensor
;
...
...
@@ -117,8 +123,11 @@ public class AccelerometerSensor extends AndroidNonvisibleComponent
addToSensorCache
(
X_CACHE
,
xAccel
);
addToSensorCache
(
Y_CACHE
,
yAccel
);
addToSensorCache
(
Z_CACHE
,
zAccel
);
if
(
isShaking
(
X_CACHE
,
xAccel
)
||
isShaking
(
Y_CACHE
,
yAccel
)
||
isShaking
(
Z_CACHE
,
zAccel
))
{
//KARISHMA
long
currentTime
=
System
.
currentTimeMillis
();
if
((
isShaking
(
X_CACHE
,
xAccel
)
||
isShaking
(
Y_CACHE
,
yAccel
)
||
isShaking
(
Z_CACHE
,
zAccel
))
/*KARISHMA*/
&&
(
timeLastShook
==
0
||
currentTime
>=
timeLastShook
+
MINIMUM_INTERVAL
))
{
//KARISHMA
timeLastShook
=
currentTime
;
Shaking
();
}
...
...
@@ -130,7 +139,13 @@ public class AccelerometerSensor extends AndroidNonvisibleComponent
*/
@SimpleEvent
public
void
Shaking
()
{
EventDispatcher
.
dispatchEvent
(
this
,
"Shaking"
);
//KARISHMA
//int currentTime = (int) System.currentTimeMillis();
//if(timeLastShook == 0 || currentTime > timeLastShook + MINIMUM_INTERVAL)
//{
//timeLastShook += currentTime;
EventDispatcher
.
dispatchEvent
(
this
,
"Shaking"
);
//}
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment