viernes, 30 de marzo de 2012

Localize your apps and content more easily – new formats in Translator Toolkit


Cross-posted with the Google Open Source Blog and the Google Translate Blog

At Google, we put a lot of energy into helping localize the world's information to make it more useful to more people. It's not just about localizing our own products – we want to provide tools that make it easy for translators and developers around the world to localize their own apps and content. Google Translator Toolkit is our online translation tool for amateur and professional translators -- it’s built onGoogle Translate and supports more than 100,000 language pairs.

This week, the Translator Toolkit team has launched support for four new translation-related file formats:

Android Resource (.xml)
Application Resource Bundle (.arb)
Chrome Extension (.json)
GNU gettext-based (.po)

With these new file formats, you can use Translator Toolkit to localize your apps and other products and content much more quickly and easily.

For example, to translate your Android application, go into the res/values directory and upload strings.xml into Translator Toolkit -- Translator Toolkit will now automatically translate it. You can then share your translations with amateur or professional translators, who can localize the text using Translator Toolkit’s WYSIWYG online editor.


When you’re finished, you can export your translated application and store it in a locale-specific directory in Android. Voilà -- easy localization! 翻译起来太方便了!

In addition, we’ve made the Translator Toolkit interface more intuitive for these new file formats so users can translate faster and more accurately. For example, you can turn on ‘Customized colors’ so translators can annotate the edited segments, ‘Number of characters in the segment’ to make sure the text doesn’t run too long (very important for mobile devices), and ‘Synchronized scrolling’ so you can scroll the original and translated text at the same time, which makes navigation much easier.



With these new file formats and UI features, along with the file formats we already support (.aea, .srt, .html), we hope Translator Toolkit can help you reach more users around the world.

When you’re ready, give Google Translator Toolkit a try and suggest any improvements you’d like to see so we can work on making it even better.


Chris Yang and Haidong Shao are on the Google Translation Toolkit team. 

jueves, 29 de marzo de 2012

Android Developer Tutorial | Location Manager |


Here I will build upon the same to show how changes in location can be displayed on the map.
The location services are provided in the android.location package.

In order to use location services, our activity needs to implement the LocationManager Interface.
What does a LocationManager provide? 

It is through this interface that an application can access the system’s location services. These services basically allow the application to obtain periodic updates of the device’s geographical location. It also helps in firing an application specific intent when the device comes within the proximity of a specified location.
Since in my example I want to simulate a location change and make my activity respond to the same, I am implementing this interface.

In order to make it an effective application, I have shown my location (hard-coded) on the google map. Then, I have used the location manager to handle any change in the location. The change in location needs to be simulated on the emulator by connecting through telnet. How to simulate location change is given at the end of this tutorial.

Now, dive into the code. 


Step 1: Obtain the LocationManager instance:

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, this);

After getting the location manager, I am setting default GPS provider and asking to be notified if the location changes by more than 500 meters from the current location, the frequency of updation being 1 sec.

Step 2: Override the onLocationChanged() method in order to respond to changes in location.

      public void onLocationChanged(Location location) {
            if (location != null) {
                  double lat = location.getLatitude();
                  double lng = location.getLongitude();
                  String currentLocation = "The location is changed to Lat: " + lat + " Lng: " + lng;
                  myLoc.setText(currentLocation);
                  geoPoint = new GeoPoint((int) lat * 1000000, (int) lng * 1000000);
                  myMC.animateTo(geoPoint);
            }
      }

This method gets invoked when we change the location through the telnet connection to the emulator as described at the end of the tutorial. Based on the latitude and the longitude settings sent, the GeoPoint is changed to display the new location.

That is it. I have not overridden any of the other methods provided by the locationManager. Complete code is downloadable here.

How to simulate location change in the emulator?
Start the Emulator from eclipse
Start a command prompt
Start telnet
Then, type, o localhost 5554
This connects the telnet client to the android emulator (assuming emulator is running locally listening on port 5554. Else this connection fails)
Now type
geo fix 79.000000 13.000000 (or your latitude and longitude)
This sends the location change signal to the emulator.

martes, 27 de marzo de 2012

Android Developer Tutorial | SQLite DB Example |


There are 4 ways of storing data on the android platform:

  • 1.    Preferences
  • 2.    SQLite Database
  • 3.    Files
  • 4.    Network

A word about each of them here and then I will move on to an example that shows how to work with SQLite DB that comes along with the android platform.

Preferences – 
Basically used for storing user preferences for a single application or across applications for a mobile. This is typically name-value pairs accessible to the context.

Databases – 
Android supports creating of databases based on SQLite db. Each database is private to the applications that creates it 

Files –
Files can be directly stored on the mobile or on to an extended storage medium. By default other applications cannot access it.

Network – 
Data can be stored and retrieved from the network too depending on the availability.

If an application wants to store and retrieve data for its own use, without having to share the data across applications, it can access the SQLite DB directly.

In this example, we will do the following:
1.    Create a database (typically a one time activity)
2.    Create a table (typically a one time activity)
3.    Insert values into the table
4.    Retrieve the values from the table
5.    Display the retrieved values as a List view
6.    Delete all the records from the table before closing the connection to the database

Step 1: Create a database:

   sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAMEMODE_PRIVATEnull);

This opens a database defined in the constant SAMPLE_DB_NAME, if it already exists. Else it creates a database and opens it. The second parameter is operating mode : MODE_PRIVATE meaning it is accessible to only this context. The other modes are and MODE_WORLD_WRITABLE. MODE_WORLD_READABLE

Step 2: Create a Table:

sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
                        SAMPLE_TABLE_NAME +
                        " (LastName VARCHAR, FirstName VARCHAR," +
                        " Country VARCHAR, Age INT(3));");

Step 3: Insert values into the table:

sampleDB.execSQL("INSERT INTO " +
                        SAMPLE_TABLE_NAME +
                        " Values ('Makam','Sai Geetha','India',25);");

Step 4: Retrieve values 

Cursor c = sampleDB.rawQuery("SELECT FirstName, Age FROM " +
                        SAMPLE_TABLE_NAME +
                        " where Age > 10 LIMIT 5"null);
            
      if (c != null ) {
            if  (c.moveToFirst()) {
                  do {
String firstName = c.getString(c.getColumnIndex("FirstName"));
                  int age = c.getInt(c.getColumnIndex("Age"));
                  results.add("" + firstName + ",Age: " + age);
                  }while (c.moveToNext());
            } 
       }

Step 5: Display the values as a list 
            
       this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));

The statement displays it as a list as the class extends a ListActivity.

Step 6: Delete the values from the table in the finally part of the try block

finally {
            if (sampleDB != null
                  sampleDB.execSQL("DELETE FROM " + SAMPLE_TABLE_NAME);
                  sampleDB.close();
        }

It is as simple as this to work with the SQLite DB even in android. No different from a desktop application. However, there are various overloaded methods of query() provided by the SQLIteDatabase class which can be more optimally used instead of execSQL.

The complete code for this example is downloadable here.

domingo, 25 de marzo de 2012

Google Android store fools hundreds in China


The unofficial Android store we’re discovering exists in Zhuhai today shows us what it really means to go up against the masses in the world’s largest smartphone market. What we’ve got here is an off-green skinny store with the Android logo posted above the official Android text logo. This store not only offers Android devices galore, it’s carrying the iPhone as well!
What you’re going to see here is also China’s own Xiaomi phone and we wouldn’t be surprised to see the Meizu MX there as well! Both the front and back as well as the inside right have glowing logos, two of them Androids and the third a lovely Apple. This store sells electronics exclusively while the only real Android-centric superstore made by Google is Androidland – a mega fabulous playland for Android enthusiasts and new users alike. +Androidland, unlike this Chinese knock-off, was made in collaboration with Telstra and smartphone and tablet makers Samsung, HTC, Sony Ericsson, Motorola and LG.
Back in China you’ll find that this Android store stands alone. Android, Apple, and Windows Phone are ramping up their processes in China this season to keep up with the ever-growing demand that China is presenting. As China accepts smartphones as the norm for the nation, so too must all manufacturers drop what they’re doing and head on over to the mainland to get a piece of the pie. Get ready for more oddities on the way!
UPDATE: this is apparently only one of several such “Glowing Android” stores spread across the nation, each of them also carrying Apple products and HTC product galore.
UPDATE 2: The person who took the photos of the main shop goes by the name Brian Glucroft, and can be found on his page at isidorsfuge.com – check it out for additional details!

Android Developer Tutorial | Broadcast Receivers |


The concept of Broadcast Receivers, one of the fundamental blocks of Android, is very simple. These are applications that will respond to any intent that is broadcast by other applications. Provided the broadcast intent matches the intent specified against the receiver in the AndroidManifest.xml

This goes to automatically imply that many activities, events, services or the like can broadcast intents expecting the appropriate action to be automatically taken. So, to begin with, let us see the various Broadcast events that are given by the platform itself. Here is a standard list obtained from the android documentation:

·         ACTION_TIME_TICK
·         ACTION_TIME_CHANGED
·         ACTION_TIMEZONE_CHANGED
·         ACTION_BOOT_COMPLETED
·         ACTION_PACKAGE_ADDED
·         ACTION_PACKAGE_CHANGED
·         ACTION_PACKAGE_REMOVED
·         ACTION_PACKAGE_RESTARTED
·         ACTION_PACKAGE_DATA_CLEARED
·         ACTION_UID_REMOVED
·         ACTION_BATTERY_CHANGED
·         ACTION_POWER_CONNECTED
·         ACTION_POWER_DISCONNECTED
·         ACTION_SHUTDOWN

For details on when each of these intents get broadcasted, please see the android documentation. I have chosen the BROADCAST event ACTION_TIME_CHANGED as I can simulate a time change in the emulator. How to simulate the time change from adb shell is given at the end of this tutorial. 

Now let us get on to the example of a broadcast receiver. You can download the complete code here

Any activity that intends to respond to broadcasts has to extend theandroid.content.BroadcastReceiver class and implement the single method onReceive().

In my example, I just notify on the status bar that the time has changed and the moment the user clicks on the status bar and sees the details, clicks on the details, the notification is removed from the status bar. 

When the user clicks on the detailed portion, I take the user to the contacts application, just for anything better. Ideally this should take to an activity relevant to the application. So, if you see the onReceive()method, it is nothing but a notification example. That is all. 

      private NotificationManager mNotificationManager;
      private int SIMPLE_NOTFICATION_ID;
      
      @Override
      public void onReceive(Context context, Intent intent) {

        mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
      Notification notifyDetails = new Notification(R.drawable.android,"Time Reset!",System.currentTimeMillis());
      PendingIntent myIntent = PendingIntent.getActivity(context, 0, newIntent(Intent.ACTION_VIEW, People.CONTENT_URI), 0);
      notifyDetails.setLatestEventInfo(context, "Time has been Reset""Click on me to view Contacts", myIntent);
      notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL;
      mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
            Log.i(getClass().getSimpleName(),"Sucessfully Changed Time");

      }

Once this class is ready, start the android emulator in eclipse. Then, simulate a time changed from the command prompt as given below. You will see the notification come up.

Simulating a time change in the emulator:

To start the adb shell type (in windows, assuming the path has been set to the tools folder of android sdk installation):

C:\> adb shell
#date –- 2009-10-01 14:24:59
20070325.123456
#date –s 20070325.123456

The first step date –- gives the time in seconds since Jan 1st 1970. Take the result and give it as a parameter to date –s, the time is reset in adb and within a minute on the android emulator. This broadcasts the event that time has been changed in the emulator and kicks off the Broadcast Receiver program that has been executed.