Time for action – saving references to Objects in native Store

  1. Create a new Java class com.packtpub.store.Color encapsulating an integer representation of a color. This integer is parsed from String containing HTML code (for example, #FF0000) thanks to the android.graphics.Color class:
    package com.packtpub.store;
    import android.text.TextUtils;
    public class Color {
        private int mColor;
        public Color(String pColor) {
            if (TextUtils.isEmpty(pColor)) {
                throw new IllegalArgumentException();
            }
            mColor = android.graphics.Color.parseColor(pColor);
        }
        @Override
        public String toString() {
            return String.format("#%06X", mColor);
        }
    }
  2. In StoreType.java, append the new Color data type to the enumeration:
    public enum StoreType {
        Integer,
        String,
        Color
    }
  3. In the Store ...

Get Android NDK Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.