Show more context in the Android app when starting the server.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4502 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		| @@ -20,6 +20,7 @@ import android.webkit.WebResourceRequest; | ||||
| import android.webkit.WebView; | ||||
| import android.webkit.WebViewClient; | ||||
| import android.widget.Button; | ||||
| import android.widget.TextView; | ||||
| import java.io.BufferedInputStream; | ||||
| import java.io.BufferedReader; | ||||
| import java.io.File; | ||||
| @@ -54,11 +55,14 @@ public class MainActivity extends Activity { | ||||
| 		setContentView(R.layout.activity_main); | ||||
|  | ||||
| 		web_view = (WebView)findViewById(R.id.web); | ||||
| 		set_status("Extracting executable..."); | ||||
| 		Log.w("tildefriends", String.format("getFilesDir() is %s", getFilesDir().toString())); | ||||
| 		Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString())); | ||||
|  | ||||
| 		if (!extract_executable()) { | ||||
| 			Log.w("tildefriends", "Failed to extract a compatible executable."); | ||||
| 			set_status("No compatible ABI found."); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		String port_file_path = getFilesDir().toString() + "/port.txt"; | ||||
| @@ -84,9 +88,14 @@ public class MainActivity extends Activity { | ||||
| 								if (port >= 0) { | ||||
| 									base_url = "http://127.0.0.1:" + String.valueOf(port) + "/"; | ||||
| 									activity.runOnUiThread(() -> { | ||||
| 										activity.hide_status(); | ||||
| 										web_view.loadUrl(base_url); | ||||
| 									}); | ||||
| 									break; | ||||
| 								} else { | ||||
| 									activity.runOnUiThread(() -> { | ||||
| 										activity.set_status("Waiting to connect..."); | ||||
| 									}); | ||||
| 								} | ||||
| 							} | ||||
| 						} | ||||
| @@ -104,6 +113,7 @@ public class MainActivity extends Activity { | ||||
| 		}); | ||||
| 		thread.start(); | ||||
|  | ||||
| 		set_status("Starting server..."); | ||||
| 		String exe = getFilesDir().toString() + "/tildefriends"; | ||||
| 		ProcessBuilder builder = new ProcessBuilder(exe, "run", "-z", getPackageResourcePath().toString(), "-a", "out_http_port_file=" + port_file_path, "-p", "0"); | ||||
| 		Log.w("tildefriends", "files = " + getFilesDir().toString()); | ||||
| @@ -261,4 +271,17 @@ public class MainActivity extends Activity { | ||||
| 		} | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| 	private void set_status(String text) { | ||||
| 		TextView text_view = (TextView)findViewById(R.id.text); | ||||
| 		web_view.setVisibility(View.GONE); | ||||
| 		text_view.setVisibility(View.VISIBLE); | ||||
| 		text_view.setText(text); | ||||
| 	} | ||||
|  | ||||
| 	private void hide_status() { | ||||
| 		TextView text_view = (TextView)findViewById(R.id.text); | ||||
| 		web_view.setVisibility(View.VISIBLE); | ||||
| 		text_view.setVisibility(View.GONE); | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -5,10 +5,14 @@ | ||||
| 	android:layout_height="match_parent" | ||||
| 	android:orientation="vertical"> | ||||
| 	<WebView | ||||
| 		android:id="@+id/web" | ||||
| 		android:layout_width="match_parent" | ||||
| 		android:layout_height="match_parent"/> | ||||
| 	<TextView | ||||
| 		android:id="@+id/text" | ||||
| 		android:layout_width="match_parent" | ||||
| 		android:layout_height="match_parent" | ||||
| 		android:id="@+id/web"> | ||||
| 	</WebView> | ||||
| 		android:gravity="center_horizontal|center_vertical"/> | ||||
| 	<Button | ||||
| 		android:id="@+id/refresh" | ||||
| 		android:layout_width="fill_parent" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user