Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #12 from jonathan-reisdorf/file-uploads
Browse files Browse the repository at this point in the history
File uploads
  • Loading branch information
jonathan-reisdorf authored Oct 5, 2018
2 parents cbe8a4d + 3946b7e commit 17c550b
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 55 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "org.crossnode.bb10beol"
minSdkVersion 18
targetSdkVersion 18
versionCode 15
versionName "1.8.0"
versionCode 16
versionName "1.8.1"
}
buildTypes {
debug {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
16 changes: 9 additions & 7 deletions app/src/main/java/org/crossnode/bb10beol/Browser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.crossnode.bb10beol;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.view.ViewGroup.LayoutParams;
Expand All @@ -12,16 +11,18 @@


public class Browser {
private Activity activity;
public boolean isInitialized = false;

private MainActivity activity;
private LinearLayout mainLayout;

private BrowserTabManager browserTabManager;
private BrowserTabManager tabManager;
private XWalkView navigationWebView;
private BrowserResourceClient navigationResourceClient;

private String navigationFileUrl = "file:///android_asset/navigation.html";

Browser(Activity activity, LinearLayout mainLayout) {
Browser(MainActivity activity, LinearLayout mainLayout) {
this.activity = activity;
this.mainLayout = mainLayout;
}
Expand All @@ -33,16 +34,16 @@ public void initialize(String url) {
mainLayout.setBackgroundColor(Color.BLACK);

navigationWebView = new XWalkView(activity);
browserTabManager = new BrowserTabManager(activity, mainLayout, navigationWebView);
XWalkView xWalkWebView = browserTabManager.initialize(url);
tabManager = new BrowserTabManager(activity, mainLayout, navigationWebView);
XWalkView xWalkWebView = tabManager.initialize(url);

XWalkCookieManager mCookieManager = new XWalkCookieManager();
mCookieManager.setAcceptCookie(true);
mCookieManager.setAcceptFileSchemeCookies(true);

navigationResourceClient = new BrowserResourceClient(navigationWebView, navigationWebView);
navigationWebView.setResourceClient(navigationResourceClient);
navigationWebView.addJavascriptInterface(new NavigationJsInterface(activity, browserTabManager), "navigation");
navigationWebView.addJavascriptInterface(new NavigationJsInterface(activity, tabManager), "navigation");
navigationWebView.addJavascriptInterface(new NavigationConvenienceJsInterface(activity), "navigationConvenience");
navigationWebView.loadUrl(navigationFileUrl);

Expand All @@ -52,6 +53,7 @@ public void initialize(String url) {

mainLayout.addView(xWalkWebView);
mainLayout.addView(navigationWebView);
isInitialized = true;
}

public void onResume() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.xwalk.core.XWalkNavigationItem;
import org.xwalk.core.XWalkView;

import android.app.Activity;
import android.graphics.Color;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
Expand All @@ -23,12 +22,12 @@ public class BrowserTabManager {
public BrowserResourceClient currentResourceClient = null;
public BrowserResourceClient previousResourceClient = null;

private Activity activity;
private MainActivity activity;
private LinearLayout mainLayout;
private XWalkView navigationWebView;


BrowserTabManager(Activity activity, LinearLayout mainLayout, XWalkView navigationWebView) {
BrowserTabManager(MainActivity activity, LinearLayout mainLayout, XWalkView navigationWebView) {
this.activity = activity;
this.mainLayout = mainLayout;
this.navigationWebView = navigationWebView;
Expand All @@ -48,9 +47,11 @@ public XWalkView addTab(String url, boolean systemTab) {

public XWalkView addTab(String url, String customUserAgentString, boolean systemTab, boolean openTab) {
XWalkView xWalkWebView = new XWalkView(activity);

BrowserResourceClient browserResourceClient = new BrowserResourceClient(xWalkWebView, navigationWebView);

xWalkWebView.setResourceClient(browserResourceClient);
xWalkWebView.setUIClient(new BrowserUIClient(activity, xWalkWebView));
xWalkWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, (float) 1));

if (customUserAgentString != null && !customUserAgentString.equals("")) {
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/org/crossnode/bb10beol/BrowserUIClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.crossnode.bb10beol;

import android.net.Uri;
import android.webkit.ValueCallback;

import org.xwalk.core.XWalkFileChooser;
import org.xwalk.core.XWalkUIClient;
import org.xwalk.core.XWalkView;

public class BrowserUIClient extends XWalkUIClient {
private MainActivity _activity;

public BrowserUIClient(MainActivity activity, XWalkView view) {
super(view);
_activity = activity;
}

@Override
public void openFileChooser(XWalkView view, ValueCallback<Uri> uploadFile, String acceptType, String capture) {
if (_activity.fileChooser == null) {
_activity.fileChooser = new XWalkFileChooser(_activity);
}

_activity.fileChooser.showFileChooser(uploadFile, acceptType, capture);
}
}
31 changes: 23 additions & 8 deletions app/src/main/java/org/crossnode/bb10beol/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
package org.crossnode.bb10beol;

//import android.view.WindowManager;

import android.app.Activity;
import android.widget.LinearLayout;
import android.os.Bundle;
import android.content.Intent;

import org.xwalk.core.XWalkActivity;
import org.xwalk.core.XWalkFileChooser;

public class MainActivity extends Activity {
private Browser browser;
public class MainActivity extends XWalkActivity {
public Browser browser = null;
public XWalkFileChooser fileChooser = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout mainLayout = (LinearLayout) this.findViewById(R.id.mainLayout);
browser = new Browser(this, mainLayout);
browser.initialize(null);
//this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

@Override
protected void onResume() {
super.onResume();
browser.onResume();

if (browser.isInitialized) {
browser.onResume();
}
}

@Override
protected void onXWalkReady() {
browser.initialize(null);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (fileChooser != null) {
fileChooser.onActivityResult(requestCode, resultCode, data);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.crossnode.bb10beol;

import android.app.Activity;
import android.content.Context;
import android.content.ClipboardManager;
import android.content.ClipData;
Expand All @@ -10,10 +9,10 @@

public class NavigationConvenienceJsInterface {
private boolean _isEnabled = false;
private Activity _activity;
private MainActivity _activity;
private String _clipboardText = null;

NavigationConvenienceJsInterface(Activity activity) {
NavigationConvenienceJsInterface(MainActivity activity) {
_activity = activity;
}

Expand Down
46 changes: 22 additions & 24 deletions app/src/main/java/org/crossnode/bb10beol/NavigationJsInterface.java
Original file line number Diff line number Diff line change
@@ -1,93 +1,91 @@
package org.crossnode.bb10beol;

import android.app.Activity;

import org.xwalk.core.XWalkView;
import org.xwalk.core.JavascriptInterface;


class NavigationJsInterface {
private Activity activity;
private BrowserTabManager browserTabManager;
private MainActivity _activity;
private BrowserTabManager _browserTabManager;
private String tabsOverviewFileUrl = "file:///android_asset/tabs.html";
private String contextMenuFileUrl = "file:///android_asset/context.html";

NavigationJsInterface(Activity activity, BrowserTabManager browserTabManager) {
this.activity = activity;
this.browserTabManager = browserTabManager;
NavigationJsInterface(MainActivity activity, BrowserTabManager browserTabManager) {
_activity = activity;
_browserTabManager = browserTabManager;
}

@JavascriptInterface
public void openUrl(final String url) {
activity.runOnUiThread(new Runnable() {
_activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (!browserTabManager.currentResourceClient.isSystem) {
if (!_browserTabManager.currentResourceClient.isSystem) {
// TODO load on previous/non-system/new tab in that case!
browserTabManager.load(url);
_browserTabManager.load(url);
}
}
});
}

@JavascriptInterface
public void setUserAgentString(final String userAgentString) {
activity.runOnUiThread(new Runnable() {
_activity.runOnUiThread(new Runnable() {
@Override
public void run() {
browserTabManager.currentTab.setUserAgentString(userAgentString);
_browserTabManager.currentTab.setUserAgentString(userAgentString);
}
});
}

@JavascriptInterface
public void showTabsOverview() {
activity.runOnUiThread(new Runnable() {
_activity.runOnUiThread(new Runnable() {
@Override
public void run() {
XWalkView webview = browserTabManager.addTab(tabsOverviewFileUrl, true);
webview.addJavascriptInterface(new TabsJsInterface(activity, webview, browserTabManager), "tabs");
XWalkView webview = _browserTabManager.addTab(tabsOverviewFileUrl, true);
webview.addJavascriptInterface(new TabsJsInterface(_activity, webview, _browserTabManager), "tabs");
}
});
}

@JavascriptInterface
public void showContextMenu() {
activity.runOnUiThread(new Runnable() {
_activity.runOnUiThread(new Runnable() {
@Override
public void run() {
XWalkView webview = browserTabManager.addTab(contextMenuFileUrl, true);
webview.addJavascriptInterface(new PageContextInterface(activity, browserTabManager), "pageContext");
XWalkView webview = _browserTabManager.addTab(contextMenuFileUrl, true);
webview.addJavascriptInterface(new PageContextInterface(_activity, _browserTabManager), "pageContext");
}
});
}

@JavascriptInterface
public void closeSystemTab() {
activity.runOnUiThread(new Runnable() {
_activity.runOnUiThread(new Runnable() {
@Override
public void run() {
browserTabManager.closeSystemTab();
_browserTabManager.closeSystemTab();
}
});
}

@JavascriptInterface
public void goPrev() {
activity.runOnUiThread(new Runnable() {
_activity.runOnUiThread(new Runnable() {
@Override
public void run() {
browserTabManager.currentResourceClient.goPrev();
_browserTabManager.currentResourceClient.goPrev();
}
});
}

@JavascriptInterface
public void goNext() {
activity.runOnUiThread(new Runnable() {
_activity.runOnUiThread(new Runnable() {
@Override
public void run() {
browserTabManager.currentResourceClient.goNext();
_browserTabManager.currentResourceClient.goNext();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package org.crossnode.bb10beol;

import android.app.Activity;

import org.json.JSONException;
import org.json.JSONObject;

import org.xwalk.core.JavascriptInterface;


public class PageContextInterface {
private Activity _activity;
private MainActivity _activity;
private BrowserTabManager _browserTabManager;
private BrowserResourceClient _resourceClient;

private String _title;
private String _url;

PageContextInterface(Activity activity, BrowserTabManager browserTabManager) {
PageContextInterface(MainActivity activity, BrowserTabManager browserTabManager) {
_activity = activity;
_browserTabManager = browserTabManager;
_resourceClient = browserTabManager.previousResourceClient;
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/org/crossnode/bb10beol/TabsJsInterface.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package org.crossnode.bb10beol;

import android.app.Activity;

import org.json.JSONArray;

import org.xwalk.core.JavascriptInterface;
import org.xwalk.core.XWalkView;


class TabsJsInterface {
private Activity _activity;
private MainActivity _activity;
private XWalkView _webview;
private BrowserTabManager _browserTabManager;

TabsJsInterface(Activity activity, XWalkView webview, BrowserTabManager browserTabManager) {
TabsJsInterface(MainActivity activity, XWalkView webview, BrowserTabManager browserTabManager) {
this._activity = activity;
this._webview = webview;
this._browserTabManager = browserTabManager;
Expand Down

0 comments on commit 17c550b

Please sign in to comment.