diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5285acc..83e102d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,8 +1,9 @@ import com.android.build.api.dsl.ManagedVirtualDevice plugins { - id("com.android.application") - id("org.jetbrains.kotlin.android") + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.compose) } android { @@ -36,7 +37,7 @@ android { jvmTarget = libs.versions.build.jvmTarget.get() } buildFeatures { - viewBinding = true + compose = true } testOptions { unitTests { @@ -75,10 +76,20 @@ android { } dependencies { - implementation(libs.android.material) - implementation(libs.androidx.navigation.fragment.ktx) - implementation(libs.androidx.navigation.ui.ktx) + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.activity.compose) + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.androidx.ui) + implementation(libs.androidx.ui.graphics) + implementation(libs.androidx.ui.tooling.preview) + implementation(libs.androidx.material3) testImplementation(kotlin("test")) androidTestImplementation(kotlin("test")) - androidTestImplementation(libs.espresso.core) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.androidx.ui.test.junit4) + debugImplementation(libs.androidx.ui.tooling) + debugImplementation(libs.androidx.ui.test.manifest) } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e2ca5bd..6c90a90 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,11 +10,13 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/Theme.ManagedVirtualDevice" + android:theme="@style/Theme.MyApplication" tools:targetApi="31"> + android:exported="true" + android:label="@string/app_name" + android:theme="@style/Theme.MyApplication"> diff --git a/app/src/main/java/siarhei/luskanau/managed/virtual/device/FirstFragment.kt b/app/src/main/java/siarhei/luskanau/managed/virtual/device/FirstFragment.kt deleted file mode 100644 index fd1cebd..0000000 --- a/app/src/main/java/siarhei/luskanau/managed/virtual/device/FirstFragment.kt +++ /dev/null @@ -1,42 +0,0 @@ -package siarhei.luskanau.managed.virtual.device - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import androidx.navigation.fragment.findNavController -import siarhei.luskanau.managed.virtual.device.databinding.FragmentFirstBinding - -/** - * A simple [Fragment] subclass as the default destination in the navigation. - */ -class FirstFragment : Fragment() { - private var bindingLocal: FragmentFirstBinding? = null - - // This property is only valid between onCreateView and - // onDestroyView. - private val binding get() = bindingLocal!! - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - bindingLocal = FragmentFirstBinding.inflate(inflater, container, false) - return binding.root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - binding.buttonFirst.setOnClickListener { - findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment) - } - } - - override fun onDestroyView() { - super.onDestroyView() - bindingLocal = null - } -} diff --git a/app/src/main/java/siarhei/luskanau/managed/virtual/device/MainActivity.kt b/app/src/main/java/siarhei/luskanau/managed/virtual/device/MainActivity.kt index 9af601c..22cbcec 100644 --- a/app/src/main/java/siarhei/luskanau/managed/virtual/device/MainActivity.kt +++ b/app/src/main/java/siarhei/luskanau/managed/virtual/device/MainActivity.kt @@ -1,59 +1,49 @@ +@file:Suppress("FunctionNaming") + package siarhei.luskanau.managed.virtual.device import android.os.Bundle -import android.view.Menu -import android.view.MenuItem -import androidx.appcompat.app.AppCompatActivity -import androidx.core.view.WindowCompat -import androidx.navigation.findNavController -import androidx.navigation.ui.AppBarConfiguration -import androidx.navigation.ui.navigateUp -import androidx.navigation.ui.setupActionBarWithNavController -import com.google.android.material.snackbar.Snackbar -import siarhei.luskanau.managed.virtual.device.databinding.ActivityMainBinding - -class MainActivity : AppCompatActivity() { - private lateinit var appBarConfiguration: AppBarConfiguration - private lateinit var binding: ActivityMainBinding - +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import siarhei.luskanau.managed.virtual.device.ui.theme.MyApplicationTheme + +class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { - WindowCompat.setDecorFitsSystemWindows(window, false) super.onCreate(savedInstanceState) - - binding = ActivityMainBinding.inflate(layoutInflater) - setContentView(binding.root) - - setSupportActionBar(binding.toolbar) - - val navController = findNavController(R.id.nav_host_fragment_content_main) - appBarConfiguration = AppBarConfiguration(navController.graph) - setupActionBarWithNavController(navController, appBarConfiguration) - - binding.fab.setOnClickListener { view -> - Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) - .setAnchorView(R.id.fab) - .setAction("Action", null).show() + enableEdgeToEdge() + setContent { + MyApplicationTheme { + Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> + Greeting( + name = "Android", + modifier = Modifier.padding(innerPadding) + ) + } + } } } +} - override fun onCreateOptionsMenu(menu: Menu): Boolean { - // Inflate the menu; this adds items to the action bar if it is present. - menuInflater.inflate(R.menu.menu_main, menu) - return true - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - return when (item.itemId) { - R.id.action_settings -> true - else -> super.onOptionsItemSelected(item) - } - } +@Composable +fun Greeting(name: String, modifier: Modifier = Modifier) { + Text( + text = "Hello $name!", + modifier = modifier + ) +} - override fun onSupportNavigateUp(): Boolean { - val navController = findNavController(R.id.nav_host_fragment_content_main) - return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp() +@Preview(showBackground = true) +@Composable +fun GreetingPreview() { + MyApplicationTheme { + Greeting("Android") } } diff --git a/app/src/main/java/siarhei/luskanau/managed/virtual/device/SecondFragment.kt b/app/src/main/java/siarhei/luskanau/managed/virtual/device/SecondFragment.kt deleted file mode 100644 index 567947e..0000000 --- a/app/src/main/java/siarhei/luskanau/managed/virtual/device/SecondFragment.kt +++ /dev/null @@ -1,42 +0,0 @@ -package siarhei.luskanau.managed.virtual.device - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import androidx.navigation.fragment.findNavController -import siarhei.luskanau.managed.virtual.device.databinding.FragmentSecondBinding - -/** - * A simple [Fragment] subclass as the second destination in the navigation. - */ -class SecondFragment : Fragment() { - private var bindingLocal: FragmentSecondBinding? = null - - // This property is only valid between onCreateView and - // onDestroyView. - private val binding get() = bindingLocal!! - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - bindingLocal = FragmentSecondBinding.inflate(inflater, container, false) - return binding.root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - binding.buttonSecond.setOnClickListener { - findNavController().navigate(R.id.action_SecondFragment_to_FirstFragment) - } - } - - override fun onDestroyView() { - super.onDestroyView() - bindingLocal = null - } -} diff --git a/app/src/main/java/siarhei/luskanau/managed/virtual/device/ui/theme/Color.kt b/app/src/main/java/siarhei/luskanau/managed/virtual/device/ui/theme/Color.kt new file mode 100644 index 0000000..a366a86 --- /dev/null +++ b/app/src/main/java/siarhei/luskanau/managed/virtual/device/ui/theme/Color.kt @@ -0,0 +1,13 @@ +@file:Suppress("MagicNumber") + +package siarhei.luskanau.managed.virtual.device.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) diff --git a/app/src/main/java/siarhei/luskanau/managed/virtual/device/ui/theme/Theme.kt b/app/src/main/java/siarhei/luskanau/managed/virtual/device/ui/theme/Theme.kt new file mode 100644 index 0000000..554eab1 --- /dev/null +++ b/app/src/main/java/siarhei/luskanau/managed/virtual/device/ui/theme/Theme.kt @@ -0,0 +1,59 @@ +@file:Suppress("FunctionNaming") + +package siarhei.luskanau.managed.virtual.device.ui.theme + +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun MyApplicationTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} diff --git a/app/src/main/java/siarhei/luskanau/managed/virtual/device/ui/theme/Type.kt b/app/src/main/java/siarhei/luskanau/managed/virtual/device/ui/theme/Type.kt new file mode 100644 index 0000000..79e25c1 --- /dev/null +++ b/app/src/main/java/siarhei/luskanau/managed/virtual/device/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package siarhei.luskanau.managed.virtual.device.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml similarity index 100% rename from app/src/main/res/drawable-v24/ic_launcher_foreground.xml rename to app/src/main/res/drawable/ic_launcher_foreground.xml diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 16313e0..0000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml deleted file mode 100644 index e416e1c..0000000 --- a/app/src/main/res/layout/content_main.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_first.xml b/app/src/main/res/layout/fragment_first.xml deleted file mode 100644 index ddd9575..0000000 --- a/app/src/main/res/layout/fragment_first.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - -