Уроки по Kotlin Android Studio

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>

GPS Tracker

Серия уроков “Gps Tracker” На данном курсе создаем приложение для записи маршрутов бега или хотьбы с помощью Gps. Изучаем использование OSM (Open Street Maps) для отображения карты на экране смартфона, добавления маркеров, отрисовка маршрута, время прохождения маршрута, дистанция и средняя скорость. Используем базу данных и библиотеку Room для сохранения маршрутов. Используем таймер для отсчета времени. А также в приложении для работы в фоновом режиме создаем сервис для получения местоположения. Учимся… Подробнее »GPS Tracker

Bluetooth module | #2

https://youtu.be/JObsNyWqO6E fragment_list.xml <?xml version=”1.0″ encoding=”utf-8″?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:layout_width=”match_parent” android:layout_height=”match_parent” android:background=”#454545″> <androidx.cardview.widget.CardView android:id=”@+id/cardView” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_marginStart=”3dp” android:layout_marginTop=”3dp” android:layout_marginEnd=”3dp” android:backgroundTint=”#191919″ app:cardCornerRadius=”6dp” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent”> <LinearLayout android:layout_width=”match_parent” android:layout_height=”match_parent” android:gravity=”center” android:orientation=”horizontal”> <TextView android:id=”@+id/tvPaired” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginTop=”9dp” android:layout_marginEnd=”16dp” android:layout_marginBottom=”9dp” android:text=”@string/paired_devices” android:textColor=”@color/blue” /> <ImageButton android:id=”@+id/imBluetoothOn” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:background=”@null” app:srcCompat=”@drawable/ic_bluetooth_on” /> </LinearLayout> </androidx.cardview.widget.CardView> <androidx.cardview.widget.CardView android:id=”@+id/cardView2″ android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_marginStart=”3dp” android:layout_marginEnd=”3dp” android:backgroundTint=”#191919″ app:cardCornerRadius=”6dp” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”@+id/guideline2″> <LinearLayout android:layout_width=”match_parent” android:layout_height=”match_parent” android:gravity=”center” android:orientation=”horizontal”> <TextView android:id=”@+id/tvSearch” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginTop=”9dp” android:layout_marginEnd=”16dp” android:layout_marginBottom=”9dp” android:text=”@string/search_devices”… Подробнее »Bluetooth module | #2

Bluetooth module | #1

https://youtu.be/QKGdPJR_tbU AndroidManifest.xml <?xml version=”1.0″ encoding=”utf-8″?><manifest xmlns:android=”http://schemas.android.com/apk/res/android” > <uses-permission android:name=”android.permission.BLUETOOTH” /> <uses-permission android:name=”android.permission.BLUETOOTH_ADMIN” /> <uses-permission android:name=”android.permission.BLUETOOTH_SCAN” /> <uses-permission android:name=”android.permission.BLUETOOTH_CONNECT” /> <uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION” /> <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” /> <application> <activity android:name=”.BaseActivity” android:exported=”false” > <meta-data android:name=”android.app.lib_name” android:value=”” /> </activity> </application></manifest> MainActivity.kt import androidx.appcompat.app.AppCompatActivityimport android.os.Bundleclass MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) }} BaseActivity.kt import androidx.appcompat.app.AppCompatActivityimport android.os.Bundleclass BaseActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_base) }}

Weather App JetPack Compose #10 : MainList()

UI.kt import androidx.compose.foundation.clickableimport androidx.compose.foundation.layout.*import androidx.compose.foundation.lazy.LazyColumnimport androidx.compose.foundation.lazy.itemsIndexedimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.material.Cardimport androidx.compose.material.Textimport androidx.compose.runtime.Composableimport androidx.compose.runtime.MutableStateimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.text.TextStyleimport androidx.compose.ui.text.font.FontStyleimport androidx.compose.ui.tooling.preview.Previewimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.spimport coil.compose.AsyncImageimport com.meter_alc_rgb.weatherappcomposey.data.WeatherModelimport com.meter_alc_rgb.weatherappcomposey.ui.theme.BlueLight@Composablefun MainList(list: List<WeatherModel>, currentDay: MutableState<WeatherModel>){ LazyColumn( modifier = Modifier.fillMaxSize() ) { itemsIndexed( list ) { _, item -> ListItem(item, currentDay) } }}@Composablefun ListItem(item: WeatherModel, currentDay: MutableState<WeatherModel>) { Card( modifier = Modifier .fillMaxWidth() .padding(top = 3.dp).clickable { if (item.hours.isEmpty()) return@clickable currentDay.value = item }, backgroundColor = BlueLight, elevation = 0.dp,… Подробнее »Weather App JetPack Compose #10 : MainList()

NavigationView & Navigation #2

MainActivity import androidx.appcompat.app.AppCompatActivityimport android.os.Bundleimport androidx.navigation.NavControllerimport androidx.navigation.findNavControllerimport androidx.navigation.ui.AppBarConfigurationimport androidx.navigation.ui.navigateUpimport androidx.navigation.ui.setupActionBarWithNavControllerimport androidx.navigation.ui.setupWithNavControllerimport com.neco_dev.navigationdrawerlesson.databinding.ActivityMainBindingclass MainActivity : AppCompatActivity() { private lateinit var conf: AppBarConfiguration private lateinit var navController: NavController private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) setSupportActionBar(binding.ab.toolbar) navController = findNavController(R.id.fragmentContainerView) conf = AppBarConfiguration( setOf( R.id.item1, R.id.item2 ), binding.drawer ) setupActionBarWithNavController(navController, conf) binding.navView.setupWithNavController(navController) } override fun onSupportNavigateUp(): Boolean { return navController.navigateUp(conf) || super.onSupportNavigateUp() }} main_navigation.xml <?xml version=”1.0″… Подробнее »NavigationView & Navigation #2

NavigationView & Navigation

MainActivity import androidx.appcompat.app.AppCompatActivityimport android.os.Bundleclass MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) }} activity_main.xml <?xml version=”1.0″ encoding=”utf-8″?><androidx.drawerlayout.widget.DrawerLayout 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=”match_parent” android:fitsSystemWindows=”true” tools:openDrawer=”start” tools:context=”.MainActivity”> <com.google.android.material.navigation.NavigationView android:id=”@+id/navView” android:layout_width=”match_parent” android:layout_height=”match_parent” android:layout_gravity=”start” app:headerLayout=”@layout/header” android:fitsSystemWindows=”true” app:menu=”@menu/main_drawer” /> <include layout=”@layout/action_bar” android:layout_width=”wrap_content” android:layout_height=”wrap_content” /></androidx.drawerlayout.widget.DrawerLayout> header.xml <?xml version=”1.0″ encoding=”utf-8″?><androidx.constraintlayout.widget.ConstraintLayout 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=”170dp” android:background=”#8A0000″> <TextView android:id=”@+id/textView” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginStart=”16dp” android:layout_marginBottom=”5dp” android:text=”The sport app!” android:textColor=”#FDFDFD” android:textSize=”16sp” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintHorizontal_bias=”0.0″ app:layout_constraintStart_toStartOf=”parent” /> <ImageView android:id=”@+id/imageView”… Подробнее »NavigationView & Navigation

Navigation

MainActivity import androidx.appcompat.app.AppCompatActivityimport android.os.Bundleimport androidx.navigation.findNavControllerimport androidx.navigation.ui.setupActionBarWithNavControllerclass MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) setupActionBarWithNavController(findNavController(R.id.fragmentContainerView)) } override fun onSupportNavigateUp(): Boolean { val controller = findNavController(R.id.fragmentContainerView) return controller.navigateUp() || super.onSupportNavigateUp() }} dependencies implementation(“androidx.navigation:navigation-fragment-ktx:2.5.2”)implementation(“androidx.navigation:navigation-ui-ktx:2.5.2”) MainFragment import android.os.Bundleimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport android.widget.Buttonimport androidx.navigation.fragment.findNavControllerimport com.neco_dev.navtesty.Rclass MainFragment : Fragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_main,… Подробнее »Navigation

Weather App JetPack Compose #9 : MainCard()

https://youtu.be/4Q83Ns_N_8w MianScreen import androidx.compose.foundation.layout.*import androidx.compose.foundation.lazy.LazyColumnimport androidx.compose.foundation.lazy.itemsIndexedimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.material.*import androidx.compose.runtime.Composableimport androidx.compose.runtime.MutableStateimport androidx.compose.runtime.rememberCoroutineScopeimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clipimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.text.TextStyleimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.spimport coil.compose.AsyncImageimport com.google.accompanist.pager.ExperimentalPagerApiimport com.google.accompanist.pager.HorizontalPagerimport com.google.accompanist.pager.pagerTabIndicatorOffsetimport com.google.accompanist.pager.rememberPagerStateimport com.meter_alc_rgb.weatherappcomposey.Rimport com.meter_alc_rgb.weatherappcomposey.data.WeatherModelimport com.meter_alc_rgb.weatherappcomposey.ui.theme.BlueLightimport kotlinx.coroutines.launch@Composablefun MainCard(currentDay: MutableState<WeatherModel>) { Column( modifier = Modifier .padding(5.dp) ) { Card( modifier = Modifier.fillMaxWidth(), backgroundColor = BlueLight, elevation = 0.dp ) { Column( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally ) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween ) { Text( text… Подробнее »Weather App JetPack Compose #9 : MainCard()