Skip to content

Commit

Permalink
Add screen flashlight quick action
Browse files Browse the repository at this point in the history
Closes #2097
  • Loading branch information
kylecorry31 committed Dec 29, 2023
1 parent cacb9d5 commit d7383c5
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class AstronomyQuickActionBinder(
QuickActionType.SunsetAlert -> QuickActionSunsetAlert(button, fragment)
QuickActionType.NightMode -> QuickActionNightMode(button, fragment)
QuickActionType.Pedometer -> QuickActionPedometer(button, fragment)
QuickActionType.ScreenFlashlight -> QuickActionScreenFlashlight(button, fragment)
else -> QuickActionNone(button, fragment)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class NavigationQuickActionBinder(
QuickActionType.NightMode -> QuickActionNightMode(button, fragment)
QuickActionType.Backtrack -> QuickActionBacktrack(button, fragment)
QuickActionType.Pedometer -> QuickActionPedometer(button, fragment)
QuickActionType.ScreenFlashlight -> QuickActionScreenFlashlight(button, fragment)
else -> QuickActionNone(button, fragment)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kylecorry.trail_sense.quickactions

import android.widget.ImageButton
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.shared.CustomUiUtils
import com.kylecorry.trail_sense.shared.QuickActionButton

class QuickActionScreenFlashlight(btn: ImageButton, fragment: Fragment) :
QuickActionButton(btn, fragment) {

override fun onCreate() {
super.onCreate()
button.setImageResource(R.drawable.ic_screen_flashlight)
CustomUiUtils.setButtonState(button, false)
button.setOnClickListener {
fragment.findNavController().navigate(R.id.fragmentToolScreenFlashlight)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ToolsQuickActionBinder(
QuickActionType.Backtrack -> QuickActionBacktrack(createButton(), fragment)
QuickActionType.WeatherMonitor -> QuickActionWeather(createButton(), fragment)
QuickActionType.Pedometer -> QuickActionPedometer(createButton(), fragment)
QuickActionType.ScreenFlashlight -> QuickActionScreenFlashlight(createButton(), fragment)
else -> null // No other actions are supported
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class WeatherQuickActionBinder(
QuickActionType.NightMode -> QuickActionNightMode(button, fragment)
QuickActionType.WeatherMonitor -> QuickActionWeather(button, fragment)
QuickActionType.Pedometer -> QuickActionPedometer(button, fragment)
QuickActionType.ScreenFlashlight -> QuickActionScreenFlashlight(button, fragment)
else -> QuickActionNone(button, fragment)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum class QuickActionType(val id: Int) {
Backtrack(15),
WeatherMonitor(16),
Pedometer(17),
ScreenFlashlight(18),
}

object QuickActionUtils {
Expand All @@ -48,6 +49,7 @@ object QuickActionUtils {
QuickActionType.Backtrack -> context.getString(R.string.backtrack)
QuickActionType.WeatherMonitor -> context.getString(R.string.weather_monitor)
QuickActionType.Pedometer -> context.getString(R.string.pedometer)
QuickActionType.ScreenFlashlight -> context.getString(R.string.screen_flashlight_full_name)
}.capitalizeWords()
}

Expand All @@ -67,7 +69,8 @@ object QuickActionUtils {
context,
Sensor.TYPE_STEP_COUNTER
)
) QuickActionType.Pedometer else null
) QuickActionType.Pedometer else null,
QuickActionType.ScreenFlashlight
)
}

Expand All @@ -88,7 +91,8 @@ object QuickActionUtils {
context,
Sensor.TYPE_STEP_COUNTER
)
) QuickActionType.Pedometer else null
) QuickActionType.Pedometer else null,
QuickActionType.ScreenFlashlight
)

return list.filterNotNull()
Expand All @@ -112,7 +116,8 @@ object QuickActionUtils {
context,
Sensor.TYPE_STEP_COUNTER
)
) QuickActionType.Pedometer else null
) QuickActionType.Pedometer else null,
QuickActionType.ScreenFlashlight
)
}

Expand All @@ -131,7 +136,8 @@ object QuickActionUtils {
context,
Sensor.TYPE_STEP_COUNTER
)
) QuickActionType.Pedometer else null
) QuickActionType.Pedometer else null,
QuickActionType.ScreenFlashlight
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.kylecorry.trail_sense.databinding.FragmentClinometerBinding
import com.kylecorry.trail_sense.shared.*
import com.kylecorry.trail_sense.shared.CustomUiUtils.getPrimaryMarkerColor
import com.kylecorry.trail_sense.shared.DistanceUtils.toRelativeDistance
import com.kylecorry.trail_sense.shared.colors.AppColor
import com.kylecorry.trail_sense.shared.haptics.HapticSubsystem
import com.kylecorry.trail_sense.shared.permissions.alertNoCameraPermission
import com.kylecorry.trail_sense.shared.permissions.requestCamera
Expand Down Expand Up @@ -161,7 +160,7 @@ class ClinometerFragment : BoundFragment<FragmentClinometerBinding>() {
if (isAugmentedReality) {
binding.arView.start(false)
}
binding.clinometerTitle.leftButton.setImageResource(R.drawable.ic_screen_flashlight)
binding.clinometerTitle.leftButton.setImageResource(R.drawable.ic_phone_portrait)
CustomUiUtils.setButtonState(binding.clinometerTitle.leftButton, false)
clinometer = getClinometer()
} else {
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/res/drawable/flashlight.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<!--drawable/flashlight.xml-->
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:width="24dp" android:viewportWidth="24" android:viewportHeight="24" android:tint="?android:textColorSecondary">
<path android:fillColor="#fff" android:pathData="M9 10L6 5h12l-3 5H9m9-6H6V2h12v2M9 22V11h6v11H9m3-9a1 1 0 0 0-1 1 1 1 0 0 0 1 1 1 1 0 0 0 1-1 1 1 0 0 0-1-1z"/>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#ffffff"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#ffffff"
android:pathData="M9 10L6 5h12l-3 5H9m9-6H6V2h12v2M9 22V11h6v11H9m3-9a1 1 0 0 0-1 1 1 1 0 0 0 1 1 1 1 0 0 0 1-1 1 1 0 0 0-1-1z" />
</vector>
3 changes: 3 additions & 0 deletions app/src/main/res/drawable/ic_phone_portrait.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<vector android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M17 1.01L7 1C5.9 1 5 1.9 5 3v18c0 1.1 0.9 2 2 2h10c1.1 0 2-0.9 2-2V3c0-1.1-0.9-1.99-2-1.99zM17 19H7V5h10v14z"/>
</vector>
11 changes: 8 additions & 3 deletions app/src/main/res/drawable/ic_screen_flashlight.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<vector android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M17 1.01L7 1C5.9 1 5 1.9 5 3v18c0 1.1 0.9 2 2 2h10c1.1 0 2-0.9 2-2V3c0-1.1-0.9-1.99-2-1.99zM17 19H7V5h10v14z"/>
</vector>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_phone_portrait" />
<item
android:width="10dp"
android:height="10dp"
android:drawable="@drawable/flashlight"
android:gravity="center" />
</layer-list>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,7 @@
<string name="pref_use_dynamic_colors_on_compass" translatable="false">pref_use_dynamic_colors_on_compass</string>
<string name="compass_dynamic_colors">Compass Dynamic Colors</string>
<string name="compass_dynamic_colors_summary">Use Dynamic Colors for cardinal directions</string>
<string name="screen_flashlight_full_name">Screen Flashlight</string>
<plurals name="map_group_summary">
<item quantity="one">%d map</item>
<item quantity="other">%d maps</item>
Expand Down

0 comments on commit d7383c5

Please sign in to comment.