Smart Gallery Java App Download

Posted on
  1. Gallery App Download Android

This is a SMART app that can be used inEHR (electonic health record) systems supporting SMART on FHIR to displayFHIRSDCQuestionnaire formsand collect data as FHIR QuestionnaireResponse resources.

Download Android Wear - Smartwatch APK (latest version) for Samsung, Huawei, Xiaomi, LG, HTC, Lenovo and all other Android phones, tablets and devices. Based on 22 years of education expertise, Notebook is designed for schools and used by 2.4 million educators worldwide. Download your copy now!

Demo

There is a demoof this app running as a GitHub pages website, but to see it work with a SMARTon FHIR context, try it out via theSMART App Gallery.(That will open a page containing the GitHub pages demo, but the SMART on FHIRconnection will be established, so you will be able to save and load FHIRresources.)

The app relies on the LHC-Forms renderingwidget for displaying forms. It has partial support for both FHIRSTU3 andR4 SDC Questionnaires.

For some sample forms to try, this repository comes with some forms undere2e-test/data which are used by the test code to test the app. The FHIR serverin the SMART App Gallery gets reset nightly, so might not find Questionnairesthere, but you can always use the Upload button to upload a new Questionnaireresource. If downloading one of the forms from GitHub, be sure click on the'Raw' button, which will open a page which only has the Questionnaire data. Forexample:https://raw.githubusercontent.com/lhncbc/lforms-fhir-app/master/e2e-tests/data/vital-sign-questionnaire.jsonwill open a page for a vital signs Questionnaire which you can save to a localfile and then use 'Upload' to use it in the app.

Customizing the App

If you wish to install and build the app locally so that you can customize it,see below. Note that adding support for additional parts of the SDC specification willrequire edits to the LHC-Forms widget. (Pullrequests are very welcome, but it might be better to open an issue first to seeif we are already working on that feature.)

Install Dependencies

We have two kinds of dependencies in this project: tools and Angular framework code. The tools helpus manage and test the application.

  • We get the tools we depend upon via npm, the Node package manager (npm).
  • We get the Angular code via bower, a client-side code package manager (bower).
  • In order to run the end-to-end tests, you will also need to have theJava Development Kit (JDK) installed on your machine. Check out the section onend-to-end testing for more info.

We have preconfigured npm to automatically run bower so we can simply do:

Behind the scenes this will also call bower install. After that, you should find out that you havetwo new folders in your project.

  • node_modules - contains the npm packages for the tools we need
  • app/bower_components - contains the Angular framework files

Note that the bower_components folder would normally be installed in the root folder butangular-seed changes this location through the .bowerrc file. Putting it in the app foldermakes it easier to serve the files by a web server.

Run the Application

We have preconfigured the project with a simple development web server. The simplest way to startthis server is:

Now browse to the app at localhost:8000/lforms-fhir-app/.

Running End-to-End Tests

The angular-seed app comes with end-to-end tests, again written in Jasmine. These testsare run with the Protractor End-to-End test runner. It uses native events and hasspecial features for Angular applications.

  • The configuration is found at e2e-tests/protractor-conf.js.
  • The end-to-end tests are found in e2e-tests/*spec.js.

Protractor simulates interaction with our web app and verifies that the application respondscorrectly. Therefore, our web server needs to be serving up the application, so that Protractor caninteract with it.

Before starting Protractor, open a separate terminal window and run:Kreps notes on the theory of choice.

In addition, since Protractor is built upon WebDriver, we need to ensure that it is installed andup-to-date. The angular-seed project is configured to do this automatically before running theend-to-end tests, so you don't need to worry about it. If you want to manually update the WebDriver,you can run:

Once you have ensured that the development web server hosting our application is up and running, youcan run the end-to-end tests using the supplied npm script:

This script will execute the end-to-end tests against the application being hosted on thedevelopment server.

There are many reasons you might find yourself needing to create an image gallery – whether it’s to show off album covers for a music app, to present feature images for articles in a feed, or to showcase your work in a portfolio. To make the right impression though, these apps should allow users to effortlessly swipe through multiple images without slowdown and that’s where things get a little tricky.

This tutorial will show you how to create a seamless gallery filled with nice big images and then adapt that for a number of different applications. Along the way, we’ll see how to use RecyclerViews, adapters and Picasso – so hopefully it will make for a great learning exercise, whatever you end up doing with it! Full code and project included below…

To create our Android gallery, we’re going to use something called a RecyclerView. This is a handy view that acts very much like a ListView but with the advantage of allowing us to scroll quickly through large data sets. It does this by only loading the images that are currently in view at any given time. This means we can load more images without the app becoming very slow. There’s a lot more that you can do with this view and it’s used all over Google’s own apps, so check out the full explanation to using RecyclerView to find out more.

The good news is that this is all we really need to create our gallery – a RecyclerView filled with images. The bad news is that the RecyclerView is a little more complicated than most other views. Because of course it is.

RecyclerView is not, for starters, available to drag and drop using the design view. So we’ll just have to add it to the activity_main.xml, like so:

Notice that we’re referencing the Android Support Library. This means we also need to modify our build.gradle in order to include the dependency. Just add this line to the app level file:

And if that’s not installed, then you’re going to have to open the SDK manager and install it. Fortunately, Android Studio is pretty smart about prompting you to do all this. I just got a new computer, so I can play along with you!

Head back to the XML and it should now be working just fine. Except the list is not populated except with ‘item 1, item 2, item 3’. What we need to do, is load our images into here.

As mentioned, populating our recycler view is a little more complicated than using a regular list. By which, I mean it’s way more complicated… but it’s a great chance for us to learn some handy new skills. So there’s that.

For a RecyclerView, we’re also going to need a layout manager and an adapter. This is what’s going to allow us to organize the information in our view and add the images. We’ll start by initializing our views and attaching an adapter in the onCreate of MainActivity.java. This looks like so:

We’re setting the layout as activity_main, then we’re finding the RecyclerView and initializing it. Notice that we use HasFixedSize to make sure that it won’t stretch to accommodate the content. We’re also creating the layout manager and the adapter here. There are multiple types of layout manager but true to gallery-form, we’re going to pick a grid rather than a long list. Remember to import the GridLayoutManager and the RecyclerView as Android Studio prompts you to do so. Meanwhile, when you highlight MyAdapter, you’ll be given the option to ‘Create Class MyAdapter’. Go for it – make your own MyAdapter.Java and then switch back. We’ll come back to this later.

Before we can use the new adapter class, we first need to create our data set. This is going to take the form of an array list. So in other words, we’re going to place a list of all our images in here, which the adapter will then read and use to fill out the RecyclerView.

Just to make life a little more complicated, creating the Array List is also going to require a new class. First though, create a string array and an integer array in the same MainActivity.Java:

The strings can be anything you want – these will be the titles of your images. As for the integers, these are image IDs. This means they need to point to images in your Drawables folder. Drop some images into there that aren’t too massive and make sure the names are all correct.

Remember: a list is a collection of variables (like strings or integers), whereas an array is more like a filing cabinet of variables. By creating an ArrayList then, we’re basically creating a list of filing cabinets, allowing us to store two collections of data in one place. In this case, the data is a selection of image titles and image IDs.

Now create a new Java Class called CreateList and add this code:

What we have here is a method we can use to add new elements (setImage_title, setImage_ID) and retrieve them (getImage_title, getImage_ID). This will let us run through the two arrays we made and stick them into the ArrayList. You’ll need to import array lists.

We do this, like so:

So we’re performing a loop while we go through all the image titles and adding them to the correct array in the ArrayList one at a time. Each time, we’re using the same index (i), in order to add the image ID to its respective location.

Confused yet?

Before you head over to MyAdapter.java, you first need to create a new XML layout in the layout directory. I’ve called mine cell_layout.xml and it looks like so:

All this is, is the layout for the individual cells in our grid layout. Each one will have an image at the top, with text just underneath. Nice.

Now you can go back to your MyAdapter.java. This is where we’re going to take the list, take the cell layout and then use both those things to fill the RecyclerView. We already attached this to the RecyclerView in MainActivity.Java, so now all that’s left is… lots and lots of complex code.

It’s probably easiest if I just show you…

So what we’re doing here is to get our ArrayList and then create a ViewHolder. A ViewHolder makes it easier for us to iterate lots of views without having to write findViewByID every time – which would be impractical for a very long list.

We create the VewHolder by referencing the cell_layout file we created earlier, and then bind it with the data from our ArrayList. We find the TextView first and set that to be the relevant string, then we find the ImageView and use the image ID integer to set the image resource. Notice that I’ve also setScaleType to CENTER_CROP. This means that the image will be centered but cropped to fill the enter cell in a relatively attractive manner. There are other scale types but I believe that this is by far the most attractive for our purposes.

Don’t forget to import the ImageView and TextView classes. And remember you need to add some images to your drawables folder. Once you’ve done that though you should be ready to go!

Give it a try and you should end up with something that looks a little like this:

Except without all the pictures of me… This is just what I happened to have to hand, don’t judge!

Not working as expected? Don’t worry – this is a pretty complicated app for beginners. You can find the full thing over at GitHub here and then just work through each step while referring to the code.

So right now we have a strange slideshow of photos of me. Not really a great app…

So what might you use this code for? Well, there are plenty of apps that essentially boil down to galleries – this would be a great way to create a portfolio for your business for example, or perhaps a visual guide of some sort.

In that case, we might want to add an onClick so that we can show some information, or perhaps a larger version of the image when someone taps their chosen item. To do this, we just need to import the onClickListener and then add this code to onBindViewHolder:

If we wanted to load a selection of photos on the user’s device meanwhile, we’d simply have to list files in a particular directory. To do that, we’d just need to use listFiles to take the file names and load them into our ListArray list, using something list this:

Except you’ll be changing your path string to something useful, like the user’s camera roll (rather than the root directory). Then you can load the bitmaps from the images on an SD card or internal storage by using the image name and path, like so:

You’ll probably want to get thumbnails from them too. This way, the list will be populated dynamically – so that when new photos are added to that directory, you’re gallery will update to show them each time you open it. This is how you might make a gallery app for displaying the images on a user’s phone, for example.

Or alternatively, another way we could make this app a little fancier, would be to download images from the web.

This might sound like a whole extra chapter but it’s actually pretty simple as well. You just need to use the Picasso library, which is very easy and completely free. First, add the dependency like we did earlier:

Then, change your ArrayList to contain two string arrays instead of a string and an integer. Instead of image IDs, you’re going to fill this second string array with URLs for your images (in inverted commas). Now you just swap out the line in your onBindViewHolder to:

Remember to add the relevant permission and it really is that easy – you can now download your images right from a list of URLs and that way update them on the fly without having to update the app! Picasso will also cache images to keep things nice and zippy for you.

Note as well that if you wanted to have more than two images per row, you would simply swap:

For:

This will give you something like the following:

If you don’t like the text and you just want images, then you can easily remove the string array from proceedings. Or for a quick hack if you don’t want to stray too far from my code, you can just make the TextView super thin.

And there you have it – your very own basic image gallery. There are plenty of uses for this and hopefully you’ve learned a few useful bits and pieces along the way. Stay tuned for more tutorials just like this one!

Java apps for phones

And remember, the full project can be found here for your reference.

Comments
Please enable JavaScript to view the comments powered by Disqus.