movie box an android application using rest …

91
MOVIE BOX AN ANDROID APPLICATION USING REST INTERFACE A Project Presented to the faculty of the Department of Computer Science California State University, Sacramento Submitted in partial satisfaction of the requirements for the degree of MASTER OF SCIENCE in Computer Science by Suganya Srinivasan FALL 2017

Upload: others

Post on 11-Nov-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MOVIE BOX AN ANDROID APPLICATION USING REST …

MOVIE BOX

AN ANDROID APPLICATION USING REST INTERFACE

A Project

Presented to the faculty of the Department of Computer Science

California State University, Sacramento

Submitted in partial satisfaction of

the requirements for the degree of

MASTER OF SCIENCE

in

Computer Science

by

Suganya Srinivasan

FALL

2017

Page 2: MOVIE BOX AN ANDROID APPLICATION USING REST …

ii

© 2017

Suganya Srinivasan

ALL RIGHTS RESERVED

Page 3: MOVIE BOX AN ANDROID APPLICATION USING REST …

iii

MOVIEBOX

AN ANDROID APPLICATION USING REST INTERFACE

A Project

by

Suganya Srinivasan

Approved by:

__________________________________, Committee Chair

Dr. V.Scott Gordon

__________________________________, Second Reader

Dr. Doan Nguyen

_______________________

Date

Page 4: MOVIE BOX AN ANDROID APPLICATION USING REST …

iv

Student: Suganya Srinivasan

I certify that this student has met the requirements for format contained in the University

format manual, and that this project is suitable for shelving in the Library and credit is to

be awarded for the project.

__________________________, Graduate Coordinator ___________________

Dr. Jinsong Ouyang Date

Department of Computer Science

Page 5: MOVIE BOX AN ANDROID APPLICATION USING REST …

v

Abstract

of

MOVIEBOX

AN ANDROID APPLICATION USING REST INTERFACE

by

Suganya Srinivasan

There are lot of movies available to watch and nowadays people prefer to watch movies at

home rather than going to theatres. They don’t want to waste spending time and money on

a worthless movie. So how are they going to figure out what’s good and what’s not-so-

good? What if the Netflix recommendations aren’t working for them? The purpose of this

app is to point the user in the direction of something worth checking out. The application

that I have developed is an attempt to make use of all the latest technologies and integrate

them into a useful app. This application allows users to discover the most popular movies,

Top rated and Upcoming movies which are now running in theatres. After reading the

synopsis and reviews, people get the flexibility to decide if they want to watch the movies

or not. The project has been developed using different technologies Java, Android and

SQLite and is integrated together with android libraries such as Picasso and Retrofit.

Page 6: MOVIE BOX AN ANDROID APPLICATION USING REST …

vi

The developed application is based on the data available in TMdb [The Movie DB API],

but can also incorporate new data sources. This application uses REST interface to pull

fresh content each time it opens from the database.

_______________________, Committee Chair

Chair Dr. V. Scott Gordon

_______________________

Date

Page 7: MOVIE BOX AN ANDROID APPLICATION USING REST …

vii

ACKNOWLEDGEMENTS

It is with my immense gratitude that I acknowledge the support and help of my Professor,

Dr. Scott Gordon, who has always encouraged me into this research. Without his

continuous guidance and persistent help, this project would not have been a success for me.

I want to thank Prof. Doan Nguyen for his contribution in completion of this project. I am

grateful to the California State University, Sacramento and department of Computer

Science without whom this project would have not been possible. I also thank my husband

Ashwin Lakshminarasimhan, who has been pillar of support and my family and friends,

for their endless love and support throughout my life.

Page 8: MOVIE BOX AN ANDROID APPLICATION USING REST …

viii

TABLE OF CONTENTS

Page

Acknowledgements ........................................................................................................... vii

List of Figures ................................................................................................................... xii

1. INTRODUCTION .......................................................................................................... 1

1.1 Motivation ................................................................................................................. 1

1.2 Related Work............................................................................................................. 1

1.3 Proposed System ....................................................................................................... 2

1.4 Features and Functionalities ...................................................................................... 3

2. BACKGROUND ............................................................................................................ 4

2.1 Android...................................................................................................................... 4

2.2 JAVA ......................................................................................................................... 4

2.3 RESTful API ............................................................................................................. 5

2.4 Terminology .............................................................................................................. 5

2.4.1 Activity ............................................................................................................... 5

2.4.2 Fragment ............................................................................................................. 5

2.4.3 Service ................................................................................................................ 6

2.4.4 Recycler View .................................................................................................... 6

Page 9: MOVIE BOX AN ANDROID APPLICATION USING REST …

ix

2.4.5 Adapter ............................................................................................................... 7

2.5 IDE & Tools Technologies ....................................................................................... 7

2.5.1 Android studio 2.3.3 ........................................................................................... 7

2.5.2 Android Software Development Kit [SDK] ....................................................... 8

2.5.3 Android Debug Bridge [ADB] ........................................................................... 8

2.5.4 Gradle ................................................................................................................. 8

2.5.5 Android Device Monitor .................................................................................... 9

2.5.6 SDK Manager ..................................................................................................... 9

2.5.7 AVD Manager .................................................................................................... 9

2.5.8 SQLite Database ............................................................................................... 10

2.5.9 Service Life Cycle ............................................................................................ 10

2.5.10 Picasso ............................................................................................................ 12

2.5.11 Retrofit ............................................................................................................ 12

3. SYSTEM DESIGN ....................................................................................................... 13

3.1 Architectural Design ............................................................................................... 13

3.2 Detailed Design ....................................................................................................... 14

3.2.1 Android Architecture ........................................................................................ 14

3.2.2 TMdb API ......................................................................................................... 15

Page 10: MOVIE BOX AN ANDROID APPLICATION USING REST …

x

3.2.3 Application Design ........................................................................................... 16

3.2.4 User Interface Design ....................................................................................... 19

3.2.5 Database Design ............................................................................................... 21

4. OVERVIEW OF IMPLEMENTATION ...................................................................... 22

4.1 Set up Android Environment................................................................................... 22

4.2 Creating Simple Android Application..................................................................... 22

4.3 Running the Android Application ........................................................................... 26

4.4 MainActivity ........................................................................................................... 28

4.4.1 Using Picasso to load image into Image View ................................................. 36

4.4.2 Using Retrofit to Retrieve the Movie Poster .................................................... 37

4.5 MovieDetailInfo Activity ........................................................................................ 48

4.5.1 Movie Poster ..................................................................................................... 49

4.5.2 Movie Title ....................................................................................................... 50

4.5.3 Movie Releasedate ............................................................................................ 51

4.5.4 Movie Rating .................................................................................................... 52

4.5.5 Movie Synopsis ................................................................................................ 53

4.5.6 Search Feature .................................................................................................. 53

4.5.7 Other Features................................................................................................... 54

Page 11: MOVIE BOX AN ANDROID APPLICATION USING REST …

xi

5. FUTURE WORK .......................................................................................................... 57

6. CONCLUSION ............................................................................................................. 58

APPENDIX A ................................................................................................................... 59

APPENDIX B ................................................................................................................... 74

BIBILIOGRAPHY ........................................................................................................... 76

Page 12: MOVIE BOX AN ANDROID APPLICATION USING REST …

xii

LIST OF FIGURES

Figures Page

Figure 1 Recycler View ..................................................................................................... 6

Figure 2 The Service Lifecycle ........................................................................................ 11

Figure 3 Model View Presenter ....................................................................................... 13

Figure 4 File structure ....................................................................................................... 15

Figure 5 TMdb API .......................................................................................................... 16

Figure 6 Use case diagram for User .................................................................................. 17

Figure 7 Use Case Diagram for Movie Detail Activity .................................................... 18

Figure 8 Class Diagram .................................................................................................... 19

Figure 9 Home Screen ...................................................................................................... 20

Figure 10 Application Work Flow ................................................................................... 21

Figure 11 New project view .............................................................................................. 23

Figure 12 Android devices selection................................................................................. 24

Figure 13 Activities and Customization windows ............................................................ 25

Figure 14 AVD Manager .................................................................................................. 27

Figure 15 Movie Box App Icon ........................................................................................ 28

Figure 16 Popular Movies Tab ......................................................................................... 38

Figure 17 Toprated Movies Tab ....................................................................................... 46

Page 13: MOVIE BOX AN ANDROID APPLICATION USING REST …

xiii

Figure 18 Upcoming Movies Tab ..................................................................................... 48

Figure 19 Movie Poster with Title .................................................................................... 49

Figure 20 Movie Title with Overview .............................................................................. 51

Figure 21 Movie Release Date .......................................................................................... 52

Figure 22 Movie Rating .................................................................................................... 52

Figure 23 Scrollable View of Movie Synopsis ................................................................. 53

Figure 24 Search View...................................................................................................... 55

Figure 25 Other Features .................................................................................................. 56

Page 14: MOVIE BOX AN ANDROID APPLICATION USING REST …

1

1 INTRODUCTION

1.1 Motivation

In Today’s world, People want to watch movies at home rather than going to theatres.

Streaming movies are becoming increasingly common these days, thanks to the high speed

internet streaming-enable devices like computers, Smart Tv’s. Also watching movies at

home is less expensive compared to watching movies at theatre. There are many

applications in the market which stream movies online. There are thousands of movies

streamed in different genres, so people prefer to pick the genre based on reading the movie

synopsis and getting to know more information about the movie. Studies show that more

than two-thirds of people prefer watching movies at home rather than theatres [1]. Also,

people are increasingly dependent on smart phones for on-the-spot information and Movie

box provides all the movie related information at one place.

1.2 Related Work

There are many applications on the market that provides movie information. GOOD

SHOW is an app which provides movie reviews and helps people discover movies and TV

shows from friend’s reviews and allows them to add movies to their watch list. But the

limitation is, it is an iOS app. Most of the apps like Netflix and Hulu require users to login

to the Netflix or Hulu service to use and get their personalized content and

recommendations. When the user just want to look for Movie titles and get an abstract of

Page 15: MOVIE BOX AN ANDROID APPLICATION USING REST …

2

the movie, this is a disadvantage. Some of the applications provide movie reviews, some

applications provide ratings and release information separately. For example, Guidebox

provides the list of sources where movies are available

1.3 Proposed System

The proposed solution is ‘Moviebox’, an android mobile application using REST Interface

[2], which provides movie lovers with the most updated movie information and this helps

them save time and money. They can read the movie information and then decide if they

want to watch movies at theatre or at home. This application helps users to find the most

popular movies, top rated movies and upcoming movies which will be running in theatres.

It also provides the list of movies based on different genres. Users will be able to read the

ratings, movie synopsis, and release information about the latest movie. MovieBox is

developed using different technologies Java, Android and SQLite and it is integrated

together with android libraries such as Picasso and Retrofit. Movie box application is based

on the data available in TMdb [The Movie DB API], but can also incorporate new data

sources. My application uses REST interface to pull fresh content each time it opens from

the database. In particular, my design has the following feature. I have organized the movie

title in such a way that it helps people to go over the list of grid and discover the most

popular movies. My idea is to keep it simple and provide a user friendly experience to the

users. Overall, Moviebox is an attempt to demonstrate the integration of several latest

technologies to create a useful real time app.

Page 16: MOVIE BOX AN ANDROID APPLICATION USING REST …

3

1.4 Features and Functionalities

With Movie Box, the user should be able to

View the list of movies and their posters

Should be able to search for movies

Should be able to navigate between different tabs and view movies based on

different categories like Popular, Top rated and Upcoming

On clicking the movie poster, user should be able to view movie details below

Overview

Release Date

Rating

Synopsis

.

Page 17: MOVIE BOX AN ANDROID APPLICATION USING REST …

4

2 BACKGROUND

This project brings together many API’s, languages and other technologies. This chapter

describes those technologies which are used and other terminologies used throughout the

remaining of the report.

2.1 Android

Android is an open source mobile operating system which was developed by Google [3,

4]. It is based on Linux system and is designed to be used for touch screen devices like

Tablets and smart phones [4]. It was launched in 2003 and is the world’s most popular

mobile OS. Movie Box is written in Java programming language and uses The Movie

Database [Tmdb] API and SQLite database, to run on Android OS.

2.2 JAVA

Java is a general-purpose programming languages (like C, C++ etc.) which was developed

by Sun Microsystems [5]. Java is object-oriented and has many libraries and tools which

makes a developers life easier. One of the powerful feature of java is that it protects from

many of the problems inherent in native code like memory leaks, bad pointers etc. It's fast

and efficient enough as existing compilers and virtual machines can run it almost as fast as

native code [5].

Page 18: MOVIE BOX AN ANDROID APPLICATION USING REST …

5

2.3 RESTful API

Moviebox is built on REST Application Programming Interface that enables the user to

use HTTP requests to PUT, GET, DELETE and POST data [2] [6]. It is used as an approach

to communicate and used in web services development [6]. Rest requires less bandwidth

compared to SOAP [Simple Object Access Protocol] and hence is more preferred. A

RESTful API takes advantage of HTTP methodologies and it uses GET to retrieve a

resource such as object, file or block; PUT to change the state of or update a resource;

POST to create that resource; and DELETE to remove it.

2.4 Terminology

This section gives a brief introduction to all the terminology used in this report.

2.4.1 Activity

Activity is an important component of android. An Android activity is one screen of the

Android applications user interface [7]. It is very similar to windows in a desktop

application. In other words, activity provides a platform where the users interact with the

User Interface [7]. An Android app may contain one or more screens.

2.4.2 Fragment

A Fragment represents a piece of user interface in the activity [8]. In other words, it is

placed in an activity as a part of an applications user interface [8]. Fragment has its own

Page 19: MOVIE BOX AN ANDROID APPLICATION USING REST …

6

Lifecycle which is dependent on the activity and hence it is closely tied to the activity.

Fragments are used to build a multipane user interface each with its own layout.

2.4.3 Service

Service is an application component which performs long running operations in the

background [9]. Once started, service still continues to run even after the user moves to

another application [9]. A bound service will operate as long as another application is

bound to the parent [9]. When these services unbind, all the services are destroyed.

2.4.4 Recycler View

Recycler View is a widget which acts like a container that displays a large number of data

[10]. It allows the user to scroll data efficiently with limited views [10]. The below Figure

1 shows the working of recycler view.

Figure 1 Recycler View [10]

Page 20: MOVIE BOX AN ANDROID APPLICATION USING REST …

7

2.4.5 Adapter

An Adapter acts like a bridge between the user interface components and the actual data

source [11]. For example, if we want to use List view in android, we can use adapter to

populate data in the list view.

2.5 IDE & Tools Technologies

Android SDK is an integral part of Android Application Development. Based on the

application on which the application is intended to run, the user needs to download the

corresponding SDK version. For this project the targeted development version was

Android 5.0 Lollipop (SDK 21).

2.5.1 Android studio 2.3.3

Android studio is an official IDE [Integrated App Development] used for developing

android applications [12]. It is based on IntelliJ IDEA platform. IntelliJ IDEA is as Java

integrated development environment [IDE] for developing software applications. Android

studio provides an interface to create Android apps. It is where we write project code,

design the app, edit, and run it in app and Test. Android also provides the SDK which is

the Software Development Kit. Java language is used for writing android programs and the

SDK is needed to make the programs run on android. Android studio combines all these

together at one place. Android studio allows us to run the code using an emulator or a piece

of hardware connected to our machine. When the code runs, the SDK provides feedback

Page 21: MOVIE BOX AN ANDROID APPLICATION USING REST …

8

and we can use it to debug and fix problems. It also provides hints while coding and will

suggest changes that can fix the errors and make the code more efficient.

2.5.2 Android Software Development Kit [SDK]

Android SDK contains multiple packages such as Android SDK Build Tools, Android SDK

Platform Tools and Android Emulator for app development and it groups all these tools

into one single package [13]. These SDK Tools are required to build android apps. An

emulator is a QEMU device based emulation tool that helps to debug and validate apps in

run-time environment. Users use SDK to save time and avoid writing redundant code.

2.5.3 Android Debug Bridge [ADB]

Android Debug Bridge is a tool which helps the user to communicate with any connected

android device. It helps with a variety of device actions like installation, debug and viewing

the output of the app [13].

2.5.4 Gradle

Gradle is a tool which helps android studio to convert all the different files into single APK

(Android Package Kit) file [14]. If we want to add any dependency such as a local binary

or remote binary, we can go into build.gradle (app) and add the dependency. There are two

gradle files. One for the module (app) and one for the whole project. Gradle is a build

system to automate scripts. It provides an automated way to make the app compatible with

the emulator in which it runs. Hence, we need to provide all the necessary files such as jar

Page 22: MOVIE BOX AN ANDROID APPLICATION USING REST …

9

files, SDK version and build tool version. Different libraries can be added to the project by

adding just a small piece of code using the Gradle.

2.5.5 Android Device Monitor

It helps the user manage the android device by providing a UI to debug the app using the

debug and analysis tools available [15]. It is a very powerful tool for controlling the device.

It helps us to view all the hidden files in the project by getting the permission. We can

select any project and explore the files using device monitor.

2.5.6 SDK Manager

User can view, install, update and uninstall android packages using a tool called SDK

Manager [16]. Latest android API’s and tools can be downloaded and installed using SDK

Manager. It separates the API, tools and platforms into different packages, and helps with

installation, update and uninstallation of packages for the Android SDK.

2.5.7 AVD Manager

An Android Virtual Device (AVD) is a configuration that defines the behavior of an

Android device which should be simulated in the Android Emulator [17]. It enables the

user to create any virtual devices with any desired API level and supports higher SDK’s. It

provides the graphical user interface where the user can create and manage the Android

virtual devices. AVD is required to test the behavior of the app but emulators are slow

compared to the real time app.

Page 23: MOVIE BOX AN ANDROID APPLICATION USING REST …

10

2.5.8 SQLite Database

Android also supports an inbuilt database SQLite, which is a software library that uses a

SQL database engine to develop small applications and perform create, update and delete

operations [18]. It is a relational database management system, not based on client-server

model. It is a popular as it is embedded in application software such as web browsers, OS

and other applications. Moviebox uses SQLite db to store the movie detail locally and to

sort the movies based on rating. One of the advantage of SQLite is that it limits the size of

the data.

2.5.9 Service Life Cycle

A service is an application component which can run in the background without the need

for the user interface to be turned on [19]. Services can be categorized as bound or unbound.

Unbounded service is a service which is "started" when an application component calls the

startService(). Any service can run in the background irrespective of component that started

it being destroyed [19]. Example of an unbounded service is an upload file operation. Once

the file is uploaded, the service is destroyed. A bound service allows components to interact

with each other, send request and get results. As long as other component is bounded, a

bound service runs. If the bound components unbounds, the service will be destroyed. The

below Figure 2 explains the Service Lifecycle.

Page 24: MOVIE BOX AN ANDROID APPLICATION USING REST …

11

Figure 2 The Service Lifecycle [19]

The relevant callback methods are:

startService(): When we want to start an unbound service, startService() is called

onCreate(): When the service is first created, onCreate is called

onStartCommand(): When the service is started, onStartCommand() is called.

onDestroy(): When service is no longer required and is to be destroyed,

onDestroy() is called.

onBind(): This method is called if the user wants to bind with an activity.

Page 25: MOVIE BOX AN ANDROID APPLICATION USING REST …

12

2.5.10 Picasso

Picasso is used for downloading image and caching [20]. Using images in an android app

is common, and Picasso helps in loading the images. It helps the developers by creating a

placeholder for downloaded images, resizing and cropping/scaling. An example call to

Picasso is:

Picasso.with(context).load("image url").into(imageView);

Advantages of using Picasso include resizing of images using minimum memory, Image

view recycling and automatic handling of memory and disk caching.

2.5.11 Retrofit

Retrofit is a library developed by Square Inc., which provides a HTTP client for Android

and Java [21]. It provides annotations which allow the developers to explain the HTTP

request. It also provides annotations to handle and support URL parameter replacement

and query parameter [21]. It allows the developers to manage object conversion body

request, Multipart body request and file upload.

Every method defined must have an HTTP request that provides the request and the

corresponding URL. An example of GET method is:

@GET("users/list")

Page 26: MOVIE BOX AN ANDROID APPLICATION USING REST …

13

3 SYSTEM DESIGN

3.1 Architectural Design

This project is based on the MVP [Model View Presenter] Design pattern [22]. The three

important components are

Model - It is the Data Layer which is responsible for handling the business logic and

communicates with the network and other database layers [22].

View – It is the User Interface Layer which displays the data to the user and notifies the

presenter about the user interactions [22].

Presenter – It gets the data from the Model, applies the logic for User Interface and decides

what to display to the user and reacts to the user inputs from the view [22].

Figure 3 Model View Presenter [22]

Page 27: MOVIE BOX AN ANDROID APPLICATION USING REST …

14

The above Figure 3 shows the Model View Presenter Model. A related design pattern is

MVC [Model View Controller], where the given view provides a visual of the given object,

and the controller is the middle man between the view and the model. In MVP [Model

View Presenter], the Presenter is the middle man between the view and the model that gets

the data from model and returns the data to the view in the required format [22]. The view

Layer is the interface to the user and must be simple and reliable. It also separates the

Layers to facilitate validation.

3.2 Detailed Design

3.2.1 Android Architecture

The application has client-server architecture with Android Mobile Application as client

[3] [8]. Android client is a user interface which interacts with server to get desired

information. Figure 4 shows the file structure of the Movie box android application. All

applications have an AndroidManifest.xml in its parent directory. The Manifest file

provides the necessary information required to run the code. The Android Manifest code is

given in Appendix B. The res folder contains the drawable sub folders. The drawable folder

contains all the images, and the layout folder contains the xml files that represent the UI of

the application.

Page 28: MOVIE BOX AN ANDROID APPLICATION USING REST …

15

Figure 4 File structure

3.2.2 TMdb API

Moviebox uses the information from The Movie db [23] and version 3 of TMdb API. We

can request an API key by logging in to the user account of TMdb. Once the key is issued,

we should be able to pull the movie information in the form of http request using the API

key. It is an open source API and any user can access it. The request is in the format of

URL:https://api.themoviedb.org/3/movie/76341?api_key={api_key}. We can also

authenticate other users who have TMdb account to extend the Tmdb experience within

our application. This lets other users rate movies, create a watch list while staying in sync

with their account on Tmdb. User authentication is controlled by a parameter session_id.

Guest session is another type of user authentication where a user has restricted permission

to just rate the movie or TV show. The below Figure 5 is the Tmdb API website.

Page 29: MOVIE BOX AN ANDROID APPLICATION USING REST …

16

Figure 5 TMdb API [23]

3.2.3 Application Design

The main aim of the system design is to define the components, data, modules and interface

required by the system in order to satisfy the requirements. Functional Requirements can

be depicted by UML Use case diagram. Use case diagram list the series of actions or steps

performed by the user. In other words, it is the interaction between the user and the system

in order to achieve the goal. The diagram in Figure 6 shows the use case diagram of Main

Activity. The diagram in Figure 7 shows the use case diagram for movie detail activity. A

Class diagram describes the structure of a system using the systems' classes, their attributes

and the methods or operations used. The diagram in Figure 8 shows the class diagram of

MovieBox App.

Page 30: MOVIE BOX AN ANDROID APPLICATION USING REST …

17

Actor

PopularMovies Tab

Toprated Movies Tab

Upcoming Movies Tab

Figure 6 Use case diagram for User

Page 31: MOVIE BOX AN ANDROID APPLICATION USING REST …

18

Movie Poster

Movie Title

Movie Overview

Movie Release Date

Movie Synopsis

Actor

Figure 7 Use Case Diagram for Movie Detail Activity

Page 32: MOVIE BOX AN ANDROID APPLICATION USING REST …

19

Movie

mTitlemPostermReleasedatemRatingmSynopsis

onCreate().parcellable

MoviesAdapter

mMovieslistmMovieInflatermContext

getItemCount()onCreate.view()

Picasso

mMoviePlaceholdermContext

getPoster()

Main Activity

mMoviesAdaptermRecycllerview

onCreate()getpopularmobies()get Topratedmovies()getUpcoming movies()

Retrofit

mMovieslist

callback()mMoviesApi()

Figure 8 Class Diagram

3.2.4 User Interface Design

User Interface Design for any mobile application should strive to be sufficiently easy such

that a new user can use the app. The app should be user friendly and easily accessible. A

good design approach is to have a three click rule where the user should be able to get all

the information in just three clicks. This application has two main screens:

Home screen

Page 33: MOVIE BOX AN ANDROID APPLICATION USING REST …

20

Movie Detail screen

Home screen is where the movie posters are displayed across three different tabs, and the

user should be able to view the movies based on Popular category, Top-rated Category and

Upcoming Category. Movie Detail screen is where the users can select the movie posters

and use the app to view the movie information.

Following Figure 9 is the main (home screen). As seen from the image, this screen has all

the key features.

Figure 9 Home Screen

Page 34: MOVIE BOX AN ANDROID APPLICATION USING REST …

21

3.2.5 Database Design

In this project, I have used SQLite database which is an open source database to sort the

movies based on different order. Moviebox connects to the TMdb database using the REST

API [24]. It uses HTTP request to GET the data from the database using the Web services

[24]. The movie information is fetched using the JSON formats. In this project, when we

click on a movie poster the information is sent via web services in JSON format and

displayed to users from the Tmdb. The Figure 10 below illustrates this process.

Figure 10 Application Work Flow [24]

Page 35: MOVIE BOX AN ANDROID APPLICATION USING REST …

22

4 OVERVIEW OF IMPLEMENTATION

4.1 Set up Android Environment

These are the prerequisite software which we need to install in order to develop the android

Application [12]

1. Java JDK: We can download the latest of version of JDK from the oracle java JDK

Download page and install it. We then need to configure the PATH and JAVA_HOME

environment variables corresponding to directory containing Java.

2. Android SDK: We can download the Latest version of android sdk from official android

website.

3. Android studio 2.3: Android studio is an IDE designed specifically for creating android

apps.

4.2 Creating Simple Android Application

To create a simple android application one needs to navigate to File->New->New Project-

>Android Application Project. The application name is provided here. The application is

referenced by the app name and is identified by that name within the Android studio. The

interface for a new android application on android studio is shown in Figure 11.

After selecting the name of the app, we click the Next button and navigate to the next

screen where we configure the project settings. Select the ‘Minimum SDK’ which is the

Page 36: MOVIE BOX AN ANDROID APPLICATION USING REST …

23

lowest version of Android this app supports and ‘Target SDK’ which is the highest version

of Android on which this app is tested and click the Next button.

Figure 11 New project view

Page 37: MOVIE BOX AN ANDROID APPLICATION USING REST …

24

Figure 12 Android devices selection

The Figure 12 shows the Android devices selection tab which show the various form

factors that the app can run on. After selecting the SDK versions, we navigate to the Add

an Activity to Mobile dialog box where we select the default blank activity and select Next

button. On the final screen, we see the Activity Name populated with the default name

‘MainActivity’ and click Finish. The Figure 13 shows these Activities and Customization

windows.

Page 38: MOVIE BOX AN ANDROID APPLICATION USING REST …

25

Figure 13 Activities and Customization windows

The package name is used to identify the application uniquely and it is created by reversing

the domain URL name followed by application name. The Hello World program is stored

by default in the app and we just need to run it.

Page 39: MOVIE BOX AN ANDROID APPLICATION USING REST …

26

The src directory contains all the application source files. The res directory (resource

directory) contains sub folders like layout, drawable-hdpi, menu, values etc. Each file is

identified with a precompiled ID in the res directory is accessed using R.id.[res id]. This

makes it easy to access image and icon files.

All the information regarding permissions to access external features such as accessing

internet are present in the manifest file [3]. Permissions are by default created for all basic

android application as the project is built. The app is run by clicking on the Run Tab->Run

‘app’. On running this, the main activity class starts and loads a layout file that says "Hello

World” by default.

4.3 Running the Android Application

There are two ways to run the android app

We can use any android device to install the app directly and run the application.

First we need to Plugin the android device with a usb connection. Second, we need

to navigate to the phone settings->Developer Options and enable USB Debugging.

Lastly, when we click on the Run ‘app’, we will be able to view the Select

Deployment Target dialog box where we need to select the Connected USB device

listed and click OK. This allows Android studio to install the app directly on the

connected device & start the app.

Page 40: MOVIE BOX AN ANDROID APPLICATION USING REST …

27

We can use Android Emulator to run the application, and in order to do so we need

to configure the Android Virtual Device. The AVD is device configuration which

allows the user to customize virtual device based on different device specifications

such as screen resolution, RAM, phone memory, CPU, camera etc. Figure 14 shows

the AVD Manager.

Figure 14 AVD Manager

This allows the android studio to install and run the application thorough emulator by

clicking on Run app from the Run Tab and selecting the android virtual device shown in

the table. We will be able to see a list of various AVD’s which can be used to test the

android application on different device configurations like phone or tablet and different

Page 41: MOVIE BOX AN ANDROID APPLICATION USING REST …

28

android versions. Emulators help to test the android app without the need to use a physical

device.

4.4 MainActivity

When the user navigates to the app screen, he should be able to view the MovieBox icon.

The Moviebox icon is shown below in Figure 15.

Figure 15 Movie Box App Icon

Page 42: MOVIE BOX AN ANDROID APPLICATION USING REST …

29

On clicking the MovieBox icon, he should be able to launch the application. The layout of

Home screen is defined in activity_main.xml. The Main Activity class loads all the user

interface fields and text using the activity_main XML file which is present in res/layout

folder of the project. The Main Activity class contains the code to display the home screen,

which displays a scrollable list of all the movie poster using the concept of Recycler View

[25]. The activity_main.xml code is given in Appendix A. The layout res files shows the

architecture of user interface in an activity.

The following statement from the MainActivity.java code loads the UI component.

setContentView(R.layout.activity_main);

In my code, I have created the Main Activity and converted it to AppcompatActivity in

order to support the TabLayout or the Navigation Drawer [26]. The user should be able to

view Three tabs Popular, Toprated, Upcoming with Popular tab selected as default. The

user should be able to view a gridview of movies posters which are scrollable.

Moviebox Code Modules:

I have used TabLayout, which is view Type introduced in android [27]. It provides a

horizontal layout of tabs at the top of the screen. The tabs are created through newTab()

and the population of tabs are done by TabLayout.Tab. When any tab selection state is

changed, it is notified through the OnTabSelected Listener Interface.

Page 43: MOVIE BOX AN ANDROID APPLICATION USING REST …

30

TabLayout is implemented with ViewPager. ViewPager is used to swipe through pages of

data. The below java snippet depicts how a TabLayout and ViewPager are defined in the

MainActivity.

/**

*Below is the code for TabLayout

*@see

https://developer.android.com/reference/android/support/design/widget/TabLayout.h

tml

*/

TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);

tabLayout.addTab(tabLayout.newTab().setText("Popular"));

tabLayout.addTab(tabLayout.newTab().setText("Toprated"));

tabLayout.addTab(tabLayout.newTab().setText("Upcoming"));

tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

The below XMLsnippet depicts how a TabLayout architecture design is implemented with

ViewPager in the content_main.xml.

<android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/toolbar" android:background="?attr/colorAccent" android:elevation="6dp" android:minHeight="?attr/actionBarSize" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_below="@id/tab_layout"/>

In order to setup ViewPager in Main Activity, I had to set up ViewPager Adapter.

Page 44: MOVIE BOX AN ANDROID APPLICATION USING REST …

31

/**

*@see

https://developer.android.com/reference/android/support/design/widget/TabL

ayout.html

*/

final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);

final PagerAdapter adapter = new PagerAdapter

(getSupportFragmentManager(), tabLayout.getTabCount());

viewPager.setAdapter(adapter);

viewPager.addOnPageChangeListener(new

TabLayout.TabLayoutOnPageChangeListener(tabLayout));

tabLayout.setOnTabSelectedListener(new

TabLayout.OnTabSelectedListener() {

//This is a callback interface which is invoked when tab selection

changes.

@Override

public void onTabSelected(TabLayout.Tab tab) {

viewPager.setCurrentItem(tab.getPosition());

if(tab.getPosition()==0) // position for Tab1

Popular Movies

{

getPopularMovies();

}

else if(tab.getPosition()==1) // position for Tab 2

Toprated Movies

{

getTopRatedMovies();

}

else if(tab.getPosition()==2) // position for Tab 3

Upcoming Movies

{

getUpcomingMovies();}

}

Page 45: MOVIE BOX AN ANDROID APPLICATION USING REST …

32

Callback interface ViewPager.OnPageChangeListener is used for responding to changing

state of the selected page. This class contains the necessary calls back to the Tablayout to

ensure that the Tab positons are in sync.

The next important feature implemented in the MainActivity is Recycler view [25]. The

home screen displays scrollable movie posters. This feature can be implemented by using

the object android.support.v7.widget.RecylerView.Recycler. This is responsible for

managing item views for reuse. Here I have created a grid view of movie poster images by

creating a row for these items, and used that layout which I created in the adapter. The

Recycler view only creates required number of views to display the data needed at a time.

For example, for a 2x2 grid which scrolls vertically, the Recyclerview creates 8 views. It

displays 4 views at a time two above and two below are ready to be shown when scrolled.

As the user scrolls, already created views are displayed by the Recyclerview which binds

new data to them.

To make this job easier, Android developer site provides a smooth scrolling option with

the view Holder. The Recycler view creates eight views to display the number of rows and

columns and by doing so avoids creating new views whenever user scrolls..

By using this feature, I have created a class which references all the views which are needed

to populate the layout. This reference is reused frequently by calling method

findViewById(). This advantage greatly improves the performance of the app. The recycler

Page 46: MOVIE BOX AN ANDROID APPLICATION USING REST …

33

view uses the Adapter as the data source and I have used View Holders to keep reference

in memory.

When I need a new view, we can either create a new ViewHolder or use a recyclerview

which recycles the view with the one which already exist in stack. Following are the steps

I followed in MovieBox development. First I declared the Recycler view in the

content_main layout and reference it in our MainActivity.java.

<android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent"/>

The code below defines the Recycler view in the MainActivity.java

mMovieRecyclerView = (RecyclerView)

findViewById(com.suganya.MovieBox.R.id.recyclerView);

mMovieRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));

Then, I created a MovieAdapter class extended with RecyclerView.Adapter

<ViewHolder>. Next I extended the class RecyclerView.ViewHolder, and created a

ViewHolder for the adapter:

Page 47: MOVIE BOX AN ANDROID APPLICATION USING REST …

34

/*

*MovieboxAdapter class is called which extends to RecyclerView.

**/

public static class MovieboxAdapter extends

RecyclerView.Adapter<MoviePlaceHolder> {

private List<MovieInfo> mMoviesList;

private LayoutInflater mMovieInflater;

private Context mContext;

public MovieboxAdapter(Context context) {

this.mContext = context;

this.mMovieInflater = LayoutInflater.from(context);

}

Then, I initialized the View.OnClickListener and implemented the method required

for View.OnClickListener since ViewHolders can handle their own event

onCreateViewHolder() create viewHolder for the Adapter.

@Override

public MoviePlaceHolder onCreateViewHolder(ViewGroup parent, final int

viewType) {

View view =

mMovieInflater.inflate(com.suganya.MovieBox.R.layout.row_movie, parent, false);

final MoviePlaceHolder viewHolder = new MoviePlaceHolder(view);

view.setOnClickListener(new View.OnClickListener() {

The code below displays the current item view and shows a new activity by creating intent.

Next I added the method to the image holder.

Page 48: MOVIE BOX AN ANDROID APPLICATION USING REST …

35

@Override

public void onClick(View view) {

int position = viewHolder.getAdapterPosition();

Intent intent = new Intent(mContext, MovieInfoActivity.class);

intent.putExtra(MovieInfoActivity.EXTRA_MOVIE,

mMoviesList.get(position));

mContext.startActivity(intent);

}

});

return viewHolder;

}

onBindViewHolder() method binds the image to the ViewHolder. I have used Picasso

library to import the images from the URL:

Page 49: MOVIE BOX AN ANDROID APPLICATION USING REST …

36

@Override

public void onBindViewHolder(MoviePlaceHolder holder, int

position) {

MovieInfo movie = mMoviesList.get(position);

Picasso.with(mContext)

.load(movie.getPoster())

.placeholder(com.suganya.MovieBox.R.color.colorAccent)

.into(holder.imageView);

}

@Override

public int getItemCount() {

return (mMoviesList == null) ? 0 : mMoviesList.size();

}

public void displayMovieList(List<MovieInfo> movieList) {

this.mMoviesList = new ArrayList<>();

this.mMoviesList.addAll(movieList);

notifyDataSetChanged();

}

}

}

Lastly, I hook the Recyclerview to the Adapter to make sure it retrieves the images when

it is created .

4.4.1 Using Picasso to load image into Image View

Picasso is an image library which is used for image loading and image processing [20].

The library handles every step from loading initial http request to caching of images. The

below import statement should be added to the Main Activity class in order to use Picasso.

import com.squareup.picasso.Picasso;

For using Picasso, permissions should be added to the manifest file:

Page 50: MOVIE BOX AN ANDROID APPLICATION USING REST …

37

<uses-permission android:name="android.permission.INTERNET" />

Then I added imageView to the layout file

<?xml version="1.0" encoding="utf-8"?> <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/imageView" android:adjustViewBounds="true" android:layout_width="wrap_content" android:layout_height="wrap_content"/>

Then I added the below code to the MainActivity.java file.

Picasso.with(mContext)

.load(movie.getPoster())

.placeholder(com.suganya.MovieBox.R.color.colorAccent)

.into(holder.imageView);

First I got a reference and then loaded the image into the image view using Picasso. Then,

getPoster() method and the location of the image is loaded. Finally, Picasso is called to

display the movie poster image and the image is passed to the View object. The complete

code is given in Appendix A.

4.4.2 Using Retrofit to Retrieve the Movie Poster

The user should be able to see three tabs [Popular Movies/ TopratedMovies/ Upcoming]

on opening the app which is the Home screen. Popular Movies Tab will be displayed by

default. He should be able to view the Grid view of Movie poster images displayed based

Page 51: MOVIE BOX AN ANDROID APPLICATION USING REST …

38

on the Tab selected. The Figure 16 shows the Popular Movies tab which is the default

Home Page the user is greeted with.

Figure 16 Popular Movies Tab

I have used the Retrofit library, which is REST client for Android which is developed by

Square [21]. It provides an easy way to retrieve the data and upload JSON file using a

REST based service. I have implemented retrofit and used it to display movie pages from

the TMdb API by following the steps below.

Page 52: MOVIE BOX AN ANDROID APPLICATION USING REST …

39

1. Downloaded Retrofit and installed or imported Retrofit by adding the below code

to the build.gradle app file

Compile ‘com.squareup.retrofit:retrofit:1.9.0’

2. Imported the library in the MainActivity.java

import retrofit.Callback;

import retrofit.RequestInterceptor;

import retrofit.RestAdapter;

import retrofit.RetrofitError;

import retrofit.client.Response;

3. Then created an interface which will represent the API. Here, I had set up an

interface to the API, which expose calls on an API endpoint like

https://api.themoviedb.org/3/movie/popular?api_key=4e759e0ec75edf2f80e6d752

6aee7735&language=en-US&page=1

Page 53: MOVIE BOX AN ANDROID APPLICATION USING REST …

40

package com.suganya.MovieBox;

import retrofit.Callback;

import retrofit.http.GET;

/**

*This class mMoviesApi creates an interface which will represent

*the API.Retrofits gets annotation with URL and the

*getPopularmovies, getTopratedMovies, getUpcomingmovies methods

*will return the list of *Movie Result

*@author Suganya Srinivasan

*@version Nov 9 2017

*/

public interface mMoviesApi {

@GET("/movie/popular")

void getPopularMovies(Callback<Movie.MovieInfo> cb);

@GET("/movie/top_rated")

void getTopRatedMovies(Callback<Movie.MovieInfo> cb);

@GET("/movie/upcoming")

void getUpcomingMovies(Callback<Movie.MovieInfo> cb);

}

The methods then need to be annotated for retrofit to know the kind of request and the end

point it should connect to. The results come back from API as an object and a Movie class

is created.

Page 54: MOVIE BOX AN ANDROID APPLICATION USING REST …

41

public class Movie implements Parcelable{

private String title;

@SerializedName("poster_path")

private String poster;

@SerializedName("overview")

private String description;

@SerializedName("backdrop_path")

private String backdrop;

@SerializedName("release_date")

private String Releasedate;

@SerializedName("vote_average")

private String VoteAverage;

public Movie() {}

protected Movie(Parcel in) {

title = in.readString();

poster = in.readString();

description = in.readString();

backdrop = in.readString();

Releasedate = in.readString();

VoteAverage = in.readString();

}

Then the code below is added to Movie class

public static class MovieResult {

private List<Movie> results;

public List<Movie> getResults() {

return results;

}

}

After setup is done, the API needs to be called, before which we need to initialize retrofit.

First a rest adapter is created with all the configuration detail it needs in order to use the

Page 55: MOVIE BOX AN ANDROID APPLICATION USING REST …

42

interface. The rest adapter sets the endpoint as the first part of the url for the API. A request

interceptor gets called for every request made instead of adding API key each time. The

log level informs the retrofit about the request and responses that it should display.

Now REST adapter is complete and we use the getPopularMovies() method using callback.

Callback is a method used to pull data from web services and is executed by a different

object. Success method will be called on success of the callback. I will have access to the

movie list from the server using that method. I can then use that movie list and pass it to

the adapter.

Page 56: MOVIE BOX AN ANDROID APPLICATION USING REST …

43

/**

*This method is called when Tab0 is selected and it displays the list of

*popular movies

*This method uses RequestInterceptor with RequestFacde in Retrofit 1.9.0

*version

*@see

*https://square.github.io/retrofit/1.x/retrofit/retrofit/RequestIntercept

*or.html

*/

private void getPopularMovies() {

RestAdapter MyAdapter = new RestAdapter.Builder()

.setEndpoint("http://api.themoviedb.org/3")

.setRequestInterceptor(new RequestInterceptor() {

@Override

public void intercept(RequestFacade Mrequest) {

Mrequest.addEncodedQueryParam("api_key",

"4e759e0ec75edf2f80e6d7526aee7735");

}

})

.setLogLevel(RestAdapter.LogLevel.FULL)

.build();

mMoviesApi service = MyAdapter.create(mMoviesApi.class);

service.getPopularMovies(new Callback<MovieInfo.mMovieResult>() {

/**

*The below code used the success and failure methods in Retrofit 1.9.0.

*@see

*http://static.javadoc.io/com.squareup.retrofit/retrofit/1.9.0/retrofit/R

*esponseCallback.html

*/

@Override

public void success(MovieInfo.mMovieResult movieResult,

Response response) {

mMovieAdapter.displayMovieList(movieResult.getResults());

}

@Override

public void failure(RetrofitError error) {

error.printStackTrace();

}

});

}

Page 57: MOVIE BOX AN ANDROID APPLICATION USING REST …

44

Below is a sample JSON array which contains the movie list objects of a single item

{

"poster_path": "/IfB9hy4JH1eH6HEfIgIGORXi5h.jpg",

"adult": false,

"overview": "Jack Reacher must uncover the truth behind a major government

conspiracy in order to clear his name.",

"release_date": "2016-10-19",

"genre_ids": [

53,

28,

80,

18,

9648

],

"id": 343611,

"original_title": "Jack Reacher: Never Go Back",

"original_language": "en",

"title": "Jack Reacher: Never Go Back",

"backdrop_path": "/4ynQYtSEuU5hyipcGkfD6ncwtwz.jpg",

"popularity": 26.818468,

"vote_count": 201,

"video": false,

"vote_average": 4.19

}

The below getTopratedMovies() method make calls to the API to retrieve the list of

toprated Movies from the API.

Page 58: MOVIE BOX AN ANDROID APPLICATION USING REST …

45

/**

*This method is called when Tab1 is selected and it displays the list of

*Toprated movies

*This method uses RequestInterceptor with RequestFacade request in Retrofit

*1.9.0 version

*@see

*https://square.github.io/retrofit/1.x/retrofit/retrofit/RequestInterceptor.

*html

*/

private void getTopRatedMovies() {

RestAdapter MyAdapter = new RestAdapter.Builder()

.setEndpoint("http://api.themoviedb.org/3")

.setRequestInterceptor(new RequestInterceptor() {

@Override

public void intercept(RequestFacade Mrequest) {

Mrequest.addEncodedQueryParam("api_key",

"4e759e0ec75edf2f80e6d7526aee7735");

}

})

.setLogLevel(RestAdapter.LogLevel.FULL)

.build();

mMoviesApi service = MyAdapter.create(mMoviesApi.class);

service.getTopRatedMovies(new Callback<MovieInfo.mMovieResult>() {

/**

*The below code used the success and failure methods in Retrofit 1.9.0.

*@see

*http://static.javadoc.io/com.squareup.retrofit/retrofit/1.9.0/retrofit/Resp

*onseCallback.html

*/

@Override

public void success(MovieInfo.mMovieResult movieResult, Response

response) {

mMovieAdapter.displayMovieList(movieResult.getResults());

}

@Override

public void failure(RetrofitError error) {

error.printStackTrace();

}

});

}

Page 59: MOVIE BOX AN ANDROID APPLICATION USING REST …

46

When the user clicks on the Toprated Tab, he should be able to see the grid view of all the

toprated Movies. The Toprated Movies tab is shown in Figure 17.

Figure 17 Toprated Movies Tab

The below getUpcomingMovies() method make calls to the API to retrieve the list of

Upcoming Movies from the API.

Page 60: MOVIE BOX AN ANDROID APPLICATION USING REST …

47

/**

*This method is called when Tab2 is selected and it displays the list of

*upcoming movies

*This method uses RequestInterceptor with RequestFacade request in

*Retrofit 1.9.0 version

*@see

*https://square.github.io/retrofit/1.x/retrofit/retrofit/RequestIntercepto

*r.html

*/

private void getUpcomingMovies() {

/**

*get Retrofit instance with the URL

*/

RestAdapter MyAdapter = new RestAdapter.Builder()

.setEndpoint("http://api.themoviedb.org/3")

.setRequestInterceptor(new RequestInterceptor() {

@Override

public void intercept(RequestFacade Mrequest) {

Mrequest.addEncodedQueryParam("api_key",

"4e759e0ec75edf2f80e6d7526aee7735");

}

})

.setLogLevel(RestAdapter.LogLevel.FULL)

.build();

mMoviesApi service = MyAdapter.create(mMoviesApi.class);

service.getUpcomingMovies(new Callback<MovieInfo.mMovieResult>() {

/**

*The below code used the success and failure methods in Retrofit 1.9.0.

*@see

*http://static.javadoc.io/com.squareup.retrofit/retrofit/1.9.0/retrofit/Re

*sponseCallback.html

*/

@Override

public void success(MovieInfo.mMovieResult movieResult,

Response response) {

mMovieAdapter.displayMovieList(movieResult.getResults());

}

@Override

public void failure(RetrofitError error) {

error.printStackTrace();

}

});

}

Page 61: MOVIE BOX AN ANDROID APPLICATION USING REST …

48

Figure 18 Upcoming Movies Tab

When the user clicks on the Upcoming Tab, he should be able to see the grid view of all

the Upcoming Movies. The Upcoming Movies Tab is shown in above Figure 18.

4.5 MovieDetailInfo Activity

When the user clicks on the Movie image poster in Home screen, he should be navigated

to the next screen where he should be able to view the movie detail below

Page 62: MOVIE BOX AN ANDROID APPLICATION USING REST …

49

Movie Poster with Title

Overview

Release date

Rating

Synopsis

The MovieInfo Activity class loads all the user interface components using the

content_movie_detail XML file which is present in res folder of the project.

The complete code is given in Appendix B.

4.5.1 Movie Poster

When the user clicks on the Beauty and the Beast movie poster, he should be able to view

the movie poster at the top of the screen. The Movie poster with movie name is shown in

Figure 19.

Figure 19 Movie Poster with Title

Page 63: MOVIE BOX AN ANDROID APPLICATION USING REST …

50

The following methods retrieve the data from the API using the MovieAPI Interface

/**

*@ return the Poster

*/

public String getPoster() {

return "http://image.tmdb.org/t/p/w500" + poster;

}

/**

*@Paramer set Poster

*/

public void setPoster(String poster) {

this.poster = poster;

}

4.5.2 Movie Title

The get method (accessor method) returns the value of the member with which they are

associated and the set method (mutator method) sets a new value to the member.

/**

*@ return the Title

*/

public String getTitle() {

return title;

}

/**

*@Paramer set Title

*/

public void setTitle(String title) {

this.title = title;

}

Page 64: MOVIE BOX AN ANDROID APPLICATION USING REST …

51

User should be able to view the Movie Title with the Overview. The Movie Title with

overview is shown in Figure 20.

Figure 20 Movie Title with Overview

4.5.3 Movie Releasedate

The below methods retrieve the data from the API using the MovieAPI Interface

/**

*@ return the ReleaseDate

*/

public String getReleasedate() {return Releasedate; }

/**

*@Paramer set Releasedate

*/

public void setReleasedate(String Releasedate) {this.Releasedate =

Releasedate; }

User should be able to view the Movie Releasedate. The movie Release date is shown in

below Figure 21.

Page 65: MOVIE BOX AN ANDROID APPLICATION USING REST …

52

Figure 21 Movie Release Date

4.5.4 Movie Rating

The below methods retrieve the data from the API using the MovieAPI Interface

/**

*@ return the VoteAverage

*/

public String getVoteAverage() {return VoteAverage; }

/**

*@Paramer set VoteAverage

*/

public void setVoteAverage(String VoteAverage) {this.VoteAverage =

VoteAverage; }

User should be able to view the Movie Rating. The Movie Rating is shown in below

Figure 22.

Figure 22 Movie Rating

Page 66: MOVIE BOX AN ANDROID APPLICATION USING REST …

53

4.5.5 Movie Synopsis

User should be able to view the synopsis or the plot of the selected movie. The movie

Synopsis is shown in below Figure 23.

Figure 23 Scrollable View of Movie Synopsis

4.5.6 Search Feature

When the user clicks on the search icon in the Home Screen, the user should be able to

view the Search View where he can type the Movie names he is looking for. It should

display a list of movie names starting with the mentioned alphabet. The below code depicts

the implementation of Search view [28] It is a widget which provides a UI for the users to

Page 67: MOVIE BOX AN ANDROID APPLICATION USING REST …

54

type the query and search for the result in the search view. User picks the option from the

list of results shown.

@Override

public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(com.suganya.MovieBox.R.menu.menu_main, menu);

SearchManager searchManager =

(SearchManager) getSystemService(Context.SEARCH_SERVICE);

SearchView searchView =

(SearchView) menu.findItem(R.id.action_search).getActionView();

searchView.setSearchableInfo(

searchManager.getSearchableInfo(getComponentName()));

return true;

}

The Search View feature is shown in Figure 24.

4.5.7 Other Features

I have added other features to the design where user can check for updates, look into the

help option to know more about the app, Settings and Refresh option. The other features

are shown in Figure 25 below.

Page 68: MOVIE BOX AN ANDROID APPLICATION USING REST …

55

Figure 24 Search View

Page 69: MOVIE BOX AN ANDROID APPLICATION USING REST …

56

Figure 25 Other Features

Page 70: MOVIE BOX AN ANDROID APPLICATION USING REST …

57

5 FUTURE WORK

There are several features that could be challenging to expand the scope and improve the

app. Some desirable features that can be added in future are:

Include movie trailers for each movie. This will give users a good feel to watch

and later decide if they want to watch it in theatres

Include movie reviews from different sites like Imdb

Include ability for Users to bookmark their favorite movies and implement the

search feature

Another feature would be to include the links of streaming sites where this movie

will be available to watch for free

Moreover, implementing this application in iOS platform as an iPhone App as

there are many iPhone users.

Improve the performance of the app. It takes few seconds to pull the images from

the Tmdb API. This should be reduced to <3 seconds. This will be a challenging

feature to add.

Page 71: MOVIE BOX AN ANDROID APPLICATION USING REST …

58

6 CONCLUSION

Moviebox is an android mobile application developed using REST Interface [2], which

provides movie lovers with the most updated movie information and this helps them save

time and money. Moviebox provides the below features to users:

View the List of movies and their posters

Should be able to search for movies

Should be able to navigate between different tabs and view movies based on

different categories like Popular, Top rated and Upcoming

Users should also be able to read the ratings, movie synopsis, and release information about

the latest movie. MovieBox is developed using different technologies Java, Android and

SQLite and it is integrated together with android libraries such as Picasso and Retrofit. This

app is extremely useful for all people as they can view all the movie information at any

place and time in their mobile. This in turn will help people save time and money as users

can decide what movie they want to watch in theatres. The User Interface of this app is

also so simple that any user can use this app with ease. It does not require any user account

creation or payment and hence any user can use it for free.

Page 72: MOVIE BOX AN ANDROID APPLICATION USING REST …

59

APPENDIX A

MainActivity.java

Page 73: MOVIE BOX AN ANDROID APPLICATION USING REST …

60

Page 74: MOVIE BOX AN ANDROID APPLICATION USING REST …

61

Page 75: MOVIE BOX AN ANDROID APPLICATION USING REST …

62

Page 76: MOVIE BOX AN ANDROID APPLICATION USING REST …

63

Page 77: MOVIE BOX AN ANDROID APPLICATION USING REST …

64

Page 78: MOVIE BOX AN ANDROID APPLICATION USING REST …

65

Page 79: MOVIE BOX AN ANDROID APPLICATION USING REST …

66

Page 80: MOVIE BOX AN ANDROID APPLICATION USING REST …

67

Page 81: MOVIE BOX AN ANDROID APPLICATION USING REST …

68

Page 82: MOVIE BOX AN ANDROID APPLICATION USING REST …

69

Movie.java

Page 83: MOVIE BOX AN ANDROID APPLICATION USING REST …

70

Page 84: MOVIE BOX AN ANDROID APPLICATION USING REST …

71

Page 85: MOVIE BOX AN ANDROID APPLICATION USING REST …

72

Page 86: MOVIE BOX AN ANDROID APPLICATION USING REST …

73

mMoviespi.java

Page 87: MOVIE BOX AN ANDROID APPLICATION USING REST …

74

APPENDIX B

MovieInfoActivity.java

Page 88: MOVIE BOX AN ANDROID APPLICATION USING REST …

75

Page 89: MOVIE BOX AN ANDROID APPLICATION USING REST …

76

BIBILIOGRAPHY

[1] "PR Newswire Article," [Online]. Available: https://www.prnewswire.com/news-

releases/survey-reveals-two-thirds-of-americans-prefer-watching-movies-at-home-

over-the-theater-and-women-are-more-likely-than-men-to-read-the-book-before-

seeing-the-movie-version-278348301.html. [Accessed 05 October 2017].

[2] "RESTful Web Services Tutorial," Tutorials point, [Online]. Available:

https://www.tutorialspoint.com/restful/. [Accessed 15 September 2017].

[3] "Android," Google, [Online]. Available: https://www.android.com/. [Accessed 15

August 2017].

[4] "Android (operating system)," Wikipedia, [Online]. Available:

https://en.wikipedia.org/wiki/Android_(operating_system). [Accessed 15 August

2017].

[5] "Java," Oracle Corporation[US], [Online]. Available: https://www.java.com/en/.

[Accessed 07 September 2017].

[6] "Building a RESTful Web Service," Spring by Pivotal, [Online]. Available:

https://spring.io/guides/gs/rest-service/. [Accessed 10 September 2017].

[7] "Activity," Android Developers, [Online]. Available:

https://developer.android.com/reference/android/app/Activity.html. [Accessed 02

September 2017].

[8] "Fragments," Android Developers, [Online]. Available:

https://developer.android.com/guide/components/fragments.html. [Accessed 02

September 2017].

[9] "Services," Android Developers, [Online]. Available:

https://developer.android.com/guide/components/services.html. [Accessed 02

September 2017].

Page 90: MOVIE BOX AN ANDROID APPLICATION USING REST …

77

[10] "Creating Lists and Cards," [Online]. Available:

https://developer.android.com/training/material/lists-cards.html. [Accessed 02

September 2017].

[11] "Adapter," Android Developers, [Online]. Available:

https://developer.android.com/reference/android/widget/Adapter.html. [Accessed

03 September 2017].

[12] "Android Studio," Android Developer, [Online]. Available:

https://developer.android.com/studio/releases/index.html#3-0-0. [Accessed 05

September 2017].

[13] "SDK Tools," Android Developer, [Online]. Available:

https://developer.android.com/studio/releases/sdk-tools.html. [Accessed 15 August

2017].

[14] "Android Plugin for Gradle Release Notes," Android Developer, [Online].

Available: https://developer.android.com/studio/releases/gradle-plugin.html.

[Accessed 01 October 2017].

[15] "Android Device Monitor," Android Developer, [Online]. Available:

https://developer.android.com/studio/profile/monitor.html. [Accessed 20

September 2017].

[16] "sdk Manager," Android Developer, [Online]. Available:

https://developer.android.com/studio/command-line/sdkmanager.html. [Accessed

20 September 2017].

[17] "Create and Manage Virtual Devices," Android Developer, [Online]. Available:

https://developer.android.com/studio/run/managing-avds.html. [Accessed 20

September 2017].

[18] "SQLite," [Online]. Available: https://www.sqlite.org/. [Accessed 15 September

2017].

[19] "Android Service Tutorial," Java Point, [Online]. Available:

https://www.javatpoint.com/android-service-tutorial. [Accessed 22 September

2017].

Page 91: MOVIE BOX AN ANDROID APPLICATION USING REST …

78

[20] "Square Inc. Picasso," [Online]. Available: http://square.github.io/picasso/.

[Accessed 15 September 2017].

[21] "Square Inc. Retrofit," [Online]. Available: http://square.github.io/retrofit/.

[Accessed 15 September 2017].

[22] "Wikipedia. Model-View-Presenter," [Online]. Available:

https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter.

[Accessed 15 September 2017].

[23] "TMdb," [Online]. Available: https://www.themoviedb.org/?language=en.

[Accessed 15 September 2017].

[24] "Code Tutlus. Android SDK:Making Remote API Calls. Copyright 2017,"

[Online]. Available: https://code.tutsplus.com/tutorials/android-sdk-making-

remote-api-calls--mobile-17568. [Accessed 15 September 2017].

[25] "Razeware Inc. Android RecyclerView Tutorial with Kotlin," [Online]. Available:

https://www.raywenderlich.com/170075/android-recyclerview-tutorial-kotlin.

[Accessed 15 September 2017].

[26] "Code Path. AppCompatActivity. Codepath 2017," [Online]. Available:

https://guides.codepath.com/android/Migrating-to-the-AppCompat-Library.

[Accessed 15 September 2017].

[27] "Android Developer. Android TabLayout with ViewPager," [Online]. Available:

https://developer.android.com/reference/android/support/design/widget/TabLayout.

html. [Accessed 15 September 2017].

[28] "Android Developer. SearchView," [Online]. Available:

https://developer.android.com/reference/android/widget/SearchView.html.

[Accessed 15 September 2017].