This file contains hidden or 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
import com.google.gson.JsonDeserializationContext | |
import com.google.gson.JsonDeserializer | |
import com.google.gson.JsonElement | |
import com.google.gson.annotations.SerializedName | |
import java.lang.reflect.Type | |
class EnumJsonAdapter<T : Enum<T>>(private val defaultValue: Enum<T>) : JsonDeserializer<Enum<T>> { | |
override fun deserialize( | |
json: JsonElement?, |
This file contains hidden or 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
WorkManager.getInstance(this) | |
.beginUniqueWork("ForegroundWorker", ExistingWorkPolicy.APPEND_OR_REPLACE, | |
OneTimeWorkRequest.from(ForegroundWorker::class.java)).enqueue() |
This file contains hidden or 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
class ForegroundWorker(context: Context, parameters: WorkerParameters) : | |
CoroutineWorker(context, parameters) { | |
private val notificationManager = | |
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | |
override suspend fun doWork(): ListenableWorker.Result = withContext(Dispatchers.IO) { | |
setForeground(createForegroundInfo()) | |
return@withContext runCatching { | |
runTask() |
This file contains hidden or 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
//Fake long running task for 60 seconds | |
private suspend fun runTask() { | |
delay(60000) | |
} |
This file contains hidden or 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
//Creates notifications for service | |
private fun createForegroundInfo(): ForegroundInfo { | |
val id = "1225" | |
val channelName = "Downloads Notification" | |
val title = "Downloading" | |
val cancel = "Cancel" | |
val body = "Long running task is running" | |
val intent = WorkManager.getInstance(applicationContext) |
This file contains hidden or 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
class ForegroundWorker(context: Context, parameters: WorkerParameters) : | |
CoroutineWorker(context, parameters) { | |
override suspend fun doWork(): Result { | |
TODO("Not yet implemented") | |
} | |
} |
This file contains hidden or 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
/** | |
* Touch listener to detect when a user touches the ArScene plane to place a model | |
*/ | |
arFragment.setOnTapArPlaneListener { hitResult, plane, motionEvent -> | |
setModelOnUi(hitResult) | |
} |
This file contains hidden or 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
/** | |
* Used to load model and set it on ArScene where a user Taps | |
*/ | |
private fun setModelOnUi(hitResult: HitResult) { | |
loadModel(R.raw.model) { modelRenderable -> | |
//Used to get anchor point on scene where user tapped | |
val anchor = hitResult.createAnchor() | |
//Created an anchor node to attach the anchor with its parent | |
val anchorNode = AnchorNode(anchor) | |
//Added arSceneView as parent to the anchorNode. So our anchors will bind to arSceneView. |
This file contains hidden or 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
arFragment = fragment as ArFragment | |
/** | |
* Touch listener to detect when a user touches the ArScene plane to place a model | |
*/ | |
arFragment.setOnTapArPlaneListener { hitResult, plane, motionEvent -> | |
} |
This file contains hidden or 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
/** | |
* Used to laod models from 'raw' with a callback when loading is complete | |
*/ | |
fun loadModel(@RawRes model: Int, callback: (ModelRenderable) -> Unit) { | |
ModelRenderable | |
.builder() | |
.setSource(this, model) | |
.build() | |
.thenAccept { modelRenderable -> | |
callback(modelRenderable) |
NewerOlder