-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzAndroid.pde
executable file
·406 lines (321 loc) · 11.2 KB
/
zAndroid.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
//// How to enable Android mode in your code:
//// ctrl+a
//// ctrl+/
//// Yes. That's really how you do it.
//// Make sure to do it to zDesktop too.
//import android.content.Context;
//import android.app.Activity;
//import android.content.Intent;
//import android.net.Uri;
//import android.os.Bundle;
//import android.os.Environment;
//import android.provider.MediaStore;
//import android.os.Bundle;
//import android.graphics.Bitmap;
//import android.media.MediaPlayer;
//import android.net.Uri;
//import android.content.res.AssetManager;
//import processing.sound.*;
//import android.os.Build;
//import android.provider.Settings;
//public static final int ANDROID_LAUNCH_CAM = 1;
//public static final int ANDROID_CAMERA_REQUEST = 2;
//static int ANDROID_RESULT_OK;
//private void shouldNotBeCalled(String funcitonName) {
// timewayEngine.console.bugWarnOnce(funcitonName+": You should not call this in Android mode!");
//}
//public boolean isLinux() {
// return false;
//}
//public boolean isWindows() {
// return false;
//}
//public boolean isMacOS() {
// return false;
//}
//public boolean isAndroid() {
// return true;
//}
//@SuppressWarnings("unused")
//public void setDesktopIcon(String iconPath) {
// // No desktop or icons on a phone obviously, don't do anything.
//}
//public String sketchPath() {
// return sketchPath;
//}
//protected PSurface initSurface() {
// // Don't do anything. Except return the essentials.
// return surface;
//}
//@SuppressWarnings("unused")
//protected void selectOutputSketch(String promptMessage, String outputFileSelected) {
// // TODO: implement file selector.
//}
//// Android doesn't have ctrl and alt keys.
//public static final int CONTROL = -2;
//public static final int ALT = -3;
//public Object getFromClipboardStringFlavour() {
// return "Clipboard Text";
//}
//public Object getFromClipboardImageFlavour() {
// return timewayEngine.display.errorImg;
//}
//public PImage getPImageFromClipboard()
//{
// return timewayEngine.display.errorImg;
//}
//@SuppressWarnings("unused")
//public void copyStringToClipboard(String s) {
//}
//@SuppressWarnings("unused")
//public boolean isClipboardImage(Object o) {
// return false;
//}
//@SuppressWarnings("unused")
//public void desktopOpen(String file) {
//}
//public void openErrorLog() {
//}
//@SuppressWarnings("unused")
//public void minimalErrorDialog(String mssg) {
//}
//public void requestAndroidPermissions() {
// if (!hasPermission("android.permission.MANAGE_EXTERNAL_STORAGE")) {
// requestPermission("android.permission.MANAGE_EXTERNAL_STORAGE");
// }
// if (!hasPermission("android.permission.READ_EXTERNAL_STORAGE")) {
// requestPermission("android.permission.READ_EXTERNAL_STORAGE");
// }
// if (!hasPermission("android.permission.WRITE_EXTERNAL_STORAGE")) {
// requestPermission("android.permission.WRITE_EXTERNAL_STORAGE");
// }
// timewayEngine.console.log("All files permission: "+hasAllFilesAccessPermission());
// requestAllFilesAccessPermission();
//}
//public boolean hasAllFilesAccessPermission() {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// // Check if the app has the "All Files Access" permission
// return Environment.isExternalStorageManager();
// }
// return true; // Permissions are handled differently on lower API levels
//}
//public void requestAllFilesAccessPermission() {
// Context context = getContext();
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// // If permission is not granted, prompt the user to change the setting
// if (!hasAllFilesAccessPermission()) {
// Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
// intent.setData(Uri.parse("package:" + context.getPackageName()));
// context.startActivity(intent);
// }
// }
//}
//public void openTouchKeyboard() {
// openKeyboard();
//}
//public void closeTouchKeyboard() {
// closeKeyboard();
//}
//public String getAndroidCacheDir() {
// String dir = getContext().getCacheDir().getAbsolutePath();
// if (dir.charAt(dir.length()-1) != '/') dir += "/"; // Directorify
// return dir;
//}
//public String getAndroidWriteableDir() {
// String dir = getContext().getFilesDir().getAbsolutePath();
// if (dir.charAt(dir.length()-1) != '/') dir += "/"; // Directorify
// return dir;
//}
//@SuppressWarnings("unused")
//public PImage getDCaptureImage(DSCapture capture) {
// return timewayEngine.display.errorImg;
//}
//@SuppressWarnings("unused")
//public int getDCaptureWidth(DSCapture capture) {
// shouldNotBeCalled("getDCaptureWidth");
// return 0;
//}
//@SuppressWarnings("unused")
//public int getDCaptureHeight(DSCapture capture) {
// shouldNotBeCalled("getDCaptureHeight");
// return 0;
//}
//public FileInputStream getFileInputStream(String file) {
// try {
// return getContext().openFileInput(sketchPath(file));
// }
// catch (Exception e) {
// timewayEngine.console.warn(e.getMessage());
// return null;
// }
//}
//public FileOutputStream getFileOutputStream(String file) {
// try {
// return getContext().openFileOutput(file, 3);
// }
// catch (Exception e) {
// timewayEngine.console.warn(e.getMessage());
// return null;
// }
//}
//boolean cameraPermissionRequested = false;
//public void openAndroidCamera() {
// if (!cameraPermissionRequested) {
// requestPermission("android.permission.CAMERA", "onCameraPermissionResponse");
// }
// else {
// startAndroidCamera();
// }
//}
//void onCameraPermissionResponse(boolean granted) {
// if (granted) {
// cameraPermissionRequested = true;
// startAndroidCamera();
// }
//}
//void startAndroidCamera() {
// Intent intent= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// //intent.putExtra(MediaStore.EXTRA_OUTPUT);
// try {
// getActivity().startActivityForResult(intent, ANDROID_LAUNCH_CAM);
// } catch (RuntimeException e) {
// // display error state to the user
// timewayEngine.console.warn("Failed to request camera: "+e.getMessage());
// }
//}
//boolean once = false;
//public void onActivityResult(int requestCode, int resultCode, Intent data)
//{
// if (resultCode == Activity.RESULT_CANCELED && !once) {
// once = true;
// }
// //if (requestCode == ANDROID_CAMERA_REQUEST){
// timewayEngine.console.log(requestCode);
// try {
// // Get the image from android camera.
// Bitmap imageBitmap = null;
// try {
// imageBitmap = (Bitmap) data.getParcelableExtra("data", Bitmap.class);
// }
// catch (Exception e) {
// timewayEngine.console.warn("getdata Photo error: "+e.getMessage());
// return;
// }
// //Bundle extras = data.getExtras();
// //Bitmap imageBitmap = (Bitmap) extras.get("data");
// //timewayEngine.console.log(imageBitmap.getWidth()+" "+imageBitmap.getHeight());
// //imageBitmap.getPixels(int[] pixels, int offset, int stride, int x, int y, int width, int height)
// //timewayEngine.console.log("tout est ok------------------");
// // Now to convert the image to pimage
// // swapped width and height cus image is on its side.
// int wi = imageBitmap.getHeight();
// int hi = imageBitmap.getWidth();
// PImage photo = createImage(wi, hi, ARGB);
// photo.loadPixels();
// try {
// for (int y = 0; y < imageBitmap.getHeight(); y++) {
// for (int x = 0; x < imageBitmap.getWidth(); x++) {
// photo.pixels[x*wi + y] = imageBitmap.getPixel(x, (imageBitmap.getHeight()-y-1));
// }
// }
// }
// catch (Exception e) {
// timewayEngine.console.warn("getpixel Photo error: "+e.getMessage());
// return;
// }
// photo.updatePixels();
// if (timewayEngine.currScreen instanceof Editor) {
// ((Editor)timewayEngine.currScreen).endCameraAndroid(photo);
// }
// }
// catch (Exception e) {
// timewayEngine.console.warn("Couldn't get result image, error: "+e.getMessage());
// }
//}
//void backPressed() {
// timewayEngine.inputPromptShown = false;
// if (timewayEngine.currScreen instanceof PixelRealmWithUI) {
// PixelRealmWithUI screen = (PixelRealmWithUI)timewayEngine.currScreen;
// screen.menu = null;
// screen.menuShown = false;
// }
//}
//@SuppressWarnings("unused")
//public void saveByteArrayAsWAV(byte[] audioData, int sampleRate, int bitDepth, int numChannels, String path) {
// // Not used in android so do nothing
//}
//public class AndroidMedia {
// MediaPlayer mediaPlayer = null;
// public AndroidMedia(String path) {
// // paths in the user files
// if (path.charAt(0) == '/') {
// File fff = new File(path);
// if (!fff.exists()) {
// timewayEngine.console.warn("(AndroidMedia) "+path+" doesn't exist.");
// }
// else {
// mediaPlayer = MediaPlayer.create(getContext(), Uri.fromFile(fff));
// }
// }
// // Paths in the assets
// else {
// mediaPlayer = new MediaPlayer();
// try {
// mediaPlayer.setDataSource(surface.getAssets().openFd(path));
// mediaPlayer.prepare();
// }
// catch (IOException e) {
// timewayEngine.console.warn("IOException MediaPlayer "+path+": "+e.getMessage());
// mediaPlayer = null;
// }
// catch (RuntimeException e) {
// timewayEngine.console.warn("Couldn't play "+path+": "+e.getMessage());
// mediaPlayer = null;
// }
// }
// }
// public void play() {
// if (mediaPlayer != null) {
// mediaPlayer.setLooping(false);
// mediaPlayer.start();
// }
// }
// public void loop() {
// if (mediaPlayer != null) {
// mediaPlayer.setLooping(true);
// mediaPlayer.start();
// }
// }
// public void stop() {
// if (mediaPlayer != null) {
// mediaPlayer.stop();
// }
// }
// public void volume(float vol) {
// if (mediaPlayer != null) {
// mediaPlayer.setVolume(vol, vol);
// }
// }
// public void pause() {
// }
// public boolean isPlaying() {
// if (mediaPlayer != null) {
// return mediaPlayer.isPlaying();
// }
// return false;
// }
//}
////SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
////String fileName = "IMG_" + simpleDateFormat.format(new Date()) + ".jpg";
////File myDirectory = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/");
////cameraImageFile = new File(myDirectory, fileName);
////Uri imageUri = Uri.fromFile(cameraImageFile);
////Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
////intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
////startActivityForResult(intent, CAMERA_PIC_REQUEST);
////**OnActivityResult:**
////switch (requestCode) {
////case CAMERA_PIC_REQUEST:
////ImageView.setImageBitmap(decodeFile(cameraImageFile.getAbsolutePath()));
////}
////break;