Icons and strings

If you’ve made it this far, you actually have a fully working Android app! If we wanted to, this app is pretty much ready to publish! Let’s add an icon and clean up the code a little bit: Right-click our res folder and select New → Image Asset Select “Launcher icon” from the dropdown menu at the top For “Asset type” (in the foreground layer tab), select “Image”, and select the highest-resolution version of our grim reaper icon (the one from drawable-xxxhdpi folder in the zip file)....

April 10, 2018

Displaying large lists (Kotlin)

Remember I talked about having limited resources available in mobile apps? That means we can’t just stuff all our data into a massive scroll view and hope it works. (Websites are notorious for doing just that. To make it work, your phone kills most non-essential processes when you open those websites.) The solution is to make it look like we have an infinite list of things to display. We do this by making views only for the list items currently onscreen....

April 9, 2018

Sharing is caring – using Intents and the app bar (Kotlin)

Let’s say we want to make it easy to share our deadline with friends. To do that, we’d like to have a button at the app bar at the top of the screen that opens the famous Share Menu when tapped. After selecting the app to use for sharing the deadline, that app is opened, ready to share the text: “I have a deadline in just X hours! Help me procrastinate”...

April 3, 2018

Animation (Kotlin)

Finally, let’s do the animation! We need images of a CS student and the grim reaper. To speed things up, here are some ready-made images in the right dimensions. As you see, there’s a very specific folder structure here, telling Android Studio which images are for which display DPI (“display pixels per inch”). Again, Android Studio take care of much of this for you, and quasi-official tools like Android Asset Studio handle just about everything else....

April 3, 2018

Save the date! (Kotlin)

So do we put the deadline in outState and consider ourselves done? Well, we want to keep the deadline even if the entire phone is turned off, don’t we? Instead, we’ll use SharedPreferences. This is essentially a glorified way to save small amounts of data in key:value format on disk. SharedPreferences survive practically everything except a factory reset (and even then we can choose to have it backed up by Google)....

March 30, 2018

Setting and showing a deadline (Kotlin)

Let’s be honest here: dealing with date arithmetic is a pain, and working with Java or Kotlin does not exactly make things easier. In real apps, use JodaTime or JSR-310 to deal with dates. To keep things simple, we’ll use the old java.util.Date class you know from TDT4100 (“the Java course”) and a very dirty hack to calculate the number of hours left. Android Studio will complain, if you find it annoying just add @Suppress("DEPRECATION") at the top of our class....

March 28, 2018

Interactivity (Kotlin)

Even though we have a fancy layout now, the button doesn’t do anything. How can we write code that updates the text when the button is clicked? Actually, setContentView(…); in MainActivity returns nothing at all, so how can we even access our views from the code? The solution is to give every view an ID, and then do a lookup to get hold of them. Kotlin will do the lookup for us....

March 28, 2018

Sharing is caring – using Intents and the app bar

Let’s say we want to make it easy to share our deadline with friends. To do that, we’d like to have a button at the app bar at the top of the screen that opens the famous Share Menu when tapped. After selecting the app to use for sharing the deadline, that app is opened, ready to share the text: “I have a deadline in just X hours! Help me procrastinate”...

March 27, 2018

Animation

Finally, let’s do the animation! We need images of a CS student and the grim reaper. To speed things up, here are some ready-made images in the right dimensions. As you see, there’s a very specific folder structure here, telling Android Studio which images are for which display DPI (“display pixels per inch”). Again, Android Studio takes care of much of this for you, and quasi-official tools like Android Asset Studio handle just about everything else....

March 26, 2018

Interactivity

Even though we have a fancy layout now, the button doesn’t do anything. How can we write code that updates the text when the button is clicked? Actually, setContentView(…); in MainActivity returns nothing at all, so how can we even access our views from the code? The solution is to give every view an ID, and then do a lookup to get hold of them. Let’s start with the text:...

March 26, 2018