mirror of
https://github.com/processing/processing4.git
synced 2026-02-14 02:45:36 +01:00
wiring in the permissions code
This commit is contained in:
@@ -139,6 +139,7 @@ class Build {
|
||||
if (className != null) {
|
||||
// final File androidXML = new File(tempBuildFolder, "AndroidManifest.xml");
|
||||
// writeAndroidManifest(androidXML, sketch.getName(), className);
|
||||
manifest.setClassName(className);
|
||||
writeBuildProps(new File(tempBuildFolder, "build.properties"));
|
||||
buildFile = new File(tempBuildFolder, "build.xml");
|
||||
writeBuildXML(buildFile, sketch.getName());
|
||||
|
||||
@@ -34,11 +34,15 @@ import processing.xml.XMLElement;
|
||||
public class Manifest {
|
||||
static final String MANIFEST_XML = "AndroidManifest.xml";
|
||||
|
||||
static final String CRAP_REALLY_SORRY =
|
||||
static final String WORLD_OF_HURT_COMING =
|
||||
"Errors occurred while reading or writing " + MANIFEST_XML + ",\n" +
|
||||
"which means lots of things are likely to stop working properly.\n" +
|
||||
"To prevent losing any data, it's recommended that you use “Save As”\n" +
|
||||
"to save a separate copy of your sketch, and the restart Processing.";
|
||||
static final String MULTIPLE_ACTIVITIES =
|
||||
"Processing only supports a single Activity in the AndroidManifest.xml\n" +
|
||||
"file. Only the first activity entry will be updated, and you better \n" +
|
||||
"hope that's the right one, smart guy.";
|
||||
|
||||
private Editor editor;
|
||||
private Sketch sketch;
|
||||
@@ -102,7 +106,22 @@ public class Manifest {
|
||||
save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setClassName(String className) {
|
||||
XMLElement[] kids = xml.getChildren("application/activity");
|
||||
if (kids.length != 1) {
|
||||
Base.showWarning("Don't touch that", MULTIPLE_ACTIVITIES, null);
|
||||
}
|
||||
XMLElement activity = kids[0];
|
||||
String currentName = activity.getString("android:name");
|
||||
// only update if there are changes
|
||||
if (currentName == null || !currentName.equals(className)) {
|
||||
activity.setString("android:name", "." + className);
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void writeBlankManifest(final File file) {
|
||||
final PrintWriter writer = PApplet.createWriter(file);
|
||||
writer.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||
@@ -161,7 +180,7 @@ public class Manifest {
|
||||
}
|
||||
}
|
||||
if (xml == null) {
|
||||
Base.showWarning("Error handling " + MANIFEST_XML, CRAP_REALLY_SORRY, null);
|
||||
Base.showWarning("Error handling " + MANIFEST_XML, WORLD_OF_HURT_COMING, null);
|
||||
}
|
||||
// return xml;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package processing.app.tools.android;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
@@ -221,7 +222,8 @@ public class Permissions extends JFrame implements Tool {
|
||||
okButton.setPreferredSize(dim);
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PApplet.println(getSelections());
|
||||
//PApplet.println(getSelections());
|
||||
saveSelections();
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
@@ -270,6 +272,19 @@ public class Permissions extends JFrame implements Tool {
|
||||
}
|
||||
|
||||
|
||||
protected void setSelections(String[] sel) {
|
||||
HashMap<String,Object> map = new HashMap<String, Object>();
|
||||
for (String s : sel) {
|
||||
map.put(s, new Object());
|
||||
}
|
||||
DefaultListModel model = (DefaultListModel) permissionList.getModel();
|
||||
for (int i = 0; i < count; i++) {
|
||||
JCheckBox box = (JCheckBox) model.get(i);
|
||||
box.setSelected(map.containsKey(box.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected String[] getSelections() {
|
||||
ArrayList<String> sel = new ArrayList<String>();
|
||||
DefaultListModel model = (DefaultListModel) permissionList.getModel();
|
||||
@@ -280,6 +295,13 @@ public class Permissions extends JFrame implements Tool {
|
||||
}
|
||||
return sel.toArray(new String[0]);
|
||||
}
|
||||
|
||||
|
||||
protected void saveSelections() {
|
||||
String[] sel = getSelections();
|
||||
Manifest mf = new Manifest(editor);
|
||||
mf.setPermissions(sel);
|
||||
}
|
||||
|
||||
|
||||
public String getMenuTitle() {
|
||||
@@ -288,12 +310,16 @@ public class Permissions extends JFrame implements Tool {
|
||||
|
||||
|
||||
public void init(Editor editor) {
|
||||
this.editor = editor;
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// parse the manifest file here and figure out what permissions are valid
|
||||
// parse the manifest file here and figure out what permissions are set
|
||||
Manifest mf = new Manifest(editor);
|
||||
setSelections(mf.getPermissions());
|
||||
|
||||
// show the window and get to work
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user