Set Toast string dynamically to enable translation and add french
This commit is contained in:
parent
632777819b
commit
8f5c8dbd01
@ -72,13 +72,13 @@ class MainActivity : AppCompatActivity() {
|
||||
bluetoothManager = getSystemService(BLUETOOTH_SERVICE) as android.bluetooth.BluetoothManager
|
||||
bluetoothAdapter = bluetoothManager.adapter
|
||||
if (bluetoothAdapter == null) {
|
||||
Toast.makeText(this, "Bluetooth not supported by your device", Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(this, getString(R.string.bluetooth_unsupported), Toast.LENGTH_LONG).show()
|
||||
return
|
||||
}
|
||||
|
||||
connectBtn.setOnClickListener {
|
||||
if (isConnected) {
|
||||
Toast.makeText(this, "Already connected", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(this, getString(R.string.already_connected), Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
if (isTesting) {
|
||||
Toast.makeText(this, "Running in testing mode", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(this, getString(R.string.is_testing_mode), Toast.LENGTH_SHORT).show()
|
||||
Log.d(tag, "Starting fake data stream")
|
||||
|
||||
Thread {
|
||||
@ -111,7 +111,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val device = pairedDevices?.find { it.name == deviceName }
|
||||
|
||||
if (device == null) {
|
||||
Toast.makeText(this, "HC-05 not found, try pairing it to your phone via bluetooth", Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(this, getString(R.string.hc05_not_found), Toast.LENGTH_LONG).show()
|
||||
return
|
||||
}
|
||||
|
||||
@ -121,13 +121,13 @@ class MainActivity : AppCompatActivity() {
|
||||
bluetoothSocket?.connect()
|
||||
isConnected = true
|
||||
runOnUiThread {
|
||||
Toast.makeText(this, "Connected to HC-05", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(this, getString(R.string.connected), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
listenForData()
|
||||
} catch (e: IOException) {
|
||||
Log.e(tag, "Connection failed", e)
|
||||
runOnUiThread {
|
||||
Toast.makeText(this, "Connection failed: ${e.message}", Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(this, getString(R.string.connection_failed) + ": ${e.message}", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
|
||||
@ -2,4 +2,9 @@
|
||||
<string name="app_name" translatable="false">I2D_Project_15_app</string>
|
||||
<string name="connect_btn">Se connecter au HC-05</string>
|
||||
<string name="connected">Connecté au HC-05</string>
|
||||
<string name="bluetooth_unsupported">Votre appareil ne supporte pas le bluetooth</string>
|
||||
<string name="already_connected">Le module est déja connecté</string>
|
||||
<string name="is_testing_mode">L\'application est en mode de test les valeurs sont aléatoires</string>
|
||||
<string name="hc05_not_found">HC-05 introuvable, essayez de l\'apparailler a votre téléphone en bluetooth</string>
|
||||
<string name="connection_failed">Connexion impossible</string>
|
||||
</resources>
|
||||
@ -3,6 +3,12 @@
|
||||
|
||||
<string name="connect_btn">Connect to HC-05</string>
|
||||
<string name="connected">Connected to HC-05</string>
|
||||
<string name="bluetooth_unsupported">Bluetooth is not supported by your device</string>
|
||||
<string name="already_connected">The device is already connected</string>
|
||||
<string name="is_testing_mode">The app is running in testing mode the values are random</string>
|
||||
<string name="hc05_not_found">HC-05 not found, try pairing it to your phone via bluetooth</string>
|
||||
<string name="connection_failed">Connection failed</string>
|
||||
|
||||
|
||||
<string name="temp_format" translatable="false">%.1f°C</string>
|
||||
<string name="hum_format" translatable="false">%.1f%%</string>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user