diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..a2d7c21 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..54d5acd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..d81b54f --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,70 @@ +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' + id 'kotlinx-serialization' + id 'androidx.navigation.safeargs.kotlin' + id 'com.google.secrets_gradle_plugin' version '0.4' +} + +android { + namespace 'de.morhenn.ar_localization' + compileSdk 33 + + defaultConfig { + applicationId "de.morhenn.ar_localization" + minSdk 24 + targetSdk 33 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + buildFeatures { + viewBinding true + } + aaptOptions { + noCompress 'filamat', 'ktx' + } +} + +dependencies { + + implementation 'androidx.core:core-ktx:1.9.0' + implementation 'com.google.android.material:material:1.7.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + + // Navigation component + implementation "androidx.navigation:navigation-fragment-ktx:2.5.3" + implementation "androidx.navigation:navigation-ui-ktx:2.5.3" + + // Play services + implementation 'com.google.android.gms:play-services-maps:18.1.0' + implementation 'com.google.android.gms:play-services-location:21.0.1' + //OAuth + implementation 'com.google.android.gms:play-services-auth:20.3.0' + + // LiveData + implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.5.1" + + //JSON serialization + implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2' + + // SceneView + implementation 'io.github.sceneview:arsceneview:0.6.1-SNAPSHOT' + + implementation 'com.google.ar:core:1.34.0' //need min 1.33 for new cloud console endpoint +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# 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 *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..804ea8c --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/assets/materials/anchor_hosting_point_1_20.filamat b/app/src/main/assets/materials/anchor_hosting_point_1_20.filamat new file mode 100644 index 0000000..893f06f Binary files /dev/null and b/app/src/main/assets/materials/anchor_hosting_point_1_20.filamat differ diff --git a/app/src/main/assets/models/cube.glb b/app/src/main/assets/models/cube.glb new file mode 100644 index 0000000..8a3211b Binary files /dev/null and b/app/src/main/assets/models/cube.glb differ diff --git a/app/src/main/java/de/morhenn/ar_localization/MainActivity.kt b/app/src/main/java/de/morhenn/ar_localization/MainActivity.kt new file mode 100644 index 0000000..04117e2 --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/MainActivity.kt @@ -0,0 +1,12 @@ +package de.morhenn.ar_localization + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle + +class MainActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + } +} \ No newline at end of file diff --git a/app/src/main/java/de/morhenn/ar_localization/MyApplication.kt b/app/src/main/java/de/morhenn/ar_localization/MyApplication.kt new file mode 100644 index 0000000..ab6fe18 --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/MyApplication.kt @@ -0,0 +1,24 @@ +package de.morhenn.ar_localization + +import android.app.Application +import de.morhenn.ar_localization.utils.FileLog + +class MyApplication : Application() { + + companion object { + @JvmField + var initialized = false + const val TAG = "ArLocalizationApp" + } + + override fun onCreate() { + super.onCreate() + if (!initialized) { + initialized = true + //initialize all static utils + + FileLog.init(applicationContext, true) + Thread.setDefaultUncaughtExceptionHandler { _, e -> FileLog.fatal(e) } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/de/morhenn/ar_localization/adapter/FloorPlanListAdapter.kt b/app/src/main/java/de/morhenn/ar_localization/adapter/FloorPlanListAdapter.kt new file mode 100644 index 0000000..36d6a18 --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/adapter/FloorPlanListAdapter.kt @@ -0,0 +1,32 @@ +package de.morhenn.ar_localization.adapter + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import de.morhenn.ar_localization.databinding.ItemFloorPlanListBinding +import de.morhenn.ar_localization.model.FloorPlan + +class FloorPlanListAdapter(private val floorPlanList: List) : RecyclerView.Adapter() { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val binding = ItemFloorPlanListBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return ViewHolder(binding) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.bind(floorPlanList[position], position) + } + + override fun getItemCount(): Int { + return floorPlanList.size + } + + class ViewHolder(private val binding: ItemFloorPlanListBinding) : RecyclerView.ViewHolder(binding.root) { + + fun bind(floorPlan: FloorPlan, position: Int) { + binding.floorPlanListItemName.text = floorPlan.name + binding.floorPlanListItemInfo.text = floorPlan.info + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/de/morhenn/ar_localization/filament/AnchorHostingPoint.kt b/app/src/main/java/de/morhenn/ar_localization/filament/AnchorHostingPoint.kt new file mode 100644 index 0000000..9f92a1e --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/filament/AnchorHostingPoint.kt @@ -0,0 +1,230 @@ +package de.morhenn.ar_localization.filament + +import android.content.Context +import android.opengl.Matrix +import com.google.android.filament.* +import com.google.ar.core.Camera +import com.google.ar.core.Pose +import io.github.sceneview.math.Position +import java.nio.ByteBuffer +import java.nio.ByteOrder +import kotlin.math.* + +class AnchorHostingPoint( + context: Context, + private val engine: Engine, + private val scene: Scene, +) { + + companion object { + + private const val INNER_RADIUS = 0.15f + private const val OUTER_RADIUS = 0.25f + private const val CIRCLE_SEGMENTS_COUNT = 40 + private const val COLOR_SEGMENTS_COUNT = 10 + private const val WHITE = 0xffffffff.toInt() + private const val GREEN = 0xff00ff00.toInt() + + } + + @Entity + private val renderable: Int + private val material: Material + private val vertexBuffer: VertexBuffer + private val indexBuffer: IndexBuffer + private val colorData: ByteBuffer + + private var x = 0f + private var y = 0f + private var z = 0f + + private val highlightedSegments = BooleanArray(COLOR_SEGMENTS_COUNT) + private val matrix = FloatArray(16) + private val projectionMatrix = FloatArray(16) + private val viewMatrix = FloatArray(16) + private val worldPosition = FloatArray(4) + private val clipSpacePosition = FloatArray(4) + + var enabled: Boolean = false + set(value) { + if (value != field) { + field = value + + if (value) scene.addEntity(renderable) + else scene.removeEntity(renderable) + } + } + + val allSegmentsHighlighted + get() = highlightedSegments.all { it } + + init { + material = loadMaterial(context, engine, "anchor_hosting_point_1_20.filamat") + + val n = CIRCLE_SEGMENTS_COUNT + + val intSize = 4 + val floatSize = 4 + val shortSize = 2 + + val vertexSize = 3 * floatSize + val vertexCount = n * 2 + val indexCount = n * 2 * 3 + val vertexData = ByteBuffer.allocate(vertexCount * vertexSize).order(ByteOrder.nativeOrder()) + + for (i in 1..n) { + val angle = PI.toFloat() * 2 * i / n + + val x = cos(angle) + val z = -sin(angle) + + vertexData.putVertex(x * OUTER_RADIUS, 0f, z * OUTER_RADIUS) + vertexData.putVertex(x * INNER_RADIUS, 0f, z * INNER_RADIUS) + } + + vertexData.flip() + colorData = ByteBuffer.allocate(vertexCount * intSize).order(ByteOrder.nativeOrder()) + for (i in 1..n) { + colorData.putInt(WHITE) + colorData.putInt(WHITE) + } + + colorData.flip() + + vertexBuffer = VertexBuffer.Builder() + .bufferCount(2) + .vertexCount(vertexCount) + .attribute(VertexBuffer.VertexAttribute.POSITION, 0, VertexBuffer.AttributeType.FLOAT3, 0, vertexSize) + .attribute(VertexBuffer.VertexAttribute.COLOR, 1, VertexBuffer.AttributeType.UBYTE4, 0, intSize) + .normalized(VertexBuffer.VertexAttribute.COLOR) + .build(engine) + + vertexBuffer.apply { + setBufferAt(engine, 0, vertexData) + setBufferAt(engine, 1, colorData) + } + + val indexData = ByteBuffer.allocate(indexCount * shortSize).order(ByteOrder.nativeOrder()) + + for (i in 0 until n) { + indexData.putShort(i * 2) + indexData.putShort((i + 1) % n * 2) + indexData.putShort(i * 2 + 1) + indexData.putShort((i + 1) % n * 2) + indexData.putShort((i + 1) % n * 2 + 1) + indexData.putShort(i * 2 + 1) + } + + indexData.flip() + + indexBuffer = IndexBuffer.Builder() + .indexCount(indexCount) + .bufferType(IndexBuffer.Builder.IndexType.USHORT) + .build(engine) + + indexBuffer.setBuffer(engine, indexData) + + renderable = EntityManager.get().create() + + RenderableManager.Builder(1) + .boundingBox(Box(0f, 0f, 0f, OUTER_RADIUS, 0.01f, OUTER_RADIUS)) + .geometry(0, RenderableManager.PrimitiveType.TRIANGLES, vertexBuffer, indexBuffer, 0, indexCount) + .material(0, material.defaultInstance) + .build(engine, renderable) + } + + fun setPosition(pose: Pose) { + x = pose.tx() + y = pose.ty() + 0.01f + z = pose.tz() + + Matrix.setIdentityM(matrix, 0) + Matrix.translateM(matrix, 0, x, y, z) + + val transformManager = engine.transformManager + transformManager.setTransform(transformManager.getInstance(renderable), matrix) + } + + fun position(): Position { + return Position(x, y, z) + } + + fun destroy() { + engine.apply { + destroyEntity(renderable) + destroyMaterial(material) + destroyVertexBuffer(vertexBuffer) + destroyIndexBuffer(indexBuffer) + } + } + + fun highlightSegment(cameraPose: Pose) { + val dx = cameraPose.tx() - x + val dz = cameraPose.tz() - z + + var angle = -atan2(dz, dx) + + if (angle < 0) angle += (PI * 2).toFloat() + + val index = floor(angle / (PI * 2) * COLOR_SEGMENTS_COUNT).toInt() + + if (!highlightedSegments[index]) { + highlightedSegments[index] = true + updateColorData(index) + } + } + + fun highlightAllSegments() { + val n = CIRCLE_SEGMENTS_COUNT + + for (i in 1..n) { + colorData.putInt(GREEN) + colorData.putInt(GREEN) + } + + colorData.rewind() + + vertexBuffer.setBufferAt(engine, 1, colorData) + } + + fun isInFrame(camera: Camera): Boolean { + camera.getProjectionMatrix(projectionMatrix, 0, 0.01f, 30f) + camera.getViewMatrix(viewMatrix, 0) + + Matrix.multiplyMM(matrix, 0, projectionMatrix, 0, viewMatrix, 0) + + worldPosition[0] = x + worldPosition[1] = y + worldPosition[2] = z + worldPosition[3] = 1f + + Matrix.multiplyMV(clipSpacePosition, 0, matrix, 0, worldPosition, 0) + + val clipSpaceX = clipSpacePosition[0] / clipSpacePosition[3] + val clipSpaceY = clipSpacePosition[1] / clipSpacePosition[3] + + return clipSpaceX in -1f..1f && clipSpaceY in -1f..1f + } + + private fun updateColorData(index: Int) { + val n = CIRCLE_SEGMENTS_COUNT + val ratio = CIRCLE_SEGMENTS_COUNT / COLOR_SEGMENTS_COUNT + + val intSize = 4 + for (i in 1..n) { + when { + i >= index * ratio && i <= (index + 1) * ratio + 1 + || index == COLOR_SEGMENTS_COUNT - 1 && i <= 1 -> { + colorData.putInt(GREEN) + colorData.putInt(GREEN) + } + else -> { + colorData.position(colorData.position() + 2 * intSize) + } + } + } + + colorData.rewind() + vertexBuffer.setBufferAt(engine, 1, colorData) + } +} diff --git a/app/src/main/java/de/morhenn/ar_localization/filament/ByteBuffer.kt b/app/src/main/java/de/morhenn/ar_localization/filament/ByteBuffer.kt new file mode 100644 index 0000000..76d869f --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/filament/ByteBuffer.kt @@ -0,0 +1,19 @@ +package de.morhenn.ar_localization.filament + +import java.nio.ByteBuffer + +fun ByteBuffer.putShort(value: Int): ByteBuffer = putShort(value.toShort()) + +fun ByteBuffer.putVertex(x: Float, y: Float, z: Float): ByteBuffer { + putFloat(x) + putFloat(y) + putFloat(z) + return this +} + +fun ByteBuffer.putTriangle(first: Int, second: Int, third: Int): ByteBuffer { + putShort(first) + putShort(second) + putShort(third) + return this +} diff --git a/app/src/main/java/de/morhenn/ar_localization/filament/Filament.kt b/app/src/main/java/de/morhenn/ar_localization/filament/Filament.kt new file mode 100644 index 0000000..b41bc1f --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/filament/Filament.kt @@ -0,0 +1,24 @@ +package de.morhenn.ar_localization.filament + +import android.content.Context +import com.google.android.filament.Engine +import com.google.android.filament.Material +import java.nio.ByteBuffer +import java.nio.channels.Channels + +fun loadMaterial(context: Context, engine: Engine, name: String): Material { + val dst: ByteBuffer + + context.assets.openFd("materials/$name").use { fd -> + val input = fd.createInputStream() + dst = ByteBuffer.allocate(fd.length.toInt()) + + val src = Channels.newChannel(input) + src.read(dst) + src.close() + + dst.rewind() + } + + return Material.Builder().payload(dst, dst.remaining()).build(engine) +} diff --git a/app/src/main/java/de/morhenn/ar_localization/fragments/AugmentedRealityFragment.kt b/app/src/main/java/de/morhenn/ar_localization/fragments/AugmentedRealityFragment.kt new file mode 100644 index 0000000..697dca3 --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/fragments/AugmentedRealityFragment.kt @@ -0,0 +1,194 @@ +package de.morhenn.ar_localization.fragments + +import android.net.Uri +import android.os.Bundle +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.fragment.app.viewModels +import androidx.lifecycle.lifecycleScope +import com.google.ar.core.Anchor +import com.google.ar.core.Config +import com.google.ar.sceneform.rendering.ModelRenderable +import com.google.ar.sceneform.rendering.Renderable +import com.google.ar.sceneform.rendering.ResourceManager +import de.morhenn.ar_localization.databinding.FragmentAugmentedRealityBinding +import de.morhenn.ar_localization.filament.AnchorHostingPoint +import de.morhenn.ar_localization.fragments.AugmentedRealityFragment.ArState.* +import de.morhenn.ar_localization.fragments.AugmentedRealityFragment.ModelName.DEBUG_CUBE +import de.morhenn.ar_localization.viewmodel.AugmentedRealityViewModel +import io.github.sceneview.Filament +import io.github.sceneview.ar.ArSceneView +import io.github.sceneview.ar.arcore.ArFrame +import io.github.sceneview.ar.arcore.LightEstimationMode +import io.github.sceneview.ar.arcore.planeFindingEnabled +import io.github.sceneview.ar.node.ArModelNode +import io.github.sceneview.ar.node.PlacementMode +import io.github.sceneview.model.await +import java.util.* + +class AugmentedRealityFragment : Fragment() { + + enum class ArState( + val progressBarVisibility: Int = View.INVISIBLE, + val fabEnabled: Boolean = false, + ) { + NOT_INITIALIZED, + PLACE_ANCHOR(fabEnabled = true), + SCAN_ANCHOR_CIRCLE, + HOSTING(progressBarVisibility = View.VISIBLE), + HOST_SUCCESS, + HOST_FAILED, + } + + enum class ArMode { + CREATE_FLOOR_PLAN, + LOCALIZE + } + + enum class ModelName { + DEBUG_CUBE, + } + + private var arState: ArState = NOT_INITIALIZED + private var arMode: ArMode = ArMode.CREATE_FLOOR_PLAN + + //viewBinding + private var _binding: FragmentAugmentedRealityBinding? = null + private val binding get() = _binding!! + + private val viewModelAR: AugmentedRealityViewModel by viewModels() + + private lateinit var sceneView: ArSceneView + + private var modelMap: EnumMap = EnumMap(ModelName::class.java) + private lateinit var anchorHostingCircle: AnchorHostingPoint + private var placementNode: ArModelNode? = null + private var anchorNode: ArModelNode? = null + + + private var startRotation: Float = 0f + + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + _binding = FragmentAugmentedRealityBinding.inflate(inflater, container, false) + + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + lifecycleScope.launchWhenCreated { + loadModels() + } + sceneView = binding.sceneView + sceneView.lightEstimationMode = LightEstimationMode.AMBIENT_INTENSITY + + sceneView.onArSessionCreated = { + sceneView.configureSession { _, config -> + config.planeFindingEnabled = true + config.cloudAnchorMode = Config.CloudAnchorMode.ENABLED + config.geospatialMode = Config.GeospatialMode.ENABLED + } + } + + sceneView.onArFrame = { frame -> + onArFrame(frame) + } + } + + private fun onArFrame(frame: ArFrame) { + when (arState) { + NOT_INITIALIZED -> { + if (frame.isTrackingPlane) { + initializeAR() + } + } + PLACE_ANCHOR -> { + placementNode?.let { + it.pose?.let { pose -> + anchorHostingCircle.setPosition(pose) + } + } + } + SCAN_ANCHOR_CIRCLE -> { + if (anchorHostingCircle.isInFrame(frame.camera)) { + anchorHostingCircle.highlightSegment(frame.camera.pose) + } + if (anchorHostingCircle.allSegmentsHighlighted) { + hostCloudAnchor() + } + } + else -> {} //NOOP + } + } + + private fun initializeAR() { + updateState(PLACE_ANCHOR) + anchorHostingCircle = AnchorHostingPoint(requireContext(), Filament.engine, sceneView.renderer.filamentScene) + anchorHostingCircle.enabled = true + placementNode = ArModelNode(placementMode = PlacementMode.PLANE_HORIZONTAL).apply { + parent = sceneView + isVisible = true + } + } + + private fun hostCloudAnchor() { + updateState(HOSTING) + anchorNode?.let { anchorNode -> + anchorNode.hostCloudAnchor(365) { anchor: Anchor, success: Boolean -> + if (success) { + updateState(HOST_SUCCESS) + anchorNode.isVisible = true + anchorHostingCircle.enabled = false + Log.d("O_O", "Cloud anchor hosted successfully") + } else { + updateState(HOST_FAILED) + Log.d("O_O", "Cloud anchor hosting failed") + } + } + } + } + + private fun onPlaceClicked() { + placementNode?.let { + updateState(SCAN_ANCHOR_CIRCLE) + anchorNode = ArModelNode(PlacementMode.DISABLED).apply { + parent = sceneView + anchor = it.createAnchor() + isVisible = false + setModel(modelMap[DEBUG_CUBE]) + } + startRotation = sceneView.camera.transform.rotation.y + } + } + + private fun updateState(state: ArState) { + arState = state + binding.arExtendedFab.isEnabled = arState.fabEnabled + binding.arProgressBar.visibility = arState.progressBarVisibility + binding.arExtendedFab.setOnClickListener { + when (arState) { + PLACE_ANCHOR -> onPlaceClicked() + else -> {} //NOOP + } + } + } + + private suspend fun loadModels() { + modelMap[DEBUG_CUBE] = ModelRenderable.builder() + .setSource(context, Uri.parse("models/cube.glb")) + .setIsFilamentGltf(true) + .await(lifecycle) + } + + override fun onDestroy() { + //TODO this is only needed in 0.6.0, since it is in sceneView for newer versions + ResourceManager.getInstance().destroyAllResources() + + super.onDestroy() + } +} \ No newline at end of file diff --git a/app/src/main/java/de/morhenn/ar_localization/fragments/FloorPlanListFragment.kt b/app/src/main/java/de/morhenn/ar_localization/fragments/FloorPlanListFragment.kt new file mode 100644 index 0000000..ed605dc --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/fragments/FloorPlanListFragment.kt @@ -0,0 +1,42 @@ +package de.morhenn.ar_localization.fragments + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.navigation.fragment.findNavController +import androidx.navigation.navGraphViewModels +import androidx.recyclerview.widget.LinearLayoutManager +import de.morhenn.ar_localization.R +import de.morhenn.ar_localization.databinding.FragmentFloorPlanListBinding +import de.morhenn.ar_localization.model.FloorPlan +import de.morhenn.ar_localization.utils.FileLog +import de.morhenn.ar_localization.viewmodel.FloorPlanViewModel + +class FloorPlanListFragment : Fragment() { + + //viewBinding + private var _binding: FragmentFloorPlanListBinding? = null + private val binding get() = _binding!! + + private val viewModelFloorPlan: FloorPlanViewModel by navGraphViewModels(R.id.nav_graph_xml) + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + _binding = FragmentFloorPlanListBinding.inflate(inflater, container, false) + + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + binding.floorPlanList.layoutManager = LinearLayoutManager(requireContext()) + binding.floorPlanList.adapter = viewModelFloorPlan.listAdapter + + binding.fabFloorPlanList.setOnClickListener { + findNavController().navigate(FloorPlanListFragmentDirections.actionFloorPlanListFragmentToAugmentedRealityFragment()) + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/de/morhenn/ar_localization/model/CloudAnchor.kt b/app/src/main/java/de/morhenn/ar_localization/model/CloudAnchor.kt new file mode 100644 index 0000000..6b5ea70 --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/model/CloudAnchor.kt @@ -0,0 +1,25 @@ +package de.morhenn.ar_localization.model + +import io.github.sceneview.math.Rotation +import kotlinx.serialization.Serializable + +@Serializable +data class CloudAnchor( + var text: String, //description to search by + var cloudAnchorId: String, + + //geo position of the anchor + var lat: Double, + var lng: Double, + var alt: Double, + var compassHeading: Double, + + //relative position of the anchor to current main anchor + var relativeX: Float, + var relativeY: Float, + var relativeZ: Float, + var relativeQuaternion: SerializableQuaternion, //TODO use quaternion or euler angles, or constrain to always the main anchors rotation? +) { + constructor(text: String, cloudAnchorId: String, lat: Double, lng: Double, alt: Double, compassHeading: Double) : + this(text, cloudAnchorId, lat, lng, alt, compassHeading, 0.0f, 0.0f, 0.0f, SerializableQuaternion()) +} diff --git a/app/src/main/java/de/morhenn/ar_localization/model/FloorPlan.kt b/app/src/main/java/de/morhenn/ar_localization/model/FloorPlan.kt new file mode 100644 index 0000000..3a7ac3c --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/model/FloorPlan.kt @@ -0,0 +1,14 @@ +package de.morhenn.ar_localization.model + +import kotlinx.serialization.Serializable + +@Serializable +data class FloorPlan( + var name: String, + var info: String, + //TODO author / owner / permissions + var mainAnchor: CloudAnchor, + var mappingPointList: List, + var cloudAnchorList: List + +) diff --git a/app/src/main/java/de/morhenn/ar_localization/model/MappingPoint.kt b/app/src/main/java/de/morhenn/ar_localization/model/MappingPoint.kt new file mode 100644 index 0000000..c26d982 --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/model/MappingPoint.kt @@ -0,0 +1,11 @@ +package de.morhenn.ar_localization.model + +import kotlinx.serialization.Serializable + +@Serializable +data class MappingPoint( + var relativeX: Float, + var relativeY: Float, + var relativeZ: Float, + var relativeQuaternion: SerializableQuaternion, +) diff --git a/app/src/main/java/de/morhenn/ar_localization/model/SerializableQuaternion.kt b/app/src/main/java/de/morhenn/ar_localization/model/SerializableQuaternion.kt new file mode 100644 index 0000000..50fb985 --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/model/SerializableQuaternion.kt @@ -0,0 +1,17 @@ +package de.morhenn.ar_localization.model + +import dev.romainguy.kotlin.math.Quaternion +import kotlinx.serialization.Serializable + +@Serializable +data class SerializableQuaternion( + var x: Float, + var y: Float, + var z: Float, + var w: Float, +) { + constructor(q: Quaternion) : this(q.x, q.y, q.z, q.w) + constructor() : this(1f, 0f, 0f, 0f) + + fun toQuaternion(): Quaternion = Quaternion(x, y, z, w) +} diff --git a/app/src/main/java/de/morhenn/ar_localization/utils/FileLog.kt b/app/src/main/java/de/morhenn/ar_localization/utils/FileLog.kt new file mode 100644 index 0000000..72f84d7 --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/utils/FileLog.kt @@ -0,0 +1,168 @@ +package de.morhenn.ar_localization.utils + +import android.content.Context +import android.util.Log +import java.io.File +import java.io.PrintWriter +import java.io.StringWriter +import java.text.SimpleDateFormat +import java.util.* +import kotlin.system.exitProcess + +object FileLog { + + private const val FILE_NAME = "ArLocalization.txt" + private const val FATAL_TAG = "FATAL" + private const val MAX_FILE_LINES = 3000 + private const val MAX_RANK = 10 + private var logToLogcat = false + private var fileDir: File? = null + + fun init(context: Context, logToLogcat: Boolean) { + fileDir = context.filesDir + writeBlankLine() + write("[-- AR-Navigation launched --]") + FileLog.logToLogcat = logToLogcat + if (FileLog.logToLogcat) { + Log.i("de.morhenn.ar_navigation.util.FileLog", "AR-Navigation launched") + } + } + + fun d(tag: String, message: String) { + if (logToLogcat) { + Log.d(tag, message) + if (message.length > 4000) { + Log.d(tag, "Message was too long, a part might have been cut off! Length was ${message.length}") + } + } + write("D/$tag: $message") + } + + fun d(tag: String, logBuffer: LogBuffer) { + d(tag, "", logBuffer) + } + + fun d(tag: String, message: String, logBuffer: LogBuffer) { + d(tag, "$message\n${logBuffer.retrieveLog()}") + } + + fun w(tag: String, message: String) { + if (logToLogcat) { + Log.w(tag, message) + } + write("W/$tag: $message") + } + + fun e(tag: String, message: String) { + if (logToLogcat) { + Log.e(tag, message) + } + write("E/$tag: $message") + } + + fun e(tag: String, throwable: Throwable) { + if (logToLogcat) { + Log.e(tag, null, throwable) + } + val sw = StringWriter() + val pw = PrintWriter(sw) + throwable.printStackTrace(pw) + write("E/$tag: $sw") + } + + fun e(tag: String, message: String, throwable: Throwable) { + if (logToLogcat) { + Log.e(tag, message, throwable) + } + val sw = StringWriter() + val pw = PrintWriter(sw) + throwable.printStackTrace(pw) + write("E/$tag: $message ${System.lineSeparator()} $sw") + } + + fun fatal(throwable: Throwable) { + //surround with try and catch to prevent having to handle a potential log crash (infinite loop) + try { + e(FATAL_TAG, "A fatal crash caused the app to stop", throwable) + } catch (e: Exception) { + e.printStackTrace() + } + exitProcess(1) + } + + private fun writeBlankLine() { + val file = File(fileDir, FILE_NAME) + file.appendText(System.lineSeparator()) + } + + private fun write(text: String) { + val file = File(fileDir, FILE_NAME) + file.appendText("${currentTimeAsString()} $text") + file.appendText(System.lineSeparator()) + var lines = file.readLines() + val size = lines.size + val overSize = size - MAX_FILE_LINES + if (overSize > 0) { + lines = lines.drop(overSize) + val result = lines.joinToString(separator = System.lineSeparator()) + file.writeText(result) + file.appendText(System.lineSeparator()) + } + } + + private fun currentTimeAsString(): String { + val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US) + return sdf.format(Date()) + } + + open class LogBuffer { + //TODO limit lines to prevent overflow / heavy memory usage + private val stringBuilder = StringBuilder() + fun append(msg: String) { + stringBuilder.append(msg) + } + + fun appendLine(msg: String) { + append("$msg\n") + } + + fun retrieveLog(): String { + val result = stringBuilder.toString() + stringBuilder.clear() + return result + } + + fun reset() { + stringBuilder.clear() + } + } + + class RankedLogBuffer : LogBuffer() { + private val prefixStringBuilder = StringBuilder() + fun appendLine(msg: String, rank: Int) { + if (rank < 0 || rank > MAX_RANK) { + throw IllegalArgumentException("Rank may only be between 0 and $MAX_RANK (inclusive)") + } + if (rank != 0) { + repeat(rank - 1) { + append("│ ") + } + append("├─ ") + } + if (msg.contains("\n")) { + var newMsg = msg + if (rank != 0) { + repeat(rank - 1) { + prefixStringBuilder.append("│ ") + } + prefixStringBuilder.append("├─ ") //Two spaces indicate a newline inside the ranked message + newMsg = msg.replace("\n", "\n$prefixStringBuilder").removeSuffix("\n$prefixStringBuilder") + prefixStringBuilder.clear() + } + appendLine(newMsg) + } else { + appendLine(msg) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/de/morhenn/ar_localization/viewmodel/AugmentedRealityViewModel.kt b/app/src/main/java/de/morhenn/ar_localization/viewmodel/AugmentedRealityViewModel.kt new file mode 100644 index 0000000..b6ab1a5 --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/viewmodel/AugmentedRealityViewModel.kt @@ -0,0 +1,6 @@ +package de.morhenn.ar_localization.viewmodel + +import androidx.lifecycle.ViewModel + +class AugmentedRealityViewModel : ViewModel() { +} \ No newline at end of file diff --git a/app/src/main/java/de/morhenn/ar_localization/viewmodel/FloorPlanViewModel.kt b/app/src/main/java/de/morhenn/ar_localization/viewmodel/FloorPlanViewModel.kt new file mode 100644 index 0000000..d7b163c --- /dev/null +++ b/app/src/main/java/de/morhenn/ar_localization/viewmodel/FloorPlanViewModel.kt @@ -0,0 +1,31 @@ +package de.morhenn.ar_localization.viewmodel + +import androidx.lifecycle.ViewModel +import de.morhenn.ar_localization.adapter.FloorPlanListAdapter +import de.morhenn.ar_localization.model.CloudAnchor +import de.morhenn.ar_localization.model.FloorPlan +import de.morhenn.ar_localization.model.MappingPoint +import de.morhenn.ar_localization.model.SerializableQuaternion + +class FloorPlanViewModel : ViewModel() { + + val floorPlanList: ArrayList = ArrayList() + val listAdapter = FloorPlanListAdapter(floorPlanList) + + init { + loadDebugFloorPlan() + } + + private fun loadDebugFloorPlan() { + val mainCloudAnchor = CloudAnchor("main", "noRealID", 0.0, 0.0, 0.0, 0.0) + val mappingPoint = MappingPoint(1f, 1f, 0f, SerializableQuaternion()) + val floorPlan = FloorPlan( + "Debug Floor Plan", + "This is a debug floor plan. It is used for testing purposes only.", + mainCloudAnchor, + listOf(mappingPoint), + listOf(mainCloudAnchor) + ) + floorPlanList.add(0, floorPlan) + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_baseline_add_24.xml b/app/src/main/res/drawable/ic_baseline_add_24.xml new file mode 100644 index 0000000..89633bb --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_add_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_place_item_24.xml b/app/src/main/res/drawable/ic_place_item_24.xml new file mode 100644 index 0000000..9aa58d3 --- /dev/null +++ b/app/src/main/res/drawable/ic_place_item_24.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..17710a8 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_augmented_reality.xml b/app/src/main/res/layout/fragment_augmented_reality.xml new file mode 100644 index 0000000..442c748 --- /dev/null +++ b/app/src/main/res/layout/fragment_augmented_reality.xml @@ -0,0 +1,42 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_floor_plan_list.xml b/app/src/main/res/layout/fragment_floor_plan_list.xml new file mode 100644 index 0000000..9242433 --- /dev/null +++ b/app/src/main/res/layout/fragment_floor_plan_list.xml @@ -0,0 +1,23 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_floor_plan_list.xml b/app/src/main/res/layout/item_floor_plan_list.xml new file mode 100644 index 0000000..8428d5a --- /dev/null +++ b/app/src/main/res/layout/item_floor_plan_list.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml new file mode 100644 index 0000000..976a1c9 --- /dev/null +++ b/app/src/main/res/navigation/nav_graph.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..6ee7998 --- /dev/null +++ b/app/src/main/res/values-night/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..41f0e0a --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + AR-Localization + Button to create a new Floor Plan + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..de0b28d --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/backup_rules.xml b/app/src/main/res/xml/backup_rules.xml new file mode 100644 index 0000000..fa0f996 --- /dev/null +++ b/app/src/main/res/xml/backup_rules.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/data_extraction_rules.xml b/app/src/main/res/xml/data_extraction_rules.xml new file mode 100644 index 0000000..9ee9997 --- /dev/null +++ b/app/src/main/res/xml/data_extraction_rules.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..e30d532 --- /dev/null +++ b/build.gradle @@ -0,0 +1,16 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + ext.kotlin_version = '1.7.20' + ext.nav_version = "2.5.3" + dependencies { + classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" + classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1" + + classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" + } +} +plugins { + id 'com.android.application' version '7.3.1' apply false + id 'com.android.library' version '7.3.1' apply false + id 'org.jetbrains.kotlin.android' version '1.7.20' apply false +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..3c5031e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,23 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..6a87db2 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Oct 28 10:38:16 CEST 2022 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..4f906e0 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..355f3d9 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,17 @@ +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenLocal() + mavenCentral() + } +} +rootProject.name = "ar-localization" +include ':app'