Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Commit

Permalink
改进用户体验
Browse files Browse the repository at this point in the history
  • Loading branch information
grandiloquent committed Oct 21, 2021
1 parent aaafad7 commit 25b6a7e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Notes/C++.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@

- https://github.com/OpenAtomFoundation/TencentOS-tiny/blob/master/components/connectivity/qcloud-iot-hub-sdk/3rdparty/platform/os/linux/HAL_TCP_linux.c
- https://github.com/OpenAtomFoundation/TencentOS-tiny/blob/master/components/connectivity/iotkit-embedded-3.0.1/3rdparty/wrappers/os/ubuntu/HAL_UDP_linux.c
- https://github.com/OpenAtomFoundation/TencentOS-tiny/blob/master/components/connectivity/qcloud-iot-hub-sdk/3rdparty/platform/os/windows/HAL_TCP_win.c

- https://github.com/espressif/arduino-esp32
25 changes: 20 additions & 5 deletions app/src/main/java/euphoria/psycho/explorer/WebActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package euphoria.psycho.explorer;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Process;
import android.util.Log;
Expand All @@ -21,8 +23,14 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.nio.charset.StandardCharsets;

import androidx.annotation.Nullable;
import euphoria.psycho.share.KeyShare;
import euphoria.psycho.share.StringShare;
import euphoria.psycho.share.WebViewShare;

import static euphoria.psycho.videos.VideosHelper.USER_AGENT;

public class WebActivity extends Activity {
private WebView mWebView;
Expand All @@ -43,15 +51,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
mWebView = findViewById(R.id.web);
mWebView.clearCache(true);
JavaInterface javaInterface = new JavaInterface();
mWebView.addJavascriptInterface(javaInterface, "JInterface");
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setAppCacheEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
Expand Down Expand Up @@ -119,6 +123,17 @@ public void onShowCustomView(View paramView, CustomViewCallback paramCustomViewC
}

private class JavaInterface {
@JavascriptInterface
public void download(String videoUri) {
if (videoUri.contains("m3u8")) {
Intent intent = new Intent(WebActivity.this, euphoria.psycho.tasks.VideoActivity.class);
intent.setData(Uri.parse(videoUri));
WebActivity.this.startActivity(intent);
} else {
WebViewShare.downloadFile(WebActivity.this, KeyShare.toHex(videoUri.toString().getBytes(StandardCharsets.UTF_8)), videoUri.toString(), USER_AGENT);
}
}

@JavascriptInterface
public void parse(String uri) {
new Thread(() -> {
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/euphoria/psycho/share/StringShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public static String join(String separator, List<String> value) {
return sb.toString();
}

public static boolean matchAny(String[] patterns, String value) {
for (String s : patterns) {
Pattern pattern = Pattern.compile(s);
if (pattern.matcher(value).find()) return true;
}
return false;
}

public static String padStart(String s, int length, char padChar) {
if (length < 0)
throw new IllegalArgumentException(String.format("Desired length %d is less than zero.", length));
Expand Down

0 comments on commit 25b6a7e

Please sign in to comment.