Implement the attributes defined by the styleable resource.
- [Instructor] 'Kay, let's switch back to checkbox class, and we see that Android Studio has picked up on the styleable resource that we defined. This is no longer red, and this attribute is no longer red. So this is a standard convention. We define the styleable resource as the name, and then the attributes would be concatenated onto the name. getCheckBoxVectors, which is this method, supports loading the SVG files as part of inflating the view, and here is where we are expecting to get the SVG file names from our layout attributes.
The other method, here, getCheckBoxVectors, is an overrided method, and it supports loading directly from string names. So let's finish implementing that method here. We're going to call getIdentifier, so let's declare a local variable called checkedResource, and we call the getIdentifer, and we pass in our filenameOn, and type raw, and we pass in packageName.
We're going to do the same thing for the unchecked state. I'm just going to rename this to unchecked, and we will change this file name to filenameOff. Now let's define some private class members. The first one, let's scroll back up, the first private member will be checked, and it's type PictureDrawable.
The other type is unchecked, and it's also a PictureDrawable, so I'm just going to copy that and rename this to unchecked. I'm just going to copy this now, and then we can go back down here to our getCheckBoxVectors. Let's initialize the PictureDrawable, the first one checked. We're going to call the loadVectorFromSvgFile, and we'll pass in our checked resource.
We're going to do the same thing for the unchecked PictureDrawable, and we'll use the unchecked resource. Okay, now let's define the private method for loadVectorFromSvgFile. So, I select the lightbulb, and I select Create method, and hit Return for the defaults. Now we have an empty method for loadVectorFromSvgFile. Before we implement this method, let's switch over to our gradle file.
We want to add a gradle dependency. So, let's go into project view, and we'll go into the Gradle Scripts and select Module: app build.gradle. Let's add a dependency here, at the bottom. Our dependency is going to be called com.caverock: androidsvg, version 1.2.2-beta.
Okay, let's do a gradle sync to make sure everything's okay, and now we are ready to go back to our checkbox class.
- Creating a custom layout with XML
- Setting up OnClick handlers
- Making API calls
- Creating custom views
- Implementing ViewHolder objects
- Signing certificates
- Adding a checkbox