viernes, 31 de mayo de 2013

Free software a possible activity for spanish productive model

Let's go to see real models of free software strategies in public administration.

Munich (Germany)
The administration of the city of Munich in Germany has completed the switch to the open source desktop. The IT department is now securing the strategy, to make sure it can be maintained by the city and to sustainably support interactions with citizens, businesses and other public authorities.

The city is now using a unified desktop system, Limux, its own distribution based on the Ubuntu Linux open source operating system and open source applications, on 14,000 of the total 15,000 desktops, spread over 51 offices across the city. That is 2,000 more than it's intended goal, using Limux on 80 % of its desktops.
Hofmann, head of the migration project,  stressed that saving money was never the primary aim. However, he said that moving to open source saved the city over 10 million euro so far.

Extremadura (Spain)
The government of Spain's autonomous region of Extremadura has begun the switch to open source of it desktop PCs. The government expects the majority of its 40,000 PCs to be migrated this year. Extremadura estimates that the move to open source will help save 30 million euro per year.

French Gendarmerie (France)
The French Gendarmerie is migrating some 90,000 desktops. Moreover the Gendarmerie estimates dramatic savings from using free open source software that amount to nearly 7 million Euros per year (2 million euros in licences).

Resume
 
Administration Country Number of desktops Saving (5 years) Saving a Desktop
City of Munich Germany 14,000 10,000,000.00 € 714.29 €
Autonomous region of Extremadura Spain 40,000 30,000,000.00 € 750.00 €
French Gendarmerie* France 90,000 35,000,000.00 € 388.89 €







Calculus

What it would happen if we do calculus for desktop of General Public Administration of Spain. Here, the figures
-->
Administration Country Number of desktops Saving (5 years) Saving a Desktop
General administration (mean)


520.83 €
General Public Administration Spain 450,012 234,381,250.00 € 520.83 €
Local Administration Spain 344,378 179,363,541.67 € 520.83 €
TOTAL

413,744,791.67 €
Direct Employment equivalent (for example programmer or support operator)

3,310
 
Result

    - Direct saving of licences, SO, office suite, antivirus system, ...
    - Ease of maintenance delivers significant time savings
    - Seamless integration simplifies processes

Conclusion
 - Saving of 414 million of € in 5 years, we could employ 3,310 programmers or support operators. (It is important to note that Windows 7 has a total of 920 developers, we could develop 3 new versions of Windows )
 - How many new employees around this business of free software will be create, direct and indirect employment.
 - How many companies could take advantage of use free software product in different ways, internal cost (licenses, better support, ...) and more competitive products using firmware base on free software.

Spain needs new ideas and activities in its productive model, maybe and I am convinced that this would be one of them. And public administrations should encourage local employment.


References

domingo, 26 de mayo de 2013

Android - Inter Process Communication

What the best way to do inter process communication (IPC) in Android between activities, the answer is parcelable

you need to implement an interface Parcelable

import android.os.Parcel;
import android.os.Parcelable;

public class UserParcelable implements Parcelable {
    private Integer mID;
    private String mName;
    private String mDescription;

...

} 


 and override the following method:
- writeToParcel(Parcel out, int flags): You should implement serialization of the object.


    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mID);
        out.writeString(mName);
        out.writeString(mDescription);
    } 

- describeContents(): You should define the kind of object, for instance using hashCode().

       
    @Override
    public int describeContents() {

        return hashCode();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((mDescription == null) ? 0 : mDescription.hashCode());
        result = prime * result + ((mID == null) ? 0 : mID.hashCode());
        result = prime * result + ((mName == null) ? 0 : mName.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        UserParcelable other = (UserParcelable) obj;
        if (mDescription == null) {
            if (other.mDescription != null)
                return false;
        } else if (!mDescription.equals(other.mDescription))
            return false;
        if (mID == null) {
            if (other.mID != null)
                return false;
        } else if (!mID.equals(other.mID))
            return false;
        if (mName == null) {
            if (other.mName != null)
                return false;
        } else if (!mName.equals(other.mName))
            return false;
        return true;

    }
       


- Object CREATOR: You should implement de-serialize your custom data objects from Parcel.

   public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
        public UserParcelable createFromParcel(Parcel in) {
            return new UserParcelable(in);
        }

        public UserParcelable[] newArray(int size) {
            return new UserParcelable[size];
        }
    };
       


- Constructor: You should define a constructor with parcel as argument.

       
    UserParcelable(Parcel in) {
        mID = in.readInt();
        mName = in.readString();
        mDescription = in.readString();
    }
    

It is important to note that using parcelable object than serializable object is sometimes up to 15 times faster. (http://blog.rocapal.org/?p=560)



jueves, 23 de mayo de 2013

The most important state diagrams in Android

ACTIVITY

The following diagram shows the important state paths of an Activity:

SERVICE

The following diagram shows the important state paths of a service:

miércoles, 22 de mayo de 2013

Android Components

Android components
    - Activity
    - Service
    - Content Provider
    - Broadcast Receiver



Application components are the essential building blocks of an Android application. Each component is a different point through which the system can enter your application. Not all components are actual entry points for the user and some depend on each other, but each one exists as its own entity and plays a specific role—each one is a unique building block that helps define your application's overall behavior.

There are four different types of application components. Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.

Here are the four types of application components:

ACTIVITIES [User Interaction]
    Activities are components that interact with the user and represents a single screen with a user interface, an activity is a single, focused thing that the user can do. For instance, an instant message application might have one activity that shows the list of contacts, another the conversation detail, and another activity for sending emails. Although all of them work together in an application, each one is independet of the others. As such, a different application could start any one of these activities.




  
 An activity is implemented as a subclass of Activity.

 public class MyActivity extends Activity {
     ...
 }


public class Activity extends ApplicationContext {

     protected void onCreate(Bundle savedInstanceState);

     protected void onStart();
    
     protected void onRestart();

     protected void onResume();

     protected void onPause();

     protected void onStop();

     protected void onDestroy();
 }



Declaring the activity in the manifest
<manifest ... >
  <application ... >
      <activity android:name=".ExampleActivity" />
      ...
  </application ... >
  ...
</manifest >


Starting activity
Intent intent = new Intent(this, SignInActivity.class);
startActivity(intent);


Android developers -> Activity
http://developer.android.com/reference/android/app/Activity.html
http://developer.android.com/guide/components/activities.html


SERVICES [Service Provider]
A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. A service does not provide a user interface. For instance, a service might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it.

Because it is sometime misundestood let's go to show what it is not
    - A Service is not a separate process.
    - A Service is not a thread.

Traditionally, there are two classes you can extend to create a started service:
    Service

        IntentService (This is a subclass of Service that uses a worker thread to handle all start requests, one at a time)

Declaring a service in the manifest
<manifest ... >
  ...
  <application ... >
      <service android:name=".ExampleService" />
      ...
  </application>
</manifest>


Starting a Service
    Intent intent = new Intent(this, HelloService.class);
    startService(intent);


Android developers -> Service
http://developer.android.com/reference/android/app/Service.html
http://developer.android.com/guide/components/services.html


CONTENT PROVIDERS [Data Provider]
Content providers manage access to a structured set of data. They encapsulate the data, and provide mechanisms for defining data security. Content providers are the standard interface that connects data in one process with code running in another process. Application could store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Through the content provider, other applications can query or even modify the data.

    A content provider is implemented as a subclass of ContentProvider and must implement a standard set of APIs that enable other applications to perform transactions.
public class ExampleProvider extends ContentProvider {
...
 public Cursor query(
        Uri uri,
        String[] projection,
        String selection,
        String[] selectionArgs,
        String sortOrder) {
...
}



Android developers -> Content Provider
http://developer.android.com/guide/topics/providers/content-providers.html
http://developer.android.com/reference/android/content/ContentProvider.html


BROADCAST RECEIVER [System Event Listener]

A unique aspect of the Android system design is that any application can start another application’s component. For example, if you want the user to capture a photo with the device camera, there's probably another application that does that and your application can use it, instead of developing an activity to capture a photo yourself. You don't need to incorporate or even link to the code from the camera application. Instead, you can simply start the activity in the camera application that captures a photo. When complete, the photo is even returned to your application so you can use it. To the user, it seems as if the camera is actually a part of your application.

Because the system runs each application in a separate process with file permissions that restrict access to other applications, your application cannot directly activate a component from another application. The Android system, however, can. So, to activate a component in another application, you must deliver a message to the system that specifies your intent to start a particular component. The system then activates the component for you.

Broadcast Receivers enable reception of intents from the system or other applications without running other activities or services of the application.

A broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as an Intent object.

Android developers -> Broadcast Receiver
http://developer.android.com/reference/android/content/BroadcastReceiver.html