added webview support

This commit is contained in:
tobiasKaminsky 2017-04-04 16:30:34 +02:00
parent 5b6ecabae8
commit dfbfd051f4
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
4 changed files with 169 additions and 0 deletions

View file

@ -80,6 +80,9 @@
<activity android:name=".ui.activity.ActivitiesListActivity"/>
<activity android:name=".ui.activity.FolderSyncActivity" />
<activity android:name=".ui.activity.UploadFilesActivity" />
<activity android:name=".ui.activity.ExternalSiteWebView"
android:configChanges="orientation|screenSize|keyboardHidden"
/>
<activity android:name=".ui.activity.ReceiveExternalFilesActivity"
android:taskAffinity=""

View file

@ -0,0 +1,115 @@
/**
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2017 Tobias Kaminsky
* Copyright (C) 2017 Nextcloud GmbH.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* <p>
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android.ui.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.owncloud.android.R;
import com.owncloud.android.lib.common.utils.Log_OC;
/**
* This activity shows an URL as a web view
*/
public class ExternalSiteWebView extends FileActivity {
private static final String TAG = ExternalSiteWebView.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
Log_OC.v(TAG, "onCreate() start");
// TODO get name, url, boolean showSidebar
// show progress
getWindow().requestFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.externalsite_webview);
WebView webview = (WebView) findViewById(R.id.webView);
// setup toolbar
setupToolbar();
// setup drawer
setupDrawer(R.id.nav_external);
getSupportActionBar().setTitle("About us");
// enable zoom
webview.getSettings().setBuiltInZoomControls(true);
// enable javascript
webview.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setProgress(progress * 1000);
}
});
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, getString(R.string.webview_error) + ": " + description, Toast.LENGTH_SHORT).show();
}
});
webview.loadUrl("http://nextcloud.com");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean retval;
switch (item.getItemId()) {
case android.R.id.home: {
if (isDrawerOpen()) {
closeDrawer();
} else {
openDrawer();
}
}
default:
retval = super.onOptionsItemSelected(item);
}
return retval;
}
@Override
public void showFiles(boolean onDeviceOnly) {
super.showFiles(onDeviceOnly);
Intent fileDisplayActivity = new Intent(getApplicationContext(),
FileDisplayActivity.class);
fileDisplayActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(fileDisplayActivity);
}
}

View file

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Nextcloud Android client application
Copyright (C) 2016 Tobias Kaminsky
Copyright (C) 2016 Nextcloud.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
License as published by the Free Software Foundation; either
version 3 of the License, or any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU AFFERO GENERAL PUBLIC LICENSE for more details.
You should have received a copy of the GNU Affero General Public
License along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:fitsSystemWindows="true">
<!-- The main content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/toolbar_standard"/>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<include
layout="@layout/drawer"
android:layout_width="@dimen/drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>

View file

@ -619,6 +619,7 @@
<!-- Activities -->
<string name="activities_no_results_headline">No activity yet</string>
<string name="activities_no_results_message">This stream will show events like\nadditions, changes &amp; shares</string>
<string name="webview_error">Error occurred</string>
</resources>