From cdb5b988cb71a1453625edadc57b735466303dc5 Mon Sep 17 00:00:00 2001 From: Matthew Hepburn Date: Tue, 28 Aug 2018 09:08:18 -0400 Subject: [PATCH 1/3] initial working version of opening intent from webview --- app/gradlew | 0 .../android/chatrooms/ui/ChatRoomsFragment.kt | 2 +- .../webview/weblink/ui/WebViewActivity.kt | 36 ++++++++++++------- 3 files changed, 25 insertions(+), 13 deletions(-) mode change 100644 => 100755 app/gradlew diff --git a/app/gradlew b/app/gradlew old mode 100644 new mode 100755 diff --git a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt index 3a06fd4fb3..1bd182bc5c 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt @@ -400,7 +400,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView, WebLinksView { web_search.setOnClickListener { - CustomTab.openCustomTab(context!!, link, WebViewFallback(), true) +// CustomTab.openCustomTab(context!!, link, WebViewFallback(), true) startActivity(this.activity?.webViewIntent(link, if (!title.isEmpty()) title else resources.getString(R.string.url_preview_title))) } diff --git a/app/src/main/java/chat/rocket/android/webview/weblink/ui/WebViewActivity.kt b/app/src/main/java/chat/rocket/android/webview/weblink/ui/WebViewActivity.kt index 255c8d27f1..446b174319 100644 --- a/app/src/main/java/chat/rocket/android/webview/weblink/ui/WebViewActivity.kt +++ b/app/src/main/java/chat/rocket/android/webview/weblink/ui/WebViewActivity.kt @@ -3,7 +3,9 @@ package chat.rocket.android.webview.weblink.ui import android.annotation.SuppressLint import android.content.Context import android.content.Intent +import android.net.Uri import android.os.Bundle +import android.util.Log import android.webkit.WebResourceRequest import android.webkit.WebView import android.webkit.WebViewClient @@ -116,22 +118,32 @@ class WebViewActivity : AppCompatActivity() { private fun setupWebView() { web_view.settings.javaScriptEnabled = true web_view.webViewClient = object : WebViewClient() { + override fun onPageFinished(view: WebView?, url: String?) { - super.onPageFinished(view, url) - view_loading.hide() +// super.onPageFinished(view, url) +// view_loading.hide() } - override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean { - if (request?.url.toString().startsWith("https://www.google.com/search", ignoreCase = true)) - return false - if (request?.url.toString().startsWith("https://www.aa.com", ignoreCase = true)) { - ToastHelper.showCustomToast(view?.context, - "Can I help you get access to this content?") - return true - } - return isNewUrl(request?.url.toString()) + override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?) : Boolean { + Log.e("Viasat-Veranda", "shouldOverride") + + try { +val intent = Intent(Intent.ACTION_VIEW, + Uri.parse("viasat://newtab")) + // some code + + // handler + + intent.setPackage("com.viasat.browser") + startActivity(intent) } - } +catch (e: Exception) { +Log.e("Viasat-Veranda", e.message) +} + return true + } + } + web_view.loadUrl(webPageUrl) } From ff82ea1746cb03c0868cc2d9e751674ca3b1706c Mon Sep 17 00:00:00 2001 From: Matthew Hepburn Date: Thu, 30 Aug 2018 09:47:12 -0400 Subject: [PATCH 2/3] change web search to use VB custom tab. Also includes commented out code to make web search use a VB intent --- .../android/chatrooms/ui/ChatRoomsFragment.kt | 19 +++++++++++++++---- .../rocket/android/customtab/CustomTab.kt | 6 +++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt index 1bd182bc5c..0ffd3a4ed6 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt @@ -1,7 +1,9 @@ package chat.rocket.android.chatrooms.ui import android.app.AlertDialog +import android.content.Intent import android.content.SharedPreferences +import android.net.Uri import android.os.Bundle import android.os.Handler import android.util.Log @@ -391,7 +393,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView, WebLinksView { val title = SharedPreferenceHelper.getString("web_search_title", "Internet Search") val description = SharedPreferenceHelper.getString("web_search_desc", "Faster web with the Viasat Browser") val imageUrl = SharedPreferenceHelper.getString("web_search_image", "") - val link = SharedPreferenceHelper.getString("web_search_link", "https://www.google.com") + val link = SharedPreferenceHelper.getString("web_search_link", "viasat-native://newtab") updateUI(title, text_title, description, text_description, @@ -400,8 +402,17 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView, WebLinksView { web_search.setOnClickListener { -// CustomTab.openCustomTab(context!!, link, WebViewFallback(), true) - startActivity(this.activity?.webViewIntent(link, if (!title.isEmpty()) title else resources.getString(R.string.url_preview_title))) + // start Viasat Browser and have it open new tab page in a custom tab + CustomTab.openCustomTab(context!!, link, WebViewFallback(), true) + + // alternative: start Viasat Browser as a new intent - causes Viasat Browser + // to be the foreground app open to new tab page + + //val intent = Intent(Intent.ACTION_VIEW, + //Uri.parse("viasat-native://newtab")) + //intent.setPackage("com.viasat.browser") + + //startActivity(intent) } val linkPreviewCallback = object : LinkPreviewCallback { @@ -475,4 +486,4 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView, WebLinksView { //presenter.chatRoomsByName(name ?: "") return true } -} \ No newline at end of file +} diff --git a/app/src/main/java/chat/rocket/android/customtab/CustomTab.kt b/app/src/main/java/chat/rocket/android/customtab/CustomTab.kt index 36e31f9cae..1c12aa1b1d 100644 --- a/app/src/main/java/chat/rocket/android/customtab/CustomTab.kt +++ b/app/src/main/java/chat/rocket/android/customtab/CustomTab.kt @@ -12,8 +12,8 @@ import chat.rocket.android.R object CustomTab { fun openCustomTab(context: Context, url: String, fallback: CustomTabFallback?, setBackButton: Boolean = false) { - val uri = Uri.parse(CustomTabsHelper.convertSchemeToLower(url)) - + val uri = Uri.parse(url) + val customTabIntentBuilder = CustomTabsIntent.Builder() customTabIntentBuilder.setToolbarColor(ResourcesCompat.getColor(context.resources, R.color.colorPrimary, context.theme)) @@ -55,4 +55,4 @@ object CustomTab { interface CustomTabFallback { fun openUri(context: Context, uri: Uri) } -} \ No newline at end of file +} From 4c7bfbdfe9cd1c85f52ec64e775b57cd4606d022 Mon Sep 17 00:00:00 2001 From: matthep34 Date: Thu, 30 Aug 2018 09:58:29 -0400 Subject: [PATCH 3/3] revert unnecessary changes --- .../webview/weblink/ui/WebViewActivity.kt | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/chat/rocket/android/webview/weblink/ui/WebViewActivity.kt b/app/src/main/java/chat/rocket/android/webview/weblink/ui/WebViewActivity.kt index 446b174319..255c8d27f1 100644 --- a/app/src/main/java/chat/rocket/android/webview/weblink/ui/WebViewActivity.kt +++ b/app/src/main/java/chat/rocket/android/webview/weblink/ui/WebViewActivity.kt @@ -3,9 +3,7 @@ package chat.rocket.android.webview.weblink.ui import android.annotation.SuppressLint import android.content.Context import android.content.Intent -import android.net.Uri import android.os.Bundle -import android.util.Log import android.webkit.WebResourceRequest import android.webkit.WebView import android.webkit.WebViewClient @@ -118,32 +116,22 @@ class WebViewActivity : AppCompatActivity() { private fun setupWebView() { web_view.settings.javaScriptEnabled = true web_view.webViewClient = object : WebViewClient() { - override fun onPageFinished(view: WebView?, url: String?) { -// super.onPageFinished(view, url) -// view_loading.hide() + super.onPageFinished(view, url) + view_loading.hide() } - override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?) : Boolean { - Log.e("Viasat-Veranda", "shouldOverride") - - try { -val intent = Intent(Intent.ACTION_VIEW, - Uri.parse("viasat://newtab")) - // some code - - // handler - - intent.setPackage("com.viasat.browser") - startActivity(intent) + override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean { + if (request?.url.toString().startsWith("https://www.google.com/search", ignoreCase = true)) + return false + if (request?.url.toString().startsWith("https://www.aa.com", ignoreCase = true)) { + ToastHelper.showCustomToast(view?.context, + "Can I help you get access to this content?") + return true + } + return isNewUrl(request?.url.toString()) } -catch (e: Exception) { -Log.e("Viasat-Veranda", e.message) -} - return true - } - } - + } web_view.loadUrl(webPageUrl) }