{"id":413,"date":"2016-06-02T20:37:45","date_gmt":"2016-06-02T19:37:45","guid":{"rendered":"http:\/\/jonika.nu\/JonasBlogg\/?p=413"},"modified":"2016-06-02T20:44:11","modified_gmt":"2016-06-02T19:44:11","slug":"am-i-the-only-one-who-rewrites-the-same-project-over-and-over-again","status":"publish","type":"post","link":"https:\/\/jonika.nu\/JonasBlogg\/archives\/413","title":{"rendered":"Am i the only one who rewrites the same project over and over again? :)"},"content":{"rendered":"<p>Am I the only one why keeps rewriting the same code, over and over again, while learning new languages or plattforms?<\/p>\n<p>For me, it&#8217;s mainly because i hate to run Hello world examples\u00a0or create meaningless projects. Because of that, my hobby project <a href=\"http:\/\/jonika.nu\/JonasBlogg\/hobbyprojects\/natuicalc\">NautiCalc<\/a> (you can find i web version <a href=\"http:\/\/jonika.nu\/NautiCalc\">right here<\/a>) has been rewritten in PHP, Objective-C, Java, Javascript \u00a0on plattforms like iOS, Android, Web\u00a0and\u00a0OS X.<\/p>\n<p>And now, it&#8217;s time again! Last week I\u00a0attended to DevSum 2016, and I\u00a0got totally hooked by\u00a0Xamarin! Time to build a cross-plattform version, running on iOS and Android!<\/p>\n<p>After 3-4 days of coding with Xamarin on my Mac, my first reactions are:<\/p>\n<ul>\n<li>Xamarin studio is surprisingly \u00a0complete, and supports pretty much everything you need!<\/li>\n<li>Creating UI in XAML is really nice! I&#8217;ve missed it since i dropped Silverlight.<\/li>\n<li>Xamarin.Forms is really nice and makes it easy to write cross-plattform apps. The best thing is that it maps to native components for each plattform.<\/li>\n<li>The built-in dependency injection adds to that!<\/li>\n<\/ul>\n<h2>NautiCalc in Xamarin<\/h2>\n<p>So, my main screen is built up by a TabbedPage built with XAML. In this page all i do is adding my namespace, so i can reference separate pages for each tab, instead of have one huge XAML file.<\/p>\n<pre class=\"lang:xhtml decode:true \">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;TabbedPage xmlns=\"http:\/\/xamarin.com\/schemas\/2014\/forms\" xmlns:me=\"clr-namespace:NautiCalc;assembly=NautiCalc\" xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2009\/xaml\" x:Class=\"NautiCalc.TabbedMainPage\"&gt;\r\n\t&lt;TabbedPage.Children&gt;\r\n\t\t&lt;me:NavigatePage \/&gt;\r\n\t\t&lt;me:WeatherPage \/&gt;\r\n\t\t&lt;me:CalculatePage \/&gt;\r\n\t\t&lt;me:AboutPage \/&gt;\r\n\t&lt;\/TabbedPage.Children&gt;\r\n&lt;\/TabbedPage&gt;<\/pre>\n<p>The TabbedPage render native navigation menus for each plattform. IT works with Windows as well, but who cares about Windows phones?<\/p>\n<p>Below you can see the about page on Android and iOS, where the navigation is created by the XAML in my TabbedPage. The Android version lacks graphics at this moment,<\/p>\n<p><a href=\"http:\/\/jonika.nu\/JonasBlogg\/archives\/413\/androidaboutscreen\" rel=\"attachment wp-att-419\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-419 aligncenter\" src=\"http:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/AndroidAboutScreen.png\" alt=\"AndroidAboutScreen\" width=\"370\" height=\"654\" srcset=\"https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/AndroidAboutScreen.png 856w, https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/AndroidAboutScreen-170x300.png 170w, https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/AndroidAboutScreen-768x1357.png 768w, https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/AndroidAboutScreen-580x1024.png 580w\" sizes=\"(max-width: 370px) 100vw, 370px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/jonika.nu\/JonasBlogg\/archives\/413\/iosaboutscreen\" rel=\"attachment wp-att-420\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-420 aligncenter\" src=\"http:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/iOSAboutScreen.png\" alt=\"iOSAboutScreen\" width=\"370\" height=\"658\" srcset=\"https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/iOSAboutScreen.png 750w, https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/iOSAboutScreen-169x300.png 169w, https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/iOSAboutScreen-576x1024.png 576w\" sizes=\"(max-width: 370px) 100vw, 370px\" \/><\/a><\/p>\n<p>The XAML for the about page above is also the same on both plattforms. There&#8217;s only one thing thats different on each plattform, and that is the margins:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;ContentPage Icon=\"Nauticalc_24.png\" Title=\"AboutPage\" xmlns=\"http:\/\/xamarin.com\/schemas\/2014\/forms\" xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2009\/xaml\" x:Class=\"NautiCalc.AboutPage\"&gt;\r\n\t&lt;ContentPage.Padding&gt;\r\n\t\t&lt;OnPlatform x:TypeArguments=\"Thickness\"&gt;\r\n\t\t\t&lt;OnPlatform.iOS&gt;\r\n\t\t\t\t15,120,5,0\r\n\t\t\t&lt;\/OnPlatform.iOS&gt;\r\n\t\t\t&lt;OnPlatform.Android&gt;\r\n\t\t\t\t15,100,5,0\r\n\t\t\t&lt;\/OnPlatform.Android&gt;\r\n\t\t&lt;\/OnPlatform&gt;\r\n\t&lt;\/ContentPage.Padding&gt;\r\n\t&lt;StackLayout&gt;\r\n\t\t&lt;StackLayout Padding=\"15,0,15,0\"&gt;\r\n\t\t\t&lt;Image Source=\"Nauticalc_72.png\" \/&gt;\r\n\t\t\t&lt;Label FontSize=\"24\" Margin=\"0,25,0,25\" FontAttributes=\"Bold\" Text=\"NautiCalc\" HorizontalOptions=\"Center\" VerticalOptions=\"Center\" \/&gt;\r\n\t\t\t&lt;Label Font=\"Small\" Text=\"Helps you navigate at sea. Keeps track at your speed, course and position and helps you calculate how fast you need to go, how far you can reach in a certain time and what distance you cover at a certain speed and time\" \/&gt;\r\n\t\t&lt;\/StackLayout&gt;\r\n\t\t&lt;StackLayout Padding=\"15,50,15,0\" Orientation=\"Horizontal\"&gt;\r\n\t\t\t&lt;Label Text=\"Twitter:\" VerticalOptions=\"Center\" \/&gt;\r\n\t\t\t&lt;Label Text=\"@jonlin76\" TextColor=\"Blue\" x:Name=\"JonikaTwitter\" VerticalOptions=\"Center\" HorizontalOptions=\"EndAndExpand\" \/&gt;\r\n\t\t&lt;\/StackLayout&gt;\r\n\t\t&lt;StackLayout Padding=\"15,0,15,0\" Orientation=\"Horizontal\"&gt;\r\n\t\t\t&lt;Label Text=\"E-mail:\" VerticalOptions=\"Center\" \/&gt;\r\n\t\t\t&lt;Label Text=\"jonas@jonika.nu\" TextColor=\"Blue\" x:Name=\"JonikaMail\" VerticalOptions=\"Center\" HorizontalOptions=\"EndAndExpand\" \/&gt;\r\n\t\t&lt;\/StackLayout&gt;\r\n\t\t&lt;StackLayout Padding=\"15,0,15,0\" Orientation=\"Horizontal\"&gt;\r\n\t\t\t&lt;Label Text=\"Blogg:\" VerticalOptions=\"Center\" \/&gt;\r\n\t\t\t&lt;Label Text=\"http:\/\/jonika.nu\/JonasBlogg\/\" x:Name=\"JonikaBlogg\" TextColor=\"Blue\" VerticalOptions=\"Center\" HorizontalOptions=\"EndAndExpand\" \/&gt;\r\n\t\t&lt;\/StackLayout&gt;\r\n\t&lt;\/StackLayout&gt;\r\n&lt;\/ContentPage&gt;<\/pre>\n<p>And, off course, there&#8217;s a small code behind as well. We need to add a GestureRecognizer to enable click on the hyperlinks:<\/p>\n<pre class=\"lang:c# decode:true \">\t\tpublic AboutPage ()\r\n\t\t{\r\n\t\t\tInitializeComponent ();\r\n\r\n\t\t\tTapGestureRecognizer tapRec = new TapGestureRecognizer ();\r\n\t\t\ttapRec.Tapped += (object sender, EventArgs e) =&gt; {\r\n\t\t\t\tif (sender.Equals (JonikaTwitter))\r\n\t\t\t\t\tDevice.OpenUri (new Uri (\"https:\/\/twitter.com\/jonlin76\"));\r\n\t\t\t\tif (sender.Equals (JonikaMail))\r\n\t\t\t\t\tDevice.OpenUri (new Uri (\"mailto:jonas@jonika.nu\"));\r\n\t\t\t\tif (sender.Equals (JonikaBlogg))\r\n\t\t\t\t\tDevice.OpenUri (new Uri (\"http:\/\/www.jonika.nu\/JonasBlogg\"));\r\n\t\t\t};\r\n\r\n\t\t\tJonikaBlogg.GestureRecognizers.Add (tapRec);\r\n\t\t\tJonikaMail.GestureRecognizers.Add (tapRec);\r\n\t\t\tJonikaTwitter.GestureRecognizers.Add (tapRec);\r\n\t\t}<\/pre>\n<p>My NavigationPage (the main screen in the app) uses Xamarin.Forms.Maps. This package has to be installed from NuGet, and it also requires some initiation and for Android som configuration like API key. When that is done, map component renders Apple Maps on iOS, Google Maps on Android and Bing Maps on Windows. All with the same code!<\/p>\n<p><a href=\"http:\/\/jonika.nu\/JonasBlogg\/archives\/413\/iosnavigationscreen\" rel=\"attachment wp-att-424\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-424\" src=\"http:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/iOSNavigationScreen.png\" alt=\"iOSNavigationScreen\" width=\"359\" height=\"638\" srcset=\"https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/iOSNavigationScreen.png 750w, https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/iOSNavigationScreen-169x300.png 169w, https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/iOSNavigationScreen-576x1024.png 576w\" sizes=\"(max-width: 359px) 100vw, 359px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/jonika.nu\/JonasBlogg\/archives\/413\/androidnavigationpage\" rel=\"attachment wp-att-425\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-425\" src=\"http:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/AndroidNavigationPage.png\" alt=\"AndroidNavigationPage\" width=\"359\" height=\"638\" srcset=\"https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/AndroidNavigationPage.png 360w, https:\/\/jonika.nu\/JonasBlogg\/wp-content\/uploads\/2016\/06\/AndroidNavigationPage-169x300.png 169w\" sizes=\"(max-width: 359px) 100vw, 359px\" \/><\/a><\/p>\n<p>Cross-plattform have never been easier, and ism deeply impressed by both Xamarin Studio and the framework!<\/p>\n<p>Time will tell if the app finishes, or maybe i&#8217;ll change my mind and rewrites this project before it gets done. Who knows \ud83d\ude42<\/p>\n<a href=\"https:\/\/twitter.com\/jonlin76\" class=\"twitter-follow-button\" data-show-count=\"false\" data-size=\"small\">Follow jonlin76<\/a>\n<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=\/^http:\/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+':\/\/platform.twitter.com\/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');<\/script>","protected":false},"excerpt":{"rendered":"<p>Am I the only one why keeps rewriting the same code, over and over again, while learning new languages or plattforms? For me, it&#8217;s mainly because i hate to run Hello world examples\u00a0or create meaningless projects. Because of that, my hobby project NautiCalc (you can find i web version right here) has been rewritten in &hellip; <a href=\"https:\/\/jonika.nu\/JonasBlogg\/archives\/413\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Am i the only one who rewrites the same project over and over again? \ud83d\ude42<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59,38],"tags":[43,99,42,98,82,97],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/jonika.nu\/JonasBlogg\/wp-json\/wp\/v2\/posts\/413"}],"collection":[{"href":"https:\/\/jonika.nu\/JonasBlogg\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jonika.nu\/JonasBlogg\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jonika.nu\/JonasBlogg\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jonika.nu\/JonasBlogg\/wp-json\/wp\/v2\/comments?post=413"}],"version-history":[{"count":13,"href":"https:\/\/jonika.nu\/JonasBlogg\/wp-json\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":431,"href":"https:\/\/jonika.nu\/JonasBlogg\/wp-json\/wp\/v2\/posts\/413\/revisions\/431"}],"wp:attachment":[{"href":"https:\/\/jonika.nu\/JonasBlogg\/wp-json\/wp\/v2\/media?parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jonika.nu\/JonasBlogg\/wp-json\/wp\/v2\/categories?post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jonika.nu\/JonasBlogg\/wp-json\/wp\/v2\/tags?post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}