How can I get the imagelevel of an ImageView? - java

In my app I'm using a few Imageviews with LevelListDrawables to be able to change then dynamically.
But now I want to know if I can read in which level the ImageView is stated, I set the level with setImageLevel() but there is no against hanging method to get the imagelevel.
So my question is: Is there a way to get the current imagelevel of an imageview?

You can't do it directly to the ImageView, but you can do this
imageView.getDrawable().getLevel()
That will do the trick, for further information the offical documentation for Drawable#getLevel()

Related

Showing lists of image to RecyclerView from internet

I have a long list of images that i need to show in to recyclerView. I am using glide to show the images from my adapter.
Glide.with(context).load(feed.getImgLink()).diskCacheStrategy(DiskCacheStrategy.NONE).into(holder.myImgView);
The above is the code am using i set the DiskCacheStrategy to none because I'm trying to show Instagram like Feed and i didn't want to permanently cache the img on disk.
The first time i see the image there is no problem it is displayed normal but after i scroll down and back up the image reload again. I get that i haven't cache the image in to disk but there is still momery cache.
Is there any way i can solve i could use diskcache to ALL but it is taking space for just one time viewing.
Try this.
Glide.with(context).load(imageUrl).into(holder.myImgView);

Searching a method like getResourcesID(int)

I'm searching a method that gives me the ID (int) from the Resource from a ImageView in my App. I don't know the name of the Image or something else. i only have an imageview and there is an Image from my Resources inside.
The reason is that i need it is to save it in my SQLite Database as an Integer.
Because later i will read this Data in my SQLite Database to use the method
ImageView.setImageResource((int) R.drawable.SavedPic).
I'm only a beginner in programming so it will not be the best way to do it but i coding the hole day and i hope that you can give me the right method.
There is no direct way to get the Image Resource Id from an ImageView. But there is a way to hold onto that using tags. So if you have an ImageView called imageView and an image resource called R.drawable.image you can do something like this:
imageView.setImageResource(R.drawable.image);
imageView.setTag(R.drawable.image);
And later when you want to get the resource Id associated with the ImageView you can fetch it using
int imageResourceId = (Integer) imageView.getTag();

How to get the uri of the images stored in the phone and return them in a String[]

I am trying to create a custom gallery with a single select option. I've used the code provided by google docs to create a GridView that contains the images contained in drawable.
Now I want to change it by making the GridView show all the images stored in the phone.
To get all images from the phone you need to query the android.provider.MediaStore
First make sure you have the AndroidPermission.READ_EXTERNAL_STORAGE, then get the thumbnails for the grid.
Here is a simple way to do this:
HERE
Hope this helps.

Create a view class that is a combination of two views Android

In my app, I have a screen that displays some images next to text. These images are downloaded from the internet, so there will be some latency in displaying them. Right now I have an ImageView and a ProgressBar overlaying each other, and toggling the visibilities when the Bitmap becomes available. Is there any way to combine the two into one class that will handle it all in case I want to use this somewhere else?
One way to go about solving the problem is to make your own custom view which extends ProgressBar and draw the image in the ondraw(Canvasn canvas) using a Rect. That way, your image can be embedded in your view and you can always make it reusable by allowing your self to set the image via a setter/resource xml files which specify the attributes that go along with your custom view. Here's a reusable ProgressButton that I wrote that maybe of use to you, it shows how I did something similar to what I described (it's one which I think works well):
PregressButton
Yes there are a number of ways to combine widgets into a single custom class. Have a read of Custom Components. This should help you decide which approach you want to use for your situation.

How do I insert multiple image in Edit Text in android

I am trying to insert multiple images in one editText. I have used following code to attach image to EditText
txt = (EditText)findViewById(R.id.text);
Bitmap bitmap = BitmapFactory.decodeFile(attach);
Drawable drawable = new BitmapDrawable(bitmap);
txt.setBackgroundDrawable(drawable);
But the problem is it only attach one file and show, If i used array then only the last image is only show. at any how it only shows one Image. Is there any way to show multiple images in one Editbox. Thanks in advance.
Because you can only have one background.... if you want more then there is a layer Drawable which you can use and also you can put the button in a frame layout and add a couple of imageViews below/over it for the rest of the images.
But the best solution will probably be instead of having a couple of bitmaps to just make a single one in Photoshop or equivalent photo editing app and place that one.
According to docs: http://developer.android.com/reference/android/view/View.html#setBackgroundDrawable(android.graphics.drawable.Drawable)
You are not able to provide more than one Drawable item in argument
And I don't know if you understand what is .setBackgroundDrawable(d) method purpose, but it is not meant to be used for displaying images inside text but to set Background of EditText View.
So you're not inserting images in EditText but setting its background,
look for some Rich Text Edit components usable for Android
such as http://code.google.com/p/android-richtexteditor/
or others..
You can probably use a LayerDrawable with the constructor LayerDrawable(Drawable[] layers) to chain together several images and display them as an EditText's background, though as Marek said, I suspect you're looking for something other than setting images in the background.

Categories