Tuesday, September 27, 2011

Android’s Text to Speech

This is a sample activity which shows How to use Android’s Text to Speech capabilities. Text to Speech was introduced in Android 1.6, so when you create your new Android project make sure your minimum required SDK is set to Android 1.6 (or API level 4).

Underlying Algorithm:
Basic description of algorithm in step by step form:
1.) Create a Project MyTextToSpeech.
2.) Put the following code snippet in res/layout/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
    
<EditText android:id="@+id/input_text" 
        android:text=""
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
/>
<Button android:id="@+id/speak_button" 
        android:text="Speak to me"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
/>
</LinearLayout>
3.) You just need to import the following packages and create a TextToSpeech object.
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
4.) The second is an OnInitListener which you will need to implement.
5.) Run the Application.
Steps to Create:
1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. MyTextToSpeech. Enter following information:
Project name: MyTextToSpeech
Build Target: Android APIs 2.1
Application name: MyTextToSpeech
Package name: com.app.MyTextToSpeech
Create Activity: MyTextToSpeech
On Clicking Finish MyTextToSpeech code structure is generated with the necessary Android Packages being imported along with MyTextToSpeech.java. MyTextToSpeech class will look like following:
package com.app.MyTextToSpeech;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MyTextToSpeech extends Activity implements OnInitListener{
        /** Called when the activity is first created. */
        private int MY_DATA_CHECK_CODE = 0;
        private TextToSpeech tts;
        private EditText inputText;
        private Button speakButton;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            inputText = (EditText) findViewById(R.id.input_text);
            speakButton = (Button) findViewById(R.id.speak_button);
            speakButton.setOnClickListener(new OnClickListener() {                      
                @Override
                public void onClick(View v) {
                   String text = inputText.getText().toString();
                   if (text!=null && text.length()>0) {
                        Toast.makeText(MyTextToSpeech.this, "Saying: " + text, Toast.LENGTH_LONG).show();
                        tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                   }
                }
            });
            Intent checkIntent = new Intent();
            checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
            startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
       }
       protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == MY_DATA_CHECK_CODE) {
                if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
                        // success, create the TTS instance
                        tts = new TextToSpeech(this, this);
                } 
                else {
                        // missing data, install it
                        Intent installIntent = new Intent();
                        installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                        startActivity(installIntent);
                }
         }
       }
        @Override
        public void onInit(int status) {                
          if (status == TextToSpeech.SUCCESS) {
                Toast.makeText(MyTextToSpeech.this, "Text-To-Speech engine is initialized", Toast.LENGTH_LONG).show();
          }
          else if (status == TextToSpeech.ERROR) {
                Toast.makeText(MyTextToSpeech.this, "Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();
          }
        }
}
Output –The final output:

Rating Bar


This example shows how to crating rating bar in android.
Algorithm:
1.) Create a new project by File-> New -> Android Project name it RatingBarExample.
2.) Write following code into your main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:paddingLeft="10dip"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
    <RatingBar android:id="@+id/ratingbar1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:numStars="3"
       android:rating="2.5" />
    <RatingBar android:id="@+id/ratingbar2"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:numStars="5"
       android:rating="2.25" />
    <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_marginTop="10dip">
       
        <TextView android:id="@+id/rating"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content" />
           
        <RatingBar android:id="@+id/small_ratingbar"
           style="?android:attr/ratingBarStyleSmall"
           android:layout_marginLeft="5dip"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="center_vertical" />
           
    </LinearLayout>
    <RatingBar android:id="@+id/indicator_ratingbar"
       style="?android:attr/ratingBarStyleIndicator"
       android:layout_marginLeft="5dip"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center_vertical" />
           
</LinearLayout>
3.) Write following code into your strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, RatingBarExample!</string>
    <string name="app_name">RatingBarExample</string>
     <string name="ratingbar_rating">Rating:</string>
</resources>
4.) Build and run your code and check the output given below in the doc.
Steps:
1.) Create a project named RatingBarExample and set the information as stated in the image.
Build Target: Android 3.0
Application Name: RatingBarExample
Package Name: com.org. RatingBarExample
Activity Name: RatingBarExample
Min SDK Version: 11
2.) Open RatingBarExample.java file and write following code there:
package com.org.RatingBarExample;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.TextView;
public class RatingBarExample extends Activity implementsRatingBar.OnRatingBarChangeListener {
    RatingBar mSmallRatingBar;
    RatingBar mIndicatorRatingBar;
    TextView mRatingText;
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        mRatingText = (TextView) findViewById(R.id.rating);
        // We copy the most recently changed rating on to these indicator-only
        // rating bars
        mIndicatorRatingBar = (RatingBar) findViewById(R.id.indicator_ratingbar);
        mSmallRatingBar = (RatingBar) findViewById(R.id.small_ratingbar);
       
        // The different rating bars in the layout. Assign the listener to us.
        ((RatingBar)findViewById(R.id.ratingbar1)).setOnRatingBarChangeListener(this);
        ((RatingBar)findViewById(R.id.ratingbar2)).setOnRatingBarChangeListener(this);
    }
    public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromTouch){
        final int numStars = ratingBar.getNumStars();
        mRatingText.setText(
                getString(R.string.ratingbar_rating) + " " + rating + "/" + numStars);
        // Since this rating bar is updated to reflect any of the other rating
        // bars, we should update it to the current values.
        if (mIndicatorRatingBar.getNumStars() != numStars) {
            mIndicatorRatingBar.setNumStars(numStars);
            mSmallRatingBar.setNumStars(numStars);
        }
        if (mIndicatorRatingBar.getRating() != rating) {
            mIndicatorRatingBar.setRating(rating);
            mSmallRatingBar.setRating(rating);
        }
        final float ratingBarStepSize = ratingBar.getStepSize();
        if (mIndicatorRatingBar.getStepSize() != ratingBarStepSize) {
            mIndicatorRatingBar.setStepSize(ratingBarStepSize);
            mSmallRatingBar.setStepSize(ratingBarStepSize);
        }
    }
}
3.) Compile and build the project.
4.) Run on 3.0 simulator for the output.
Output

Monday, August 29, 2011

History of Android


The BlackBerry and iPhone, which have appealing and high-volume mobile platforms, are addressing opposite ends of a spectrum. The BlackBerry is rock-solid for the enterprise business user. For a consumer device, it's hard to compete with the iPhone for ease of use and the "cool factor." Android, a young and yet-unproven platform, has the potential to play at both ends of the mobile-phone spectrum and perhaps even bridge the gulf between work and play.
Today, many network-based or network-capable appliances run a flavor of the Linux kernel. It's a solid platform: cost-effective to deploy and support and readily accepted as a good design approach for deployment. The UI for such devices is often HTML-based and viewable with a PC or Mac browser. But not every appliance needs to be controlled by a general computing device. Consider a conventional appliance, such as a stove, microwave or bread maker. What if your household appliances were controlled by Android and boasted a color touch screen? With an Android UI on the stove-top, the author might even be able to cook something.

With the ever increasing use of mobile devices,  especially in developing countries like China and India,  we envision a new generation of applications that will change the ways that we work and live



Motivation

The use of mobile devices has penetrated almost every corner of our world. Many citizens of developing countries like China and India may have never used, let alone owned a personal computer, however now they are using mobile phones in their daily life to conduct businesses and communicate with their co-workers and family members. We envision the unique characteristics of mobile computing (e.g., location-based services) driving a new generation of applications that will change the ways that we work and live today.

One broad class of mobile applications is those that facilitate collaboration, and we imagine that such applications will have a large impact on the developing world. For example, in the developing world mobile collaboration technologies might help knowledge sharing among farmers, sales coordination among small commodity vendors, collaborative learning among village youth, and family-based health care monitoring for the elderly. As most users are not IT experts and they vary in many respects, such as language and technology literacy, one of the challenges is to design and develop consumable collaboration services that can be easily leveraged by the masses (e.g., illiterate users, farmers, and migrant workers alike). If we believe that voice communication and text messaging are the two most used mobile collaboration services today, one interesting question is what would be the next mass-consumable “killer” mobile collaboration service(s) and what factors (e.g., mobile technologies and national culture) would influence the development of such applications/services.

In addition to aiding collaboration between people who already know that they want to collaborate, another interesting area would be to leverage mobile devices to facilitate opportunistic collaboration, which is to help people identify collaboration opportunities unknown in advance. In many situations, people may not have sufficient knowledge about others whom they would like to connect and collaborate with. For example, an orange farmer may want to know about the side effect of applying a pest control substance to her orange grove; or a migrant worker may want to find a new employer to suit his preferred working schedule. However, they may not know where or whom they could get information from, especially when the information provided by a generic service is inadequate. Although researchers in the area of social recommender systems have started to tackle this problem, none of the existing efforts has taken into account the characteristics of mobile devices that would most likely used by people in such situations. For example, it would be interesting to explore whether one’s location information provided by mobile devices could facilitate opportunistic collaboration, and determine which other information provided by mobile devices could help but without sacrificing one’s privacy.

Not only do citizens of the developing world use mobile phones to connect with their fellow citizens, but they may also use mobile devices to communicate with people in the rest of the world. For example, a Chinese businessman in the fashion business may negotiate a contract with a U.S. retailer via mobile phone; and an African farmer may talk to a Chinese farming equipment supplier to arrange a shipment. However, cultural differences, including communication styles and language barriers, may prevent an effective collaboration between them. It would be interesting to examine the barriers systematically and explore innovative way to facilitate such cross-cultural collaboration via mobile devices.




Thinking back, it's hard to believe that with so many Android phones on the market today, that the first version of the Android OS was released only 3 years ago, but the full story starts a few years earlier.

It all began in October 2003 when Andy Rubin, Rich Miner, Nick Sears and Chris White founded Android Inc. in Palo Alto, California. Rubin was quoted by saying the purpose of Android was to allow "smarter mobile devices that are more aware of its owner's location and preferences", though at that time not much else was known about what type of phone software it would turn out to be.

Two years later, Android Inc. was acquired by Google in 2005 (though the amount has never been disclosed) and became a wholly owned subsidiary, but key employees were kept during the acquisition. In the two years that followed, the first Android SDK Beta was released to developers and phone manufactures. This was based on the Linux kernel to allow a flexible and upgradeable system. During this time, Google also helped form the Open Handset Alliance, along with a dozen other software and hardware companies, with the purpose to develop open standards for mobile phones.

Then in September 2008, the HTC Dream G1 was released by T-Mobile as the first device to run on theAndroid 1.0 operating system, which brought us the Android Market, full HTML web browser, GMail and E-Mail connectivity, as well as Google Contacts, Calendar, Maps, Sync, Search, and Media Player. The HTC Dream G1 featured a 3.2" display with 480x320 resolution, sliding QWERTY keyboard, 528MHz processor, 192MB of RAM, and a 3.2MP autofocus camera. 

Google's Android OS: Past, Present, and Future
In February 2009, the HTC Dream G1 was updated to Android 1.1, which added more details in Maps, a longer screen timeout in the dialer, and the ability to save message attachments.

By mid year, there was Android 1.5 Cupcake that added the all important desktop Widgets, on-screen keyboard, faster camera response with video recording, browser copy & paste, and being able to upload videos directly to YouTube. In September 2009, Android 1.6 Donut was released, though there was still only a handful of Android models on the market. Not only did it bring many bug fixes, but also expanded the Voice & Text Search capabilities to include bookmarks & history, contacts, the web, a new Text-to-Speech, support for WVGA displays, and also CDMA/EVDO cellular network support.

When Android 2.0 Eclair hit later in 2009, that's when things started to heat up. It was a more advanced and refined operating system, with updates to almost every aspect of the user interface, including multiple E-Mail accounts, Exchange support, new Browser interface, and Bluetooth 2.1 support. Not only that, but it is also when the originalMotorola DROID came to the market from Verizon Wireless. The device featured a 3.7" display with 480x854 resolution, EVDO Rev A for data, sliding QWERTY keyboard, 600MHz processor, 5MP autofocus camera, Wi-Fi and Bluetooth. This is also when we started to see many more Android devices being manufactured and sold world-wide. 

The next major release was Android 2.2 Froyo in the first half of 2010. This brought new internal optimizations to improve the overall speed, memory, and performance of the operating system. This, along with a new V8 JavaScript allowed the browser to work faster. We also saw an improved Application Launcher, more Widgets, USB tethering, Voice Dialing over Bluetooth, and Adobe Flash support in the Web Browser.

Later that year, Android 2.3 Gingerbread was announced, bring an updated user interface, support for larger and higher-resolution screens, improved power management, redesigned on-screen keyboard, enhanced copy/paste, support for Near Field Communications (NFC), audio effects in the music player, updated download manager, and support for more hardware sensors (gyroscope, barometer). It was then followed by service-updates to Android 2.3.3, 2.3.4 (voice/video chat in Google Talk), and 2.3.5 (for the Nexus S 4G).

Google has also spread its wings into the Tablet market as well. Even though there have been Tablets running Android 2.x since 2010, such as the Samsung Galaxy Tab, the newAndroid 3.0 Honeycomb operating system released in early 2011 is designed specifically for Tablets. The resigned holographic user interface still has an "Android feel" to it, and features a System Bar for accessing notifications, Action Bar, and Multitasking icon for bringing up a thumbnail view of open apps. There are also new desktop Widgets that were introduced in Honeycomb.

Android 2.3.x Gingerbread is still the latest iteration that is in currently available for Android smartphones today (mid-2011). Though the next version has already been announced: Android Ice Cream Sandwich, which is expected to combine elements of Gingerbread and Honeycomb together. Due for release later this year, little is know about it, but it will no longer require phones to have function buttons below the screen, as they will be on the bottom of the screen as icons (similar to how it is done in Honeycomb).

As of August 2011, Canalys research claims that 51.9 million Android devices shipped just in second quarter of this year (five times that of Q2 2010), which now accounts for 48% of all smartphones shipped world-wide. In the U.S. alone, Nielsen Ratings research found that 39% of smartphones were Android, followed by Apple's iOS at 28% and RIM's BlackBerry OS at 20%.