Filed Under #android
I haven’t spent a whole lot of time with React Native, mostly using it for prototyping or for quick tools I personally need. One common thing I seem to require though is a Modal component, and I was always thinking how strange it is that the Modal requires an onRequestClose callback on Android devices. It’s not strange to have required properties by any means, but the fact that this one property is Android only is...
The Android [Canvas](https://developer.android.com/reference/android/graphics/Canvas.html) provides convenient methods for drawing simple shapes such as circles and rectangles, using [drawCircle](https://developer.android.com/reference/android/graphics/Canvas.html#drawCircle(float, float, float, android.graphics.Paint)) and [drawRect](https://developer.android.com/reference/android/graphics/Canvas.html#drawRect(android.graphics.Rect, android.graphics.Paint)) respectively, but beyond these the majority of shapes require some custom Path logic to draw. Two shapes that I was required to draw were triangles and rhombuses, so I thought I'd share how I accomplished this.
Android Intents allow developers to share data such as text, images and URLs with other apps. This is handy for Share buttons, allowing users to tweet, post, email or message their friends from within your app or game.
In today's post, I'd like to share with you how I conditionally render components in React Native. Let's say you want to show a Log In button for unauthenticated users, and a Log Out button for user's who have authenticated. How would you go about doing this?
Recently I came across a situation where I wanted to animate the background color of the app's Toolbar, TabLayout, FloatingActionButton, and the window StatusBar when the selected tab changes. To do this, I chose to use the ValueAnimator which allows you to iterate over the difference of two values over a timed interval. I also used an ArgbEvaluator for the ValueAnimator's evaluator to handle the calculation of each animation step between the two ARGB colors.
Allowing users to share screenshots of a their progress in a game, or their view of an app, is a great way to drive installs and increase the reach of your Android application. Users can certainly use the native screenshot functionality of their device, but it would be great to be able to provide a button or any other means of sharing their view from within the app, that takes a screenshot of the relevant content for them.
In this post I'll be going over how to create a fullscreen background image for your views in React Native. While I'll be focusing on fullscreen images in particular, this will actually directly apply to any background image, fullscreen or not.
The following trick actually works for any Java interface, Android or otherwise, but I find this to be particularly painful in animation-heavy Android applications, so I'm going to be using the AnimationListener interface as an example.
A while back I wrote about how to Use GSON to Fetch and Parse JSON into Java Models for Android, and that post proved to be quite popular even to this day. However I'd like to provide you with a new tutorial that goes over how to perform the same task of fetching and parsing JSON into Java objects with GSON, but using updated libraries such as Volley, and demonstrate how much cleaner and more maintainable the code becomes.
In Part 2 we created the layout and style of the calculator, but it still doesn't do anything. In Part 3, we'll continue from where we left off by handling touch events, performing the arithmetic, and updating the calculator UI using State.
In Part 1 we went through the setup of a 'Hello, React!' application. In Part 2, we'll continue from where we left off and begin laying out and styling our calculator app.
Animations, when used correctly, can be a simple way to enhance the user experience of your products, adding a little bit of fun that a motionless view just doesn't have. Today I'll be demonstrating how to add some basic left and right sliding animations to your Views and Activities on Android.
Square photos are all the rage now since Instagram introduced them back in 2010, but implementing them on Android is much more painful than you'd imagine.
Recently I wanted to add an animation to an ImageView to infinitely rotate in place, in order to create a custom loading spinner. The requirements were simple enough that customizing the ProgressBar view wasn't necessary, and we didn't need anything fancy like a GIF.
There's three common methods of creating a String with the appropriate user ID in place, namely direct string concatenation, using a StringBuilder, or using String.format. I personally find using the String.format method to be the cleanest and tend to use it when applicable, but I recently began wondering how it actually performs against the other two methods.
Given a future date, how can you update a TextView with a countdown timer to the date on Android? Pretty easily in fact, using a couple quantity strings, the TimeUnit class, and a Handler.
The Android TextView supports displaying a drawable beside, above, or below the text, but how do you programatically change the color of the drawable to match the text? Turns out it's actually really easy using a PorterDuffColorFilter, but a little obscured behind some silly documentation.
IconEditText provides a reusable view for displaying an ImageView with an EditText for Android 4.0+.
SQLite is a public domain database engine that is designed to be incredibly minimal and simplistic, with a tiny footprint, making it a perfect candidate for mobile devices. Luckily for us, Android comes equipped with the database out of the box, and a very handy library for interacting with it.
I've been working on a very simple Android app that fetches and displays blog posts from my site. As I was developing the app, I decided that it would probably be of more use to show people the source code than to actually release the app on Google Play, seeing as how a mobile device isn't the greatest way to view code snippets.
Previously I wrote about how to animate views into place using a ListView on Android, similar to how Google does it in their Google Plus app. I decided to publish an Android library that manages the animations for you, allowing you to easily integrate it into any project.
Google Plus style ListViews are all the rage these days on Android because of the slick animations it displays when presenting data. When a user scrolls down, new items animate up into view, and quite frankly it looks awesome. In my latest app I decided to implement the same style animation, and it turned out to be very easy to implement. I also decided to implement an animation when scrolling up in the ListView so that the rows animate down into view.
This tutorial will cover how to fetch and parse JSON from a remote server on Android. We will use GSON, a JSON parsing library developed by Google, to quickly parse the JSON into Java objects with very minimal work required.
XOR encryption (or Exclusive-OR encryption) is a common method of encrypting text into a format that cannot be trivially cracked by the average person. XOR encryption is great for storing things like game save data, and other data types that are stored locally on a users computer, that while not a big deal if they are tampered with, you would like to deter people from doing so. XOR encryption is also used often as a part of more complex encryption algorithms.
Everyone knows using the default font in an application can get a little boring. The new Roboto typeface in Android is all well and good, but it can leave something to be desired at times. Luckily, using a custom font is quite easy.
Recently I was parsing a REST API that returned data in JSON format, and noticed that this particular API formatted it's dates in a peculiar way:
Something that can be helpful in Android development is to know if your app is in the background, or if it is presently active. Determining this programmatically can be tricky, but it is by no means impossible. Using your Application object, you can register a listener for activity lifecycle changes, and keep track of your application's state.
When using resources in an Android application, it is usually sufficient to make use the of resource manager with functions such as getString() and getDrawable(). Occasionally however, you will need to get the actual URI of a resource. The process is very easy, as the URI has a very sensible setup: android.resource://[package-name]/[Resource-ID] All you need to do is replace the package name with your app's package name, as defined in the manifest, and the resource...
Unfortunately, Android does not support viewing PDFs out of the box in a WebView. Luckily, Google has a nifty little tool that allows you to perform this very task quite easily using Google Docs. Basically we will embed our PDF in a Google Doc page on-the-fly and load that. Here's the code:
A lot of times when using a REST API, it is effective to map integers from your JSON to an enum in your Java models. With Google's GSON library, the process of doing this is can be a little tricky, but I find it well worth the added effort to do so.
Something that is very common in user interface design is to have a repeating background image on your views. The image is normally very small, and repeats across your view's background to give it more texture or style than a flat background color. This trick is often used for simple gradients, providing better performance than programmatically drawing the gradient on the view, but it can also be used for textures or more complicated gradients to...
A common method of developing HTML5 applications for Android is to implement a native WebView and have it load your HTML5 web page. Using this method, the user is presented with what looks like a native application, because the 'browser' used to render your HTML does not have any of the standard browser buttons or the URL input. It simply loads your HTML with no other UI elements.