-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from jperedadnr/master
iOS implementation for rest of services
- Loading branch information
Showing
138 changed files
with
7,868 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2019, Gluon | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY | ||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include <stdarg.h> | ||
|
||
static __inline__ void AttachLog(const char *file, int lineNumber, const char *funcName, NSString* format, ...) | ||
{ | ||
va_list argList; | ||
va_start(argList, format); | ||
NSString* formattedMessage = [[NSString alloc] initWithFormat: format arguments: argList]; | ||
va_end(argList); | ||
NSLog(@"[AttachLog] %@", formattedMessage); | ||
|
||
static NSDateFormatter* dateFormatter; | ||
if (!dateFormatter) { | ||
dateFormatter = [[NSDateFormatter alloc] init]; | ||
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"]; | ||
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]]; | ||
} | ||
fprintf(stderr, "[AttachLog] %s %s:%3d %s\n", [[dateFormatter stringFromDate:[NSDate date]] UTF8String], funcName, lineNumber, [formattedMessage UTF8String]); | ||
[formattedMessage release]; | ||
} | ||
|
||
#define AttachLog(MSG, ...) AttachLog(__FILE__, __LINE__, __PRETTY_FUNCTION__, MSG, ## __VA_ARGS__ ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
apply plugin: 'org.openjfx.javafxplugin' | ||
|
||
javafx { | ||
modules 'javafx.base' | ||
modules 'javafx.graphics' | ||
} | ||
|
||
dependencies { | ||
implementation project(':util') | ||
implementation project(":lifecycle") | ||
} | ||
|
||
ext.description = 'Common API to access accelerometer features' |
27 changes: 27 additions & 0 deletions
27
...ometer/src/main/java/com/gluonhq/attach/accelerometer/impl/DummyAccelerometerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...erometer/src/main/java/com/gluonhq/attach/accelerometer/impl/IOSAccelerometerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2016, 2019, Gluon | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY | ||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.gluonhq.attach.accelerometer.impl; | ||
|
||
import com.gluonhq.attach.accelerometer.Acceleration; | ||
import com.gluonhq.attach.accelerometer.AccelerometerService; | ||
import com.gluonhq.attach.lifecycle.LifecycleEvent; | ||
import com.gluonhq.attach.lifecycle.LifecycleService; | ||
import javafx.application.Platform; | ||
import javafx.beans.property.ReadOnlyObjectProperty; | ||
import javafx.beans.property.ReadOnlyObjectWrapper; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
|
||
public class IOSAccelerometerService implements AccelerometerService { | ||
|
||
static { | ||
System.loadLibrary("Accelerometer"); | ||
initAccelerometer(); | ||
} | ||
|
||
private static ReadOnlyObjectWrapper<Acceleration> acceleration; | ||
|
||
public IOSAccelerometerService() { | ||
acceleration = new ReadOnlyObjectWrapper<>(); | ||
|
||
LifecycleService.create().ifPresent(l -> { | ||
l.addListener(LifecycleEvent.PAUSE, IOSAccelerometerService::stopObserver); | ||
l.addListener(LifecycleEvent.RESUME, () -> startObserver(FILTER_GRAVITY, FREQUENCY)); | ||
}); | ||
startObserver(FILTER_GRAVITY, FREQUENCY); | ||
} | ||
|
||
@Override | ||
public Acceleration getCurrentAcceleration() { | ||
return acceleration.get(); | ||
} | ||
|
||
@Override | ||
public ReadOnlyObjectProperty<Acceleration> accelerationProperty() { | ||
return acceleration.getReadOnlyProperty(); | ||
} | ||
|
||
// native | ||
private static native void initAccelerometer(); | ||
private static native void startObserver(boolean filterGravity, int rateInMillis); | ||
private static native void stopObserver(); | ||
|
||
// callback | ||
private static void notifyAcceleration(double x, double y, double z, double t) { | ||
Acceleration a = new Acceleration(x, y, z, toLocalDateTime(t)); | ||
Platform.runLater(() -> acceleration.setValue(a)); | ||
} | ||
|
||
private static LocalDateTime toLocalDateTime(double t) { | ||
return LocalDateTime.ofInstant(Instant.ofEpochMilli((long) t), ZoneId.systemDefault()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2016, 2019, Gluon | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY | ||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
#include "jni.h" | ||
#include "AttachMacros.h" | ||
#import <CoreMotion/CoreMotion.h> | ||
|
||
@interface Accelerometer : UIViewController {} | ||
@property (strong, nonatomic) CMMotionManager *motionManager; | ||
- (void) startObserver; | ||
- (void) stopObserver; | ||
@end | ||
|
||
void sendAcceleration(CMAccelerometerData *accelerometerData); |
Oops, something went wrong.