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. 10
      android/res/layout/activity_web_console.xml
  4. 30
      android/src/org/purplei2p/i2pd/WebConsoleActivity.java

4
android/AndroidManifest.xml

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

1
android/build.gradle

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

10
android/res/layout/activity_web_console.xml

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

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

@ -2,14 +2,18 @@ package org.purplei2p.i2pd;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem; import android.view.MenuItem;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import java.util.Objects; import java.util.Objects;
public class WebConsoleActivity extends Activity { public class WebConsoleActivity extends Activity {
private WebView webView;
private SwipeRefreshLayout swipeRefreshLayout;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -18,13 +22,37 @@ public class WebConsoleActivity extends Activity {
Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true); Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true);
final WebView webView = findViewById(R.id.webview1); webView = (WebView) findViewById(R.id.webview1);
webView.setWebViewClient(new WebViewClient()); webView.setWebViewClient(new WebViewClient());
final WebSettings webSettings = webView.getSettings(); final WebSettings webSettings = webView.getSettings();
webSettings.setBuiltInZoomControls(true); webSettings.setBuiltInZoomControls(true);
webSettings.setJavaScriptEnabled(false); webSettings.setJavaScriptEnabled(false);
webView.loadUrl("http://127.0.0.1:7070"); // TODO: instead 7070 I2Pd....HttpPort 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) { public boolean onOptionsItemSelected(MenuItem item) {

Loading…
Cancel
Save