Book Image

Android NDK: Beginner's Guide

By : Sylvain Ratabouil
Book Image

Android NDK: Beginner's Guide

By: Sylvain Ratabouil

Overview of this book

Table of Contents (18 chapters)
Android NDK Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 class, append two new native methods to retrieve and save a Color object:

    public class Store {
        ...
        public native Color getColor(String pKey);
        public native void...