Skip to content

Commit

Permalink
Add OpenJDK installer
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Apr 26, 2020
1 parent 23d7014 commit 0c92b7c
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "3.0.0_preview1_1b_20200426"
versionName "3.0.0_INDEV_1b_20200426"
}

buildTypes {
Expand Down
91 changes: 80 additions & 11 deletions app/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import android.net.*;
import static android.view.ViewGroup.LayoutParams.*;
import net.kdt.pojavlaunch.update.*;
import net.kdt.pojavlaunch.util.*;
import java.net.*;

public class PojavLoginActivity extends MineActivity
{
Expand All @@ -36,6 +38,7 @@ public class PojavLoginActivity extends MineActivity
private SharedPreferences firstLaunchPrefs;
private String PREF_IS_DONOTSHOWAGAIN_WARN = "isWarnDoNotShowAgain";
private String PREF_IS_INSTALLED_LIBRARIES = "isLibrariesExtracted";
private String PREF_IS_INSTALLED_OPENJDK = "isOpenJDKInstalled";

private boolean isInitCalled = false;
@Override
Expand Down Expand Up @@ -105,18 +108,20 @@ private class InitTask extends AsyncTask<Void, String, Integer>{
private ProgressBar progress;

private ProgressBar progressSpin;
private EditText progressLog;
private TextView startSubText;
// private EditText progressLog;
private AlertDialog progDlg;

@Override
protected void onPreExecute()
{
LinearLayout startScr = new LinearLayout(PojavLoginActivity.this);
LayoutInflater.from(PojavLoginActivity.this).inflate(R.layout.start_screen, startScr);

startSubText = (TextView) startScr.findViewById(R.id.start_screen_sub_text);

replaceFonts(startScr);

progress = (ProgressBar) startScr.findViewById(R.id.startscreenProgress);
progress = (ProgressBar) startScr.findViewById(R.id.start_screen_progress);
//startScr.addView(progress);

AlertDialog.Builder startDlg = new AlertDialog.Builder(PojavLoginActivity.this, R.style.AppTheme);
Expand Down Expand Up @@ -157,7 +162,60 @@ protected Integer doInBackground(Void[] p1)

} catch (InterruptedException e) {}
}

if (!firstLaunchPrefs.getBoolean(PREF_IS_INSTALLED_OPENJDK, false)) {
// Install OpenJDK
runOnUiThread(new Runnable(){

@Override
public void run()
{
startSubText.setText(R.string.openjdk_install_download);
}
});
publishProgress("i0");
File openjdkZip = new File(Tools.MAIN_PATH, "OpenJDK.zip");
File oldOpenjdkFolder = new File(Tools.datapath, "openjdk");
File newOpenjdkFolder = new File(Tools.datapath, "jre");
try {
// BEGIN download file
URL url = new URL("https://github.com/khanhduytran0/PojavLauncher/releases/download/v3.0.0-preview1/net.kdt.pojavlaunch.openjdk.zip");
URLConnection connection = url.openConnection();
connection.connect();
int fileLength = connection.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(openjdkZip);
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress("+", null, Integer.toString((int) (total * 100 / fileLength)));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
// END download file

runOnUiThread(new Runnable(){

@Override
public void run()
{
startSubText.setText(R.string.openjdk_install_unpack);
}
});
publishProgress("i1");
Tools.ZipTool.unzip(openjdkZip, new File(Tools.datapath));
oldOpenjdkFolder.renameTo(newOpenjdkFolder);

Runtime.getRuntime().exec("chmod -R 700 " + newOpenjdkFolder.getAbsolutePath());
} catch (Throwable e) {
Tools.showError(PojavLoginActivity.this, e, true);
}
}

initMain();

return 0;
Expand All @@ -166,12 +224,25 @@ protected Integer doInBackground(Void[] p1)
@Override
protected void onProgressUpdate(String... obj)
{

if (obj[0].equals("visible")) {
progress.setVisibility(View.VISIBLE);
} else if (obj.length == 2 && obj[1] != null) {
if (obj[0] != null) {
if (obj[0].equals("visible")) {
progress.setVisibility(View.VISIBLE);
}

if (obj[0].equals("i0")) {
progress.setIndeterminate(false);
} else if (obj[0].equals("i1")) {
progress.setIndeterminate(true);
} else if (obj[0].equals("+")) {
progress.setMax(Integer.parseInt(obj[2].substring(1)));
progress.setProgress(progress.getProgress() + 1);
}
}
/*
if (obj.length > 1 && obj[1] != null) {
progressLog.append(obj[1]);
}
*/
}

@Override
Expand All @@ -181,9 +252,9 @@ protected void onPostExecute(Integer obj) {
if (obj == 0) {
if (progDlg != null) progDlg.dismiss();
uiInit();
} else if (progressLog != null) {
} /* else if (progressLog != null) {
progressLog.setText(getResources().getString(R.string.error_checklog, "\n\n" + progressLog.getText()));
}
} */

}
/*
Expand Down Expand Up @@ -294,8 +365,6 @@ private void initMain()
//FileAccess.copyAssetToFolderIfNonExist(this, "1.7.3.jar", Tools.versnDir + "/1.7.3");
//FileAccess.copyAssetToFolderIfNonExist(this, "1.7.10.jar", Tools.versnDir + "/1.7.10");

// Download and install OpenJDK
// https://github.com/khanhduytran0/PojavLauncher/releases/download/untagged-eb8f813f9739ae4472cf/net.kdt.pojavlaunch.openjdk.zip
}
catch(Exception e){
Tools.showError(this, e);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/net/kdt/pojavlaunch/util/IoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class IoUtil {

private IoUtil() {
}

public static void pipe( /*PojavLauncherActivity activity,*/ InputStream is, OutputStream out, byte[] buf) throws IOException {
public static void pipe(InputStream is, OutputStream out, byte[] buf) throws IOException {
while (true) {
//if (cancel) throw new CancelException();

Expand Down
15 changes: 10 additions & 5 deletions app/src/main/res/layout/start_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:id="@+id/startscreenLinearLayout1">
android:id="@+id/start_screen_layout">

<TextView
android:layout_width="wrap_content"
Expand All @@ -17,14 +17,19 @@
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/app_motd"/>
android:text="@string/app_motd"
android:id="@+id/start_screen_sub_text"/>

<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:id="@+id/startscreenProgress"
android:visibility="invisible"/>
android:id="@+id/start_screen_progress"
android:visibility="visible"
android:indeterminate="true"
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"/>

</LinearLayout>

6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<!-- Logging output -->
<string name="log_title">Log output</string>

<!-- Login strings -->
<string name="login_online_username_hint">Email or username</string>
<string name="login_online_username_question">(Which do I use?)</string>
Expand All @@ -31,6 +31,10 @@
<string name="login_error_exist_username">This username already exist</string>

<string name="login_select_account">Select account</string>

<!-- OpenJDK -->
<string name="openjdk_install_download">Downloading OpenJDK</string>
<string name="openjdk_install_unpack">Unpacking OpenJDK</string>

<!-- Hint -->
<string name="hint_select_account">To select, click it. To delete an account, hold it.</string>
Expand Down

0 comments on commit 0c92b7c

Please sign in to comment.