Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class BrowserFragment : Fragment(R.layout.fragment_browser) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
hideKeyboard()
onCommit(binding.toolbarEditText.text.toString())
binding.toolbarEditText.clearFocus()
selectedTab().webview.requestFocus()
true
} else {
false
Expand Down Expand Up @@ -163,6 +165,18 @@ class BrowserFragment : Fragment(R.layout.fragment_browser) {
}
fullscreenView = null
}

override fun onUriChanged(view: WPEView, uri: String) {
super.onUriChanged(view, uri)
binding.toolbarEditText.setText(uri)
}
}
}

selectedTab.webview.wpeViewClient = object : WPEViewClient() {
override fun onPageStarted(view: WPEView, url: String) {
super.onPageStarted(view, url)
binding.toolbarEditText.setText(url)
}
}
}
Expand Down Expand Up @@ -204,7 +218,7 @@ class BrowserFragment : Fragment(R.layout.fragment_browser) {

private fun onCommit(text: String) {
val url: String = if ((text.contains(".") || text.contains(":")) && !text.contains(" ")) {
Utils.normalizeAddress(text)
normalizeAddress(text)
} else {
SEARCH_URI_BASE + text
}
Expand All @@ -217,7 +231,7 @@ class BrowserFragment : Fragment(R.layout.fragment_browser) {
manager.hideSoftInputFromWindow(requireView().windowToken, 0)
}

private fun selectedTab() : Tab {
internal fun selectedTab() : Tab {
// For now assume we always have at least one tab
val selectedTabId = browserViewModel.browserState.value.selectedTabId
return browserViewModel.findTab(selectedTabId!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,17 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
super.onConfigurationChanged(newConfig)
Log.d(TAG, "onConfigurationChanged")
}

@Deprecated("Deprecated in superclass")
override fun onBackPressed() {
val currentFragment = navHost.childFragmentManager.fragments.firstOrNull()
if (currentFragment is BrowserFragment) {
val webView = currentFragment.selectedTab().webview
if (webView.canGoBack()) {
webView.goBack()
return
}
}
super.onBackPressed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,14 @@ fun View.requestApplyStandardInsets() {
requestApplyInsetsWhenAttached()
}

object Utils {
private fun addressHasWebScheme(address: String) : Boolean {
// If a string may be parsed as an URI that has an scheme, use it as-is.
// Otherwise fall-back to adding http://.
fun normalizeAddress(address: String): String {
val hasScheme = try {
val uri = URI(address)
return uri.scheme?.let {
it == "http"
} ?: false
}

fun normalizeAddress(address: String) : String {
return if (!addressHasWebScheme(address)) {
return "http://$address"
} else {
address
}
uri.scheme != null
} catch (_: Exception) {
false
}
return if (hasScheme) address else "http://$address"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/light_grey_30"/>
<corners android:radius="8dp"/>
<stroke android:color="@color/violet_70" android:width="2dp"/>
<corners android:radius="16dp"/>
</shape>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#000000"
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#000000"
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98 0,-0.34 -0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.09,-0.16 -0.26,-0.25 -0.44,-0.25 -0.06,0 -0.12,0.01 -0.17,0.03l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.06,-0.02 -0.12,-0.03 -0.18,-0.03 -0.17,0 -0.34,0.09 -0.43,0.25l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98 0,0.33 0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.09,0.16 0.26,0.25 0.44,0.25 0.06,0 0.12,-0.01 0.17,-0.03l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.06,0.02 0.12,0.03 0.18,0.03 0.17,0 0.34,-0.09 0.43,-0.25l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM17.45,11.27c0.04,0.31 0.05,0.52 0.05,0.73 0,0.21 -0.02,0.43 -0.05,0.73l-0.14,1.13 0.89,0.7 1.08,0.84 -0.7,1.21 -1.27,-0.51 -1.04,-0.42 -0.9,0.68c-0.43,0.32 -0.84,0.56 -1.25,0.73l-1.06,0.43 -0.16,1.13 -0.2,1.35h-1.4l-0.19,-1.35 -0.16,-1.13 -1.06,-0.43c-0.43,-0.18 -0.83,-0.41 -1.23,-0.71l-0.91,-0.7 -1.06,0.43 -1.27,0.51 -0.7,-1.21 1.08,-0.84 0.89,-0.7 -0.14,-1.13c-0.03,-0.31 -0.05,-0.54 -0.05,-0.74s0.02,-0.43 0.05,-0.73l0.14,-1.13 -0.89,-0.7 -1.08,-0.84 0.7,-1.21 1.27,0.51 1.04,0.42 0.9,-0.68c0.43,-0.32 0.84,-0.56 1.25,-0.73l1.06,-0.43 0.16,-1.13 0.2,-1.35h1.39l0.19,1.35 0.16,1.13 1.06,0.43c0.43,0.18 0.83,0.41 1.23,0.71l0.91,0.7 1.06,-0.43 1.27,-0.51 0.7,1.21 -1.07,0.85 -0.89,0.7 0.14,1.13zM12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM12,14c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:tint="?attr/colorControlNormal" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19,11H7.83l4.88,-4.88c0.39,-0.39 0.39,-1.03 0,-1.42 -0.39,-0.39 -1.02,-0.39 -1.41,0l-6.59,6.59c-0.39,0.39 -0.39,1.02 0,1.41l6.59,6.59c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L7.83,13H19c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:tint="?attr/colorControlNormal" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M5,13h11.17l-4.88,4.88c-0.39,0.39 -0.39,1.03 0,1.42 0.39,0.39 1.02,0.39 1.41,0l6.59,-6.59c0.39,-0.39 0.39,-1.02 0,-1.41l-6.58,-6.6c-0.39,-0.39 -1.02,-0.39 -1.41,0 -0.39,0.39 -0.39,1.02 0,1.41L16.17,11H5c-0.55,0 -1,0.45 -1,1s0.45,1 1,1z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#000000"
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M17.65,6.35c-1.63,-1.63 -3.94,-2.57 -6.48,-2.31 -3.67,0.37 -6.69,3.35 -7.1,7.02C3.52,15.91 7.27,20 12,20c3.19,0 5.93,-1.87 7.21,-4.56 0.32,-0.67 -0.16,-1.44 -0.9,-1.44 -0.37,0 -0.72,0.2 -0.88,0.53 -1.13,2.43 -3.84,3.97 -6.8,3.31 -2.22,-0.49 -4.01,-2.3 -4.48,-4.52C5.31,9.44 8.26,6 12,6c1.66,0 3.14,0.69 4.22,1.78l-1.51,1.51c-0.63,0.63 -0.19,1.71 0.7,1.71H19c0.55,0 1,-0.45 1,-1V6.41c0,-0.89 -1.08,-1.34 -1.71,-0.71l-0.64,0.65z"/>
Expand Down
19 changes: 10 additions & 9 deletions tools/minibrowser/src/main/res/layout/fragment_browser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
android:id="@+id/tab_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/page_progress" />
android:layout_above="@id/toolbar" />

<ProgressBar
android:id="@+id/page_progress"
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_height="8dp"
android:background="@android:color/transparent"
android:layout_above="@id/toolbar"
android:progressTint="@color/violet_70"/>
Expand All @@ -27,29 +27,30 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:layout_alignParentBottom="true"
android:background="?android:statusBarColor">
android:layout_alignParentBottom="true">

<FrameLayout
android:id="@+id/toolbar_edit_text_wrapper"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:background="@drawable/address_view_background"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:clickable="true"
android:contentDescription="@string/search_hint"
android:focusable="true"
>
android:focusable="true">

<EditText
android:id="@+id/toolbar_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:importantForAutofill="no"
android:inputType="text|textUri"
android:selectAllOnFocus="true"
android:singleLine="true"
android:layout_gravity="start|center_vertical"
android:layout_marginStart="16dp"
android:hint="@string/search_hint"/>
</FrameLayout>

Expand Down
2 changes: 2 additions & 0 deletions wpeview/src/main/java/org/wpewebkit/wpe/WKWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ private void onEstimatedLoadProgress(double progress) {
@Keep
private void onUriChanged(@NonNull String uri) {
this.uri = uri;
if (wpeChromeClient != null)
wpeChromeClient.onUriChanged(wpeView, uri);
}

@Keep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ default void onProgressChanged(@NonNull WPEView view, int progress) {}
*/
default void onReceivedTitle(@NonNull WPEView view, @NonNull String title) {}

/**
* Notify the host application that the URI has changed.
* @param view the WPEView that initiated the callback.
* @param uri the new URI.
*/
default void onUriChanged(@NonNull WPEView view, @NonNull String uri) {}

/**
* A callback interface used by the host application to notify
* the current page that its custom view has been dismissed.
Expand Down