<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Mobile_Apps_2023W_Lecture_19</id>
	<title>Mobile Apps 2023W Lecture 19 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Mobile_Apps_2023W_Lecture_19"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Mobile_Apps_2023W_Lecture_19&amp;action=history"/>
	<updated>2026-04-08T03:16:31Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Mobile_Apps_2023W_Lecture_19&amp;diff=24405&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Notes==  &lt;pre&gt; March 22 --------  Integrating webview with HNTree  we have composable functions that we can copy over, but how should the app actually work?  Should start up as a web browser with a URL bar, with a button to the side of the URL bar that says &quot;History&quot;.  Clicking on the button will switch the view to the History view.  If the user taps on a specific past URL, visit the page (potentially with confirmation)  What&#039;s the strategy?  - first, change the webvie...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Mobile_Apps_2023W_Lecture_19&amp;diff=24405&amp;oldid=prev"/>
		<updated>2023-03-22T21:13:12Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Notes==  &amp;lt;pre&amp;gt; March 22 --------  Integrating webview with HNTree  we have composable functions that we can copy over, but how should the app actually work?  Should start up as a web browser with a URL bar, with a button to the side of the URL bar that says &amp;quot;History&amp;quot;.  Clicking on the button will switch the view to the History view.  If the user taps on a specific past URL, visit the page (potentially with confirmation)  What&amp;#039;s the strategy?  - first, change the webvie...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
March 22&lt;br /&gt;
--------&lt;br /&gt;
&lt;br /&gt;
Integrating webview with HNTree&lt;br /&gt;
&lt;br /&gt;
we have composable functions that we can copy over, but how should the app actually work?&lt;br /&gt;
&lt;br /&gt;
Should start up as a web browser with a URL bar, with a button to the side of the URL bar that says &amp;quot;History&amp;quot;.  Clicking on the button will switch the view to the History view.  If the user taps on a specific past URL, visit the page (potentially with confirmation)&lt;br /&gt;
&lt;br /&gt;
What&amp;#039;s the strategy?&lt;br /&gt;
 - first, change the webviewCompose app to have a URL bar and a history button&lt;br /&gt;
 - then, copy code over to historyviewer&lt;br /&gt;
&lt;br /&gt;
Why?&lt;br /&gt;
 - separate complexity of interface design from &amp;quot;backend&amp;quot; (core functionality) design&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
My general strategy - get to &amp;quot;working code&amp;quot; ASAP, never have something that doesn&amp;#039;t run for too long&lt;br /&gt;
 - if you don&amp;#039;t do this, conceptual issues can persist for way too long&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;kotlin&amp;quot; line&amp;gt;&lt;br /&gt;
package carleton.comp2601.webviewcompose&lt;br /&gt;
&lt;br /&gt;
import android.os.Bundle&lt;br /&gt;
import android.view.ViewGroup&lt;br /&gt;
import android.webkit.WebView&lt;br /&gt;
import android.webkit.WebViewClient&lt;br /&gt;
import androidx.activity.ComponentActivity&lt;br /&gt;
import androidx.activity.compose.setContent&lt;br /&gt;
import androidx.compose.material.*&lt;br /&gt;
import androidx.compose.runtime.*&lt;br /&gt;
import androidx.compose.ui.graphics.Color&lt;br /&gt;
import androidx.compose.ui.tooling.preview.Preview&lt;br /&gt;
import androidx.compose.ui.viewinterop.AndroidView&lt;br /&gt;
&lt;br /&gt;
class MainActivity : ComponentActivity() {&lt;br /&gt;
&lt;br /&gt;
    override fun onCreate(savedInstanceState: Bundle?) {&lt;br /&gt;
        super.onCreate(savedInstanceState)&lt;br /&gt;
        setContent {&lt;br /&gt;
            // Calling the composable function&lt;br /&gt;
            // to display element and its contents&lt;br /&gt;
            MainContent()&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Creating a composable&lt;br /&gt;
// function to display Top Bar&lt;br /&gt;
@Composable&lt;br /&gt;
fun MainContent() {&lt;br /&gt;
    var curURL by remember { mutableStateOf(&amp;quot;https://news.ycombinator.com&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
    Scaffold(&lt;br /&gt;
//        topBar = { TopAppBar(title = {Text(&amp;quot;COMP 2601&amp;quot;)})},&lt;br /&gt;
        topBar = { URLBar(curURL = curURL, updateURL = { curURL = it }) },&lt;br /&gt;
        content = { MyContent(curURL = curURL, updateURL = { curURL = it }) }&lt;br /&gt;
    )&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
@Composable&lt;br /&gt;
fun URLBar(curURL: String, updateURL: (String) -&amp;gt; Unit) {&lt;br /&gt;
    var newURL = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    TextField(&lt;br /&gt;
        value = curURL,&lt;br /&gt;
        //onFocusChange = { updateURL(newURL) },&lt;br /&gt;
        //onValueChange = { updatedURL: String -&amp;gt; newURL = updatedURL},&lt;br /&gt;
        onValueChange = updateURL,&lt;br /&gt;
        label = { Text(&amp;quot;Enter URL here&amp;quot;) }&lt;br /&gt;
    )&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Creating a composable&lt;br /&gt;
// function to create WebView&lt;br /&gt;
// Calling this function as&lt;br /&gt;
// content in the above function&lt;br /&gt;
@Composable&lt;br /&gt;
fun MyContent(curURL: String, updateURL: (String) -&amp;gt; Unit){&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    // Adding a WebView inside AndroidView&lt;br /&gt;
    // with layout as full screen&lt;br /&gt;
    AndroidView(factory = {&lt;br /&gt;
        WebView(it).apply {&lt;br /&gt;
//            layoutParams = ViewGroup.LayoutParams(&lt;br /&gt;
//                ViewGroup.LayoutParams.MATCH_PARENT,&lt;br /&gt;
//                ViewGroup.LayoutParams.MATCH_PARENT&lt;br /&gt;
//            )&lt;br /&gt;
            webViewClient = WebViewClient()&lt;br /&gt;
            loadUrl(curURL)&lt;br /&gt;
        }&lt;br /&gt;
    }, update = {&lt;br /&gt;
        it.loadUrl(curURL)&lt;br /&gt;
    })&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// For displaying preview in&lt;br /&gt;
// the Android Studio IDE emulator&lt;br /&gt;
@Preview(showBackground = true)&lt;br /&gt;
@Composable&lt;br /&gt;
fun DefaultPreview() {&lt;br /&gt;
    MainContent()&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>