Skip to content

Commit 6100924

Browse files
committed
Add old java files
1 parent 1300391 commit 6100924

File tree

4 files changed

+265
-1
lines changed

4 files changed

+265
-1
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package org.kivy.android;
2+
3+
import java.io.UnsupportedEncodingException;
4+
import java.io.File;
5+
import java.io.FileInputStream;
6+
import java.util.Properties;
7+
8+
import android.util.Log;
9+
import android.graphics.Bitmap;
10+
import android.graphics.BitmapFactory;
11+
12+
13+
/**
14+
* This represents a project we've scanned for.
15+
*/
16+
public class Project {
17+
18+
String dir = null;
19+
String title = null;
20+
String author = null;
21+
Bitmap icon = null;
22+
boolean landscape = false;
23+
24+
static String decode(String s) {
25+
try {
26+
return new String(s.getBytes("ISO-8859-1"), "UTF-8");
27+
} catch (UnsupportedEncodingException e) {
28+
return s;
29+
}
30+
}
31+
32+
/**
33+
* Scans directory for a android.txt file. If it finds one,
34+
* and it looks valid enough, then it creates a new Project,
35+
* and returns that. Otherwise, returns null.
36+
*/
37+
public static Project scanDirectory(File dir) {
38+
39+
// We might have a link file.
40+
if (dir.getAbsolutePath().endsWith(".link")) {
41+
try {
42+
43+
// Scan the android.txt file.
44+
File propfile = new File(dir, "android.txt");
45+
FileInputStream in = new FileInputStream(propfile);
46+
Properties p = new Properties();
47+
p.load(in);
48+
in.close();
49+
50+
String directory = p.getProperty("directory", null);
51+
52+
if (directory == null) {
53+
return null;
54+
}
55+
56+
dir = new File(directory);
57+
58+
} catch (Exception e) {
59+
Log.i("Project", "Couldn't open link file " + dir, e);
60+
}
61+
}
62+
63+
// Make sure we're dealing with a directory.
64+
if (! dir.isDirectory()) {
65+
return null;
66+
}
67+
68+
try {
69+
70+
// Scan the android.txt file.
71+
File propfile = new File(dir, "android.txt");
72+
FileInputStream in = new FileInputStream(propfile);
73+
Properties p = new Properties();
74+
p.load(in);
75+
in.close();
76+
77+
// Get the various properties.
78+
String title = decode(p.getProperty("title", "Untitled"));
79+
String author = decode(p.getProperty("author", ""));
80+
boolean landscape = p.getProperty("orientation", "portrait").equals("landscape");
81+
82+
// Create the project object.
83+
Project rv = new Project();
84+
rv.title = title;
85+
rv.author = author;
86+
rv.icon = BitmapFactory.decodeFile(new File(dir, "icon.png").getAbsolutePath());
87+
rv.landscape = landscape;
88+
rv.dir = dir.getAbsolutePath();
89+
90+
return rv;
91+
92+
} catch (Exception e) {
93+
Log.i("Project", "Couldn't open android.txt", e);
94+
}
95+
96+
return null;
97+
98+
}
99+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.kivy.android;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.view.Gravity;
8+
import android.widget.ArrayAdapter;
9+
import android.widget.TextView;
10+
import android.widget.LinearLayout;
11+
import android.widget.ImageView;
12+
import android.graphics.Bitmap;
13+
import android.graphics.BitmapFactory;
14+
import android.util.Log;
15+
16+
import org.renpy.android.ResourceManager;
17+
18+
public class ProjectAdapter extends ArrayAdapter<Project> {
19+
20+
private Activity mContext;
21+
private ResourceManager resourceManager;
22+
23+
public ProjectAdapter(Activity context) {
24+
super(context, 0);
25+
26+
mContext = context;
27+
resourceManager = new ResourceManager(context);
28+
}
29+
30+
public View getView(int position, View convertView, ViewGroup parent) {
31+
Project p = getItem(position);
32+
33+
View v = resourceManager.inflateView("chooser_item");
34+
TextView title = (TextView) resourceManager.getViewById(v, "title");
35+
TextView author = (TextView) resourceManager.getViewById(v, "author");
36+
ImageView icon = (ImageView) resourceManager.getViewById(v, "icon");
37+
38+
title.setText(p.title);
39+
author.setText(p.author);
40+
icon.setImageBitmap(p.icon);
41+
42+
return v;
43+
}
44+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package org.kivy.android;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
6+
import android.content.Intent;
7+
import android.content.res.Resources;
8+
import android.util.Log;
9+
import android.view.View;
10+
import android.widget.ListView;
11+
import android.widget.TextView;
12+
import android.widget.AdapterView;
13+
import android.os.Environment;
14+
15+
import java.io.File;
16+
import java.util.ArrayList;
17+
import java.util.Arrays;
18+
import android.net.Uri;
19+
20+
import org.renpy.android.ResourceManager;
21+
22+
public class ProjectChooser extends Activity implements AdapterView.OnItemClickListener {
23+
24+
ResourceManager resourceManager;
25+
26+
String urlScheme;
27+
28+
@Override
29+
public void onStart()
30+
{
31+
super.onStart();
32+
33+
resourceManager = new ResourceManager(this);
34+
35+
urlScheme = resourceManager.getString("urlScheme");
36+
37+
// Set the window title.
38+
setTitle(resourceManager.getString("appName"));
39+
40+
// Scan the sdcard for files, and sort them.
41+
File dir = new File(Environment.getExternalStorageDirectory(), urlScheme);
42+
43+
File entries[] = dir.listFiles();
44+
45+
if (entries == null) {
46+
entries = new File[0];
47+
}
48+
49+
Arrays.sort(entries);
50+
51+
// Create a ProjectAdapter and fill it with projects.
52+
ProjectAdapter projectAdapter = new ProjectAdapter(this);
53+
54+
// Populate it with the properties files.
55+
for (File d : entries) {
56+
Project p = Project.scanDirectory(d);
57+
if (p != null) {
58+
projectAdapter.add(p);
59+
}
60+
}
61+
62+
if (projectAdapter.getCount() != 0) {
63+
64+
View v = resourceManager.inflateView("project_chooser");
65+
ListView l = (ListView) resourceManager.getViewById(v, "projectList");
66+
67+
l.setAdapter(projectAdapter);
68+
l.setOnItemClickListener(this);
69+
70+
setContentView(v);
71+
72+
} else {
73+
74+
View v = resourceManager.inflateView("project_empty");
75+
TextView emptyText = (TextView) resourceManager.getViewById(v, "emptyText");
76+
77+
emptyText.setText("No projects are available to launch. Please place a project into " + dir + " and restart this application. Press the back button to exit.");
78+
79+
setContentView(v);
80+
}
81+
}
82+
83+
public void onItemClick(AdapterView parent, View view, int position, long id) {
84+
Project p = (Project) parent.getItemAtPosition(position);
85+
86+
Intent intent = new Intent(
87+
"org.kivy.LAUNCH",
88+
Uri.fromParts(urlScheme, p.dir, ""));
89+
90+
intent.setClassName(getPackageName(), "org.kivy.android.PythonActivity");
91+
this.startActivity(intent);
92+
this.finish();
93+
}
94+
}

pythonforandroid/bootstraps/sdl2/build/src/org/kivy/android/PythonActivity.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,41 @@ protected void onCreate(Bundle savedInstanceState) {
7272
this.mActivity = this;
7373
this.showLoadingScreen();
7474

75+
// Figure out the directory where the game is. If the game was
76+
// given to us via an intent, then we use the scheme-specific
77+
// part of that intent to determine the file to launch. We
78+
// also use the android.txt file to determine the orientation.
79+
//
80+
// Otherwise, we use the public data, if we have it, or the
81+
// private data if we do not.
82+
if (getIntent() != null && getIntent().getAction() != null &&
83+
getIntent().getAction().equals("org.kivy.LAUNCH")) {
84+
File path = new File(getIntent().getData().getSchemeSpecificPart());
85+
86+
Project p = Project.scanDirectory(path);
87+
88+
if (p != null) {
89+
SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", p.dir + "/main.py");
90+
} else {
91+
SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", "main.pyo");
92+
}
93+
94+
// Let old apps know they started.
95+
try {
96+
FileWriter f = new FileWriter(new File(path, ".launch"));
97+
f.write("started");
98+
f.close();
99+
} catch (IOException e) {
100+
// pass
101+
}
102+
}
75103

76104
String app_root_dir = getAppRoot();
77105
String mFilesDirectory = mActivity.getFilesDir().getAbsolutePath();
78106
Log.v(TAG, "Setting env vars for start.c and Python to use");
79107
SDLActivity.nativeSetEnv("ANDROID_PRIVATE", mFilesDirectory);
80108
SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", app_root_dir);
81109
SDLActivity.nativeSetEnv("ANDROID_APP_PATH", app_root_dir);
82-
SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", "main.pyo");
83110
SDLActivity.nativeSetEnv("PYTHONHOME", app_root_dir);
84111
SDLActivity.nativeSetEnv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib");
85112
SDLActivity.nativeSetEnv("PYTHONOPTIMIZE", "2");

0 commit comments

Comments
 (0)