-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'no.normedia.adbwificonnector' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "no.normedia.adbwificonnector" | ||
minSdk 23 | ||
targetSdk 33 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
vectorDrawables { | ||
useSupportLibrary true | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
buildFeatures { | ||
compose true | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion '1.3.2' | ||
} | ||
packagingOptions { | ||
resources { | ||
excludes += '/META-INF/{AL2.0,LGPL2.1}' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.8.0' | ||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1' | ||
implementation 'androidx.activity:activity-compose:1.5.1' | ||
implementation platform('androidx.compose:compose-bom:2022.10.00') | ||
implementation 'androidx.compose.ui:ui' | ||
implementation 'androidx.compose.ui:ui-graphics' | ||
implementation 'androidx.compose.ui:ui-tooling-preview' | ||
implementation 'androidx.compose.material3:material3' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') | ||
androidTestImplementation 'androidx.compose.ui:ui-test-junit4' | ||
debugImplementation 'androidx.compose.ui:ui-tooling' | ||
debugImplementation 'androidx.compose.ui:ui-test-manifest' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package no.normedia.adbwificonnector | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("no.normedia.adbwificonnector", appContext.packageName) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> | ||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.ADBwificonnector" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".WifiConnectActivity" | ||
android:exported="true" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="connect" /> | ||
<action android:name="disconnect" /> | ||
<category android:name="android.intent.category.DEFAULT" /> | ||
</intent-filter> | ||
<meta-data android:name="ssid" /> | ||
<meta-data android:name="password" /> | ||
</activity> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.ADBwificonnector"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// MainActivity.kt | ||
package no.normedia.adbwificonnector | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.IntentFilter | ||
import android.net.wifi.WifiManager | ||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.runtime.LaunchedEffect | ||
import kotlinx.coroutines.delay | ||
import no.normedia.adbwificonnector.ui.theme.ADBwificonnectorTheme | ||
|
||
class MainActivity : ComponentActivity() { | ||
private lateinit var wifiStateReceiver: BroadcastReceiver | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
ADBwificonnectorTheme { | ||
ADBwificonnectorContent() | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun ADBwificonnectorContent() { | ||
val wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager | ||
val wifiInfo = wifiManager.connectionInfo | ||
val ssid = wifiInfo.ssid | ||
val isConnected by remember { mutableStateOf(ssid != null && ssid != "0x" && ssid.isNotEmpty()) } | ||
|
||
LaunchedEffect(isConnected) { | ||
if (isConnected) { | ||
delay(3000) | ||
finish() | ||
} | ||
} | ||
|
||
Surface( | ||
modifier = Modifier.fillMaxSize(), | ||
color = MaterialTheme.colorScheme.background | ||
) { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
ADBwificonnectorTitle() | ||
if (isConnected) { | ||
Greeting("Connected to $ssid") | ||
} else { | ||
Greeting("Not connected to wifi") | ||
} | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
ADBwificonnectorExitButton() | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun ADBwificonnectorTitle() { | ||
Text( | ||
text = "ADB Wifi Connector", | ||
style = MaterialTheme.typography.headlineMedium, | ||
modifier = Modifier.padding(bottom = 16.dp) | ||
) | ||
} | ||
|
||
@Composable | ||
fun ADBwificonnectorExitButton() { | ||
Button(onClick = { finish() }) { | ||
Text(text = "Exit") | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
// Ensure content is freeeeeeeeeesh | ||
setContent { | ||
ADBwificonnectorTheme { | ||
ADBwificonnectorContent() | ||
} | ||
} | ||
// Register a broadcast receiver to listen for wifi state changes | ||
wifiStateReceiver = object : BroadcastReceiver() { | ||
override fun onReceive(context: Context?, intent: Intent?) { | ||
setContent { | ||
ADBwificonnectorTheme { | ||
ADBwificonnectorContent() | ||
} | ||
} | ||
} | ||
} | ||
val intentFilter = IntentFilter() | ||
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION) | ||
registerReceiver(wifiStateReceiver, intentFilter) | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
// Unregister the broadcast receiver when the activity is paused | ||
unregisterReceiver(wifiStateReceiver) | ||
} | ||
} | ||
|
||
@Composable | ||
fun Greeting(message: String, modifier: Modifier = Modifier) { | ||
Text( | ||
text = message, | ||
modifier = modifier | ||
) | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun GreetingPreview() { | ||
ADBwificonnectorTheme { | ||
Greeting("Connected to Wifi") | ||
} | ||
} |