Professional Documents
Culture Documents
NEWS APP
by
Bachelor of Technology
in
Management A.K.T.U
July, 2021
AMAN YADAV 1
TABLE OF CONTENTS Page
DECLARATION ................................................................................................... 3
ACKNOWLEDGEMENTS .................................................................................. 4
ABSTRACT ........................................................................................................... 5
CHAPTER 1 INTRODUCTION
CHAPTER 4 METHODOLOGY
CHAPTER 5 CODING
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 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.
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
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
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
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
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.
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.
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:
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.
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
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.
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.
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.
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.*
recyclerView.layoutManager =
LinearLayoutManager(this) fetchData()
mAdapter =
NewsListAdapter(this)
recyclerView.adapter =
mAdapter
}
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)
}
Activity_main.xml
AMAN YADAV 22
}
}
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
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
)
}
notifyDataSetChanged()
}
}
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
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
)
}
notifyDataSetChanged()
}
}
interface NewsItemClicked {
AndroidManifest.xml
<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" />
</manifest>
AMAN YADAV 25
item_news.xml
<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.
• 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.
• 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.
• The Newsstand tab makes it easy to find and follow the sources that you trust,
as well as browse and discover new ones.
• 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.
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