-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51a4c66
commit bca8df6
Showing
3 changed files
with
58 additions
and
14 deletions.
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
app/src/main/java/com/kylecorry/trail_sense/shared/views/NorthReferenceBadge.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,53 @@ | ||
package com.kylecorry.trail_sense.shared.views | ||
|
||
import android.content.Context | ||
import android.graphics.Color | ||
import android.util.AttributeSet | ||
import android.widget.FrameLayout | ||
import com.kylecorry.andromeda.core.system.Resources | ||
import com.kylecorry.ceres.badge.CeresBadge | ||
import com.kylecorry.trail_sense.R | ||
import com.kylecorry.trail_sense.shared.FormatService | ||
|
||
class NorthReferenceBadge( | ||
context: Context, | ||
attrs: AttributeSet? = null | ||
) : FrameLayout(context, attrs) { | ||
|
||
private val badge = CeresBadge(context, attrs) | ||
private val formatter = FormatService.getInstance(context) | ||
|
||
var useTrueNorth: Boolean = false | ||
set(value) { | ||
field = value | ||
updateBadge() | ||
} | ||
|
||
var showLabel: Boolean = true | ||
set(value) { | ||
field = value | ||
updateBadge() | ||
} | ||
|
||
init { | ||
badge.layoutParams = LayoutParams( | ||
LayoutParams.WRAP_CONTENT, | ||
LayoutParams.WRAP_CONTENT | ||
) | ||
badge.setBackgroundTint(Color.TRANSPARENT) | ||
badge.setForegroundTint(Resources.androidTextColorSecondary(context)) | ||
useTrueNorth = false | ||
addView(badge) | ||
} | ||
|
||
private fun updateBadge() { | ||
badge.setImageResource(formatter.getCompassReferenceIcon(useTrueNorth)) | ||
val text = when { | ||
!showLabel -> null | ||
useTrueNorth -> context.getString(R.string.true_north) | ||
else -> context.getString(R.string.magnetic_north) | ||
} | ||
badge.setStatusText(text) | ||
} | ||
|
||
} |
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