Skip to content

Commit

Permalink
fix code formating
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Derkach authored and Andrey Derkach committed Jul 25, 2019
1 parent bd0d8b8 commit eeb5008
Show file tree
Hide file tree
Showing 22 changed files with 391 additions and 388 deletions.
Expand Up @@ -18,12 +18,10 @@ abstract class BaseLifecycleActivity : AppCompatActivity() {
setContentView(layoutId)
}

protected fun replaceFragment(
fragment: Fragment,
needToAddToBackStack: Boolean = true,
@AnimRes inAnimRes: Int = 0,
@AnimRes outAnimRes: Int = 0
) {
protected fun replaceFragment(fragment: Fragment,
needToAddToBackStack: Boolean = true,
@AnimRes inAnimRes: Int = 0,
@AnimRes outAnimRes: Int = 0) {
val name = fragment.javaClass.simpleName
supportFragmentManager.beginTransaction().apply {
if (inAnimRes != 0 || outAnimRes != 0) setCustomAnimations(inAnimRes, outAnimRes)
Expand Down Expand Up @@ -66,6 +64,6 @@ abstract class BaseLifecycleActivity : AppCompatActivity() {
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
supportFragmentManager.findFragmentById(containerId)
?.onRequestPermissionsResult(requestCode, permissions, grantResults)
?.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
}
Expand Up @@ -28,7 +28,7 @@ abstract class BaseLifecycleFragment : Fragment() {
protected var toolbar: Toolbar? = null

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
inflater.inflate(layoutId, container, false)
inflater.inflate(layoutId, container, false)

override fun onResume() {
super.onResume()
Expand Down
Expand Up @@ -8,5 +8,5 @@ package com.cleveroad.aropensource.ui.base
* @return first object which implement interface [T]
*/
inline fun <reified T> bindInterfaceOrThrow(vararg objects: Any?): T =
objects.find { it is T } as T
?: throw NotImplementedInterfaceException(T::class.java)
objects.find { it is T } as T
?: throw NotImplementedInterfaceException(T::class.java)
Expand Up @@ -12,9 +12,9 @@ class InstrumentsFragment : BaseLifecycleFragment(), View.OnClickListener {

companion object {
fun newInstance() =
InstrumentsFragment().apply {
arguments = Bundle()
}
InstrumentsFragment().apply {
arguments = Bundle()
}
}

override val layoutId = R.layout.fragment_instruments
Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Expand Up @@ -17,5 +17,3 @@ org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
Expand Up @@ -46,7 +46,7 @@ abstract class BaseLifecycleFragment : Fragment() {
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
inflater.inflate(layoutId, container, false)
inflater.inflate(layoutId, container, false)

override fun onResume() {
super.onResume()
Expand Down Expand Up @@ -157,16 +157,16 @@ abstract class BaseLifecycleFragment : Fragment() {
* @return Screen title
*/
private fun getStringScreenTitle() =
when (getScreenTitle()) {
NO_TITLE -> EMPTY_STRING
else -> getString(getScreenTitle())
}
when (getScreenTitle()) {
NO_TITLE -> EMPTY_STRING
else -> getString(getScreenTitle())
}

@SuppressWarnings("SpreadOperator")
protected fun requestPermission(
vararg permission: String,
isDeniedCallback: () -> Unit = { },
isGrantedCallback: () -> Unit
vararg permission: String,
isDeniedCallback: () -> Unit = { },
isGrantedCallback: () -> Unit
) {
permissionDisposable?.add(rxPermission?.request(*permission)?.subscribe { granted ->
if (granted) isGrantedCallback() else isDeniedCallback()
Expand Down
@@ -1,4 +1,4 @@
package com.cleveroad.arfacedetector.ui.base

fun <T1 : Any, T2 : Any, R : Any> safeLet(p1: T1?, p2: T2?, block: (T1, T2) -> R?): R? =
if (p1 == null || p2 == null) null else block(p1, p2)
if (p1 == null || p2 == null) null else block(p1, p2)
Expand Up @@ -21,11 +21,11 @@ class AugmentedFacesFragment : BaseLifecycleFragment() {
private const val RES_ID_EXTRA = "res_id"

fun newInstance(@DrawableRes resId: Int) =
AugmentedFacesFragment().apply {
arguments = Bundle().apply {
putInt(RES_ID_EXTRA, resId)
AugmentedFacesFragment().apply {
arguments = Bundle().apply {
putInt(RES_ID_EXTRA, resId)
}
}
}
}

override val layoutId = R.layout.fragment_augmented_faces
Expand Down Expand Up @@ -71,10 +71,10 @@ class AugmentedFacesFragment : BaseLifecycleFragment() {
if (!faceNodeMap.containsKey(face)) {
safeLet(bitmap, context) { bitmap, context ->
faceNodeMap[face] =
CustomAugmentedFaceNode(face, context, bitmap)
.apply {
setParent(sceneView.scene)
}
CustomAugmentedFaceNode(face, context, bitmap)
.apply {
setParent(sceneView.scene)
}
}
}
}
Expand Down
Expand Up @@ -18,7 +18,7 @@ import com.google.ar.sceneform.ux.AugmentedFaceNode


class CustomAugmentedFaceNode(augmentedFace: AugmentedFace?, private val context: Context, private val bitmap: Bitmap) :
AugmentedFaceNode(augmentedFace) {
AugmentedFaceNode(augmentedFace) {

companion object {
private const val HALF_DIVIDER = 2
Expand All @@ -33,23 +33,23 @@ class CustomAugmentedFaceNode(augmentedFace: AugmentedFace?, private val context
logoNode?.setParent(this)
logoNode?.isEnabled = isTracking()

val imageView = LayoutInflater.from(context).inflate(R.layout.logo_view, null) as ImageView
val imageView = LayoutInflater.from(context).inflate(R.layout.image_node_view, null) as ImageView
imageView.setImageBitmap(bitmap)

ViewRenderable.builder()
.setView(context, imageView)
.build()
.thenAccept { renderable ->
logoNode?.renderable = renderable
}
.exceptionally { throwable ->
Toast.makeText(context, "Could not load plane card view.", Toast.LENGTH_LONG).show()
throw AssertionError("Could not load plane card view.", throwable)
}
.setView(context, imageView)
.build()
.thenAccept { renderable ->
logoNode?.renderable = renderable
}
.exceptionally { throwable ->
Toast.makeText(context, "Could not load plane card view.", Toast.LENGTH_LONG).show()
throw AssertionError("Could not load plane card view.", throwable)
}
}

private fun isTracking() =
augmentedFace != null && augmentedFace?.trackingState == TrackingState.TRACKING
augmentedFace != null && augmentedFace?.trackingState == TrackingState.TRACKING

override fun onUpdate(frameTime: FrameTime?) {
super.onUpdate(frameTime)
Expand All @@ -61,12 +61,11 @@ class CustomAugmentedFaceNode(augmentedFace: AugmentedFace?, private val context
val leftHeard = getRegionPose(AugmentedFace.RegionType.FOREHEAD_LEFT)

val zCoordinate =
(leftHeard.tz() + rightHeard.tz()) / HALF_DIVIDER + (getRegionPose(AugmentedFace.RegionType.NOSE_TIP).tz() - centerPose.tz()) * -1
logoNode?.worldPosition = Vector3(
(leftHeard.tx() + rightHeard.tx()) / HALF_DIVIDER,
(leftHeard.ty() + rightHeard.ty()) / HALF_DIVIDER,
zCoordinate
)
(leftHeard.tz() + rightHeard.tz()) / HALF_DIVIDER + (getRegionPose(AugmentedFace.RegionType.NOSE_TIP).tz() - centerPose.tz()) * -1
logoNode?.worldPosition =
Vector3((leftHeard.tx() + rightHeard.tx()) / HALF_DIVIDER,
(leftHeard.ty() + rightHeard.ty()) / HALF_DIVIDER,
zCoordinate)
}
}
}
Expand Down
Expand Up @@ -18,12 +18,12 @@ internal class FaceDetectorFragment : ArFragment() {
}

override fun getSessionConfiguration(session: Session?): Config =
Config(session).apply {
augmentedFaceMode = Config.AugmentedFaceMode.MESH3D
}
Config(session).apply {
augmentedFaceMode = Config.AugmentedFaceMode.MESH3D
}

override fun getSessionFeatures(): MutableSet<Session.Feature> =
mutableSetOf(Session.Feature.FRONT_CAMERA)
mutableSetOf(Session.Feature.FRONT_CAMERA)

/**
* Override to turn off planeDiscoveryController. Plane trackables are not supported with the
Expand Down
Expand Up @@ -28,11 +28,11 @@ class FaceDetectorFragment : BaseLifecycleFragment(), CompoundButton.OnCheckedCh
private const val RES_ID_EXTRA = "res_id"

fun newInstance(@DrawableRes resId: Int) =
FaceDetectorFragment().apply {
arguments = Bundle().apply {
putInt(RES_ID_EXTRA, resId)
FaceDetectorFragment().apply {
arguments = Bundle().apply {
putInt(RES_ID_EXTRA, resId)
}
}
}
}

override val layoutId = R.layout.ml_kit_face_detector_fragment
Expand Down Expand Up @@ -61,7 +61,7 @@ class FaceDetectorFragment : BaseLifecycleFragment(), CompoundButton.OnCheckedCh

override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) {
cameraSource?.setFacing(if (isChecked) CAMERA_FACING_FRONT else CAMERA_FACING_BACK)
firePreview?.stop()
cameraSourcePreview?.stop()
startCameraSource()
}

Expand All @@ -72,7 +72,7 @@ class FaceDetectorFragment : BaseLifecycleFragment(), CompoundButton.OnCheckedCh

/** Stops the camera. */
override fun onPause() {
firePreview?.stop()
cameraSourcePreview?.stop()
super.onPause()
}

Expand All @@ -89,9 +89,9 @@ class FaceDetectorFragment : BaseLifecycleFragment(), CompoundButton.OnCheckedCh
private fun startCameraSource() {
cameraSource?.let {
try {
firePreview ?: Log.d(LOG_TAG, "resume: Preview is null")
fireFaceOverlay ?: Log.d(LOG_TAG, "resume: graphOverlay is null")
safeLet(firePreview, fireFaceOverlay) { firePreview, fireFaceOverlay ->
cameraSourcePreview ?: Log.d(LOG_TAG, "resume: Preview is null")
faceOverlay ?: Log.d(LOG_TAG, "resume: graphOverlay is null")
safeLet(cameraSourcePreview, faceOverlay) { firePreview, fireFaceOverlay ->
firePreview.start(cameraSource, fireFaceOverlay)
}
} catch (e: IOException) {
Expand All @@ -105,7 +105,7 @@ class FaceDetectorFragment : BaseLifecycleFragment(), CompoundButton.OnCheckedCh
private fun createCameraSource() {
// If there's no existing cameraSource, create one.
if (cameraSource == null) {
cameraSource = CameraSource(activity, fireFaceOverlay)
cameraSource = CameraSource(activity, faceOverlay)
}
safeLet(context, arguments?.getInt(RES_ID_EXTRA)) { context, resId ->
BitmapUtils.getBitmapFromVectorDrawable(context, resId)?.let {
Expand Down
Expand Up @@ -26,8 +26,10 @@
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresPermission;

import com.google.android.gms.common.images.Size;

import java.io.IOException;
Expand Down

0 comments on commit eeb5008

Please sign in to comment.