Headline

Advanced Technology:Android programming

Motivation

The implementation demonstrates advanced style of Technology:Android programming using the Technology:Android SDK and the Technology:Android Development Tool. The application uses other approaches compared to the two other implementations simpleAndroid and richerAndroid. This application is intended for employees. It aims to track his worked time. At the end of the month the Employee get an approximate salary expectation. It uses the geolocation feature by checking into a Android Service which is a background application to determine whether the employee is in the workplace. The time difference between the last and current review is added to the working hours.

The application demonstrates how to use...

Illustration

AppWidget

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 
	android:minWidth="147dip" 
	android:minHeight="72dip" 
	android:initialLayout="@layout/main"
/>

In the XML-Code we define the default properties of our AppWidget. In line three and four we define the size of the AppWidget-Layout and in line five we define the Layout of the AppWidget.

public class CompanyWidget extends AppWidgetProvider{
   @Override
   public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
      super.onUpdate(context, appWidgetManager, appWidgetIds);
      ...
      appWidgetManager.updateAppWidget(appWidgetIds, views);
}

In the class CompanyWidget we update the AppWidget

TabActivity

intent = new Intent().setClass(this, GeneralSettings.class);
spec = tabHost.newTabSpec("general").setIndicator("General",
           res.getDrawable(android.R.drawable.ic dialog map))
           .setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
...
tabHost.setCurrentTab(1);

In line one we create an Intent to launch an Activity for the tab. In line two till five we initialize a TabSpec for each tab and add it to the TabHost. In the last line we set our default TabSpec.

Manager & Provider

lManager = (LocationManager) getSystemService(LOCATION SERVICE);
cManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY SERVICE);

We use the system services Location Manager and Connectivity Manager to get the status of GPS and internet connection.

Service

Intent i = new Intent(this, WorkService.class);
i.putExtra("profile", profile);
startService(i);

In line one we create an Intent with the Service Class. In line two we put the profile object in the intent and in line three we start the Service.

Geolocation

if(gps enabled) {
   lManager.requestLocationUpdates(LocationManager.GPS PROVIDER, UPDATE TIME, 0, updateListenerForGPS);
}
   else
      if(network enabled)
         lManager.requestLocationUpdates(LocationManager.NETWORK PROVIDER, UPDATE TIME, 0, updateListenerForNetwork);

In line two and five we start the requests for the location.

private LocationListener updateListenerForGPS = new LocationListener() {
   @Override
   public void onStatusChanged(String provider, int status, Bundle extras) {			
   }
   @Override
   public void onProviderEnabled(String provider) {
      lManager.removeUpdates(updateListenerForNetwork);	
   }
   @Override
   public void onProviderDisabled(String provider) {
   }
   @Override
   public void onLocationChanged(Location location) {
   ...
   profile.addWorkedTime((double)(actualTime-lastUpdateTime)/60000);
   ...
   }
};

In line twelve we get in the onLocationChanged-method the current location. We use it, to look if the Employee is in the company. If he is then he get in line 14 a salary increase.

Map view & Overlay

Map view

<RelativeLayout
   ...>
   <com.google.android.maps.MapView
      android:id="@+id/mv google map"
      ...
      android:apiKey="@string/map key"/>
</relativelayout>

In line 4 we give the Map view an ID. In line 6 we use a map key. Here you find more information about the Map key. We show the Map in a MapActivity.

Overlay

We use two overlays in our implementation. The MapActivity constructs an rectangle with the CompanyOverlay and the MyLocationOverlay is a standard Android overlay to draw your own position.

MapView mView;
List<Overlay> mapOverlays;
MyLocationOverlay myLocationOverlay;
...
myLocationOverlay = new MyLocationOverlay(this, mView);
...
mView.getOverlays().add(myLocationOverlay);

In line 5 we create a MyLocationOverlay. In line 7 we get a list with overlays and we add the created mylocationOverlay to draw our position.

Preferences

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
   <PreferenceCategory>
      <Preference android:key="profile" />
   </preferencecategory>
</preferencescreen>

In line three we define the key for the preference.

private SharedPreferences settings;
...
settings = getSharedPreferences(getPackageName()+" preferences", MODE PRIVATE);	
...
settings.edit().putInt("profile", pos).commit();
...
settings.getInt("profile", 0);

In line three we get the preference-object. In line five we edit the preference with putInt(key,value) and we commit the changes. In line seven we get the value with getInt(key,default).

Architecture

Usage

Metadata


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    User edits

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.