Byte of Toast: How to Detect Wired and Bluetooth Headphone Disconnects

Tagged under: headphones, bluetooth, audio, and music

Posted by Chris Pierick on 20 Jun 2016


When building an app that plays music, it is important to be able to pause the music when the headphones are disconnected. You may start this process by trying to listen to Intents such as Intent.ACTION_HEADSET_PLUG and BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED. Marshmallow even has a really nice AudioDeviceCallback which may be helpful once adoption of Marshmallow has gone up. Since this all seems overly complicated, you may just shrug and say, “typical Android”.

Read More

NFC On Android, Part 2: Implementation Details

Tagged under: NFC, near field communication, and wireless

Posted by Ben Berry on 06 Jun 2016


Last month, we discussed the history of Near Field Communication, what it is, and introduced some high level concepts about how it can be used. This week, we’ll dive into how to put those ideas into practice on Android.

To start with, add the NFC permission to your app’s manifest. Then, to read and write NFC tags, you can use an activity like this:

public class ReadWriteActivity extends AppCompatActivity implements ReaderCallback {
    @Override
    protected void onResume() {
        super.onResume();
        NfcAdapter.getDefaultAdapter(this).enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS, null);
    }

    @Override
    protected void onPause() {
        super.onPause();
        NfcAdapter.getDefaultAdapter(this).disableReaderMode(this);
    }

    @Override
    public void onTagDiscovered(Tag tag) {
        // do work with the tag
    }
}
Read More

What Every Android Dev Should Know From I/O '16

Tagged under: Google I/O

Posted by Patrick Jackson on 25 May 2016


News and information from Google I/O can be a firehose. All the info and session videos can be found at the I/O site, but here is my list of Android highlights that every Android dev should know.

Read More

NFC On Android, Part 1: History and Concepts

Tagged under: nfc, near field communication, and wireless

Posted by Ben Berry on 06 May 2016


Near Field Communication (NFC) is an RFID technology that’s been rattling around in the mobile world for years and never quite managed to take off. More general forms RFID still dominate badging and physical access control. Apple Pay and Android Pay are struggling to find acceptance without anybody mentioning they run on NFC. And nobody’s quite figured out why you would use an NFC sticker to control your Android phone when an app like Tasker can tell your location, movement mode, and connected wireless networks.

So I was quite surprised to find that modern versions of Android have surprisingly robust support for NFC and it’s the rare Android phone that omits hardware support for it. It may be the case that NFC hasn’t really taken off in any major way, but that’s certainly not for lack of support in Android hardware or software. There’s plenty of cool stuff to be done with NFC.

Read More

Intro to the Design Support Library - Part 1

Tagged under: ui, material, and lollipop

Posted by Curtis Martin on 14 Mar 2016


If you’re an Android developer (and you probably are if you’re reading this blog), you’ve probably heard of the Design Support Library. It was unveiled at Google I/O last year, and comes with several classes to assist you in making your apps follow the Material Design Guidelines. This leads to not only a great user experience, but consistency across apps all over the Android ecosystem. This is something that has been sorely lacking up until the introduction of Lollipop. In this post, I’m going to show you how to use several elements of the Design Support Library in your app, as well as point out a few gotchas I’ve come across.

Read More

What is data binding and what does it solve?

Tagged under: data binding and support library

Posted by Adam Shea on 24 Jul 2015


Data binding allows us to remove all the boilerplate findViewById() calls as well as having to manually update those views in the code. With Android now officially supporting data binding it opens the doors for a MVVM architecture. MVVM stands for Model-View-ViewModel. With MVVM the ViewModel and the View are really de-coupled making it easy to test the ViewModel without even needing a View. Since the View updates its components via a data binder there is no need for the ViewModel to be dependent on it. The ViewModel can simply update the Model and whichever View is currently binding to that Model will also update.

Read More

Material Range Slider

Tagged under: support library

Posted by Patrick Jackson on 19 Jun 2015


Material design is the new hotness and there are tons of guidelines and mock ups that Google has given to us. While they have given us a few implementations with the new Design Support Library, we are still left to implement lots of widgets ourselves. Recently we made a custom range picker so the user could select a range of prices. We think it’s nice so we are sharing it here with you (source and sample app on github), and perhaps you can get ideas for implementing your own material-inspired widgets.

Read More

On-Screen Keyboard Tracking, Part 2

Tagged under: keyboard

Posted by Ben Berry on 04 Jun 2015


A few months ago, we discussed the basic steps you can use to keep track of whether a screen in your app has the soft keyboard open.

At Ticketmaster Mobile Studio, we’ve found this especially important and useful on a Fragment or Activity that has one single EditText on it and a bunch of other Views. Whether the rest of the screen is a camera preview or a complex RecyclerView, managing that one EditText can become a problem. Today’s post will help you control whether the EditText has focus and, perhaps more importantly, an annoying blinking cursor, even when the soft keyboard is closed.

Read More

The Joy of Painting: Canvas 101

Tagged under: ui, canvas, paths, and drawing

Posted by Curtis Martin on 13 Apr 2015


In a previous blog post, we touched on creating custom UI components containing several stock Android controls. But what if you want to create a completely custom View, complete with its own drawing behavior? To accomplish that, you’ll need to become familiar with the Canvas.

What Canvas?

Just as in actual painting, an Android Canvas is a surface on which drawing can be performed. Every View subclass has an easy way to get access to that View’s Canvas. Simply override the onDraw(Canvas canvas) method like so:

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    //Draw some stuff on the Canvas here!
}
Read More

How to use Android's Job Scheduler

Tagged under: job scheduler and support library

Posted by Chris Pierick on 21 Feb 2015


One of the really cool things about Lollipop is the new JobScheduler API. Not only is this API exciting for developers but end users should also be excited. This surprisingly easy to use API lets your app schedule a job to take place according to a number of parameters. The cool thing about this is that you can easily set parameters that will save the end user lots of battery life, giving your users one less reason to uninstall your app. There are three main parts to this API: JobInfo, JobService and JobScheduler.

Read More

Developing a Watch Face for Android Wear Lollipop

Tagged under: android, wear, watch face, and lollipop

Posted by James Barr on 10 Dec 2014


Today, Google announced Lollipop for Android Wear devices. One of the most anticipated features included in this update is official support for developing watch faces. This is such an exciting feature that many developers, Two Toasters included, have already released unofficial watch faces (such as Chron) using unofficial methods. Two Toasters was lucky enough to get early access to the watch face APIs and had the opportunity to partner with Specialized, a brand well known to cyclists everywhere, to develop the Specialized Bikes Watch Face that is uniquely suited to cyclists. Now that official support exists for watch faces, let me show you how to implement one the proper way so you can gain all of the benefits and features from using the new APIs.

Read More

Byte of Toast: Tinting Drawables on Lollipop

Tagged under:

Posted by Chris Pierick on 06 Dec 2014


One of the cool things about Android 5.0 Lollipop is that you can colorize system UI widgets through the themes and styles. While this is nice, it doesn’t work for every drawable you provide. But thankfully this is also easy. First create a png resource, your drawable, which only has transparency and white, this can be a 9-patch. Next in res/drawable or res/drawable-v21 make an xml drawable. For our example we’ll call this drawable ic_back_red.xml. In this file the <bitmap> tag should be our root and we need to set the src and tint fields.

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/ic_back"
    android:tint="@color/red_tint"/>
Note: that tint can be a color or a color statelist. You can also use the current colorPrimary with ?android:colorPrimary as your tint.

Boom, your drawable has been tinted. You can reference this anywhere drawables can be referenced and it will use the appropriate resource bucket for the original png.

Read More

On-Screen Keyboard State Tracking in 3 Easy Steps

Tagged under: keyboard

Posted by Ben Berry on 14 Oct 2014


If you’ve never been frustrated by the inability in Android to know whether or not the on-screen keyboard is open, this article probably isn’t for you. Even if you have hit that roadblock in the past, it’s very possible that Android was trying to save you from a bad design decision. But if you really want to know how to deal with whether or not the soft keyboard is open, read on.

Read More

Android Bluetooth Low Energy Tutorial

Tagged under: bluetooth and btle

Posted by Marcelle Gibble on 22 Sep 2014


In July 2013, the Android API 18 release introduced support for Bluetooth Low Energy (BTLE). With increasing numbers of devices hitting the market, adding support for BTLE devices has become a priority for many. However, diving into the Android BTLE documentation can be a bit daunting for the novice. This tutorial will walk through the basic concepts of BTLE, and then show snippets of code to further illustrate the communication with remote devices.

Read More

MessageApi: Simple Conversations with Android Wear

Tagged under: wear, messageapi, and bluetooth

Posted by Curtis Martin on 18 Aug 2014


Android Wear has finally arrived, and we can all finally live out our childhood dreams of being Dick Tracy. A new frontier for both developers and consumers alike, Wear allows us to use our existing Android devices in new and exciting ways. In fact, the Wear platform itself is absolutely dependent on communicating with our phones and tablets. Google has come up with some pretty simple APIs that facilitate this communication, luckily for us. Today, we’re going to talk about MessageApi, which is the simplest way we can pass information to and from a Wear device.

Read More

Developing Watchfaces for Android Wear

Tagged under: android, wear, and watchface

Posted by James Barr on 18 Jul 2014


DEPRECATED: The official Android Wear Watch Face API has been released. You can find more details in our updated post.

This past week, Two Toasters released their first Android Wear watchface called Chron. Having worked on Chron and seen the lack of documentation about developing watchfaces, I wanted to share what we have learned and what we have done in order to make future watchfaces easier to develop.

Read More

Null Shared Preference Key == Bad News Droids

Tagged under: shared preference, bug, android, and java

Posted by Chris Pierick on 04 Jul 2014


There is a little [known bug][1] in Android’s SharedPreference that will have devastating effects on your app. This revolves around what happens when you try to save a null key into SharedPreferences. The first question is:

Why would you have a null key?

This is a good question. In most cases, if you have “good” code, you’ll never run into this. Let me tell you how I ran into this problem.

Read More

Creating Reusable Custom Components

Tagged under: ui and views

Posted by Curtis Martin on 21 Jun 2014


The stock Views provided by Android are pretty flexible, and usually they’re good enough if you’re adhering to the Android Design Guidelines. Sometimes you might want to add some special functionality to an existing View, or modify its look outside of what the stock attributes will allow. In those cases, you need to make a custom component. Fortunately for us, that’s quite easy to do!

In this example, we need to make a CheckBox with the following requirements: * Two lines of text: a title and a description * The “box” itself aligns to the right side of the View * Tapping anywhere in the View will toggle the state of the CheckBox

Read More

Testing Apps Dependent On Private Repos

Tagged under: android, tools, and testing

Posted by James Barr on 06 Jun 2014


Testing is an important part of our development process. Travis is an extremely helpful service that integrates with GitHub and runs our unit tests in a continous integration fashion. Often, we are developing apps for clients, and as such, we are working in a private GitHub repo. This is not an issue for us since Travis sets up public & private SSH keys in order to access the app’s private repo. The issue we recently ran into, though, was when that app is dependent on another private repo, such as an SDK that we are also developing in private. Here are the steps we took to fix our CI process in a secure manner…

Read More

Google Maps with Custom View Overlays

Tagged under: google maps sdk and custom view

Posted by Patrick Jackson on 27 May 2014


Google Maps SDK on Android is great. However, for a recent project at Two Toasters we had a use case that is not handled by the Maps SDK directly. In our case we needed a dotted circle on top of the map and query data based on the radius of the circle. The circle and marker remain in the same place as the user scrolls and pans. There is nothing in the Google Maps SDK to handle this for us. Enter Custom Views!

Read More

Adding Sections to CursorAdapter

Tagged under: cursoradapter, java, opensource, and tutorial

Posted by Chris Pierick on 09 May 2014


Creating a ListAdapter from a BaseAdapter with sections is fairly easy, though it can be non-trival. Here at Two Toasters we often use SQLite databases with a CursorAdapter. CursorAdapter abstracts getView from you by having you implement newView and bindView instead. This is great because then you don’t have manage any of the view recycling yourself and the cursor is given to you already moved to the position for your list item. This is where things get tricky when you want to add sections.

SectionCursorAdapter was created to make adding sections to the CursorAdapter with fast scroll trival. It is a scientific fact that it’s 348.265% easier to implement compared to adding sections to a BaseAdapter on array data(clinical trial data available on request). The question is, is it really that hard to implement your own sectioning CursorAdapter? Also, is this library really that versatile, and what does this give you over creating one yourself?

Read More

Smooth ActionBar Transitions when Opening a Navigation Drawer

Tagged under: android, java, and animation

Posted by Ben Berry on 25 Apr 2014


Have you ever wanted your Action Bar to animate and change as smoothly as your Navigation Drawer when the drawer opens and closes? Here at Two Toasters, this is exactly the kind of little touch we pay attention to. So when we come across this kind of janky transition, we fix it:

What it looks like before

Read More

Upgrading QA for Android

Tagged under:

Posted by Karl Smith on 11 Apr 2014


If you are a QA veteran, you have likely formed a set of skills and routines that allow you to tackle each project efficiently. For the most part, you can re-institute your toolset if you move to a different QA position or your company begins developing for new platforms.

Coming from a web QA background, I spent most days dealing with the 4 major web browsers and a handful of operating systems. I had my routine of going through each, performing Black Box, Regression, Ad-Hoc, and Smoke testing. Eventually, the company I was with decided to take their product mobile and I was introduced to iOS for the first time. With little adjustment, I was able to translate my web skills to iOS testing.

Read More

Customizing Your Build With Gradle

Tagged under: android, opensource, and tools

Posted by James Barr on 28 Mar 2014


If you haven’t already heard, Gradle is the new build system for Android apps. Android Studio, the new development IDE for Android apps, leverages Gradle for doing the actual building of the app. The great thing about Gradle is that it is very customizable. You could even setup your Gradle build configuration such that you would not have to alter your Eclipse ADT project structure. So basically, there is no reason not to go ahead and try out Gradle right now. And when you do, here are some cool things that you can try out…

Read More

CWAC-Camera - An Easier Way to Take Photos in Android

Tagged under: camera and opensource

Posted by Curtis Martin on 14 Mar 2014


One of Android’s greatest strengths is its ability to run on a plethora of different types of devices and hardware configurations. For developers, however, this presents an interesting problem: how do you go about supporting all these different hardware variations? While Google has done a fine job of abstracting the finer details of hardware interaction away from the developer in most cases, the Android camera API still poses a substantial number of hurdles to this day.

Read More

2013: The Death of Gingerbread

Tagged under: GB and ICS

Posted by Chris Pierick on 04 Mar 2014


Gingerbread is dead. That’s right, not dying but dead.

This happened in 2013 but most developers have not realized it yet. Unless you’re coding internal apps for your company and have an unfortunate requirement, there is no reason to code for an Android version before API 15 (IceCreamSandwich). Even that is unfortunate as API 15 was released on December 16, 2011(1), well over two years ago.

Gingerbread and IceCreamSandwich are losing marketshare

Right now, if you set your app’s minimum API level to 16, you are missing out on 35% of the market. That is changing rapidly as both Gingerbread and IceCreamSandwich are on a downward slope(Fig 1).

Read More

Android Helpers

Tagged under:

Posted by Fred Medlin on 09 Jan 2013


Java helpers are simply classes that work can be delegated to. There is no difference in Android applications. Keeping helper classes small, tight and focused can improve your app. Here are some advantages:

  • Enforce framework requirements in a concise way.
  • Wrap platform differences
  • Keep your code DRY

First things first. Create a class with a private constructor. That will prevent accidental instantiation of the helper class. For our purposes, the helper class will simply be a collection of public static methods.

Read More

© 2016 Ticketmaster Mobile Studio