CircleToSearch with multi search engine support for all android
Kotlin
clickable searchbar
AKS Labs57d670f08a7b
diff --git a/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt b/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.ktindex be9586c..14bab1f 100644--- a/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt+++ b/app/src/main/java/com/akslabs/circletosearch/ui/CircleToSearchScreen.kt@@ -15,6 +15,7 @@ import androidx.compose.foundation.Imageimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.borderimport androidx.compose.foundation.gestures.detectDragGestures+import androidx.compose.foundation.gestures.detectTapGesturesimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.Row@@ -112,10 +113,12 @@ fun CircleToSearchScreen(val webViews = remember { mutableMapOf<SearchEngine, WebView>() }// Bottom Sheet State- val sheetState = rememberModalBottomSheetState(- skipPartiallyExpanded = false // Allow half-expanded state+ val scaffoldState = androidx.compose.material3.rememberBottomSheetScaffoldState(+ bottomSheetState = androidx.compose.material3.rememberStandardBottomSheetState(+ initialValue = androidx.compose.material3.SheetValue.Hidden,+ skipHiddenState = false+ ))- var showBottomSheet by remember { mutableStateOf(false) }// Drawing Stateval currentPathPoints = remember { mutableStateListOf<Offset>() }@@ -134,620 +137,640 @@ fun CircleToSearchScreen(animationSpec = tween(1000), label = "alpha")- // Root Box- Box(- modifier = Modifier- .fillMaxSize()- .background(Color.Black)- ) {- // 1. Screenshot Layer- if (screenshot != null) {- Box(- modifier = Modifier.fillMaxSize()- ) {- Image(- bitmap = screenshot.asImageBitmap(),- contentDescription = "Screenshot",- contentScale = ContentScale.Crop,- modifier = Modifier.fillMaxSize()- )+ // Helper to create and configure WebView+ fun createWebView(ctx: android.content.Context): WebView {+ return WebView(ctx).apply {+ layoutParams = ViewGroup.LayoutParams(+ ViewGroup.LayoutParams.MATCH_PARENT,+ ViewGroup.LayoutParams.MATCH_PARENT+ )++ // Caching & Performance - must be set on WebView directly+ setLayerType(android.view.View.LAYER_TYPE_HARDWARE, null)++ settings.apply {+ javaScriptEnabled = true+ domStorageEnabled = true+ databaseEnabled = true+ useWideViewPort = true+ loadWithOverviewMode = true+ setSupportZoom(true)+ builtInZoomControls = true+ displayZoomControls = false- // Tint Overlay- Box(- modifier = Modifier- .fillMaxSize()- .background(- brush = Brush.verticalGradient(- colors = OverlayGradientColors.map { it.copy(alpha = 0.3f) }- )- )- )- }- }-- // 2. Gradient Border Layer (Overlaying screenshot, clipped to rounded corners)- Box(- modifier = Modifier- .fillMaxSize()- .border(- width = 8.dp,- brush = Brush.verticalGradient(colors = OverlayGradientColors),- shape = RoundedCornerShape(24.dp) // Rounded corners for device- )- .clip(RoundedCornerShape(24.dp))- )-- // 3. Drawing Canvas (Interactive Layer)- Canvas(- modifier = Modifier- .fillMaxSize()- .pointerInput(Unit) {- detectDragGestures(- onDragStart = { offset ->- // Clear previous state- currentPathPoints.clear()- currentPathPoints.add(offset)- selectionRect = null- scope.launch { selectionAnim.snapTo(0f) }- },- onDrag = { change, _ ->- val offset = change.position- currentPathPoints.add(offset)- },- onDragEnd = {- if (currentPathPoints.isNotEmpty()) {- var minX = Float.MAX_VALUE- var minY = Float.MAX_VALUE- var maxX = Float.MIN_VALUE- var maxY = Float.MIN_VALUE-- currentPathPoints.forEach { p ->- minX = min(minX, p.x)- minY = min(minY, p.y)- maxX = max(maxX, p.x)- maxY = max(maxY, p.y)- }-- val rect = Rect(- minX.toInt(),- minY.toInt(),- maxX.toInt(),- maxY.toInt()- )-- selectionRect = rect- // Clear points to remove the drawn line and show the lens rect- currentPathPoints.clear()-- scope.launch {- selectionAnim.animateTo(- targetValue = 1f,- animationSpec = tween(600)- )- android.util.Log.d("CircleToSearch", "Selection rect: ${rect.left},${rect.top},${rect.right},${rect.bottom}")- selectedBitmap = ImageUtils.cropBitmap(screenshot!!, rect)- android.util.Log.d("CircleToSearch", "Cropped bitmap size: ${selectedBitmap!!.width}x${selectedBitmap!!.height}")- isSearching = true- showBottomSheet = true // Show the bottom sheet- }- }- }- )- }- ) {- // Draw current path (Real-time)- if (currentPathPoints.size > 1) {- val path = Path().apply {- moveTo(currentPathPoints.first().x, currentPathPoints.first().y)- for (i in 1 until currentPathPoints.size) {- lineTo(currentPathPoints[i].x, currentPathPoints[i].y)- }+ // Caching+ cacheMode = WebSettings.LOAD_DEFAULT++ // Enhanced settings for "Normal" browser behavior+ allowFileAccess = true+ allowContentAccess = true+ allowFileAccessFromFileURLs = true+ allowUniversalAccessFromFileURLs = true+ mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW++ userAgentString = if (isDesktopMode) {+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"+ } else {+ "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36"}- // Glow- drawPath(- path = path,- brush = Brush.linearGradient(OverlayGradientColors),- style = Stroke(width = 30f, cap = StrokeCap.Round, join = StrokeJoin.Round),- alpha = 0.6f- )- // Core- drawPath(- path = path,- color = Color.White,- style = Stroke(width = 12f, cap = StrokeCap.Round, join = StrokeJoin.Round)- )+ // Dark Mode+ if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {+ WebSettingsCompat.setForceDark(this, if (isDarkMode) WebSettingsCompat.FORCE_DARK_ON else WebSettingsCompat.FORCE_DARK_OFF)+ }}- // Draw Lens Animation (Rounded Corner Brackets)- if (selectionRect != null && selectionAnim.value > 0f) {- val rect = selectionRect!!- val progress = selectionAnim.value- val left = rect.left.toFloat()- val top = rect.top.toFloat()- val right = rect.right.toFloat()- val bottom = rect.bottom.toFloat()-- val width = right - left- val height = bottom - top- val cornerRadius = 64f // Increased radius for rounder look- val armLength = min(width, height) * 0.2f // Length of the straight part+ // Enable Third-Party Cookies+ android.webkit.CookieManager.getInstance().setAcceptThirdPartyCookies(this, true)- // Top Left- val tlPath = Path().apply {- moveTo(left, top + armLength)- lineTo(left, top + cornerRadius)- arcTo(- rect = androidx.compose.ui.geometry.Rect(left, top, left + 2 * cornerRadius, top + 2 * cornerRadius),- startAngleDegrees = 180f,- sweepAngleDegrees = 90f,- forceMoveTo = false- )- lineTo(left + armLength, top)- }- // Top Right- val trPath = Path().apply {- moveTo(right - armLength, top)- lineTo(right - cornerRadius, top)- arcTo(- rect = androidx.compose.ui.geometry.Rect(right - 2 * cornerRadius, top, right, top + 2 * cornerRadius),- startAngleDegrees = 270f,- sweepAngleDegrees = 90f,- forceMoveTo = false- )- lineTo(right, top + armLength)- }- // Bottom Right- val brPath = Path().apply {- moveTo(right, bottom - armLength)- lineTo(right, bottom - cornerRadius)- arcTo(- rect = androidx.compose.ui.geometry.Rect(right - 2 * cornerRadius, bottom - 2 * cornerRadius, right, bottom),- startAngleDegrees = 0f,- sweepAngleDegrees = 90f,- forceMoveTo = false- )- lineTo(right - armLength, bottom)- }- // Bottom Left- val blPath = Path().apply {- moveTo(left + armLength, bottom)- lineTo(left + cornerRadius, bottom)- arcTo(- rect = androidx.compose.ui.geometry.Rect(left, bottom - 2 * cornerRadius, left + 2 * cornerRadius, bottom),- startAngleDegrees = 90f,- sweepAngleDegrees = 90f,- forceMoveTo = false- )- lineTo(left, bottom - armLength)+ webViewClient = object : WebViewClient() {+ override fun shouldOverrideUrlLoading(view: WebView?, request: android.webkit.WebResourceRequest?): Boolean {+ return false // Load in WebView}-- val bracketAlpha = progress- val bracketStroke = Stroke(width = 12f, cap = StrokeCap.Round, join = StrokeJoin.Round)-- // Draw Brackets with Glow- listOf(tlPath, trPath, brPath, blPath).forEach { p ->- drawPath(p, Color.White, style = bracketStroke, alpha = bracketAlpha)- drawPath(p, Brush.linearGradient(OverlayGradientColors), style = Stroke(width = 20f, cap = StrokeCap.Round), alpha = bracketAlpha * 0.5f)+ }+ isNestedScrollingEnabled = true+ setOnTouchListener { v, event ->+ when (event.action) {+ android.view.MotionEvent.ACTION_DOWN -> {+ v.parent.requestDisallowInterceptTouchEvent(true)+ }+ android.view.MotionEvent.ACTION_UP, android.view.MotionEvent.ACTION_CANCEL -> {+ v.parent.requestDisallowInterceptTouchEvent(false)+ }}-- // Optional: Flash effect inside- drawRoundRect(- color = Color.White,- topLeft = Offset(left, top),- size = Size(width, height),- cornerRadius = CornerRadius(32f),- style = Stroke(width = 4f),- alpha = (1f - progress) * 0.5f- )+ false}}+ }- // 4. Header (Top)- Row(- modifier = Modifier- .fillMaxWidth()- .padding(top = 48.dp, start = 16.dp, end = 16.dp)- .align(Alignment.TopCenter),- verticalAlignment = Alignment.CenterVertically- ) {- IconButton(- onClick = onClose,+ // Back Handler Logic+ BackHandler(enabled = true) {+ val currentWebView = webViews[selectedEngine]+ if (currentWebView != null && currentWebView.canGoBack()) {+ currentWebView.goBack()+ } else if (scaffoldState.bottomSheetState.currentValue == androidx.compose.material3.SheetValue.Expanded) {+ scope.launch { scaffoldState.bottomSheetState.partialExpand() }+ } else if (scaffoldState.bottomSheetState.currentValue == androidx.compose.material3.SheetValue.PartiallyExpanded) {+ scope.launch { scaffoldState.bottomSheetState.hide() }+ } else {+ onClose()+ }+ }++ androidx.compose.material3.BottomSheetScaffold(+ scaffoldState = scaffoldState,+ sheetPeekHeight = 150.dp, // Peek height when collapsed+ sheetContainerColor = Color.Transparent,+ sheetContentColor = MaterialTheme.colorScheme.onSurface,+ sheetDragHandle = { BottomSheetDefaults.DragHandle() },+ sheetSwipeEnabled = true,+ sheetContent = {+ // Bottom Sheet Content (Results)+ Column(modifier = Modifier- .background(Color.Gray.copy(alpha = 0.5f), CircleShape)- .size(40.dp)+ .fillMaxWidth()+ .height(800.dp)+ .background(MaterialTheme.colorScheme.surface, RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp))) {- Icon(Icons.Default.Close, contentDescription = "Close", tint = Color.White)- }- Spacer(modifier = Modifier.weight(1f))- Text(- text = selectedEngine.name,- style = MaterialTheme.typography.headlineMedium.copy(- fontWeight = FontWeight.Bold,- color = Color.White- )- )- Spacer(modifier = Modifier.weight(1f))-- // Menu- Box {- var showMenu by remember { mutableStateOf(false) }- IconButton(- onClick = { showMenu = true },- modifier = Modifier- .background(Color.Gray.copy(alpha = 0.5f), CircleShape)- .size(40.dp)+ Spacer(modifier = Modifier.height(16.dp))++ // Tabs+ ScrollableTabRow(+ selectedTabIndex = searchEngines.indexOf(selectedEngine),+ edgePadding = 16.dp,+ containerColor = Color.Transparent,+ contentColor = MaterialTheme.colorScheme.onSurface,+ indicator = {}) {- Icon(Icons.Default.MoreVert, contentDescription = "Menu", tint = Color.White)+ searchEngines.forEach { engine ->+ val selected = selectedEngine == engine+ Tab(+ selected = selected,+ onClick = { selectedEngine = engine },+ text = {+ Text(+ engine.name,+ style = MaterialTheme.typography.labelLarge,+ modifier = Modifier+ .background(+ if (selected) MaterialTheme.colorScheme.secondaryContainer else MaterialTheme.colorScheme.surface,+ RoundedCornerShape(16.dp)+ )+ .padding(horizontal = 16.dp, vertical = 8.dp),+ color = if (selected) MaterialTheme.colorScheme.onSecondaryContainer else MaterialTheme.colorScheme.onSurface+ )+ }+ )+ }+ }++ // Reset everything when bitmap changes (new area selected)+ LaunchedEffect(selectedBitmap) {+ hostedImageUrl = null+ searchUrl = null+ preloadedUrls.clear()+ webViews.values.forEach { it.destroy() }+ webViews.clear()+ }++ // Preload Logic+ LaunchedEffect(selectedBitmap, hostedImageUrl) {+ if (selectedBitmap != null) {+ isLoading = true+ scope.launch { scaffoldState.bottomSheetState.expand() }++ // 1. Upload to host if needed (for URL-based engines)+ if (hostedImageUrl == null) {+ val url = ImageSearchUploader.uploadToImageHost(selectedBitmap!!)+ if (url != null) {+ hostedImageUrl = url+ } else {+ isLoading = false+ return@LaunchedEffect+ }+ }++ // 2. Preload ALL engines+ searchEngines.forEach { engine ->+ if (!preloadedUrls.containsKey(engine)) {+ val url = if (engine.isDirectUpload) {+ when (engine) {+ SearchEngine.Baidu -> ImageSearchUploader.getBaiduUrl(hostedImageUrl!!)+ SearchEngine.Lenso -> ImageSearchUploader.getLensoUrl(hostedImageUrl!!)+ SearchEngine.Perplexity -> ImageSearchUploader.getPerplexityUrl(hostedImageUrl!!)+ SearchEngine.ChatGPT -> ImageSearchUploader.getChatGPTUrl(hostedImageUrl!!)+ else -> null+ }+ } else {+ when (engine) {+ SearchEngine.Google -> ImageSearchUploader.getGoogleLensUrl(hostedImageUrl!!)+ SearchEngine.Bing -> ImageSearchUploader.getBingUrl(hostedImageUrl!!)+ SearchEngine.Yandex -> ImageSearchUploader.getYandexUrl(hostedImageUrl!!)+ SearchEngine.TinEye -> ImageSearchUploader.getTinEyeUrl(hostedImageUrl!!)+ else -> null+ }+ }++ if (url != null) {+ preloadedUrls[engine] = url+ }+ }+ }++ // Set current searchUrl+ searchUrl = preloadedUrls[selectedEngine]+ isLoading = false+ }}- androidx.compose.material3.DropdownMenu(- expanded = showMenu,- onDismissRequest = { showMenu = false }- ) {- androidx.compose.material3.DropdownMenuItem(- text = { Text(if (isDesktopMode) "Mobile Mode" else "Desktop Mode") },- onClick = {- isDesktopMode = !isDesktopMode- showMenu = false+ // Update searchUrl when engine changes+ LaunchedEffect(selectedEngine, preloadedUrls) {+ if (preloadedUrls.containsKey(selectedEngine)) {+ searchUrl = preloadedUrls[selectedEngine]+ }+ }++ Box(modifier = Modifier.fillMaxSize()) {+ // Show loading only if the SELECTED engine isn't ready+ if (isLoading || preloadedUrls[selectedEngine] == null) {+ Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {+ androidx.compose.material3.CircularProgressIndicator()}- )- androidx.compose.material3.DropdownMenuItem(- text = { Text(if (isDarkMode) "Light Mode" else "Dark Mode") },- onClick = {- isDarkMode = !isDarkMode- showMenu = false+ }++ // Dynamic Settings Update+ LaunchedEffect(isDesktopMode, isDarkMode) {+ val newUserAgent = if (isDesktopMode) {+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"+ } else {+ "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36"}- )- androidx.compose.material3.DropdownMenuItem(- text = { Text("Copy URL") },- onClick = {- if (searchUrl != null) {- val clipboard = context.getSystemService(android.content.Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager- val clip = android.content.ClipData.newPlainText("Search URL", searchUrl)- clipboard.setPrimaryClip(clip)+ webViews.values.forEach { wv ->+ if (wv.settings.userAgentString != newUserAgent) {+ wv.settings.userAgentString = newUserAgent+ }+ if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {+ WebSettingsCompat.setForceDark(wv.settings, if (isDarkMode) WebSettingsCompat.FORCE_DARK_ON else WebSettingsCompat.FORCE_DARK_OFF)}- showMenu = false}- )- androidx.compose.material3.DropdownMenuItem(- text = { Text("Open in Browser") },- onClick = {- if (searchUrl != null) {- try {- val intent = android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(searchUrl))- context.startActivity(intent)- } catch (e: Exception) {- android.util.Log.e("CircleToSearch", "Failed to open browser", e)- }+ }++ // Cleanup+ DisposableEffect(Unit) {+ onDispose {+ webViews.values.forEach { it.destroy() }+ webViews.clear()+ }+ }++ // Render ALL WebViews that have URLs+ searchEngines.forEach { engine ->+ val url = preloadedUrls[engine]+ if (url != null) {+ val isSelected = (engine == selectedEngine)++ androidx.compose.runtime.key(engine) {+ AndroidView(+ factory = { ctx ->+ val swipeRefresh = SwipeRefreshLayout(ctx).apply {+ layoutParams = ViewGroup.LayoutParams(+ ViewGroup.LayoutParams.MATCH_PARENT,+ ViewGroup.LayoutParams.MATCH_PARENT+ )+ }++ val webView = createWebView(ctx)+ webViews[engine] = webView+ webView.loadUrl(url)++ swipeRefresh.addView(webView)++ swipeRefresh.setOnRefreshListener {+ webView.reload()+ swipeRefresh.isRefreshing = false+ }++ swipeRefresh+ },+ update = { swipeRefresh ->+ var webView: WebView? = null+ for (i in 0 until swipeRefresh.childCount) {+ val child = swipeRefresh.getChildAt(i)+ if (child is WebView) {+ webView = child+ break+ }+ }++ if (webView != null) {+ // Update URL if changed (e.g. new search)+ if (webView.url != url && url != webView.originalUrl) {+ webView.loadUrl(url)+ }+ }+ },+ modifier = Modifier+ .fillMaxSize()+ .zIndex(if (isSelected) 1f else 0f)+ .graphicsLayer {+ alpha = if (isSelected) 1f else 0f+ }+ )}- showMenu = false}- )+ }}}}-- // 5. Search Bar / Pill (Bottom Fixed)+ ) { _ ->+ // Root BoxBox(modifier = Modifier- .align(Alignment.BottomCenter)- .fillMaxWidth()- .padding(horizontal = 16.dp, vertical = 24.dp)- .shadow(8.dp, CircleShape)- .background(Color(0xFF1F1F1F), CircleShape)- .height(64.dp)- .padding(horizontal = 20.dp)+ .fillMaxSize()+ .background(Color.Black)) {- Row(- modifier = Modifier.align(Alignment.CenterStart),- verticalAlignment = Alignment.CenterVertically- ) {- if (selectedBitmap != null) {+ // 1. Screenshot Layer+ if (screenshot != null) {+ Box(+ modifier = Modifier.fillMaxSize()+ ) {Image(- bitmap = selectedBitmap!!.asImageBitmap(),- contentDescription = "Selected",+ bitmap = screenshot.asImageBitmap(),+ contentDescription = "Screenshot",contentScale = ContentScale.Crop,+ modifier = Modifier.fillMaxSize()+ )++ // Tint Overlay+ Box(modifier = Modifier- .size(40.dp)- .clip(RoundedCornerShape(12.dp))- .border(1.dp, Color.Gray, RoundedCornerShape(12.dp))+ .fillMaxSize()+ .background(+ brush = Brush.verticalGradient(+ colors = OverlayGradientColors.map { it.copy(alpha = 0.3f) }+ )+ ))- } else {- // G Logo- Row {- Text("G", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFF4285F4)))- Text("o", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFFEA4335)))- Text("o", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFFFBBC05)))- Text("g", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFF4285F4)))- Text("l", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFF34A853)))- Text("e", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFFEA4335)))- }}}-- Row(- modifier = Modifier.align(Alignment.CenterEnd),- verticalAlignment = Alignment.CenterVertically- ) {- Icon(Icons.Default.Mic, "Mic", tint = Color.White)- Spacer(modifier = Modifier.width(24.dp))- Icon(Icons.Default.MusicNote, "Music", tint = Color.White)- Spacer(modifier = Modifier.width(24.dp))- Icon(Icons.Default.Translate, "Translate", tint = Color.White)- }- }- // 6. Modal Bottom Sheet- if (showBottomSheet) {- ModalBottomSheet(- onDismissRequest = { showBottomSheet = false },- sheetState = sheetState,- dragHandle = { BottomSheetDefaults.DragHandle() },- containerColor = Color.Transparent,- scrimColor = Color.Black.copy(alpha = 0.3f)- ) {- // Bottom Sheet Content (Results)- Column(- modifier = Modifier- .fillMaxWidth()- .height(800.dp)- .background(MaterialTheme.colorScheme.surface, RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp))- ) {- Spacer(modifier = Modifier.height(16.dp))-- // Tabs- ScrollableTabRow(- selectedTabIndex = searchEngines.indexOf(selectedEngine),- edgePadding = 16.dp,- containerColor = Color.Transparent,- contentColor = MaterialTheme.colorScheme.onSurface,- indicator = {}- ) {- searchEngines.forEach { engine ->- val selected = selectedEngine == engine- Tab(- selected = selected,- onClick = { selectedEngine = engine },- text = {- Text(- engine.name,- style = MaterialTheme.typography.labelLarge,- modifier = Modifier- .background(- if (selected) MaterialTheme.colorScheme.secondaryContainer else MaterialTheme.colorScheme.surface,- RoundedCornerShape(16.dp)- )- .padding(horizontal = 16.dp, vertical = 8.dp),- color = if (selected) MaterialTheme.colorScheme.onSecondaryContainer else MaterialTheme.colorScheme.onSurface- )- }- )- }- }-- // Reset hosted URL when bitmap changes- LaunchedEffect(selectedBitmap) {- hostedImageUrl = null- searchUrl = null- }+ // 2. Gradient Border Layer (Overlaying screenshot, clipped to rounded corners)+ Box(+ modifier = Modifier+ .fillMaxSize()+ .border(+ width = 8.dp,+ brush = Brush.verticalGradient(colors = OverlayGradientColors),+ shape = RoundedCornerShape(24.dp) // Rounded corners for device+ )+ .clip(RoundedCornerShape(24.dp))+ )- // Preload Logic- LaunchedEffect(selectedBitmap, hostedImageUrl) {- if (selectedBitmap != null) {- isLoading = true-- // 1. Upload to host if needed (for URL-based engines)- if (hostedImageUrl == null) {- val url = ImageSearchUploader.uploadToImageHost(selectedBitmap!!)- if (url != null) {- hostedImageUrl = url- } else {- isLoading = false- return@LaunchedEffect- }- }+ // 3. Drawing Canvas (Interactive Layer)+ Canvas(+ modifier = Modifier+ .fillMaxSize()+ .pointerInput(Unit) {+ detectDragGestures(+ onDragStart = { offset ->+ // Clear previous state+ currentPathPoints.clear()+ currentPathPoints.add(offset)+ selectionRect = null+ scope.launch { selectionAnim.snapTo(0f) }+ },+ onDrag = { change, _ ->+ val offset = change.position+ currentPathPoints.add(offset)+ },+ onDragEnd = {+ if (currentPathPoints.isNotEmpty()) {+ var minX = Float.MAX_VALUE+ var minY = Float.MAX_VALUE+ var maxX = Float.MIN_VALUE+ var maxY = Float.MIN_VALUE- // 2. Preload ALL engines- searchEngines.forEach { engine ->- if (!preloadedUrls.containsKey(engine)) {- val url = if (engine.isDirectUpload) {- when (engine) {- SearchEngine.Baidu -> ImageSearchUploader.getBaiduUrl(hostedImageUrl!!)- SearchEngine.Lenso -> ImageSearchUploader.getLensoUrl(hostedImageUrl!!)- SearchEngine.Perplexity -> ImageSearchUploader.getPerplexityUrl(hostedImageUrl!!)- SearchEngine.ChatGPT -> ImageSearchUploader.getChatGPTUrl(hostedImageUrl!!)- else -> null- }- } else {- when (engine) {- SearchEngine.Google -> ImageSearchUploader.getGoogleLensUrl(hostedImageUrl!!)- SearchEngine.Bing -> ImageSearchUploader.getBingUrl(hostedImageUrl!!)- SearchEngine.Yandex -> ImageSearchUploader.getYandexUrl(hostedImageUrl!!)- SearchEngine.TinEye -> ImageSearchUploader.getTinEyeUrl(hostedImageUrl!!)- else -> null- }+ currentPathPoints.forEach { p ->+ minX = min(minX, p.x)+ minY = min(minY, p.y)+ maxX = max(maxX, p.x)+ maxY = max(maxY, p.y)}- if (url != null) {- preloadedUrls[engine] = url+ val rect = Rect(+ minX.toInt(),+ minY.toInt(),+ maxX.toInt(),+ maxY.toInt()+ )++ selectionRect = rect+ // Clear points to remove the drawn line and show the lens rect+ currentPathPoints.clear()++ scope.launch {+ selectionAnim.animateTo(+ targetValue = 1f,+ animationSpec = tween(600)+ )+ android.util.Log.d("CircleToSearch", "Selection rect: ${rect.left},${rect.top},${rect.right},${rect.bottom}")+ selectedBitmap = ImageUtils.cropBitmap(screenshot!!, rect)+ android.util.Log.d("CircleToSearch", "Cropped bitmap size: ${selectedBitmap!!.width}x${selectedBitmap!!.height}")+ isSearching = true+ // Sheet expands automatically in LaunchedEffect}}}-- // Set current searchUrl- searchUrl = preloadedUrls[selectedEngine]- isLoading = false- }+ )}-- // Update searchUrl when engine changes- LaunchedEffect(selectedEngine, preloadedUrls) {- if (preloadedUrls.containsKey(selectedEngine)) {- searchUrl = preloadedUrls[selectedEngine]+ ) {+ // Draw current path (Real-time)+ if (currentPathPoints.size > 1) {+ val path = Path().apply {+ moveTo(currentPathPoints.first().x, currentPathPoints.first().y)+ for (i in 1 until currentPathPoints.size) {+ lineTo(currentPathPoints[i].x, currentPathPoints[i].y)}}++ // Glow+ drawPath(+ path = path,+ brush = Brush.linearGradient(OverlayGradientColors),+ style = Stroke(width = 30f, cap = StrokeCap.Round, join = StrokeJoin.Round),+ alpha = 0.6f+ )+ // Core+ drawPath(+ path = path,+ color = Color.White,+ style = Stroke(width = 12f, cap = StrokeCap.Round, join = StrokeJoin.Round)+ )+ }- // Helper to create and configure WebView- fun createWebView(ctx: android.content.Context): WebView {- return WebView(ctx).apply {- layoutParams = ViewGroup.LayoutParams(- ViewGroup.LayoutParams.MATCH_PARENT,- ViewGroup.LayoutParams.MATCH_PARENT- )- settings.apply {- javaScriptEnabled = true- domStorageEnabled = true- databaseEnabled = true- useWideViewPort = true- loadWithOverviewMode = true- setSupportZoom(true)- builtInZoomControls = true- displayZoomControls = false-- // Enhanced settings for "Normal" browser behavior- allowFileAccess = true- allowContentAccess = true- allowFileAccessFromFileURLs = true- allowUniversalAccessFromFileURLs = true- mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW-- userAgentString = if (isDesktopMode) {- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"- } else {- "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36"- }-- // Dark Mode- if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {- WebSettingsCompat.setForceDark(this, if (isDarkMode) WebSettingsCompat.FORCE_DARK_ON else WebSettingsCompat.FORCE_DARK_OFF)- }- }-- // Enable Third-Party Cookies- android.webkit.CookieManager.getInstance().setAcceptThirdPartyCookies(this, true)+ // Draw Lens Animation (Rounded Corner Brackets)+ if (selectionRect != null && selectionAnim.value > 0f) {+ val rect = selectionRect!!+ val progress = selectionAnim.value+ val left = rect.left.toFloat()+ val top = rect.top.toFloat()+ val right = rect.right.toFloat()+ val bottom = rect.bottom.toFloat()++ val width = right - left+ val height = bottom - top+ val cornerRadius = 64f // Increased radius for rounder look+ val armLength = min(width, height) * 0.2f // Length of the straight part- webViewClient = object : WebViewClient() {- override fun shouldOverrideUrlLoading(view: WebView?, request: android.webkit.WebResourceRequest?): Boolean {- return false // Load in WebView- }- }- isNestedScrollingEnabled = true- setOnTouchListener { v, event ->- when (event.action) {- android.view.MotionEvent.ACTION_DOWN -> {- v.parent.requestDisallowInterceptTouchEvent(true)- }- android.view.MotionEvent.ACTION_UP, android.view.MotionEvent.ACTION_CANCEL -> {- v.parent.requestDisallowInterceptTouchEvent(false)- }- }- false- }- }+ // Top Left+ val tlPath = Path().apply {+ moveTo(left, top + armLength)+ lineTo(left, top + cornerRadius)+ arcTo(+ rect = androidx.compose.ui.geometry.Rect(left, top, left + 2 * cornerRadius, top + 2 * cornerRadius),+ startAngleDegrees = 180f,+ sweepAngleDegrees = 90f,+ forceMoveTo = false+ )+ lineTo(left + armLength, top)+ }+ // Top Right+ val trPath = Path().apply {+ moveTo(right - armLength, top)+ lineTo(right - cornerRadius, top)+ arcTo(+ rect = androidx.compose.ui.geometry.Rect(right - 2 * cornerRadius, top, right, top + 2 * cornerRadius),+ startAngleDegrees = 270f,+ sweepAngleDegrees = 90f,+ forceMoveTo = false+ )+ lineTo(right, top + armLength)+ }+ // Bottom Right+ val brPath = Path().apply {+ moveTo(right, bottom - armLength)+ lineTo(right, bottom - cornerRadius)+ arcTo(+ rect = androidx.compose.ui.geometry.Rect(right - 2 * cornerRadius, bottom - 2 * cornerRadius, right, bottom),+ startAngleDegrees = 0f,+ sweepAngleDegrees = 90f,+ forceMoveTo = false+ )+ lineTo(right - armLength, bottom)+ }+ // Bottom Left+ val blPath = Path().apply {+ moveTo(left + armLength, bottom)+ lineTo(left + cornerRadius, bottom)+ arcTo(+ rect = androidx.compose.ui.geometry.Rect(left, bottom - 2 * cornerRadius, left + 2 * cornerRadius, bottom),+ startAngleDegrees = 90f,+ sweepAngleDegrees = 90f,+ forceMoveTo = false+ )+ lineTo(left, bottom - armLength)}- Box(modifier = Modifier.fillMaxSize()) {- // Show loading only if the SELECTED engine isn't ready- if (isLoading || preloadedUrls[selectedEngine] == null) {- Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {- androidx.compose.material3.CircularProgressIndicator()- }- }+ val bracketAlpha = progress+ val bracketStroke = Stroke(width = 12f, cap = StrokeCap.Round, join = StrokeJoin.Round)++ // Draw Brackets with Glow+ listOf(tlPath, trPath, brPath, blPath).forEach { p ->+ drawPath(p, Color.White, style = bracketStroke, alpha = bracketAlpha)+ drawPath(p, Brush.linearGradient(OverlayGradientColors), style = Stroke(width = 20f, cap = StrokeCap.Round), alpha = bracketAlpha * 0.5f)+ }++ // Optional: Flash effect inside+ drawRoundRect(+ color = Color.White,+ topLeft = Offset(left, top),+ size = Size(width, height),+ cornerRadius = CornerRadius(32f),+ style = Stroke(width = 4f),+ alpha = (1f - progress) * 0.5f+ )+ }+ }- // Back Handler- BackHandler(enabled = true) {- val currentWebView = webViews[selectedEngine]- if (currentWebView != null && currentWebView.canGoBack()) {- currentWebView.goBack()- } else {- // Dismiss sheet- showBottomSheet = false+ // 4. Header (Top)+ Row(+ modifier = Modifier+ .fillMaxWidth()+ .padding(top = 48.dp, start = 16.dp, end = 16.dp)+ .align(Alignment.TopCenter),+ verticalAlignment = Alignment.CenterVertically+ ) {+ IconButton(+ onClick = onClose,+ modifier = Modifier+ .background(Color.Gray.copy(alpha = 0.5f), CircleShape)+ .size(40.dp)+ ) {+ Icon(Icons.Default.Close, contentDescription = "Close", tint = Color.White)+ }+ Spacer(modifier = Modifier.weight(1f))+ Text(+ text = selectedEngine.name,+ style = MaterialTheme.typography.headlineMedium.copy(+ fontWeight = FontWeight.Bold,+ color = Color.White+ )+ )+ Spacer(modifier = Modifier.weight(1f))++ // Menu+ Box {+ var showMenu by remember { mutableStateOf(false) }+ IconButton(+ onClick = { showMenu = true },+ modifier = Modifier+ .background(Color.Gray.copy(alpha = 0.5f), CircleShape)+ .size(40.dp)+ ) {+ Icon(Icons.Default.MoreVert, contentDescription = "Menu", tint = Color.White)+ }++ androidx.compose.material3.DropdownMenu(+ expanded = showMenu,+ onDismissRequest = { showMenu = false }+ ) {+ androidx.compose.material3.DropdownMenuItem(+ text = { Text(if (isDesktopMode) "Mobile Mode" else "Desktop Mode") },+ onClick = {+ isDesktopMode = !isDesktopMode+ showMenu = false}- }-- // Dynamic Settings Update- LaunchedEffect(isDesktopMode, isDarkMode) {- val newUserAgent = if (isDesktopMode) {- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"- } else {- "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36"+ )+ androidx.compose.material3.DropdownMenuItem(+ text = { Text(if (isDarkMode) "Light Mode" else "Dark Mode") },+ onClick = {+ isDarkMode = !isDarkMode+ showMenu = false}- webViews.values.forEach { wv ->- if (wv.settings.userAgentString != newUserAgent) {- wv.settings.userAgentString = newUserAgent- }- if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {- WebSettingsCompat.setForceDark(wv.settings, if (isDarkMode) WebSettingsCompat.FORCE_DARK_ON else WebSettingsCompat.FORCE_DARK_OFF)+ )+ androidx.compose.material3.DropdownMenuItem(+ text = { Text("Copy URL") },+ onClick = {+ if (searchUrl != null) {+ val clipboard = context.getSystemService(android.content.Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager+ val clip = android.content.ClipData.newPlainText("Search URL", searchUrl)+ clipboard.setPrimaryClip(clip)}+ showMenu = false}- }-- // Cleanup- DisposableEffect(Unit) {- onDispose {- webViews.values.forEach { it.destroy() }- webViews.clear()+ )+ androidx.compose.material3.DropdownMenuItem(+ text = { Text("Open in Browser") },+ onClick = {+ if (searchUrl != null) {+ try {+ val intent = android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(searchUrl))+ context.startActivity(intent)+ } catch (e: Exception) {+ android.util.Log.e("CircleToSearch", "Failed to open browser", e)+ }+ }+ showMenu = false}- }+ )+ }+ }+ }- // Render ALL WebViews that have URLs- searchEngines.forEach { engine ->- val url = preloadedUrls[engine]- if (url != null) {- val isSelected = (engine == selectedEngine)-- androidx.compose.runtime.key(engine) {- AndroidView(- factory = { ctx ->- val swipeRefresh = SwipeRefreshLayout(ctx).apply {- layoutParams = ViewGroup.LayoutParams(- ViewGroup.LayoutParams.MATCH_PARENT,- ViewGroup.LayoutParams.MATCH_PARENT- )- }-- val webView = createWebView(ctx)- webViews[engine] = webView- webView.loadUrl(url)-- swipeRefresh.addView(webView)-- swipeRefresh.setOnRefreshListener {- webView.reload()- swipeRefresh.isRefreshing = false- }-- swipeRefresh- },- update = { swipeRefresh ->- var webView: WebView? = null- for (i in 0 until swipeRefresh.childCount) {- val child = swipeRefresh.getChildAt(i)- if (child is WebView) {- webView = child- break- }- }-- if (webView != null) {- // Update URL if changed (e.g. new search)- if (webView.url != url && url != webView.originalUrl) {- webView.loadUrl(url)- }- }- },- modifier = Modifier- .fillMaxSize()- .zIndex(if (isSelected) 1f else 0f)- .graphicsLayer {- alpha = if (isSelected) 1f else 0f- }- )- }+ // 5. Search Bar / Pill (Bottom Fixed) - Clickable to open sheet+ Box(+ modifier = Modifier+ .align(Alignment.BottomCenter)+ .fillMaxWidth()+ .padding(horizontal = 16.dp, vertical = 24.dp)+ .shadow(8.dp, CircleShape)+ .background(Color(0xFF1F1F1F), CircleShape)+ .height(64.dp)+ .padding(horizontal = 20.dp)+ .pointerInput(Unit) {+ detectTapGestures {+ scope.launch {+ scaffoldState.bottomSheetState.expand()}}}+ ) {+ Row(+ modifier = Modifier.align(Alignment.CenterStart),+ verticalAlignment = Alignment.CenterVertically+ ) {+ if (selectedBitmap != null) {+ Image(+ bitmap = selectedBitmap!!.asImageBitmap(),+ contentDescription = "Selected",+ contentScale = ContentScale.Crop,+ modifier = Modifier+ .size(40.dp)+ .clip(RoundedCornerShape(12.dp))+ .border(1.dp, Color.Gray, RoundedCornerShape(12.dp))+ )+ } else {+ // G Logo+ Row {+ Text("G", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFF4285F4)))+ Text("o", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFFEA4335)))+ Text("o", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFFFBBC05)))+ Text("g", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFF4285F4)))+ Text("l", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFF34A853)))+ Text("e", style = MaterialTheme.typography.headlineMedium.copy(fontWeight = FontWeight.Bold, color = Color(0xFFEA4335)))+ }+ }+ }++ Row(+ modifier = Modifier.align(Alignment.CenterEnd),+ verticalAlignment = Alignment.CenterVertically+ ) {+ Icon(Icons.Default.Mic, "Mic", tint = Color.White)+ Spacer(modifier = Modifier.width(24.dp))+ Icon(Icons.Default.MusicNote, "Music", tint = Color.White)+ Spacer(modifier = Modifier.width(24.dp))+ Icon(Icons.Default.Translate, "Translate", tint = Color.White)}}}diff --git a/build_log.txt b/build_log.txtindex f09f216..1e1451c 100644Binary files a/build_log.txt and b/build_log.txt differ