From a8b3e4d2a0c6857255f4dc8fa85c5b060c3b00d9 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Sat, 19 Jan 2019 14:53:36 +0000 Subject: [PATCH] Add WebView for Android TVs (fixes #227) (#225) * WIP * AndroidManifest: Add WebViewActivity * Open WebViewActivity from prefs, move to "Debug" menu * Add WebViewActivity below SettingsActivity * Add strings for ssl security notice * Handle web page links and ssl warnings correctly * Mention issue tracker URL in pref summary * Don't use ACTION_VIEW for deeplinks on syncthing's WebUI * Rename string: report_issue_summary to open_issue_tracker_summary * Imported translations * Add "open in browser" drawable * Add webview_options menu * Add strings: web page loading, open in browser * Add option to open webpage in browser on non-TV devices (fixes #227) * Imported de translation --- app/src/main/AndroidManifest.xml | 13 ++ .../activities/SettingsActivity.java | 2 + .../activities/WebGuiActivity.java | 5 +- .../activities/WebViewActivity.java | 172 ++++++++++++++++++ .../drawable-hdpi/ic_open_in_new_white_24.png | Bin 0 -> 233 bytes .../drawable-mdpi/ic_open_in_new_white_24.png | Bin 0 -> 181 bytes .../ic_open_in_new_white_24.png | Bin 0 -> 269 bytes .../ic_open_in_new_white_24.png | Bin 0 -> 312 bytes .../ic_open_in_new_white_24.png | Bin 0 -> 447 bytes app/src/main/res/menu/webview_options.xml | 12 ++ app/src/main/res/values-ca-rES/strings.xml | 4 +- app/src/main/res/values-de/strings.xml | 17 +- app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-nl/strings.xml | 1 + app/src/main/res/values-ro/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 11 ++ app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 17 +- app/src/main/res/xml/app_settings.xml | 16 +- 24 files changed, 264 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/com/nutomic/syncthingandroid/activities/WebViewActivity.java create mode 100644 app/src/main/res/drawable-hdpi/ic_open_in_new_white_24.png create mode 100644 app/src/main/res/drawable-mdpi/ic_open_in_new_white_24.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_open_in_new_white_24.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_open_in_new_white_24.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_open_in_new_white_24.png create mode 100644 app/src/main/res/menu/webview_options.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7fdced8e..91e7e942 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -74,6 +74,19 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activities.MainActivity" /> + + + + + + + { + try { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: + handler.proceed(); + sslNoticeUserDecision = true; + break; + case DialogInterface.BUTTON_NEGATIVE: + handler.cancel(); + if (isRunningOnTV) { + // Finish as there is no other way to display the website. + finish(); + } + break; + } + } catch (Exception e) { + Log.e(TAG, "onReceivedSslError:OnClickListener", e); + } + }; + mSecurityNoticeDialog = new AlertDialog.Builder(WebViewActivity.this) + .setTitle(R.string.security_notice) + .setMessage(getString(R.string.ssl_cert_invalid_text, webPageUrl)) + .setPositiveButton(R.string.cont, listener) + .setNegativeButton(R.string.cancel_title, listener) + .show(); + } + + @Override + public void onPageFinished(WebView view, String url) { + mWebView.setVisibility(View.VISIBLE); + mLoadingView.setVisibility(View.GONE); + } + }; + + /** + * Initialize WebView. + */ + @Override + @SuppressLint("SetJavaScriptEnabled") + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + isRunningOnTV = Util.isRunningOnTV(WebViewActivity.this); + setContentView(R.layout.activity_web_gui); + webPageUrl = getString(R.string.issue_tracker_url); + mLoadingView = findViewById(R.id.loading); + ((TextView) findViewById(R.id.loading_text)).setText(getString(R.string.web_page_loading, webPageUrl)); + mWebView = findViewById(R.id.webview); + mWebView.getSettings().setJavaScriptEnabled(true); + mWebView.getSettings().setDomStorageEnabled(true); + mWebView.setWebViewClient(mWebViewClient); + mWebView.clearCache(true); + if (mWebView.getUrl() == null) { + mWebView.stopLoading(); + mWebView.loadUrl(webPageUrl); + } + } + + /** + * Saves current tab index and fragment states. + */ + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + Util.dismissDialogSafe(mSecurityNoticeDialog, this); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.webview_options, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + menu.findItem(R.id.openBrowser).setVisible(!isRunningOnTV); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.openBrowser: + // This can only be triggered on a non-TV device. + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webPageUrl))); + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + public void onBackPressed() { + if (mWebView.canGoBack()) { + mWebView.goBack(); + } else { + finish(); + super.onBackPressed(); + } + } + + @Override + public void onPause() { + mWebView.onPause(); + mWebView.pauseTimers(); + super.onPause(); + } + + @Override + public void onResume() { + super.onResume(); + mWebView.resumeTimers(); + mWebView.onResume(); + } + + @Override + protected void onDestroy() { + mWebView.destroy(); + mWebView = null; + super.onDestroy(); + } +} diff --git a/app/src/main/res/drawable-hdpi/ic_open_in_new_white_24.png b/app/src/main/res/drawable-hdpi/ic_open_in_new_white_24.png new file mode 100644 index 0000000000000000000000000000000000000000..1418728552e33c634c29f0512ee8a2513eba52a1 GIT binary patch literal 233 zcmVHM-Ca&XfY(rxs)7ICWoBKA!l;P z8B3sm380v9$eH+#oQWZ4V#t{}(1w>Y`O&sKoyjkI?L-WD{|Hs^$KQt$fZ9U?a~et? jSJE!om+e#8m8GZ;>eT&<&nd{#00000NkvXXu0mjf0bpO4 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_open_in_new_white_24.png b/app/src/main/res/drawable-mdpi/ic_open_in_new_white_24.png new file mode 100644 index 0000000000000000000000000000000000000000..056acf4770e37777ec02783438ad0dce613aeafb GIT binary patch literal 181 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+i8c!F;kP61LlNs3>0t8sC9UWWh zSFF4CmTQsFuA@stZET`j*fv-nJ`}dUb)KN&vL-h6JzOaY7mRiuczybCgWi{^kC?Bf zJN577cbTtm%jxporI^w6tIC26UGMyaYPoFrGxGLM-O9-CLJC-JQ f!r)SP{ZkglWi|_#6P+@E?qKkA^>bP0l+XkKw>m*Z literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_open_in_new_white_24.png b/app/src/main/res/drawable-xhdpi/ic_open_in_new_white_24.png new file mode 100644 index 0000000000000000000000000000000000000000..39a335039cb8fc1b983955adaf803155d348b58e GIT binary patch literal 269 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}b0DE1oWnAr*{oFEX+*1&Xvj^xoPM zq|M24pn*|$gPFjpX;&Or9WsA3AADTld|C2@HTMtucfCg6Pel|x@;kps+V=GG=O!oS z9N;^~nwQLc_tEK%OSdvl`p!J5K8o?={uOT+N@w*OFkjhod5`!61meE%$NJ=HHik*- zmCrCteb&n$s(*HNL(RP}DQBY@L8zMH?DouiEF1hj-R7`2c&t@$mZW8SZs!c6>;9Atw{rTA7+E?`X2&v4P*EH$eX}c)I$z JtaD0e0sz-|a##QW literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_open_in_new_white_24.png b/app/src/main/res/drawable-xxhdpi/ic_open_in_new_white_24.png new file mode 100644 index 0000000000000000000000000000000000000000..04f285cfab2b182639f8f920d973b38bdecf0f45 GIT binary patch literal 312 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY0wn)GsXhauJY5_^Dj45h*~rP{DB$++>VeH{ zTX%DdavN;b)DF;f=;70O)Kj0lnZ2l=``J@w`P1jNtXj2-YpPy5&%>wbQtp_;rKS&vw*ovCoZ(6J%8 ziQza4V;?7zj4+FZ8b?8hz=IzO2Ocs`IM1jspV`5Vy`hGWm9dXsNha|vqdPN_${4W9 zkB;gGHpX)lys>Ao_%@BPucrN6!{f$(D;-#wL{~T@uW@7Bb^O&qhuSq&Y*Ej|7H3cE xotisu=B{+J-syVBd1kIE|MpT~3D6(Em|FJEHo6&D^cxry44$rjF6*2Ung9YgcfSAt literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_open_in_new_white_24.png b/app/src/main/res/drawable-xxxhdpi/ic_open_in_new_white_24.png new file mode 100644 index 0000000000000000000000000000000000000000..08bfc707666393ffd5fc7288e62b27936a3952c7 GIT binary patch literal 447 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%&M7z}V*L;uuoF`1UHJ+u=l+_K)IQ zQo=JF!#UW>R#-V(In7lpZM<}Yb=&MS$E0%n#T0(r+P~)c`S;Zg*FPV8eVygRPmhrqNer7?XE~whSWoekO-}1?7M#cI&v*agyzS}ToJ=>ESQ?T0m zoG&Km+obpu?UOjrl6&qt6VSK`pRXb-iRa|_`PzA(l)$I_sCi5u<^T;azE`~OH~*Z^ z^FAMK$Umg>H|9U?%A0G>zo)+Q)?RKPIVc84~ czPH>{mrOXia+2s`V8k$Zy85}Sb4q9e0192sssI20 literal 0 HcmV?d00001 diff --git a/app/src/main/res/menu/webview_options.xml b/app/src/main/res/menu/webview_options.xml new file mode 100644 index 00000000..f2401556 --- /dev/null +++ b/app/src/main/res/menu/webview_options.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/app/src/main/res/values-ca-rES/strings.xml b/app/src/main/res/values-ca-rES/strings.xml index 282f16e5..6ef06242 100644 --- a/app/src/main/res/values-ca-rES/strings.xml +++ b/app/src/main/res/values-ca-rES/strings.xml @@ -310,6 +310,7 @@ Esperant interfície gràfica + @@ -515,9 +516,6 @@ Informeu d\'un problema - - Obre el rastrejador de problemes del Syncthing-Fork - Versió del Syncthing diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index bf06bf79..3a1d355f 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -343,6 +343,21 @@ Bitte melden Sie auftretende Probleme via GitHub. Warte auf Weboberfläche + + + + + Sicherheitshinweis + + + Die Webseite \"%1$s\" scheint ein ungültiges SSL-Zertifikat zur Verschlüsselung aufzuweisen. Fortfahren? + + + Lade Webseite:\n%1$s... + + + In Browser öffnen + @@ -562,7 +577,7 @@ Bitte melden Sie auftretende Probleme via GitHub. Fehler melden - Syncthing-Fork Fehlersammlung öffnen + Öffne die Syncthing-Fork Fehlersammlung bei %1$s diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 148ecec9..9e9a4a1b 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -199,6 +199,7 @@ Esperando a la interfaz gráfica + diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 63797e20..dc13a9e1 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -228,6 +228,7 @@ En attente de l\'interface WEB + diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 93ae7b00..c0d8ae96 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -225,6 +225,7 @@ Caricamento Interfaccia Web + diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index e3f34f97..3fd335ec 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -209,6 +209,7 @@ GUI を待機中 + diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 38e6937c..3a80b026 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -247,6 +247,7 @@ Wachten op interface + diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index a563a810..241b91e8 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -243,6 +243,7 @@ Se așteaptă interfața + diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 799ee914..3b4d7cf9 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -285,6 +285,7 @@ Ожидание GUI + diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 6eb71e97..19b66c76 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -297,6 +297,7 @@ Väntar på gränssnitt + diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 15bb0070..2308b16f 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -285,6 +285,7 @@ 正在等待管理页面 + @@ -301,13 +302,21 @@ 运行条件 下方选项将控制 Syncthing 何时启用 + 让它在Wi-Fi上运行 + 设备连接到Wi-Fi网络时运行。 + + 让它在计量Wi-Fi上运行 设备在付费 Wi-Fi 网络环境下启用 Syncthing 警告:可能会产生大量费用 + 在指定的Wi-Fi网络上运行 选择 Wi-Fi 网络 已选择的 Wi-Fi 网络 : %1$s + 未指定Wi-Fi网络。 单击以指定网络。 + 请打开无线网络连接并选择网络 + 需要许可 遵循 Android 电池省电模式设置 省电模式启动时禁用 Syncthing @@ -391,6 +400,8 @@ 强制所有的流量经由 Tor 代理,需要 Orbot,以及禁用其它代理选项。 + SOCKS5 代理 + HTTP(S) 代理 使用传统哈希 强制 Syncthing 使用传统哈希包以提高兼容性 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 4ed20b5d..c0185fbd 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -207,6 +207,7 @@ 正在等待 GUI + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e4cba9a2..50cef47d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -343,6 +343,21 @@ Please report any problems you encounter via Github. Waiting for GUI + + + + + Security Notice + + + Website at %1$s appears to have an invalid certificate for SSL encryption. Proceed? + + + Loading webpage:\n%1$s ... + + + Open in browser + @@ -570,7 +585,7 @@ Please report any problems you encounter via Github. Report Issue - Open the Syncthing-Fork issue tracker + Open the Syncthing-Fork issue tracker at %1$s https://github.com/Catfriend1/syncthing-android/issues diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index 2ed48769..e4cbe589 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -213,6 +213,14 @@ + + + + @@ -285,14 +293,6 @@ - - - -