diff --git a/Tabster-no-ib/Info.plist.xml b/Tabster-no-ib/Info.plist.xml new file mode 100644 index 00000000..c2956aaf --- /dev/null +++ b/Tabster-no-ib/Info.plist.xml @@ -0,0 +1,77 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${app.name} + CFBundleExecutable + ${app.executable} + CFBundleIdentifier + ${app.id} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${app.name} + CFBundlePackageType + APPL + CFBundleShortVersionString + ${app.version} + CFBundleSignature + ???? + CFBundleVersion + ${app.build} + LSRequiresIPhoneOS + + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + armv7 + + 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/Tabster-no-ib/build.gradle b/Tabster-no-ib/build.gradle new file mode 100644 index 00000000..6b8ee386 --- /dev/null +++ b/Tabster-no-ib/build.gradle @@ -0,0 +1,3 @@ +ext { + mainClassName = "org.robovm.samples.tabster.Tabster" +} \ No newline at end of file diff --git a/Tabster-no-ib/pom.xml b/Tabster-no-ib/pom.xml new file mode 100644 index 00000000..b4b28993 --- /dev/null +++ b/Tabster-no-ib/pom.xml @@ -0,0 +1,32 @@ + + + + 4.0.0 + + + org.robovm + robovm-samples-parent + 1.0 + + + robovm-samples-tabster-no-ib + RoboVM port of Apple's Tabster sample without storyboards + + jar + + + src/main/java + + + + + org.robovm + robovm-rt + + + org.robovm + robovm-cocoatouch + + + \ No newline at end of file diff --git a/Tabster/resources/Default-568h@2x~iphone.png b/Tabster-no-ib/resources/Default-568h@2x~iphone.png similarity index 100% rename from Tabster/resources/Default-568h@2x~iphone.png rename to Tabster-no-ib/resources/Default-568h@2x~iphone.png diff --git a/Tabster/resources/Default-667h@2x~iphone.png b/Tabster-no-ib/resources/Default-667h@2x~iphone.png similarity index 100% rename from Tabster/resources/Default-667h@2x~iphone.png rename to Tabster-no-ib/resources/Default-667h@2x~iphone.png diff --git a/Tabster/resources/Default-736h@3x~iphone.png b/Tabster-no-ib/resources/Default-736h@3x~iphone.png similarity index 100% rename from Tabster/resources/Default-736h@3x~iphone.png rename to Tabster-no-ib/resources/Default-736h@3x~iphone.png diff --git a/Tabster/resources/Default-Landscape@2x~ipad.png b/Tabster-no-ib/resources/Default-Landscape@2x~ipad.png similarity index 100% rename from Tabster/resources/Default-Landscape@2x~ipad.png rename to Tabster-no-ib/resources/Default-Landscape@2x~ipad.png diff --git a/Tabster/resources/Default-Landscape~ipad.png b/Tabster-no-ib/resources/Default-Landscape~ipad.png similarity index 100% rename from Tabster/resources/Default-Landscape~ipad.png rename to Tabster-no-ib/resources/Default-Landscape~ipad.png diff --git a/Tabster/resources/Default-Portrait@2x~ipad.png b/Tabster-no-ib/resources/Default-Portrait@2x~ipad.png similarity index 100% rename from Tabster/resources/Default-Portrait@2x~ipad.png rename to Tabster-no-ib/resources/Default-Portrait@2x~ipad.png diff --git a/Tabster/resources/Default-Portrait~ipad.png b/Tabster-no-ib/resources/Default-Portrait~ipad.png similarity index 100% rename from Tabster/resources/Default-Portrait~ipad.png rename to Tabster-no-ib/resources/Default-Portrait~ipad.png diff --git a/Tabster/resources/Default@2x~iphone.png b/Tabster-no-ib/resources/Default@2x~iphone.png similarity index 100% rename from Tabster/resources/Default@2x~iphone.png rename to Tabster-no-ib/resources/Default@2x~iphone.png diff --git a/Tabster/resources/Icon-60@2x.png b/Tabster-no-ib/resources/Icon-60@2x.png similarity index 100% rename from Tabster/resources/Icon-60@2x.png rename to Tabster-no-ib/resources/Icon-60@2x.png diff --git a/Tabster/resources/Icon-60@3x.png b/Tabster-no-ib/resources/Icon-60@3x.png similarity index 100% rename from Tabster/resources/Icon-60@3x.png rename to Tabster-no-ib/resources/Icon-60@3x.png diff --git a/Tabster/resources/Icon-72.png b/Tabster-no-ib/resources/Icon-72.png similarity index 100% rename from Tabster/resources/Icon-72.png rename to Tabster-no-ib/resources/Icon-72.png diff --git a/Tabster/resources/Icon-72@2x.png b/Tabster-no-ib/resources/Icon-72@2x.png similarity index 100% rename from Tabster/resources/Icon-72@2x.png rename to Tabster-no-ib/resources/Icon-72@2x.png diff --git a/Tabster/resources/Icon-76.png b/Tabster-no-ib/resources/Icon-76.png similarity index 100% rename from Tabster/resources/Icon-76.png rename to Tabster-no-ib/resources/Icon-76.png diff --git a/Tabster/resources/Icon-76@2x.png b/Tabster-no-ib/resources/Icon-76@2x.png similarity index 100% rename from Tabster/resources/Icon-76@2x.png rename to Tabster-no-ib/resources/Icon-76@2x.png diff --git a/Tabster/resources/Icon-Small-40.png b/Tabster-no-ib/resources/Icon-Small-40.png similarity index 100% rename from Tabster/resources/Icon-Small-40.png rename to Tabster-no-ib/resources/Icon-Small-40.png diff --git a/Tabster/resources/Icon-Small-40@2x.png b/Tabster-no-ib/resources/Icon-Small-40@2x.png similarity index 100% rename from Tabster/resources/Icon-Small-40@2x.png rename to Tabster-no-ib/resources/Icon-Small-40@2x.png diff --git a/Tabster/resources/Icon-Small-40@3x.png b/Tabster-no-ib/resources/Icon-Small-40@3x.png similarity index 100% rename from Tabster/resources/Icon-Small-40@3x.png rename to Tabster-no-ib/resources/Icon-Small-40@3x.png diff --git a/Tabster/resources/Icon-Small.png b/Tabster-no-ib/resources/Icon-Small.png similarity index 100% rename from Tabster/resources/Icon-Small.png rename to Tabster-no-ib/resources/Icon-Small.png diff --git a/Tabster/resources/Icon-Small@2x.png b/Tabster-no-ib/resources/Icon-Small@2x.png similarity index 100% rename from Tabster/resources/Icon-Small@2x.png rename to Tabster-no-ib/resources/Icon-Small@2x.png diff --git a/Tabster/resources/Icon-Small@3x.png b/Tabster-no-ib/resources/Icon-Small@3x.png similarity index 100% rename from Tabster/resources/Icon-Small@3x.png rename to Tabster-no-ib/resources/Icon-Small@3x.png diff --git a/Tabster/resources/Icon.png b/Tabster-no-ib/resources/Icon.png similarity index 100% rename from Tabster/resources/Icon.png rename to Tabster-no-ib/resources/Icon.png diff --git a/Tabster-no-ib/resources/Images.xcassets/cherrylake.imageset/Contents.json b/Tabster-no-ib/resources/Images.xcassets/cherrylake.imageset/Contents.json new file mode 100644 index 00000000..c6454aab --- /dev/null +++ b/Tabster-no-ib/resources/Images.xcassets/cherrylake.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "cherrylake.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "cherrylake@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Tabster-no-ib/resources/Images.xcassets/cherrylake.imageset/cherrylake.png b/Tabster-no-ib/resources/Images.xcassets/cherrylake.imageset/cherrylake.png new file mode 100644 index 00000000..5aae0f49 Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/cherrylake.imageset/cherrylake.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/cherrylake.imageset/cherrylake@2x.png b/Tabster-no-ib/resources/Images.xcassets/cherrylake.imageset/cherrylake@2x.png new file mode 100644 index 00000000..0c71e75d Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/cherrylake.imageset/cherrylake@2x.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/lakedonpedro.imageset/Contents.json b/Tabster-no-ib/resources/Images.xcassets/lakedonpedro.imageset/Contents.json new file mode 100644 index 00000000..aa11fe4a --- /dev/null +++ b/Tabster-no-ib/resources/Images.xcassets/lakedonpedro.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "lakedonpedro.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "lakedonpedro@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Tabster-no-ib/resources/Images.xcassets/lakedonpedro.imageset/lakedonpedro.png b/Tabster-no-ib/resources/Images.xcassets/lakedonpedro.imageset/lakedonpedro.png new file mode 100644 index 00000000..6c58ebad Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/lakedonpedro.imageset/lakedonpedro.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/lakedonpedro.imageset/lakedonpedro@2x.png b/Tabster-no-ib/resources/Images.xcassets/lakedonpedro.imageset/lakedonpedro@2x.png new file mode 100644 index 00000000..30ec1e37 Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/lakedonpedro.imageset/lakedonpedro@2x.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/left.imageset/Contents.json b/Tabster-no-ib/resources/Images.xcassets/left.imageset/Contents.json new file mode 100644 index 00000000..bc628230 --- /dev/null +++ b/Tabster-no-ib/resources/Images.xcassets/left.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "left.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "left@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Tabster-no-ib/resources/Images.xcassets/left.imageset/left.png b/Tabster-no-ib/resources/Images.xcassets/left.imageset/left.png new file mode 100644 index 00000000..7f2bfa98 Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/left.imageset/left.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/left.imageset/left@2x.png b/Tabster-no-ib/resources/Images.xcassets/left.imageset/left@2x.png new file mode 100644 index 00000000..92ec8d17 Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/left.imageset/left@2x.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/left_pressed.imageset/Contents.json b/Tabster-no-ib/resources/Images.xcassets/left_pressed.imageset/Contents.json new file mode 100644 index 00000000..63dfee77 --- /dev/null +++ b/Tabster-no-ib/resources/Images.xcassets/left_pressed.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "left_pressed.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "left_pressed@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Tabster-no-ib/resources/Images.xcassets/left_pressed.imageset/left_pressed.png b/Tabster-no-ib/resources/Images.xcassets/left_pressed.imageset/left_pressed.png new file mode 100644 index 00000000..bb4bd5dd Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/left_pressed.imageset/left_pressed.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/left_pressed.imageset/left_pressed@2x.png b/Tabster-no-ib/resources/Images.xcassets/left_pressed.imageset/left_pressed@2x.png new file mode 100644 index 00000000..23bc54b2 Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/left_pressed.imageset/left_pressed@2x.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/tab1.imageset/Contents.json b/Tabster-no-ib/resources/Images.xcassets/tab1.imageset/Contents.json new file mode 100644 index 00000000..2fc4e153 --- /dev/null +++ b/Tabster-no-ib/resources/Images.xcassets/tab1.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "tab1.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "tab1@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Tabster-no-ib/resources/Images.xcassets/tab1.imageset/tab1.png b/Tabster-no-ib/resources/Images.xcassets/tab1.imageset/tab1.png new file mode 100644 index 00000000..f06666ea Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/tab1.imageset/tab1.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/tab1.imageset/tab1@2x.png b/Tabster-no-ib/resources/Images.xcassets/tab1.imageset/tab1@2x.png new file mode 100644 index 00000000..fe40031a Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/tab1.imageset/tab1@2x.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/tab2.imageset/Contents.json b/Tabster-no-ib/resources/Images.xcassets/tab2.imageset/Contents.json new file mode 100644 index 00000000..b07a0b76 --- /dev/null +++ b/Tabster-no-ib/resources/Images.xcassets/tab2.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "tab2.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "tab2@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Tabster-no-ib/resources/Images.xcassets/tab2.imageset/tab2.png b/Tabster-no-ib/resources/Images.xcassets/tab2.imageset/tab2.png new file mode 100644 index 00000000..db0d2fbb Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/tab2.imageset/tab2.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/tab2.imageset/tab2@2x.png b/Tabster-no-ib/resources/Images.xcassets/tab2.imageset/tab2@2x.png new file mode 100644 index 00000000..ebe332b3 Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/tab2.imageset/tab2@2x.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/tab3.imageset/Contents.json b/Tabster-no-ib/resources/Images.xcassets/tab3.imageset/Contents.json new file mode 100644 index 00000000..3af34cc8 --- /dev/null +++ b/Tabster-no-ib/resources/Images.xcassets/tab3.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "tab3.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "tab3@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Tabster-no-ib/resources/Images.xcassets/tab3.imageset/tab3.png b/Tabster-no-ib/resources/Images.xcassets/tab3.imageset/tab3.png new file mode 100644 index 00000000..d30e813d Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/tab3.imageset/tab3.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/tab3.imageset/tab3@2x.png b/Tabster-no-ib/resources/Images.xcassets/tab3.imageset/tab3@2x.png new file mode 100644 index 00000000..6e29a006 Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/tab3.imageset/tab3@2x.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/tab4.imageset/Contents.json b/Tabster-no-ib/resources/Images.xcassets/tab4.imageset/Contents.json new file mode 100644 index 00000000..b43a7e16 --- /dev/null +++ b/Tabster-no-ib/resources/Images.xcassets/tab4.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "tab4.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "tab4@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Tabster-no-ib/resources/Images.xcassets/tab4.imageset/tab4.png b/Tabster-no-ib/resources/Images.xcassets/tab4.imageset/tab4.png new file mode 100644 index 00000000..662caa58 Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/tab4.imageset/tab4.png differ diff --git a/Tabster-no-ib/resources/Images.xcassets/tab4.imageset/tab4@2x.png b/Tabster-no-ib/resources/Images.xcassets/tab4.imageset/tab4@2x.png new file mode 100644 index 00000000..92658514 Binary files /dev/null and b/Tabster-no-ib/resources/Images.xcassets/tab4.imageset/tab4@2x.png differ diff --git a/Tabster-no-ib/robovm.properties b/Tabster-no-ib/robovm.properties new file mode 100644 index 00000000..2908ae44 --- /dev/null +++ b/Tabster-no-ib/robovm.properties @@ -0,0 +1,6 @@ +app.version=1.0 +app.id=org.robovm.samples.tabster +app.mainclass=org.robovm.samples.tabster.Tabster +app.executable=Tabster +app.build=1 +app.name=Tabster \ No newline at end of file diff --git a/Tabster-no-ib/robovm.xml b/Tabster-no-ib/robovm.xml new file mode 100644 index 00000000..73876651 --- /dev/null +++ b/Tabster-no-ib/robovm.xml @@ -0,0 +1,13 @@ + + ${app.executable} + ${app.mainclass} + ios + thumbv7 + + + resources + + + ios + Info.plist.xml + \ No newline at end of file diff --git a/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/Tabster.java b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/Tabster.java new file mode 100644 index 00000000..fc50bb75 --- /dev/null +++ b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/Tabster.java @@ -0,0 +1,238 @@ +/* + * 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 Tabster sample (v1.6) + * which is copyright (C) 2011-2014 Apple Inc. + */ + +package org.robovm.samples.tabster; + +import java.util.ArrayList; +import java.util.List; + +import org.robovm.apple.foundation.Foundation; +import org.robovm.apple.foundation.NSArray; +import org.robovm.apple.foundation.NSAutoreleasePool; +import org.robovm.apple.foundation.NSCoder; +import org.robovm.apple.foundation.NSMutableArray; +import org.robovm.apple.foundation.NSString; +import org.robovm.apple.foundation.NSUserDefaults; +import org.robovm.apple.uikit.UIApplication; +import org.robovm.apple.uikit.UIApplicationDelegateAdapter; +import org.robovm.apple.uikit.UIApplicationLaunchOptions; +import org.robovm.apple.uikit.UIColor; +import org.robovm.apple.uikit.UIImage; +import org.robovm.apple.uikit.UINavigationController; +import org.robovm.apple.uikit.UINavigationControllerDelegateAdapter; +import org.robovm.apple.uikit.UIScreen; +import org.robovm.apple.uikit.UITabBarController; +import org.robovm.apple.uikit.UITabBarItem; +import org.robovm.apple.uikit.UIViewController; +import org.robovm.apple.uikit.UIWindow; +import org.robovm.samples.tabster.viewcontrollers.FavoritesViewController; +import org.robovm.samples.tabster.viewcontrollers.FeaturedViewController; +import org.robovm.samples.tabster.viewcontrollers.FourViewController; +import org.robovm.samples.tabster.viewcontrollers.OneViewController; +import org.robovm.samples.tabster.viewcontrollers.ThreeViewController; +import org.robovm.samples.tabster.viewcontrollers.TwoViewController; + +public class Tabster extends UIApplicationDelegateAdapter { + private static final boolean CUSTOMIZE_TAB_BAR = false; // Turn on/off + // custom tab bar + // appearance + + // NSUserDefaults keys: + private static final String TAB_BAR_ORDER_PREF_KEY = "TabBarOrder"; // The + // ordering + // of + // the + // tabs + + private UIWindow window; + private UITabBarController tabBarController; + + private UINavigationController oneNavController; + private OneViewController oneViewController; + private UINavigationController twoNavController; + private TwoViewController twoViewController; + private UINavigationController threeNavController; + private ThreeViewController threeViewController; + private FourViewController fourViewController; + private FavoritesViewController favoritesViewController; + private FeaturedViewController featuredViewController; + + @SuppressWarnings("unchecked") + @Override + public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) { + // Set up the view controller. + tabBarController = new UITabBarController(); + + // customize the More page's navigation bar color + tabBarController.getMoreNavigationController().getNavigationBar().setTintColor(UIColor.gray()); + + // Adding view controllers. + NSArray viewControllers = new NSMutableArray(); + + oneViewController = new OneViewController(); + oneNavController = new UINavigationController(oneViewController); + oneNavController.setTabBarItem(new UITabBarItem("One", UIImage.create("tab1"), 0)); + viewControllers.add(oneNavController); + + twoViewController = new TwoViewController(); + twoNavController = new UINavigationController(twoViewController); + twoNavController.setTabBarItem(new UITabBarItem("Two", UIImage.create("tab2"), 0)); + viewControllers.add(twoNavController); + + threeViewController = new ThreeViewController(); + threeNavController = new UINavigationController(threeViewController); + threeNavController.setTabBarItem(new UITabBarItem("Three", UIImage.create("tab3"), 0)); + viewControllers.add(threeNavController); + + fourViewController = new FourViewController(); + viewControllers.add(fourViewController); + + favoritesViewController = new FavoritesViewController(); + viewControllers.add(favoritesViewController); + + featuredViewController = new FeaturedViewController(); + viewControllers.add(featuredViewController); + + tabBarController.setViewControllers(viewControllers); + + if (CUSTOMIZE_TAB_BAR) { + // set the bar tint color for iOS 7 and later + if (Foundation.getMajorSystemVersion() >= 7) { + tabBarController.getTabBar().setBarTintColor(UIColor.darkGray()); + } else { + // set the bar tint color for iOS 6 and earlier + tabBarController.getTabBar().setTintColor(UIColor.darkGray()); + } + + tabBarController.getTabBar().setSelectedImageTintColor(UIColor.yellow()); + + // note: + // 1) you can also apply additional custom appearance to UITabBar + // using: + // "backgroundImage" and "selectionIndicatorImage" + // 2) you can also customize the appearance of individual + // UITabBarItems as well. + } + + // restore the tab-order from prefs + NSArray arr = (NSArray) NSUserDefaults.getStandardUserDefaults().getArray( + TAB_BAR_ORDER_PREF_KEY); + + if (arr != null && arr.size() > 0) { + List classNames = arr.asStringList(); + NSArray controllers = new NSMutableArray<>(); + for (String className : classNames) { + for (UIViewController controller : tabBarController.getViewControllers()) { + String controllerClassName = null; + + if (controller instanceof UINavigationController) { + controllerClassName = ((UINavigationController) controller).getTopViewController().getClass() + .getName(); + } else { + controllerClassName = controller.getClass().getName(); + } + + if (className.equals(controllerClassName)) { + controllers.add(controller); + break; + } + } + } + + if (controllers.size() == tabBarController.getViewControllers().size()) { + tabBarController.setViewControllers(controllers); + } + } + + // listen for changes in view controller from the More screen + tabBarController.getMoreNavigationController().setDelegate(new UINavigationControllerDelegateAdapter() { + @Override + public void willShowViewController(UINavigationController navigationController, + UIViewController viewController, + boolean animated) { + if (viewController == tabBarController.getMoreNavigationController().getViewControllers().first()) { + // returned to the More page + } + } + }); + + // choose to make one of our view controllers + // ("FeaturedViewController"), + // not movable/reorderable in More's edit screen + NSArray customizeableViewControllers; + if (tabBarController.getViewControllers() == null) { + customizeableViewControllers = new NSMutableArray<>(); + } else { + customizeableViewControllers = new NSMutableArray<>(tabBarController.getViewControllers()); + } + for (UIViewController viewController : customizeableViewControllers) { + if (viewController instanceof FeaturedViewController) { + customizeableViewControllers.remove(viewController); + break; + } + } + tabBarController.setCustomizableViewControllers(customizeableViewControllers); + + // 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(tabBarController); + // Make the window visible. + window.makeKeyAndVisible(); + + return true; + } + + @Override + public void didEnterBackground(UIApplication application) { + // this will store tab ordering. + saveTabOrder(); + } + + /** Store the tab-order to preferences */ + private void saveTabOrder() { + List classNames = new ArrayList(); + for (UIViewController controller : tabBarController.getViewControllers()) { + if (controller instanceof UINavigationController) { + UINavigationController navController = (UINavigationController) controller; + classNames.add(navController.getTopViewController().getClass().getName()); + } else { + classNames.add(controller.getClass().getName()); + } + } + + NSUserDefaults.getStandardUserDefaults().put(TAB_BAR_ORDER_PREF_KEY, NSArray.fromStrings(classNames)); + } + + @Override + public boolean shouldRestoreApplicationState(UIApplication application, NSCoder coder) { + return true; + } + + @Override + public boolean shouldSaveApplicationState(UIApplication application, NSCoder coder) { + return true; + } + + public static void main(String[] args) { + NSAutoreleasePool pool = new NSAutoreleasePool(); + UIApplication.main(args, null, Tabster.class); + pool.close(); + } +} diff --git a/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/FavoritesViewController.java b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/FavoritesViewController.java new file mode 100644 index 00000000..0483d03f --- /dev/null +++ b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/FavoritesViewController.java @@ -0,0 +1,77 @@ +/* + * 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 Tabster sample (v1.6) + * which is copyright (C) 2011-2014 Apple Inc. + */ + +package org.robovm.samples.tabster.viewcontrollers; + +import java.util.HashMap; +import java.util.Map; + +import org.robovm.apple.coregraphics.CGRect; +import org.robovm.apple.foundation.NSObjectProtocol; +import org.robovm.apple.uikit.NSLayoutConstraint; +import org.robovm.apple.uikit.NSLayoutFormatOptions; +import org.robovm.apple.uikit.UIColor; +import org.robovm.apple.uikit.UIFont; +import org.robovm.apple.uikit.UILabel; +import org.robovm.apple.uikit.UINavigationController; +import org.robovm.apple.uikit.UITabBarItem; +import org.robovm.apple.uikit.UITabBarSystemItem; +import org.robovm.apple.uikit.UIView; +import org.robovm.apple.uikit.UIViewController; + +public class FavoritesViewController extends UIViewController { + private final UILabel titleLabel; + + public FavoritesViewController () { + setTabBarItem(new UITabBarItem(UITabBarSystemItem.Favorites, 0)); + + UIView view = getView(); + view.setBackgroundColor(UIColor.fromRGBA(0.77, 1, 1, 1)); + + titleLabel = new UILabel(new CGRect(0, 0, 100, 100)); + titleLabel.setFont(UIFont.getSystemFont(17)); + titleLabel.setText("Favorites"); + titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false); + view.addSubview(titleLabel); + + // Layout + Map views = new HashMap<>(); + views.put("parent", view); + views.put("title", titleLabel); + + view.addConstraints(NSLayoutConstraint.create("H:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterY, null, + views)); + view.addConstraints(NSLayoutConstraint.create("V:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterX, null, + views)); + } + + @Override + public void viewWillAppear (boolean animated) { + super.viewWillAppear(animated); + + // if we were navigated to through the More screen table, then we have a navigation bar which + // also means we have a title. So hide the title label in this case, otherwise, we need it + if (getParentViewController() instanceof UINavigationController) { + titleLabel.setHidden(true); + } else { + titleLabel.setHidden(false); + } + } + +} diff --git a/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/FeaturedViewController.java b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/FeaturedViewController.java new file mode 100644 index 00000000..7c5143d9 --- /dev/null +++ b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/FeaturedViewController.java @@ -0,0 +1,76 @@ +/* + * 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 Tabster sample (v1.6) + * which is copyright (C) 2011-2014 Apple Inc. + */ + +package org.robovm.samples.tabster.viewcontrollers; + +import java.util.HashMap; +import java.util.Map; + +import org.robovm.apple.coregraphics.CGRect; +import org.robovm.apple.foundation.NSObjectProtocol; +import org.robovm.apple.uikit.NSLayoutConstraint; +import org.robovm.apple.uikit.NSLayoutFormatOptions; +import org.robovm.apple.uikit.UIColor; +import org.robovm.apple.uikit.UIFont; +import org.robovm.apple.uikit.UILabel; +import org.robovm.apple.uikit.UINavigationController; +import org.robovm.apple.uikit.UITabBarItem; +import org.robovm.apple.uikit.UITabBarSystemItem; +import org.robovm.apple.uikit.UIView; +import org.robovm.apple.uikit.UIViewController; + +public class FeaturedViewController extends UIViewController { + private final UILabel titleLabel; + + public FeaturedViewController () { + setTabBarItem(new UITabBarItem(UITabBarSystemItem.Featured, 0)); + + UIView view = getView(); + view.setBackgroundColor(UIColor.fromRGBA(0.9, 1, 0.7, 1)); + + titleLabel = new UILabel(new CGRect(0, 0, 100, 100)); + titleLabel.setFont(UIFont.getSystemFont(17)); + titleLabel.setText("Featured"); + titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false); + view.addSubview(titleLabel); + + // Layout + Map views = new HashMap<>(); + views.put("parent", view); + views.put("title", titleLabel); + + view.addConstraints(NSLayoutConstraint.create("H:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterY, null, + views)); + view.addConstraints(NSLayoutConstraint.create("V:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterX, null, + views)); + } + + @Override + public void viewWillAppear (boolean animated) { + super.viewWillAppear(animated); + + // if we were navigated to through the More screen table, then we have a navigation bar which + // also means we have a title. So hide the title label in this case, otherwise, we need it + if (getParentViewController() instanceof UINavigationController) { + titleLabel.setHidden(true); + } else { + titleLabel.setHidden(false); + } + } +} diff --git a/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/FourViewController.java b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/FourViewController.java new file mode 100644 index 00000000..e7696588 --- /dev/null +++ b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/FourViewController.java @@ -0,0 +1,75 @@ +/* + * 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 Tabster sample (v1.6) + * which is copyright (C) 2011-2014 Apple Inc. + */ + +package org.robovm.samples.tabster.viewcontrollers; + +import java.util.HashMap; +import java.util.Map; + +import org.robovm.apple.foundation.NSObjectProtocol; +import org.robovm.apple.uikit.NSLayoutConstraint; +import org.robovm.apple.uikit.NSLayoutFormatOptions; +import org.robovm.apple.uikit.UIColor; +import org.robovm.apple.uikit.UIFont; +import org.robovm.apple.uikit.UIImage; +import org.robovm.apple.uikit.UILabel; +import org.robovm.apple.uikit.UINavigationController; +import org.robovm.apple.uikit.UITabBarItem; +import org.robovm.apple.uikit.UIView; +import org.robovm.apple.uikit.UIViewController; + +public class FourViewController extends UIViewController { + private final UILabel titleLabel; + + public FourViewController () { + setTabBarItem(new UITabBarItem("Four", UIImage.create("tab4"), 0)); + + UIView view = getView(); + view.setBackgroundColor(UIColor.fromRGBA(0.32, 1, 0.3, 1)); + + titleLabel = new UILabel(); + titleLabel.setFont(UIFont.getSystemFont(17)); + titleLabel.setText("FOUR"); + titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false); + view.addSubview(titleLabel); + + // Layout + Map views = new HashMap<>(); + views.put("parent", view); + views.put("title", titleLabel); + + view.addConstraints(NSLayoutConstraint.create("H:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterY, null, + views)); + view.addConstraints(NSLayoutConstraint.create("V:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterX, null, + views)); + } + + @Override + public void viewWillAppear (boolean animated) { + super.viewWillAppear(animated); + + // if we were navigated to through the More screen table, then we have a navigation bar which + // also means we have a title. So hide the title label in this case, otherwise, we need it + if (getParentViewController() instanceof UINavigationController) { + titleLabel.setHidden(true); + } else { + titleLabel.setHidden(false); + } + } +} diff --git a/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/LandscapeViewController.java b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/LandscapeViewController.java new file mode 100644 index 00000000..7ecd5348 --- /dev/null +++ b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/LandscapeViewController.java @@ -0,0 +1,76 @@ +/* + * 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 Tabster sample (v1.6) + * which is copyright (C) 2011-2014 Apple Inc. + */ + +package org.robovm.samples.tabster.viewcontrollers; + +import org.robovm.apple.coregraphics.CGRect; +import org.robovm.apple.uikit.UIButton; +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.UIImage; +import org.robovm.apple.uikit.UIImageView; +import org.robovm.apple.uikit.UIInterfaceOrientationMask; +import org.robovm.apple.uikit.UIView; +import org.robovm.apple.uikit.UIViewController; + +public class LandscapeViewController extends UIViewController { + private UIImage image; + private final UIImageView imageView; + + public LandscapeViewController () { + UIView view = getView(); + view.setBackgroundColor(UIColor.white()); + + imageView = new UIImageView(new CGRect(0, 0, 568, 320)); + view.addSubview(imageView); + + UIButton button = new UIButton(new CGRect(20, 259, 49, 41)); + button.setImage(UIImage.create("left"), UIControlState.Normal); + button.setImage(UIImage.create("left_pressed"), UIControlState.with(UIControlState.Selected, UIControlState.Highlighted)); + button.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener() { + @Override + public void onTouchUpInside (UIControl control, UIEvent event) { + dismissViewController(false, null); + } + }); + view.addSubview(button); + } + + @Override + public void viewWillAppear (boolean animated) { + super.viewWillAppear(animated); + imageView.setImage(image); + } + + @Override + public UIInterfaceOrientationMask getSupportedInterfaceOrientations () { + return UIInterfaceOrientationMask.Landscape; + } + + @Override + public boolean shouldAutorotate () { + return true; + } + + public void setImage (UIImage image) { + this.image = image; + } +} diff --git a/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/ModalViewController.java b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/ModalViewController.java new file mode 100644 index 00000000..eb7e24b9 --- /dev/null +++ b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/ModalViewController.java @@ -0,0 +1,86 @@ +/* + * 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 Tabster sample (v1.6) + * which is copyright (C) 2011-2014 Apple Inc. + */ + +package org.robovm.samples.tabster.viewcontrollers; + +import java.util.HashMap; +import java.util.Map; + +import org.robovm.apple.foundation.NSObjectProtocol; +import org.robovm.apple.uikit.NSLayoutConstraint; +import org.robovm.apple.uikit.NSLayoutFormatOptions; +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.UILabel; +import org.robovm.apple.uikit.UIView; +import org.robovm.apple.uikit.UIViewController; + +public class ModalViewController extends UIViewController { + private SubLevelViewController owningViewController; + private final UILabel titleLabel; + + public ModalViewController () { + UIView view = getView(); + view.setBackgroundColor(UIColor.white()); + + titleLabel = new UILabel(); + titleLabel.setFont(UIFont.getSystemFont(17)); + titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false); + view.addSubview(titleLabel); + + UIButton button = UIButton.create(UIButtonType.RoundedRect); + button.setTitle("Done", UIControlState.Normal); + button.setTitleShadowColor(UIColor.fromWhiteAlpha(0.5, 1), UIControlState.Normal); + button.setTranslatesAutoresizingMaskIntoConstraints(false); + button.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener() { + @Override + public void onTouchUpInside (UIControl control, UIEvent event) { + dismissViewController(true, null); + } + }); + view.addSubview(button); + + // Layout + Map views = new HashMap<>(); + views.put("parent", view); + views.put("title", titleLabel); + views.put("done", button); + + view.addConstraints(NSLayoutConstraint.create("H:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterY, null, + views)); + view.addConstraints(NSLayoutConstraint.create("V:[parent]-(<=1)-[title]-33-[done]", + NSLayoutFormatOptions.AlignAllCenterX, null, views)); + } + + @Override + public void viewWillAppear (boolean animated) { + super.viewWillAppear(animated); + + titleLabel.setText(owningViewController.getCurrentSelectionTitle()); + } + + public void setOwningViewController (SubLevelViewController owningViewController) { + this.owningViewController = owningViewController; + } +} diff --git a/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/OneViewController.java b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/OneViewController.java new file mode 100644 index 00000000..77e5e707 --- /dev/null +++ b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/OneViewController.java @@ -0,0 +1,95 @@ +/* + * 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 Tabster sample (v1.6) + * which is copyright (C) 2011-2014 Apple Inc. + */ + +package org.robovm.samples.tabster.viewcontrollers; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.robovm.apple.foundation.NSIndexPath; +import org.robovm.apple.uikit.UIColor; +import org.robovm.apple.uikit.UITableView; +import org.robovm.apple.uikit.UITableViewCell; +import org.robovm.apple.uikit.UITableViewCellAccessoryType; +import org.robovm.apple.uikit.UITableViewCellStyle; +import org.robovm.apple.uikit.UITableViewController; +import org.robovm.apple.uikit.UITableViewDataSourceAdapter; +import org.robovm.apple.uikit.UITableViewDelegateAdapter; + +public class OneViewController extends UITableViewController { + private final List dataList; + private SubLevelViewController subLevelViewController; + + public OneViewController () { + dataList = new ArrayList<>(Arrays.asList("Mac Pro", "Mac mini", "iMac", "MacBook", "MacBook Pro", "MacBook Air")); + + subLevelViewController = new SubLevelViewController(); + + UITableView tableView = getTableView(); + tableView.setAlwaysBounceVertical(true); + tableView.setBackgroundColor(UIColor.white()); + tableView.setDataSource(new UITableViewDataSourceAdapter() { + @Override + public long getNumberOfRowsInSection (UITableView tableView, long section) { + return dataList.size(); + } + + @Override + public UITableViewCell getCellForRow (UITableView tableView, NSIndexPath indexPath) { + final String cellID = "cellID"; + + UITableViewCell cell = tableView.dequeueReusableCell(cellID); + if (cell == null) { + cell = new UITableViewCell(UITableViewCellStyle.Default, cellID); + cell.setAccessoryType(UITableViewCellAccessoryType.DisclosureIndicator); + } + cell.getTextLabel().setText(dataList.get((int)indexPath.getRow())); + + return cell; + } + }); + tableView.setDelegate(new UITableViewDelegateAdapter() { + @Override + public void didSelectRow (UITableView tableView, NSIndexPath indexPath) { + UITableViewCell cell = tableView.getCellForRow(indexPath); + subLevelViewController.setTitle(cell.getTextLabel().getText()); + + getNavigationController().pushViewController(subLevelViewController, true); + } + }); + + } + + @Override + public void viewDidLoad () { + super.viewDidLoad(); + + getNavigationItem().setTitle("One"); + } + + @Override + public void viewWillAppear (boolean animated) { + super.viewWillAppear(animated); + + // this UIViewController is about to re-appear, make sure we remove the current selection in our table view + NSIndexPath tableSelection = getTableView().getIndexPathForSelectedRow(); + getTableView().deselectRow(tableSelection, false); + } +} diff --git a/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/SubLevelViewController.java b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/SubLevelViewController.java new file mode 100644 index 00000000..b9acf607 --- /dev/null +++ b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/SubLevelViewController.java @@ -0,0 +1,87 @@ +/* + * 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 Tabster sample (v1.6) + * which is copyright (C) 2011-2014 Apple Inc. + */ + +package org.robovm.samples.tabster.viewcontrollers; + +import java.util.Arrays; +import java.util.List; + +import org.robovm.apple.foundation.NSIndexPath; +import org.robovm.apple.uikit.UITableView; +import org.robovm.apple.uikit.UITableViewCell; +import org.robovm.apple.uikit.UITableViewCellAccessoryType; +import org.robovm.apple.uikit.UITableViewCellSelectionStyle; +import org.robovm.apple.uikit.UITableViewCellStyle; +import org.robovm.apple.uikit.UITableViewController; +import org.robovm.apple.uikit.UITableViewDataSourceAdapter; +import org.robovm.apple.uikit.UITableViewDelegateAdapter; + +public class SubLevelViewController extends UITableViewController { + private String currentSelectionTitle; + private List dataList; + private ModalViewController modalViewController; + + public SubLevelViewController () { + dataList = Arrays.asList("Feature 1", "Feature 2"); + + UITableView tableView = getTableView(); + tableView.setAlwaysBounceVertical(true); + tableView.setDelegate(new UITableViewDelegateAdapter() { + @Override + public void didSelectRow (UITableView tableView, NSIndexPath indexPath) { + tableView.deselectRow(indexPath, false); + } + + @Override + public void accessoryButtonTapped (UITableView tableView, NSIndexPath indexPath) { + modalViewController.setOwningViewController(SubLevelViewController.this); + UITableViewCell cell = tableView.getCellForRow(indexPath); + currentSelectionTitle = cell.getTextLabel().getText(); + presentViewController(modalViewController, true, null); + } + }); + tableView.setDataSource(new UITableViewDataSourceAdapter() { + @Override + public long getNumberOfRowsInSection (UITableView tableView, long section) { + return dataList.size(); + } + + @Override + public UITableViewCell getCellForRow (UITableView tableView, NSIndexPath indexPath) { + final String identifier = "cellID2"; + + UITableViewCell cell = tableView.dequeueReusableCell(identifier); + if (cell == null) { + cell = new UITableViewCell(UITableViewCellStyle.Default, identifier); + cell.setAccessoryType(UITableViewCellAccessoryType.DetailDisclosureButton); + cell.setSelectionStyle(UITableViewCellSelectionStyle.Blue); + } + cell.getTextLabel().setText(dataList.get((int)indexPath.getRow())); + + return cell; + } + }); + + modalViewController = new ModalViewController(); + } + + public String getCurrentSelectionTitle () { + return currentSelectionTitle; + } +} diff --git a/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/ThreeViewController.java b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/ThreeViewController.java new file mode 100644 index 00000000..c81b6a94 --- /dev/null +++ b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/ThreeViewController.java @@ -0,0 +1,140 @@ +/* + * 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 Tabster sample (v1.6) + * which is copyright (C) 2011-2014 Apple Inc. + */ + +package org.robovm.samples.tabster.viewcontrollers; + +import java.util.HashMap; +import java.util.Map; + +import org.robovm.apple.foundation.NSObjectProtocol; +import org.robovm.apple.foundation.NSRange; +import org.robovm.apple.foundation.NSString; +import org.robovm.apple.foundation.NSUserDefaults; +import org.robovm.apple.uikit.NSLayoutConstraint; +import org.robovm.apple.uikit.NSLayoutFormatOptions; +import org.robovm.apple.uikit.UIBarButtonItem; +import org.robovm.apple.uikit.UIBarButtonSystemItem; +import org.robovm.apple.uikit.UIColor; +import org.robovm.apple.uikit.UIFont; +import org.robovm.apple.uikit.UIKeyboardType; +import org.robovm.apple.uikit.UILabel; +import org.robovm.apple.uikit.UITextBorderStyle; +import org.robovm.apple.uikit.UITextField; +import org.robovm.apple.uikit.UITextFieldDelegateAdapter; +import org.robovm.apple.uikit.UIView; +import org.robovm.apple.uikit.UIViewController; + +public class ThreeViewController extends UIViewController { + private static final String BADGE_VALUE_PREF_KEY = "BadgeValue"; // badge value key for storing to NSUserDefaults + + private UIBarButtonItem doneButton; + private final UITextField badgeField; + + public ThreeViewController () { + UIView view = getView(); + view.setBackgroundColor(UIColor.fromWhiteAlpha(0.66, 1)); + + badgeField = new UITextField(); + badgeField.setBorderStyle(UITextBorderStyle.RoundedRect); + badgeField.setFont(UIFont.getSystemFont(14)); + badgeField.setKeyboardType(UIKeyboardType.NumberPad); + badgeField.setTranslatesAutoresizingMaskIntoConstraints(false); + badgeField.setDelegate(new UITextFieldDelegateAdapter() { + @Override + public void didBeginEditing (UITextField textField) { + // user is starting to edit, add the done button to the navigation bar + getNavigationItem().setRightBarButtonItem(doneButton); + } + + @Override + public void didEndEditing (UITextField textField) { + // user is done editing, remove the done button from the navigation bar + getNavigationItem().setRightBarButtonItem(null); + } + + @Override + public boolean shouldChangeCharacters (UITextField textField, NSRange range, String string) { + boolean result = true; + + // restrict the maximum number of characters to 5 + if (textField.getText().length() == 5 && string.length() > 0) { + result = false; + } + + return result; + } + }); + view.addSubview(badgeField); + + UILabel valueLabel = new UILabel(); + valueLabel.setText("Value"); + valueLabel.setTranslatesAutoresizingMaskIntoConstraints(false); + valueLabel.setFont(UIFont.getSystemFont(17)); + valueLabel.setTextColor(UIColor.darkText()); + view.addSubview(valueLabel); + + // Layout + Map views = new HashMap<>(); + views.put("value", valueLabel); + views.put("badge", badgeField); + views.put("top", getTopLayoutGuide()); + + view.addConstraints(NSLayoutConstraint.create("H:|-20-[value(48)]-[badge]-20-|", NSLayoutFormatOptions.None, null, views)); + view.addConstraints(NSLayoutConstraint.create("V:[top]-58-[value]", NSLayoutFormatOptions.None, null, views)); + view.addConstraints(NSLayoutConstraint.create("V:[top]-54-[badge]", NSLayoutFormatOptions.None, null, views)); + + doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, new UIBarButtonItem.OnClickListener() { + @Override + public void onClick (UIBarButtonItem barButtonItem) { + // dismiss the keyboard by resigning our badge edit field as first responder + badgeField.resignFirstResponder(); + + // set the badge value to our tab item (but only if a valid string) + if (badgeField.getText().length() > 0) { + // a value was entered, + // because we are inside a navigation controller, + // we must access its tabBarItem to set the badgeValue. + getNavigationController().getTabBarItem().setBadgeValue(badgeField.getText()); + } else { + // no value was entered + getNavigationController().getTabBarItem().setBadgeValue(null); + } + + NSUserDefaults.getStandardUserDefaults().put(BADGE_VALUE_PREF_KEY, new NSString(badgeField.getText())); + } + }); + } + + @Override + public void viewDidLoad () { + super.viewDidLoad(); + + getNavigationItem().setTitle("Three"); + } + + @Override + public void viewWillAppear (boolean animated) { + // set the badge value in our test field and tabbar item + String badgeValue = NSUserDefaults.getStandardUserDefaults().getString(BADGE_VALUE_PREF_KEY); + if (badgeValue != null && badgeValue.length() != 0) { + badgeField.setText(badgeValue); + getNavigationController().getTabBarItem().setBadgeValue(badgeField.getText()); + } + } +} diff --git a/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/TwoViewController.java b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/TwoViewController.java new file mode 100644 index 00000000..a86394a5 --- /dev/null +++ b/Tabster-no-ib/src/main/java/org/robovm/samples/tabster/viewcontrollers/TwoViewController.java @@ -0,0 +1,92 @@ +/* + * 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 Tabster sample (v1.6) + * which is copyright (C) 2011-2014 Apple Inc. + */ + +package org.robovm.samples.tabster.viewcontrollers; + +import java.util.Arrays; +import java.util.List; + +import org.robovm.apple.foundation.NSIndexPath; +import org.robovm.apple.uikit.UIColor; +import org.robovm.apple.uikit.UIImage; +import org.robovm.apple.uikit.UITableView; +import org.robovm.apple.uikit.UITableViewCell; +import org.robovm.apple.uikit.UITableViewCellAccessoryType; +import org.robovm.apple.uikit.UITableViewCellStyle; +import org.robovm.apple.uikit.UITableViewController; +import org.robovm.apple.uikit.UITableViewDataSourceAdapter; +import org.robovm.apple.uikit.UITableViewDelegateAdapter; + +public class TwoViewController extends UITableViewController { + private final List dataList; + private LandscapeViewController landscapeViewController; + + public TwoViewController () { + dataList = Arrays.asList("Cherry Lake", "Lake Don Pedro"); + + landscapeViewController = new LandscapeViewController(); + + UITableView tableView = getTableView(); + tableView.setAlwaysBounceVertical(true); + tableView.setBackgroundColor(UIColor.white()); + tableView.setDataSource(new UITableViewDataSourceAdapter() { + @Override + public long getNumberOfRowsInSection (UITableView tableView, long section) { + return dataList.size(); + } + + @Override + public UITableViewCell getCellForRow (UITableView tableView, NSIndexPath indexPath) { + final String cellID = "cellIDTwo"; + + UITableViewCell cell = tableView.dequeueReusableCell(cellID); + if (cell == null) { + cell = new UITableViewCell(UITableViewCellStyle.Default, cellID); + cell.setAccessoryType(UITableViewCellAccessoryType.DisclosureIndicator); + } + cell.getTextLabel().setText(dataList.get((int)indexPath.getRow())); + + return cell; + } + }); + tableView.setDelegate(new UITableViewDelegateAdapter() { + @Override + public void didSelectRow (UITableView tableView, NSIndexPath indexPath) { + UITableViewCell cell = tableView.getCellForRow(indexPath); + UIImage image = null; + String text = cell.getTextLabel().getText(); + if (text.equals("Cherry Lake")) { + image = UIImage.create("cherrylake"); + } else if (text.equals("Lake Don Pedro")) { + image = UIImage.create("lakedonpedro"); + } + landscapeViewController.setImage(image); + presentViewController(landscapeViewController, true, null); + } + }); + + } + + @Override + public void viewDidLoad () { + super.viewDidLoad(); + + getNavigationItem().setTitle("Two"); + } +} diff --git a/Tabster-resources/Base.lproj/Four.storyboard b/Tabster-resources/Base.lproj/Four.storyboard new file mode 100644 index 00000000..404b92f4 --- /dev/null +++ b/Tabster-resources/Base.lproj/Four.storyboard @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tabster-resources/Base.lproj/Main.storyboard b/Tabster-resources/Base.lproj/Main.storyboard new file mode 100644 index 00000000..6d8363a2 --- /dev/null +++ b/Tabster-resources/Base.lproj/Main.storyboard @@ -0,0 +1,387 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Contents.json b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..ffa15158 --- /dev/null +++ b/Tabster-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/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png new file mode 100644 index 00000000..dc692891 Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png differ diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png new file mode 100644 index 00000000..a0e7f3d2 Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png differ diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-76.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-76.png new file mode 100644 index 00000000..1353f4e8 Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-76.png differ diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-76@2x.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-76@2x.png new file mode 100644 index 00000000..02186449 Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-76@2x.png differ diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40.png new file mode 100644 index 00000000..868d80b9 Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40.png differ diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x-1.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x-1.png new file mode 100644 index 00000000..8db82b0f Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x-1.png differ diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png new file mode 100644 index 00000000..8db82b0f Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png differ diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png new file mode 100644 index 00000000..dc692891 Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png differ diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small.png new file mode 100644 index 00000000..595c460d Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small.png differ diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small@2x-1.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small@2x-1.png new file mode 100644 index 00000000..6f9e1565 Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small@2x-1.png differ diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small@2x.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small@2x.png new file mode 100644 index 00000000..6f9e1565 Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small@2x.png differ diff --git a/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small@3x.png b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small@3x.png new file mode 100644 index 00000000..8219640c Binary files /dev/null and b/Tabster-resources/Images.xcassets/AppIcon.appiconset/Icon-Small@3x.png differ diff --git a/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Contents.json b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Contents.json new file mode 100644 index 00000000..5379aae6 --- /dev/null +++ b/Tabster-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/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-568h@2x~iphone.png b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-568h@2x~iphone.png new file mode 100644 index 00000000..fb1d4236 Binary files /dev/null and b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-568h@2x~iphone.png differ diff --git a/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Landscape@2x~ipad.png b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Landscape@2x~ipad.png new file mode 100644 index 00000000..e17e1121 Binary files /dev/null and b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Landscape@2x~ipad.png differ diff --git a/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Landscape~ipad.png b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Landscape~ipad.png new file mode 100644 index 00000000..71b5a2b3 Binary files /dev/null and b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Landscape~ipad.png differ diff --git a/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Portrait@2x~ipad.png b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Portrait@2x~ipad.png new file mode 100644 index 00000000..7e9edb2c Binary files /dev/null and b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Portrait@2x~ipad.png differ diff --git a/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Portrait~ipad.png b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Portrait~ipad.png new file mode 100644 index 00000000..c1b70744 Binary files /dev/null and b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default-Portrait~ipad.png differ diff --git a/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default@2x~iphone.png b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default@2x~iphone.png new file mode 100644 index 00000000..c43b69c9 Binary files /dev/null and b/Tabster-resources/Images.xcassets/LaunchImage.launchimage/Default@2x~iphone.png differ diff --git a/Tabster/Info.plist.xml b/Tabster/Info.plist.xml index c2956aaf..8fad5307 100644 --- a/Tabster/Info.plist.xml +++ b/Tabster/Info.plist.xml @@ -24,6 +24,10 @@ ${app.build} LSRequiresIPhoneOS + UIMainStoryboardFile + Main + MinimumOSVersion + 8.0 UIDeviceFamily 1 @@ -46,32 +50,5 @@ 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/Tabster/resources/Images.xcassets/cherrylake.imageset/Contents.json b/Tabster/resources/Images.xcassets/cherrylake.imageset/Contents.json index c6454aab..6780aed4 100644 --- a/Tabster/resources/Images.xcassets/cherrylake.imageset/Contents.json +++ b/Tabster/resources/Images.xcassets/cherrylake.imageset/Contents.json @@ -9,10 +9,6 @@ "idiom" : "universal", "scale" : "2x", "filename" : "cherrylake@2x.png" - }, - { - "idiom" : "universal", - "scale" : "3x" } ], "info" : { diff --git a/Tabster/resources/Images.xcassets/lakedonpedro.imageset/Contents.json b/Tabster/resources/Images.xcassets/lakedonpedro.imageset/Contents.json index aa11fe4a..2acfd14d 100644 --- a/Tabster/resources/Images.xcassets/lakedonpedro.imageset/Contents.json +++ b/Tabster/resources/Images.xcassets/lakedonpedro.imageset/Contents.json @@ -9,10 +9,6 @@ "idiom" : "universal", "scale" : "2x", "filename" : "lakedonpedro@2x.png" - }, - { - "idiom" : "universal", - "scale" : "3x" } ], "info" : { diff --git a/Tabster/resources/Images.xcassets/left.imageset/Contents.json b/Tabster/resources/Images.xcassets/left.imageset/Contents.json index bc628230..b57f3915 100644 --- a/Tabster/resources/Images.xcassets/left.imageset/Contents.json +++ b/Tabster/resources/Images.xcassets/left.imageset/Contents.json @@ -9,10 +9,6 @@ "idiom" : "universal", "scale" : "2x", "filename" : "left@2x.png" - }, - { - "idiom" : "universal", - "scale" : "3x" } ], "info" : { diff --git a/Tabster/resources/Images.xcassets/left_pressed.imageset/Contents.json b/Tabster/resources/Images.xcassets/left_pressed.imageset/Contents.json index 63dfee77..c2959a1e 100644 --- a/Tabster/resources/Images.xcassets/left_pressed.imageset/Contents.json +++ b/Tabster/resources/Images.xcassets/left_pressed.imageset/Contents.json @@ -9,10 +9,6 @@ "idiom" : "universal", "scale" : "2x", "filename" : "left_pressed@2x.png" - }, - { - "idiom" : "universal", - "scale" : "3x" } ], "info" : { diff --git a/Tabster/resources/Images.xcassets/tab1.imageset/Contents.json b/Tabster/resources/Images.xcassets/tab1.imageset/Contents.json index 2fc4e153..38247e29 100644 --- a/Tabster/resources/Images.xcassets/tab1.imageset/Contents.json +++ b/Tabster/resources/Images.xcassets/tab1.imageset/Contents.json @@ -9,10 +9,6 @@ "idiom" : "universal", "scale" : "2x", "filename" : "tab1@2x.png" - }, - { - "idiom" : "universal", - "scale" : "3x" } ], "info" : { diff --git a/Tabster/resources/Images.xcassets/tab2.imageset/Contents.json b/Tabster/resources/Images.xcassets/tab2.imageset/Contents.json index b07a0b76..414e2349 100644 --- a/Tabster/resources/Images.xcassets/tab2.imageset/Contents.json +++ b/Tabster/resources/Images.xcassets/tab2.imageset/Contents.json @@ -9,10 +9,6 @@ "idiom" : "universal", "scale" : "2x", "filename" : "tab2@2x.png" - }, - { - "idiom" : "universal", - "scale" : "3x" } ], "info" : { diff --git a/Tabster/resources/Images.xcassets/tab3.imageset/Contents.json b/Tabster/resources/Images.xcassets/tab3.imageset/Contents.json index 3af34cc8..921e9f61 100644 --- a/Tabster/resources/Images.xcassets/tab3.imageset/Contents.json +++ b/Tabster/resources/Images.xcassets/tab3.imageset/Contents.json @@ -9,10 +9,6 @@ "idiom" : "universal", "scale" : "2x", "filename" : "tab3@2x.png" - }, - { - "idiom" : "universal", - "scale" : "3x" } ], "info" : { diff --git a/Tabster/resources/Images.xcassets/tab4.imageset/Contents.json b/Tabster/resources/Images.xcassets/tab4.imageset/Contents.json index b43a7e16..fba2972a 100644 --- a/Tabster/resources/Images.xcassets/tab4.imageset/Contents.json +++ b/Tabster/resources/Images.xcassets/tab4.imageset/Contents.json @@ -9,10 +9,6 @@ "idiom" : "universal", "scale" : "2x", "filename" : "tab4@2x.png" - }, - { - "idiom" : "universal", - "scale" : "3x" } ], "info" : { diff --git a/Tabster/src/main/java/org/robovm/samples/tabster/Tabster.java b/Tabster/src/main/java/org/robovm/samples/tabster/Tabster.java index fc50bb75..e5f26da9 100644 --- a/Tabster/src/main/java/org/robovm/samples/tabster/Tabster.java +++ b/Tabster/src/main/java/org/robovm/samples/tabster/Tabster.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. @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Portions of this code is based on Apple Inc's Tabster sample (v1.6) - * which is copyright (C) 2011-2014 Apple Inc. + * Portions of this code is based on Apple Inc's PhotoPicker sample (v2.0) + * which is copyright (C) 2010-2013 Apple Inc. */ - package org.robovm.samples.tabster; import java.util.ArrayList; @@ -33,83 +32,41 @@ import org.robovm.apple.uikit.UIApplicationDelegateAdapter; import org.robovm.apple.uikit.UIApplicationLaunchOptions; import org.robovm.apple.uikit.UIColor; -import org.robovm.apple.uikit.UIImage; import org.robovm.apple.uikit.UINavigationController; import org.robovm.apple.uikit.UINavigationControllerDelegateAdapter; -import org.robovm.apple.uikit.UIScreen; +import org.robovm.apple.uikit.UIStoryboard; import org.robovm.apple.uikit.UITabBarController; -import org.robovm.apple.uikit.UITabBarItem; import org.robovm.apple.uikit.UIViewController; -import org.robovm.apple.uikit.UIWindow; -import org.robovm.samples.tabster.viewcontrollers.FavoritesViewController; import org.robovm.samples.tabster.viewcontrollers.FeaturedViewController; -import org.robovm.samples.tabster.viewcontrollers.FourViewController; -import org.robovm.samples.tabster.viewcontrollers.OneViewController; -import org.robovm.samples.tabster.viewcontrollers.ThreeViewController; -import org.robovm.samples.tabster.viewcontrollers.TwoViewController; public class Tabster extends UIApplicationDelegateAdapter { - private static final boolean CUSTOMIZE_TAB_BAR = false; // Turn on/off - // custom tab bar - // appearance - - // NSUserDefaults keys: - private static final String TAB_BAR_ORDER_PREF_KEY = "TabBarOrder"; // The - // ordering - // of - // the - // tabs - - private UIWindow window; + // Turn on/off custom tab bar appearance + private static final boolean CUSTOMIZE_TAB_BAR = false; + + // The ordering of the tabs + private static final String TAB_BAR_ORDER_PREF_KEY = "TabBarOrder"; + private UITabBarController tabBarController; - private UINavigationController oneNavController; - private OneViewController oneViewController; - private UINavigationController twoNavController; - private TwoViewController twoViewController; - private UINavigationController threeNavController; - private ThreeViewController threeViewController; - private FourViewController fourViewController; - private FavoritesViewController favoritesViewController; - private FeaturedViewController featuredViewController; - - @SuppressWarnings("unchecked") + @SuppressWarnings({ "deprecation", "unchecked" }) @Override - public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) { - // Set up the view controller. - tabBarController = new UITabBarController(); + public boolean willFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) { + // add the tab bar controller's current view as a subview of the window + tabBarController = (UITabBarController) getWindow().getRootViewController(); // customize the More page's navigation bar color tabBarController.getMoreNavigationController().getNavigationBar().setTintColor(UIColor.gray()); - // Adding view controllers. - NSArray viewControllers = new NSMutableArray(); - - oneViewController = new OneViewController(); - oneNavController = new UINavigationController(oneViewController); - oneNavController.setTabBarItem(new UITabBarItem("One", UIImage.create("tab1"), 0)); - viewControllers.add(oneNavController); - - twoViewController = new TwoViewController(); - twoNavController = new UINavigationController(twoViewController); - twoNavController.setTabBarItem(new UITabBarItem("Two", UIImage.create("tab2"), 0)); - viewControllers.add(twoNavController); - - threeViewController = new ThreeViewController(); - threeNavController = new UINavigationController(threeViewController); - threeNavController.setTabBarItem(new UITabBarItem("Three", UIImage.create("tab3"), 0)); - viewControllers.add(threeNavController); + // Adding controller from the Four.storyboard + NSArray classController = tabBarController.getViewControllers(); + NSMutableArray controllerArray = new NSMutableArray<>(classController); - fourViewController = new FourViewController(); - viewControllers.add(fourViewController); + UIStoryboard storyboard = UIStoryboard.create("Four", null); + UIViewController four = storyboard.instantiateInitialViewController(); - favoritesViewController = new FavoritesViewController(); - viewControllers.add(favoritesViewController); + controllerArray.add(3, four); - featuredViewController = new FeaturedViewController(); - viewControllers.add(featuredViewController); - - tabBarController.setViewControllers(viewControllers); + tabBarController.setViewControllers(controllerArray); if (CUSTOMIZE_TAB_BAR) { // set the bar tint color for iOS 7 and later @@ -172,15 +129,9 @@ public void willShowViewController(UINavigationController navigationController, } }); - // choose to make one of our view controllers - // ("FeaturedViewController"), + // choose to make one of our view controllers ("FeaturedViewController") // not movable/reorderable in More's edit screen - NSArray customizeableViewControllers; - if (tabBarController.getViewControllers() == null) { - customizeableViewControllers = new NSMutableArray<>(); - } else { - customizeableViewControllers = new NSMutableArray<>(tabBarController.getViewControllers()); - } + NSArray customizeableViewControllers = tabBarController.getViewControllers(); for (UIViewController viewController : customizeableViewControllers) { if (viewController instanceof FeaturedViewController) { customizeableViewControllers.remove(viewController); @@ -189,14 +140,8 @@ public void willShowViewController(UINavigationController navigationController, } tabBarController.setCustomizableViewControllers(customizeableViewControllers); - // 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(tabBarController); - // Make the window visible. - window.makeKeyAndVisible(); - return true; + } @Override @@ -231,8 +176,8 @@ public boolean shouldSaveApplicationState(UIApplication application, NSCoder cod } public static void main(String[] args) { - NSAutoreleasePool pool = new NSAutoreleasePool(); - UIApplication.main(args, null, Tabster.class); - pool.close(); + try (NSAutoreleasePool pool = new NSAutoreleasePool()) { + UIApplication.main(args, null, Tabster.class); + } } } diff --git a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FavoritesViewController.java b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FavoritesViewController.java index 0483d03f..14fb7352 100644 --- a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FavoritesViewController.java +++ b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FavoritesViewController.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. @@ -13,60 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Portions of this code is based on Apple Inc's Tabster sample (v1.6) - * which is copyright (C) 2011-2014 Apple Inc. + * Portions of this code is based on Apple Inc's PhotoPicker sample (v2.0) + * which is copyright (C) 2010-2013 Apple Inc. */ - package org.robovm.samples.tabster.viewcontrollers; -import java.util.HashMap; -import java.util.Map; - -import org.robovm.apple.coregraphics.CGRect; -import org.robovm.apple.foundation.NSObjectProtocol; -import org.robovm.apple.uikit.NSLayoutConstraint; -import org.robovm.apple.uikit.NSLayoutFormatOptions; -import org.robovm.apple.uikit.UIColor; -import org.robovm.apple.uikit.UIFont; import org.robovm.apple.uikit.UILabel; import org.robovm.apple.uikit.UINavigationController; -import org.robovm.apple.uikit.UITabBarItem; -import org.robovm.apple.uikit.UITabBarSystemItem; -import org.robovm.apple.uikit.UIView; import org.robovm.apple.uikit.UIViewController; +import org.robovm.objc.annotation.CustomClass; +import org.robovm.objc.annotation.IBOutlet; +@CustomClass("FavoritesViewController") public class FavoritesViewController extends UIViewController { - private final UILabel titleLabel; - - public FavoritesViewController () { - setTabBarItem(new UITabBarItem(UITabBarSystemItem.Favorites, 0)); - - UIView view = getView(); - view.setBackgroundColor(UIColor.fromRGBA(0.77, 1, 1, 1)); - - titleLabel = new UILabel(new CGRect(0, 0, 100, 100)); - titleLabel.setFont(UIFont.getSystemFont(17)); - titleLabel.setText("Favorites"); - titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false); - view.addSubview(titleLabel); - - // Layout - Map views = new HashMap<>(); - views.put("parent", view); - views.put("title", titleLabel); - - view.addConstraints(NSLayoutConstraint.create("H:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterY, null, - views)); - view.addConstraints(NSLayoutConstraint.create("V:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterX, null, - views)); - } + private UILabel titleLabel; @Override - public void viewWillAppear (boolean animated) { + public void viewWillAppear(boolean animated) { super.viewWillAppear(animated); - // if we were navigated to through the More screen table, then we have a navigation bar which - // also means we have a title. So hide the title label in this case, otherwise, we need it + // if we were navigated to through the More screen table, then we have a + // navigation bar which also means we have a title. So hide the title + // label in this case, otherwise, we need it if (getParentViewController() instanceof UINavigationController) { titleLabel.setHidden(true); } else { @@ -74,4 +42,8 @@ public void viewWillAppear (boolean animated) { } } + @IBOutlet + private void setTitleLabel(UILabel titleLabel) { + this.titleLabel = titleLabel; + } } diff --git a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FeaturedViewController.java b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FeaturedViewController.java index 7c5143d9..6c0eefb9 100644 --- a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FeaturedViewController.java +++ b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FeaturedViewController.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. @@ -13,64 +13,37 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Portions of this code is based on Apple Inc's Tabster sample (v1.6) - * which is copyright (C) 2011-2014 Apple Inc. + * Portions of this code is based on Apple Inc's PhotoPicker sample (v2.0) + * which is copyright (C) 2010-2013 Apple Inc. */ - package org.robovm.samples.tabster.viewcontrollers; -import java.util.HashMap; -import java.util.Map; - -import org.robovm.apple.coregraphics.CGRect; -import org.robovm.apple.foundation.NSObjectProtocol; -import org.robovm.apple.uikit.NSLayoutConstraint; -import org.robovm.apple.uikit.NSLayoutFormatOptions; -import org.robovm.apple.uikit.UIColor; -import org.robovm.apple.uikit.UIFont; import org.robovm.apple.uikit.UILabel; import org.robovm.apple.uikit.UINavigationController; -import org.robovm.apple.uikit.UITabBarItem; -import org.robovm.apple.uikit.UITabBarSystemItem; -import org.robovm.apple.uikit.UIView; import org.robovm.apple.uikit.UIViewController; +import org.robovm.objc.annotation.CustomClass; +import org.robovm.objc.annotation.IBOutlet; +@CustomClass("FeaturedViewController") public class FeaturedViewController extends UIViewController { - private final UILabel titleLabel; - - public FeaturedViewController () { - setTabBarItem(new UITabBarItem(UITabBarSystemItem.Featured, 0)); - - UIView view = getView(); - view.setBackgroundColor(UIColor.fromRGBA(0.9, 1, 0.7, 1)); - - titleLabel = new UILabel(new CGRect(0, 0, 100, 100)); - titleLabel.setFont(UIFont.getSystemFont(17)); - titleLabel.setText("Featured"); - titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false); - view.addSubview(titleLabel); - - // Layout - Map views = new HashMap<>(); - views.put("parent", view); - views.put("title", titleLabel); - - view.addConstraints(NSLayoutConstraint.create("H:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterY, null, - views)); - view.addConstraints(NSLayoutConstraint.create("V:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterX, null, - views)); - } + private UILabel titleLabel; @Override - public void viewWillAppear (boolean animated) { + public void viewWillAppear(boolean animated) { super.viewWillAppear(animated); - // if we were navigated to through the More screen table, then we have a navigation bar which - // also means we have a title. So hide the title label in this case, otherwise, we need it + // if we were navigated to through the More screen table, then we have a + // navigation bar which also means we have a title. So hide the title + // label in this case, otherwise, we need it if (getParentViewController() instanceof UINavigationController) { titleLabel.setHidden(true); } else { titleLabel.setHidden(false); } } + + @IBOutlet + private void setTitleLabel(UILabel titleLabel) { + this.titleLabel = titleLabel; + } } diff --git a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FourViewController.java b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FourViewController.java index e7696588..14277e38 100644 --- a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FourViewController.java +++ b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/FourViewController.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. @@ -13,63 +13,53 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Portions of this code is based on Apple Inc's Tabster sample (v1.6) - * which is copyright (C) 2011-2014 Apple Inc. + * Portions of this code is based on Apple Inc's PhotoPicker sample (v2.0) + * which is copyright (C) 2010-2013 Apple Inc. */ - package org.robovm.samples.tabster.viewcontrollers; -import java.util.HashMap; -import java.util.Map; - -import org.robovm.apple.foundation.NSObjectProtocol; -import org.robovm.apple.uikit.NSLayoutConstraint; -import org.robovm.apple.uikit.NSLayoutFormatOptions; -import org.robovm.apple.uikit.UIColor; -import org.robovm.apple.uikit.UIFont; import org.robovm.apple.uikit.UIImage; import org.robovm.apple.uikit.UILabel; import org.robovm.apple.uikit.UINavigationController; import org.robovm.apple.uikit.UITabBarItem; -import org.robovm.apple.uikit.UIView; import org.robovm.apple.uikit.UIViewController; +import org.robovm.objc.annotation.CustomClass; +import org.robovm.objc.annotation.IBOutlet; +@CustomClass("FourViewController") public class FourViewController extends UIViewController { - private final UILabel titleLabel; - - public FourViewController () { - setTabBarItem(new UITabBarItem("Four", UIImage.create("tab4"), 0)); - - UIView view = getView(); - view.setBackgroundColor(UIColor.fromRGBA(0.32, 1, 0.3, 1)); + private UILabel titleLabel; - titleLabel = new UILabel(); - titleLabel.setFont(UIFont.getSystemFont(17)); - titleLabel.setText("FOUR"); - titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false); - view.addSubview(titleLabel); - - // Layout - Map views = new HashMap<>(); - views.put("parent", view); - views.put("title", titleLabel); + /** + * this is called when the UITabBarController loads it's views at launch + * time + */ + @Override + public void awakeFromNib() { + // make our tabbar icon a custom one; + // we could do it in Interface Builder, but this is just to illustrate a + // point about using awakeFromNib vs. viewDidLoad. - view.addConstraints(NSLayoutConstraint.create("H:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterY, null, - views)); - view.addConstraints(NSLayoutConstraint.create("V:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterX, null, - views)); + UITabBarItem customTab = new UITabBarItem("Four", UIImage.create("tab4.png"), 0); + setTabBarItem(customTab); } @Override - public void viewWillAppear (boolean animated) { + public void viewWillAppear(boolean animated) { super.viewWillAppear(animated); - // if we were navigated to through the More screen table, then we have a navigation bar which - // also means we have a title. So hide the title label in this case, otherwise, we need it + // if we were navigated to through the More screen table, then we have a + // navigation bar which also means we have a title. So hide the title + // label in this case, otherwise, we need it if (getParentViewController() instanceof UINavigationController) { titleLabel.setHidden(true); } else { titleLabel.setHidden(false); } } + + @IBOutlet + private void setTitleLabel(UILabel titleLabel) { + this.titleLabel = titleLabel; + } } diff --git a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/LandscapeViewController.java b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/LandscapeViewController.java index 7ecd5348..e6ddccab 100644 --- a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/LandscapeViewController.java +++ b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/LandscapeViewController.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. @@ -13,64 +13,52 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Portions of this code is based on Apple Inc's Tabster sample (v1.6) - * which is copyright (C) 2011-2014 Apple Inc. + * Portions of this code is based on Apple Inc's PhotoPicker sample (v2.0) + * which is copyright (C) 2010-2013 Apple Inc. */ - package org.robovm.samples.tabster.viewcontrollers; -import org.robovm.apple.coregraphics.CGRect; -import org.robovm.apple.uikit.UIButton; -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.foundation.NSObject; import org.robovm.apple.uikit.UIImage; import org.robovm.apple.uikit.UIImageView; import org.robovm.apple.uikit.UIInterfaceOrientationMask; -import org.robovm.apple.uikit.UIView; 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("LandscapeViewController") public class LandscapeViewController extends UIViewController { + private UIImageView imageView; private UIImage image; - private final UIImageView imageView; - - public LandscapeViewController () { - UIView view = getView(); - view.setBackgroundColor(UIColor.white()); - - imageView = new UIImageView(new CGRect(0, 0, 568, 320)); - view.addSubview(imageView); - UIButton button = new UIButton(new CGRect(20, 259, 49, 41)); - button.setImage(UIImage.create("left"), UIControlState.Normal); - button.setImage(UIImage.create("left_pressed"), UIControlState.with(UIControlState.Selected, UIControlState.Highlighted)); - button.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener() { - @Override - public void onTouchUpInside (UIControl control, UIEvent event) { - dismissViewController(false, null); - } - }); - view.addSubview(button); + @IBAction + private void actionCompleted(NSObject sender) { + dismissViewController(false, null); } @Override - public void viewWillAppear (boolean animated) { + public void viewWillAppear(boolean animated) { super.viewWillAppear(animated); imageView.setImage(image); } @Override - public UIInterfaceOrientationMask getSupportedInterfaceOrientations () { + public UIInterfaceOrientationMask getSupportedInterfaceOrientations() { return UIInterfaceOrientationMask.Landscape; } @Override - public boolean shouldAutorotate () { + public boolean shouldAutorotate() { return true; } - public void setImage (UIImage image) { + public void setImage(UIImage image) { this.image = image; } + + @IBOutlet + private void setImageView(UIImageView imageView) { + this.imageView = imageView; + } } diff --git a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/ModalViewController.java b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/ModalViewController.java index eb7e24b9..1b1df225 100644 --- a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/ModalViewController.java +++ b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/ModalViewController.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. @@ -13,74 +13,33 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Portions of this code is based on Apple Inc's Tabster sample (v1.6) - * which is copyright (C) 2011-2014 Apple Inc. + * Portions of this code is based on Apple Inc's PhotoPicker sample (v2.0) + * which is copyright (C) 2010-2013 Apple Inc. */ - package org.robovm.samples.tabster.viewcontrollers; -import java.util.HashMap; -import java.util.Map; - -import org.robovm.apple.foundation.NSObjectProtocol; -import org.robovm.apple.uikit.NSLayoutConstraint; -import org.robovm.apple.uikit.NSLayoutFormatOptions; -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.UILabel; -import org.robovm.apple.uikit.UIView; import org.robovm.apple.uikit.UIViewController; +import org.robovm.objc.annotation.CustomClass; +import org.robovm.objc.annotation.IBOutlet; +@CustomClass("ModalViewController") public class ModalViewController extends UIViewController { private SubLevelViewController owningViewController; - private final UILabel titleLabel; - - public ModalViewController () { - UIView view = getView(); - view.setBackgroundColor(UIColor.white()); - - titleLabel = new UILabel(); - titleLabel.setFont(UIFont.getSystemFont(17)); - titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false); - view.addSubview(titleLabel); - - UIButton button = UIButton.create(UIButtonType.RoundedRect); - button.setTitle("Done", UIControlState.Normal); - button.setTitleShadowColor(UIColor.fromWhiteAlpha(0.5, 1), UIControlState.Normal); - button.setTranslatesAutoresizingMaskIntoConstraints(false); - button.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener() { - @Override - public void onTouchUpInside (UIControl control, UIEvent event) { - dismissViewController(true, null); - } - }); - view.addSubview(button); - - // Layout - Map views = new HashMap<>(); - views.put("parent", view); - views.put("title", titleLabel); - views.put("done", button); - - view.addConstraints(NSLayoutConstraint.create("H:[parent]-(<=1)-[title]", NSLayoutFormatOptions.AlignAllCenterY, null, - views)); - view.addConstraints(NSLayoutConstraint.create("V:[parent]-(<=1)-[title]-33-[done]", - NSLayoutFormatOptions.AlignAllCenterX, null, views)); - } + private UILabel titleLabel; @Override - public void viewWillAppear (boolean animated) { + public void viewWillAppear(boolean animated) { super.viewWillAppear(animated); - titleLabel.setText(owningViewController.getCurrentSelectionTitle()); } - public void setOwningViewController (SubLevelViewController owningViewController) { + public void setOwningViewController(SubLevelViewController owningViewController) { this.owningViewController = owningViewController; } + + @IBOutlet + private void setTitleLabel(UILabel titleLabel) { + this.titleLabel = titleLabel; + } } diff --git a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/OneViewController.java b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/OneViewController.java index 77e5e707..8fb820f2 100644 --- a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/OneViewController.java +++ b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/OneViewController.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. @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Portions of this code is based on Apple Inc's Tabster sample (v1.6) - * which is copyright (C) 2011-2014 Apple Inc. + * Portions of this code is based on Apple Inc's PhotoPicker sample (v2.0) + * which is copyright (C) 2010-2013 Apple Inc. */ - package org.robovm.samples.tabster.viewcontrollers; import java.util.ArrayList; @@ -24,72 +23,56 @@ import java.util.List; import org.robovm.apple.foundation.NSIndexPath; -import org.robovm.apple.uikit.UIColor; +import org.robovm.apple.foundation.NSObject; +import org.robovm.apple.uikit.UIStoryboardSegue; import org.robovm.apple.uikit.UITableView; import org.robovm.apple.uikit.UITableViewCell; -import org.robovm.apple.uikit.UITableViewCellAccessoryType; -import org.robovm.apple.uikit.UITableViewCellStyle; import org.robovm.apple.uikit.UITableViewController; -import org.robovm.apple.uikit.UITableViewDataSourceAdapter; -import org.robovm.apple.uikit.UITableViewDelegateAdapter; +import org.robovm.objc.annotation.CustomClass; +@CustomClass("OneViewController") public class OneViewController extends UITableViewController { - private final List dataList; - private SubLevelViewController subLevelViewController; - - public OneViewController () { - dataList = new ArrayList<>(Arrays.asList("Mac Pro", "Mac mini", "iMac", "MacBook", "MacBook Pro", "MacBook Air")); - - subLevelViewController = new SubLevelViewController(); - - UITableView tableView = getTableView(); - tableView.setAlwaysBounceVertical(true); - tableView.setBackgroundColor(UIColor.white()); - tableView.setDataSource(new UITableViewDataSourceAdapter() { - @Override - public long getNumberOfRowsInSection (UITableView tableView, long section) { - return dataList.size(); - } - - @Override - public UITableViewCell getCellForRow (UITableView tableView, NSIndexPath indexPath) { - final String cellID = "cellID"; - - UITableViewCell cell = tableView.dequeueReusableCell(cellID); - if (cell == null) { - cell = new UITableViewCell(UITableViewCellStyle.Default, cellID); - cell.setAccessoryType(UITableViewCellAccessoryType.DisclosureIndicator); - } - cell.getTextLabel().setText(dataList.get((int)indexPath.getRow())); - - return cell; - } - }); - tableView.setDelegate(new UITableViewDelegateAdapter() { - @Override - public void didSelectRow (UITableView tableView, NSIndexPath indexPath) { - UITableViewCell cell = tableView.getCellForRow(indexPath); - subLevelViewController.setTitle(cell.getTextLabel().getText()); - - getNavigationController().pushViewController(subLevelViewController, true); - } - }); + private List dataList; + @Override + public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) { + if (segue.getIdentifier().equals("SubLevelSegue")) { + SubLevelViewController subLevelViewController = (SubLevelViewController) segue + .getDestinationViewController(); + UITableViewCell cell = (UITableViewCell) sender; + subLevelViewController.setTitle(cell.getTextLabel().getText()); + } } @Override - public void viewDidLoad () { + public void viewDidLoad() { super.viewDidLoad(); - - getNavigationItem().setTitle("One"); + dataList = new ArrayList<>( + Arrays.asList("Mac Pro", "Mac mini", "iMac", "MacBook", "MacBook Pro", "MacBook Air")); } @Override - public void viewWillAppear (boolean animated) { + public void viewWillAppear(boolean animated) { super.viewWillAppear(animated); - // this UIViewController is about to re-appear, make sure we remove the current selection in our table view + // this UIViewController is about to re-appear, make sure we remove the + // current selection in our table view NSIndexPath tableSelection = getTableView().getIndexPathForSelectedRow(); getTableView().deselectRow(tableSelection, false); } + + @Override + public long getNumberOfRowsInSection(UITableView tableView, long section) { + return dataList.size(); + } + + @Override + public UITableViewCell getCellForRow(UITableView tableView, NSIndexPath indexPath) { + final String cellID = "cellID"; + + UITableViewCell cell = tableView.dequeueReusableCell(cellID); + cell.getTextLabel().setText(dataList.get((int) indexPath.getRow())); + + return cell; + } } diff --git a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/SubLevelViewController.java b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/SubLevelViewController.java index b9acf607..feb1b807 100644 --- a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/SubLevelViewController.java +++ b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/SubLevelViewController.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. @@ -13,75 +13,70 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Portions of this code is based on Apple Inc's Tabster sample (v1.6) - * which is copyright (C) 2011-2014 Apple Inc. + * Portions of this code is based on Apple Inc's PhotoPicker sample (v2.0) + * which is copyright (C) 2010-2013 Apple Inc. */ - package org.robovm.samples.tabster.viewcontrollers; import java.util.Arrays; import java.util.List; import org.robovm.apple.foundation.NSIndexPath; +import org.robovm.apple.foundation.NSObject; +import org.robovm.apple.uikit.UIStoryboardSegue; import org.robovm.apple.uikit.UITableView; import org.robovm.apple.uikit.UITableViewCell; -import org.robovm.apple.uikit.UITableViewCellAccessoryType; -import org.robovm.apple.uikit.UITableViewCellSelectionStyle; -import org.robovm.apple.uikit.UITableViewCellStyle; import org.robovm.apple.uikit.UITableViewController; -import org.robovm.apple.uikit.UITableViewDataSourceAdapter; -import org.robovm.apple.uikit.UITableViewDelegateAdapter; +import org.robovm.objc.annotation.CustomClass; +import org.robovm.objc.annotation.IBAction; +@CustomClass("SubLevelViewController") public class SubLevelViewController extends UITableViewController { private String currentSelectionTitle; private List dataList; - private ModalViewController modalViewController; - public SubLevelViewController () { + @Override + public void viewDidLoad() { + super.viewDidLoad(); dataList = Arrays.asList("Feature 1", "Feature 2"); + } + + @Override + public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) { + if (segue.getIdentifier().equals("modalSegue")) { + ModalViewController modalViewController = (ModalViewController) segue.getDestinationViewController(); + modalViewController.setOwningViewController(this); + UITableViewCell cell = (UITableViewCell) sender; + currentSelectionTitle = cell.getTextLabel().getText(); + } + } - UITableView tableView = getTableView(); - tableView.setAlwaysBounceVertical(true); - tableView.setDelegate(new UITableViewDelegateAdapter() { - @Override - public void didSelectRow (UITableView tableView, NSIndexPath indexPath) { - tableView.deselectRow(indexPath, false); - } + @Override + public void didSelectRow(UITableView tableView, NSIndexPath indexPath) { + tableView.deselectRow(indexPath, false); + } + + @Override + public long getNumberOfRowsInSection(UITableView tableView, long section) { + return dataList.size(); + } - @Override - public void accessoryButtonTapped (UITableView tableView, NSIndexPath indexPath) { - modalViewController.setOwningViewController(SubLevelViewController.this); - UITableViewCell cell = tableView.getCellForRow(indexPath); - currentSelectionTitle = cell.getTextLabel().getText(); - presentViewController(modalViewController, true, null); - } - }); - tableView.setDataSource(new UITableViewDataSourceAdapter() { - @Override - public long getNumberOfRowsInSection (UITableView tableView, long section) { - return dataList.size(); - } + @Override + public UITableViewCell getCellForRow(UITableView tableView, NSIndexPath indexPath) { + String cellID2 = "cellID2"; - @Override - public UITableViewCell getCellForRow (UITableView tableView, NSIndexPath indexPath) { - final String identifier = "cellID2"; + UITableViewCell cell = tableView.dequeueReusableCell(cellID2); + cell.getTextLabel().setText(dataList.get((int) indexPath.getRow())); - UITableViewCell cell = tableView.dequeueReusableCell(identifier); - if (cell == null) { - cell = new UITableViewCell(UITableViewCellStyle.Default, identifier); - cell.setAccessoryType(UITableViewCellAccessoryType.DetailDisclosureButton); - cell.setSelectionStyle(UITableViewCellSelectionStyle.Blue); - } - cell.getTextLabel().setText(dataList.get((int)indexPath.getRow())); + return cell; + } - return cell; - } - }); + @IBAction + private void unwindToSub(UIStoryboardSegue unwindSegue) { - modalViewController = new ModalViewController(); } - public String getCurrentSelectionTitle () { + public String getCurrentSelectionTitle() { return currentSelectionTitle; } } diff --git a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/ThreeViewController.java b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/ThreeViewController.java index c81b6a94..055cfff3 100644 --- a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/ThreeViewController.java +++ b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/ThreeViewController.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. @@ -13,128 +13,110 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Portions of this code is based on Apple Inc's Tabster sample (v1.6) - * which is copyright (C) 2011-2014 Apple Inc. + * Portions of this code is based on Apple Inc's PhotoPicker sample (v2.0) + * which is copyright (C) 2010-2013 Apple Inc. */ - package org.robovm.samples.tabster.viewcontrollers; -import java.util.HashMap; -import java.util.Map; - -import org.robovm.apple.foundation.NSObjectProtocol; import org.robovm.apple.foundation.NSRange; -import org.robovm.apple.foundation.NSString; import org.robovm.apple.foundation.NSUserDefaults; -import org.robovm.apple.uikit.NSLayoutConstraint; -import org.robovm.apple.uikit.NSLayoutFormatOptions; import org.robovm.apple.uikit.UIBarButtonItem; import org.robovm.apple.uikit.UIBarButtonSystemItem; -import org.robovm.apple.uikit.UIColor; -import org.robovm.apple.uikit.UIFont; -import org.robovm.apple.uikit.UIKeyboardType; -import org.robovm.apple.uikit.UILabel; -import org.robovm.apple.uikit.UITextBorderStyle; import org.robovm.apple.uikit.UITextField; -import org.robovm.apple.uikit.UITextFieldDelegateAdapter; -import org.robovm.apple.uikit.UIView; +import org.robovm.apple.uikit.UITextFieldDelegate; import org.robovm.apple.uikit.UIViewController; +import org.robovm.objc.annotation.CustomClass; +import org.robovm.objc.annotation.IBOutlet; -public class ThreeViewController extends UIViewController { - private static final String BADGE_VALUE_PREF_KEY = "BadgeValue"; // badge value key for storing to NSUserDefaults +@CustomClass("ThreeViewController") +public class ThreeViewController extends UIViewController implements UITextFieldDelegate { + // badge value key for storing to NSUserDefaults + private static final String BADGE_VALUE_PREF_KEY = "BadgeValue"; + private UITextField badgeField; private UIBarButtonItem doneButton; - private final UITextField badgeField; - - public ThreeViewController () { - UIView view = getView(); - view.setBackgroundColor(UIColor.fromWhiteAlpha(0.66, 1)); - - badgeField = new UITextField(); - badgeField.setBorderStyle(UITextBorderStyle.RoundedRect); - badgeField.setFont(UIFont.getSystemFont(14)); - badgeField.setKeyboardType(UIKeyboardType.NumberPad); - badgeField.setTranslatesAutoresizingMaskIntoConstraints(false); - badgeField.setDelegate(new UITextFieldDelegateAdapter() { - @Override - public void didBeginEditing (UITextField textField) { - // user is starting to edit, add the done button to the navigation bar - getNavigationItem().setRightBarButtonItem(doneButton); - } - - @Override - public void didEndEditing (UITextField textField) { - // user is done editing, remove the done button from the navigation bar - getNavigationItem().setRightBarButtonItem(null); - } - - @Override - public boolean shouldChangeCharacters (UITextField textField, NSRange range, String string) { - boolean result = true; - - // restrict the maximum number of characters to 5 - if (textField.getText().length() == 5 && string.length() > 0) { - result = false; - } - - return result; - } - }); - view.addSubview(badgeField); - - UILabel valueLabel = new UILabel(); - valueLabel.setText("Value"); - valueLabel.setTranslatesAutoresizingMaskIntoConstraints(false); - valueLabel.setFont(UIFont.getSystemFont(17)); - valueLabel.setTextColor(UIColor.darkText()); - view.addSubview(valueLabel); - // Layout - Map views = new HashMap<>(); - views.put("value", valueLabel); - views.put("badge", badgeField); - views.put("top", getTopLayoutGuide()); + @Override + public void viewDidLoad() { + super.viewDidLoad(); - view.addConstraints(NSLayoutConstraint.create("H:|-20-[value(48)]-[badge]-20-|", NSLayoutFormatOptions.None, null, views)); - view.addConstraints(NSLayoutConstraint.create("V:[top]-58-[value]", NSLayoutFormatOptions.None, null, views)); - view.addConstraints(NSLayoutConstraint.create("V:[top]-54-[badge]", NSLayoutFormatOptions.None, null, views)); + // set the badge value in our test field and tabbar item + String badgeValue = NSUserDefaults.getStandardUserDefaults().getString(BADGE_VALUE_PREF_KEY); doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, new UIBarButtonItem.OnClickListener() { @Override - public void onClick (UIBarButtonItem barButtonItem) { - // dismiss the keyboard by resigning our badge edit field as first responder + public void onClick(UIBarButtonItem barButtonItem) { + // dismiss the keyboard by resigning our badge edit field as + // first responder badgeField.resignFirstResponder(); - // set the badge value to our tab item (but only if a valid string) - if (badgeField.getText().length() > 0) { + // set the badge value to our tab item (but only if a valid + // string) + if (badgeField.getText() != null && badgeField.getText().length() > 0) { // a value was entered, // because we are inside a navigation controller, - // we must access its tabBarItem to set the badgeValue. + // we must access its tabBarItem to set the badgeValue getNavigationController().getTabBarItem().setBadgeValue(badgeField.getText()); } else { // no value was entered getNavigationController().getTabBarItem().setBadgeValue(null); } - NSUserDefaults.getStandardUserDefaults().put(BADGE_VALUE_PREF_KEY, new NSString(badgeField.getText())); + NSUserDefaults.getStandardUserDefaults().put(BADGE_VALUE_PREF_KEY, badgeField.getText()); } }); + + if (badgeValue != null && badgeValue.length() > 0) { + badgeField.setText(badgeValue); + getNavigationController().getTabBarItem().setBadgeValue(badgeField.getText()); + } } @Override - public void viewDidLoad () { - super.viewDidLoad(); + public void didBeginEditing(UITextField textField) { + // user is starting to edit, add the done button to the navigation bar + getNavigationItem().setRightBarButtonItem(doneButton); + } - getNavigationItem().setTitle("Three"); + @Override + public void didEndEditing(UITextField textField) { + // user is done editing, remove the done button from the navigation bar + getNavigationItem().setRightBarButtonItem(null); } @Override - public void viewWillAppear (boolean animated) { - // set the badge value in our test field and tabbar item - String badgeValue = NSUserDefaults.getStandardUserDefaults().getString(BADGE_VALUE_PREF_KEY); - if (badgeValue != null && badgeValue.length() != 0) { - badgeField.setText(badgeValue); - getNavigationController().getTabBarItem().setBadgeValue(badgeField.getText()); - } + public boolean shouldChangeCharacters(UITextField textField, NSRange range, String string) { + boolean result = true; + + // restrict the maximum number of characters to 5 + if (textField.getText().length() == 5 && string.length() > 0) + result = false; + + return result; + } + + @Override + public boolean shouldBeginEditing(UITextField textField) { + return true; + } + + @Override + public boolean shouldEndEditing(UITextField textField) { + return true; + } + + @Override + public boolean shouldClear(UITextField textField) { + return true; + } + + @Override + public boolean shouldReturn(UITextField textField) { + return true; + } + + @IBOutlet + private void setBadgeField(UITextField badgeField) { + this.badgeField = badgeField; } } diff --git a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/TwoViewController.java b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/TwoViewController.java index a86394a5..1d659f46 100644 --- a/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/TwoViewController.java +++ b/Tabster/src/main/java/org/robovm/samples/tabster/viewcontrollers/TwoViewController.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. @@ -13,80 +13,61 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Portions of this code is based on Apple Inc's Tabster sample (v1.6) - * which is copyright (C) 2011-2014 Apple Inc. + * Portions of this code is based on Apple Inc's PhotoPicker sample (v2.0) + * which is copyright (C) 2010-2013 Apple Inc. */ - package org.robovm.samples.tabster.viewcontrollers; import java.util.Arrays; import java.util.List; import org.robovm.apple.foundation.NSIndexPath; -import org.robovm.apple.uikit.UIColor; +import org.robovm.apple.foundation.NSObject; import org.robovm.apple.uikit.UIImage; +import org.robovm.apple.uikit.UIStoryboardSegue; import org.robovm.apple.uikit.UITableView; import org.robovm.apple.uikit.UITableViewCell; -import org.robovm.apple.uikit.UITableViewCellAccessoryType; -import org.robovm.apple.uikit.UITableViewCellStyle; import org.robovm.apple.uikit.UITableViewController; -import org.robovm.apple.uikit.UITableViewDataSourceAdapter; -import org.robovm.apple.uikit.UITableViewDelegateAdapter; +import org.robovm.objc.annotation.CustomClass; +@CustomClass("TwoViewController") public class TwoViewController extends UITableViewController { - private final List dataList; - private LandscapeViewController landscapeViewController; + private List dataList; - public TwoViewController () { + @Override + public void viewDidLoad() { + super.viewDidLoad(); dataList = Arrays.asList("Cherry Lake", "Lake Don Pedro"); + } - landscapeViewController = new LandscapeViewController(); - - UITableView tableView = getTableView(); - tableView.setAlwaysBounceVertical(true); - tableView.setBackgroundColor(UIColor.white()); - tableView.setDataSource(new UITableViewDataSourceAdapter() { - @Override - public long getNumberOfRowsInSection (UITableView tableView, long section) { - return dataList.size(); - } - - @Override - public UITableViewCell getCellForRow (UITableView tableView, NSIndexPath indexPath) { - final String cellID = "cellIDTwo"; + @Override + public long getNumberOfRowsInSection(UITableView tableView, long section) { + return dataList.size(); + } - UITableViewCell cell = tableView.dequeueReusableCell(cellID); - if (cell == null) { - cell = new UITableViewCell(UITableViewCellStyle.Default, cellID); - cell.setAccessoryType(UITableViewCellAccessoryType.DisclosureIndicator); - } - cell.getTextLabel().setText(dataList.get((int)indexPath.getRow())); + @Override + public UITableViewCell getCellForRow(UITableView tableView, NSIndexPath indexPath) { + String cellID = "cellIDTwo"; - return cell; - } - }); - tableView.setDelegate(new UITableViewDelegateAdapter() { - @Override - public void didSelectRow (UITableView tableView, NSIndexPath indexPath) { - UITableViewCell cell = tableView.getCellForRow(indexPath); - UIImage image = null; - String text = cell.getTextLabel().getText(); - if (text.equals("Cherry Lake")) { - image = UIImage.create("cherrylake"); - } else if (text.equals("Lake Don Pedro")) { - image = UIImage.create("lakedonpedro"); - } - landscapeViewController.setImage(image); - presentViewController(landscapeViewController, true, null); - } - }); + UITableViewCell cell = tableView.dequeueReusableCell(cellID); + cell.getTextLabel().setText(dataList.get((int) indexPath.getRow())); + return cell; } @Override - public void viewDidLoad () { - super.viewDidLoad(); - - getNavigationItem().setTitle("Two"); + public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) { + if (segue.getIdentifier().equals("LandscapeViewSegue")) { + LandscapeViewController landscapeViewController = (LandscapeViewController) segue + .getDestinationViewController(); + UITableViewCell cell = (UITableViewCell) sender; + UIImage image = null; + if (cell.getTextLabel().getText().equals("Cherry Lake")) { + image = UIImage.create("cherrylake"); + } else if (cell.getTextLabel().getText().equals("Lake Don Pedro")) { + image = UIImage.create("lakedonpedro"); + } + landscapeViewController.setImage(image); + } } }