Skip to content

Commit

Permalink
Merge pull request #14 from jperedadnr/master
Browse files Browse the repository at this point in the history
iOS implementation for rest of services
  • Loading branch information
José Pereda authored Jun 23, 2019
2 parents 40bbd54 + df2dfab commit 4f3af41
Show file tree
Hide file tree
Showing 138 changed files with 7,868 additions and 97 deletions.
49 changes: 49 additions & 0 deletions gradle/include/AttachMacros.h
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__ )
28 changes: 18 additions & 10 deletions gradle/native-build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ ext.nativeBuild = { buildDir, projectDir, name, os ->
}

def JAVAHOME = System.getenv("JAVA_HOME")
def includeFlags = "-I$JAVAHOME/include"
def includeFlags = [
"-I$JAVAHOME/include",
"-I$projectDir/../../gradle/include",
]
def osIncludeFlags = ""

if (os == "ios") {
Expand Down Expand Up @@ -101,6 +104,12 @@ ext.nativeBuild = { buildDir, projectDir, name, os ->
args lipoArgs
}

println("native build for $name finished")
File n = new File(lipoOutput)
if (n.exists()) {
println "Adding $n to native jar"
n
}
} else {
// TODO
def compileOutput = "$buildDir/native/$os"
Expand All @@ -111,19 +120,18 @@ ext.nativeBuild = { buildDir, projectDir, name, os ->
def cargs = [
"-c", includeFlags, osIncludeFlags, sharedSources, osSources
].flatten()

exec {
executable "/usr/bin/gcc"
args cargs
workingDir compileOutput
}
}

println("native build for $name finished")
File n = new File("$buildDir/native/${os}")
if (n.exists()) {
println "Adding lib${name} to native jar"
fileTree("$buildDir/native/${os}").filter { it.isFile() }.files
.first()
// TODO
File n = new File("$buildDir/native/${os}")
if (n.exists()) {
println "Adding lib${name} to native jar"
fileTree("$buildDir/native/${os}").filter { it.isFile() }.files
.first()
}
}
}
3 changes: 2 additions & 1 deletion modules/accelerometer/build.gradle
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'
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/*
* 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.
*/
package com.gluonhq.attach.accelerometer.impl;

import com.gluonhq.attach.accelerometer.AccelerometerService;
Expand Down
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/

/**
* Primary API package for Down - Accelerometer plugin,
* Primary API package for Attach - Accelerometer plugin,
* contains the interface {@link com.gluonhq.attach.accelerometer.AccelerometerService} and related classes.
*/
package com.gluonhq.attach.accelerometer;
3 changes: 2 additions & 1 deletion modules/accelerometer/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
*/
module com.gluonhq.attach.accelerometer {

requires javafx.base;
requires javafx.graphics;
requires com.gluonhq.attach.util;
requires com.gluonhq.attach.lifecycle;

exports com.gluonhq.attach.accelerometer;
exports com.gluonhq.attach.accelerometer.impl to com.gluonhq.attach.util;
Expand Down
40 changes: 40 additions & 0 deletions modules/accelerometer/src/main/native/ios/Accelerometer.h
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);
Loading

0 comments on commit 4f3af41

Please sign in to comment.