-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sighting compass to bearing input
Closes #1186
- Loading branch information
1 parent
2126320
commit b944c65
Showing
5 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
...c/main/java/com/kylecorry/trail_sense/shared/camera/SightingCompassBottomSheetFragment.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.kylecorry.trail_sense.shared.camera | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.DialogInterface | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.util.Size | ||
import android.view.KeyEvent | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.camera.core.ExperimentalZeroShutterLag | ||
import androidx.camera.core.ImageCapture | ||
import androidx.camera.view.PreviewView | ||
import androidx.core.net.toUri | ||
import androidx.core.view.isInvisible | ||
import androidx.core.view.isVisible | ||
import com.kylecorry.andromeda.camera.ImageCaptureSettings | ||
import com.kylecorry.andromeda.fragments.BoundFullscreenDialogFragment | ||
import com.kylecorry.trail_sense.databinding.FragmentPhotoImportSheetBinding | ||
import com.kylecorry.andromeda.fragments.inBackground | ||
import com.kylecorry.sol.units.Bearing | ||
import com.kylecorry.trail_sense.databinding.FragmentSightingCompassSheetBinding | ||
import com.kylecorry.trail_sense.shared.FormatService | ||
import com.kylecorry.trail_sense.shared.extensions.onIO | ||
import com.kylecorry.trail_sense.shared.extensions.onMain | ||
import com.kylecorry.trail_sense.shared.io.FileSubsystem | ||
|
||
class SightingCompassBottomSheetFragment( | ||
private val onSelect: (bearing: Bearing?) -> Unit | ||
) : BoundFullscreenDialogFragment<FragmentSightingCompassSheetBinding>() { | ||
|
||
private val formatter by lazy { FormatService.getInstance(requireContext()) } | ||
|
||
var bearing: Float? = null | ||
set(value) { | ||
field = value | ||
if (isBound) { | ||
updateUI() | ||
} | ||
} | ||
|
||
@SuppressLint("UnsafeOptInUsageError") | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
val volumeKeys = listOf(KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP) | ||
dialog?.setOnKeyListener { _, keyCode, event -> | ||
if (!volumeKeys.contains(keyCode) || event.action != KeyEvent.ACTION_DOWN) { | ||
return@setOnKeyListener false | ||
} | ||
confirmBearing() | ||
true | ||
} | ||
|
||
dialog?.setOnCancelListener { onSelect(null) } | ||
|
||
binding.camera.setScaleType(PreviewView.ScaleType.FIT_CENTER) | ||
binding.camera.clipToOutline = true | ||
binding.camera.start( | ||
lifecycleOwner = this, | ||
readFrames = false | ||
) | ||
|
||
binding.toolTitle.rightButton.setOnClickListener { | ||
onSelect(null) | ||
dismiss() | ||
} | ||
|
||
binding.captureButton.setOnClickListener { | ||
confirmBearing() | ||
} | ||
|
||
updateUI() | ||
} | ||
|
||
private fun updateUI() { | ||
binding.toolTitle.title.text = bearing?.let { formatter.formatDegrees(it) } ?: "" | ||
binding.linearCompass.azimuth = Bearing(bearing ?: 0f) | ||
} | ||
|
||
private fun confirmBearing() { | ||
onSelect(bearing?.let { Bearing(it) }) | ||
dismiss() | ||
} | ||
|
||
override fun onDestroyView() { | ||
if (isBound) { | ||
binding.camera.stop() | ||
} | ||
super.onDestroyView() | ||
} | ||
|
||
override fun onDismiss(dialog: DialogInterface) { | ||
super.onDismiss(dialog) | ||
binding.camera.stop() | ||
} | ||
|
||
override fun generateBinding( | ||
layoutInflater: LayoutInflater, | ||
container: ViewGroup? | ||
): FragmentSightingCompassSheetBinding { | ||
return FragmentSightingCompassSheetBinding.inflate(layoutInflater, container, false) | ||
} | ||
} |
This file contains 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
This file contains 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
62 changes: 62 additions & 0 deletions
62
app/src/main/res/layout/fragment_sighting_compass_sheet.xml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:theme="@style/AppTheme"> | ||
|
||
<com.kylecorry.ceres.toolbar.CeresToolbar | ||
android:id="@+id/tool_title" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
app:flattenButtons="true" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:rightButtonIcon="@drawable/ic_cancel" | ||
app:showSubtitle="false" /> | ||
|
||
<com.kylecorry.trail_sense.shared.views.CameraView | ||
android:id="@+id/camera" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:layout_gravity="center" | ||
android:layout_marginStart="16dp" | ||
android:layout_marginEnd="16dp" | ||
android:background="@drawable/rounded_rectangle" | ||
app:layout_constraintBottom_toTopOf="@id/capture_button" | ||
app:layout_constraintDimensionRatio="H,1:1" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/tool_title" /> | ||
|
||
<View | ||
android:id="@+id/view_camera_line" | ||
android:layout_width="1dp" | ||
android:layout_height="0dp" | ||
android:background="@color/orange_40" | ||
app:layout_constraintBottom_toBottomOf="@id/camera" | ||
app:layout_constraintEnd_toEndOf="@id/camera" | ||
app:layout_constraintStart_toStartOf="@id/camera" | ||
app:layout_constraintTop_toTopOf="@id/camera" /> | ||
|
||
<com.kylecorry.trail_sense.navigation.ui.LinearCompassView | ||
android:id="@+id/linear_compass" | ||
android:layout_width="0dp" | ||
android:layout_height="100dp" | ||
app:layout_constraintBottom_toBottomOf="@id/camera" | ||
app:layout_constraintEnd_toEndOf="@id/camera" | ||
app:layout_constraintStart_toStartOf="@id/camera" | ||
app:layout_constraintTop_toTopOf="@id/camera" /> | ||
|
||
<com.kylecorry.trail_sense.shared.camera.ShutterButton | ||
android:id="@+id/capture_button" | ||
android:layout_width="64dp" | ||
android:layout_height="64dp" | ||
android:layout_marginBottom="16dp" | ||
android:text="@string/camera_capture" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains 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