Android: Add simple launcher

This adds a minimal launcher activity for the android app, which does
the followings:

- Opens a file chooser to let user select a zip file
- Extracts the zip into the app's internal storage
- Launches the SDL activity
This commit is contained in:
kichikuou
2019-12-31 21:17:39 +09:00
parent e3c812da3a
commit 358ea7b1a9
6 changed files with 146 additions and 9 deletions
@@ -0,0 +1,35 @@
/* Copyright (C) 2019 <KichikuouChrome@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package io.github.kichikuou.system3;
import org.libsdl.app.SDLActivity;
public class GameActivity extends SDLActivity {
@Override
protected String[] getLibraries() {
return new String[] {
"hidapi",
"SDL2",
// "SDL2_image",
// "SDL2_mixer",
// "SDL2_net",
// "SDL2_ttf",
"system3"
};
}
}
@@ -0,0 +1,91 @@
/* Copyright (C) 2019 <KichikuouChrome@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package io.github.kichikuou.system3;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class LauncherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("application/zip");
startActivityForResult(Intent.createChooser(i, "Choose a file"), 0);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK)
extractFiles(data.getData(), getApplicationContext().getFilesDir());
startGame();
}
boolean extractFiles(Uri zipUri, File outDir) {
try {
InputStream input = getContentResolver().openInputStream(zipUri);
if (input == null)
return false;
ZipInputStream zip;
if (Build.VERSION.SDK_INT >= 24)
zip = new ZipInputStream(new BufferedInputStream(input), Charset.forName("Shift_JIS"));
else
zip = new ZipInputStream(new BufferedInputStream(input));
byte[] buffer = new byte[4096];
ZipEntry zipEntry;
while ((zipEntry = zip.getNextEntry()) != null) {
File entryName = new File(zipEntry.getName());
if (zipEntry.isDirectory())
continue;
Log.d("Extracting", entryName.toString());
File outFile = new File(outDir, entryName.getName());
BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(outFile));
int size;
while ((size = zip.read(buffer)) > 0) {
output.write(buffer, 0, size);
}
output.close();
}
zip.close();
return true;
} catch (IOException e) {
Log.e("launcher", "Error while extracting zip", e);
return false;
}
}
void startGame() {
Intent i = new Intent();
i.setClass(getApplicationContext(), GameActivity.class);
startActivity(i);
}
}