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
|
bluetoothManager = getSystemService(BLUETOOTH_SERVICE) as android.bluetooth.BluetoothManager
|
||||||
bluetoothAdapter = bluetoothManager.adapter
|
bluetoothAdapter = bluetoothManager.adapter
|
||||||
if (bluetoothAdapter == null) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
connectBtn.setOnClickListener {
|
connectBtn.setOnClickListener {
|
||||||
if (isConnected) {
|
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
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isTesting) {
|
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")
|
Log.d(tag, "Starting fake data stream")
|
||||||
|
|
||||||
Thread {
|
Thread {
|
||||||
@ -111,7 +111,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val device = pairedDevices?.find { it.name == deviceName }
|
val device = pairedDevices?.find { it.name == deviceName }
|
||||||
|
|
||||||
if (device == null) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,13 +121,13 @@ class MainActivity : AppCompatActivity() {
|
|||||||
bluetoothSocket?.connect()
|
bluetoothSocket?.connect()
|
||||||
isConnected = true
|
isConnected = true
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
Toast.makeText(this, "Connected to HC-05", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, getString(R.string.connected), Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
listenForData()
|
listenForData()
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.e(tag, "Connection failed", e)
|
Log.e(tag, "Connection failed", e)
|
||||||
runOnUiThread {
|
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()
|
}.start()
|
||||||
|
|||||||
@ -2,4 +2,9 @@
|
|||||||
<string name="app_name" translatable="false">I2D_Project_15_app</string>
|
<string name="app_name" translatable="false">I2D_Project_15_app</string>
|
||||||
<string name="connect_btn">Se connecter au HC-05</string>
|
<string name="connect_btn">Se connecter au HC-05</string>
|
||||||
<string name="connected">Connecté 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>
|
</resources>
|
||||||
@ -3,6 +3,12 @@
|
|||||||
|
|
||||||
<string name="connect_btn">Connect to HC-05</string>
|
<string name="connect_btn">Connect to HC-05</string>
|
||||||
<string name="connected">Connected 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="temp_format" translatable="false">%.1f°C</string>
|
||||||
<string name="hum_format" translatable="false">%.1f%%</string>
|
<string name="hum_format" translatable="false">%.1f%%</string>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user