├── share.png
├── ios
└── sharekore
│ ├── ShareKore.h
│ └── ShareKore.mm
├── android
├── sharekore
│ ├── ShareKore.h
│ └── ShareKore.cpp
└── java
│ └── sharekore
│ └── ShareKore.java
├── README.md
├── korefile.js
└── Sources
└── share
└── Share.hx
/share.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luboslenco/share_kha/HEAD/share.png
--------------------------------------------------------------------------------
/ios/sharekore/ShareKore.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace ShareKore {
4 |
5 | void share(const char* subject, const char* body, const char* url, bool attachScreenshot);
6 | }
7 |
--------------------------------------------------------------------------------
/android/sharekore/ShareKore.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace ShareKore {
4 |
5 | void share(const char* subject, const char* body, const char* url, bool attachScreenshot);
6 | }
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # share_kha
2 | Share library for Haxe Kha
3 |
4 | ## Usage
5 | - Clone repository into 'your_project/Libraries'
6 | - Bring up share dialog:
7 | ``` hx
8 | share.Share.share(subject:String, body:String, url:String, attachScreenshot:Bool);
9 | ```
10 |
11 |
--------------------------------------------------------------------------------
/korefile.js:
--------------------------------------------------------------------------------
1 | var project = new Project('share_kha');
2 |
3 | if (platform === Platform.iOS) {
4 | project.addFile('ios/sharekore/**');
5 | project.addIncludeDir('ios/sharekore');
6 | }
7 | else if (platform === Platform.Android) {
8 | project.addFile('android/sharekore/**');
9 | project.addIncludeDir('android/sharekore');
10 | project.addJavaDir('android/java');
11 | }
12 |
13 | return project;
14 |
--------------------------------------------------------------------------------
/Sources/share/Share.hx:
--------------------------------------------------------------------------------
1 | package share;
2 |
3 | #if (sys_ios || sys_android_native)
4 | @:headerCode('
5 | #include
6 | ')
7 | #end
8 |
9 | class Share {
10 |
11 | #if (sys_ios || sys_android_native)
12 | @:functionCode('ShareKore::share(subject, body, url, attachScreenshot);')
13 | #end
14 | public static function share(subject:String, body:String, url:String, attachScreenshot:Bool):Void {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/android/sharekore/ShareKore.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 |
5 | namespace ShareKore {
6 |
7 | void share(const char* subject, const char* body, const char* url, bool attachScreenshot) {
8 | JNIEnv* env;
9 | KoreAndroid::getActivity()->vm->AttachCurrentThread(&env, NULL);
10 |
11 | jclass cls = KoreAndroid::findClass(env, "sharekore.ShareKore");
12 |
13 | jmethodID shareId = env->GetStaticMethodID(cls, "share", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V");
14 |
15 | jstring jsubject = env->NewStringUTF(subject);
16 | jstring jbody = env->NewStringUTF(body);
17 | jstring jurl = env->NewStringUTF(url);
18 |
19 | env->CallStaticVoidMethod(cls, shareId, jsubject, jbody, jurl, attachScreenshot);
20 |
21 | KoreAndroid::getActivity()->vm->DetachCurrentThread();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/android/java/sharekore/ShareKore.java:
--------------------------------------------------------------------------------
1 | package sharekore;
2 |
3 | import android.content.Intent;
4 | import com.ktxsoftware.kore.KoreActivity;
5 |
6 | public class ShareKore {
7 |
8 | public static void share(String subject, String body, String url, boolean attachScreenshot) {
9 | Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
10 | sendIntent.setType("text/plain");
11 | if (subject != null && subject != "") sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
12 | if (body != null && body != "") sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
13 | KoreActivity.getInstance().startActivity(sendIntent);
14 | }
15 |
16 | /*public void shareit()
17 | {
18 | View view = findViewById(R.id.layout);//your layout id
19 | view.getRootView();
20 | String state = Environment.getExternalStorageState();
21 | if (Environment.MEDIA_MOUNTED.equals(state))
22 | {
23 | File picDir = new File(Environment.getExternalStorageDirectory()+ "/myPic");
24 | if (!picDir.exists())
25 | {
26 | picDir.mkdir();
27 | }
28 | view.setDrawingCacheEnabled(true);
29 | view.buildDrawingCache(true);
30 | Bitmap bitmap = view.getDrawingCache();
31 | // Date date = new Date();
32 | String fileName = "mylove" + ".jpg";
33 | File picFile = new File(picDir + "/" + fileName);
34 | try
35 | {
36 | picFile.createNewFile();
37 | FileOutputStream picOut = new FileOutputStream(picFile);
38 | bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), (int)(bitmap.getHeight()/1.2));
39 | boolean saved = bitmap.compress(CompressFormat.JPEG, 100, picOut);
40 | if (saved)
41 | {
42 | Toast.makeText(getApplicationContext(), "Image saved to your device Pictures "+ "directory!", Toast.LENGTH_SHORT).show();
43 | } else
44 | {
45 | //Error
46 | }
47 | picOut.close();
48 | }
49 | catch (Exception e)
50 | {
51 | e.printStackTrace();
52 | }
53 | view.destroyDrawingCache();
54 | } else {
55 | //Error
56 |
57 | }
58 |
59 | Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
60 | sharingIntent.setType("image/jpeg");
61 | sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(picFile.getAbsolutePath()));
62 | startActivity(Intent.createChooser(sharingIntent, "Share via"));
63 | }*/
64 | }
65 |
--------------------------------------------------------------------------------
/ios/sharekore/ShareKore.mm:
--------------------------------------------------------------------------------
1 | #include
2 | #import
3 |
4 | namespace ShareKore {
5 |
6 | void share(const char* subject, const char* body, const char* url, bool attachScreenshot) {
7 |
8 | UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
9 |
10 | UIImage *image;
11 | if (attachScreenshot) {
12 | if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
13 | UIGraphicsBeginImageContextWithOptions(window.bounds.size, NO, [UIScreen mainScreen].scale);
14 | else
15 | UIGraphicsBeginImageContext(window.bounds.size);
16 |
17 | [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
18 |
19 | image = UIGraphicsGetImageFromCurrentImageContext();
20 | UIGraphicsEndImageContext();
21 | }
22 |
23 | NSString *stext = [[NSString alloc] initWithUTF8String:body];
24 | NSURL *surl = [NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];
25 |
26 | NSArray *itemsToShare;
27 | if (attachScreenshot) {
28 | itemsToShare = @[stext, surl, image];
29 | }
30 | else {
31 | itemsToShare = @[stext, surl];
32 | }
33 |
34 | UIActivityViewController *activityVC = [[UIActivityViewController alloc]
35 | initWithActivityItems:itemsToShare
36 | applicationActivities:nil];
37 |
38 | [activityVC setValue:[[NSString alloc] initWithUTF8String:subject] forKey:@"subject"];
39 |
40 | if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
41 | // Required for iPad
42 | activityVC.popoverPresentationController.sourceView = [[UIApplication sharedApplication] keyWindow];
43 |
44 | // Remove arrow from action sheet
45 | [activityVC.popoverPresentationController setPermittedArrowDirections:0];
46 |
47 | // Set action sheet to middle of view
48 | activityVC.popoverPresentationController.sourceRect = [[UIApplication sharedApplication] keyWindow].frame;
49 | }
50 |
51 | /*activityVC.excludedActivityTypes = @[UIActivityTypeAddToReadingList,
52 | UIActivityTypeCopyToPasteboard,
53 | UIActivityTypePrint,
54 | UIActivityTypeAssignToContact,
55 | UIActivityTypeSaveToCameraRoll,
56 | UIActivityTypeAddToReadingList,
57 | //UIActivityTypeMail,
58 | UIActivityTypeAirDrop];*/
59 |
60 | UIViewController *shareVC;
61 | shareVC = [[UIViewController alloc] init];
62 | [window addSubview:shareVC.view];
63 | [shareVC presentViewController:activityVC animated:YES completion:nil];
64 |
65 | [activityVC setCompletionHandler:^(NSString *activityType, BOOL completed)
66 | {
67 | [shareVC.view removeFromSuperview];
68 | }];
69 | }
70 | }
71 |
--------------------------------------------------------------------------------