Skip to content

Commit

Permalink
Merge pull request #7 from NordicSemiconductor/feature/softap
Browse files Browse the repository at this point in the history
Adds Soft AP feature
  • Loading branch information
philips77 authored Jun 4, 2024
2 parents 5b8ae65 + 62e270e commit 16d7aa2
Show file tree
Hide file tree
Showing 158 changed files with 4,383 additions and 2,484 deletions.
30 changes: 11 additions & 19 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,27 @@ plugins {
}

android {
namespace = "no.nordicsemi.android.wifi.provisioning"
namespace = "no.nordicsemi.android.wifi.provisioner.app"
defaultConfig {
applicationId = "no.nordicsemi.android.wifi.provisioning"
}
}

dependencies {
implementation(project(":lib_provisioner"))

implementation(libs.androidx.lifecycle.runtime.compose)
implementation(project(":feature:ble"))
implementation(project(":feature:softap"))
implementation(project(":feature:common"))
implementation(project(":feature:ui"))
implementation(project(":lib:ble"))
implementation(project(":lib:softap"))

implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.material.iconsExtended)

implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.nordic.scanner)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.lifecycle.viewModel.compose)

implementation(libs.nordic.core)
implementation(libs.nordic.theme)
implementation(libs.nordic.navigation)
implementation(libs.nordic.uiscanner)
implementation(libs.nordic.uilogger)
implementation(libs.nordic.permission)

implementation(libs.accompanist.placeholder)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.timber)
}
9 changes: 5 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name="no.nordicsemi.android.wifi.provisioning.WifiProvisionerApplication"
android:name="no.nordicsemi.android.wifi.provisioner.WifiProvisionerApplication"
android:allowBackup="true"
android:enableOnBackInvokedCallback="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:label="@string/label_ble_provisioner"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/NordicTheme"
tools:targetApi="31">
tools:targetApi="tiramisu">
<activity
android:name="no.nordicsemi.android.wifi.provisioning.MainActivity"
android:name="no.nordicsemi.android.wifi.provisioner.MainActivity"
android:exported="true"
android:theme="@style/NordicTheme.SplashScreen">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package no.nordicsemi.android.wifi.provisioning
package no.nordicsemi.android.wifi.provisioner

import no.nordicsemi.android.common.navigation.createDestination
import no.nordicsemi.android.common.navigation.createSimpleDestination
import no.nordicsemi.android.common.navigation.defineDestination
import no.nordicsemi.android.wifi.provisioning.home.view.HomeScreen
import no.nordicsemi.android.wifi.provisioning.wifi.view.WifiData
import no.nordicsemi.android.wifi.provisioning.wifi.view.WifiScannerScreen


val HomeDestinationId = createSimpleDestination("home-destination")
val WifiScannerId = createDestination<Unit, WifiData>("wifi-scanner-destination")

val HomeDestinations = listOf(
val HomeDestination = listOf(
defineDestination(HomeDestinationId) { HomeScreen() },
defineDestination(WifiScannerId) { WifiScannerScreen() }
)
162 changes: 162 additions & 0 deletions app/src/main/java/no/nordicsemi/android/wifi/provisioner/HomeScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* Copyright (c) 2022, Nordic Semiconductor
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package no.nordicsemi.android.wifi.provisioner

import android.os.Build
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import kotlinx.coroutines.launch
import no.nordicsemi.android.common.navigation.viewmodel.SimpleNavigationViewModel
import no.nordicsemi.android.common.theme.view.NordicAppBar
import no.nordicsemi.android.wifi.provisioner.app.BuildConfig
import no.nordicsemi.android.wifi.provisioner.app.R
import no.nordicsemi.android.wifi.provisioner.ble.sections.ProvisionOverBleSection
import no.nordicsemi.android.wifi.provisioner.ble.view.BleDestination
import no.nordicsemi.android.wifi.provisioner.softap.view.ProvisionOverWifiSection
import no.nordicsemi.android.wifi.provisioner.softap.view.SoftApDestination

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen() {
val vm: SimpleNavigationViewModel = hiltViewModel()
val context = LocalContext.current
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
Scaffold(
contentWindowInsets = WindowInsets(0, 0, 0, 0),
topBar = {
NordicAppBar(
text = stringResource(id = R.string.label_ble_provisioner)
)
},
snackbarHost = {
SnackbarHost(hostState = snackbarHostState)
},
) { innerPadding ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(innerPadding)
.consumeWindowInsets(innerPadding)
.windowInsetsPadding(
WindowInsets.safeDrawing.only(
WindowInsetsSides.Horizontal,
),
),
horizontalAlignment = Alignment.CenterHorizontally
) {
Row(
modifier = Modifier
.fillMaxWidth()
.weight(0.4f, true),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
Image(
painter = painterResource(id = R.drawable.ic_nrf70),
contentDescription = stringResource(id = R.string.ic_nrf70),
modifier = Modifier
.widthIn(max = 200.dp)
.padding(8.dp)
)
}
Column(
modifier = Modifier
.fillMaxWidth()
.weight(0.4f, true),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
ProvisionOverBleSection {
vm.navigateTo(BleDestination)
}
ProvisionOverWifiSection {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
vm.navigateTo(SoftApDestination)
} else {
scope.launch {
snackbarHostState.showSnackbar(
message = context.getString(R.string.error_softap_not_supported),
actionLabel = context.getString(R.string.dismiss)
)
}
}
}
}
Row(
modifier = Modifier.fillMaxWidth().padding(bottom = 16.dp),
horizontalArrangement = Arrangement.Center,
) {
Text(
text = stringResource(
id = R.string.app_version,
BuildConfig.VERSION_NAME,
BuildConfig.VERSION_CODE
),
modifier = Modifier.padding(bottom = 48.dp),
textAlign = TextAlign.End,
style = MaterialTheme.typography.labelMedium
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,46 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package no.nordicsemi.android.wifi.provisioning
package no.nordicsemi.android.wifi.provisioner

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import dagger.hilt.android.AndroidEntryPoint
import no.nordicsemi.android.common.navigation.NavigationView
import no.nordicsemi.android.common.theme.NordicActivity
import no.nordicsemi.android.common.theme.NordicTheme
import no.nordicsemi.android.wifi.provisioning.scanner.ProvisionerScannerDestination
import no.nordicsemi.android.wifi.provisioner.ble.view.BleProvisioningDestinations
import no.nordicsemi.android.wifi.provisioner.softap.view.SoftApProvisionerDestinations

@AndroidEntryPoint
class MainActivity : NordicActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge(statusBarStyle = SystemBarStyle.dark(Color.TRANSPARENT))

setContent {
NordicTheme {
Surface(modifier = Modifier.fillMaxSize()) {
NavigationView(HomeDestinations + ProvisionerScannerDestination)
NavigationView(
destinations = (HomeDestination +
BleProvisioningDestinations).run {
// Soft AP is available on Android 10 and newer.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
this + SoftApProvisionerDestinations
} else {
this
}
}
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package no.nordicsemi.android.wifi.provisioning
package no.nordicsemi.android.wifi.provisioner

import android.app.Application
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber


@HiltAndroidApp
class WifiProvisionerApplication : Application() {

override fun onCreate() {
super.onCreate()

Timber.plant(Timber.DebugTree())
}
}
Loading

0 comments on commit 16d7aa2

Please sign in to comment.