<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cats &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/cat/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Tue, 01 Oct 2024 15:31:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Android Tablet Support</title>
		<link>https://blog.xojo.com/2024/10/01/android-tablet-support/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Tue, 01 Oct 2024 15:31:26 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[2024r3]]></category>
		<category><![CDATA[Cats]]></category>
		<category><![CDATA[Layout Editor]]></category>
		<category><![CDATA[Tablet]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=13552</guid>

					<description><![CDATA[Android apps made with Xojo have always worked on tablets, but until Xojo 2024r3 there has been no easy way to design your screens for&#8230;]]></description>
										<content:encoded><![CDATA[
<p>Android apps made with Xojo have always worked on tablets, but until Xojo 2024r3 there has been no easy way to design your screens for tablets. Below are the new features that should make it easier to create Android tablet apps.</p>



<h2 class="wp-block-heading">Layout Editor</h2>



<p>The Layout Editor has been enhanced with two settings that can adjust the layout.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="288" height="62" src="https://blog.xojo.com/wp-content/uploads/2024/08/image-4.png" alt="" class="wp-image-13553"/></figure>



<p>The command bar has two toggle buttons. The first one already existed and it is for displaying the layout in portrait (the default) or landscape.</p>



<p>The new toggle button displays the layout in a phone size (the default) or a tablet size. When you switch between any of these toggles, the locking is applied to the controls on the layout.</p>



<p>The layout editor also remembers the selections so that the next time you visit the layout, it will be where you left it. Here you can see a landscape tablet layout:</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="793" src="https://blog.xojo.com/wp-content/uploads/2024/08/image-5-1024x793.png" alt="" class="wp-image-13554" srcset="https://blog.xojo.com/wp-content/uploads/2024/08/image-5-1024x793.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/08/image-5-300x232.png 300w, https://blog.xojo.com/wp-content/uploads/2024/08/image-5-768x595.png 768w, https://blog.xojo.com/wp-content/uploads/2024/08/image-5-1536x1189.png 1536w, https://blog.xojo.com/wp-content/uploads/2024/08/image-5-2048x1585.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">Default Screen</h2>



<p>The App Inspector has an additional Default Tablet Screen property. When your app is launched on a phone or tablet-sized device, the specified screen is what gets displayed.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="634" height="218" src="https://blog.xojo.com/wp-content/uploads/2024/08/image-6.png" alt="" class="wp-image-13555" srcset="https://blog.xojo.com/wp-content/uploads/2024/08/image-6.png 634w, https://blog.xojo.com/wp-content/uploads/2024/08/image-6-300x103.png 300w" sizes="(max-width: 634px) 100vw, 634px" /></figure>



<p>You can also choose &#8220;None&#8221; for a default screen if you just want to share a single screen across both types of devices.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>If you choose &#8220;None&#8221; for the Default Phone Screen, then the app won&#8217;t launch on a phone. If you choose &#8220;None&#8221; for a Default Tablet Screen, the app will launch on the tablet using the Default Phone Screen, which matches prior behavior.</p>
</blockquote>



<h2 class="wp-block-heading">Design Considerations</h2>



<p>Xojo for Android uses locking to automatically adjust controls on the layout. Locking will work for certain types of layouts that you want to run on both phones and tablets, but may not be sufficient for more complex layouts. In these situations, you are better served by designing completely separate layouts for phone and tablet and then using the above Default Screen properties to show the correct one.</p>



<p>When you need to show additional screens, you can show the phone or tablet screen in code by checking the device using DeviceData.Orientation and DeviceData.UserInterfaceType.</p>



<pre class="wp-block-code"><code>If System.Device.UserInterfaceType = SystemDeviceData.UserInterfaceTypes.Tablet Then
  // Show tablet screen
  myTabletScreen.Show
Else
  // Show phone screen
  myPhoneScreen.Show
End If</code></pre>



<p>When you have multiple screens, it often makes sense to put the UI in containers and then use the containers on the different screens.</p>



<p>You can run your apps on a Tablet emulator for testing (you can create one using Android Studio) or you can debug directly on device. I enabled on-device debugging for a Lenovo Tab M10 Plus 3rd Gen with these steps:</p>



<ul class="wp-block-list">
<li>Go to Settings.</li>



<li>Select About tablet.</li>



<li>Tap 7 times in a row on the build number. This enabled Developer options. You may be prompted to enter your PIN.</li>



<li>Select System and then Developer Options.</li>



<li>Turn on USB debugging and give it permission.</li>
</ul>



<p>The tablet will now appear as a debug device in Xojo, allowing you to run your Android projects on it.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="3552" height="2893" src="https://blog.xojo.com/wp-content/uploads/2024/09/D0D09B0C-7135-4067-A893-29D1420CAA14.png" alt="" class="wp-image-13724" srcset="https://blog.xojo.com/wp-content/uploads/2024/09/D0D09B0C-7135-4067-A893-29D1420CAA14.png 3552w, https://blog.xojo.com/wp-content/uploads/2024/09/D0D09B0C-7135-4067-A893-29D1420CAA14-300x244.png 300w, https://blog.xojo.com/wp-content/uploads/2024/09/D0D09B0C-7135-4067-A893-29D1420CAA14-1024x834.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/09/D0D09B0C-7135-4067-A893-29D1420CAA14-768x626.png 768w, https://blog.xojo.com/wp-content/uploads/2024/09/D0D09B0C-7135-4067-A893-29D1420CAA14-1536x1251.png 1536w, https://blog.xojo.com/wp-content/uploads/2024/09/D0D09B0C-7135-4067-A893-29D1420CAA14-2048x1668.png 2048w" sizes="auto, (max-width: 3552px) 100vw, 3552px" /></figure>



<h2 class="wp-block-heading">What about Chromebook?</h2>



<p><a href="https://www.chromium.org/chromium-os/chrome-os-systems-supporting-android-apps/" target="_blank" rel="noreferrer noopener">Some Chromebooks</a> are <a href="https://support.google.com/chromebook/answer/7021273" target="_blank" rel="noreferrer noopener">able to run Android apps</a> and <a href="https://www.chromium.org/chromium-os/chrome-os-systems-supporting-android-apps/" target="_blank" rel="noreferrer noopener">those that can</a> are also able to run Xojo&#8217;s Android apps. Android apps can be installed via the Play Store (give <a href="https://play.google.com/store/apps/details?id=com.xojo.catsup&amp;hl=en_US&amp;pli=1" target="_blank" rel="noreferrer noopener">CatsUp a try</a>) or manually, although doing it manually is rather difficult (I have not yet gotten that working on my Chromebook). The Play Store options works well, however. Here&#8217;s CatsUp from the Play Store running on my Lenovo 300e Chromebook:</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="768" src="https://blog.xojo.com/wp-content/uploads/2024/08/F98FE354-8315-4BCA-B204-C9D24EE0B86B_1_102_o-1024x768.jpeg" alt="" class="wp-image-13576" style="width:913px;height:auto" srcset="https://blog.xojo.com/wp-content/uploads/2024/08/F98FE354-8315-4BCA-B204-C9D24EE0B86B_1_102_o-1024x768.jpeg 1024w, https://blog.xojo.com/wp-content/uploads/2024/08/F98FE354-8315-4BCA-B204-C9D24EE0B86B_1_102_o-300x225.jpeg 300w, https://blog.xojo.com/wp-content/uploads/2024/08/F98FE354-8315-4BCA-B204-C9D24EE0B86B_1_102_o-768x576.jpeg 768w, https://blog.xojo.com/wp-content/uploads/2024/08/F98FE354-8315-4BCA-B204-C9D24EE0B86B_1_102_o-1536x1152.jpeg 1536w, https://blog.xojo.com/wp-content/uploads/2024/08/F98FE354-8315-4BCA-B204-C9D24EE0B86B_1_102_o.jpeg 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>When run on the Chromebook, Android apps can have a size of Phone, Tablet or Resizable. You can see that as an option in the title bar of the above screenshot. For best results you probably want to design your apps for a landscape tablet.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Xojo for Android does not have direct support for Chromebook features at this time, but if there is something you&#8217;d like to see, be sure to create an Issue so that we can look into it.</p>
</blockquote>



<p>Since Chromebooks are just (low-end) Linux machines at their core, they can technically run Xojo Linux apps (x86 or ARM depending on the Chromebook), but this usually requires some sort of <a href="https://support.google.com/chromebook/answer/9145439" target="_blank" rel="noreferrer noopener">additional Linux installation</a>.</p>



<p>And of course, Chromebooks are typically meant to run web apps, which Xojo can also do quite well.</p>



<h2 class="wp-block-heading">Eddie&#8217;s Electronics Example Project</h2>



<p>The Android Eddie&#8217;s Electronics example project has been updated to run on both phones and tablets. It makes use of Containers to contain the UI and displays them using screens for the appropriate device type.</p>



<p>Here you can see the Customer screen for a tablet displays the list of customers on the left, with details and invoices on the right.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="676" src="https://blog.xojo.com/wp-content/uploads/2024/08/image-7-1024x676.png" alt="" class="wp-image-13557" srcset="https://blog.xojo.com/wp-content/uploads/2024/08/image-7-1024x676.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/08/image-7-300x198.png 300w, https://blog.xojo.com/wp-content/uploads/2024/08/image-7-768x507.png 768w, https://blog.xojo.com/wp-content/uploads/2024/08/image-7-1536x1014.png 1536w, https://blog.xojo.com/wp-content/uploads/2024/08/image-7.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Compare that to the phone version which has you navigate between that information using separate screens.</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="483" height="1024" src="https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncsc-483x1024.png" alt="" class="wp-image-13564" srcset="https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncsc-483x1024.png 483w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncsc-142x300.png 142w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncsc-768x1628.png 768w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncsc-725x1536.png 725w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncsc.png 850w" sizes="auto, (max-width: 483px) 100vw, 483px" /></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="485" height="1024" src="https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncyb-485x1024.png" alt="" class="wp-image-13565" srcset="https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncyb-485x1024.png 485w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncyb-142x300.png 142w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncyb-768x1620.png 768w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncyb-728x1536.png 728w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-ncyb.png 856w" sizes="auto, (max-width: 485px) 100vw, 485px" /></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="482" height="1024" src="https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-nddd-482x1024.png" alt="" class="wp-image-13566" srcset="https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-nddd-482x1024.png 482w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-nddd-141x300.png 141w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-nddd-768x1632.png 768w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-nddd-723x1536.png 723w, https://blog.xojo.com/wp-content/uploads/2024/08/SCR-20240829-nddd.png 852w" sizes="auto, (max-width: 482px) 100vw, 482px" /></figure>
</div>
</div>



<p>Tablet supports opens up a whole other category of users for your Android apps and should be particularly useful to those making bespoke apps for clients.</p>



<p><em>Paul learned to program in BASIC at age 13 and has programmed in more languages than he remembers, with Xojo being an obvious favorite. When not working on Xojo, you can find him talking about retrocomputing at <a href="https://goto10.substack.com" target="_blank" rel="noreferrer noopener">Goto 10</a> and </em>on Mastodon @lefebvre@hachyderm.io.</p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>CatsUp! 2022</title>
		<link>https://blog.xojo.com/2022/03/16/catsup-2022/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Wed, 16 Mar 2022 15:53:53 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Cats]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Multi-Platform Development]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=10135</guid>

					<description><![CDATA[With just a few lines of code, you can create a Xojo app for iOS and Android that shows a new cat picture each time you launch it. I call this app “CatsUp!”. It's a play on ketchup/catsup, get it?]]></description>
										<content:encoded><![CDATA[
<p>Back in 2015, I wrote a <a href="https://blog.xojo.com/2015/10/01/cats-up-using-httpsocket-with-the-cat-rest-api/">blog post</a> about an iOS app called CatsUp! that used <a href="https://thecatapi.com">The Cat API</a> to display random cat pictures. Things have changed a lot since then, so it&#8217;s time for an update!</p>



<p>With just a few lines of code, you can create a mobile app that shows a new cat picture each time you launch it. I call this app “CatsUp!”. It&#8217;s a play on <a href="https://writingexplained.org/catsup-vs-ketchup-difference">ketchup/catsup</a>, get it?</p>



<h3 class="wp-block-heading">Set Up The Project</h3>



<p>Create a new iOS project called “CatsUp”. Drag an ImageViewer control onto Screen1, make it fill most of the area and change its Name to &#8220;CatImage&#8221;. Drag a Button to the bottom and change its Caption to “Cat Me!”. Also change the Screen Title to be &#8220;CatsUp!&#8221;. The result should look something like this:</p>



<figure class="wp-block-image size-medium"><img loading="lazy" decoding="async" width="184" height="300" src="https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-09.52.48@2x-184x300.png" alt="" class="wp-image-10136" srcset="https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-09.52.48@2x-184x300.png 184w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-09.52.48@2x-626x1024.png 626w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-09.52.48@2x.png 750w" sizes="auto, (max-width: 184px) 100vw, 184px" /></figure>



<h3 class="wp-block-heading">The Cat API</h3>



<p>The&nbsp;<a href="https://docs.thecatapi.com/">Cat API documentation page</a>&nbsp;describes the full API. For access to most features you will want to sign up for a free account and use an API key. For the purposes of this post, I will just use it without an API key. The URL for the method to get a random cat picture is:</p>



<pre class="wp-block-preformatted">https://api.thecatapi.com/v1/images/search</pre>



<p>The above URL returns JSON that contains the location of a picture to display. Paste it into a web browser to try it. In my test I got this JSON:</p>



<pre class="wp-block-preformatted">[{"breeds":[],"id":"99v","url":"https://cdn2.thecatapi.com/images/99v.jpg","width":384,"height":384}]</pre>



<p>To make CatsUp, we will essentially add some code to 1) send the first request, 2) get the JSON and pull out the picture URL, 3) get the picture and display it.</p>



<h3 class="wp-block-heading">Add Code</h3>



<p>Add the Pressed event to the Button with this code:</p>



<pre class="wp-block-preformatted">CatConnection.Send("GET", "https://api.thecatapi.com/v1/images/search")</pre>



<p>This calls the Send() method on a URLConnection object, called CatConnection, to get the JSON with the picture URL.</p>



<p>So now you need to drag a URLConnection object from the Library onto the Screen. Click on this newly added URLConnection1 item in the Tray and in the Inspector change its name to &#8220;CatConnection&#8221;. Add its ContentReceived event with this code:</p>



<pre class="wp-block-preformatted">Var json As JSONItem = New JSONItem
json.Load(content)

Var catItem As JSONItem
catItem = json.ValueAt(0)

Var picURL As String
picURL = catItem.Value("url").StringValue

ImageDownload.Send("GET", picURL)</pre>



<p>The above code loads the JSON into a JSONItem and then fetches the &#8220;url&#8221; value. It sends this URL to another URLConnection, called ImageDownload, to get the actual picture to display.</p>



<p>Drag a second URLConnection onto the screen and change its name to &#8220;ImageDownload&#8221;. Add its ContentReceived event with this code:</p>



<pre class="wp-block-preformatted">Var pic As Picture = Picture.FromData(content)
CatImage.Image = pic</pre>



<p>Try running the project in the iOS Simulator. Click the button to see a new cat picture.</p>



<p>This is what I see:</p>



<figure class="wp-block-image size-medium is-resized"><img loading="lazy" decoding="async" src="https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.46.03@2x-157x300.png" alt="" class="wp-image-10139" width="229" height="438" srcset="https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.46.03@2x-157x300.png 157w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.46.03@2x-536x1024.png 536w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.46.03@2x-768x1468.png 768w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.46.03@2x-803x1536.png 803w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.46.03@2x-1071x2048.png 1071w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.46.03@2x.png 1204w" sizes="auto, (max-width: 229px) 100vw, 229px" /></figure>



<p>Oops, silly me. I actually created this as an Android project and ran it in the Android Emulator. Sorry about that, here is what it looks like as an iOS project running in the iOS Simulator:</p>



<figure class="wp-block-image size-medium is-resized"><img loading="lazy" decoding="async" src="https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.47.56@2x-edited.png" alt="" class="wp-image-10141" width="234" height="532" srcset="https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.47.56@2x-edited.png 1000w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.47.56@2x-edited-132x300.png 132w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.47.56@2x-edited-450x1024.png 450w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.47.56@2x-edited-768x1747.png 768w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.47.56@2x-edited-675x1536.png 675w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.47.56@2x-edited-900x2048.png 900w" sizes="auto, (max-width: 234px) 100vw, 234px" /></figure>



<p>That&#8217;s right, the exact same code for this project can be used in both <strong>iOS</strong> and <strong>Android</strong> projects! And for another bit of Android news, this CatsUp! app, with a couple minor enhancements, is now available in the <a href="https://play.google.com/store/apps/details?id=com.xojo.catsup">Google Play Store</a>:</p>



<figure class="wp-block-image size-large is-resized"><a href="https://play.google.com/store/apps/details?id=com.xojo.catsup"><img loading="lazy" decoding="async" src="https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.52.46@2x-618x1024.png" alt="" class="wp-image-10143" width="349" height="578" srcset="https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.52.46@2x-618x1024.png 618w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.52.46@2x-181x300.png 181w, https://blog.xojo.com/wp-content/uploads/2022/03/CleanShot-2022-03-16-at-10.52.46@2x.png 750w" sizes="auto, (max-width: 349px) 100vw, 349px" /></a></figure>



<p>Have fun with this and may every day be a Caturday!</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Making An iOS App For The Daily WTF API</title>
		<link>https://blog.xojo.com/2016/01/20/making-an-ios-app-for-the-daily-wtf-api/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Wed, 20 Jan 2016 00:00:00 +0000</pubDate>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Cats]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[PAW]]></category>
		<category><![CDATA[REST]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2016/01/20/making-an-ios-app-for-the-daily-wtf-api/</guid>

					<description><![CDATA[Use web services to display articles from The Daily WTF technology snafu web site.]]></description>
										<content:encoded><![CDATA[<p>If you work in the technologiy industry, I&#8217;m sure you&#8217;ve heard of the <a href="http://thedailywtf.com">Daily WTF</a> site. Their fun stories about technology gone wrong makes it one of my favorite web sites.</p>
<p><span id="more-233"></span></p>
<p>Recently they just <a href="http://thedailywtf.com/articles/tdwtf-api">announced a web services API</a> for accessing their articles and other information. And as I&#8217;ve talked about <a href="../../../com/xojo/blog/test-web-services-with-rest-tester.html" target="_blank" rel="noopener">in</a> <a href="../../../com/xojo/blog/format-sql.html" target="_blank" rel="noopener">other</a> <a href="../../../com/xojo/blog/how-to-write-a-slackbot-in-less-than-20-lines-of-code.html" target="_blank" rel="noopener">posts</a> and <a href="https://www.youtube.com/playlist?list=PLPoq910Q9jXiH5A32myqHwd1WLuUnBTuO" target="_blank" rel="noopener">webinars</a>, it&#8217;s often quite easy to use web services with Xojo apps.</p>
<p>I&#8217;ll show you how you can quickly create an iOS app that shows the most recent TDWTF posts and then displays them when you tap on their title.</p>
<p>To start, create a Xojo iOS project.</p>
<p>On the default View (View1), use the Inspector to set a couple properties:</p>
<ul>
<li>BackButtonTitle: Articles</li>
<li>Title: The Daily WTF</li>
</ul>
<p>Now drag a <a href="http://developer.xojo.com/iostable">Table</a> from the Library onto the View and stretch it to fit the entire layout area. Name the table <strong>ArticleTable</strong>. This Table will be used to display the list of recent articles.</p>
<p>To get the articles, you just have to make the appropriate API call. Looking at the <a href="https://github.com/tdwtf/WtfWebApp/blob/master/Docs/API.md">API docs</a>, there is an API command called /articles/recent which returns a JSON document of the recent articles and related information. This is the actual API call. To see its JSON results, use a tool like <a href="https://luckymarmot.com/paw">Paw</a> (now with <a href="../../../com/xojo/blog/generating-xojo-code-from-paw.html">Xojo extensions</a>) or <a href="../../../com/xojo/blog/test-web-services-with-rest-tester.html">RESTy</a> with this URL (a browser will also show the unformatted JSON):</p>
<p><a href="http://thedailywtf.com/api/articles/recent">http://thedailywtf.com/api/articles/recent</a></p>
<p>If you look at the JSON results, you&#8217;ll see that it returns an array of articles with a &#8220;Title&#8221; entry containing the title of the article and a &#8220;Url&#8221; entry containing the URL of the article.</p>
<p>To call this in the Xojo app, I&#8217;ll use an <a href="http://developer.xojo.com/xojo-net-httpsocket">HTTPSocket</a>. In the Library, drag the item called &#8220;Generic Object&#8221; onto the Layout. It will appear in the Shelf at the bottom. In its Inspector, change the name to <strong>WTFSocket</strong> and set its super to &#8220;Xojo.Net.HTTPSocket&#8221;.</p>
<p>Now add an event handler to the socket, right-&gt;click on the socket, select &#8220;Add To&#8221; and then &#8220;Event Handler&#8221;. Add the PageReceived event handler. In it, put this code to request the articles:</p>
<pre>// Convert the binary Content data to JSON text and then
// parse it to an array.
Dim jsonText As Text = TextEncoding.UTF8.ConvertDataToText(Content)
Dim jsonArray() As Auto = Data.ParseJSON(jsonText)

// Loop through the array and add each article to
// the table.
ArticleTable.AddSection("")
For i As Integer = 0 To jsonArray.Ubound
  Dim article As Dictionary = jsonArray(i)

  Dim cell As iOSTableCellData = ArticleTable.CreateCell
  cell.Text = article.Value("Title")
  cell.Tag = article.Value("Url")

  Dim author As Dictionary = article.Value("Author")
  cell.DetailText = article.Value("DisplayDate") + " by " + author.Value("Name")
  ArticleTable.AddRow(0, cell)
Next</pre>
<p>The URL is being put into the Tag for the cell so that it can be used later to display the article when its row is tapped.</p>
<p>You&#8217;ll also see I&#8217;m also accessing the &#8220;DisplayDate&#8221; value and grabbing the &#8220;Name&#8221; from the &#8220;Author&#8221; object in the JSON.</p>
<p>Now you&#8217;ll want to call the web service. Add the Open event handler to the View with this code:</p>
<pre>// Call the /articles/recent web service
WTFSocket.Send("GET", "http://thedailywtf.com/api/articles/recent")</pre>
<p>Run the project and you&#8217;ll see the list of recent article appear:</p>
<p><img loading="lazy" decoding="async" class="aligncenter" title="WTFArticleList.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/WTFArticleList.pngt1466486449161ampwidth480ampheight742" sizes="auto, (max-width: 480px) 100vw, 480px" alt="WTFArticleList.png" width="480" height="742" /></p>
<p>The final step is to display the article when it is tapped in the list. You&#8217;ll want another View to display the article (Insert-&gt;View). Name the view <strong>ArticleView</strong>. On this View, set the NavigationBarVisible property to ON and drag an HTML Viewer onto it. Make the HTML Viewer fill the entire View layout and name it <strong>ArticleViewer</strong>.</p>
<p>Add a method to ArticleView called <strong>ShowArticle(url As Text)</strong> with this code:</p>
<pre>ArticleViewer.LoadURL(url)</pre>
<p>This method loads the URL into the HTML Viewer and is called when its row is tapped in the list of articles.</p>
<p>Speaking of which, back on View1 add the Action event handler to the table with this code:</p>
<pre>// Get the URL from the tag for the tapped row
Dim url As Text = Me.RowData(section, row).Tag

// Display the article on the new view and show it
Dim v As New ArticleView
v.ShowArticle(url)
PushTo(v)</pre>
<p>Now run the project. You&#8217;ll see the list of article as before. Tap on an article to show the new view with the article.</p>
<p><img loading="lazy" decoding="async" class="aligncenter" title="WTFArticle.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/WTFArticle.pngt1466486449161ampwidth480ampheight742" sizes="auto, (max-width: 480px) 100vw, 480px" alt="WTFArticle.png" width="480" height="742" /></p>
<p>Take a look at the full API to see what other cool features you can add to the app. Here are some suggestions:</p>
<ul>
<li>Display a random article</li>
<li>Display more than the last 8 recent articles</li>
<li>Cache the article contents on the device and use the cache when the article is displayed again</li>
<li>Display articles by month/year</li>
</ul>
<p><!--HubSpot Call-to-Action Code --> <span id="hs-cta-wrapper-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-wrapper"> <span id="hs-cta-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-node hs-cta-7bcc3f87-4442-4a30-90b2-c9264729660a"><br />
<!-- [if lte IE 8]>


<div id="hs-cta-ie-element"></div>


<![endif]--> <a href="http://blog.xojo.com/2015/10/01/cats-up-using-httpsocket-with-the-cat-rest-api/" target="_blank" rel="noopener"><img loading="lazy" decoding="async" id="hs-cta-img-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-img aligncenter" style="border-width: 0px; margin: 0 auto; display: block; margin-top: 20px; margin-bottom: 20px;" src="https://blog.xojo.com/wp-content/uploads/2016/01/7bcc3f87-4442-4a30-90b2-c9264729660a.png" alt="Use HTTPSocket with Cat REST API" width="432" height="73" align="middle" /></a></span></span> <!-- end HubSpot Call-to-Action Code --></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Write a Slackbot in Less Than 20 Lines of Code</title>
		<link>https://blog.xojo.com/2016/01/12/write-a-slackbot-in-less-than-20-lines-of-code/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Tue, 12 Jan 2016 00:00:00 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Cats]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Slack]]></category>
		<category><![CDATA[Web Service]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2016/01/12/write-a-slackbot-in-less-than-20-lines-of-code/</guid>

					<description><![CDATA[Learn how to create a Slackbot for Slack in just a few lines of Xojo code.]]></description>
										<content:encoded><![CDATA[<p><strong>What is Slackbot?</strong></p>
<p>Slack has an API called &#8220;slash commands&#8221; that lets a user type a slash (/) followed by a command name in order to perform a special action. For example, Slack has <a href="https://get.slack.help/hc/en-us/articles/201259356-Using-slash-commands">many built-in slash commands</a>, one example is /help. Here&#8217;s how you can easily add your own slash commands using a Xojo web app and the HandleSpecialURL (or HandleURL) method.</p>
<p>Your slash command makes an HTTP request to your Xojo web service app. The web services does its thing and then returns the result back to Slack to display.</p>
<h2><span id="more-288"></span>A Xojo Web Service</h2>
<p>For demonstration, I&#8217;m going to show you how to create a Slackbot that returns a &#8220;cat fact&#8221;. The slash command will be /catfact. When you use the /catfact command, Slack calls a Xojo web service which then makes a call to the <a href="http://catfacts-api.appspot.com/doc.html">Cat Fact API</a>, parses the resulting JSON and returns an interesting cat fact back to Slack to display in your channel.</p>
<p><img decoding="async" style="width: 320px; display: block; margin-left: auto; margin-right: auto;" title="coding_cat.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/coding_cat.pngt1466486449161ampwidth320" sizes="(max-width: 320px) 100vw, 320px" alt="coding_cat.png" width="320" /></p>
<p>As I&#8217;ve covered in a couple <a href="http://developer.xojo.com/webinar-web-services">Web Services webinars</a> last year, it is pretty easy to make a web service using Xojo. For this example, create a new web project and name it CatFact.</p>
<p>First you will create a simple method that will fetch a Cat Fact. Create a method on the App object, <strong>GetCatFact As String</strong>, with this code:</p>
<pre>// New request came in, so create a new HTTPSocket
Dim catSocket As New HTTPSocket

// Get a cat fact and wait for it to be returned
Dim factData As String = catSocket.Get("http://catfacts-api.appspot.com/api/facts?number=1", 30)

// Once the cat fact is returned, parse the JSON and send it to the original requester.
Dim jsonText As Text = DefineEncoding(factData, Encodings.UTF8).ToText
Dim jsonDict As Xojo.Core.Dictionary = Xojo.Data.ParseJSON(jsonText)
Dim facts() As Auto = jsonDict.Value("facts")

// Extract the fact text from the JSON
Dim fact As Text
If facts.Ubound &gt;= 0 Then
  fact = facts(0)
End If

Return fact</pre>
<p>In this Xojo project you&#8217;ll now create a simple web page UI to test that calling the Cat Fact API works. On the default page (WebPage1), add a Button and a TextField. In the Button&#8217;s Action event handler, add this code:</p>
<pre>CatFactArea.Text = App.GetCatFact</pre>
<p>Run the web app and on click the button. You should see a cat fact appear in the Text Area. The fact I got was:</p>
<p><strong>The cat has 500 skeletal muscles (humans have 650).</strong></p>
<p>Now you can add the code to process the web service request. Add the HandleSpecialURL event to the App object and use this code:</p>
<pre>If Request.Path = "CatFact" Then
  Request.Print(GetCatFact)
  Return True
End If</pre>
<p>You can test this by running the web project and then in a new tab entering the API URL, which displays a cat fact in the browser:</p>
<pre>http://127.0.0.1:8080/api/CatFact</pre>
<h2>Hook Up Web Service to Slack</h2>
<p>Now that you know the web service works, the next step is to hook it up to Slack. But before you can do that, you have to host the web app somewhere on the Internet; Slack can&#8217;t see your local web app! For this example, I&#8217;ve published the Cat Fact web service to <a href="http://developer.xojo.com/xojo-cloud">Xojo Cloud</a> because it&#8217;s fast and easy. This is the URL to the Cat Fact web service on Xojo Cloud:</p>
<pre>http://demos.xojo.com/CatFacts/index.cgi/api/CatFact</pre>
<p>Now you need to go to your Slack team settings to <a href="https://my.slack.com/services/new/slash-commands">add a slash command</a>. On that screen you&#8217;ll want to set the name of the <strong>Command</strong> to &#8220;/catfact&#8221; and the <strong>URL</strong> to &#8220;http://demos.xojo.com/CatFacts/index.cgi/api/CatFact&#8221; (the URL from above). Also change the <strong>Customize Name</strong> field to &#8220;CatFact&#8221;. You can ignore all the other fields and click the Save Integration button at the bottom.</p>
<p>That&#8217;s it. The slash command is now active. Head on over to your Slack team and type /catfact into a channel. You&#8217;ll get back a fact from &#8220;CatFact&#8221;.</p>
<p><img loading="lazy" decoding="async" title="SlackbotCatFact.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/SlackbotCatFact.pngt1466486449161ampwidth578ampheight151" sizes="auto, (max-width: 578px) 100vw, 578px" alt="SlackbotCatFact.png" width="578" height="151" /></p>
<p>And it took less than 20 lines of code! You can now use this technique to integrate your own web services into Slack.</p>
<p>By default, only you will see the cat fact returned by the Slashbot; it is not broadcast to the entire channel. You can change this by returning specifically formatted JSON rather than just a text string (as described on the <a href="https://api.slack.com/slash-commands">Slack Commands API page</a>).</p>
<p>If you come up with a great slash command and want to make it available to the world, you can attach it to a <a href="https://api.slack.com/slack-apps">Slack app</a> and publish it to the <a href="https://slack.com/apps">App Directory</a>. The steps for this are also in the <a href="https://api.slack.com/slash-commands">Slash Commands API page</a>.</p>
<p style="text-align: center;"><!--HubSpot Call-to-Action Code --> <span id="hs-cta-wrapper-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-wrapper"> <span id="hs-cta-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-node hs-cta-7bcc3f87-4442-4a30-90b2-c9264729660a"><br />
<!-- [if lte IE 8]>


<div id="hs-cta-ie-element"></div>


<![endif]--> <a href="http://blog.xojo.com/2015/10/01/cats-up-using-httpsocket-with-the-cat-rest-api/" target="_blank"><img loading="lazy" decoding="async" id="hs-cta-img-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-img aligncenter" style="border-width: 0px;" src="https://blog.xojo.com/wp-content/uploads/2016/01/7bcc3f87-4442-4a30-90b2-c9264729660a.png" alt="Use HTTPSocket with Cat REST API" width="432" height="73" /></a> </span><script src="https://js.hscta.net/cta/current.js" charset="utf-8">// <![CDATA[
<script type="text/javascript"><![CDATA[ hbspt.cta.load(608515, '7bcc3f87-4442-4a30-90b2-c9264729660a', {});
// ]]&gt;</script></span><br />
<!-- end HubSpot Call-to-Action Code --></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Hour of Code: Cat Pictures</title>
		<link>https://blog.xojo.com/2015/12/07/hour-of-code-cat-pictures/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Mon, 07 Dec 2015 00:00:00 +0000</pubDate>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cats]]></category>
		<category><![CDATA[Hour of Code]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2015/12/07/hour-of-code-cat-pictures/</guid>

					<description><![CDATA[In Hour of Code for 2015, learn how to make an iOS app that shows fun cat pictures.]]></description>
										<content:encoded><![CDATA[<p>It&#8217;s time again for <a href="https://code.org/">Hour of Code</a>! The Hour of Code is a global movement reaching tens of millions of students in 180+ countries. Anyone, anywhere can participate in Hour of Code, from ages 4 to 104. At Xojo, we are again participating in this wonderful way to help people learn to program.</p>
<p><span id="more-283"></span></p>
<h2>Catsup</h2>
<p>In this tutorial, you&#8217;ll learn how to create an iOS app that displays random cat pictures, which I call &#8220;Catsup&#8221;. Meow!</p>
<p>To get started, you&#8217;ll need the following:</p>
<ul>
<li>A Mac with OS X 10.7 or later. Creating iOS apps requires OS X.</li>
<li><a href="http://xojo.com/download/" target="_blank">Xojo</a> (the free version works for this tutorial)</li>
<li><a href="https://itunes.apple.com/us/app/xcode/id497799835?mt=12">Xcode</a> (for the iOS Simulator, which is part of the installation)</li>
</ul>
<p>Download and install Xojo and then download and install Xcode from the <a href="https://itunes.apple.com/us/app/xcode/id497799835?mt=12">App Store</a>. After Xcode is installed, you&#8217;ll need to run it once to accept its license agreement and allow it to finish the installation. After that you can quit Xcode; you will not need it again.</p>
<p>Start Xojo and in the Project Chooser window that appears click on iOS and in the Application Name field, enter the name for you app (&#8220;CatsUp&#8221;) and click OK.</p>
<p><img loading="lazy" decoding="async" title="ProjectChooser.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/ProjectChooser.pngt1466486449161ampwidth578ampheight319" sizes="auto, (max-width: 578px) 100vw, 578px" alt="ProjectChooser.png" width="578" height="319" /></p>
<p>This displays the Xojo main Workspace where you will create your app. In the Workspace, View1 is selected by default. This is where you will design the layout (aka user interface or UI) for you app. You do this using simple drag and drop. You&#8217;ll drag controls from the Library area on the right onto the layout area in the center.</p>
<p>Since this is your first app, it is pretty simple. You&#8217;ll only need two controls: an ImageView and a Button.</p>
<p>First, find the ImageView in the Library (on the right) and drag it onto the View in the center. Place the ImageView near the top of the area and resize it so that it uses about 3/4 of the space. It should look something like this:</p>
<p><img loading="lazy" decoding="async" title="ImageViewLayout.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/ImageViewLayout.pngt1466486449161ampwidth578ampheight390" sizes="auto, (max-width: 578px) 100vw, 578px" alt="ImageViewLayout.png" width="578" height="390" /></p>
<p>Now you can drag a button from the Library onto the layout. Place the button near the bottom of the layout and center it. Your layout should now look like this:</p>
<p><img loading="lazy" decoding="async" title="ButtonLayout.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/ButtonLayout.pngt1466486449161ampwidth578ampheight390" sizes="auto, (max-width: 578px) 100vw, 578px" alt="ButtonLayout.png" width="578" height="390" /></p>
<p>Now you need to clean up the layout a bit to prepare for writing code later. When writing code, it is helpful to have descriptive names for things so that your code makes more sense when you read it. The ImageView and the Button you added to the layout were just given default names of ImageView1 and Button1, which is not all that descriptive and certainly doesn&#8217;t make their purpose clear. So you should rename them.</p>
<p>Click on the ImageView in the layout and then in the toolbar at the top of the window, click the Inspector button. This displays the &#8220;properties&#8221; for the ImageView on the right side in what is called the Inspector. A property is a specific detail about something. For example, a property of the sky is that it is blue. As you can see, an ImageVIew has several property values that you can change. The first one to change is the &#8220;Name&#8221; property.</p>
<p>Click in the field next to Name and change its text from &#8220;ImageView&#8221; to something more descriptive, such as &#8220;CatImage&#8221;. Since you are making property changes with the Inspector, this is also a good time to change another property to make the pictures display better. Change the ContentMode property (using the dropdown) from &#8220;ScaleToFill&#8221; to &#8220;ScaleAspectFill&#8221;. What is the difference you ask? ScaleToFill just enlarges (or shrinks) the picture so that it uses all the space in the ImageView. But this can result is weird stretching of cat pictures, making cats appear fatter or skinnier. Of course, maybe you might prefer that! With &#8220;ScaleAspectFill&#8221;, the picture will be enlarged or shrunk as necessary to fit the space in the ImageView, but the proportions of the picture will remain the same. This might the picture might not use all the available space, but it will look the way it is supposed to, without scary resizing.</p>
<p>The Properties for the ImageView should now look like this:</p>
<p><img decoding="async" title="ImageViewProperties2.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/ImageViewProperties2.pngt1466486449161" alt="ImageViewProperties2.png" /></p>
<p>Now click on the Button to change its properties. You will not be referring to the Button in code, so you don&#8217;t <em>have</em> to change its name, but I like to change it anyway to better describe its purpose. This may be a simple project, but it is a good habit to get into doing and is especially important when projects get more sophisticated.</p>
<p>Change the name of the Button from &#8220;Button1&#8221; to &#8220;ShowCatPictureButton&#8221;. You might also have noticed that the button Caption says &#8220;Untitled&#8221;. That is not helpful. How will the user know what happens when they click it? So you also need to change the Caption property text from &#8220;Untitled&#8221; to something like &#8220;Show a Cat&#8221;.</p>
<p>The Properties for the Button should now look like this:</p>
<p><img loading="lazy" decoding="async" title="ButtonProperties.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/ButtonProperties.pngt1466486449161ampwidth349ampheight423" sizes="auto, (max-width: 349px) 100vw, 349px" alt="ButtonProperties.png" width="349" height="423" /></p>
<p><em>Even though you haven&#8217;t yet written any code, you have already created an app.</em> Sure, the app doesn&#8217;t technically do anything, but you can at least run it to take at look at how your user interface (UI) looks in the iOS Simulator. To do so, click the big &#8220;Run&#8221; button on the toolbar at the top of the window. This creates your app and runs it on the iOS Simulator. It should look like this:</p>
<p><img decoding="async" style="width: 320px;" title="Catsup2.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/Catsup2.pngt1466486449161ampwidth320" sizes="(max-width: 320px) 100vw, 320px" alt="Catsup2.png" width="320" /></p>
<p>That&#8217;s not all that interesting, so now it is time to start adding some code to actually get cat pictures and display them!</p>
<p>Your app will get pictures from the Internet using a web site called <a href="http://thecatapi.com/">TheCatAPI</a>. This website gives you a different cat picture each time you call it. The process for your app will be to call the web site (using a special URL for accessing its &#8220;web service&#8221;) when the button is clicked and then display the picture using the CatImage control after it is received.</p>
<p>Xojo uses an object-oriented programming language, which means that you create things (aka objects) to contain information or perform actions. In order to get a cat picture from the Internet, you need an object that can connect to the Internet and receive information as needed.  In Xojo, this is called an HttpSocket.</p>
<p>HttpSocket is a class that is built-in to Xojo. A class is essentially an object definition. With this information, you can now add an object to your view and tell it to use HttpSocket as it definition.</p>
<p><strong>But before you proceed here is a public service announcement:</strong> Now is a good time to make sure you save your project. Just like when writing a document in a word processor, you should always save your work often so that you don&#8217;t lose changes in case something bad happens, such as a power failure or an system crash. In the File menu, select Save As and save your project somewhere on the computer, such as the Desktop or Documents folder.</p>
<p>Back in Xojo, you&#8217;ll want to click the Library button on the toolbar to show the list of Library controls. You&#8217;ll want to drag the &#8220;Generic Object&#8221; control from the Library onto the layout area of the view. Since a Generic Object is not an actual UI control, it will not appear within the View, but will instead appear at the bottom (the Shelf).</p>
<p><img loading="lazy" decoding="async" title="GenericObjectLayout2.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/GenericObjectLayout2.pngt1466486449161ampwidth578ampheight435" sizes="auto, (max-width: 578px) 100vw, 578px" alt="GenericObjectLayout2.png" width="578" height="435" /></p>
<p>Now click on Generic Object and then click the Inspector button on the toolbar to show its properties. You need to give it a better name and tell it to use the HttpSocket class. Change the Name property to &#8220;CatConnector&#8221; since this object will be responsible for connecting to the Internet to get cat pictures.</p>
<p>Change the Super property to &#8220;Xojo.Net.HttpSocket&#8221;. This tells the the object that it is based on the HttpSocket, which exposes the capabilities to connect to the Internet and receive information.</p>
<p><img loading="lazy" decoding="async" title="SocketProperties.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/SocketProperties.pngt1466486449161ampwidth351ampheight93" sizes="auto, (max-width: 351px) 100vw, 351px" alt="SocketProperties.png" width="351" height="93" /></p>
<p>(Now is a good time to save your project.)</p>
<p>It time to add the first bit of code that displays the picture that was received. Right-click on the CatConnector object in the Shelf and select &#8220;Add to CatConnector&#8221; in the menu, from the submenu select &#8220;Event Handler&#8221;. This displays the Event Handler window.</p>
<p>In addition to being object-oriented, Xojo is event-based. Events are actions that occur when something happens in your app, such as the user tapping on the UI or data being received from the Internet.</p>
<p>In the list of event handlers, you want to click the PageReceived and then click the OK button to add the event handler to the CatConnector. The PageReceived event handler is what is called when the picture is received from the web site.</p>
<p>If you look back at the CatConnector in the Navigator on the left, you&#8217;ll now see that &#8220;PageReceived&#8221; is displayed below it. This is where you will put the code to display the picture.</p>
<p><img loading="lazy" decoding="async" title="SocketPageReceived.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/SocketPageReceived.pngt1466486449161ampwidth198ampheight81" sizes="auto, (max-width: 198px) 100vw, 198px" alt="SocketPageReceived.png" width="198" height="81" /></p>
<p>Click on &#8220;PageReceived&#8221; to display the Code Editor where you can enter this code:</p>
<pre>Dim catPic As iOSImage = iOSImage.FromData(Content)
CatImage.Image = catPic
ShowCatPictureButton.Enabled = True</pre>
<p>This code converts the data received by the CatConnector to an Image, then tells the CatImage control to display it and enables the button so you can request another picture.</p>
<p>Speaking of the button, the last bit of code to add is to actually request a cat picture from the web site, which is what the button is for. Double-click on the button to display the Add Event Handler window. The Action event handler is what gets called when the button is tapped, so click on that and then click the OK button.</p>
<p><img loading="lazy" decoding="async" title="ButtonEvents.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/ButtonEvents.pngt1466486449161ampwidth578ampheight310" sizes="auto, (max-width: 578px) 100vw, 578px" alt="ButtonEvents.png" width="578" height="310" /></p>
<p>This adds an Action event handler to ShowCatPictureButton. Click on the Action event in the Navigator on the left.</p>
<p><img loading="lazy" decoding="async" title="ButtonAction.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/ButtonAction.pngt1466486449161ampwidth209ampheight140" sizes="auto, (max-width: 209px) 100vw, 209px" alt="ButtonAction.png" width="209" height="140" /></p>
<p>This displays the code editor where you can add this code to request a cat picture:</p>
<pre>CatConnector.Send("GET", "http://thecatapi.com/api/images/get")
Me.Enabled = False</pre>
<p>The CatConnector.Send line of code is requesting a cat picture from the web site. The second line of code disables the button so that you cannot request another picture until the first one is received.</p>
<p>That is it for code. Now is a great time to save your project.</p>
<p>And now you can Run it. The finished app will display a new cat picture each time you click the button.</p>
<p><img loading="lazy" decoding="async" title="Catsup-Finished.png" src="https://blog.xojo.com/wp-content/uploads/2015/12/Catsup-Finished.pngt1466486449161ampwidth484ampheight746" sizes="auto, (max-width: 484px) 100vw, 484px" alt="Catsup-Finished.png" width="484" height="746" /></p>
<p>Here is the completed project: <a href="http://files.xojo.com/BlogExamples/CatsUpHourOfCode.xojo_binary_project.zip">Catsup</a></p>
<p>Now that you&#8217;ve created your first, fun app, it&#8217;s time for you to try to modify it a bit on your own.</p>
<p>Here are some additional things you can add to Catsup:</p>
<ul>
<li>Easy: Increase the size of the Button text and maybe change its font and color.</li>
</ul>
<ul>
<li>Play around with different values for the Button properties to change its color, font and size. Be sure to click the &#8220;Gear&#8221; button on the Inspector to see additional properties.</li>
</ul>
<p>&nbsp;</p>
<ul>
<li>Medium: Play a &#8220;Meow!&#8221; sound when a new picture is displayed.
<ul>
<li>Find a &#8220;Meow&#8221; MP3 sound on the Internet and drag it in the Navigator (on the left) of you project.</li>
<li>Use the name of the sound in the project followed by &#8220;.Play&#8221; to play the sound when the picture is displayed.</li>
</ul>
</li>
<li>Harder: Save the picture to the Camera Roll.
<ul>
<li>Store the picture in a property when it is received. Refer to <a href="http://developer.xojo.com/properties-methods-and-events$Properties">Properties</a> in the Xojo User Guide.</li>
<li>Add a Save button to the Navigation Bar. Refer to <a href="http://developer.xojo.com/ios-toolbars">Toolbars</a> in the Xojo User Guide for tips.</li>
<li>When the Save button is pressed, save the picture to the Camera Roll. Refer to Toolbars in the Xojo User Guide to determine when the button was pressed.</li>
<li>You&#8217;ll need to call the Apple iOS library to save to the Camera Roll with this code:</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<pre>Declare Sub UIImageWriteToSavedPhotosAlbum Lib "UIKit" ( _
  img As Ptr, target As Ptr, sel As Ptr, info As Ptr)
UIImageWriteToSavedPhotosAlbum(CatImageProperty.Handle, _
  Nil, Nil, Nil)
</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Cats Up: Using HTTPSocket with the Cat REST API</title>
		<link>https://blog.xojo.com/2015/10/01/cats-up-using-httpsocket-with-the-cat-rest-api/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Thu, 01 Oct 2015 00:00:00 +0000</pubDate>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Cats]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Mobile]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2015/10/01/cats-up-using-httpsocket-with-the-cat-rest-api/</guid>

					<description><![CDATA[A perfect way to demonstrate HTTPSocket- the Cat API provides a REST (web services) API that can send you random cat pictures. ]]></description>
										<content:encoded><![CDATA[<p>On the Internet, everyone loves cats. Using HTTPSocket and The Cat REST API, Xojo makes it easy for you to get the cat pictures you need to brighten your day. Read on to learn how to make everyday Caturday&#8230;and for more cat puns.</p>
<p><span id="more-258"></span></p>
<p>When preparing materials for the <a href="http://developer.xojo.com/webinar-httpsocket">HTTPSocket webinar</a> I came across <a href="http://thecatapi.com/">The Cat API</a>. This wonderful site provides <a href="http://thecatapi.com/docs.html">a REST (web services) API</a> that sends you random cat pictures. What a perfect way to demonstrate <a href="http://developer.xojo.com/xojo-net-httpsocket">HTTPSocket</a>!</p>
<p>With just a few lines of code, I&#8217;m going to show you how to create an iPhone app that will show you a new cat picture each time you launch it. I call this app &#8220;Cats Up&#8221;.</p>
<p><img decoding="async" style="width: 320px; display: block; margin-left: auto; margin-right: auto;" title="Cat + Cat = Cute1" src="https://blog.xojo.com/wp-content/uploads/2015/10/Cat1.pngt1466486449161" alt="Cat + Cat = Cute1" data-constrained="true" /></p>
<h2>Set up the iOS Project</h2>
<p>Launch Xojo and create a new iOS project called &#8220;CatsUp&#8221;. Drag an ImageView control onto the View and make it fill most of the area. Drag a Button to the View and place it at the bottom with the title &#8220;Cats Up!&#8221;. The result should look like this:</p>
<p><img decoding="async" style="display: block; margin-left: auto; margin-right: auto; width: 388px;" title="ios preview cats up" src="https://blog.xojo.com/wp-content/uploads/2015/10/CatsUpLayout.pngt1466486449161" alt="ios preview cats up" data-constrained="true" /></p>
<h2>View the Cat API</h2>
<p>The <a href="http://thecatapi.com/docs.html">Cat API documentation page</a> describes the full API, but this project only needs to use the get method to get you &#8220;all the fancy cat images you can handle&#8221;. The URL for this method is:</p>
<pre>http://thecatapi.com/api/images/get</pre>
<h2>Add Code</h2>
<p>It is time to add a tiny amount of code. First, you need to create an HTTPSocket subclass.</p>
<ol>
<li>Click the Insert button on the toolbar and select Class. Name the class CatCloud.</li>
<li>Set the class Super to &#8220;Xojo.Net.HTTPSocket&#8221;.</li>
<li>Add a method to the class called GetCat with this code:</li>
</ol>
<pre>Try
  Self.Send("GET","http://thecatapi.com/api/images/get")
Catch t As UnsupportedOperationException
  Return
End Try</pre>
<p>Now select your view (View1) and drag the CatCloud class onto it. This adds it to the Shelf at the bottom on the layout editor. It will automatically be named CatCloud1.</p>
<p>Double-click CatCloud1 to add the PageReceived event handler and add this code:</p>
<pre>Dim catPic As iOSImage 
catPic = iOSImage.FromData(content)
ImageView1.Image = catPic</pre>
<p>Next double-click the button to add the Action event handler and add this code:</p>
<pre>CatCloud1.GetCat</pre>
<p>Lastly, add an Open event handler to the View and add this code:</p>
<pre>CatCloud1.GetCat</pre>
<h2>Test</h2>
<p>Run your project to launch it in the iOS Simulator. An initial cat picture should appear. Click the &#8220;Cats Up!&#8221; to show a new picture.</p>
<p><img decoding="async" style="width: 320px; display: block; margin-left: auto; margin-right: auto;" title="Cat Vader" src="https://blog.xojo.com/wp-content/uploads/2015/10/Cat_Vader.pngt1466486449161" alt="Cat Vader" data-constrained="true" /></p>
<p>May the cat be with you.</p>
<ul>
<li><a href="http://files.xojo.com/BlogExamples/Catsup.xojo_binary_project.zip">Download the iOS project</a></li>
</ul>
<p><strong>March 2022 UPDATE:</strong> Get Cats Up! for Android in the <a href="https://play.google.com/store/apps/details?id=com.xojo.catsup">Google Play Store</a>!</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
