Skip to content

Commit 9e57a33

Browse files
committed
re-enabled apk export
1 parent 9298967 commit 9e57a33

File tree

5 files changed

+81
-60
lines changed

5 files changed

+81
-60
lines changed

mode/languages/mode.properties

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ android_debugger.error.debugger_exception = Debugger error: %s
6060
android_editor.status.exporting_project = Exporting an Android project of the sketch...
6161
android_editor.status.project_export_completed = Done with project export.
6262
android_editor.status.project_export_failed = Error with project export.
63+
android_editor.status.exporting_package = Exporting signed package...
64+
android_editor.status.package_export_completed = Done with package export.
65+
android_editor.status.package_export_failed = Error with package export.
6366
android_editor.status.exporting_bundle = Exporting signed bundle...
6467
android_editor.status.bundle_export_completed = Done with bundle export.
6568
android_editor.status.bundle_export_failed = Error with bundle export.
69+
6670
android_editor.error.cannot_create_sketch_properties = Error While creating sketch properties file "%s": %s
6771

6872
# ---------------------------------------
@@ -83,9 +87,9 @@ android_mode.dialog.wallpaper_installed_title = Wallpaper installed!
8387
android_mode.dialog.wallpaper_installed_body = Processing just built and installed your sketch as a live wallpaper on the selected device.<br><br>You need to open the wallpaper picker in the device in order to select it as the new background.
8488
android_mode.dialog.watchface_installed_title = Watch face installed!
8589
android_mode.dialog.watchface_installed_body = Processing just built and installed your sketch as a watch face on the selected device.<br><br>You need to add it as a favourite watch face on the device and then select it from the watch face picker in order to run it.
86-
android_mode.dialog.cannot_export_bundle_title = Cannot export bundle...
90+
android_mode.dialog.cannot_export_package_title = Cannot complete export...
8791
android_mode.dialog.cannot_export_package_body = The sketch still has the default package name. Not good, since this name will uniquely identify your app on the Play store... for ever! Come up with a different package name and write in the AndroidManifest.xml file in the sketch folder, after the "package=" attribute inside the manifest tag, which also contains version code and name. Once you have done that, try exporting the sketch again.<br><br>For more info on distributing apps from Processing,<br>check <a href=\"%s\">this online tutorial</a>.
88-
android_mode.dialog.cannot_use_default_icons_title = Cannot export bundle...
92+
android_mode.dialog.cannot_use_default_icons_title = Cannot complete export...
8993
android_mode.dialog.cannot_use_default_icons_body = The sketch does not include all required app icons. Processing could use its default set of Android icons, which are okay to test the app on your device, but a bad idea to distribute it on the Play store. Create a full set of unique icons for your app, and copy them into the sketch folder. Once you have done that, try exporting the sketch again.<br><br>For more info on distributing apps from Processing,<br>check <a href=\"%s\">this online tutorial</a>.
9094
android_mode.warn.cannot_load_sdk_title = Bad news...
9195
android_mode.warn.cannot_load_sdk_body = The Android SDK could not be loaded.\nThe Android Mode will be disabled.

mode/src/processing/mode/android/AndroidEditor.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ public boolean handleSaveAs() {
123123

124124

125125
public JMenu buildFileMenu() {
126+
String exportPackageTitle = AndroidToolbar.getTitle(AndroidToolbar.EXPORT_PACKAGE, true);
127+
JMenuItem exportPackage = Toolkit.newJMenuItem(exportPackageTitle, 'K');
128+
exportPackage.addActionListener(new ActionListener() {
129+
public void actionPerformed(ActionEvent e) {
130+
handleExportPackage();
131+
}
132+
});
133+
134+
126135
String exportBundleTitle = AndroidToolbar.getTitle(AndroidToolbar.EXPORT_BUNDLE, false);
127136
JMenuItem exportBundle = Toolkit.newJMenuItem(exportBundleTitle, 'B');
128137
exportBundle.addActionListener(new ActionListener() {
@@ -521,13 +530,52 @@ public void run() {
521530
}
522531
}
523532

533+
/**
534+
* Create a release package of the sketch
535+
*/
536+
public void handleExportPackage() {
537+
if (androidMode.checkPackageName(sketch, appComponent) &&
538+
androidMode.checkAppIcons(sketch, appComponent) && handleExportCheckModified()) {
539+
new KeyStoreManager(this, KeyStoreManager.PACKAGE);
540+
}
541+
}
542+
543+
public void startExportPackage(final String keyStorePassword) {
544+
new Thread() {
545+
public void run() {
546+
startIndeterminate();
547+
statusNotice(AndroidMode.getTextString("android_editor.status.exporting_bundle"));
548+
AndroidBuild build = new AndroidBuild(sketch, androidMode, appComponent);
549+
try {
550+
File projectFolder = build.exportPackage(keyStorePassword);
551+
if (projectFolder != null) {
552+
statusNotice(AndroidMode.getTextString("android_editor.status.package_export_completed"));
553+
Platform.openFolder(projectFolder);
554+
} else {
555+
statusError(AndroidMode.getTextString("android_editor.status.package_export_failed"));
556+
}
557+
} catch (IOException e) {
558+
statusError(e);
559+
} catch (SketchException e) {
560+
statusError(e);
561+
} catch (InterruptedException e) {
562+
e.printStackTrace();
563+
} catch (Exception e) {
564+
e.printStackTrace();
565+
}
566+
stopIndeterminate();
567+
}
568+
}.start();
569+
}
570+
571+
524572
/**
525573
* Create a release bundle of the sketch
526574
*/
527575
public void handleExportBundle() {
528576
if (androidMode.checkPackageName(sketch, appComponent) &&
529577
androidMode.checkAppIcons(sketch, appComponent) && handleExportCheckModified()) {
530-
new KeyStoreManager(this);
578+
new KeyStoreManager(this, KeyStoreManager.BUNDLE);
531579
}
532580
}
533581

mode/src/processing/mode/android/AndroidMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public boolean checkPackageName(Sketch sketch, int comp) {
332332
String name = manifest.getPackageName();
333333
if (name.toLowerCase().equals(defName.toLowerCase())) {
334334
// The user did not set the package name, show error and stop
335-
AndroidUtil.showMessage(AndroidMode.getTextString("android_mode.dialog.cannot_export_bundle_title"),
335+
AndroidUtil.showMessage(AndroidMode.getTextString("android_mode.dialog.cannot_export_package_title"),
336336
AndroidMode.getTextString("android_mode.dialog.cannot_export_package_body", DISTRIBUTING_APPS_TUT_URL));
337337
return false;
338338
}

mode/src/processing/mode/android/AndroidToolbar.java

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public class AndroidToolbar extends EditorToolbar {
4545
static protected final int NEW = 2;
4646
static protected final int OPEN = 3;
4747
static protected final int SAVE = 4;
48-
static protected final int EXPORT_BUNDLE = 5;
49-
static protected final int EXPORT_PROJECT = 6;
48+
static protected final int EXPORT_PACKAGE = 5;
49+
static protected final int EXPORT_BUNDLE = 6;
50+
static protected final int EXPORT_PROJECT = 7;
5051

5152

5253
private AndroidEditor aEditor;
@@ -77,58 +78,15 @@ static public String getTitle(int index, boolean shift) {
7778
case NEW: return "New";
7879
case OPEN: return "Open";
7980
case SAVE: return "Save";
80-
case EXPORT_BUNDLE: return AndroidMode.getTextString("menu.file.export_signed_bundle");
81+
82+
83+
case EXPORT_PACKAGE: return AndroidMode.getTextString("menu.file.export_signed_package");
84+
case EXPORT_BUNDLE: return AndroidMode.getTextString("menu.file.export_signed_bundle");
8185
case EXPORT_PROJECT: return AndroidMode.getTextString("menu.file.export_android_project");
8286
}
8387
return null;
8488
}
8589

86-
/*
87-
public void handlePressed(MouseEvent e, int sel) {
88-
boolean shift = e.isShiftDown();
89-
AndroidEditor aeditor = (AndroidEditor) editor;
90-
91-
switch (sel) {
92-
case RUN:
93-
if (!shift) {
94-
aeditor.handleRunDevice();
95-
} else {
96-
aeditor.handleRunEmulator();
97-
}
98-
break;
99-
100-
case STOP:
101-
aeditor.handleStop();
102-
break;
103-
104-
case OPEN:
105-
// TODO I think we need a longer chain of accessors here.
106-
JPopupMenu popup = editor.getMode().getToolbarMenu().getPopupMenu();
107-
popup.show(this, e.getX(), e.getY());
108-
break;
109-
110-
case NEW:
111-
// if (shift) {
112-
base.handleNew();
113-
// } else {
114-
// base.handleNewReplace();
115-
// }
116-
break;
117-
118-
case SAVE:
119-
aeditor.handleSave(false);
120-
break;
121-
122-
case EXPORT:
123-
if (!shift) {
124-
aeditor.handleExportPackage();
125-
} else {
126-
aeditor.handleExportProject();
127-
}
128-
break;
129-
}
130-
}
131-
*/
13290

13391
@Override
13492
public List<EditorButton> createButtons() {

mode/src/processing/mode/android/KeyStoreManager.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242

4343
@SuppressWarnings("serial")
4444
public class KeyStoreManager extends JFrame {
45+
final static protected int PACKAGE = 0;
46+
final static protected int BUNDLE = 1;
47+
4548
final static private int BOX_BORDER = Toolkit.zoom(13);
4649
final static private int PASS_BORDER = Toolkit.zoom(15);
4750
final static private int LABEL_WIDTH = Toolkit.zoom(400);
@@ -64,14 +67,14 @@ public class KeyStoreManager extends JFrame {
6467
JTextField country;
6568
JTextField stateName;
6669

67-
public KeyStoreManager(final AndroidEditor editor) {
70+
public KeyStoreManager(final AndroidEditor editor, final int kind) {
6871
super("Android keystore manager");
6972
this.editor = editor;
7073

71-
createLayout();
74+
createLayout(kind);
7275
}
7376

74-
private void createLayout() {
77+
private void createLayout(int kind) {
7578
Container outer = getContentPane();
7679
outer.removeAll();
7780

@@ -104,14 +107,22 @@ public void actionPerformed(ActionEvent e) {
104107
commonName.getText(), organizationalUnit.getText(), organizationName.getText(),
105108
localityName.getText(), stateName.getText(), country.getText());
106109

107-
setVisible(false);
108-
editor.startExportBundle(new String(passwordField.getPassword()));
110+
setVisible(false);
111+
if (kind == KeyStoreManager.BUNDLE) {
112+
editor.startExportBundle(new String(passwordField.getPassword()));
113+
} else {
114+
editor.startExportPackage(new String(passwordField.getPassword()));
115+
}
109116
} catch (Exception e1) {
110117
e1.printStackTrace();
111118
}
112119
} else {
113120
setVisible(false);
114-
editor.startExportBundle(new String(passwordField.getPassword()));
121+
if (kind == KeyStoreManager.BUNDLE) {
122+
editor.startExportBundle(new String(passwordField.getPassword()));
123+
} else {
124+
editor.startExportPackage(new String(passwordField.getPassword()));
125+
}
115126
}
116127
}
117128
}
@@ -147,7 +158,7 @@ public void actionPerformed(ActionEvent e) {
147158
setVisible(true);
148159
} else {
149160
keyStore = null;
150-
createLayout();
161+
createLayout(kind);
151162
}
152163
}
153164
}

0 commit comments

Comments
 (0)