Summer Training Project Report: Submitted by
Summer Training Project Report: Submitted by
Summer Training Project Report: Submitted by
Submitted By:
Shivam Jha
IT-2K13
(CSJMA13001390-160)
**********************************************
COMPANY PROFILE
Android History :
THE BIRTH OF ANDROID
Google Acquires Android Inc.
In July 2005, Google acquired Android Inc., a small startup company based in Palo Alto,
CA. Android's co-founders who went to work at Google included Andy Rubin (co-founder
of Danger), Rich Miner (co-founder of Wildfire Communications, Inc), Nick Sears (once
VP at T-Mobile), and Chris White (one of the first engineers at WebTV). At the time, little
was known about the functions of Android Inc. other than they made software for mobile
phones.
2.1.2 Open Handset Alliance Founded
On 5 November 2007, the Open Handset Alliance, a consortium of several companies
which include Google, HTC, Intel, Motorola, Qualcomm, T-Mobile, Sprint Nextel and
NVIDIA, was unveiled with the goal to develop open standards for mobile devices.
ANDROID VERSIONS
Android 1.0 (Angel Cake) : The first version of the open source software
was released back in 2008.
Android 1.1 (Battenberg) : In Feb 2009, version 1.1
Android 1.5 (Cupcake) : Launched in April 2009
Android 1.6 (Donut) : Released in September 2009. Brought the Quick
Search Box and had Screen Size Diversity.
Android 2.0 / 2.1 (clair) : Released in 26 October 2009 and January
2010. Supported High Density Displays and Live Wallpapers which
responds to touch. Supported Google Maps Navigation, Speech to text and
Home Screen Customization.
Android 2.2 (Froyofrozen yogurt) : Released in the summer of 2010.
Android added the support of Voice-Actions and Portable Mobile-Hotspots
and Increased performance.
Android 2.3 (Gingerbread) : Gingerbread landed by the end of 2010.
Added new Gaming APIs, support for NFC and Battery Management.
Android 3.0 (Honeycomb): For the first time Google released a software
that was totally focused on tablets. This version released in July/august
2011. Added System Bars for on-Screen Navigation Controls and Quick
Settings.
Android 4.0 (Ice Cream Sandwich 4.0): Released in October 2011.
Supported custom Home-Screen, data usage control and Android Beam for
sharing over NFC.
Android 4.1 (jelly bean4.1) : Released in 26th June 2012. Google Now
was added and Actionable notifications were also featured. It also
supported multiple users on One Device by Account Switching feature.
Android 4.4 (KitKat) : Voice: OK Google was featured also were
immersive design and smart dialer.
Android 5.0 (Lollypop) : It supports on many devices from watches to
TV. Introduced Material Design and Notifications on Lock Screen.
Android 6.0 (Marshmallow) : Added flexible permissions and the
consumes less battery by optimizing apps.
FEATURES OF ANDROID OS
Media support for common audio, video, and still image formats (MPEG4,
H.264, MP3, AAC, AMR, JPG, PNG, GIF)
BINDER IPC
The Binder Inter-Process Communication (IPC) mechanism allows the application framework to
cross process boundaries and call into the Android system services code. This enables high level
framework APIs to interact with Android system services. At the application framework level, this
communication is hidden from the developer and things appear to "just work."
SYSTEM SERVICES
The hardware abstraction layer (HAL) defines a standard interface for hardware vendors to
implement and allows Android to be agnostic about lower-level driver implementations. The HAL
allows you to implement functionality without affecting or modifying the higher level system. HAL
implementations are packaged into modules (.so) file and loaded by the Android system at the
appropriate time.
LINUX KERNEL
Developing your device drivers is similar to developing a typical Linux device driver. Android uses a
version of the Linux kernel with a few special additions such as wake locks (a memory
management system that is more aggressive in preserving memory), the Binder IPC driver, and
other features important for a mobile embedded platform. These additions are primarily for
system functionality and do not affect driver development.
Android System Architecture
Why Android is better ?
Applications
- Google Applications
Android includes most of the time many Google applications like Gmail, YouTube or Maps.
These applications are delivered with the machine most of the time, except in certain
cases, such as some phones running android on which the provider has replaced Google
applications by its own applications.
-Widgets
With android, it is possible to use widgets which are small tools that can most often get
information. These widgets are directly visible on the main window.
-Android Market
This is an online software store to buy applications. Developers who created applications
can add them into the store, and these applications can be downloaded by users, they can
be both free and paid.
Multitasking
Android allows multitasking in the sense that multiple applications can run simultaneously.
With Task Manager it is possible view all running tasks and to switch from one to another
easily.
SDK
A development kit has been put at disposal of everybody. Accordingly, any developer can
create their own applications, or change the android platform. This kit contains a set of
libraries, powerful tools for debugging and development, a phone emulator, thorough
documentation, FAQs and tutorials.
Modifiability:
This allows everyone to use, improve or transform the functions of Android for example
transform the interface in function of uses, to transform the platform in a real system
embedded Linux.
Build Target Version of Project : Marshmallow(Version 6.0-API Level 23)
Features
i) Fingerprint Authentication
This release offers new APIs to let you authenticate users by using their fingerprint scans
on supported devices, Use these APIs in conjunction with the Android Keystore system.
viii) Notifications
This release adds the following API changes for notifications:
When starting a new project, Android Studio automatically creates some of these files for
you, as shown in above figure, and populates them based onsensible defaults.
TOOLS USED IN PROJECT
Instant Run
Push code and resource changes to your app running on a device or
emulator and see the changes instantly come to life.
Instant Run dramatically speeds up your edit, build, and run cycles.
5. OpenWeatherMap API
OpenWeatherMap is a website which provides
API for the weather forecasts of various types.
Summer Training Project: Weather APP
A Weather App which shows the weather forecast for
Present day as well as Next 2 Weeks.
It shows the weather forecasts in a very interactive
manner.
For example :
Clear Sky.
Rain.
Light Clouds.
Storm. etc.
Features of the App
ForecastFragment forecastFragment =
((ForecastFragment)getSupportFragmentManager()
.findFragmentById(R.id.fragment_forecast));
forecastFragment.setUseTodayLayout(!mTwoPane);
SunshineSyncAdapter.initializeSyncAdapter(this);
}
return super.onOptionsItemSelected(item);
}
getSupportFragmentManager().beginTransaction()
.add(R.id.weather_detail_container, fragment).commit(); }
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
if (cursor != null) {
String locationSetting = Utility.getPreferredLocation(getActivity());
((Callback) getActivity())
.onItemSelected(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
locationSetting, cursor.getLong(COL_WEATHER_DATE)
));
}
mPosition = position;
}
});
mForecastAdapter.setUseTodayLayout(mUseTodayLayout);
return rootView;
}
room.
onActivityCreated() : It is called when the fragment's activity has
been created and this fragment's view hierarchy instantiated. It is
creating and initializing the Loader.
public void onActivityCreated(Bundle savedInstanceState) {
getLoaderManager().initLoader(FORECAST_LOADER, null, this);
super.onActivityCreated(savedInstanceState);
}
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps
installed!");
Toast.makeText(getActivity(),"No Receiving Apps
Installed.",Toast.LENGTH_SHORT).show();
}
}
}
}
String locationSetting =
Utility.getPreferredLocation(getActivity());
Uri weatherForLocationUri =
WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(
locationSetting, System.currentTimeMillis());
bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_location_key)));
bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_units_key)));
}
sqLiteDatabase.execSQL(SQL_CREATE_LOCATION_TABLE);
sqLiteDatabase.execSQL(SQL_CREATE_WEATHER_TABLE);
onUpgrade() : Since the database is only cache for the online data
from API therefore, the upgrade policy is to simply drop the table and
then create a new one.
WeatherProvider.java : This class works as a Content Provider for the
App.
A Content Provider works as a wrapper or Insulation between the
Database and App. Other apps can use it to access the database without
knowing that how it is stored. It is also useful when we are trying to change
the Database type from SQLite to a file or Dynamic Runtime data or a
different Database.
When the data is changed ContentProvider is used by SyncAdapters and
CursorLoaders to update and display the data.
@Override
public Bundle editProperties(
AccountAuthenticatorResponse r, String s) { throw new UnsupportedOperationException();}
@Override
public Bundle addAccount(AccountAuthenticatorResponse r, String s,String s2,String[] strings,
Bundle bundle) throws NetworkErrorException {
return null;
}
@Override
public Bundle confirmCredentials( AccountAuthenticatorResponse r,Account account, Bundle
bundle) throws NetworkErrorException {
return null;
}
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse r,Account account,String s,Bundle
bundle) throws NetworkErrorException {
throw new UnsupportedOperationException();
}
@Override
public String getAuthTokenLabel(String s) { throw new UnsupportedOperationException(); }
@Override
public Bundle updateCredentials(AccountAuthenticatorResponse r,Account account, String s,
Bundle bundle) throws NetworkErrorException {
throw new UnsupportedOperationException();
}
@Override
public Bundle hasFeatures(AccountAuthenticatorResponse r,Account account, String[] strings)
throws NetworkErrorException {
throw new UnsupportedOperationException();
}
SunshineSyncAdapter.java : It does the work of syncing the data from the
network in the background. This works as SyncManager.
It handles multiple sync requests using SyncAdapters.
Also takes care of other things like checking for Network Connection and
retrying download of the data.
In this class we are regularly querying the data from the API on fixed
intervals and getting data in JSON format.
The Query URL is like
api.openweathermap.org/data/2.5/forecast/daily?q=208017&mode=json&units=metric&
cnt=1&APPID=[MY_OWM_API_KEY]
"city":{
"id":1261638,
"country":"IN",
},
"list":[
"dt":1470722400,
"pressure":998.91,
"humidity":86,
"weather":[
],
"speed":3.57,"deg":190, "clouds":32
}
WEATHER FORECAST FOR TODAY
The SyncAdapter has few functions.
getWeatherDataFromJson() : It takes the string representing the
complete forecast in JSON format and pull out the data we need to
construct the Strings needed for display.
This function also inserts the values into the database using a
ContentValues vector and bulkInsert() method.
CONFIGUREPERIODICSYNC() FUNCTION
private void getWeatherDataFromJson(String forecastJsonStr,String locationSetting)
throws JSONException {
final String OWM_CITY = "city",OWM_CITY_NAME = "name",OWM_COORD = "coord",OWM_LATITUDE = "lat";
final String OWM_LONGITUDE = "lon",OWM_LIST = "list",OWM_PRESSURE = "pressure",OWM_HUMIDITY = "humidity";
final String OWM_WINDSPEED = "speed",OWM_WIND_DIRECTION = "deg",OWM_TEMPERATURE = "temp";
final String OWM_MAX = "max",String OWM_MIN = "min",OWM_WEATHER =
"weather",OWM_DESCRIPTION="main",OWM_WEATHER_ID = "id";
try {
JSONObject forecastJson = new JSONObject(forecastJsonStr);
JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST);
JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY);
String cityName = cityJson.getString(OWM_CITY_NAME);
JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD);
double cityLatitude = cityCoord.getDouble(OWM_LATITUDE);
double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE);
long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude);
Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length());
Time dayTime = new Time();
dayTime.setToNow();
int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff);
dayTime = new Time();
for(int i = 0; i < weatherArray.length(); i++) {
long dateTime;double pressure;int humidity;double windSpeed;double windDirection;
double high, low; Sring description;int weatherId;
JSONObject dayForecast = weatherArray.getJSONObject(i);
dateTime = dayTime.setJulianDay(julianStartDay+i);
pressure = dayForecast.getDouble(OWM_PRESSURE);
humidity = dayForecast.getInt(OWM_HUMIDITY);
windSpeed = dayForecast.getDouble(OWM_WINDSPEED);
windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION);
JSONObject weatherObject =
dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0);
description = weatherObject.getString(OWM_DESCRIPTION);
weatherId = weatherObject.getInt(OWM_WEATHER_ID);
JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE);
high = temperatureObject.getDouble(OWM_MAX);
low = temperatureObject.getDouble(OWM_MIN);
ContentValues weatherValues = new ContentValues();
weatherValues.put(WeatherContract.WeatherEntry.COLUMN_LOC_KEY, locationId);
weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DATE, dateTime);
weatherValues.put(WeatherContract.WeatherEntry.COLUMN_HUMIDITY, humidity);
weatherValues.put(WeatherContract.WeatherEntry.COLUMN_PRESSURE, pressure);
weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WIND_SPEED, windSpeed);
weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DEGREES, windDirection);
weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP, high);
weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP, low);
weatherValues.put(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC, description);
weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID, weatherId);
cVVector.add(weatherValues);
}
int inserted = 0;
if ( cVVector.size() > 0 ) {
ContentValues[] cvArray = new ContentValues[cVVector.size()];
cVVector.toArray(cvArray);
getContext().getContentResolver().bulkInsert(WeatherContract.WeatherEntry.CONTENT_URI, cvArray);
getContext().getContentResolver().delete(WeatherContract.WeatherEntry.CONTENT_URI,
WeatherContract.WeatherEntry.COLUMN_DATE + " <= ?",
new String[] {Long.toString(dayTime.setJulianDay(julianStartDay-1))});
notifyWeather();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
FUNCTION GETWEATHERDATAFROMJSON()
SunshineAuthenticatorService.java : This class is a service which lets
the sync adapter to access the authenticator.
@Override
public void onCreate() {
// Create a new authenticator object
mAuthenticator = new SunshineAuthenticator(this);
}
@Override
public IBinder onBind(Intent intent) {
return mAuthenticator.getIBinder();
}
}
@Override
public void onCreate() {
synchronized (sSyncAdapterLock) {
if (sSunshineSyncAdapter == null) {
sSunshineSyncAdapter = new SunshineSyncAdapter(getApplicationContext(), true);
}
}
}
@Override
public IBinder onBind(Intent intent) {
return sSunshineSyncAdapter.getSyncAdapterBinder();
}
}