Add ServerSettingActivity
This commit is contained in:
@@ -5,7 +5,7 @@ plugins {
|
||||
|
||||
android {
|
||||
namespace 'com.logitech.vc.kirbytest'
|
||||
compileSdk 32
|
||||
compileSdk 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.logitech.vc.kirbytest"
|
||||
@@ -53,6 +53,7 @@ dependencies {
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'
|
||||
implementation 'androidx.activity:activity:1.8.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
|
||||
<!-- Request legacy Bluetooth permissions on versions older than API 31 (Android 12). -->
|
||||
<uses-permission
|
||||
android:name="android.permission.BLUETOOTH"
|
||||
@@ -16,16 +14,12 @@
|
||||
<uses-permission
|
||||
android:name="android.permission.ACCESS_FINE_LOCATION"
|
||||
android:maxSdkVersion="30" />
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission
|
||||
android:name="android.permission.BLUETOOTH_SCAN"
|
||||
android:usesPermissionFlags="neverForLocation"
|
||||
tools:targetApi="s" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
@@ -35,12 +29,15 @@
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.SensorTestingApp"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".ServerSettingActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
@@ -51,8 +48,10 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service android:name=".BLEService" android:foregroundServiceType="connectedDevice" />
|
||||
|
||||
<service
|
||||
android:name=".BLEService"
|
||||
android:foregroundServiceType="connectedDevice" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -196,8 +196,12 @@ class KirbyDevice(
|
||||
}
|
||||
|
||||
private fun publishMeasurementAutoServer(measurement: DecoderIaq.Measurement) {
|
||||
// Read url from SharedPreferences
|
||||
val sharedPref = context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE)
|
||||
val url = sharedPref.getString(
|
||||
"kirby_data_post_url",
|
||||
context.getString(R.string.kirby_data_post_url_default)) ?: context.getString(R.string.kirby_data_post_url_default)
|
||||
val accessKey = BuildConfig.API_KEY
|
||||
val url = BuildConfig.API_BASE_URL
|
||||
|
||||
if(url.isEmpty()) {
|
||||
return
|
||||
|
||||
@@ -15,7 +15,6 @@ import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
@@ -23,7 +22,6 @@ import android.view.View.INVISIBLE
|
||||
import android.view.View.VISIBLE
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.result.contract.ActivityResultContracts.CreateDocument
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@@ -303,6 +301,13 @@ class MainActivity : AppCompatActivity() {
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.action_server_setting -> {
|
||||
// Goto server setting intent
|
||||
val intent = Intent(this, ServerSettingActivity::class.java)
|
||||
startActivity(intent)
|
||||
return true
|
||||
}
|
||||
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.logitech.vc.kirbytest
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
|
||||
class ServerSettingActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContentView(R.layout.activity_server_setting)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
||||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||
insets
|
||||
}
|
||||
|
||||
// Get current server setting from SharedPreferences
|
||||
val sharedPref = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE)
|
||||
var currentUrl = sharedPref.getString(
|
||||
"kirby_data_post_url",
|
||||
getString(R.string.kirby_data_post_url_default)) ?: getString(R.string.kirby_data_post_url_default)
|
||||
val editTextServerSetting = findViewById<EditText>(R.id.editTextServerSetting)
|
||||
editTextServerSetting.setText(currentUrl)
|
||||
|
||||
val doneButton = findViewById<Button>(R.id.buttonDone)
|
||||
doneButton.setOnClickListener {
|
||||
// Save editTextServerSetting to SharedPreferences
|
||||
val serverSetting = editTextServerSetting.text.toString()
|
||||
sharedPref.edit().putString("kirby_data_post_url", serverSetting).apply()
|
||||
finish()
|
||||
}
|
||||
|
||||
val cancelButton = findViewById<Button>(R.id.buttonCancel)
|
||||
cancelButton.setOnClickListener {
|
||||
finish()
|
||||
}
|
||||
|
||||
val defaultButton = findViewById<Button>(R.id.buttonDefault)
|
||||
defaultButton.setOnClickListener {
|
||||
editTextServerSetting.setText(getString(R.string.kirby_data_post_url_default))
|
||||
}
|
||||
}
|
||||
}
|
||||
56
app/src/main/res/layout/activity_server_setting.xml
Normal file
56
app/src/main/res/layout/activity_server_setting.xml
Normal file
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="10dp"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/main">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewServerSetting"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/server_url"
|
||||
android:textSize="24sp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginBottom="20dp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextServerSetting"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:autofillHints="@string/kirby_data_post_url_default"
|
||||
android:hint="@string/kirby_data_post_url_default" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonDone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/done"
|
||||
android:layout_marginEnd="10dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonCancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/cancel"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="5dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonDefault"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/defaultString"
|
||||
android:layout_marginStart="10dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -12,4 +12,9 @@
|
||||
android:orderInCategory="200"
|
||||
android:title="@string/action_reset_log"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_server_setting"
|
||||
android:orderInCategory="200"
|
||||
android:title="@string/action_server_setting"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
@@ -2,10 +2,16 @@
|
||||
<string name="app_name">Kirby Test App</string>
|
||||
<string name="action_export">Export to csv</string>
|
||||
<string name="action_reset_log">Reset log</string>
|
||||
<string name="action_server_setting">Server Setting</string>
|
||||
<!-- Strings used for fragments for navigation -->
|
||||
<string name="first_fragment_label">First Fragment</string>
|
||||
<string name="second_fragment_label">Second Fragment</string>
|
||||
<string name="next">Next</string>
|
||||
<string name="previous">Previous</string>
|
||||
<string name="server_url">Server URL</string>
|
||||
<string name="kirby_data_post_url_default">http://vc-automation.logitech.com/teststation/kirbyData</string>
|
||||
<string name="done">Done</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="defaultString">Default</string>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user