Skip to content

Commit

Permalink
Add HorizontalPager with Settings Page
Browse files Browse the repository at this point in the history
  • Loading branch information
NiroDeveloper committed May 31, 2024
1 parent 268a354 commit bcaadbb
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ android {
vectorDrawables {
useSupportLibrary = true
}

}

buildTypes {
Expand All @@ -37,6 +36,7 @@ android {
}
buildFeatures {
compose = true
buildFeatures.buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.11"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@ import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.result.ActivityResultLauncher
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.wear.ambient.AmbientLifecycleObserver
import androidx.wear.compose.material.HorizontalPageIndicator
import androidx.wear.compose.material.PageIndicatorState
import androidx.wear.compose.material.Text
import androidx.wear.tooling.preview.devices.WearDevices
import dev.niro.cameraremote.bluetooth.BluetoothController
import dev.niro.cameraremote.bluetooth.helper.BluetoothPermission
import dev.niro.cameraremote.interfaces.IAmbientModeState
import dev.niro.cameraremote.ui.pages.RemoteLayout
import dev.niro.cameraremote.ui.pages.RemotePage
import dev.niro.cameraremote.ui.pages.SettingsLayout

class MainActivity : ComponentActivity(), AmbientLifecycleObserver.AmbientLifecycleCallback, IAmbientModeState {

Expand Down Expand Up @@ -42,7 +58,7 @@ class MainActivity : ComponentActivity(), AmbientLifecycleObserver.AmbientLifecy
}

setContent {
RemoteLayout(permissionLauncher)
MainActivityLayout(permissionLauncher)
}
}

Expand All @@ -64,4 +80,35 @@ class MainActivity : ComponentActivity(), AmbientLifecycleObserver.AmbientLifecy
override fun isAmbientModeActive(): Boolean {
return isInAmbientMode
}
}

@OptIn(ExperimentalFoundationApi::class)
@Preview(device = WearDevices.RECT, showSystemUi = true)
@Preview(device = WearDevices.SQUARE, showSystemUi = true)
@Preview(device = WearDevices.SMALL_ROUND, showSystemUi = true)
@Preview(device = WearDevices.LARGE_ROUND, showSystemUi = true)
@Composable
fun MainActivityLayout(permissionLauncher: ActivityResultLauncher<String>? = null) {
val pagerState = rememberPagerState { 3 }

HorizontalPager(state = pagerState) {page ->
when(page) {
0 -> RemoteLayout(permissionLauncher)
1 -> Text(text = "Devices List", modifier = Modifier.fillMaxSize())
2 -> SettingsLayout()
}
}

val pageIndicatorState: PageIndicatorState = remember {
object : PageIndicatorState {
override val pageOffset: Float
get() = 0f
override val selectedPage: Int
get() = pagerState.currentPage
override val pageCount: Int
get() = pagerState.pageCount
}
}

HorizontalPageIndicator(pageIndicatorState = pageIndicatorState, modifier = Modifier.padding(12.dp))
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import dev.niro.cameraremote.ui.activities.ErrorActivity
import kotlin.math.roundToInt

object RemotePage {
val triggerButtonIcon = mutableIntStateOf(0)
val timerDelayText = mutableStateOf("")
val triggerButtonIcon = mutableIntStateOf(R.drawable.baseline_linked_camera_24)
val timerDelayText = mutableStateOf("0s")
val modeTextDecoration = mutableStateOf(TextDecoration.None)
val progressIndicator = mutableFloatStateOf(0f)

Expand Down
82 changes: 82 additions & 0 deletions app/src/main/java/dev/niro/cameraremote/ui/pages/SettingsPage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package dev.niro.cameraremote.ui.pages

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import androidx.wear.compose.material.PositionIndicator
import androidx.wear.compose.material.Switch
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.ToggleChip
import androidx.wear.tooling.preview.devices.WearDevices
import dev.niro.cameraremote.BuildConfig
import dev.niro.cameraremote.R

object SettingsPage {

var vibrationEnabled = mutableStateOf(true)

}

@Preview(device = WearDevices.RECT, showSystemUi = true)
@Preview(device = WearDevices.SQUARE, showSystemUi = true)
@Preview(device = WearDevices.SMALL_ROUND, showSystemUi = true)
@Preview(device = WearDevices.LARGE_ROUND, showSystemUi = true)
@Composable
fun SettingsLayout() {
val scalingState = rememberScalingLazyListState()

PositionIndicator(scalingLazyListState = scalingState)

ScalingLazyColumn(
modifier = Modifier.fillMaxSize(),
state = scalingState
) {

item {
Text(
text = stringResource(id = R.string.settings),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
)
}

item {
var vibrationEnabled by remember { mutableStateOf(true) }

ToggleChip(
checked = vibrationEnabled,
onCheckedChange = { vibrationEnabled = it },
label = { Text(stringResource(id = R.string.vibration)) },
toggleControl = { Switch(checked = vibrationEnabled) },
modifier = Modifier.fillMaxWidth()
)
}

item {
Text(
text = "v${BuildConfig.VERSION_NAME}",
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
)
}

}
}
9 changes: 9 additions & 0 deletions app/src/main/java/dev/niro/cameraremote/utils/Vibrator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ import android.content.Context
import android.os.Build
import android.os.VibrationEffect
import android.os.VibratorManager
import dev.niro.cameraremote.ui.pages.SettingsPage

object Vibrator {

fun tick(context: Context) {
if (!SettingsPage.vibrationEnabled.value) {
return
}

getVibrator(context).vibrate(VibrationEffect.createOneShot(50, 100))
}

fun shoot(context: Context) {
if (!SettingsPage.vibrationEnabled.value) {
return
}

getVibrator(context).vibrate(VibrationEffect.createOneShot(100, 200))
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
<string name="error_no_devices_found">Kein Gerät verfügbar.\n\nVerbinden Sie ihr Smartphone über die Geräteeinstellungen.</string>
<string name="bluetooth_permission_description">Diese App benötigt Zugriff auf die Bluetooth Schnittstelle dieser Smartwatch, um Signale an Ihr Smartphone zu versenden.\n\nBeim Auslesen der Bluetooth Schnittstelle können Geräte in der Nähe identifiziert werden.</string>
<string name="error_bluetooth_permission_denied">Sie haben die Bluetooth Berechtigung zu oft abgeleht.\n\nWenn Sie die App verwenden möchten, müssen Sie nun die Bluetooth Berechtigung in den Geräte Einstellungen für diese App aktivieren.</string>
<string name="settings">Einstellungen</string>
<string name="vibration">Vibration</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
<string name="error_no_devices_found">No devices available.\n\nConnect your phone over the device settings.</string>
<string name="bluetooth_permission_description">This app requires access to the Bluetooth interface of this smartwatch in order to send signals to your smartphone.\n\nWhen reading out the Bluetooth interface, devices in the vicinity can be identified.</string>
<string name="error_bluetooth_permission_denied">You have rejected the Bluetooth permission too often.\n\nIf you want to use the app, you must now activate Bluetooth permission for this app in the device settings.</string>
<string name="settings">Settings</string>
<string name="vibration">Vibration</string>
</resources>

0 comments on commit bcaadbb

Please sign in to comment.