How to implement custom device photos gallery for android? - android

I'm working on android application that will have basic image gallery functionality included. I've managed to build activity that fetches list of photos from my application backend API and render them in android gridview within activity layout.
This is how it looks like at the moment:
However I'm having difficulties to build same gallery experience for user's device photos that were taken by camera and stored on device. Two solutions I considered were:
Building my own image gallery.
Starting default android image gallery using intent.
Solution 1: I belive that first solution will take me too much time to developed. I started with this tutorial but as soon I implemented it I found out that it is running too slow. Then I take a look at android camera source code to find solution but again I found that it will take me too much time to review the code and to build my own gallery from scratch. I also believe that it is not in Android OS philosophy to rewrite functionalities that already exists but to use Intents to start activities that can handle actions you need. This lead me to second solution.
Solution 2: I tried calling default android gallery using intent in order to browse user's device photos by soon I was stuck again. Problem this time was that as soon as user tap on photo, gallery exits and returns to activity that originaly started it, and I expected (and I want) to start large image preview instead. I saw that others had this problem too how to open gallery via intent without result.
Because I didn't find the fix for this I decided to quit.
My question is how can I overcome these problems and build gallery that is similar to one I already have for web photos.
If anyone could give me reference I would be most thankful.

this question is pretty old but, as it has a lot of views and quite a lot of upvotes, it could be good to bring an answer to it.
So, first the tutorials evolved a bit and you can find some cool stuff for your #1 option:
This is the one I prefer
This one uses a deprecated UI element but is also cool
This uses an Adapter which is, to me, the best way to proceed.
For your #2 option, I do not see any idea to not to return to the original activity because you still do not have control over the result of the intent you send through the system.
But there are another solution that you didn't mention: there are librairies which are very cool and that you could customise to get exactly what you want:
This one is a bit fancy
This one seems also to be pretty cool but you could have problems importing it because it's not a gradle project
This is the one I would definitely use.

Related

displaying images in android with zoom/pan/rotate etc functionality

So i got a lot of solutions online but none of them were simple and complete. First i tried using imageview and adding external libraries for zooming etc. but i couldn't find one which had all the functionality we see in a gallery app without being extremely slow. I read something about canvas though don't know what it is. I also found "zooming a view" in android official tutorial but it was just a single tap zoom. So which is the best solution (in terms of functionality and speed) for this: I want an activity to show just a single image such that the user can zoom/rotate/pan it as its gonna contain text that the user needs to be able to read. So basically just like a gallery app. Is it possible to call on the gallery app activity to display this image? Why doesnt android have better support to do this? What is the best way you would suggest.

Android app - logic / principles

Hello guys (and girls),
I need your help in the matter of how to structure things in an Android app that I'm developing.
So far I have:
a Login activity that shows up right after the app is started
a Main activity that display some options for the user. Among them there is an option to start the device's camera (user taps on an icon that should launch the Camera), take a picture, crop it / rotate it and upload it to a remote server
Now, my question is: how should I organize things in my app logic so that everything will be clear and easy to manage in the future, for the upcoming versions?
I'm thinking like this but I'm not sure if it is the right way:
create a separate activity (eg. PictureCaptureActivity) for the picture capture task
create a separate activity (eg. PictureProcessActivity) for the picture processing tasks (crop and / or rotate - these options will be available via some buttons displayed on screen, in the main menu bar)
create a separate activity (eg. PictureUploadActivity) for the picture upload tasks
Or should I include all these functionality in my MainActivity somehow? Or... ?
Thank you in advance for your guidelines!
Before i start referring you to well written documentation and examples i have one main point i would like to emphasis and convey.
You are referring to Activities where modern Android applications are compartmentalized by Fragments (not that modern, almost 3 years) and the point of that being that the same application can work by utilizing almost 100% of the code on all Android* devices and form factors (mobile, tablet, TV, wear, auto etc.).
Now lets talk business, the best place to start reading on regarding Android is Google:
Design/patterns/application structure - from the android.developers.com documentation site.
Application quality checklist - created by Google following hundreds of case studies and a meticulously planned UX test.
Design guidelines - updated just 2 days ago (16.4.15).
IOSched - Google's display window for Android code where they show how they think an Application should look, feel and behave.
After that i would love to link you to a code lab i co-wrote with a couple of friends and a few blog posts i have written as a follow-up:
AndConLab
My tech blog on Android
Goodluck.
PictureCaptureActivity
Do you want to have a custom interface for taking pictures with the camera, or use an existing application on the phone?
Yes - You will need a PictureCaptureActivity and will have to implement the camera functionality yourself.
No - You can use an Intent to get the user to take a picture using another application and return it to you.
Either way, you will need to look at the Camera documentation.
PictureProcessActivity
You will most likely need to have a PictureProcessActivity to process the pictures in the manner you want.
PictureUploadActivity
The PictureUploadActivity is not really necessary. You could use a Progress Dialog or Progress Bar to show the progress in the PictureProcessActivity.
MainActivity
In my opinion you need at least two activities:
MainActivity / PictureCaptureActivity to take a photo
PictureProcessActivity to process the photo
You could fit it all into one activity by hiding and showing icons in the Action Bar, but I'd rather not because the Activity Documentation states:
An activity is a single, focused thing that the user can do.
Disclaimer: There is no 100% correct way to do this.
I've found this to be very helpful when it comes to code keeping: https://google-styleguide.googlecode.com/svn/trunk/javaguide.html
The one thing I can't stress enough: comment your code

Zbar bar code native extension for AIR will not launch after home button takes focus away from application

Following the simple instructions for the qr-zbar, I have successfully implemented a native barcode scanner! It works great so far.
qr-zbar-ane Github: https://github.com/saumitrabhave/qr-zbar-ane
Unfortunately, while actively scanning, if the home button is pressed or another activity takes over, upon coming back to the original application the activity is stuck and will not initialize the bar code scanner anytime after that.
I have tried multiple ways of reloading and switching views in the air application to call a new instance of the qr-zbar.
Resetting:
scanner.removeEventListener(ScannerEvent.SCAN, onScan);
scanner.stop();
scanner.reset();
scanner = null;
Creating again:
scanner = new Scanner();
scanner.setTargetArea(targetArea,"0xF53100","0x4BFF33");
scanner.setConfig(Symbology.ALL,Config.ENABLE,1);
scanner.addEventListener(ScannerEvent.SCAN, onScan,false, 0, true);
scanner.launch(true, "back");
loadGroup.visible = false;
trace("Launched: " + ServerRequest.scanner.launched);
Here is the Issue described in the commit notes! Exact problem.
https://github.com/saumitrabhave/qr-zbar-ane/blob/master/NativeAndroid/src/com/sbhave/nativeExtension/ui/CameraActivity.java
Update: I found that this is the case for a newer update to android. Downloading a keylogger for Galaxy S4 and Nexus 5, I'm unable to see the KeyEvent for a home button press.
Firstly apologies for such a long response time. Here is a point-wise update which will also answer your question (hopefully).
The reason you see the code in repository but still issue not being fixed, its because I did not update the .ane which includes this fix. So, if you want to get it running with current APIs, you may need to checkout the project(at the last commit with old API) and re-compile/re-generate the ane on your end. I know, it doesnt sound interesting, read the next point for a good news (maybe).
As you might have seen already the old model wasn't flexible enough, As it spawns its own Activity, Actionscript developer did not have any control over the UI in scanning mode. Hence I have re-designed the whole API in which the Scanner acts similar to a StageWebView(i.e. placed on top of the stage at given position and with given size so that you can have your own UI around it, with the limitation that you can not draw ON THE scanner).
2.1 It also removes the notion of SingleScan or MultiScan and gives the developer flexibility to implement his own nature of scanning using APIs like pause(), resume(), attach and detach scanner while camera preview is in progress etc.
2.2 It will also have other features like Scanning from a given Bitmap instead of Live Camera feed.
Any of the option above should fix your issue,
I would like to get suggessions/feedbacks/bugs as I am in the implementation phase,I can quickly resolve any valid use-cases you may have around the library.

Design of list view lazy loading images component

I have a scenario which I think is pretty common in Android applications. I know partial attempts of solving the issue were made, but until now I have not stumbled upon the full implementation. I intend to try to implement such component and open source it afterwards, but I need your help in its design.
So basically my case is the following: I have list view showing image loaded from the web and text per each row. I want to lazily load the images, placing default for each image and substituting it with the real one only when the image is downloaded. I also want to keep image cache avoiding the need to download the images multiple times in short period.
Up to now I have found several implementations that are partially working including:
Tom van Zummeren's implementation of similar component with several well known problems
Jeremy Wadsack's refinement of the concept, which is more or less working
Lazy drawables source forge project.
I also saw several stackoverflow questions regarding the problem: 1, 2, 3
However I have one more requirement which makes my task a bit more complex: I allow the user of my application to affiliate himself with some of the images. I want to load the new images associated to the user whenever the user navigates to the home screen. From it he should be able to go see his images, even before they have all been downloaded and in this case again default placeholders should be visible (Note the cross screen transition). Such use cases are:
An app listing user's youtube videos
An app for facebook - consider the images of friends
An app serving news that supports user's favorites etc
Note that I want to start fetching the new data related to the user on the home screen to provide better user experience. I will keep the user-related data stored locally forever.
The question
So my basic question is what approach should I use for the implementation of the image downloading? I know that the Android manuals say Service should be used only when I want to execute task even when application is not running. On the other side I will start the image downloading on the home screen and link the downloads to UI elements just when the user navigates to the new screen (Activity) - user-related list view and I do not know how to achieve that with AsyncTask (not that I have a very precise idea how to do it with Service either).
Any suggestion will be greatly appreciated, including links.
Universal Image Downloader is a good library which helps you to do image downloading in background with your settings.
It has so many features that you can implement at your own way.

to get a current screen view from my own application

I am running one external application from my own application and when this application opens, i want to get a view of that external application in my own application. So that i can capture a screenshot of it. Please help me in this.
I dont think thats possible. The communication between applications or even activities is limited to passing data to each other through intents. I don't think sharing references to objects across applications is possible. Please correct me.
Such a thing would be possible if they allowed you to launch an external application in your own window.
I did some search and it is quite likely it may not be possible, however I have found a possible way. Take a look at this link, which states that
Or If you want to take a ScreenShot of your current device screen (any
application) then you have to root permission, and read framebuffer
for that which will give raw data of current screen then convert it to
bitmap or any picture file you can do it in your service.
Which means that whenever your application starts an application you will need to create a service that reads the framebiffer, but if an activity is used for taking the screenshot then it will not be useful because the screenshot will then be of that activity.
See this and this, these links are related to your question as well. And see if it works.
Hope this helps.

Categories

Resources