Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cordova-plugin-background-geolocation
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Aksimaya
cordova-plugin-background-geolocation
Commits
bc09e1b3
Commit
bc09e1b3
authored
Jul 31, 2014
by
keesschollaart81
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added debug sound on position changed in WP8
parent
da7baa65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
28 deletions
+125
-28
BackgroundGeoLocation.cs
src/wp8/BackgroundGeoLocation.cs
+30
-28
DebugAudioNotifier.cs
src/wp8/DebugAudioNotifier.cs
+95
-0
No files found.
src/wp8/BackgroundGeoLocation.cs
View file @
bc09e1b3
using
System
;
using
System.Windows
;
using
Windows.Devices.Geolocation
;
using
Windows.Devices.Geolocation
;
using
WPCordovaClassLib.Cordova
;
using
WPCordovaClassLib.Cordova.Commands
;
using
WPCordovaClassLib.Cordova.JSON
;
...
...
@@ -28,20 +27,21 @@ namespace Cordova.Extension.Commands
public
BackgroundGeoLocation
()
{
this
.
IsConfiguring
=
false
;
this
.
IsConfigured
=
false
;
IsConfiguring
=
false
;
IsConfigured
=
false
;
}
public
void
configure
(
string
args
)
{
this
.
IsConfiguring
=
true
;
this
.
ConfigureCallbackToken
=
CurrentCommandCallbackId
;
IsConfiguring
=
true
;
ConfigureCallbackToken
=
CurrentCommandCallbackId
;
RunningInBackground
=
false
;
BackgroundGeoLocationOptions
=
this
.
ParseBackgroundGeoLocationOptions
(
args
);
this
.
IsConfigured
=
BackgroundGeoLocationOptions
.
ParsingSucceeded
;
this
.
IsConfiguring
=
false
;
IsConfigured
=
BackgroundGeoLocationOptions
.
ParsingSucceeded
;
IsConfiguring
=
false
;
}
private
BackgroundGeoLocationOptions
ParseBackgroundGeoLocationOptions
(
string
configureArgs
)
...
...
@@ -51,11 +51,11 @@ namespace Cordova.Extension.Commands
var
options
=
JsonHelper
.
Deserialize
<
string
[
]>
(
configureArgs
);
var
customParameters
=
JsonHelper
.
Deserialize
<
BackgroundGeoLocationOptionsParameters
>(
options
[
0
]);
var
stationaryRadius
=
0.0
;
var
distanceFilter
=
0.0
;
UInt32
locationTimeout
=
0
;
UInt32
desiredAccuracy
=
0
;
var
debug
=
false
;
double
stationaryRadius
;
double
distanceFilter
;
UInt32
locationTimeout
;
UInt32
desiredAccuracy
;
bool
debug
;
if
(!
double
.
TryParse
(
options
[
3
],
out
stationaryRadius
))
{
...
...
@@ -140,22 +140,25 @@ namespace Cordova.Extension.Commands
RunningInBackground
=
true
;
DispatchCommandResult
(
new
PluginResult
(
PluginResult
.
Status
.
OK
));
}
private
void
OnGeolocatorOnPositionChanged
(
Geolocator
sender
,
PositionChangedEventArgs
C
onfigureCallbackTokenargs
)
private
void
OnGeolocatorOnPositionChanged
(
Geolocator
sender
,
PositionChangedEventArgs
c
onfigureCallbackTokenargs
)
{
if
(
Geolocator
.
LocationStatus
==
PositionStatus
.
Disabled
||
Geolocator
.
LocationStatus
==
PositionStatus
.
NotAvailable
)
if
(
Geolocator
.
LocationStatus
==
PositionStatus
.
Disabled
||
Geolocator
.
LocationStatus
==
PositionStatus
.
NotAvailable
)
{
DispatchMessage
(
PluginResult
.
Status
.
ERROR
,
string
.
Format
(
"Cannot start: LocationStatus/PositionStatus: {0}! {1}"
,
Geolocator
.
LocationStatus
,
IsConfigured
),
true
,
this
.
ConfigureCallbackToken
);
DispatchMessage
(
PluginResult
.
Status
.
ERROR
,
string
.
Format
(
"Cannot start: LocationStatus/PositionStatus: {0}! {1}"
,
Geolocator
.
LocationStatus
,
IsConfigured
),
true
,
ConfigureCallbackToken
);
return
;
}
var
callbackJsonResult
=
ConfigureCallbackTokenargs
.
Position
.
Coordinate
.
ToJson
();
Debug
.
WriteLine
(
"PositionChanged token{0}, Coordinates: {1}"
,
ConfigureCallbackToken
,
callbackJsonResult
);
DispatchMessage
(
PluginResult
.
Status
.
OK
,
callbackJsonResult
,
true
,
this
.
ConfigureCallbackToken
);
}
var
callbackJsonResult
=
configureCallbackTokenargs
.
Position
.
Coordinate
.
ToJson
();
if
(
BackgroundGeoLocationOptions
.
Debug
)
{
DebugAudioNotifier
.
GetDebugAudioNotifier
().
PlaySound
(
DebugAudioNotifier
.
Tone
.
High
,
TimeSpan
.
FromSeconds
(
3
));
Debug
.
WriteLine
(
"PositionChanged token{0}, Coordinates: {1}"
,
ConfigureCallbackToken
,
callbackJsonResult
);
}
DispatchMessage
(
PluginResult
.
Status
.
OK
,
callbackJsonResult
,
true
,
ConfigureCallbackToken
);
}
public
void
stop
()
{
...
...
@@ -173,7 +176,7 @@ namespace Cordova.Extension.Commands
public
void
finish
()
{
throw
new
NotImplementedException
(
);
DispatchCommandResult
(
new
PluginResult
(
PluginResult
.
Status
.
NO_RESULT
)
);
}
public
void
onPaceChange
(
bool
isMoving
)
...
...
@@ -192,10 +195,10 @@ namespace Cordova.Extension.Commands
var
options
=
JsonHelper
.
Deserialize
<
string
[
]>
(
setConfigArgs
);
var
stationaryRadius
=
0.0
;
var
distanceFilter
=
0.0
;
UInt32
locationTimeout
=
0
;
UInt32
desiredAccuracy
=
0
;
double
stationaryRadius
;
double
distanceFilter
;
UInt32
locationTimeout
;
UInt32
desiredAccuracy
;
if
(!
double
.
TryParse
(
options
[
0
],
out
stationaryRadius
))
{
...
...
@@ -238,5 +241,4 @@ namespace Cordova.Extension.Commands
DispatchCommandResult
(
pluginResult
,
callBackId
);
}
}
}
src/wp8/DebugAudioNotifier.cs
0 → 100644
View file @
bc09e1b3
using
System
;
using
System.Windows
;
using
System.Windows.Threading
;
using
Microsoft.Xna.Framework
;
using
Microsoft.Xna.Framework.Audio
;
namespace
Cordova.Extension.Commands
{
public
class
DebugAudioNotifier
:
IDisposable
{
private
static
DebugAudioNotifier
_audioNotifier
;
private
DynamicSoundEffectInstance
_dynamicSound
;
private
DispatcherTimer
_timer
;
private
TimeSpan
_timeLeft
;
private
const
int
SampleRate
=
48000
;
private
Tone
_frequency
=
Tone
.
Low
;
private
int
_bufferSize
;
private
byte
[]
_soundBuffer
;
private
int
_totalTime
;
public
enum
Tone
{
Low
=
300
,
High
=
900
}
private
DebugAudioNotifier
()
{
}
public
static
DebugAudioNotifier
GetDebugAudioNotifier
()
{
return
_audioNotifier
??
(
_audioNotifier
=
new
DebugAudioNotifier
());
}
public
void
PlaySound
(
Tone
tone
,
TimeSpan
duration
)
{
Deployment
.
Current
.
Dispatcher
.
BeginInvoke
(()
=>
{
if
(
_timer
==
null
)
{
_timer
=
new
DispatcherTimer
{
Interval
=
TimeSpan
.
FromMilliseconds
(
33
)
};
_timer
.
Tick
+=
delegate
{
try
{
FrameworkDispatcher
.
Update
();
}
catch
{
}
};
}
if
(
_timer
.
IsEnabled
)
_timer
.
Stop
();
_timeLeft
=
duration
;
FrameworkDispatcher
.
Update
();
_frequency
=
tone
;
_dynamicSound
=
new
DynamicSoundEffectInstance
(
SampleRate
,
AudioChannels
.
Mono
);
_dynamicSound
.
BufferNeeded
+=
dynamicSound_BufferNeeded
;
_dynamicSound
.
Play
();
_bufferSize
=
_dynamicSound
.
GetSampleSizeInBytes
(
TimeSpan
.
FromSeconds
(
1
));
_soundBuffer
=
new
byte
[
_bufferSize
];
_timer
.
Start
();
});
}
private
void
dynamicSound_BufferNeeded
(
object
sender
,
EventArgs
e
)
{
for
(
var
i
=
0
;
i
<
_bufferSize
-
1
;
i
+=
2
)
{
var
time
=
_totalTime
/
(
double
)
SampleRate
;
var
sample
=
(
short
)(
Math
.
Sin
(
2
*
Math
.
PI
*
(
int
)
_frequency
*
time
)
*
short
.
MaxValue
);
_soundBuffer
[
i
]
=
(
byte
)
sample
;
_soundBuffer
[
i
+
1
]
=
(
byte
)(
sample
>>
8
);
_totalTime
++;
}
_timeLeft
=
_timeLeft
.
Subtract
(
TimeSpan
.
FromSeconds
(
_totalTime
/
SampleRate
));
if
(
_timeLeft
.
Ticks
<=
0
)
{
_totalTime
=
0
;
return
;
}
_dynamicSound
.
SubmitBuffer
(
_soundBuffer
);
}
public
void
Dispose
()
{
_dynamicSound
.
Dispose
();
}
}
}
\ No newline at end of file
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