Browse Source

[android] add refresh on swipe in webconsole

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/1622/head
R4SAS 4 years ago
parent
commit
2bc0850b0f
  1. 4
      android/AndroidManifest.xml
  2. 1
      android/build.gradle
  3. 16
      android/res/layout/activity_web_console.xml
  4. 32
      android/src/org/purplei2p/i2pd/WebConsoleActivity.java

4
android/AndroidManifest.xml

@ -18,6 +18,10 @@ @@ -18,6 +18,10 @@
android:requestLegacyExternalStorage="true"
android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
android:usesCleartextTraffic="true">
<meta-data
android:name="android.webkit.WebView.MetricsOptOut"
android:value="true"/>
<activity android:name=".WebConsoleActivity"></activity>
<receiver android:name=".NetworkStateChangeReceiver">

1
android/build.gradle

@ -21,6 +21,7 @@ repositories { @@ -21,6 +21,7 @@ repositories {
dependencies {
implementation 'androidx.core:core:1.0.2'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
}
android {

16
android/res/layout/activity_web_console.xml

@ -1,14 +1,22 @@ @@ -1,14 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/layout_prompt"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".WebConsoleActivity">
<WebView
android:id="@+id/webview1"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
android:layout_height="fill_parent"
android:id="@+id/swipe">
<WebView
android:id="@+id/webview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>

32
android/src/org/purplei2p/i2pd/WebConsoleActivity.java

@ -2,14 +2,18 @@ package org.purplei2p.i2pd; @@ -2,14 +2,18 @@ package org.purplei2p.i2pd;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import java.util.Objects;
public class WebConsoleActivity extends Activity {
private WebView webView;
private SwipeRefreshLayout swipeRefreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -18,19 +22,43 @@ public class WebConsoleActivity extends Activity { @@ -18,19 +22,43 @@ public class WebConsoleActivity extends Activity {
Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true);
final WebView webView = findViewById(R.id.webview1);
webView = (WebView) findViewById(R.id.webview1);
webView.setWebViewClient(new WebViewClient());
final WebSettings webSettings = webView.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setJavaScriptEnabled(false);
webView.loadUrl("http://127.0.0.1:7070"); // TODO: instead 7070 I2Pd....HttpPort
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
swipeRefreshLayout.setRefreshing(true);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
webView.reload();
}
}, 1000);
}
});
}
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id==android.R.id.home) {
if (id == android.R.id.home) {
finish();
return true;
}

Loading…
Cancel
Save