ExternalSiteWebView.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * Nextcloud Android client application
  3. *
  4. * @author Tobias Kaminsky
  5. * Copyright (C) 2017 Tobias Kaminsky
  6. * Copyright (C) 2017 Nextcloud GmbH.
  7. * <p>
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * at your option) any later version.
  12. * <p>
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. * <p>
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. package com.owncloud.android.ui.activity;
  22. import android.app.Activity;
  23. import android.content.Intent;
  24. import android.os.Bundle;
  25. import android.view.MenuItem;
  26. import android.view.Window;
  27. import android.webkit.WebChromeClient;
  28. import android.webkit.WebSettings;
  29. import android.webkit.WebView;
  30. import android.webkit.WebViewClient;
  31. import android.widget.Toast;
  32. import com.owncloud.android.MainApp;
  33. import com.owncloud.android.R;
  34. import com.owncloud.android.lib.common.utils.Log_OC;
  35. /**
  36. * This activity shows an URL as a web view
  37. */
  38. public class ExternalSiteWebView extends FileActivity {
  39. private static final String TAG = ExternalSiteWebView.class.getSimpleName();
  40. @Override
  41. protected void onCreate(Bundle savedInstanceState) {
  42. Log_OC.v(TAG, "onCreate() start");
  43. // TODO get name, url, boolean showSidebar
  44. // show progress
  45. getWindow().requestFeature(Window.FEATURE_PROGRESS);
  46. super.onCreate(savedInstanceState);
  47. setContentView(R.layout.externalsite_webview);
  48. WebView webview = (WebView) findViewById(R.id.webView);
  49. WebSettings webSettings = webview.getSettings();
  50. webview.setFocusable(true);
  51. webview.setFocusableInTouchMode(true);
  52. webview.setClickable(true);
  53. // setup toolbar
  54. setupToolbar();
  55. // setup drawer
  56. setupDrawer(R.id.nav_external);
  57. getSupportActionBar().setTitle("About us");
  58. // enable zoom
  59. webSettings.setSupportZoom(true);
  60. webSettings.setBuiltInZoomControls(true);
  61. webSettings.setDisplayZoomControls(false);
  62. // next two settings grant that non-responsive webs are zoomed out when loaded
  63. webSettings.setUseWideViewPort(true);
  64. webSettings.setLoadWithOverviewMode(true);
  65. webSettings.setUserAgentString(MainApp.getUserAgent());
  66. // no private data storing
  67. webSettings.setSavePassword(false);
  68. webSettings.setSaveFormData(false);
  69. // disable local file access
  70. webSettings.setAllowFileAccess(false);
  71. // enable javascript
  72. webview.getSettings().setJavaScriptEnabled(true);
  73. final Activity activity = this;
  74. webview.setWebChromeClient(new WebChromeClient() {
  75. public void onProgressChanged(WebView view, int progress) {
  76. activity.setProgress(progress * 1000);
  77. }
  78. });
  79. webview.setWebViewClient(new WebViewClient() {
  80. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
  81. Toast.makeText(activity, getString(R.string.webview_error) + ": " + description, Toast.LENGTH_SHORT).show();
  82. }
  83. });
  84. webview.loadUrl("http://nextcloud.com");
  85. }
  86. @Override
  87. public boolean onOptionsItemSelected(MenuItem item) {
  88. boolean retval;
  89. switch (item.getItemId()) {
  90. case android.R.id.home: {
  91. if (isDrawerOpen()) {
  92. closeDrawer();
  93. } else {
  94. openDrawer();
  95. }
  96. }
  97. default:
  98. retval = super.onOptionsItemSelected(item);
  99. }
  100. return retval;
  101. }
  102. @Override
  103. public void showFiles(boolean onDeviceOnly) {
  104. super.showFiles(onDeviceOnly);
  105. Intent fileDisplayActivity = new Intent(getApplicationContext(),
  106. FileDisplayActivity.class);
  107. fileDisplayActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  108. startActivity(fileDisplayActivity);
  109. }
  110. }