Code Monkey home page Code Monkey logo

Comments (10)

wasdennnoch avatar wasdennnoch commented on July 30, 2024

I really don't know much about what this app is doing, but if you need a bunch of icons to choose from maybe the material icon font? Only downside is that you have to create a list with all names. And I don't know if it even works in apps.

from home-assistant-android.

Maxr1998 avatar Maxr1998 commented on July 30, 2024

That would surely be a possibility, but I don't think that how the Web UI does it.. There must be a better way 😄

from home-assistant-android.

swbradshaw avatar swbradshaw commented on July 30, 2024

I assume you are targetting API 21+, so you can focus only on vector icons. If so, there are 2 ways to get these....

  1. Call API to get icon list as JSON: https://materialdesignicons.com/api/package/38EF63D0-4744-11E4-B3CF-842B2B6CFE1B

For each result in the array, you end up with the following data:

{
   id:"4F013652-22DE-48CF-886B-A0FB995E8B41",
   name:"access-point"
}

Iterate for each of those results, downloading each Andoid vector XML file (pass ID in URL) such as:
https://materialdesignicons.com/api/download/icon/vectordrawable/4F013652-22DE-48CF-886B-A0FB995E8B41

URL above results in a download called "access_point.xml" with the following content:

<!-- drawable/access_point.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="24dp"
    android:width="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
    <path android:fillColor="#000" android:pathData="M4.93,4.93C3.12,6.74 2,9.24 2,12C2,14.76 3.12,17.26 4.93,19.07L6.34,17.66C4.89,16.22 4,14.22 4,12C4,9.79 4.89,7.78 6.34,6.34L4.93,4.93M19.07,4.93L17.66,6.34C19.11,7.78 20,9.79 20,12C20,14.22 19.11,16.22 17.66,17.66L19.07,19.07C20.88,17.26 22,14.76 22,12C22,9.24 20.88,6.74 19.07,4.93M7.76,7.76C6.67,8.85 6,10.35 6,12C6,13.65 6.67,15.15 7.76,16.24L9.17,14.83C8.45,14.11 8,13.11 8,12C8,10.89 8.45,9.89 9.17,9.17L7.76,7.76M16.24,7.76L14.83,9.17C15.55,9.89 16,10.89 16,12C16,13.11 15.55,14.11 14.83,14.83L16.24,16.24C17.33,15.15 18,13.65 18,12C18,10.35 17.33,8.85 16.24,7.76M12,10A2,2 0 0,0 10,12A2,2 0 0,0 12,14A2,2 0 0,0 14,12A2,2 0 0,0 12,10Z" />
</vector>

Put these assets into the project (or another library we can reference).

OR

  1. Material icons are also in Google's project here: https://github.com/google/material-design-icons

Pull this project down, and then copy the vector files from all the categoried subfolders:
*/drawable-anydpi-v21/ic_{{name}}_black_24dp.xml

Scott

from home-assistant-android.

Maxr1998 avatar Maxr1998 commented on July 30, 2024

Oh, really nice 👌👌
Where did you find the API endpoint?
I am going to take a look at it, not sure I want to add all icons to project, maybe I just can download and reference them on demand.

from home-assistant-android.

swbradshaw avatar swbradshaw commented on July 30, 2024

True. If you can download the vector XML on-demand for icons in use and then save them to application cache, that would be ideal.

from home-assistant-android.

Maxr1998 avatar Maxr1998 commented on July 30, 2024

I'll take a look at that ;)

from home-assistant-android.

Maxr1998 avatar Maxr1998 commented on July 30, 2024

Ok, I found out that Android can only load drawables from a compiled resource file. That either means we cannot load the vectors dynamically OR we would have to compile them with aapt on the device on-the-fly and load them via an XMLResourceParser from storage, which would be a huge overkill, but exceptionally cool 😎

from home-assistant-android.

Maxr1998 avatar Maxr1998 commented on July 30, 2024

Well, my idea doesn't work. But we can still download png images from the server, and that's what I will do.

from home-assistant-android.

swbradshaw avatar swbradshaw commented on July 30, 2024

What idea did you try?
You mean download the PNG icons from the materialdesignicons.com on demand?

from home-assistant-android.

Maxr1998 avatar Maxr1998 commented on July 30, 2024

I tried to download vector images, compile them with aapt on the device and display them. Didn't work, as Android's parser system isn't built for this. And now I'll just download and display PNG files, which will definitely work.

from home-assistant-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.