Skip to content

Android: Use cache folder/subfolder to cache SVG files - #1643

Merged
devemux86 merged 3 commits into
mapsforge:masterfrom
Sublimis:android-cache-folder-1
Jan 26, 2025
Merged

devemux86 merged 3 commits into
mapsforge:masterfrom
Sublimis:android-cache-folder-1

Conversation

@Sublimis

Copy link
Copy Markdown
Contributor

On Android there is an elegant concept of a "cache folder" which should be used to cache SVG files. No application wants thousands of files in the root of its private folder, which is currently done. Even in the cache folder we create a separate subfolder for that.


public static final Config MONO_ALPHA_BITMAP = Config.ALPHA_8;

public final String LibraryFolderName = "mapsforge";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sublimis Please use a variable that starts with lowercase letters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this is not a variable but a (non-static) constant...?
In fact, maybe this should be put into the Constants class in some way.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sublimis This is not declared as static. Then it should be LIBRARY_FOLDER_NAME.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the final suggestion then? Make it static, uppercase, and include in Constants, or something else?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sublimis If it is a constant then it should be like the other constants, static with uppercase letters.
The location is not important. It can stay here, as it is not a global constant.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sublimis We could put something in Constants when it is used outside its class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the time comes for someone to use such a constant, no one will remember that there is already one buried in the android svg cache 🥲

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sublimis Does it matter?

It should not be a constant, but a variable, as other users may prefer a different folder name.
Apps may want to store there svg, png, tiles, etc. Each app may want different folder names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If by "other users" you mean other applications (not other classes in the library), then you seem to be confusing the purpose of this constant. If an application wants to change the cache folder that the library uses, it already has the means to do so, like you noticed below.

It matters for future maintainer. It could be you, me, or someone else. It's strange that something like this doesn't already exist, for any purpose. Like for example when we were naming hill shading threads we hard-coded "Mapsforge" into the name, when it would have been more elegant to have some global "library name" constant to pull from.

Also note the unfortunate naming of methods there. E.g. openFileInput() uses the folder set by setSvgCacheDir(), so it's not a general-purpose method.

But you know, whatever, as usual, these kinds of discussions take up too much time 😃

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note the unfortunate naming of methods there. E.g. openFileInput() uses the folder set by setSvgCacheDir(), so it's not a general-purpose method.

Mapsforge has a very long history of too many years and many developers.
It is difficult to rename the whole public API without serious reason. 🙂

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Note that there is the setSvgCacheDir method to customize the svg cache folder.

@Sublimis

Copy link
Copy Markdown
Contributor Author

@Sublimis Note that there is the setSvgCacheDir method to customize the svg cache folder.

That doesn't affect what was done here at all.

@Sublimis

Copy link
Copy Markdown
Contributor Author

While at this, is there still a purpose for this folder? https://github.com/mapsforge/mapsforge/tree/a2a59a6d313a33345182cc50e41882415f573067/mapsforge-themes/icons
If not, maybe you could consider deleting it.

@devemux86

devemux86 commented Jan 24, 2025 •

Copy link
Copy Markdown
Collaborator

is there still a purpose for this folder?

It contains the collection of the original svg icons.
Only some of them were processed and included in the themes.
Original icons may still be useful in the future.

@Sublimis
Sublimis marked this pull request as draft January 24, 2025 19:22
@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis My only comment here is to rename the constant, then we can merge it.

@Sublimis

Copy link
Copy Markdown
Contributor Author

Two commits, the previous one is just to show you what we had in mind:

https://github.com/mapsforge/mapsforge/blob/17dda95d84aefeecaaa501de4597a7fb78dbae5a/mapsforge-core/src/main/java/org/mapsforge/core/util/Constants.java

package org.mapsforge.core.util;

public final class Constants {

    /**
     * Display-friendly, human readable name of the library.
     */
    public static final String LIBRARY_DISPLAY_NAME = "Mapsforge";

    /**
     * Filename-friendly, machine readable name of the library.
     * To be used when there's a need to name a file, folder, or similar.
     */
    public static final String LIBRARY_FILE_NAME = "mapsforge";

    /**
     * Maximum amount of memory that the Java virtual machine will attempt to use, in megabytes.
     */
    public static final long MAX_MEMORY_MB = Runtime.getRuntime().maxMemory() / 1000 / 1000;

    private Constants() {
        throw new IllegalStateException();
    }
}

It's a little strange that the library doesn't "know" its name all these years 🙂

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis There is no perfect library! I implemented map rotation only recently, after so many years.

If it is so important, we can move the constants in the Constants class.

@Sublimis

Copy link
Copy Markdown
Contributor Author

It's not important, it's just practical and aesthetic 🙂 We can leave this for the future if it's easier that way.

@Sublimis
Sublimis marked this pull request as ready for review January 25, 2025 16:20
@devemux86 devemux86 added this to the 0.24.0 milestone Jan 26, 2025
@devemux86
devemux86 merged commit 7295ce2 into mapsforge:master Jan 26, 2025
@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants