1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 06:11:19 +00:00

Changed Activity to show web UI.

This commit is contained in:
Felix Ableitner 2014-05-06 12:03:09 +02:00
parent a93fcb3ea7
commit 76d7429a58
4 changed files with 95 additions and 19 deletions

View file

@ -14,8 +14,8 @@
android:label="@string/app_name" android:label="@string/app_name"
android:icon="@drawable/ic_launcher" > android:icon="@drawable/ic_launcher" >
<activity <activity
android:name=".MainActivity" android:name=".WebGuiActivity"
android:theme="@android:style/Theme.Holo.Light" android:theme="@android:style/Theme.Holo.Light"
android:label="@string/app_name" > android:label="@string/app_name" >
<intent-filter> <intent-filter>

21
res/layout/main.xml Normal file
View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<ProgressBar
android:id="@+id/loading"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>

View file

@ -1,17 +0,0 @@
package com.nutomic.syncthingandroid;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
private static final String TAG = "MainActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startService(new Intent(this, SyncthingService.class));
}
}

View file

@ -0,0 +1,72 @@
package com.nutomic.syncthingandroid;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class WebGuiActivity extends Activity {
private static final String TAG = "WebGuiActivity";
/**
* URL of the local syncthing web UI.
*
* TODO: read this out from native code.
*/
private static final String SYNCTHING_URL = "http://127.0.0.1:8080";
private WebView mWebView;
private ProgressBar mLoadingView;
/**
* Retries loading every second until the web UI becomes available.
*/
private WebViewClient mWebViewClient = new WebViewClient() {
private int mError = 0;
@Override
public void onReceivedError(WebView view, int errorCode, String description,
String failingUrl) {
mError = errorCode;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mError = 0;
mWebView.loadUrl(SYNCTHING_URL);
}
}, 1000);
}
@Override
public void onPageFinished(WebView view, String url) {
if (mError == 0) {
mWebView.setVisibility(View.VISIBLE);
mLoadingView.setVisibility(View.GONE);
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startService(new Intent(this, SyncthingService.class));
setContentView(R.layout.main);
mLoadingView = (ProgressBar) findViewById(R.id.loading);
mLoadingView.setIndeterminate(true);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebViewClient(mWebViewClient);
mWebView.loadUrl(SYNCTHING_URL);
}
}