Loader and pretty interface
This commit is contained in:
@@ -9,12 +9,15 @@ import android.bluetooth.le.ScanResult
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.os.Build
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
@@ -35,10 +38,16 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
||||
super.onScanResult(callbackType, result)
|
||||
val bleDevicesView = findViewById<RecyclerView>(R.id.bleDevicesView)
|
||||
val loader = findViewById<ImageView>(R.id.bleDevicesLoader)
|
||||
if (result.device.name.isNullOrBlank()) {
|
||||
return
|
||||
}
|
||||
|
||||
if (loader.visibility == View.VISIBLE) {
|
||||
(loader.drawable as? Animatable)?.stop()
|
||||
loader.visibility = View.GONE
|
||||
}
|
||||
|
||||
var deviceIndex = foundDevices.indexOfFirst { it.address == result.device.address }
|
||||
if (deviceIndex < 0) {
|
||||
deviceIndex = foundDevices.size
|
||||
@@ -60,6 +69,9 @@ class MainActivity : AppCompatActivity() {
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
val loader = findViewById<ImageView>(R.id.bleDevicesLoader)
|
||||
(loader.drawable as? Animatable)?.start()
|
||||
|
||||
val bleDevicesView = findViewById<RecyclerView>(R.id.bleDevicesView)
|
||||
bleDevicesView.layoutManager = LinearLayoutManager(this)
|
||||
bleDevicesView.adapter = BleDeviceAdapter(foundDevices, gotoControlButton)
|
||||
|
||||
72
app/src/main/res/drawable/loader.xml
Normal file
72
app/src/main/res/drawable/loader.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<animated-vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt">
|
||||
<aapt:attr name="android:drawable">
|
||||
<vector
|
||||
android:name="vector"
|
||||
android:width="60dp"
|
||||
android:height="15dp"
|
||||
android:viewportWidth="40"
|
||||
android:viewportHeight="10">
|
||||
<path
|
||||
android:name="path"
|
||||
android:pathData="M 5 0 C 3.674 0 2.402 0.527 1.464 1.464 C 0.527 2.402 0 3.674 0 5 C 0 6.326 0.527 7.598 1.464 8.536 C 2.402 9.473 3.674 10 5 10 C 6.326 10 7.598 9.473 8.536 8.536 C 9.473 7.598 10 6.326 10 5 C 10 3.674 9.473 2.402 8.536 1.464 C 7.598 0.527 6.326 0 5 0 Z"
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillAlpha="0"
|
||||
android:strokeWidth="1"/>
|
||||
<path
|
||||
android:name="path_1"
|
||||
android:pathData="M 20 0 C 18.674 0 17.402 0.527 16.464 1.464 C 15.527 2.402 15 3.674 15 5 C 15 6.326 15.527 7.598 16.464 8.536 C 17.402 9.473 18.674 10 20 10 C 21.326 10 22.598 9.473 23.536 8.536 C 24.473 7.598 25 6.326 25 5 C 25 3.674 24.473 2.402 23.536 1.464 C 22.598 0.527 21.326 0 20 0 Z"
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillAlpha="0"
|
||||
android:strokeWidth="1"/>
|
||||
<path
|
||||
android:name="path_2"
|
||||
android:pathData="M 35 0 C 33.674 0 32.402 0.527 31.464 1.464 C 30.527 2.402 30 3.674 30 5 C 30 6.326 30.527 7.598 31.464 8.536 C 32.402 9.473 33.674 10 35 10 C 36.326 10 37.598 9.473 38.536 8.536 C 39.473 7.598 40 6.326 40 5 C 40 3.674 39.473 2.402 38.536 1.464 C 37.598 0.527 36.326 0 35 0 Z"
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillAlpha="0"
|
||||
android:strokeWidth="1"/>
|
||||
</vector>
|
||||
</aapt:attr>
|
||||
<target android:name="path">
|
||||
<aapt:attr name="android:animation">
|
||||
<objectAnimator
|
||||
android:propertyName="fillAlpha"
|
||||
android:duration="500"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="1"
|
||||
android:valueType="floatType"
|
||||
android:repeatCount="infinite"
|
||||
android:repeatMode="reverse"
|
||||
android:interpolator="@android:anim/linear_interpolator"/>
|
||||
</aapt:attr>
|
||||
</target>
|
||||
<target android:name="path_1">
|
||||
<aapt:attr name="android:animation">
|
||||
<objectAnimator
|
||||
android:propertyName="fillAlpha"
|
||||
android:startOffset="200"
|
||||
android:duration="500"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="1"
|
||||
android:valueType="floatType"
|
||||
android:repeatCount="infinite"
|
||||
android:repeatMode="reverse"
|
||||
android:interpolator="@android:anim/linear_interpolator"/>
|
||||
</aapt:attr>
|
||||
</target>
|
||||
<target android:name="path_2">
|
||||
<aapt:attr name="android:animation">
|
||||
<objectAnimator
|
||||
android:propertyName="fillAlpha"
|
||||
android:startOffset="400"
|
||||
android:duration="500"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="1"
|
||||
android:valueType="floatType"
|
||||
android:repeatCount="infinite"
|
||||
android:repeatMode="reverse"
|
||||
android:interpolator="@android:anim/linear_interpolator"/>
|
||||
</aapt:attr>
|
||||
</target>
|
||||
</animated-vector>
|
||||
@@ -1,4 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="500" android:viewportHeight="500">
|
||||
<path android:fillColor="?android:textColorPrimary" android:pathData="M 15 340 L 80 340 Q 95 340 95 355 L 95 485 Q 95 500 80 500 L 15 500 Q 0 500 0 485 L 0 355 Q 0 340 15 340 Z"/>
|
||||
<path
|
||||
android:fillColor="?android:colorPrimary"
|
||||
android:pathData="M 15 340 L 80 340 Q 95 340 95 355 L 95 485 Q 95 500 80 500 L 15 500 Q 0 500 0 485 L 0 355 Q 0 340 15 340 Z" />
|
||||
<path
|
||||
android:fillColor="?android:colorButtonNormal"
|
||||
android:pathData="M 150 220 L 215 220 Q 230 220 230 235 L 230 485 Q 230 500 215 500 L 150 500 Q 135 500 135 485 L 135 235 Q 135 220 150 220 Z" />
|
||||
<path
|
||||
android:fillColor="?android:colorButtonNormal"
|
||||
android:pathData="M 285 120 L 350 120 Q 365 120 365 135 L 365 485 Q 365 500 350 500 L 285 500 Q 270 500 270 485 L 270 135 Q 270 120 285 120 Z" />
|
||||
<path
|
||||
android:fillColor="?android:colorButtonNormal"
|
||||
android:pathData="M 420 0 L 485 0 Q 500 0 500 15 L 500 485 Q 500 500 485 500 L 420 500 Q 405 500 405 485 L 405 15 Q 405 0 420 0 Z" />
|
||||
</vector>
|
||||
@@ -6,9 +6,15 @@
|
||||
android:viewportHeight="500">
|
||||
|
||||
<path
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillColor="?android:colorPrimary"
|
||||
android:pathData="M 15 340 L 80 340 Q 95 340 95 355 L 95 485 Q 95 500 80 500 L 15 500 Q 0 500 0 485 L 0 355 Q 0 340 15 340 Z" />
|
||||
<path
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillColor="?android:colorPrimary"
|
||||
android:pathData="M 150 220 L 215 220 Q 230 220 230 235 L 230 485 Q 230 500 215 500 L 150 500 Q 135 500 135 485 L 135 235 Q 135 220 150 220 Z" />
|
||||
<path
|
||||
android:fillColor="?android:colorButtonNormal"
|
||||
android:pathData="M 285 120 L 350 120 Q 365 120 365 135 L 365 485 Q 365 500 350 500 L 285 500 Q 270 500 270 485 L 270 135 Q 270 120 285 120 Z" />
|
||||
<path
|
||||
android:fillColor="?android:colorButtonNormal"
|
||||
android:pathData="M 420 0 L 485 0 Q 500 0 500 15 L 500 485 Q 500 500 485 500 L 420 500 Q 405 500 405 485 L 405 15 Q 405 0 420 0 Z" />
|
||||
</vector>
|
||||
@@ -6,12 +6,15 @@
|
||||
android:viewportHeight="500">
|
||||
|
||||
<path
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillColor="?android:colorPrimary"
|
||||
android:pathData="M 15 340 L 80 340 Q 95 340 95 355 L 95 485 Q 95 500 80 500 L 15 500 Q 0 500 0 485 L 0 355 Q 0 340 15 340 Z" />
|
||||
<path
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillColor="?android:colorPrimary"
|
||||
android:pathData="M 150 220 L 215 220 Q 230 220 230 235 L 230 485 Q 230 500 215 500 L 150 500 Q 135 500 135 485 L 135 235 Q 135 220 150 220 Z" />
|
||||
<path
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillColor="?android:colorPrimary"
|
||||
android:pathData="M 285 120 L 350 120 Q 365 120 365 135 L 365 485 Q 365 500 350 500 L 285 500 Q 270 500 270 485 L 270 135 Q 270 120 285 120 Z" />
|
||||
<path
|
||||
android:fillColor="?android:colorButtonNormal"
|
||||
android:pathData="M 420 0 L 485 0 Q 500 0 500 15 L 500 485 Q 500 500 485 500 L 420 500 Q 405 500 405 485 L 405 15 Q 405 0 420 0 Z" />
|
||||
</vector>
|
||||
@@ -6,15 +6,15 @@
|
||||
android:viewportHeight="500">
|
||||
|
||||
<path
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillColor="?android:colorPrimary"
|
||||
android:pathData="M 15 340 L 80 340 Q 95 340 95 355 L 95 485 Q 95 500 80 500 L 15 500 Q 0 500 0 485 L 0 355 Q 0 340 15 340 Z" />
|
||||
<path
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillColor="?android:colorPrimary"
|
||||
android:pathData="M 150 220 L 215 220 Q 230 220 230 235 L 230 485 Q 230 500 215 500 L 150 500 Q 135 500 135 485 L 135 235 Q 135 220 150 220 Z" />
|
||||
<path
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillColor="?android:colorPrimary"
|
||||
android:pathData="M 285 120 L 350 120 Q 365 120 365 135 L 365 485 Q 365 500 350 500 L 285 500 Q 270 500 270 485 L 270 135 Q 270 120 285 120 Z" />
|
||||
<path
|
||||
android:fillColor="?android:textColorPrimary"
|
||||
android:fillColor="?android:colorPrimary"
|
||||
android:pathData="M 420 0 L 485 0 Q 500 0 500 15 L 500 485 Q 500 500 485 500 L 420 500 Q 405 500 405 485 L 405 15 Q 405 0 420 0 Z" />
|
||||
</vector>
|
||||
@@ -25,9 +25,18 @@
|
||||
app:layout_constraintTop_toBottomOf="@id/devicesTitle"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginTop="12dp"
|
||||
tools:listitem="@layout/item_ble_device" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/bleDevicesLoader"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/loader"
|
||||
app:layout_constraintTop_toBottomOf="@id/bleDevicesView"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/gotoControlButton"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -36,6 +45,7 @@
|
||||
android:enabled="false"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginBottom="12dp"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -17,6 +17,7 @@
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:text="Helicopter BLE" />
|
||||
|
||||
<TextView
|
||||
|
||||
Reference in New Issue
Block a user