Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit d403693

Browse files
committed
Refactor sample. Change obsolete APIs, make jetpack friendly, update files
1 parent 09b1be3 commit d403693

12 files changed

Lines changed: 46 additions & 34 deletions

File tree

BluetoothLeChat/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ dependencies {
5555
implementation fileTree(dir: "libs", include: ["*.jar"])
5656
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
5757
implementation 'androidx.core:core-ktx:1.3.2'
58-
implementation 'androidx.fragment:fragment-ktx:1.3.3'
59-
implementation 'androidx.activity:activity-ktx:1.3.0-alpha07'
58+
implementation 'androidx.fragment:fragment-ktx:1.3.4'
59+
implementation 'androidx.activity:activity-ktx:1.3.0-alpha08'
6060
implementation 'androidx.appcompat:appcompat:1.2.0'
6161
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
6262
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

BluetoothLeChat/app/src/main/java/com/example/bluetoothlechat/bluetooth/ChatServer.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
@file:Suppress("ObjectPropertyName")
17+
1618
package com.example.bluetoothlechat.bluetooth
1719

1820
import android.app.Application
@@ -305,7 +307,7 @@ object ChatServer {
305307
super.onStartFailure(errorCode)
306308
// Send error state to display
307309
val errorMessage = "Advertise failed with error: $errorCode"
308-
Log.d(TAG, "Advertising failed")
310+
Log.d(TAG, errorMessage)
309311
//_viewState.value = DeviceScanViewState.Error(errorMessage)
310312
}
311313

BluetoothLeChat/app/src/main/res/layout/fragment_bluetooth_chat.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
android:id="@+id/connect_devices"
3636
android:layout_width="wrap_content"
3737
android:layout_height="wrap_content"
38-
android:layout_marginTop="16dp"
38+
android:layout_marginTop="@dimen/std_margin"
3939
android:text="@string/connect_device_prompt" />
4040
</LinearLayout>
4141

@@ -50,8 +50,8 @@
5050
android:layout_width="wrap_content"
5151
android:layout_height="wrap_content"
5252
android:layout_gravity="center_horizontal"
53-
android:padding="16dp"
54-
android:textSize="18sp" />
53+
android:padding="@dimen/std_margin"
54+
android:textSize="@dimen/txt_size_18" />
5555

5656
<androidx.recyclerview.widget.RecyclerView
5757
android:id="@+id/messages"
@@ -61,8 +61,11 @@
6161

6262
<EditText
6363
android:id="@+id/message_text"
64+
android:inputType="text"
65+
android:hint="@string/enter_message"
6466
android:layout_width="match_parent"
65-
android:layout_height="wrap_content" />
67+
android:layout_height="wrap_content"
68+
android:importantForAutofill="no" />
6669

6770
<Button
6871
android:id="@+id/send_message"

BluetoothLeChat/app/src/main/res/layout/fragment_device_scan.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
android:layout_width="wrap_content"
3737
android:layout_height="wrap_content"
3838
android:layout_gravity="center"
39-
android:paddingTop="16dp"
39+
android:paddingTop="@dimen/std_margin"
4040
android:text="@string/active_scan_message"
41-
android:textSize="18sp" />
41+
android:textSize="@dimen/txt_size_18" />
4242
</LinearLayout>
4343

4444
<androidx.recyclerview.widget.RecyclerView

BluetoothLeChat/app/src/main/res/layout/fragment_location_required.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
android:id="@+id/location_error_message"
2424
android:layout_width="0dp"
2525
android:layout_height="wrap_content"
26-
android:layout_marginStart="16dp"
27-
android:layout_marginEnd="16dp"
26+
android:layout_marginStart="@dimen/std_margin"
27+
android:layout_marginEnd="@dimen/std_margin"
2828
android:text="@string/location_required_error"
2929
app:layout_constraintBottom_toBottomOf="parent"
3030
app:layout_constraintEnd_toEndOf="parent"
@@ -35,7 +35,7 @@
3535
android:id="@+id/grant_permission_button"
3636
android:layout_width="wrap_content"
3737
android:layout_height="wrap_content"
38-
android:layout_marginTop="16dp"
38+
android:layout_marginTop="@dimen/std_margin"
3939
android:text="@string/grant_permission_prompt"
4040
app:layout_constraintEnd_toEndOf="parent"
4141
app:layout_constraintStart_toStartOf="parent"

BluetoothLeChat/app/src/main/res/layout/item_device.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
android:id="@+id/device_name"
2424
android:layout_width="0dp"
2525
android:layout_height="wrap_content"
26-
android:layout_marginStart="16dp"
27-
android:layout_marginTop="16dp"
28-
android:layout_marginEnd="16dp"
26+
android:layout_marginStart="@dimen/std_margin"
27+
android:layout_marginTop="@dimen/std_margin"
28+
android:layout_marginEnd="@dimen/std_margin"
2929
app:layout_constraintEnd_toEndOf="parent"
3030
app:layout_constraintStart_toStartOf="parent"
3131
app:layout_constraintTop_toTopOf="parent" />
@@ -34,10 +34,10 @@
3434
android:id="@+id/device_address"
3535
android:layout_width="0dp"
3636
android:layout_height="wrap_content"
37-
android:layout_marginStart="16dp"
38-
android:layout_marginTop="16dp"
39-
android:layout_marginEnd="16dp"
40-
android:layout_marginBottom="16dp"
37+
android:layout_marginStart="@dimen/std_margin"
38+
android:layout_marginTop="@dimen/std_margin"
39+
android:layout_marginEnd="@dimen/std_margin"
40+
android:layout_marginBottom="@dimen/std_margin"
4141
app:layout_constraintBottom_toBottomOf="parent"
4242
app:layout_constraintEnd_toEndOf="parent"
4343
app:layout_constraintStart_toStartOf="parent"

BluetoothLeChat/app/src/main/res/layout/item_local_message.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
android:id="@+id/message_text"
2525
android:layout_width="0dp"
2626
android:layout_height="wrap_content"
27-
android:layout_marginStart="16dp"
28-
android:layout_marginTop="8dp"
29-
android:layout_marginEnd="16dp"
30-
android:layout_marginBottom="8dp"
27+
android:layout_marginStart="@dimen/std_margin"
28+
android:layout_marginTop="@dimen/std_margin_half"
29+
android:layout_marginEnd="@dimen/std_margin"
30+
android:layout_marginBottom="@dimen/std_margin_half"
3131
android:background="@color/local_message_background"
3232
android:padding="8dp"
3333
android:textColor="#000000"

BluetoothLeChat/app/src/main/res/layout/item_remote_message.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
android:id="@+id/message_text"
2525
android:layout_width="0dp"
2626
android:layout_height="wrap_content"
27-
android:layout_marginStart="16dp"
28-
android:layout_marginTop="8dp"
29-
android:layout_marginEnd="16dp"
30-
android:layout_marginBottom="8dp"
27+
android:layout_marginStart="@dimen/std_margin"
28+
android:layout_marginTop="@dimen/std_margin_half"
29+
android:layout_marginEnd="@dimen/std_margin"
30+
android:layout_marginBottom="@dimen/std_margin_half"
3131
android:background="@color/remote_message_background"
3232
android:padding="8dp"
3333
android:textColor="#ffffff"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<dimen name="std_margin">16dp</dimen>
4+
<dimen name="txt_size_18">18sp</dimen>
5+
<dimen name="std_margin_half">8dp</dimen>
6+
</resources>

BluetoothLeChat/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929
<string name="connect_device_prompt">Connect with nearby devices</string>
3030
<string name="send_message_button">Send Message</string>
3131
<string name="chatting_with_device">Chatting with %1$s</string>
32+
<string name="enter_message">enter message</string>
3233
</resources>

0 commit comments

Comments
 (0)