neco2018

Bluetooth module | #12

DeviceListFragment.kt import android.Manifestimport android.app.Activityimport android.bluetooth.BluetoothAdapterimport android.bluetooth.BluetoothDeviceimport android.bluetooth.BluetoothManagerimport android.content.BroadcastReceiverimport android.content.Contextimport android.content.Intentimport android.content.IntentFilterimport android.content.SharedPreferencesimport android.graphics.Colorimport android.os.Buildimport android.os.Bundleimport android.util.Logimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.recyclerview.widget.LinearLayoutManagerimport com.google.android.material.snackbar.Snackbarimport com.neco_dev.bt_def.databinding.FragmentListBindingclass DeviceListFragment : Fragment(), ItemAdapter.Listener { private var preferences: SharedPreferences? = null private lateinit var itemAdapter: ItemAdapter private lateinit var discoveryAdapter: ItemAdapter private var bAdapter: BluetoothAdapter? = null private lateinit var binding: FragmentListBinding private lateinit var btLauncher: ActivityResultLauncher<Intent> private lateinit var pLauncher: ActivityResultLauncher<Array<String>> override fun onCreateView(… Подробнее »Bluetooth module | #12

Bluetooth module | #11

DeviceListFragment.kt import android.Manifestimport android.app.Activityimport android.bluetooth.BluetoothAdapterimport android.bluetooth.BluetoothDeviceimport android.bluetooth.BluetoothManagerimport android.content.BroadcastReceiverimport android.content.Contextimport android.content.Intentimport android.content.IntentFilterimport android.content.SharedPreferencesimport android.graphics.Colorimport android.os.Buildimport android.os.Bundleimport android.util.Logimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.recyclerview.widget.LinearLayoutManagerimport com.google.android.material.snackbar.Snackbarimport com.neco_dev.bt_def.databinding.FragmentListBindingclass DeviceListFragment : Fragment(), ItemAdapter.Listener { private var preferences: SharedPreferences? = null private lateinit var itemAdapter: ItemAdapter private var bAdapter: BluetoothAdapter? = null private lateinit var binding: FragmentListBinding private lateinit var btLauncher: ActivityResultLauncher<Intent> private lateinit var pLauncher: ActivityResultLauncher<Array<String>> override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState:… Подробнее »Bluetooth module | #11

Bluetooth module | #10

DeviceListFragment import android.Manifestimport android.app.Activityimport android.bluetooth.BluetoothAdapterimport android.bluetooth.BluetoothDeviceimport android.bluetooth.BluetoothManagerimport android.content.Contextimport android.content.Intentimport android.content.SharedPreferencesimport android.graphics.Colorimport android.os.Buildimport android.os.Bundleimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.recyclerview.widget.LinearLayoutManagerimport com.google.android.material.snackbar.Snackbarimport com.neco_dev.bt_def.databinding.FragmentListBindingclass DeviceListFragment : Fragment(), ItemAdapter.Listener { private var preferences: SharedPreferences? = null private lateinit var itemAdapter: ItemAdapter private var bAdapter: BluetoothAdapter? = null private lateinit var binding: FragmentListBinding private lateinit var btLauncher: ActivityResultLauncher<Intent> private lateinit var pLauncher: ActivityResultLauncher<Array<String>> override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View… Подробнее »Bluetooth module | #10

Bluetooth module | #9

DeviceListFragment import android.app.Activityimport android.bluetooth.BluetoothAdapterimport android.bluetooth.BluetoothDeviceimport android.bluetooth.BluetoothManagerimport android.content.Contextimport android.content.Intentimport android.content.SharedPreferencesimport android.graphics.Colorimport android.os.Bundleimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.recyclerview.widget.LinearLayoutManagerimport com.google.android.material.snackbar.Snackbarimport com.neco_dev.bt_def.databinding.FragmentListBindingclass DeviceListFragment : Fragment(), ItemAdapter.Listener { private var preferences: SharedPreferences? = null private lateinit var itemAdapter: ItemAdapter private var bAdapter: BluetoothAdapter? = null private lateinit var binding: FragmentListBinding private lateinit var btLauncher: ActivityResultLauncher<Intent> override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { binding = FragmentListBinding.inflate(inflater, container, false) return… Подробнее »Bluetooth module | #9

Bluetooth module | #8

https://youtu.be/Vq4XYAcVFTg DeviceListFragment.kt import android.app.Activityimport android.bluetooth.BluetoothAdapterimport android.bluetooth.BluetoothDeviceimport android.bluetooth.BluetoothManagerimport android.content.Contextimport android.content.Intentimport android.graphics.Colorimport android.os.Bundleimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.recyclerview.widget.LinearLayoutManagerimport com.google.android.material.snackbar.Snackbarimport com.neco_dev.bt_def.databinding.FragmentListBindingclass DeviceListFragment : Fragment(), ItemAdapter.Listener { private lateinit var itemAdapter: ItemAdapter private var bAdapter: BluetoothAdapter? = null private lateinit var binding: FragmentListBinding private lateinit var btLauncher: ActivityResultLauncher<Intent> override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { binding = FragmentListBinding.inflate(inflater, container, false) return binding.root } override fun onViewCreated(view: View,… Подробнее »Bluetooth module | #8

Bluetooth module | #7

https://youtu.be/nk7NodKFzgE DeviceLIstFragment.kt import android.app.Activityimport android.bluetooth.BluetoothAdapterimport android.bluetooth.BluetoothDeviceimport android.bluetooth.BluetoothManagerimport android.content.Contextimport android.content.Intentimport android.graphics.Colorimport android.os.Bundleimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.recyclerview.widget.LinearLayoutManagerimport com.google.android.material.snackbar.Snackbarimport com.neco_dev.bt_def.databinding.FragmentListBindingclass DeviceListFragment : Fragment() { private lateinit var itemAdapter: ItemAdapter private var bAdapter: BluetoothAdapter? = null private lateinit var binding: FragmentListBinding private lateinit var btLauncher: ActivityResultLauncher<Intent> override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { binding = FragmentListBinding.inflate(inflater, container, false) return binding.root } override fun onViewCreated(view: View, savedInstanceState:… Подробнее »Bluetooth module | #7

Bluetooth module | #6

DeviceListFragment import android.app.Activityimport android.bluetooth.BluetoothAdapterimport android.bluetooth.BluetoothManagerimport android.content.Contextimport android.content.Intentimport android.graphics.Colorimport android.os.Bundleimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport com.google.android.material.snackbar.Snackbarimport com.neco_dev.bt_def.databinding.FragmentListBindingclass DeviceListFragment : Fragment() { private var bAdapter: BluetoothAdapter? = null private lateinit var binding: FragmentListBinding private lateinit var btLauncher: ActivityResultLauncher<Intent> override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { binding = FragmentListBinding.inflate(inflater, container, false) return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.imBluetoothOn.setOnClickListener { btLauncher.launch(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)) }… Подробнее »Bluetooth module | #6

Bluetooth module | #5

Extensions.kt import android.widget.ImageButtonimport androidx.core.graphics.drawable.DrawableCompatimport androidx.fragment.app.Fragmentfun Fragment.changeButtonColor(button: ImageButton, color: Int){ val drawable = button.drawable DrawableCompat.setTint(drawable, color) button.setImageDrawable(drawable)} BaseActivity.kt import androidx.appcompat.app.AppCompatActivityimport android.os.Bundleimport androidx.recyclerview.widget.LinearLayoutManagerimport androidx.recyclerview.widget.RecyclerViewclass BaseActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_base) // initRcView() supportFragmentManager.beginTransaction() .replace(R.id.placeHolder, DeviceListFragment()).commit() } private fun initRcView(){ val rcView = findViewById<RecyclerView>(R.id.rcViewPaired) rcView.layoutManager = LinearLayoutManager(this) val adapter = ItemAdapter() rcView.adapter = adapter adapter.submitList(createDeviceList()) } private fun createDeviceList(): List<ListItem>{ val list = ArrayList<ListItem>() for (i in 0… Подробнее »Bluetooth module | #5

Bluetooth module | #4

BaseActivity.kt import androidx.appcompat.app.AppCompatActivityimport android.os.Bundleimport androidx.recyclerview.widget.LinearLayoutManagerimport androidx.recyclerview.widget.RecyclerViewclass BaseActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.fragment_list) initRcView() } private fun initRcView(){ val rcView = findViewById<RecyclerView>(R.id.rcViewPaired) rcView.layoutManager = LinearLayoutManager(this) val adapter = ItemAdapter() rcView.adapter = adapter adapter.submitList(createDeviceList()) } private fun createDeviceList(): List<ListItem>{ val list = ArrayList<ListItem>() for (i in 0 until 5){ list.add( ListItem( “Device $i”, “34:56:89:56” ) ) } return list }} ListItem.kt data class ListItem( val name: String,… Подробнее »Bluetooth module | #4

Bluetooth module | #3

list_item.xml <?xml version=”1.0″ encoding=”utf-8″?><androidx.cardview.widget.CardView xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_marginStart=”3dp” android:layout_marginTop=”3dp” android:layout_marginEnd=”3dp” app:cardBackgroundColor=”#1B1B1B” app:cardCornerRadius=”6dp”> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width=”match_parent” android:layout_height=”wrap_content”> <TextView android:id=”@+id/name” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginStart=”16dp” android:layout_marginTop=”5dp” android:text=”Esp 32″ android:textColor=”#ff8800″ android:textStyle=”bold” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” /> <TextView android:id=”@+id/mac” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginBottom=”5dp” android:text=”32:34:89:89″ android:textColor=”#42ABED” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintStart_toStartOf=”@+id/name” app:layout_constraintTop_toBottomOf=”@+id/name” /> <CheckBox android:id=”@+id/checkBox” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginEnd=”16dp” app:layout_constraintBottom_toBottomOf=”@+id/mac” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintTop_toTopOf=”@+id/name” /> </androidx.constraintlayout.widget.ConstraintLayout></androidx.cardview.widget.CardView>