Refer to wrongly named images in Android app - android

Is there any possibility to refer to wrongly named images in Android? I have bunch of images that have wrong names, for example IMG123456.jpg (u. c.), 1_img.jpg (number first) etc. It would be really hard to rename them all, cause I have JSON file that I load and there are also these names.
So my questions are:
Is it possible to store these image files anywhere?
Is it possible to refer to these images with Glide library?

I realized that assets folder should have path like this: src\main\assets. To refer to images with Glide in assets folder it's needed to do that like this:
.load("file:///android_asset/images/1_img.jpg")
It's very important to remember about the extension!

Related

How can i change fill color of a vector file fetched from server in android?

Is there anyway I can access the elements of vector file like fill color on the click of certain path fetched from the server. I am fetching whole vector file from the server. I have tried many library including RichPath ,VectorChildFinder, AndroidSVG but they require a vector file which is stored in res folder. It would not feasible to keep all the files in the res folder as there are many.
What I have achieved is I can parse it into a imageview but can't access the elements inside it.
Thank you.
I don't know about the others, but AndroidSVG does not require the file to be in a res or assets folder. The library doesn't include any method to fetch from a URL, but you can always fetch the file yourself and then use SVG.getFromString(fetchedSVGData).
If you don't want to handle the fetching yourself, you could use a library like Glide. It has an example of how to fetch SVGs and display with AndroidSVG.
To colour the SVG, just use AndroidSVGs ability to pass CSS stylesheet when rendering.

Android Performance: load images for listView

I'm going to develop an application which shows a ListView which each row have a seperate image (like personal picture for contacts list). It seems I have two options:
1- Store all images in Asset Folder and load image using setImageDrawable() command.
2- Store all images in Drawable Folder and load theme using setImageResource(R.drawable.xxx)
So my questions is does they differ in performance? And how can I speed up listView rendering such that images displayed in acceptable speed.
There should not much performance different to access image from Drawable or asset folder. You can see the answer too - > Android: Accessing images from assets/drawable folders
But, When you using ListView you are recreating the view . So, Where ever you store the image all the images are will not feel much different .
There are not so much differences. Just for coding pattern changes.
assets/
Bitmap files (.png, .9.png, .jpg, .gif) or XML files that are compiled into the following drawable resource.
drawable/
Arbitrary files to save in their raw form. To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.
https://developer.android.com/guide/topics/resources/providing-resources.html#ResourceTypes

Android how to load Image file with different extension using Picasso

This is a different situation. I want to load a image file which has stored with different extension like 'photo.xyz' instead of 'photo.jpg or photo.png' using Picasso. to avoid image from gallery i am storing image like this. Please help me is there any option to show like this.
Neither Picasso nor Android (which does the actual image decoding) cares what the file name is. It can be anything. The type of the image is always determined from the first few bytes of the actual image data.
As a small workaround you can programmatically put .nomedia file into your app folder to prevent images to be cached by mediaserver and displayed in a Gallery app.

How does(or doesn't) .apk handle hardlinks

Does the .apk format handle hardlinks? Or does it simply copy the same file over and over?
I've some a simple test and it seems like hardlinks are not handled, meaning that the size of the generated .apk increases significantly when you have multiple hardlinks to the same file. Is there a way to make the resources point to the same file instead?
The use case is the following: I have several images, which are used in some places in my application and their names contain some information about them. For example I could have an apple.jpg, apple_red.jpg, apple_red_big.jpg, apple_big.jpg, apple_green.jpg etc. My application uses the image that matches the data the most, and thus if the data is about a red, big apple it will use apple_red_big.jpg, while if the application only knows that the data regards apples it will simply use apple.jpg.
At the moment I'm not providing a different file for each resource, so apple_red.jpg is simply an hardlink to apple.jpg. In the future I might decide to add more images and thus apple_red.jpg could have its own image.
Also, since apple.jpg is used as a fallback option, it will pretty much always be a simple hardlink to an other image which happen to be also apple_something.jpg.
How can I avoid duplicating all these images in the final apk?
If you provide the same image under different file names (even if they are just hard links), the aapt will package them up as separate resources. Rather than using the file system to create hard links, the Android way of doing what you want is to provide alias resources. The technique is described here in the docs. Basically, you simply create a bitmap drawable that references another drawable:
file res/drawable/apple.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/apple_something" />
where you store apple_something.png in the res/drawable directory. The alias resource takes up just a tiny bit of additional room in the .apk file.
In code, both R.drawable.apple and R.drawable.apple_something would then retrieve the same image (although they would be different Drawable objects); in xml it would be #drawable/apple and #drawable/apple_something.

How to do it right : embedding a png directory to an android project and reffering to its items

what i did was that i added a directory named Images, which is full of png files to src\ (so all the images are in src\Images
and then reffered to it in code like this:
BitmapFactory.decodeFile("Images\\"+i+".png");
it didnt work, how can it be done correctly?
Add the images to the appropriate version of res/drawable-*/, based on density, then reference it a R.drawable.basename (for an image named basename.png) for places where you need them (e.g., setImageResource() on an ImageView).

Categories

Resources