You are on page 1of 30

Project Report on

NEWS APP

by

AAYUSH DOGRA (1749210001), AMAN SINGHAL (1749210015),

AMAN YADAV (1749210019)

Submitted to the Department of COMPUTER SCIENCE

in partial fulfillment of the

requirements for the degree of

Bachelor of Technology

in

Computer Science Engineering

Under the guidance of

Mr. Kishan Kumar

KCC Institute of Technology &

Management A.K.T.U

July, 2021

AMAN YADAV 1
TABLE OF CONTENTS Page

DECLARATION ................................................................................................... 3
ACKNOWLEDGEMENTS .................................................................................. 4
ABSTRACT ........................................................................................................... 5

CHAPTER 1 INTRODUCTION

CHAPTER 2 DETAILED SPECIFICATION

CHAPTER 3 BLOCK DIAGRAM

CHAPTER 4 METHODOLOGY

CHAPTER 5 CODING

CHAPTER 6 APPLICATION AND LIMITATION

CHAPTER 7 CONCLUSION

REFERENCES

AMAN YADAV 2
DECLARATION
We hereby declare that the project work entitled “News App” submitted to the Computer
Science & Engineering Department, in KCC Institute of Technology & Management
Greater Noida, is a record of an original work done by me and this project work is submitted
in the partial fulfillment of the requirement for the award of degree of B.Tech. in Department
of Computer Science & Engineering, of Dr, A.P.J. Abdul Kalam Technical University
Lucknow, UP.

AMAN YADAV (1749210019)

AMAN YADAV 3
ACKNOWLEDGEMENT

It gives us a great sense of pleasure to present the report of the B. Tech Project undertaken
during B. Tech. Final Year. We owe special debt of gratitude to our Lab In-charge for Project
Lab, Department of Computer Science & Engineering / Information Technology, KCC
Institute of Technology & Management for his/her constant support and guidance throughout
the course of our work. His / Her sincerity, thoroughness and perseverance have been a
constant source of inspiration for us. It is only his cognizant efforts that our endeavors have
seen light of the day.

Our deep sense of gratitude is accorded to Mr. Kishan Kumar, Department of CSE & IT for
his constant official support, encouragement and motivation for our project work.

Last but not the least, we acknowledge our friends for their contribution in the completion of
the project.

Signature with date

AMAN YADAV 4
ABSTRACT

News App is a simple news app which uses NewsAPI to fetch top news headlines from the
API. The main aim of this app is to be a leading example of how to build Modern Android
applications for all Android Developer.

It uses Retrofit 2 to fetch news sources and news headlines from the API and displays in a
RecyclerView. It uses Room Persistence Library to provide offline functionality App first
loads the data from DB and then checks for fresh data from API, API is only called if DB
data is empty or expired The main aim of this sample app is show how to use the
new Architecture Guidelines with Kotlin.

Components Used

 LiveData
 ViewModel
 Room Persistence Library

AMAN YADAV 5
CHAPTER 1

INTRODUCTIO

What is Android?
Android is an open source and Linux-based Operating System for mobile devices such as
smartphones and tablet computers.
Android was developed by the Open Handset Alliance, led by Google, and other companies.

Android offers a unified approach to application development for mobile devices which
means developers need only develop for Android, and their applications should be able to run
on different devices powered by Android.

The first beta version of the Android Software Development Kit (SDK) was released by
Google in 2007 where as the first commercial version, Android 1.0, was released in
September 2008.

On June 27, 2012, at the Google I/O conference, Google announced the next Android
version, 4.1 Jelly Bean. Jelly Bean is an incremental update, with the primary aim of
improving the user interface, both in terms of functionality and performance.

The source code for Android is available under free and open source software licenses.
Google publishes most of the code under the Apache License version 2.0 and the rest, Linux
kernel changes, under the GNU General Public License version 2.

Android Applications
Android applications are usually developed in the Java language using the Android Software
Development Kit. Once developed, Android applications can be packaged easily and sold out
either through a store such as Google Play or the Amazon Appstore. Android powers
hundreds of millions of mobile devices in more than 190 countries around the world. It's the
largest installed base of any mobile platform and growing fast. Every day more than 1 million
new Android devices are activated worldwide. This tutorial has been written with an aim to
teach you how to develop and package Android application. We will start from environment
setup for Android application programming and then drill down to look into various aspects
of Android applications.

AMAN YADAV 6
Features of Android
Android is a powerful operating system competing with Apple 4GS and supports great
features. Few of them are listed below:

Feature Description

Beautiful UI Android OS basic screen provides a


beautiful and intuitive user interface.

Connectivity GSM/EDGE, IDEN, CDMA, EV-DO,


UMTS, Bluetooth, Wi-Fi, LTE, NFC and
WiMAX.
Storage SQLite, a lightweight relational database, is
used for data storage purposes.

Storage H.263, H.264, MPEG-4 SP, AMR, AMR-


WB, AAC, AAC 5.1, MP3, MID, WAV,
JPEG, PNG, GIF, and BMP.
Messaging SMS and MMS

Web browser Based on the open-source Web Kit layout.

Multi-touch Android has native support for multi-touch


which was initially made available in
handsets such as the HTC Hero.
Multi-tasking User can jump from one task to another and
same time various application can run
simultaneously.
Resizable widgets Widgets are resizable, so users can expand
them to show more content or shrink them
to save space
Multi-Language Supports single direction and bi-directional
text.
GCM Google Cloud Messaging (GCM) is a
service that lets developers send short
message data to their users on Android
devices, without needing a proprietary sync
solution.
Wi-Fi Direct A technology that lets apps discover and
pair directly, over a high-bandwidth peer-to-
peer connection.

Android Beam A popular NFC-based technology that lets


users instantly share, just by touching two
NFC-enabled phones together.

AMAN YADAV 7
Introduction to App

This app uses NewsAPI to get various sources and each source can provide major headlines.
It uses Retrofit 2 to fetch news sources and news headlines from the API and displays in a
RecyclerView. It uses Room Persistence Library to provide offline functionality App first
loads the data from DB and then checks for fresh data from API, API is only called if DB
data is empty or expired The main aim of this sample app is show how to use the
new Architecture Guidelines with Kotlin.

System specification
 Mobile Version: Android 4.3 or upper versions
 RAM: 500 MB or upper versions

AMAN YADAV 8
CHAPTER 2

DETAILED SPECIFICATION

Front End

 Android software development kit

The Android software development kit (SDK) includes a comprehensive set of development
tools. These include a debugger, libraries, a handset emulator based on QEMU,
documentation, sample code, and tutorials. Currently supported development platforms
include computers running Linux, Mac OS X 10.5.8 or later, and Windows XP or later. As of
March 2015, the SDK is not available on Android itself, but the software development is
possible by using specialized Android applications.

Android Studio, [9] made by Google and powered by IntelliJ, is the official IDE; however,
developers are free to use others. Additionally, developers may use any text editor to edit
Java and XML files, then use command line tools ( Java Development Kit and Apache Ant
are required) to create, build and debug Android applications as well as control attached
Android devices (e.g., triggering a reboot, installing software package(s) remotely).

 Using Kotlin for Android Development Android mobile development has been
Kotlin-first since Google I/O in 2019. Using Kotlin for Android development, you

can benefit from:

 Less code combined with greater readability. Spend less time writing
your code and working to understand the code of others.
 Mature language and environment. Since its creation in 2011, Kotlin has
developed continuously, not only as a language but as a whole ecosystem with
robust tooling. Now it's seamlessly integrated in Android Studio and is
actively used by many companies for developing Android applications.
 Kotlin support in Android Jetpack and other libraries. KTX extensions add
Kotlin language features, such as coroutines, extension functions, lambdas, and
named parameters, to existing Android libraries.
 Interoperability with Java. You can use Kotlin along with the Java
programming language in your applications without needing to migrate all
your code to Kotlin.

AMAN YADAV 9
 Support for multiplatform development. You can use Kotlin for developing
not only Android but also iOS, backend, and web applications. Enjoy the
benefits of sharing the common code among the platforms.
 Code safety. Less code and better readability lead to fewer errors. The Kotlin
compiler detects these remaining errors, making the code safe.
 Easy learning. Kotlin is very easy to learn, especially for Java developers.
 Big community. Kotlin has great support and many contributions from the
community, which is growing all over the world. According to Google, over
60% of the top 1000 apps on the Play Store use Kotlin.

Back End

 RecyclerView: RecyclerView makes it easy to efficiently display large sets of data.


You supply the data and define how each item looks, and the RecyclerView library
dynamically creates the elements when they're needed. As the name implies,
RecyclerView recycles those individual elements. When an item scrolls off the
screen, RecyclerView doesn't destroy its view. Instead, RecyclerView reuses the
view for new items that have scrolled onscreen. This reuse vastly improves
performance, improving your app's responsiveness and reducing power
consumption.

 Chrome Custom Tabs: App developers face a choice when a user taps a URL to
either launch a browser, or build their own in-app browser using WebViews.

Both options present challenges—launching the browser is a heavy context switch


that isn't customizable, while WebViews don't share state with the browser and add
maintenance overhead.

Chrome Custom Tabs give apps more control over their web experience, and make
transitions between native and web content more seamless without having to resort to
a WebView.

Chrome Custom Tabs allow an app to customize how Chrome looks and feels. An
app can change things like:

 Toolbar color
 Enter and exit animations
 Add custom actions to the Chrome toolbar, overflow menu and
bottom toolbar.

Chrome Custom Tabs also allow the developer to pre-start Chrome and pre-fetch content for
faster loading.

 Android Architecture Components: Android architecture components are a


collection of libraries that help you design robust, testable, and maintainable
AMAN YADAV 10
apps.

AMAN YADAV 11
Start with classes for managing your UI component lifecycle and handling data
persistence.

 Learn the basics of putting together a robust app with the Guide to
app architecture.
 Manage your app's lifecycle. New lifecycle-aware components help you
manage your activity and fragment lifecycles. Survive configuration
changes, avoid memory leaks and easily load data into your UI.
 Use LiveData to build data objects that notify views when the
underlying database changes.
 ViewModel stores UI-related data that isn't destroyed on app rotations.
 Room is a SQLite object mapping library. Use it to avoid boilerplate code
and easily convert SQLite table data to Java objects. Room provides compile
time checks of SQLite statements and can return RxJava, Flowable and
LiveData observables.

NewsAPI: News API is a simple HTTP REST API for searching and retrieving live articles
from all over the web. It can help you answer questions like:

 What top stories is TechCrunch running right now?


 What new articles were published about the next iPhone today?
 Has my company or product been mentioned or reviewed by any blogs recently?

You can search for articles with any combination of the following criteria:

 Keyword or phrase. Eg: find all articles containing the word 'Microsoft'.
 Date published. Eg: find all articles published yesterday.
 Source name. Eg: find all articles by 'TechCrunch'.
 Source domain name. Eg: find all articles published on thenextweb.com.
 Language. Eg: find all articles written in English.

You can sort the results in the following orders:

 Date published
 Relevancy to search keyword
 Popularity of source

You need an API key to use the API - this is a unique key that identifies your requests.

AMAN YADAV 12
CHAPTER 3

BLOCK

DIAGRAM

Architecture

AMAN YADAV 13
Dependency Graph

View Model

AMAN YADAV 14
Android Architecture Components

Live Model

AMAN YADAV 15
App Component

Activity

AMAN YADAV 16
Android Architecture

AMAN YADAV 17
CHAPTER 4

METHODOLOG

Tools used for project

 Android Studio

Android Studio is the official Integrated development environment (IDE) for Android
platform development.

It was announced on May 16, 2013 at the Google I/O conference. Android Studio is freely
available under the Apache License 2.0.

Android Studio was in early access preview stage starting from version 0.1 in May 2013, then
entered beta stage starting from version 0.8 which was released in June 2014.

The first stable build was released in December 2014, starting from version 1.0.

Based on JetBrains' IntelliJ IDEA software, Android Studio is designed specifically for
Android development. It is available for download on Windows , Mac OS X and Linux and
replaced Android Development Tools (ADT) as Google's primary IDE for native Android
application development.

Android Tool 1: Visual Layout editor

Create complex layouts with Constraint Layout by adding constraints from each view to
other views and guidelines. Then preview your layout on any screen size by selecting one of
various device configurations or by simply resizing the preview window.

Android Tool 2: APK Analyzer

Find opportunities to reduce your Android app size by inspecting the contents of your app
APK file, even if it wasn’t built with Android Studio. Inspect the manifest file, resources, and
DEX files. Compare two APKs to see how your app size changed between app versions.

Android Tool 3: The SDK and AVD Manager

This tool serves a number of important functions. It manages the different versions of the
Android SDKs (build targets) that you can develop for, as well as third-party add-ons, tools,

AMAN YADAV 18
devices drivers, and documentation. Its second function is to manage the Android Virtual
Device configurations (AVDs) you use to configure emulator instances.

AMAN YADAV 19
Android Tool 4: Android Debug Bridge

The Android Debug Bridge (ADB) connects other tools with the emulator and devices.
Besides being critical for the other tools (most especially the Eclipse ADT plug-in) to
function, you can use it yourself from the command line to upload and download files, install
and uninstall packages, and access many other features via the shell on the device or
emulator.

AMAN YADAV 20
CHAPTER

5 CODING

MainActivity.kt

package com.example.newsfresh

import android.net.Uri
import
android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.browser.customtabs.CustomTabsIntent
import
androidx.recyclerview.widget.LinearLayoutManager
import com.android.volley.Request
import com.android.volley.Response
import com.android.volley.toolbox.JsonObjectRequest
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity(), NewsItemClicked

{ private lateinit var mAdapter: NewsListAdapter

override fun onCreate(savedInstanceState: Bundle?) {


super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

recyclerView.layoutManager =
LinearLayoutManager(this) fetchData()
mAdapter =
NewsListAdapter(this)
recyclerView.adapter =
mAdapter
}

private fun fetchData() {

val url = "https://newsapi.org/v2/top- headlines?


country=in&apiKey=ccb9edb92a2c493b87b5494ace198cb3"

// Request response from the provided


URL. val jsonObjectRequest =
JsonObjectRequest(

Request.Method.GET,
url, null,
Response.Listener {
val newsJsonArray =
it.getJSONArray("articles") val newsArray =
ArrayList<News>()
for(i in 0 until newsJsonArray.length()) {
val newsJsonObject =
newsJsonArray.getJSONObject(i) val news = News(
newsJsonObject.getString("title"),
newsJsonObject.getString("author"),

AMAN YADAV 21
},

Response.ErrorListener {

}
)
MySingleton.getInstance(this).addToRequestQueue(jsonObjectRequest)
}

override fun onItemClicked(item: News) {


val builder = CustomTabsIntent.Builder()
val customTabsIntent = builder.build()
customTabsIntent.launchUrl(this, Uri.parse(item.url))
}
}

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


MySingleton.kt
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
package com.example.newsfresh
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
import android.content.Context
android:layout_height="match_parent"
import
tools:context=".MainActivity">
com.android.volley.Request
import com.android.volley.RequestQueue
<androidx.recyclerview.widget.RecyclerView
import android:id="@+id/recyclerView"
com.android.volley.toolbox.Volley
android:layout_width="0dp"
android:layout_height="0dp"
class MySingleton constructor(context: Context)
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
{ companion object {
app:layout_constraintRight_toRightOf="parent"
@Volatile
app:layout_constraintBottom_toBottomOf="parent"/>
private var INSTANCE: MySingleton? =
null fun getInstance(context: Context)
</androidx.constraintlayout.widget.ConstraintLayout>
=
INSTANCE ?: synchronized(this) {

AMAN YADAV 22
}
}

private val requestQueue: RequestQueue by lazy {


// applicationContext is key, it keeps you from leaking the
// Activity or BroadcastReceiver if someone passes one
in. Volley.newRequestQueue(context.applicationContext)
}
fun <T> addToRequestQueue(req: Request<T>)
{ requestQueue.add(req)
}
}

News.kt

package com.example.newsfresh
NewsListAdapter.kt
data class News(
val title: String,
package
val com.example.newsfresh
author:
String, val url:
import
String, val
android.view.LayoutInflater
imageUrl: String
import android.view.View
import android.view.ViewGroup
import
android.widget.ImageView
import
android.widget.TextView
import
androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide

class NewsListAdapter(private val listener:


NewsItemClicked): RecyclerView.Adapter<NewsViewHolder>() {

private val items: ArrayList<News> = ArrayList()

override fun onCreateViewHolder(parent: ViewGroup, viewType:


Int): NewsViewHolder {
val view =
LayoutInflater.from(parent.context).inflate(R.layout.item_news, parent, false)
val viewHolder =
NewsViewHolder(view)
view.setOnClickListener{
listener.onItemClicked(items[viewHolder.adapterPosition])
}
return viewHolder
}

AMAN YADAV 23
val currentItem = items[position]
holder.titleView.text =
currentItem.title holder.author.text =
currentItem.author

Glide.with(holder.itemView.context).load(currentItem.imageUrl).into(holder.image
)
}

fun updateNews(updatedNews: ArrayList<News>)


{ items.clear()
items.addAll(updatedNews)

notifyDataSetChanged()
}
}

class NewsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)


{ val titleView: TextView = itemView.findViewById(R.id.title)
val image: ImageView = itemView.findViewById(R.id.image)
val author: TextView = itemView.findViewById(R.id.author)
}

interface NewsItemClicked {

build.gradle (:app)

package com.example.newsfresh

import
android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import
android.widget.ImageView
import
android.widget.TextView
import
androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide

class NewsListAdapter(private val listener:


NewsItemClicked): RecyclerView.Adapter<NewsViewHolder>() {

private val items: ArrayList<News> = ArrayList()

override fun onCreateViewHolder(parent: ViewGroup, viewType:


Int): NewsViewHolder {
val view =
LayoutInflater.from(parent.context).inflate(R.layout.item_news, parent, false)
val viewHolder =
NewsViewHolder(view)
view.setOnClickListener{
listener.onItemClicked(items[viewHolder.adapterPosition])
}
return viewHolder
}

AMAN YADAV 24
val currentItem = items[position]
holder.titleView.text =
currentItem.title holder.author.text =
currentItem.author

Glide.with(holder.itemView.context).load(currentItem.imageUrl).into(holder.image
)
}

fun updateNews(updatedNews: ArrayList<News>)


{ items.clear()
items.addAll(updatedNews)

notifyDataSetChanged()
}
}

class NewsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)


{ val titleView: TextView = itemView.findViewById(R.id.title)
val image: ImageView = itemView.findViewById(R.id.image)
val author: TextView = itemView.findViewById(R.id.author)
}

interface NewsItemClicked {

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newsfresh">

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>

AMAN YADAV 25
item_news.xml

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
xmlns:app="http://schemas.android.com/apk/res-auto">

<ImageView
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="200dp"
android:scaleType="centerCrop"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>

<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/image"
android:maxLines="2"
android:ellipsize="end"
android:layout_marginTop="12dp"
android:textSize="18sp"
android:textColor="#212121"/>

<TextView
android:id="@+id/author"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/title"
android:layout_marginTop="6dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

AMAN YADAV 26
CHAPTER 6

APPLICATION

S
News Apps is a personalized news aggregator that organizes and highlights what’s
happening in the world so that you can discover more about the stories that matter to
you.

Stay up to date on your interests

• The For You tab delivers the top stories across all your favorite topics and
sources in one place. You no longer need to search through various news sources
across mobile and web. Examine in-depth science, entertainment, fashion, sports,
cricket updates, finance or whatever else you care about.

One story. Numerous perspectives.

• With Full coverage you can be informed on how a story is reported from a variety
of sources. With just a tap you’ll see recent headlines from different sources, videos,
local news reports, FAQs, news analysis, social commentary and a timeline of
events for stories that developed over time.

Breaking news

• The Headlines tab offers an unfiltered view of top and breaking news articles from
around the world and India. Additional sections let you dig into more on tech news,
business news, travel news, national and international news, health and more.

Discover new sources and topics

• The Newsstand tab makes it easy to find and follow the sources that you trust,
as well as browse and discover new ones.

Access your favorite news and magazine subscriptions, together

• If you want to support your favorite news publisher, we’ve made it simple to
subscribe with your Account. This means no more forms, credit card numbers
or new passwords. Easily access them all within the same app.

A smart news app built for every phone, everywhere

• NewsFresh is designed to meet the needs of users with different phones

AMAN YADAV 27
and levels of connection.
• When your connection isn’t strong or you need to save data, NewsFresh will

AMAN YADAV 28
continue to work smoothly by slimming down the size of images and downloading
less data.

AMAN YADAV 29
CHAPTER 7

CONCLUSIO

N
The Android SDK ships with numerous other tools. Many of which are used for special
development cases. However, the tools listed above will be used with just about every
project, regardless of the type of app being developed. For more information on these and
other tools available, check out the Android Tools section of the Android website. Also, new
tools and improved tools are released on a fairly regular basis, so make sure you keep all of
the packages updated with the AVD and SDK Manager. Finally, above and beyond the
Android tools we've discussed, your best resource is the Android Developer website.
Complete with up-to-date SDK downloads, source documentation, tutorials, technical
articles, and the Android blog with the latest news, this website provides critical knowledge
and support for Android developers.

REFERNCES

 www.google.com
 GitHub: github.com/aayushdogra/News_Fresh
 Wikipedia
 Developers.android.com

AMAN YADAV 30

You might also like