Glide how can I do so that the views that were left off the screen are deleted in recyclerview - android-recyclerview

I am developing a Gallery app. And I'm using the GLIDE library to load thumbnails in a typical Recyclerview with an adapter. Everything is going very well Glide actually loads the thumbnails when I'm scrolling down but when I go back up the images are still loaded and what I want is that the items or view that were left off the screen are deleted and when I return they are loaded again and removed if off screen I hope your great help thank you very much`
here is my code
#Override
public void onBindViewHolder(#NonNull AlbumsAdapter.ViewHolder holder, #SuppressLint("RecyclerView") int position) {
holder.miniature.setLayoutParams(new RelativeLayout.LayoutParams(width,width));
Glide.with(context).load(list.get(position).getPath()).into(holder.miniature);
holder.album.setText(list.get(position).getDisplayName());
}
type here
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_album);
re=(RecyclerView)findViewById(R.id.recycler_list_album);
re.setHasFixedSize(true);
re.setItemViewCacheSize(3);
re.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
re.setNestedScrollingEnabled(false);
albumsAdapter=new AlbumsAdapter(ListAlbum.this,Albums,itemWidth);
re.setAdapter(albumsAdapter);
re.setAdapter(albumsAdapter);
The problem that the images loaded that were left off the screen remain because the size of the application increases as more images are loaded

Related

Screenshot doesn't match coordinates and size of element for iOS app

I'm using a Appium methods to take a screenshot and crop a perticular part of that screenshot according to coordinates and size of an element.
The way I do this:
Take a screenshot
This is done with getScreenShotAs() method
Crop out the part of that image
This is done
image.getSubimage(getElementCoordinateX(element),
getElementCoordinateY(element),
getElementWidth(element),getElementHeight(element));
public static int getElementWidth(MobileElement element) {
return element.getSize().getWidth();
}
public static int getElementHeight(MobileElement element) {
return element.getSize().getHeight();
}
public static int getElementCoordinateX(MobileElement element) {
return element.getLocation().getX();
}
public static int getElementCoordinateY(MobileElement element) {
return element.getLocation().getY();
}
I tested this approach on Android and it works as intended, but on iOS it crops out totally different part of the screenshot and I'm sure that it's the right element that's being located.
Developers told me that iOS apps work with frames and that I'm probably getting the bounds coordinates and not the frame's coordinates. I didn't find a way to interact with them using Appium. Is there a way to make this work as intended?
you can get screenshot of element directly using:
Ruby:
element = driver.find_element(:predicate, "type == 'XCUIElementTypeSlider'")
screenshot = driver.element_screenshot_as(element ,:base64)
This should crop the screenshot automatically and correctly...

how to get position of recylerview databinding

i am using data binding recycler view .i want to get that clicked position and show that position id(image) in view pager.i created data binding XML for image.
Position of clicked view does not matter, because views reused again and again while you scrolling content. You can directly set EventLisener to ViewHolder at onBindViewHolder(final ViewHolder holder, int position) method of RecyclerView.Adapter class

Overriding onDraw method of imageView un-centers drawable

I was following this tutorial http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html to make and imageview that can scroll in all directions. The problem is when I override the onDraw method and try to draw the drawable right to the canvas manually the drawable is off center.
#Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
getDrawable().draw(canvas);
canvas.restore();
}
if I comment out the method then the image is displayed centered in the middle correctly.
does overriding this method do something with the alignment?
After canvas.save() call canvas.concat with a Matrix taken by getImageMatrix()
P.S: Taken from pskink's comment, as this seems to have solved Brian's issue, I'm positing this as a separate answer so future readers can see it.

Android ViewPager and Camera Preview issue on Gingerbread

I did extensive documentation study on ViewPagers and on Camera apps, infact everything works quite fine, except for a major issue on GingerBread, which I haven't found any question about on S.O. so I'll try asking this one...
In my application there is a ViewPager (support library v4) which shows two fragments:
One, will call it the main fragment, the one showing when the activity starts, certain information are shown to the user, including an imageview, which is initially empty and hidden.
By swyping to the next fragment, the user sees the camera preview, which gets created when the activity is created (even if it not showing until the swype) and the button to take a picture.
When the picture is taken, the view is programmatically taken back to the main fragment, the
imageview is loaded with the new photo and unhidden so the user can see the image mixed with the other preexisting information.
If the user does not like picture, he can swype back again to the camera fragment and take another one, and so all over until he is satisfied with the result.
For this reason, before flipping back to the main fragment, I call mCamera.restartPreview() and ensure the camera is ready should the user swype back.
Everything works smoothly and fine on Android 4.x, but when I test this on a 2.3.3 (API Level 10) the camera preview remains in foreground when the main fragment is called back, and hides the view. You can see, and even scroll, the remainder of the view, in the portion of teh screen where the camerafragment shows the buttons, but the rest is overlapped by the camera preview.
Here is the code of the relevant functions:
CameraFragment onPictureTaken()
private PictureCallback mPicture = new PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile == null){
Log.d(TAG, "Error creating media file, check storage permissions: ");
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
Log.e(TAG, "FILE " +pictureFile.getAbsoluteFile().toString());
Bitmap bitmap = rotated(data);
bitmap.compress(CompressFormat.JPEG, PICTURE_QUALITY, fos);
bitmap.recycle(); //devo davvero chiamarla esplicitamente ??
mediaFile = pictureFile;
mPreview.restartPreview();
// go back to newpin activity to show it
((NewPinActivity) myActivity).newPin.setMedia(mediaFile.getAbsoluteFile().toString());
((NewPinActivity) myActivity).takeBack();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
}
}
};
and the mainfragment takeBack() method
public void takeBack(){
mViewPager.setCurrentItem(0, true);
String mainFragTag = "android:switcher:"+R.id.newpinpager+":0";
Fragment fragMain = this.getSupportFragmentManager().findFragmentByTag(mainFragTag);
try {
((NewPinMainFragment)fragMain).showPhoto(newPin.getMedia());
} catch (NullPointerException e){
}
}
Does anybody have a clue if this is an issue with the ViewPager and GingerBread or with the CameraPreview and Gingerbread or what ?
I found the answer by myself, I'll post it here in case it's going to be useful to others.
Apparently the problem was cause by the smoothscroll option of setCurrentItem method.
The issue was fixed by changing
mViewPager.setCurrentItem(0, true);
to
mViewPager.setCurrentItem(0, false);

Android View.onDraw() always has a clean Canvas

I am trying to draw an animation. To do so I have extended View and overridden the onDraw() method. What I would expect is that each time onDraw() is called the canvas would be in the state that I left it in and I could choose to clear it or just draw over parts of it (This is how it worked when I used a SurfaceView) but each time the canvas comes back already cleared. Is there a way that I can not have it cleared? Or maybe save the previous state into a Bitmap so I can just draw that Bitmap and then draw over top of it?
I'm not sure if there is a way or not. But for my custom views I either redraw everything each time onDraw() is called, or draw to a bitmap and then draw the bitmap to the canvas (like you suggested in your question).
Here is how i do it
class A extends View {
private Canvas canvas;
private Bitmap bitmap;
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (bitmap != null) {
bitmap .recycle();
}
canvas= new Canvas();
bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
canvas.setBitmap(bitmap);
}
public void destroy() {
if (bitmap != null) {
bitmap.recycle();
}
}
public void onDraw(Canvas c) {
//draw onto the canvas if needed (maybe only the parts of animation that changed)
canvas.drawRect(0,0,10,10,paint);
//draw the bitmap to the real canvas c
c.drawBitmap(bitmap,
new Rect(0,0,bitmap.getWidth(),bitmap.getHeight()),
new Rect(0,0,bitmap.getWidth(),bitmap.getHeight()), null);
}
}
you should have a look here to see the difference between basic view and surfaceView. A surfaceView has a dedicated layer for drawing, which I suppose keeps track of what you drew before. Now if you really want to do it on a basic View, you could try to put each item you draw in an array, like the exemple of itemized overlay for the mapview.
It should work pretty much the same way
Your expectations do not jib w/ reality :) The canvas will not be the way you left it, but it blank instead. You could create an ArrayList of objects to be drawn (canvas.drawCircle(), canvas.drawBitmap() etc.), then iterate though the ArrayList in the OnDraw(). I am new to graphics programming but I have used this on a small scale. Maybe there is a much better way.