Imageview Src path in Android in Appium - android

In our Android app, we use placehold images in our thumbnails until the server returns a valid image. The Android devs change the src of the ImageView when an image is found. I am unable to find the src of the ImageView because when i do a get_attribute('src'), nothing comes up. Is there a way to get the src of an ImageView?

first you need to set tag and then you can surely get the resource of ImageView.
myImageView.setTag(R.drawable.currentImage); //set this along when you set your image source
int drawableId = (Integer)myImageView.getTag(); //get the resource

I solved this by setting the ImageView description like .setContentDescription({image_resource})
and then getting it on appium with
.getAttribute("name")

Related

Android avoid image scalling in Imageview for Image Mapping like Html

Hi Am trying to implement image mapping as like html in android. For that i referred this project. Its work good when i access the image from drawable-nodpi folder. But when i access from other drawable folder the image get scaled as per the android concepts. Here i used drawable folder for checking purpose only. Actually i get image from back end service.
I also tried with bitmap by setting the no density.
Bitmap bm;
bm=BitmapFactory.decodeResource(getResources(), R.drawable.blueprint);
bm.setDensity(Bitmap.DENSITY_NONE);
mImageMap.setImageBitmap(bm); //mImageMap is customized view which extends Imageview
But it's not working. Am also tried as per this post. Its not working.Is there any way to load image to image view without scaling?
you can use Bitmap.createScaledBitmap with the orignal mesaures of the picture..
int width = orignal bitmap width
int height = orignal bitmap height
Bitmap bm;
bm = getBitmap... from network
bm = Bitmap.createScaledBitmap(bm,width,height,true);
this will create a image scaled properly and just place it in the ImageView.

display image with transparent color at runtime

I try to display a jpg in android-canvas with a specific transparent color.
It works well with a png and I also know how to convert a jpg to png with java so at the end I have a new png-file on the filesystem.
Now my question:
Is there a way to read a jpg file from the filesystem, set a transparent color at runtime (convert to png) and display the image at runtime ?
additional comment:
I try to do this in my custom view with the ondraw method and drawbitmap. I can't use an imageview. :-(
regards
Andreas
don't make the image transparent but the view.
ImageView myImage = (ImageView) findViewById(R.id.img);
myImage.setAlpha(value);
Value is something between 0 and 255. The lower the number, the more transparent the imageview.

Deep copy of a Drawable

I have an ImageView. In its onClick I get its Drawable:
Drawable dr = ((ImageView) v).getDrawable();
And set it to a dialog's ImageView:
zoomedImage.setImageDrawable(dr);
But when I close the dialog or the activity is resumed. The image at the original position gets stretched and is shown larger than its size, leading to only a portion of the image is visible in the ImageView.
Is this a case of deep copy or there is another problem?
If it is, how can do I deep copy the original Drawable so that I could set the copy to zoomed image?
Thanks in advance.
Finally I succeed!
I had similar problem, when I used color filter on my drawable it changed the drawable, its very close to the solution of the other people here, but only this worked for me:
Drawable drwNewCopy = dr.getConstantState().newDrawable().mutate();
I managed to copy the drawable using following code:
drawable.mutate().getConstantState().newDrawable();
Here mutate() makes the drawable mutable to avoid sharing its state, and getConstantState().newDrawable() creates a new copy.
Thus different ImageViews use different drawables and there's no stretching.
Use BitmapFactory to convert the drawable into bitmap separately make or perform changes on it.
The above solutions won't work for me, But it works
val myDrawable = DrawableCompat.wrap(view.background).mutate() as GradientDrawable
myDrawable.setColor(ContextCompat.getColor(view.context, R.color.White))

How to Show Image in Android using Java Code

I am try to show a image in android using java code not xml.
I have done it using xml file but my requirement is using
java code to get more funcionality .
thanks in advance for help........
IF you want to load image from drawable folder, you can using:
ImageView imgView=(ImageView) findViewById(R.id.imgView);
Drawable drawable = getResources().getDrawable(R.drawable.img);
imgView.setImageDrawable(drawable);
You have to use one default imageview in android xml when you are running app that time
in activity you have to write this code so it will replace you image with another image.
Check following code
ImageView imgView=(ImageView) findViewById(R.id.default_imgView);
imgView.setImageResource(R.drawable.yourimagename);
Using Drawable class you can show Image
Drawable drawable = Drawable.createFromPath(imagePath);
image.setImageDrawable(drawable);
I hope you are using ImageView to display the image in XML file with id iv.
In java file
ImageView iv = (ImageView)findViewById(R.id.iv);
iv.setImageResource(R.drawable.image1); // image1 is image file available in drawables folder
use ImageView and learn more about it from here imageview referecne
you can set image from bitmap,uri, from resources, etc...
frist add the images to drawable folder
and using XML image view
image = (ImageView) findViewById(R.id.imageView1);
image.setImageResource(R.drawable.image_1);
image.setImageResource(R.drawable.image_2);
..
You can use the following code
ImageView img = new ImageView(this); /*In new version of Android Studio you don't need to do castling.*/
img = findViewById(R.id.android_image);
Drawable img_drawable=getResources().getDrawable(R.drawable.draw_img);
img_cookie.setImageDrawable(img_drawable);
The code below worked fine for me.
ImageView imageViewVar = (ImageView) findViewById(R.id.imageViewId);
imageViewVar.setImageResource(R.drawable.yourImgFile);

How can I set dynamically created bitmap as livefolder icon in android?

How can I set dynamically created bitmap as livefolder icon in android?
LiveFolder takes EXTRA_LIVE_FOLDER_ICON as ShortcutIconResource. Is there a way to reference dynamically created bitmap as shortcuticonresource? In the following code segment instead of using icon as int value I would like to set the file path for the newly created bitmap file.
intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,
Intent.ShortcutIconResource.fromContext(context, icon));
It is not possible to use bitmap from a file in a live folder.

Categories

Resources