Modern Apps git

← Modern-Apps.git

launcher: add launcher app with AppSearch universal search

Commit
2cff13677b6caa691100065ee317d551624f6a1b
Author
Vayun Mathur <[email protected]>
When
2026-06-11 20:39 UTC (5 months ago)
Parents
ecd79a7

Diff

launcher/build.gradle.kts
diff --git a/launcher/build.gradle.kts b/launcher/build.gradle.ktsnew file mode 100644index 0000000000..5ea580555e--- /dev/null+++ b/launcher/build.gradle.kts@@ -0,0 +1,15 @@+plugins {+    id("common-conventions-app")+}++android {+    defaultConfig {+        applicationId = "com.vayunmathur.launcher"+    }+}++dependencies {+    implementation("androidx.appsearch:appsearch:1.1.0-alpha06")+    implementation("androidx.appsearch:appsearch-local-storage:1.1.0-alpha06")+    implementation("androidx.compose.material:material-icons-core")+}
launcher/src/main/AndroidManifest.xml
diff --git a/launcher/src/main/AndroidManifest.xml b/launcher/src/main/AndroidManifest.xmlnew file mode 100644index 0000000000..fcfd6603b8--- /dev/null+++ b/launcher/src/main/AndroidManifest.xml@@ -0,0 +1,28 @@+<?xml version="1.0" encoding="utf-8"?>+<manifest xmlns:android="http://schemas.android.com/apk/res/android">++    <uses-permission android:name="android.permission.READ_CONTACTS" />+    <uses-permission android:name="android.permission.READ_CALENDAR" />++    <application+        android:allowBackup="true"+        android:icon="@mipmap/ic_launcher"+        android:label="@string/app_name"+        android:roundIcon="@mipmap/ic_launcher"+        android:supportsRtl="true"+        android:theme="@style/Theme.General">+        <activity+            android:name=".MainActivity"+            android:exported="true"+            android:theme="@style/Theme.General"+            android:launchMode="singleTask">+            <intent-filter>+                <action android:name="android.intent.action.MAIN" />+                <category android:name="android.intent.category.HOME" />+                <category android:name="android.intent.category.DEFAULT" />+                <category android:name="android.intent.category.LAUNCHER" />+            </intent-filter>+        </activity>+    </application>++</manifest>
launcher/src/main/java/com/vayunmathur/launcher/LauncherViewModel.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/LauncherViewModel.kt b/launcher/src/main/java/com/vayunmathur/launcher/LauncherViewModel.ktnew file mode 100644index 0000000000..e1f3913a35--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/LauncherViewModel.kt@@ -0,0 +1,97 @@+package com.vayunmathur.launcher++import android.app.Application+import android.content.Intent+import android.content.pm.PackageManager+import android.graphics.drawable.Drawable+import androidx.lifecycle.AndroidViewModel+import androidx.lifecycle.viewModelScope+import com.vayunmathur.launcher.search.GroupedResults+import com.vayunmathur.launcher.search.SearchManager+import kotlinx.coroutines.FlowPreview+import kotlinx.coroutines.flow.MutableStateFlow+import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.asStateFlow+import kotlinx.coroutines.flow.debounce+import kotlinx.coroutines.flow.stateIn+import kotlinx.coroutines.launch++data class AppInfo(+    val name: String,+    val packageName: String,+    val icon: Drawable+)++@OptIn(FlowPreview::class)+class LauncherViewModel(application: Application) : AndroidViewModel(application) {+    private val searchManager = SearchManager(application)++    private val _apps = MutableStateFlow<List<AppInfo>>(emptyList())+    val apps: StateFlow<List<AppInfo>> = _apps.asStateFlow()++    private val _query = MutableStateFlow("")+    val query: StateFlow<String> = _query.asStateFlow()++    private val _searchResults = MutableStateFlow(GroupedResults())+    val searchResults: StateFlow<GroupedResults> = _searchResults.asStateFlow()++    private val _isSearching = MutableStateFlow(false)+    val isSearching: StateFlow<Boolean> = _isSearching.asStateFlow()++    init {+        viewModelScope.launch {+            searchManager.initialize()+            loadApps()+            indexData()+        }++        viewModelScope.launch {+            _query.debounce(200).collect { q ->+                if (q.isNotBlank()) {+                    _searchResults.value = searchManager.search(q)+                } else {+                    _searchResults.value = GroupedResults()+                }+            }+        }+    }++    private fun loadApps() {+        val pm = getApplication<Application>().packageManager+        val intent = Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)+        val resolveInfos: List<ResolveInfo> = pm.queryIntentActivities(intent, PackageManager.MATCH_ALL)+        _apps.value = resolveInfos+            .mapNotNull { info ->+                val label = info.loadLabel(pm)?.toString() ?: return@mapNotNull null+                AppInfo(+                    name = label,+                    packageName = info.activityInfo.packageName,+                    icon = info.loadIcon(pm)+                )+            }+            .sortedBy { it.name.lowercase() }+    }++    private suspend fun indexData() {+        searchManager.indexApps()+        searchManager.indexContacts()+        searchManager.indexCalendarEvents()+    }++    fun setQuery(q: String) {+        _query.value = q+    }++    fun setSearching(active: Boolean) {+        _isSearching.value = active+        if (!active) {+            _query.value = ""+            _searchResults.value = GroupedResults()+        }+    }++    override fun onCleared() {+        super.onCleared()+        searchManager.close()+    }+}
launcher/src/main/java/com/vayunmathur/launcher/MainActivity.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/MainActivity.kt b/launcher/src/main/java/com/vayunmathur/launcher/MainActivity.ktnew file mode 100644index 0000000000..8b8639fb67--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/MainActivity.kt@@ -0,0 +1,22 @@+package com.vayunmathur.launcher++import android.os.Bundle+import androidx.activity.ComponentActivity+import androidx.activity.compose.setContent+import androidx.activity.enableEdgeToEdge+import androidx.lifecycle.viewmodel.compose.viewModel+import com.vayunmathur.launcher.ui.HomeScreen+import com.vayunmathur.library.ui.DynamicTheme++class MainActivity : ComponentActivity() {+    override fun onCreate(savedInstanceState: Bundle?) {+        super.onCreate(savedInstanceState)+        enableEdgeToEdge()+        setContent {+            DynamicTheme {+                val viewModel: LauncherViewModel = viewModel()+                HomeScreen(viewModel)+            }+        }+    }+}
launcher/src/main/java/com/vayunmathur/launcher/search/AppDocument.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/search/AppDocument.kt b/launcher/src/main/java/com/vayunmathur/launcher/search/AppDocument.ktnew file mode 100644index 0000000000..f950d4e83a--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/search/AppDocument.kt@@ -0,0 +1,7 @@+package com.vayunmathur.launcher.search++data class AppDocument(+    val id: String,+    val name: String,+    val packageName: String+)
launcher/src/main/java/com/vayunmathur/launcher/search/CalendarDocument.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/search/CalendarDocument.kt b/launcher/src/main/java/com/vayunmathur/launcher/search/CalendarDocument.ktnew file mode 100644index 0000000000..3648599b63--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/search/CalendarDocument.kt@@ -0,0 +1,9 @@+package com.vayunmathur.launcher.search++data class CalendarDocument(+    val id: String,+    val title: String,+    val date: String = "",+    val location: String = "",+    val eventId: Long = 0+)
launcher/src/main/java/com/vayunmathur/launcher/search/ContactDocument.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/search/ContactDocument.kt b/launcher/src/main/java/com/vayunmathur/launcher/search/ContactDocument.ktnew file mode 100644index 0000000000..a52323cbd9--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/search/ContactDocument.kt@@ -0,0 +1,8 @@+package com.vayunmathur.launcher.search++data class ContactDocument(+    val id: String,+    val name: String,+    val phones: String = "",+    val lookupKey: String = ""+)
launcher/src/main/java/com/vayunmathur/launcher/search/SearchManager.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/search/SearchManager.kt b/launcher/src/main/java/com/vayunmathur/launcher/search/SearchManager.ktnew file mode 100644index 0000000000..33d614ebbf--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/search/SearchManager.kt@@ -0,0 +1,270 @@+package com.vayunmathur.launcher.search++import android.content.Context+import android.content.Intent+import android.content.pm.PackageManager+import android.database.Cursor+import android.provider.CalendarContract+import android.provider.ContactsContract+import androidx.appsearch.app.AppSearchSchema+import androidx.appsearch.app.GenericDocument+import androidx.appsearch.app.PutDocumentsRequest+import androidx.appsearch.app.SearchSpec+import androidx.appsearch.app.SetSchemaRequest+import androidx.appsearch.localstorage.LocalStorage+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext+import kotlinx.datetime.TimeZone+import kotlinx.datetime.toLocalDateTime++sealed class SearchResult {+    data class App(val name: String, val packageName: String) : SearchResult()+    data class Contact(val name: String, val contactId: String, val phones: String, val lookupKey: String) : SearchResult()+    data class CalendarEvent(val title: String, val eventId: Long, val date: String, val location: String) : SearchResult()+}++data class GroupedResults(+    val apps: List<SearchResult.App> = emptyList(),+    val contacts: List<SearchResult.Contact> = emptyList(),+    val events: List<SearchResult.CalendarEvent> = emptyList()+)++private const val SCHEMA_APP = "AppDocument"+private const val SCHEMA_CONTACT = "ContactDocument"+private const val SCHEMA_CALENDAR = "CalendarDocument"++class SearchManager(private val context: Context) {+    private var session: androidx.appsearch.app.AppSearchSession? = null++    private val appSchema = AppSearchSchema.Builder(SCHEMA_APP)+        .addProperty(AppSearchSchema.StringPropertyConfig.Builder("name")+            .setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)+            .setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_PREFIXES)+            .setTokenizerType(AppSearchSchema.StringPropertyConfig.TOKENIZER_TYPE_PLAIN)+            .build())+        .addProperty(AppSearchSchema.StringPropertyConfig.Builder("packageName")+            .setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)+            .setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_PREFIXES)+            .setTokenizerType(AppSearchSchema.StringPropertyConfig.TOKENIZER_TYPE_PLAIN)+            .build())+        .build()++    private val contactSchema = AppSearchSchema.Builder(SCHEMA_CONTACT)+        .addProperty(AppSearchSchema.StringPropertyConfig.Builder("name")+            .setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)+            .setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_PREFIXES)+            .setTokenizerType(AppSearchSchema.StringPropertyConfig.TOKENIZER_TYPE_PLAIN)+            .build())+        .addProperty(AppSearchSchema.StringPropertyConfig.Builder("phones")+            .setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)+            .setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_PREFIXES)+            .setTokenizerType(AppSearchSchema.StringPropertyConfig.TOKENIZER_TYPE_PLAIN)+            .build())+        .addProperty(AppSearchSchema.StringPropertyConfig.Builder("lookupKey")+            .setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)+            .setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_NONE)+            .build())+        .build()++    private val calendarSchema = AppSearchSchema.Builder(SCHEMA_CALENDAR)+        .addProperty(AppSearchSchema.StringPropertyConfig.Builder("title")+            .setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)+            .setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_PREFIXES)+            .setTokenizerType(AppSearchSchema.StringPropertyConfig.TOKENIZER_TYPE_PLAIN)+            .build())+        .addProperty(AppSearchSchema.StringPropertyConfig.Builder("date")+            .setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)+            .setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_PREFIXES)+            .setTokenizerType(AppSearchSchema.StringPropertyConfig.TOKENIZER_TYPE_PLAIN)+            .build())+        .addProperty(AppSearchSchema.StringPropertyConfig.Builder("location")+            .setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)+            .setIndexingType(AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_PREFIXES)+            .setTokenizerType(AppSearchSchema.StringPropertyConfig.TOKENIZER_TYPE_PLAIN)+            .build())+        .addProperty(AppSearchSchema.LongPropertyConfig.Builder("eventId")+            .setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_OPTIONAL)+            .build())+        .build()++    suspend fun initialize() = withContext(Dispatchers.IO) {+        session = LocalStorage.createSearchSessionAsync(+            LocalStorage.SearchContext.Builder(context, "launcher_db").build()+        ).get()++        session!!.setSchemaAsync(+            SetSchemaRequest.Builder()+                .addSchemas(appSchema, contactSchema, calendarSchema)+                .setForceOverride(true)+                .build()+        ).get()+    }++    suspend fun indexApps() = withContext(Dispatchers.IO) {+        val intent = Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)+        val apps = context.packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL)+        val docs = apps.mapNotNull { info ->+            val label = info.loadLabel(context.packageManager)?.toString() ?: return@mapNotNull null+            GenericDocument.Builder<GenericDocument.Builder<*>>(+                "apps", info.activityInfo.packageName, SCHEMA_APP+            )+                .setPropertyString("name", label)+                .setPropertyString("packageName", info.activityInfo.packageName)+                .build()+        }+        if (docs.isNotEmpty()) {+            session?.putAsync(+                PutDocumentsRequest.Builder().addGenericDocuments(docs).build()+            )?.get()+        }+    }++    suspend fun indexContacts() = withContext(Dispatchers.IO) {+        val docs = mutableListOf<GenericDocument>()+        try {+            val cursor: Cursor? = context.contentResolver.query(+                ContactsContract.Contacts.CONTENT_URI,+                arrayOf(+                    ContactsContract.Contacts._ID,+                    ContactsContract.Contacts.DISPLAY_NAME_PRIMARY,+                    ContactsContract.Contacts.HAS_PHONE_NUMBER,+                    ContactsContract.Contacts.LOOKUP_KEY+                ),+                null, null, null+            )+            cursor?.use {+                while (it.moveToNext()) {+                    val id = it.getString(0)+                    val name = it.getString(1) ?: continue+                    val hasPhone = it.getInt(2) > 0+                    val lookupKey = it.getString(3) ?: ""+                    var phones = ""+                    if (hasPhone) {+                        val phoneCursor = context.contentResolver.query(+                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,+                            arrayOf(ContactsContract.CommonDataKinds.Phone.NUMBER),+                            "${ContactsContract.CommonDataKinds.Phone.CONTACT_ID} = ?",+                            arrayOf(id), null+                        )+                        phoneCursor?.use { pc ->+                            val numbers = mutableListOf<String>()+                            while (pc.moveToNext()) {+                                pc.getString(0)?.let { n -> numbers.add(n) }+                            }+                            phones = numbers.joinToString(", ")+                        }+                    }+                    docs.add(+                        GenericDocument.Builder<GenericDocument.Builder<*>>(+                            "contacts", "contact_$id", SCHEMA_CONTACT+                        )+                            .setPropertyString("name", name)+                            .setPropertyString("phones", phones)+                            .setPropertyString("lookupKey", lookupKey)+                            .build()+                    )+                }+            }+        } catch (_: SecurityException) { }++        if (docs.isNotEmpty()) {+            session?.putAsync(+                PutDocumentsRequest.Builder().addGenericDocuments(docs).build()+            )?.get()+        }+    }++    suspend fun indexCalendarEvents() = withContext(Dispatchers.IO) {+        val docs = mutableListOf<GenericDocument>()+        try {+            val cursor = context.contentResolver.query(+                CalendarContract.Events.CONTENT_URI,+                arrayOf(+                    CalendarContract.Events._ID,+                    CalendarContract.Events.TITLE,+                    CalendarContract.Events.DTSTART,+                    CalendarContract.Events.EVENT_LOCATION+                ),+                null, null, "${CalendarContract.Events.DTSTART} DESC LIMIT 200"+            )+            cursor?.use {+                while (it.moveToNext()) {+                    val id = it.getLong(0)+                    val title = it.getString(1) ?: continue+                    val dtStart = it.getLong(2)+                    val location = it.getString(3) ?: ""+                    val dateStr = kotlin.time.Instant.fromEpochMilliseconds(dtStart)+                        .toLocalDateTime(TimeZone.currentSystemDefault())+                        .date.toString()+                    docs.add(+                        GenericDocument.Builder<GenericDocument.Builder<*>>(+                            "calendar", "event_$id", SCHEMA_CALENDAR+                        )+                            .setPropertyString("title", title)+                            .setPropertyString("date", dateStr)+                            .setPropertyString("location", location)+                            .setPropertyLong("eventId", id)+                            .build()+                    )+                }+            }+        } catch (_: SecurityException) { }++        if (docs.isNotEmpty()) {+            session?.putAsync(+                PutDocumentsRequest.Builder().addGenericDocuments(docs).build()+            )?.get()+        }+    }++    suspend fun search(query: String): GroupedResults = withContext(Dispatchers.IO) {+        if (query.isBlank() || session == null) return@withContext GroupedResults()++        val searchResults = session!!.search(+            query,+            SearchSpec.Builder()+                .setTermMatch(SearchSpec.TERM_MATCH_PREFIX)+                .setResultCountPerPage(50)+                .build()+        )++        val page = searchResults.nextPageAsync.get()+        val apps = mutableListOf<SearchResult.App>()+        val contacts = mutableListOf<SearchResult.Contact>()+        val events = mutableListOf<SearchResult.CalendarEvent>()++        for (result in page) {+            val doc = result.genericDocument+            when (doc.schemaType) {+                SCHEMA_APP -> apps.add(+                    SearchResult.App(+                        name = doc.getPropertyString("name") ?: "",+                        packageName = doc.getPropertyString("packageName") ?: ""+                    )+                )+                SCHEMA_CONTACT -> contacts.add(+                    SearchResult.Contact(+                        name = doc.getPropertyString("name") ?: "",+                        contactId = doc.id.removePrefix("contact_"),+                        phones = doc.getPropertyString("phones") ?: "",+                        lookupKey = doc.getPropertyString("lookupKey") ?: ""+                    )+                )+                SCHEMA_CALENDAR -> events.add(+                    SearchResult.CalendarEvent(+                        title = doc.getPropertyString("title") ?: "",+                        eventId = doc.getPropertyLong("eventId"),+                        date = doc.getPropertyString("date") ?: "",+                        location = doc.getPropertyString("location") ?: ""+                    )+                )+            }+        }++        GroupedResults(apps, contacts, events)+    }++    fun close() {+        session?.close()+    }+}
launcher/src/main/java/com/vayunmathur/launcher/ui/HomeScreen.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/HomeScreen.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/HomeScreen.ktnew file mode 100644index 0000000000..d50d5a1dfc--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/HomeScreen.kt@@ -0,0 +1,253 @@+package com.vayunmathur.launcher.ui++import android.content.ContentUris+import android.content.Intent+import android.provider.CalendarContract+import android.provider.ContactsContract+import androidx.compose.foundation.Image+import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.WindowInsets+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.statusBars+import androidx.compose.foundation.layout.windowInsetsPadding+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.lazy.grid.GridCells+import androidx.compose.foundation.lazy.grid.LazyVerticalGrid+import androidx.compose.foundation.lazy.grid.items+import androidx.compose.foundation.lazy.items+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.material.icons.Icons+import androidx.compose.material.icons.filled.Close+import androidx.compose.material.icons.filled.DateRange+import androidx.compose.material.icons.filled.Person+import androidx.compose.material.icons.filled.Search+import androidx.compose.material3.ExperimentalMaterial3Api+import androidx.compose.material3.HorizontalDivider+import androidx.compose.material3.Icon+import androidx.compose.material3.IconButton+import androidx.compose.material3.ListItem+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.SearchBar+import androidx.compose.material3.SearchBarDefaults+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import android.graphics.Bitmap+import androidx.compose.runtime.remember+import androidx.compose.ui.graphics.asImageBitmap+import com.vayunmathur.launcher.AppInfo+import com.vayunmathur.launcher.LauncherViewModel+import com.vayunmathur.launcher.search.GroupedResults+import com.vayunmathur.launcher.search.SearchResult++@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun HomeScreen(viewModel: LauncherViewModel) {+    val apps by viewModel.apps.collectAsState()+    val query by viewModel.query.collectAsState()+    val searchResults by viewModel.searchResults.collectAsState()+    val isSearching by viewModel.isSearching.collectAsState()+    val context = LocalContext.current++    Column(+        modifier = Modifier+            .fillMaxSize()+            .windowInsetsPadding(WindowInsets.statusBars)+    ) {+        SearchBar(+            inputField = {+                SearchBarDefaults.InputField(+                    query = query,+                    onQueryChange = viewModel::setQuery,+                    onSearch = {},+                    expanded = isSearching,+                    onExpandedChange = viewModel::setSearching,+                    placeholder = { Text("Search apps, contacts, events…") },+                    leadingIcon = { Icon(Icons.Default.Search, contentDescription = null) },+                    trailingIcon = {+                        if (isSearching) {+                            IconButton(onClick = { viewModel.setSearching(false) }) {+                                Icon(Icons.Default.Close, contentDescription = "Close")+                            }+                        }+                    }+                )+            },+            expanded = isSearching,+            onExpandedChange = viewModel::setSearching,+            modifier = Modifier+                .fillMaxWidth()+                .padding(horizontal = if (isSearching) 0.dp else 16.dp)+        ) {+            SearchResultsList(searchResults) { result ->+                when (result) {+                    is SearchResult.App -> {+                        context.packageManager.getLaunchIntentForPackage(result.packageName)?.let {+                            context.startActivity(it)+                        }+                    }+                    is SearchResult.Contact -> {+                        val uri = ContactsContract.Contacts.getLookupUri(+                            result.contactId.toLongOrNull() ?: 0L,+                            result.lookupKey+                        )+                        context.startActivity(Intent(Intent.ACTION_VIEW, uri))+                    }+                    is SearchResult.CalendarEvent -> {+                        val uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, result.eventId)+                        context.startActivity(Intent(Intent.ACTION_VIEW, uri))+                    }+                }+            }+        }++        Spacer(Modifier.height(8.dp))++        AppGrid(apps) { app ->+            context.packageManager.getLaunchIntentForPackage(app.packageName)?.let {+                context.startActivity(it)+            }+        }+    }+}++@Composable+fun AppGrid(apps: List<AppInfo>, onAppClick: (AppInfo) -> Unit) {+    LazyVerticalGrid(+        columns = GridCells.Adaptive(80.dp),+        contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),+        horizontalArrangement = Arrangement.spacedBy(8.dp),+        verticalArrangement = Arrangement.spacedBy(16.dp),+        modifier = Modifier.fillMaxSize()+    ) {+        items(apps, key = { it.packageName }) { app ->+            Column(+                horizontalAlignment = Alignment.CenterHorizontally,+                modifier = Modifier+                    .clickable { onAppClick(app) }+                    .padding(4.dp)+            ) {+                Image(+                    bitmap = remember(app.icon) {+                        val w = app.icon.intrinsicWidth.coerceAtLeast(1)+                        val h = app.icon.intrinsicHeight.coerceAtLeast(1)+                        val bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)+                        val canvas = android.graphics.Canvas(bmp)+                        app.icon.setBounds(0, 0, w, h)+                        app.icon.draw(canvas)+                        bmp.asImageBitmap()+                    },+                    contentDescription = app.name,+                    modifier = Modifier+                        .size(52.dp)+                        .clip(CircleShape)+                )+                Spacer(Modifier.height(4.dp))+                Text(+                    text = app.name,+                    style = MaterialTheme.typography.labelSmall,+                    maxLines = 1,+                    overflow = TextOverflow.Ellipsis,+                    textAlign = TextAlign.Center,+                    modifier = Modifier.fillMaxWidth()+                )+            }+        }+    }+}++@Composable+fun SearchResultsList(results: GroupedResults, onResultClick: (SearchResult) -> Unit) {+    LazyColumn(+        modifier = Modifier.fillMaxSize(),+        contentPadding = PaddingValues(vertical = 8.dp)+    ) {+        if (results.apps.isNotEmpty()) {+            item {+                Text(+                    "Apps",+                    style = MaterialTheme.typography.titleSmall,+                    color = MaterialTheme.colorScheme.primary,+                    modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)+                )+            }+            items(results.apps) { app ->+                ListItem(+                    headlineContent = { Text(app.name) },+                    supportingContent = { Text(app.packageName, maxLines = 1, overflow = TextOverflow.Ellipsis) },+                    modifier = Modifier.clickable { onResultClick(app) }+                )+            }+        }+        if (results.contacts.isNotEmpty()) {+            item {+                if (results.apps.isNotEmpty()) HorizontalDivider(Modifier.padding(vertical = 4.dp))+                Text(+                    "Contacts",+                    style = MaterialTheme.typography.titleSmall,+                    color = MaterialTheme.colorScheme.primary,+                    modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)+                )+            }+            items(results.contacts) { contact ->+                ListItem(+                    headlineContent = { Text(contact.name) },+                    supportingContent = {+                        if (contact.phones.isNotBlank()) Text(contact.phones, maxLines = 1, overflow = TextOverflow.Ellipsis)+                    },+                    leadingContent = { Icon(Icons.Default.Person, contentDescription = null) },+                    modifier = Modifier.clickable { onResultClick(contact) }+                )+            }+        }+        if (results.events.isNotEmpty()) {+            item {+                if (results.apps.isNotEmpty() || results.contacts.isNotEmpty()) HorizontalDivider(Modifier.padding(vertical = 4.dp))+                Text(+                    "Events",+                    style = MaterialTheme.typography.titleSmall,+                    color = MaterialTheme.colorScheme.primary,+                    modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)+                )+            }+            items(results.events) { event ->+                ListItem(+                    headlineContent = { Text(event.title) },+                    supportingContent = {+                        val subtitle = listOfNotNull(+                            event.date.takeIf { it.isNotBlank() },+                            event.location.takeIf { it.isNotBlank() }+                        ).joinToString(" · ")+                        if (subtitle.isNotBlank()) Text(subtitle, maxLines = 1, overflow = TextOverflow.Ellipsis)+                    },+                    leadingContent = { Icon(Icons.Default.DateRange, contentDescription = null) },+                    modifier = Modifier.clickable { onResultClick(event) }+                )+            }+        }+        if (results.apps.isEmpty() && results.contacts.isEmpty() && results.events.isEmpty()) {+            item {+                Box(Modifier.fillMaxWidth().padding(32.dp), contentAlignment = Alignment.Center) {+                    Text("No results", style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+                }+            }+        }+    }+}
launcher/src/main/res/drawable/ic_launcher_foreground.xml
diff --git a/launcher/src/main/res/drawable/ic_launcher_foreground.xml b/launcher/src/main/res/drawable/ic_launcher_foreground.xmlnew file mode 100644index 0000000000..85f27c511d--- /dev/null+++ b/launcher/src/main/res/drawable/ic_launcher_foreground.xml@@ -0,0 +1,25 @@+<vector xmlns:android="http://schemas.android.com/apk/res/android"+    android:width="108dp"+    android:height="108dp"+    android:viewportWidth="108"+    android:viewportHeight="108">+    <group+        android:translateX="22"+        android:translateY="22">+        <path+            android:fillColor="#FFFFFF"+            android:pathData="M32,4C16.536,4 4,16.536 4,32s12.536,28 28,28 28,-12.536 28,-28S47.464,4 32,4zM32,12a4,4 0,0 1,4 4v12h12a4,4 0,0 1,0 8H36v12a4,4 0,0 1,-8 0V36H16a4,4 0,0 1,0 -8h12V16a4,4 0,0 1,4 -4z" />+        <path+            android:fillColor="#FFFFFF"+            android:pathData="M14,14L22,14L22,22L14,22Z" />+        <path+            android:fillColor="#FFFFFF"+            android:pathData="M42,14L50,14L50,22L42,22Z" />+        <path+            android:fillColor="#FFFFFF"+            android:pathData="M14,42L22,42L22,50L14,50Z" />+        <path+            android:fillColor="#FFFFFF"+            android:pathData="M42,42L50,42L50,50L42,50Z" />+    </group>+</vector>
launcher/src/main/res/mipmap-anydpi/ic_launcher.xml
diff --git a/launcher/src/main/res/mipmap-anydpi/ic_launcher.xml b/launcher/src/main/res/mipmap-anydpi/ic_launcher.xmlnew file mode 100644index 0000000000..0b0d585e42--- /dev/null+++ b/launcher/src/main/res/mipmap-anydpi/ic_launcher.xml@@ -0,0 +1,6 @@+<?xml version="1.0" encoding="utf-8"?>+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">+    <background android:drawable="@color/ic_launcher_background"/>+    <foreground android:drawable="@drawable/ic_launcher_foreground"/>+    <monochrome android:drawable="@drawable/ic_launcher_foreground"/>+</adaptive-icon>
launcher/src/main/res/resources.properties
diff --git a/launcher/src/main/res/resources.properties b/launcher/src/main/res/resources.propertiesnew file mode 100644index 0000000000..467b3efec9--- /dev/null+++ b/launcher/src/main/res/resources.properties@@ -0,0 +1 @@+unqualifiedResLocale=en-US
launcher/src/main/res/values/ic_launcher_background.xml
diff --git a/launcher/src/main/res/values/ic_launcher_background.xml b/launcher/src/main/res/values/ic_launcher_background.xmlnew file mode 100644index 0000000000..e42fce05e8--- /dev/null+++ b/launcher/src/main/res/values/ic_launcher_background.xml@@ -0,0 +1,4 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+    <color name="ic_launcher_background">#1B6EF3</color>+</resources>
launcher/src/main/res/values/strings.xml
diff --git a/launcher/src/main/res/values/strings.xml b/launcher/src/main/res/values/strings.xmlnew file mode 100644index 0000000000..78fbe65af5--- /dev/null+++ b/launcher/src/main/res/values/strings.xml@@ -0,0 +1,4 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+    <string name="app_name">Launcher</string>+</resources>
settings.gradle.kts
diff --git a/settings.gradle.kts b/settings.gradle.ktsindex 90ec6b5cc3..587b7f6778 100644--- a/settings.gradle.kts+++ b/settings.gradle.kts@@ -58,3 +58,4 @@ include(":camera") include(":sdk:openassistant") include(":sdk:games") include(":games:app")+include(":launcher")