diff --git a/MessageComposer/Info.plist.xml b/MessageComposer/Info.plist.xml
index 18ec7ccf..8fad5307 100644
--- a/MessageComposer/Info.plist.xml
+++ b/MessageComposer/Info.plist.xml
@@ -24,6 +24,10 @@
${app.build}
LSRequiresIPhoneOS
+ UIMainStoryboardFile
+ Main
+ MinimumOSVersion
+ 8.0
UIDeviceFamily
1
@@ -36,38 +40,15 @@
UISupportedInterfaceOrientations
UIInterfaceOrientationPortrait
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight
UISupportedInterfaceOrientations~ipad
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight
- CFBundleIcons
-
- CFBundlePrimaryIcon
-
- CFBundleIconFiles
-
- Icon-Small
- Icon-Small-40
- Icon
- Icon-60
- Icon-72
-
-
-
- CFBundleIcons~ipad
-
- CFBundlePrimaryIcon
-
- CFBundleIconFiles
-
- Icon-Small
- Icon-Small-40
- Icon-72
- Icon-76
-
-
-
diff --git a/MessageComposer/build.gradle b/MessageComposer/build.gradle
deleted file mode 100644
index e431d76b..00000000
--- a/MessageComposer/build.gradle
+++ /dev/null
@@ -1,3 +0,0 @@
-ext {
- mainClassName = "org.robovm.samples.messagecomposer.MessageComposer"
-}
\ No newline at end of file
diff --git a/MessageComposer/pom.xml b/MessageComposer/pom.xml
deleted file mode 100644
index cc8696a1..00000000
--- a/MessageComposer/pom.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
- 4.0.0
-
-
- org.robovm
- robovm-samples-parent
- 1.0
-
-
- robovm-samples-messagecomposer
- RoboVM port of Apple's MessageComposer sample
-
- jar
-
-
- src/main/java
-
-
-
-
- org.robovm
- robovm-rt
-
-
- org.robovm
- robovm-cocoatouch
-
-
-
\ No newline at end of file
diff --git a/MessageComposer/resources/Base.lproj/Main.storyboard b/MessageComposer/resources/Base.lproj/Main.storyboard
new file mode 100644
index 00000000..f1b169a4
--- /dev/null
+++ b/MessageComposer/resources/Base.lproj/Main.storyboard
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MessageComposer/resources/Default-667h@2x~iphone.png b/MessageComposer/resources/Default-667h@2x~iphone.png
deleted file mode 100644
index 54ead7d9..00000000
Binary files a/MessageComposer/resources/Default-667h@2x~iphone.png and /dev/null differ
diff --git a/MessageComposer/resources/Default-736h@3x~iphone.png b/MessageComposer/resources/Default-736h@3x~iphone.png
deleted file mode 100644
index 368bfdf1..00000000
Binary files a/MessageComposer/resources/Default-736h@3x~iphone.png and /dev/null differ
diff --git a/MessageComposer/resources/Icon-72.png b/MessageComposer/resources/Icon-72.png
deleted file mode 100644
index aa9c3f05..00000000
Binary files a/MessageComposer/resources/Icon-72.png and /dev/null differ
diff --git a/MessageComposer/resources/Icon-72@2x.png b/MessageComposer/resources/Icon-72@2x.png
deleted file mode 100644
index 43a08526..00000000
Binary files a/MessageComposer/resources/Icon-72@2x.png and /dev/null differ
diff --git a/MessageComposer/resources/Icon.png b/MessageComposer/resources/Icon.png
deleted file mode 100644
index af4733a5..00000000
Binary files a/MessageComposer/resources/Icon.png and /dev/null differ
diff --git a/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Contents.json b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 00000000..ffa15158
--- /dev/null
+++ b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,80 @@
+{
+ "images" : [
+ {
+ "size" : "29x29",
+ "idiom" : "iphone",
+ "filename" : "Icon-Small@2x-1.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "29x29",
+ "idiom" : "iphone",
+ "filename" : "Icon-Small@3x.png",
+ "scale" : "3x"
+ },
+ {
+ "size" : "40x40",
+ "idiom" : "iphone",
+ "filename" : "Icon-Small-40@2x-1.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "40x40",
+ "idiom" : "iphone",
+ "filename" : "Icon-Small-40@3x.png",
+ "scale" : "3x"
+ },
+ {
+ "size" : "60x60",
+ "idiom" : "iphone",
+ "filename" : "Icon-60@2x.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "60x60",
+ "idiom" : "iphone",
+ "filename" : "Icon-60@3x.png",
+ "scale" : "3x"
+ },
+ {
+ "size" : "29x29",
+ "idiom" : "ipad",
+ "filename" : "Icon-Small.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "29x29",
+ "idiom" : "ipad",
+ "filename" : "Icon-Small@2x.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "40x40",
+ "idiom" : "ipad",
+ "filename" : "Icon-Small-40.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "40x40",
+ "idiom" : "ipad",
+ "filename" : "Icon-Small-40@2x.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "76x76",
+ "idiom" : "ipad",
+ "filename" : "Icon-76.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "76x76",
+ "idiom" : "ipad",
+ "filename" : "Icon-76@2x.png",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+}
\ No newline at end of file
diff --git a/MessageComposer/resources/Icon-60@2x.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png
similarity index 100%
rename from MessageComposer/resources/Icon-60@2x.png
rename to MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png
diff --git a/MessageComposer/resources/Icon-60@3x.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png
similarity index 100%
rename from MessageComposer/resources/Icon-60@3x.png
rename to MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png
diff --git a/MessageComposer/resources/Icon-76.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-76.png
similarity index 100%
rename from MessageComposer/resources/Icon-76.png
rename to MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-76.png
diff --git a/MessageComposer/resources/Icon-76@2x.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-76@2x.png
similarity index 100%
rename from MessageComposer/resources/Icon-76@2x.png
rename to MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-76@2x.png
diff --git a/MessageComposer/resources/Icon-Small-40.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40.png
similarity index 100%
rename from MessageComposer/resources/Icon-Small-40.png
rename to MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40.png
diff --git a/MessageComposer/resources/Icon-Small-40@2x.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x-1.png
similarity index 100%
rename from MessageComposer/resources/Icon-Small-40@2x.png
rename to MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x-1.png
diff --git a/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png
new file mode 100644
index 00000000..8db82b0f
Binary files /dev/null and b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png differ
diff --git a/MessageComposer/resources/Icon-Small-40@3x.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png
similarity index 100%
rename from MessageComposer/resources/Icon-Small-40@3x.png
rename to MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png
diff --git a/MessageComposer/resources/Icon-Small.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small.png
similarity index 100%
rename from MessageComposer/resources/Icon-Small.png
rename to MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small.png
diff --git a/MessageComposer/resources/Icon-Small@2x.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small@2x-1.png
similarity index 100%
rename from MessageComposer/resources/Icon-Small@2x.png
rename to MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small@2x-1.png
diff --git a/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small@2x.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small@2x.png
new file mode 100644
index 00000000..6f9e1565
Binary files /dev/null and b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small@2x.png differ
diff --git a/MessageComposer/resources/Icon-Small@3x.png b/MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small@3x.png
similarity index 100%
rename from MessageComposer/resources/Icon-Small@3x.png
rename to MessageComposer/resources/Images.xcassets/AppIcon.appiconset/Icon-Small@3x.png
diff --git a/MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Contents.json b/MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Contents.json
new file mode 100644
index 00000000..5379aae6
--- /dev/null
+++ b/MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Contents.json
@@ -0,0 +1,57 @@
+{
+ "images" : [
+ {
+ "orientation" : "portrait",
+ "idiom" : "iphone",
+ "extent" : "full-screen",
+ "minimum-system-version" : "7.0",
+ "filename" : "Default@2x~iphone.png",
+ "scale" : "2x"
+ },
+ {
+ "extent" : "full-screen",
+ "idiom" : "iphone",
+ "subtype" : "retina4",
+ "filename" : "Default-568h@2x~iphone.png",
+ "minimum-system-version" : "7.0",
+ "orientation" : "portrait",
+ "scale" : "2x"
+ },
+ {
+ "orientation" : "portrait",
+ "idiom" : "ipad",
+ "extent" : "full-screen",
+ "minimum-system-version" : "7.0",
+ "filename" : "Default-Portrait~ipad.png",
+ "scale" : "1x"
+ },
+ {
+ "orientation" : "landscape",
+ "idiom" : "ipad",
+ "extent" : "full-screen",
+ "minimum-system-version" : "7.0",
+ "filename" : "Default-Landscape~ipad.png",
+ "scale" : "1x"
+ },
+ {
+ "orientation" : "portrait",
+ "idiom" : "ipad",
+ "extent" : "full-screen",
+ "minimum-system-version" : "7.0",
+ "filename" : "Default-Portrait@2x~ipad.png",
+ "scale" : "2x"
+ },
+ {
+ "orientation" : "landscape",
+ "idiom" : "ipad",
+ "extent" : "full-screen",
+ "minimum-system-version" : "7.0",
+ "filename" : "Default-Landscape@2x~ipad.png",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+}
\ No newline at end of file
diff --git a/MessageComposer/resources/Default-568h@2x~iphone.png b/MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default-568h@2x~iphone.png
similarity index 100%
rename from MessageComposer/resources/Default-568h@2x~iphone.png
rename to MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default-568h@2x~iphone.png
diff --git a/MessageComposer/resources/Default-Landscape@2x~ipad.png b/MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default-Landscape@2x~ipad.png
similarity index 100%
rename from MessageComposer/resources/Default-Landscape@2x~ipad.png
rename to MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default-Landscape@2x~ipad.png
diff --git a/MessageComposer/resources/Default-Landscape~ipad.png b/MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default-Landscape~ipad.png
similarity index 100%
rename from MessageComposer/resources/Default-Landscape~ipad.png
rename to MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default-Landscape~ipad.png
diff --git a/MessageComposer/resources/Default-Portrait@2x~ipad.png b/MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default-Portrait@2x~ipad.png
similarity index 100%
rename from MessageComposer/resources/Default-Portrait@2x~ipad.png
rename to MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default-Portrait@2x~ipad.png
diff --git a/MessageComposer/resources/Default-Portrait~ipad.png b/MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default-Portrait~ipad.png
similarity index 100%
rename from MessageComposer/resources/Default-Portrait~ipad.png
rename to MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default-Portrait~ipad.png
diff --git a/MessageComposer/resources/Default@2x~iphone.png b/MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default@2x~iphone.png
similarity index 100%
rename from MessageComposer/resources/Default@2x~iphone.png
rename to MessageComposer/resources/Images.xcassets/LaunchImage.launchimage/Default@2x~iphone.png
diff --git a/MessageComposer/robovm.xml b/MessageComposer/robovm.xml
index ff8de0ce..73876651 100644
--- a/MessageComposer/robovm.xml
+++ b/MessageComposer/robovm.xml
@@ -10,7 +10,4 @@
ios
Info.plist.xml
-
- MessageUI
-
\ No newline at end of file
diff --git a/MessageComposer/src/main/java/org/robovm/samples/messagecomposer/MessageComposer.java b/MessageComposer/src/main/java/org/robovm/samples/messagecomposer/MessageComposer.java
index 68d09dbf..fe3fafc2 100644
--- a/MessageComposer/src/main/java/org/robovm/samples/messagecomposer/MessageComposer.java
+++ b/MessageComposer/src/main/java/org/robovm/samples/messagecomposer/MessageComposer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 RoboVM AB
+ * Copyright (C) 2013-2015 RoboVM AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,42 +16,23 @@
* Portions of this code is based on Apple Inc's MessageComposer sample (v1.2)
* which is copyright (C) 2010-2013 Apple Inc.
*/
-
package org.robovm.samples.messagecomposer;
import org.robovm.apple.foundation.NSAutoreleasePool;
import org.robovm.apple.uikit.UIApplication;
import org.robovm.apple.uikit.UIApplicationDelegateAdapter;
-import org.robovm.apple.uikit.UIScreen;
-import org.robovm.apple.uikit.UIWindow;
-import org.robovm.samples.messagecomposer.viewcontrollers.MessageComposerViewController;
+import org.robovm.apple.uikit.UIApplicationLaunchOptions;
public class MessageComposer extends UIApplicationDelegateAdapter {
- private UIWindow window;
- private MessageComposerViewController viewController;
@Override
- public void didFinishLaunching (UIApplication application) {
- // Set up the view controller.
- viewController = new MessageComposerViewController();
-
- // Create a new window at screen size.
- window = new UIWindow(UIScreen.getMainScreen().getBounds());
- // Set our viewcontroller as the root controller for the window.
- window.setRootViewController(viewController);
- // Make the window visible.
- window.makeKeyAndVisible();
-
- /*
- * Retains the window object until the application is deallocated. Prevents Java GC from collecting the window object too
- * early.
- */
- addStrongRef(window);
+ public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) {
+ return true;
}
- public static void main (String[] args) {
- NSAutoreleasePool pool = new NSAutoreleasePool();
- UIApplication.main(args, null, MessageComposer.class);
- pool.close();
+ public static void main(String[] args) {
+ try (NSAutoreleasePool pool = new NSAutoreleasePool()) {
+ UIApplication.main(args, null, MessageComposer.class);
+ }
}
}
diff --git a/MessageComposer/src/main/java/org/robovm/samples/messagecomposer/ui/MessageComposerViewController.java b/MessageComposer/src/main/java/org/robovm/samples/messagecomposer/ui/MessageComposerViewController.java
new file mode 100644
index 00000000..a7fee4cc
--- /dev/null
+++ b/MessageComposer/src/main/java/org/robovm/samples/messagecomposer/ui/MessageComposerViewController.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright (C) 2013-2015 RoboVM AB
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Portions of this code is based on Apple Inc's MessageComposer sample (v1.2)
+ * which is copyright (C) 2010-2013 Apple Inc.
+ */
+package org.robovm.samples.messagecomposer.ui;
+
+import java.io.File;
+import java.util.Arrays;
+
+import org.robovm.apple.foundation.NSBundle;
+import org.robovm.apple.foundation.NSData;
+import org.robovm.apple.foundation.NSError;
+import org.robovm.apple.messageui.MFMailComposeResult;
+import org.robovm.apple.messageui.MFMailComposeViewController;
+import org.robovm.apple.messageui.MFMailComposeViewControllerDelegate;
+import org.robovm.apple.messageui.MFMessageComposeViewController;
+import org.robovm.apple.messageui.MFMessageComposeViewControllerDelegate;
+import org.robovm.apple.messageui.MessageComposeResult;
+import org.robovm.apple.uikit.UILabel;
+import org.robovm.apple.uikit.UIViewController;
+import org.robovm.objc.annotation.CustomClass;
+import org.robovm.objc.annotation.IBAction;
+import org.robovm.objc.annotation.IBOutlet;
+
+@CustomClass("MessageComposerViewController")
+public class MessageComposerViewController extends UIViewController implements MFMailComposeViewControllerDelegate,
+ MFMessageComposeViewControllerDelegate {
+ /* UILabel for displaying the result of sending the message. */
+ private UILabel feedbackMsg;
+
+ @IBAction
+ private void showMailPicker() {
+ /*
+ * You must check that the current device can send email messages before
+ * you attempt to create an instance of MFMailComposeViewController.
+ * Otherwise your app will crash when it creates a new
+ * MFMailComposeViewController.
+ */
+ if (MFMailComposeViewController.canSendMail()) {
+ // The device can send email.
+ displayMailComposerSheet();
+ } else {
+ // The device can not send email.
+ feedbackMsg.setHidden(false);
+ feedbackMsg.setText("Device not configured to send mail.");
+ }
+ }
+
+ @IBAction
+ private void showSMSPicker() {
+ /*
+ * You must check that the current device can send SMS messages before
+ * you attempt to create an instance of MFMessageComposeViewController.
+ * Otherwise your app will crash when it creates a new
+ * MFMessageComposeViewController.
+ */
+ if (MFMessageComposeViewController.canSendText()) {
+ // The device can send SMS.
+ displaySMSComposerSheet();
+ } else {
+ // The device can not send email.
+ feedbackMsg.setHidden(false);
+ feedbackMsg.setText("Device not configured to send SMS.");
+ }
+ }
+
+ /**
+ * Displays an email composition interface inside the application. Populates
+ * all the Mail fields.
+ */
+ private void displayMailComposerSheet() {
+ MFMailComposeViewController picker = new MFMailComposeViewController();
+ picker.setMailComposeDelegate(this);
+ picker.setSubject("Hello from California!");
+
+ // Set up recipients
+ picker.setToRecipients(Arrays.asList("first@example.com"));
+ picker.setCcRecipients(Arrays.asList("second@example.com", "third@example.com"));
+ picker.setBccRecipients(Arrays.asList("fourth@example.com"));
+
+ // Attach an image to the email
+ String path = NSBundle.getMainBundle().findResourcePath("rainy", "jpg");
+ NSData myData = NSData.read(new File(path));
+ picker.addAttachmentData(myData, "image/jpeg", "rainy");
+
+ // Fill out the email body text
+ String emailBody = "It is raining in sunny California!";
+ picker.setMessageBody(emailBody, false);
+
+ presentViewController(picker, true, null);
+ }
+
+ /** Displays an SMS composition interface inside the application. */
+ private void displaySMSComposerSheet() {
+ MFMessageComposeViewController picker = new MFMessageComposeViewController();
+ picker.setMessageComposeDelegate(this);
+ /*
+ * You can specify one or more preconfigured recipients. The user has
+ * the option to remove or add recipients from the message composer view
+ * controller.
+ */
+ /* picker.setRecipients(NSArray.toNSArray("Phone number here")); */
+
+ /*
+ * You can specify the initial message text that will appear in the
+ * message composer view controller.
+ */
+ picker.setBody("Hello from California!");
+
+ presentViewController(picker, true, null);
+ }
+
+ @IBOutlet
+ private void setFeedbackMsg(UILabel feedbackMsg) {
+ this.feedbackMsg = feedbackMsg;
+ }
+
+ /**
+ * Dismisses the email composition interface when users tap Cancel or Send.
+ * Proceeds to update the message field with the result of the operation.
+ */
+ @Override
+ public void didFinish(MFMailComposeViewController controller, MFMailComposeResult result, NSError error) {
+ feedbackMsg.setHidden(false);
+
+ // Notifies users about errors associated with the interface
+ String resultText;
+ switch (result) {
+ case Cancelled:
+ resultText = "Result: Mail sending canceled";
+ break;
+ case Saved:
+ resultText = "Result: Mail saved";
+ break;
+ case Sent:
+ resultText = "Result: Mail sent";
+ break;
+ case Failed:
+ resultText = "Result: Mail sending failed";
+ break;
+ default:
+ resultText = "Result: Mail not sent";
+ break;
+ }
+ feedbackMsg.setText(resultText);
+
+ dismissViewController(true, null);
+ }
+
+ /**
+ * Dismisses the message composition interface when users tap Cancel or
+ * Send. Proceeds to update the feedback message field with the result of
+ * the operation.
+ */
+ @Override
+ public void didFinish(MFMessageComposeViewController controller, MessageComposeResult result) {
+ feedbackMsg.setHidden(false);
+
+ String resultText;
+ // Notifies users about errors associated with the interface
+ switch (result) {
+ case Cancelled:
+ resultText = "Result: SMS sending canceled";
+ break;
+ case Sent:
+ resultText = "Result: SMS sent";
+ break;
+ case Failed:
+ resultText = "Result: SMS sending failed";
+ break;
+ default:
+ resultText = "Result: SMS not sent";
+ break;
+ }
+ feedbackMsg.setText(resultText);
+
+ dismissViewController(true, null);
+ }
+}
diff --git a/MessageComposer/src/main/java/org/robovm/samples/messagecomposer/viewcontrollers/MessageComposerViewController.java b/MessageComposer/src/main/java/org/robovm/samples/messagecomposer/viewcontrollers/MessageComposerViewController.java
deleted file mode 100644
index b4850bab..00000000
--- a/MessageComposer/src/main/java/org/robovm/samples/messagecomposer/viewcontrollers/MessageComposerViewController.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright (C) 2014 RoboVM AB
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Portions of this code is based on Apple Inc's MessageComposer sample (v1.2)
- * which is copyright (C) 2010-2013 Apple Inc.
- */
-
-package org.robovm.samples.messagecomposer.viewcontrollers;
-
-import java.io.File;
-import java.util.Arrays;
-
-import org.robovm.apple.coregraphics.CGRect;
-import org.robovm.apple.foundation.NSBundle;
-import org.robovm.apple.foundation.NSData;
-import org.robovm.apple.foundation.NSError;
-import org.robovm.apple.messageui.MFMailComposeResult;
-import org.robovm.apple.messageui.MFMailComposeViewController;
-import org.robovm.apple.messageui.MFMailComposeViewControllerDelegateAdapter;
-import org.robovm.apple.messageui.MFMessageComposeViewController;
-import org.robovm.apple.messageui.MFMessageComposeViewControllerDelegateAdapter;
-import org.robovm.apple.messageui.MessageComposeResult;
-import org.robovm.apple.uikit.NSLineBreakMode;
-import org.robovm.apple.uikit.NSTextAlignment;
-import org.robovm.apple.uikit.UIButton;
-import org.robovm.apple.uikit.UIButtonType;
-import org.robovm.apple.uikit.UIColor;
-import org.robovm.apple.uikit.UIControl;
-import org.robovm.apple.uikit.UIControlState;
-import org.robovm.apple.uikit.UIEvent;
-import org.robovm.apple.uikit.UIFont;
-import org.robovm.apple.uikit.UIInterfaceOrientation;
-import org.robovm.apple.uikit.UILabel;
-import org.robovm.apple.uikit.UIView;
-import org.robovm.apple.uikit.UIViewController;
-
-public class MessageComposerViewController extends UIViewController {
- /* UILabel for displaying the result of sending the message. */
- private final UILabel feedbackMsg;
-
- public MessageComposerViewController () {
- UIView view = getView();
- view.setBackgroundColor(UIColor.fromWhiteAlpha(0.75, 1));
-
- UIButton mailButton = UIButton.create(UIButtonType.RoundedRect);
- mailButton.setFrame(new CGRect(20, 197, 135, 37));
- mailButton.getTitleLabel().setFont(UIFont.getSystemFont(15));
- mailButton.setTitle("Compose Mail", UIControlState.Normal);
- mailButton.setTitleColor(UIColor.fromRGBA(0.19, 0.30, 0.52, 1), UIControlState.Normal);
- mailButton.setTitleShadowColor(UIColor.fromWhiteAlpha(0, 1), UIControlState.Normal);
- mailButton.setTitleColor(UIColor.fromRGBA(1, 1, 1, 1), UIControlState.Highlighted);
- mailButton.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener() {
- @Override
- public void onTouchUpInside (UIControl control, UIEvent event) {
- showMailPicker();
- }
- });
- view.addSubview(mailButton);
-
- UIButton smsButton = UIButton.create(UIButtonType.RoundedRect);
- smsButton.setFrame(new CGRect(163, 197, 137, 37));
- smsButton.getTitleLabel().setFont(UIFont.getSystemFont(15));
- smsButton.setTitle("Compose SMS", UIControlState.Normal);
- smsButton.setTitleColor(UIColor.fromRGBA(0.19, 0.30, 0.52, 1), UIControlState.Normal);
- smsButton.setTitleShadowColor(UIColor.fromWhiteAlpha(0, 1), UIControlState.Normal);
- smsButton.setTitleColor(UIColor.fromRGBA(1, 1, 1, 1), UIControlState.Highlighted);
- smsButton.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener() {
- @Override
- public void onTouchUpInside (UIControl control, UIEvent event) {
- showSMSPicker();
- }
- });
- view.addSubview(smsButton);
-
- feedbackMsg = new UILabel(new CGRect(20, 269, 280, 117));
- feedbackMsg.setTextAlignment(NSTextAlignment.Center);
- feedbackMsg.setLineBreakMode(NSLineBreakMode.TruncatingTail);
- feedbackMsg.setNumberOfLines(7);
- feedbackMsg.setFont(UIFont.getSystemFont(15));
- feedbackMsg.setTextColor(UIColor.darkText());
- view.addSubview(feedbackMsg);
- }
-
- @Override
- public boolean shouldAutorotate (UIInterfaceOrientation toInterfaceOrientation) {
- return toInterfaceOrientation == UIInterfaceOrientation.Portrait;
- }
-
- private void showMailPicker () {
- /*
- * You must check that the current device can send email messages before you attempt to create an instance of
- * MFMailComposeViewController. Otherwise your app will crash when it creates a new MFMailComposeViewController.
- */
- if (MFMailComposeViewController.canSendMail()) {
- // The device can send email.
- displayMailComposerSheet();
- } else {
- // The device can not send email.
- feedbackMsg.setHidden(false);
- feedbackMsg.setText("Device not configured to send mail.");
- }
- }
-
- private void showSMSPicker () {
- /*
- * You must check that the current device can send SMS messages before you attempt to create an instance of
- * MFMessageComposeViewController. Otherwise your app will crash when it creates a new MFMessageComposeViewController.
- */
- if (MFMessageComposeViewController.canSendText()) {
- // The device can send SMS.
- displaySMSComposerSheet();
- } else {
- // The device can not send email.
- feedbackMsg.setHidden(false);
- feedbackMsg.setText("Device not configured to send SMS.");
- }
- }
-
- /** Displays an email composition interface inside the application. Populates all the Mail fields. */
- private void displayMailComposerSheet () {
- MFMailComposeViewController picker = new MFMailComposeViewController();
- picker.setMailComposeDelegate(new MFMailComposeViewControllerDelegateAdapter() {
- /** Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with
- * the result of the operation. */
- @Override
- public void didFinish (MFMailComposeViewController controller, MFMailComposeResult result, NSError error) {
- feedbackMsg.setHidden(false);
-
- // Notifies users about errors associated with the interface
- String resultText;
- switch (result) {
- case Cancelled:
- resultText = "Result: Mail sending canceled";
- break;
- case Saved:
- resultText = "Result: Mail saved";
- break;
- case Sent:
- resultText = "Result: Mail sent";
- break;
- case Failed:
- resultText = "Result: Mail sending failed";
- break;
- default:
- resultText = "Result: Mail not sent";
- break;
- }
- feedbackMsg.setText(resultText);
-
- dismissViewController(true, null);
- }
- });
- picker.setSubject("Hello from California!");
-
- // Set up recipients
- picker.setToRecipients(Arrays.asList("first@example.com"));
- picker.setCcRecipients(Arrays.asList("second@example.com", "third@example.com"));
- picker.setBccRecipients(Arrays.asList("fourth@example.com"));
-
- // Attach an image to the email
- String path = NSBundle.getMainBundle().findResourcePath("rainy", "jpg");
- NSData myData = NSData.read(new File(path));
- picker.addAttachmentData(myData, "image/jpeg", "rainy");
-
- // Fill out the email body text
- String emailBody = "It is raining in sunny California!";
- picker.setMessageBody(emailBody, false);
-
- presentViewController(picker, true, null);
- }
-
- /** Displays an SMS composition interface inside the application. */
- private void displaySMSComposerSheet () {
- MFMessageComposeViewController picker = new MFMessageComposeViewController();
- picker.setMessageComposeDelegate(new MFMessageComposeViewControllerDelegateAdapter() {
- /** Dismisses the message composition interface when users tap Cancel or Send. Proceeds to update the feedback message
- * field with the result of the operation. */
- @Override
- public void didFinish (MFMessageComposeViewController controller, MessageComposeResult result) {
- feedbackMsg.setHidden(false);
-
- String resultText;
- // Notifies users about errors associated with the interface
- switch (result) {
- case Cancelled:
- resultText = "Result: SMS sending canceled";
- break;
- case Sent:
- resultText = "Result: SMS sent";
- break;
- case Failed:
- resultText = "Result: SMS sending failed";
- break;
- default:
- resultText = "Result: SMS not sent";
- break;
- }
- feedbackMsg.setText(resultText);
-
- dismissViewController(true, null);
- }
- });
- /*
- * You can specify one or more preconfigured recipients. The user has the option to remove or add recipients from the
- * message composer view controller.
- */
- /* picker.setRecipients(NSArray.toNSArray("Phone number here")); */
-
- /*
- * You can specify the initial message text that will appear in the message composer view controller.
- */
- picker.setBody("Hello from California!");
-
- presentViewController(picker, true, null);
- }
-}