From e28b12c9fdb0b24ec0711df5dc65fed5726436d0 Mon Sep 17 00:00:00 2001 From: zt515 Date: Sun, 17 Dec 2017 00:54:32 +0800 Subject: [PATCH] UI: Setup Activity --- app/src/main/AndroidManifest.xml | 2 +- .../component/setup/BaseFileInstaller.java | 222 ------------------ .../neoterm/ui/pm/PackageManagerActivity.kt | 2 + app/src/main/res/layout/ui_setup.xml | 120 ++++++++-- app/src/main/res/values-zh-rCN/strings.xml | 14 +- app/src/main/res/values-zh-rTW/strings.xml | 6 +- app/src/main/res/values/strings.xml | 13 +- 7 files changed, 114 insertions(+), 265 deletions(-) delete mode 100644 app/src/main/java/io/neoterm/component/setup/BaseFileInstaller.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6c9886e..26bdbeb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -133,7 +133,7 @@ android:theme="@style/AppTheme.NoActionBar.Dark" /> > symlinks = new ArrayList<>(50); - - HttpURLConnection connection = openBaseFileConnection(); - connection.setConnectTimeout(8000); - connection.setReadTimeout(8000); - totalBytes = connection.getContentLength(); - - try (ZipInputStream zipInput = new ZipInputStream(connection.getInputStream())) { - ZipEntry zipEntry; - - while ((zipEntry = zipInput.getNextEntry()) != null) { - totalReadBytes += zipEntry.getCompressedSize(); - - final int totalReadBytesFinal = totalReadBytes; - final int totalBytesFinal = totalBytes; - - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - double progressFloat = ((double) totalReadBytesFinal) / ((double) totalBytesFinal) * 100.0; - progress.setProgress((int) progressFloat); - } catch (RuntimeException ignore) { - // activity dismissed - } - } - }); - - if (zipEntry.getName().contains("SYMLINKS.txt")) { - BufferedReader symlinksReader = new BufferedReader(new InputStreamReader(zipInput)); - String line; - while ((line = symlinksReader.readLine()) != null) { - if (line.isEmpty()) { - continue; - } - String[] parts = line.split("←"); - if (parts.length != 2) - throw new RuntimeException("Malformed symlink line: " + line); - String oldPath = parts[0]; - String newPath = STAGING_PREFIX_PATH + "/" + parts[1]; - symlinks.add(Pair.create(oldPath, newPath)); - } - } else { - String zipEntryName = zipEntry.getName(); - File targetFile = new File(STAGING_PREFIX_PATH, zipEntryName); - if (zipEntry.isDirectory()) { - if (!targetFile.mkdirs()) - throw new RuntimeException("Failed to create directory: " + targetFile.getAbsolutePath()); - } else { - try (FileOutputStream outStream = new FileOutputStream(targetFile)) { - int readBytes; - while ((readBytes = zipInput.read(buffer)) != -1) { - outStream.write(buffer, 0, readBytes); - } - } - if (zipEntryName.startsWith("bin/") || zipEntryName.startsWith("libexec") || zipEntryName.startsWith("lib/apt/methods")) { - //noinspection OctalInteger - Os.chmod(targetFile.getAbsolutePath(), 0700); - } - } - } - } - } - - connection.disconnect(); - - if (symlinks.isEmpty()) - throw new RuntimeException("No SYMLINKS.txt encountered"); - for (Pair symlink : symlinks) { - NLog.INSTANCE.e("Setup", "Linking " + symlink.first + " to " + symlink.second); - Os.symlink(symlink.first, symlink.second); - } - - if (!STAGING_PREFIX_FILE.renameTo(PREFIX_FILE)) { - throw new RuntimeException("Unable to rename staging folder"); - } - - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - resultListener.onResult(null); - } - }); - } catch (final Exception e) { - NLog.INSTANCE.e(EmulatorDebug.LOG_TAG, "Bootstrap error", e); - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - resultListener.onResult(e); - } catch (RuntimeException e) { - // Activity already dismissed - ignore. - } - } - }); - } finally { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - progress.dismiss(); - } catch (RuntimeException e) { - // Activity already dismissed - ignore. - } - } - }); - } - } - }.start(); - } - - private static HttpURLConnection openBaseFileConnection() throws IOException { - String arch = determineArchName(); - String baseUrl = NeoTermPath.INSTANCE.getSERVER_BASE_URL(); - - // Use the same source - NeoPreference.INSTANCE.store(R.string.key_package_source, baseUrl); - - return (HttpURLConnection) new URL(baseUrl + "/boot/" + arch + ".zip").openConnection(); - } - - private static String determineArchName() { - for (String androidArch : Build.SUPPORTED_ABIS) { - switch (androidArch) { - case "arm64-v8a": - return "aarch64"; - case "armeabi-v7a": - return "arm"; - case "x86_64": - return "x86_64"; -// case "x86": -// return "i686"; - } - } - throw new RuntimeException("Unable to determine arch from Build.SUPPORTED_ABIS = " + - Arrays.toString(Build.SUPPORTED_ABIS)); - } - - private static void deleteFolder(File fileOrDirectory) { - File[] children = fileOrDirectory.listFiles(); - if (children != null) { - for (File child : children) { - deleteFolder(child); - } - } - if (!fileOrDirectory.delete()) { - throw new RuntimeException("Unable to delete " + (fileOrDirectory.isDirectory() ? "directory " : "file ") + fileOrDirectory.getAbsolutePath()); - } - } - - public static ProgressDialog makeProgressDialog(Context context) { - ProgressDialog dialog = new ProgressDialog(context); - dialog.setMessage(context.getString(R.string.installer_message)); - dialog.setIndeterminate(false); - dialog.setCancelable(false); - dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - return dialog; - } -} diff --git a/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt b/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt index 8bee53b..08e5644 100644 --- a/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt +++ b/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt @@ -137,6 +137,8 @@ class PackageManagerActivity : AppCompatActivity(), SearchView.OnQueryTextListen private fun changeSourceToUserInput(sourceManager: SourceManager) { val editText = EditText(this) + editText.setSelectAllOnFocus(true) + AlertDialog.Builder(this) .setTitle(R.string.pref_package_source) .setView(editText) diff --git a/app/src/main/res/layout/ui_setup.xml b/app/src/main/res/layout/ui_setup.xml index d761aae..900eb46 100644 --- a/app/src/main/res/layout/ui_setup.xml +++ b/app/src/main/res/layout/ui_setup.xml @@ -1,41 +1,109 @@ - + android:layout_margin="32dp" + android:orientation="vertical"> - - + android:textSize="32sp" /> + android:layout_below="@id/setup_title_text" + android:text="@string/setup_setup_method" /> - \ No newline at end of file +