I am currently creating an application to display images from an SD card. Basically you make an album and add pictures to it, whether from the MediaStore collector’s camera.
I tried to implement 2 methods:
- Standard gallery app with custom BaseAdapter to return view
- Viewer with custom PagerAdapter
I do not want to display the grid view, so it should immediately go into full screen mode. After that, I want to disable scrolling left and right and only listen for clicks.
Atm both methods work in portrait mode. When I switch to landscape, some images just drop
03-20 12:20:56.515: W/OpenGLRenderer(17398): Bitmap too large to be uploaded into a texture
and then memory errors. Stack overflow, if it is full of problems with OOM and gallery, you should rework the views to make them work, because convertView is always null in getView from BaseAdapter.
So, I used recycler for views, I limit it to 2 views and portrait mode working on method 1 (using the gallery). The landscape still gives me the same problem.
For method 2 (viewflipper) it processes the views
@Override public void destroyItem(ViewGroup container, int position, Object object) {
This is never called btw ... However, portrait mode works here. The landscape is still falling.
My raster image acquisition method:
public static Bitmap getBitmap(Context ctx, int imageId, ImageView target) { String file = getPath(ctx, imageId); BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(file, bmOptions); WindowManager mgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); int scaleFactor = 1; if (mgr != null) {
It works well, I know that I use the window manager to get the screen, but that is because my ImageView still has a size (0,0) when I inflate it. Subsequently i call
imgView.setLayoutParams(new Gallery.LayoutParams( Gallery.LayoutParams.FILL_PARENT, Gallery.LayoutParams.FILL_PARENT)); imgView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
Nothing works ...
Please note that I do not use drawables or any other resources included in the APK. This gallery should be able to download images from an SD card or camera no matter what quality they were made. Obviously, the gallery should be able to process as many images as there are in the catalog.
Can someone please help me with the following questions?
- Is there a way to make the default gallery right away in full screen and lock the grid? Thus, I only need an adapter to provide images instead of creating my own views. (perhaps this fixes OOM crashes).
- Is my bitmap decoding function ok? Do I need to create some kind of hacks to catch landscape changes?
- What is the best way to make the gallery I need using a viewer or gallery?
- Does anyone have an example full-screen gallery code that doesn't crash?