skip to Main Content

I’m writing a module to create a file for use as a resource by an Android app. As a Kotlin script I can achieve this. However, now it allegedly needs to use an Android library with a Context. (I want to call hasGlyph() on a android.graphics.Paint supplied with a typeface from a font resource.) I have tried "Android library," "Java or Kotlin Library," and "Phone & Tablet Module" in the Android Studio wizard, reading here, and Gradle heck. I have come to believe an app may be my only choice, but it seems terribly inconvenient to have to retrieve the file from the device (I don’t know how to do this yet either), for a task which is more of a simple script.

  1. Is this so unusual a situation?
  2. What would be the accomplishing setup?

2

Answers


  1. Chosen as BEST ANSWER

    A Java/Kotlin script using java.awt.Font for the same functionality instead


  2. Can you share your script?

    You should have no issue in creating a library like that. What you will need to do is design your API to expose the functionality you’re trying to implement.

    I was unable to create an Android Library in Arctic Fox for some reason, so went to IntelliJ IDEA to put a sample together. But this is roughly what you should be looking to achieve.

    class Font(private val paint: Paint): HasGlyph {
        override fun hasGlyph(glyph: String) = paint.hasGlyph(glyph)
    }
    
    fun interface HasGlyph {
        fun hasGlyph(glyph: String): Boolean
    }
    

    If a framework function you’re needing to call requires an instance of Context, it may be worth thinking about if you’re requirements could be achieved without the Context instance, and if not, can you encapsulate that kind of functionality in another class/interface.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search