Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from olokobayusuf/native-projects
Browse files Browse the repository at this point in the history
Native Source Projects
  • Loading branch information
olokobayusuf authored Sep 20, 2018
2 parents 83241e9 + 375ed0a commit e3cce08
Show file tree
Hide file tree
Showing 75 changed files with 1,336 additions and 668 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ Assets/Calligraphy/
Assets/Calligraphy.meta
Assets/Support/
Assets/Support.meta
Assets/NatCamSupport/
Assets/NatCamSupport.meta
Assets/Plugins/
Assets/Plugins.meta
8 changes: 8 additions & 0 deletions Android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
1 change: 1 addition & 0 deletions Android/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Android/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Android/.idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Android/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Android/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Android/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Android/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Android</name>
<comment>Project Android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions Android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
6 changes: 6 additions & 0 deletions Android/Pedometer/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions Android/Pedometer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
23 changes: 23 additions & 0 deletions Android/Pedometer/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Pedometer</name>
<comment>Project Pedometer created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions Android/Pedometer/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=..
eclipse.preferences.version=1
42 changes: 42 additions & 0 deletions Android/Pedometer/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "27.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
libraryVariants.all { variant ->
variant.outputs.each { output ->
if (variant.name == android.buildTypes.release.name) {
def file = output.outputFile;
def fileName = "Pedometer.aar"
output.outputFile = new File(file.parent, fileName)
}
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile project(':Unity')
}

task copyToUnity(type: Copy) {
from 'build/outputs/aar/Pedometer.aar'
into '../../Assets/Pedometer/Plugins/Android'
}

assemble.finalizedBy (copyToUnity)
17 changes: 17 additions & 0 deletions Android/Pedometer/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/yusuf/Documents/ADT/SDK/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
11 changes: 11 additions & 0 deletions Android/Pedometer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yusufolokoba.pedometer">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
package com.yusufolokoba.pedometer;

import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.content.pm.PackageManager;
import android.util.Log;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;

/**
* Pedometer
* Created by Yusuf on 06/14/17.
* Created by yusuf on 9/17/18.
*/
public class PedometerActivity extends UnityPlayerActivity implements SensorEventListener {
public class Pedometer implements SensorEventListener {

private Sensor sensor;
private SensorManager manager;
private final PedometerDelegate delegate;

//region --Client API--

public Pedometer (PedometerDelegate delegate) {
this.delegate = delegate;
this.manager = (SensorManager) UnityPlayer.currentActivity.getSystemService(Context.SENSOR_SERVICE);
}

public void initialize () {
// Get sensor manager
manager = manager == null ? (SensorManager)getSystemService(Context.SENSOR_SERVICE) : manager;
// Get sensor
if ((sensor = manager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER)) == null) {
final Sensor sensor = manager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
if (sensor == null) {
Log.e("Unity", "Pedometer Error: Failed to acquire step counter sensor");
return;
}
// Start listening
manager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI);
// Log
Log.d("Unity", "Pedometer: Initialized Android backend");
}

public void release () {
// Stop listening
manager.unregisterListener(this);
// Dereference
sensor = null;
// Log
Log.d("Unity", "Pedometer: Released Android backend");
}

public boolean isSupported () {
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER);
return UnityPlayer.currentActivity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER);
}
//endregion

Expand All @@ -58,12 +54,11 @@ public void onAccuracyChanged (Sensor sensor, int accuracy) {}
@Override
public void onSensorChanged (SensorEvent event) {
// Extract data
final double
STEP2METERS = 0.715d,
steps = event.values[0],
distance = steps * STEP2METERS;
final double STEP2METERS = 0.715d;
final int steps = (int)event.values[0];
final double distance = steps * STEP2METERS;
// Send to Unity
UnityPlayer.UnitySendMessage("Pedometer", "OnEvent", String.format("%d:%f", (int)steps, distance));
delegate.onStep(steps, distance);
}
//endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.yusufolokoba.pedometer;

/**
* Pedometer
* Created by yusuf on 9/17/18.
*/
public interface PedometerDelegate {
void onStep (int steps, double distance);
}
3 changes: 3 additions & 0 deletions Android/Pedometer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Pedometer</string>
</resources>
2 changes: 2 additions & 0 deletions Android/Unity/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
configurations.maybeCreate("default")
artifacts.add("default", file('classes.jar'))
Binary file added Android/Unity/classes.jar
Binary file not shown.
Loading

0 comments on commit e3cce08

Please sign in to comment.