Stony Brook Young Investigators Review Fall 2018

Page 35

Figure 2 The user sets a time, and a notification banner pops at that time daily. (left) Figure 3 a TimePickerDialog object. (right)

user inputs the hour and minute of the day at which he or she likes to be reminded to take photos, and at that time of the day, every day, a notification banner will pop up (Figure 2) on the phone’s lock screen, or if the phone is unlocked, at the top of the screen and disappear shortly. When the user presses “Set time” to set the time, a TimePickerDialog object is constructed with an onTimeSetListener inner anonymous class, which contains methods (indicated by “()”) that perform functions that programmers want done. An onTimeSetListener() class listens for when the user sets a time using the TimePickerDialog and does something with that time; in this case, the Listener gives the time to the onTimeSet() method and displays it in the layout, so the user can see the time they last picked after closing the TimePickerDialog(). Inside the onTimeSet() definition, scheduleNotification() is called and passed the time the user picked. scheduleNotification() creates an Intent to run another Java class called AlarmReceiver, then a PendingIntent from that Intent. An Intent requests another class to perform something that the class containing the Intent cannot do. The Android system’s AlarmManager takes this PendingIntent and is told by scheduleNotification() to execute it at the user-input time daily. The AlarmManager’s job is to manage the alarms for waking up different apps. Every app that can be woken up by the AlarmManager has a class whose job is to do certain things when the app gets woken up. In this case, the job of the Side By Side app’s AlarmReceiver class is to send out a notification to users reminding them to take a photo of themselves. The second function added to the app allows two photos from the phone’s gallery to be displayed side by side. When the user picks either photo from the gallery, an Intent is created to open a Dialog for the user to pick a photo. The Intent is sent to the phone using startActivityForResult() so the phone’s system can pick another app to carry out the function the Intent asks. In this case, the system has a built in interface for the user to pick a photo from the gallery and send that photo back the app. Along with the Intent, an ID was placed inside the call of startActivityForResult(). When the phone sends back the data requested by the Intent, the system calls the app’s onActivityResult() method and passes to it the photo picked by the user along the ID, previously placed inside the startActivityForResult() call, allowing the programmer to identify and work with the photo. In this case, the photo’s Uri memory address is obtained, which identifies a particular resource, and a Bitmap photo file is generated from the Uri, where the photo is stored, to be displayed in one of the two layout ImageViews placed side by side. The third function added was retrieving and editing the .exif data of JPEG photos so users can store the their health information in the form of .exif data linked to photos and let the app retrieve the

information and display it for the corresponding photos. To retrieve .exif data, an InputStream is created from the photo Uri sent back by the app in onActivityResult(). Subsequently, an ExifInterface is created to edit the .exif data pointed to by the InputStream. Using getAttribute(), the ExifInterface returns the image description stored as .exif data for that particular photo. To edit .exif data, a file path is first obtained from the Uri retrieved in the definition of onActivityResult(). Using setAttribute() and saveAttributes(), the ExifInterface object– created to edit the .exif data pointed to by the file path– sets the image description to the data inputted by the user. The fourth function is displaying .exif data in scroll wheels. The scroll wheels were pre-made and incorporated into the app by adding the package name of the CarouselPicker GitHub library to the app’s dependencies in Android Studio. Adding the package name to the dependencies allowed the app to rely on the library and refer to code components within the library as if the code is part of the app. Once the package is added, the CarouselPicker class can be used in Java code in Android Studio. First, a Java List was made and had content (numbers like “184 pounds” and “08/02/2017”) added to it; a CarouselViewAdapter was made from that List-the adapter feeds an element to the CarouselPicker to display it when the user scrolls to that element, and reclaims the memory taken up by the elements scrolled past and no longer visible on the screen. To display the .exif data, the entire Java String of the image description (e.g., “125 65 25 Hello there”) is broken down into individual elements by space and stored in an Array (i.e., {“125”, “65”, “25”, “Hello”, “there”}). The first element is always the user’s weight in pounds, the second being the user’s height in inches, and the third being the user’s BMI in kilograms/m2. All the elements after the third element are the user’s comments, which will be re-assembled by space and will not be displayed in the Carousel but rather in a separate Dialog. These elements in the array are then put in the List used to make the CarouselViewAdapter along with words like “pounds” and “inches” to indicate which number is the weight and which the height and so on, and displayed in the Carousel. The image description .exif data was inputted by the user, except for the date on which the photo was taken. The data CharSequence, a string of characters, is obtained from the Cursor returned by managedQuery(). A Cursor has multiple columns, like a 1-by-n matrix. One of the columns contains the date in number of seconds since 12 a.m. on Jan 1, 1970 in UTC. This number is then converted to a CharSequence of the format MM/dd/yyyy using format() of the DateFormat class. The fifth function is creating and sharing the collage. When the user puts two photos side by side, the user can share the collage. When “Share collage” is pressed, a Dialog will pop up (Figure 4). In the Dialog, when “Share” is pressed, a list of social media apps already downloaded on the phone is shown (Figure 5) and the user can choose one to share his or her collage. To create the collage, the screenshot of part of the screen– a layout XML ImageView– was made using Java code. The Bitmap, obtained in onActivityResult() from the Uri of the photo the user has picked, is then placed inside this ImageView object; a Dialog is built, and the ImageView is placed inside of it. To share the collage, a ByteArrayOutputStream is created to compress the Bitmap collage into a JPEG. Then, an imaginary file path is created (imaginary because the collage is not stored in the phone so there is no file path for it) and an Uri is created from the file path. Within this Uri, an Intent or a request can be called for the phone’s system to display a list of social media app to share the photo located at this Uri memory address. How the SSH connection between app and camera was set up A Raspberry Pi 3B was used with Linux Raspbian Operating System installed on it. To make it a SSH server, the Terminal window was opened, “Interfacing Options” was selected, and when “SSH” is clicked on, “Yes” is chosen. After a reboot, the Raspberry Pi became a SSH server, and was ready to be connected to a SSH client! To make the app a SSH client, the JSch SSH

33


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.