Advertisement
Guest User

Fusetools run another app

a guest
Jun 15th, 2016
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. using Fuse.Scripting;
  2. using Fuse;
  3. using Android;
  4. using Android.ActivityUtils;
  5. using Uno.Compiler.ExportTargetInterop;
  6.  
  7. [extern(Android) ForeignInclude(Language.Java,
  8. "com.fuse.Activity",
  9. "android.content.Intent",
  10. "android.net.Uri",
  11. "android.os.Bundle",
  12. "android.provider.MediaStore",
  13. "android.database.Cursor",
  14. "android.content.Context",
  15. "android.util.Log",
  16. "java.io.File")]
  17.  
  18. public class browsePhotoAPI : NativeModule
  19. {
  20. string pathFile;
  21. public browsePhotoAPI()
  22. {
  23. AddMember( new NativeFunction("activeBrowsePhoto", (NativeCallback) activeBrowsePhoto));
  24. AddMember( new NativeFunction("getPathImage", (NativeCallback) getPathImage));
  25. }
  26.  
  27. object activeBrowsePhoto(Context c, object[] args)
  28. {
  29. pathFile = "nothing";
  30. var intent = makeMyIntent();
  31. if (intent!=null)
  32. {
  33. ActivityUtils.StartActivity(intent, OnResult);
  34. while (pathFile == "nothing") {
  35. }
  36. } else {
  37. debug_log "Didnt make intent. boooo";
  38. }
  39. debug_log "ok now";
  40. return null;
  41. }
  42.  
  43. object getPathImage(Context c, object[] args)
  44. {
  45. return pathFile;
  46. }
  47.  
  48. void setPathImage(string file)
  49. {
  50. debug_log "This is setPath:";
  51. debug_log pathFile;
  52. pathFile = file;
  53. }
  54.  
  55. [Foreign(Language.Java)]
  56. extern(android) void OnResult(int resultCode, Java.Object intent, object info)
  57. @{
  58. String TAG = "My Tag";
  59. Log.d(TAG, "what what ");
  60.  
  61. Intent i = (Intent) intent;
  62. Log.d(TAG, i.getData().getPath());
  63.  
  64. Uri u = i.getData();
  65. String result;
  66. Cursor cursor = Activity.getRootActivity().getContentResolver().query(u, null, null, null, null);
  67. if (cursor == null) { // Source is Dropbox or other similar local file path
  68. result = u.getPath();
  69. } else {
  70. cursor.moveToFirst();
  71. int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
  72. result = cursor.getString(idx);
  73. cursor.close();
  74. }
  75.  
  76. Log.d(TAG, result);
  77. @{browsePhotoAPI:Of(_this).setPathImage(string):Call(result)};
  78. @}
  79.  
  80. [Foreign(Language.Java)]
  81. static extern(android) Java.Object makeMyIntent()
  82. @{
  83. try {
  84. int PICK_CONTACT_REQUEST = 1;
  85. Intent intent=new Intent(Intent.ACTION_PICK);
  86. intent.setData(Uri.parse("content://media/external/images/media"));
  87. return intent;
  88.  
  89. } catch (Exception ex) {
  90. return null;
  91. }
  92.  
  93. @}
  94.  
  95. extern(!android) void OnResult(int resultCode, object intent, object info)
  96. {
  97. }
  98.  
  99. static extern(!android) object makeMyIntent()
  100. {
  101. return null;
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement