Skip to content

Commit 571fcde

Browse files
committed
Update the ui
1 parent 905373e commit 571fcde

44 files changed

Lines changed: 462 additions & 473 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ java {
3030
}
3131

3232
android {
33-
namespace = "com.bobek.compass"
33+
namespace = "com.earendel.compass"
3434
compileSdk = 36
3535

3636
defaultConfig {
37-
applicationId = "com.bobek.compass"
37+
applicationId = "com.earendel.compass"
3838
minSdk = 23
3939
targetSdk = 36
4040
versionCode = 31

app/src/androidTest/java/com/bobek/compass/AbstractAndroidTest.kt renamed to app/src/androidTest/java/com/earendel/compass/AbstractAndroidTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
package com.bobek.compass
19+
package com.earendel.compass
2020

2121
import android.content.Intent
2222
import androidx.navigation.fragment.NavHostFragment
2323
import androidx.test.core.app.ApplicationProvider
2424
import androidx.test.ext.junit.rules.ActivityScenarioRule
2525
import androidx.test.ext.junit.runners.AndroidJUnit4
26-
import com.bobek.compass.model.Azimuth
27-
import com.bobek.compass.model.SensorAccuracy
26+
import com.earendel.compass.model.Azimuth
27+
import com.earendel.compass.model.SensorAccuracy
2828
import org.junit.Rule
2929
import org.junit.runner.RunWith
3030

app/src/androidTest/java/com/bobek/compass/InstrumentedTest.kt renamed to app/src/androidTest/java/com/earendel/compass/InstrumentedTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
package com.bobek.compass
19+
package com.earendel.compass
2020

2121
import androidx.test.espresso.Espresso.onView
2222
import androidx.test.espresso.action.ViewActions.click
@@ -25,7 +25,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
2525
import androidx.test.espresso.matcher.ViewMatchers.withId
2626
import androidx.test.espresso.matcher.ViewMatchers.withText
2727
import androidx.test.filters.LargeTest
28-
import com.bobek.compass.model.SensorAccuracy
28+
import com.earendel.compass.model.SensorAccuracy
2929
import org.hamcrest.Matchers.not
3030
import org.junit.Test
3131

app/src/androidTest/java/com/bobek/compass/screengrab/ScreengrabTest.kt renamed to app/src/androidTest/java/com/earendel/compass/screengrab/ScreengrabTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
package com.bobek.compass.screengrab
19+
package com.earendel.compass.screengrab
2020

2121
import androidx.test.filters.LargeTest
2222
import androidx.test.platform.app.InstrumentationRegistry
23-
import com.bobek.compass.AbstractAndroidTest
23+
import com.earendel.compass.AbstractAndroidTest
2424
import org.junit.AfterClass
2525
import org.junit.BeforeClass
2626
import org.junit.Rule

app/src/main/java/com/bobek/compass/CompassApplication.kt renamed to app/src/main/java/com/earendel/compass/CompassApplication.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
package com.bobek.compass
19+
package com.earendel.compass
2020

2121
import android.app.Application
22-
import com.bobek.compass.preference.PreferenceMigrations
22+
import com.earendel.compass.preference.PreferenceMigrations
2323
import com.google.android.material.color.DynamicColors
2424

2525
class CompassApplication : Application() {

app/src/main/java/com/bobek/compass/CompassFragment.kt renamed to app/src/main/java/com/earendel/compass/CompassFragment.kt

Lines changed: 73 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
package com.bobek.compass
19+
package com.earendel.compass
2020

2121
import android.Manifest.permission.ACCESS_COARSE_LOCATION
2222
import android.Manifest.permission.ACCESS_FINE_LOCATION
23+
import android.content.pm.ActivityInfo
2324
import android.content.pm.PackageManager.PERMISSION_GRANTED
2425
import android.content.res.ColorStateList
2526
import android.hardware.Sensor
@@ -54,17 +55,17 @@ import androidx.fragment.app.Fragment
5455
import androidx.fragment.app.viewModels
5556
import androidx.lifecycle.Lifecycle
5657
import androidx.navigation.fragment.findNavController
57-
import com.bobek.compass.databinding.FragmentCompassBinding
58-
import com.bobek.compass.databinding.SensorAlertDialogViewBinding
59-
import com.bobek.compass.model.AppError
60-
import com.bobek.compass.model.Azimuth
61-
import com.bobek.compass.model.DisplayRotation
62-
import com.bobek.compass.model.LocationStatus
63-
import com.bobek.compass.model.RotationVector
64-
import com.bobek.compass.model.SensorAccuracy
65-
import com.bobek.compass.preference.PreferenceStore
66-
import com.bobek.compass.util.MathUtils
67-
import com.bobek.compass.view.CompassViewModel
58+
import com.earendel.compass.databinding.FragmentCompassBinding
59+
import com.earendel.compass.databinding.SensorAlertDialogViewBinding
60+
import com.earendel.compass.model.AppError
61+
import com.earendel.compass.model.Azimuth
62+
import com.earendel.compass.model.DisplayRotation
63+
import com.earendel.compass.model.LocationStatus
64+
import com.earendel.compass.model.RotationVector
65+
import com.earendel.compass.model.SensorAccuracy
66+
import com.earendel.compass.preference.PreferenceStore
67+
import com.earendel.compass.util.MathUtils
68+
import com.earendel.compass.view.CompassViewModel
6869
import com.google.android.material.color.MaterialColors
6970
import com.google.android.material.dialog.MaterialAlertDialogBuilder
7071
import java.util.concurrent.Executor
@@ -112,6 +113,14 @@ class CompassFragment : Fragment() {
112113
preferenceStore.hapticFeedback.observe(viewLifecycleOwner) {
113114
compassViewModel.hapticFeedback.value = it
114115
}
116+
preferenceStore.isRotationEnabled.observe(viewLifecycleOwner) { isEnabled ->
117+
requireActivity().requestedOrientation = if (isEnabled) {
118+
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
119+
} else {
120+
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
121+
}
122+
compassViewModel.isRotationEnabled.value = isEnabled
123+
}
115124
}
116125
}
117126

@@ -336,31 +345,70 @@ class CompassFragment : Fragment() {
336345
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
337346
menuInflater.inflate(R.menu.menu_compass, menu)
338347
optionsMenu = menu
348+
349+
val sensorItem = menu.findItem(R.id.action_sensor_status)
350+
sensorItem.actionView?.setOnClickListener {
351+
onMenuItemSelected(sensorItem)
352+
}
353+
339354
compassViewModel.sensorAccuracy.observe(viewLifecycleOwner) { updateSensorStatusIcon(it) }
340-
requirePreferenceStore().screenOrientationLocked.observe(viewLifecycleOwner) { updateScreenRotationIcon(it) }
341355
}
342356

343357
private fun updateSensorStatusIcon(sensorAccuracy: SensorAccuracy) {
344-
val menuItem = optionsMenu?.findItem(R.id.action_sensor_status)
345-
menuItem?.setIcon(sensorAccuracy.iconResourceId)
358+
val menuItem = optionsMenu?.findItem(R.id.action_sensor_status) ?: return
359+
360+
// Update legacy icon just in case
361+
menuItem.setIcon(sensorAccuracy.iconResourceId)
362+
363+
// Update new ActionView (Vertical Pills)
364+
val actionView = menuItem.actionView
365+
if (actionView != null) {
366+
val pill1 = actionView.findViewById<View>(R.id.sensor_pill_small)
367+
val pill2 = actionView.findViewById<View>(R.id.sensor_pill_medium)
368+
val pill3 = actionView.findViewById<View>(R.id.sensor_pill_large)
369+
370+
if (pill1 != null && pill2 != null && pill3 != null) {
371+
val typedValue = android.util.TypedValue()
372+
requireContext().theme.resolveAttribute(android.R.attr.isLightTheme, typedValue, true)
373+
val isLightTheme = typedValue.data != 0
374+
375+
val activeColor = ContextCompat.getColor(requireContext(), if (isLightTheme) R.color.pure_black else R.color.pure_white)
376+
val inactiveColor = ContextCompat.getColor(requireContext(), R.color.gray_medium)
377+
val errorColor = ContextCompat.getColor(requireContext(), android.R.color.holo_red_dark)
378+
379+
when (sensorAccuracy) {
380+
SensorAccuracy.HIGH -> {
381+
pill1.background?.setTint(activeColor); pill1.alpha = 1.0f
382+
pill2.background?.setTint(activeColor); pill2.alpha = 1.0f
383+
pill3.background?.setTint(activeColor); pill3.alpha = 1.0f
384+
}
385+
SensorAccuracy.MEDIUM -> {
386+
pill1.background?.setTint(activeColor); pill1.alpha = 1.0f
387+
pill2.background?.setTint(activeColor); pill2.alpha = 1.0f
388+
pill3.background?.setTint(inactiveColor); pill3.alpha = 0.2f
389+
}
390+
SensorAccuracy.LOW -> {
391+
pill1.background?.setTint(activeColor); pill1.alpha = 1.0f
392+
pill2.background?.setTint(inactiveColor); pill2.alpha = 0.2f
393+
pill3.background?.setTint(inactiveColor); pill3.alpha = 0.2f
394+
}
395+
SensorAccuracy.UNRELIABLE, SensorAccuracy.NO_CONTACT -> {
396+
pill1.background?.setTint(errorColor); pill1.alpha = 1.0f
397+
pill2.background?.setTint(inactiveColor); pill2.alpha = 0.2f
398+
pill3.background?.setTint(inactiveColor); pill3.alpha = 0.2f
399+
}
400+
}
401+
}
402+
}
346403

347404
if (VERSION.SDK_INT >= VERSION_CODES.O) {
348405
sensorAccuracy.iconTintAttributeResourceId
349406
.let { MaterialColors.getColor(requireContext(), it, this::class.simpleName) }
350407
.let { ColorStateList.valueOf(it) }
351-
.also { menuItem?.iconTintList = it }
408+
.also { menuItem.iconTintList = it }
352409
}
353410
}
354411

355-
private fun updateScreenRotationIcon(screenOrientationLocked: Boolean) {
356-
optionsMenu
357-
?.findItem(R.id.action_screen_rotation)
358-
?.setIcon(getScreenRotationIcon(screenOrientationLocked))
359-
}
360-
361-
@DrawableRes
362-
private fun getScreenRotationIcon(screenOrientationLocked: Boolean): Int =
363-
if (screenOrientationLocked) R.drawable.ic_screen_rotation_lock else R.drawable.ic_screen_rotation
364412

365413
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
366414
return when (menuItem.itemId) {
@@ -369,10 +417,6 @@ class CompassFragment : Fragment() {
369417
true
370418
}
371419

372-
R.id.action_screen_rotation -> {
373-
toggleRotationScreenLocked()
374-
true
375-
}
376420

377421
R.id.action_settings -> {
378422
showSettings()
@@ -398,12 +442,6 @@ class CompassFragment : Fragment() {
398442
.show()
399443
}
400444

401-
private fun toggleRotationScreenLocked() {
402-
val preferenceStore = requirePreferenceStore()
403-
preferenceStore.screenOrientationLocked.value?.let { value ->
404-
preferenceStore.screenOrientationLocked.value = value.not()
405-
}
406-
}
407445

408446
private fun showSettings() {
409447
findNavController().navigate(R.id.action_CompassFragment_to_SettingsFragment)

app/src/main/java/com/bobek/compass/MainActivity.kt renamed to app/src/main/java/com/earendel/compass/MainActivity.kt

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
package com.bobek.compass
19+
package com.earendel.compass
2020

2121
import android.Manifest.permission.ACCESS_COARSE_LOCATION
2222
import android.Manifest.permission.ACCESS_FINE_LOCATION
23-
import android.content.pm.ActivityInfo
2423
import android.content.pm.PackageManager.PERMISSION_DENIED
2524
import android.os.Bundle
2625
import android.util.Log
@@ -36,9 +35,9 @@ import androidx.navigation.fragment.NavHostFragment
3635
import androidx.navigation.ui.AppBarConfiguration
3736
import androidx.navigation.ui.navigateUp
3837
import androidx.navigation.ui.setupActionBarWithNavController
39-
import com.bobek.compass.databinding.ActivityMainBinding
40-
import com.bobek.compass.model.AppNightMode
41-
import com.bobek.compass.preference.PreferenceStore
38+
import com.earendel.compass.databinding.ActivityMainBinding
39+
import com.earendel.compass.model.AppNightMode
40+
import com.earendel.compass.preference.PreferenceStore
4241
import com.google.android.material.dialog.MaterialAlertDialogBuilder
4342

4443
private const val TAG = "MainActivity"
@@ -69,7 +68,6 @@ class MainActivity : AppCompatActivity() {
6968
private fun initPreferenceStore() {
7069
preferenceStore = PreferenceStore(this, lifecycle)
7170
preferenceStore.nightMode.observe(this) { setNightMode(it) }
72-
preferenceStore.screenOrientationLocked.observe(this) { setScreenRotationMode(it) }
7371
preferenceStore.trueNorth.observe(this) { setupTrueNorthFunctionality(it) }
7472
}
7573

@@ -78,18 +76,6 @@ class MainActivity : AppCompatActivity() {
7876
setDefaultNightMode(appNightMode.systemValue)
7977
}
8078

81-
private fun setScreenRotationMode(screenOrientationLocked: Boolean) {
82-
if (screenOrientationLocked) {
83-
setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED)
84-
} else {
85-
setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
86-
}
87-
}
88-
89-
private fun setScreenOrientation(screenOrientation: Int) {
90-
Log.d(TAG, "Setting requested orientation to value $screenOrientation")
91-
requestedOrientation = screenOrientation
92-
}
9379

9480
private fun setupTrueNorthFunctionality(trueNorth: Boolean?) {
9581
if (trueNorth == true) {

app/src/main/java/com/bobek/compass/SettingsFragment.kt renamed to app/src/main/java/com/earendel/compass/SettingsFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
package com.bobek.compass
19+
package com.earendel.compass
2020

2121
import android.os.Bundle
2222
import androidx.navigation.fragment.findNavController
2323
import androidx.preference.Preference
2424
import androidx.preference.Preference.SummaryProvider
2525
import androidx.preference.PreferenceFragmentCompat
26-
import com.bobek.compass.preference.PreferenceConstants
26+
import com.earendel.compass.preference.PreferenceConstants
2727

2828
class SettingsFragment : PreferenceFragmentCompat() {
2929

app/src/main/java/com/bobek/compass/ThirdPartyLicenseFragment.kt renamed to app/src/main/java/com/earendel/compass/ThirdPartyLicenseFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
package com.bobek.compass
19+
package com.earendel.compass
2020

2121
import android.os.Bundle
2222
import android.view.LayoutInflater
2323
import android.view.View
2424
import android.view.ViewGroup
2525
import androidx.fragment.app.Fragment
26-
import com.bobek.compass.databinding.FragmentThirdPartyLicenseBinding
26+
import com.earendel.compass.databinding.FragmentThirdPartyLicenseBinding
2727

2828
class ThirdPartyLicenseFragment : Fragment() {
2929

app/src/main/java/com/bobek/compass/ThirdPartyLicensesFragment.kt renamed to app/src/main/java/com/earendel/compass/ThirdPartyLicensesFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
package com.bobek.compass
19+
package com.earendel.compass
2020

2121
import android.os.Bundle
2222
import androidx.core.os.bundleOf

0 commit comments

Comments
 (0)