Friday, 30 March 2012

Example of using PopupWindow

android.widget.PopupWindow can be used to display an arbitrary view. The popup windows is a floating container that appears on top of the current activity.

Example of PopupWindow

Create /res/layout/popup.xml to define the view of the PopupWindow.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@android:color/background_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="1dp"
android:background="@android:color/darker_gray">
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="It's a PopupWindow" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<Button
android:id="@+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dismiss" />
</LinearLayout>
</LinearLayout>
</LinearLayout>


Main activity Java code to handle the PopupWindow
package com.exercise.AndroidPopupWindow;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;

public class AndroidPopupWindowActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);

Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});

popupWindow.showAsDropDown(btnOpenPopup, 50, -30);

}});
}
}


main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/openpopup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Open Popup Window" />

</LinearLayout>


Next:
- Disable outside PopupWindow, by setFocusable(true)

Related:
- PopupMenu, for Android 3.0(API Level 11)

Example of using PopupMenu

Android 3.0(API Level 11) provide android.widget.PopupMenu class, to displays a Menu in a modal popup window anchored to a View. The popup will appear below the anchor view if there is room, or above it if there is not. If the IME is visible the popup will not overlap it until it is touched. Touching outside of the popup will dismiss it.

Example of using PopupMenu

Create a file /res/menu/popupmenu.xml to define the PopupMenu.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/group_popupmenu">
<item android:id="@+id/menu1"
android:title="Popup menu item 1"/>
<item android:id="@+id/menu2"
android:title="Popup menu item 2"/>
<item android:id="@+id/menu3"
android:title="Popup menu item 3"/>
</group>
</menu>


Main Java code
package com.AndroidPopupMenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;

public class AndroidPopupMenuActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button button = (Button)findViewById(R.id.button);
TextView text = (TextView)findViewById(R.id.text);
ImageView image = (ImageView)findViewById(R.id.image);

button.setOnClickListener(viewClickListener);
text.setOnClickListener(viewClickListener);
image.setOnClickListener(viewClickListener);


}

OnClickListener viewClickListener
= new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showPopupMenu(v);
}

};

private void showPopupMenu(View v){
PopupMenu popupMenu = new PopupMenu(AndroidPopupMenuActivity.this, v);
popupMenu.getMenuInflater().inflate(R.menu.popupmenu, popupMenu.getMenu());

popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(AndroidPopupMenuActivity.this,
item.toString(),
Toast.LENGTH_LONG).show();
return true;
}
});

popupMenu.show();
}
}


Main layout, main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A Button"
/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A TextView"
/>
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher"
/>

</LinearLayout>


Related:
- PopupWindow

Thursday, 29 March 2012

New Guide for Enterprise Android Developers

A GUIDE TO MOBILIZING YOUR APPS
Timely execution of your company's mobile strategy means getting your development teams up to speed quickly on Android. In this step-by-step guide, you�ll find best practices for each stage of Android app development.

Topics include:
  • Best practices for each stage of mobile development
  • Enterprise-specific considerations such as security and systems integration
  • How to leverage the unique opportunities with mobility and mobile devices
  • Android development and testing tools
  • Deployment strategies

DOWNLOAD DEVELOPER GUIDE: Learn how developing mobile apps differs from desktop apps and what you can do to get up and running fast with Android app development for your enterprise.

Wednesday, 28 March 2012

Follow your Enemies on FaceBook?

Internet IconJust what we need, a FaceBook application for tracking your enemies? As if we already don't have too much personal information on the Net. Be afraid, be very afraid. Get the whole story on ReadWriteWeb.

Google Weather App

Last exercise demonstrate the basic of Google Weather API. It's modified to be a completed app with better look, with function of searching place.

Google Weather App

Main Java code:
package com.exercise.AndroidGoogleWeather;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class AndroidGoogleWeatherActivity extends Activity {

class ForecastInformation{
String city;
String postal_code;
String forecast_date;
String current_date_time;
String unit_system;
}

class CurrentConditions{
String condition;
String temp_f;
String temp_c;
String humidity;
String icon;
String wind_condition;
}

class ForecastConditions{
String day_of_week;
String low;
String high;
String icon;
String condition;
}

ForecastInformation forecastInformation;
CurrentConditions currentConditions;
List<ForecastConditions> forecastConditionsList;

Button buttonEnter;
EditText edittextPlace;
ImageView iconCurrent;
TextView textCurrent;
TextView textInfo;
ListView listForcast;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

buttonEnter = (Button)findViewById(R.id.enter);
edittextPlace = (EditText)findViewById(R.id.place);
iconCurrent = (ImageView)findViewById(R.id.iconcurrent);
textCurrent = (TextView)findViewById(R.id.textcurrent);
textInfo = (TextView)findViewById(R.id.textinfo);
listForcast = (ListView)findViewById(R.id.listforcast);

buttonEnter.setOnClickListener(EnterOnClickListener);

}

Button.OnClickListener EnterOnClickListener
= new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String place = edittextPlace.getText().toString();

String weatherString = QueryGoogleWeather(place);
Document weatherDoc = convertStringToDocument(weatherString);

if(parseGoogleWeather(weatherDoc)){
//Display Result
String c = currentConditions.condition + "\n"
+ currentConditions.temp_f + "f\n"
+ currentConditions.temp_c + "c\n"
+ currentConditions.humidity + "\n"
+ currentConditions.wind_condition + "\n";

textCurrent.setText(c);
Bitmap bm = LoadIcon(currentConditions.icon);
iconCurrent.setImageBitmap(bm);

textInfo.setText("city: " + forecastInformation.city + "\n"
+ "postal code: " + forecastInformation.postal_code + "\n"
+ "forecast date: " + forecastInformation.forecast_date + "\n"
+ "current date time: " + forecastInformation.current_date_time + "\n"
+ "unit: " + forecastInformation.unit_system);

listForcast.setAdapter(new MyCustomAdapter(
AndroidGoogleWeatherActivity.this,
R.layout.row,
forecastConditionsList));
}


}

};

public class MyCustomAdapter extends ArrayAdapter<ForecastConditions> {

public MyCustomAdapter(Context context, int textViewResourceId,
List<ForecastConditions> objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

LayoutInflater inflater=getLayoutInflater();
View row=inflater.inflate(R.layout.row, parent, false);
ImageView iconForecast = (ImageView)row.findViewById(R.id.iforecast);
TextView textForecast = (TextView)row.findViewById(R.id.tforecast);


textForecast.setText(
forecastConditionsList.get(position).day_of_week + "\n"
+ " - " + forecastConditionsList.get(position).condition + "\n"
+ forecastConditionsList.get(position).low + " ~ "
+ forecastConditionsList.get(position).high);

Bitmap bm = LoadIcon(forecastConditionsList.get(position).icon);
iconForecast.setImageBitmap(bm);

return row;
}

}

private Bitmap LoadIcon(String iconURL)
{
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
String image_URL = "http://www.google.com" + iconURL;

Bitmap bitmap = null;
InputStream in = null;
try {
in = OpenHttpConnection(image_URL);
bitmap = BitmapFactory.decodeStream(in, null, bmOptions);
in.close();
} catch (IOException e1) {
}
return bitmap;
}

private InputStream OpenHttpConnection(String strURL) throws IOException{
InputStream inputStream = null;
URL url = new URL(strURL);
URLConnection conn = url.openConnection();

try{
HttpURLConnection httpConn = (HttpURLConnection)conn;
httpConn.setRequestMethod("GET");
httpConn.connect();

if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
inputStream = httpConn.getInputStream();
}
}catch (Exception ex){
}
return inputStream;
}

private boolean parseGoogleWeather(Document srcDoc){

boolean result = false;

forecastInformation = new ForecastInformation();
currentConditions = new CurrentConditions();

//-- Get forecast_information
NodeList forecast_information = srcDoc.getElementsByTagName("forecast_information");
if (forecast_information.getLength() > 0){

//Assume place found if "forecast_information" exist
result = true;

NodeList infoChilds = forecast_information.item(0).getChildNodes();

for(int i=0; i<infoChilds.getLength(); i++){
Node n = infoChilds.item(i);

String nName = n.getNodeName();
String nValue
= n.getAttributes().getNamedItem("data").getNodeValue().toString();
if (nName.equalsIgnoreCase("city")){
forecastInformation.city = nValue;
}else if((nName.equalsIgnoreCase("postal_code"))){
forecastInformation.postal_code = nValue;
}else if((nName.equalsIgnoreCase("forecast_date"))){
forecastInformation.forecast_date = nValue;
}else if((nName.equalsIgnoreCase("current_date_time"))){
forecastInformation.current_date_time = nValue;
}else if((nName.equalsIgnoreCase("unit_system"))){
forecastInformation.unit_system = nValue;
}
}
}

//-- Get current_conditions
NodeList current_conditions = srcDoc.getElementsByTagName("current_conditions");
if(current_conditions.getLength()>0){
NodeList currentChilds = current_conditions.item(0).getChildNodes();

for(int i=0; i<currentChilds.getLength(); i++){
Node n = currentChilds.item(i);

String nName = n.getNodeName();
String nValue
= n.getAttributes().getNamedItem("data").getNodeValue().toString();
if (nName.equalsIgnoreCase("condition")){
currentConditions.condition = nValue;
}else if((nName.equalsIgnoreCase("temp_f"))){
currentConditions.temp_f = nValue;
}else if((nName.equalsIgnoreCase("temp_c"))){
currentConditions.temp_c = nValue;
}else if((nName.equalsIgnoreCase("humidity"))){
currentConditions.humidity = nValue;
}else if((nName.equalsIgnoreCase("icon"))){
currentConditions.icon = nValue;
}else if((nName.equalsIgnoreCase("wind_condition"))){
currentConditions.wind_condition = nValue;
}
}
}

//-- Get forecast_conditions
NodeList forecast_conditions = srcDoc.getElementsByTagName("forecast_conditions");
if (forecast_conditions.getLength()>0){
int forecast_conditions_length = forecast_conditions.getLength();

forecastConditionsList = new ArrayList<ForecastConditions>();

for(int j=0; j<forecast_conditions_length; j++){

ForecastConditions tmpForecastConditions = new ForecastConditions();

NodeList forecasrChilds = forecast_conditions.item(j).getChildNodes();

for(int i=0; i<forecasrChilds.getLength(); i++){

Node n = forecasrChilds.item(i);

String nName = n.getNodeName();
String nValue
= n.getAttributes().getNamedItem("data").getNodeValue().toString();

if (nName.equalsIgnoreCase("condition")){
tmpForecastConditions.condition = nValue;
}else if((nName.equalsIgnoreCase("day_of_week"))){
tmpForecastConditions.day_of_week = nValue;
}else if((nName.equalsIgnoreCase("low"))){
tmpForecastConditions.low = nValue;
}else if((nName.equalsIgnoreCase("high"))){
tmpForecastConditions.high = nValue;
}else if((nName.equalsIgnoreCase("icon"))){
tmpForecastConditions.icon = nValue;
}
}
forecastConditionsList.add(tmpForecastConditions);
}
}

return result;
}

private Document convertStringToDocument(String src){
Document dest = null;

DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder parser;

try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
Toast.makeText(AndroidGoogleWeatherActivity.this,
e1.toString(), Toast.LENGTH_LONG).show();
} catch (SAXException e) {
e.printStackTrace();
Toast.makeText(AndroidGoogleWeatherActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(AndroidGoogleWeatherActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
}

return dest;
}

private String QueryGoogleWeather(String p){

String uriPlace = Uri.encode(p);

String qResult = "";
String queryString = "http://www.google.com/ig/api?hl=en&weather=" + uriPlace;

HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(queryString);

try {
HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();

if (httpEntity != null){
InputStream inputStream = httpEntity.getContent();
Reader in = new InputStreamReader(inputStream);
BufferedReader bufferedreader = new BufferedReader(in);
StringBuilder stringBuilder = new StringBuilder();

String stringReadLine = null;

while ((stringReadLine = bufferedreader.readLine()) != null) {
stringBuilder.append(stringReadLine + "\n");
}

qResult = stringBuilder.toString();
}

} catch (ClientProtocolException e) {
e.printStackTrace();
Toast.makeText(AndroidGoogleWeatherActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(AndroidGoogleWeatherActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
}

return qResult;
}
}


main.xml layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/enter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="- Enter -"/>
<EditText
android:id="@+id/place"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:id="@+id/iconcurrent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<TextView
android:id="@+id/textcurrent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="center"/>

</LinearLayout>
<TextView
android:id="@+id/textinfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="@+id/listforcast"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>


row.xml, the row layout of the custom ListView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/iforecast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp" />
<TextView
android:id="@+id/tforecast"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>


You have to modify AndroidManifest.xml to grand permission of "android.permission.INTERNET"

Download the files.

Tuesday, 27 March 2012

Get Google Weather

It's another online weather info provided by Google:
http://www.google.com/ig/api?hl=en&weather=new%20york

Similar to Yahoo! Weather. It return weather information in XML format. It's a example to get New York weather from Google.

Get Google Weather

package com.exercise.AndroidGoogleWeather;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class AndroidGoogleWeatherActivity extends Activity {

class CurrentConditions{
String condition;
String temp_f;
String temp_c;
String humidity;
String icon;
String wind_condition;
}

class ForecastConditions{
String day_of_week;
String low;
String high;
String icon;
String condition;
}

CurrentConditions currentConditions;
List<ForecastConditions> forecastConditionsList;

TextView tvCurrentConditions;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tvCurrentConditions = (TextView)findViewById(R.id.currentconditions);

String weatherString = QueryGoogleWeather();
Document weatherDoc = convertStringToDocument(weatherString);
parseGoogleWeather(weatherDoc);

//Display Result
String s = "\n"
+ currentConditions.condition + "\n"
+ currentConditions.temp_f + "\n"
+ currentConditions.temp_c + "\n"
+ currentConditions.humidity + "\n"
+ currentConditions.icon + "\n"
+ currentConditions.wind_condition + "\n";

for(int k=0; k < 4; k++){
s += "\n"
+ forecastConditionsList.get(k).condition + "\n"
+ forecastConditionsList.get(k).day_of_week + "\n"
+ forecastConditionsList.get(k).low + "\n"
+ forecastConditionsList.get(k).high + "\n"
+ forecastConditionsList.get(k).icon + "\n";
}

tvCurrentConditions.setText(s);

}

private void parseGoogleWeather(Document srcDoc){

currentConditions = new CurrentConditions();

//-- Get current_conditions
NodeList current_conditions = srcDoc.getElementsByTagName("current_conditions");
NodeList currentChilds = current_conditions.item(0).getChildNodes();

for(int i=0; i<currentChilds.getLength(); i++){
Node n = currentChilds.item(i);

String nName = n.getNodeName();
String nValue
= n.getAttributes().getNamedItem("data").getNodeValue().toString();
if (nName.equalsIgnoreCase("condition")){
currentConditions.condition = nValue;
}else if((nName.equalsIgnoreCase("temp_f"))){
currentConditions.temp_f = nValue;
}else if((nName.equalsIgnoreCase("temp_c"))){
currentConditions.temp_c = nValue;
}else if((nName.equalsIgnoreCase("humidity"))){
currentConditions.humidity = nValue;
}else if((nName.equalsIgnoreCase("icon"))){
currentConditions.icon = nValue;
}else if((nName.equalsIgnoreCase("wind_condition"))){
currentConditions.wind_condition = nValue;
}
}

//-- Get forecast_conditions
NodeList forecast_conditions = srcDoc.getElementsByTagName("forecast_conditions");
int forecast_conditions_length = forecast_conditions.getLength();

forecastConditionsList = new ArrayList<ForecastConditions>();

for(int j=0; j<forecast_conditions_length; j++){

ForecastConditions tmpForecastConditions = new ForecastConditions();

NodeList forecasrChilds = forecast_conditions.item(j).getChildNodes();

for(int i=0; i<forecasrChilds.getLength(); i++){

Node n = forecasrChilds.item(i);

String nName = n.getNodeName();
String nValue
= n.getAttributes().getNamedItem("data").getNodeValue().toString();

if (nName.equalsIgnoreCase("condition")){
tmpForecastConditions.condition = nValue;
}else if((nName.equalsIgnoreCase("day_of_week"))){
tmpForecastConditions.day_of_week = nValue;
}else if((nName.equalsIgnoreCase("low"))){
tmpForecastConditions.low = nValue;
}else if((nName.equalsIgnoreCase("high"))){
tmpForecastConditions.high = nValue;
}else if((nName.equalsIgnoreCase("icon"))){
tmpForecastConditions.icon = nValue;
}

}

forecastConditionsList.add(tmpForecastConditions);

}


}

private Document convertStringToDocument(String src){
Document dest = null;

DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder parser;

try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
Toast.makeText(AndroidGoogleWeatherActivity.this,
e1.toString(), Toast.LENGTH_LONG).show();
} catch (SAXException e) {
e.printStackTrace();
Toast.makeText(AndroidGoogleWeatherActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(AndroidGoogleWeatherActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
}

return dest;
}

private String QueryGoogleWeather(){
String qResult = "";
String queryString = "http://www.google.com/ig/api?hl=en&weather=new%20york";

HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(queryString);

try {
HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();

if (httpEntity != null){
InputStream inputStream = httpEntity.getContent();
Reader in = new InputStreamReader(inputStream);
BufferedReader bufferedreader = new BufferedReader(in);
StringBuilder stringBuilder = new StringBuilder();

String stringReadLine = null;

while ((stringReadLine = bufferedreader.readLine()) != null) {
stringBuilder.append(stringReadLine + "\n");
}

qResult = stringBuilder.toString();
}

} catch (ClientProtocolException e) {
e.printStackTrace();
Toast.makeText(AndroidGoogleWeatherActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(AndroidGoogleWeatherActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
}

return qResult;
}
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/currentconditions"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>
</LinearLayout>


You have to modify AndroidManifest.xml to grand permission of "android.permission.INTERNET"

Download the files.

Next:
- Google Weather App

Related:
- Get weather info from Yahoo! Weather RSS Feed.
- Get description from Yahoo! Weather RSS feed, and display in WebView.

Monday, 26 March 2012

Search WOEID from http://query.yahooapis.com/

In previous exercises "Get weather info from Yahoo! Weather RSS Feed" and "Get description from Yahoo! Weather RSS feed, and display in WebView", I search Yahoo Weather with fixed WOEID. How can I know the WOEID of a certain place? Yahoo provide a web service to search WOEID.

Here is a example for "new york", you can get the woeid from the returned xml.
http://query.yahooapis.com/v1/public/yql?q=select*from%20geo.places%20where%20text=%22New%20York%22&format=xml

www.yahooapis.com

It's a example to list the woeid(s) from the returned xml from query.yahooapis.com. Enter the place you want to search in the TextView, and click the "Search WOEID by place" button. The query will be sent to http://query.yahooapis.com/ with expected place, and the returned xml will be parsed, and the woeid(s) will be listed.

Search WOEID from http://query.yahooapis.com/

package com.exercise.AndroidSearchWOEID;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class AndroidSearchWOEIDActivity extends Activity {

//Example for "New York"
//http://query.yahooapis.com/v1/public/yql?q=select*from geo.places where text="New York"&format=xml
final String yahooapisBase = "http://query.yahooapis.com/v1/public/yql?q=select*from%20geo.places%20where%20text=";
final String yahooapisFormat = "&format=xml";
String yahooAPIsQuery;

EditText place;
Button search;
ListView listviewWOEID;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

place = (EditText)findViewById(R.id.place);
search = (Button)findViewById(R.id.search);
listviewWOEID = (ListView)findViewById(R.id.woeidlist);

search.setOnClickListener(searchOnClickListener);
}

Button.OnClickListener searchOnClickListener
= new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
if(place.getText().toString().equals("")){
Toast.makeText(getBaseContext(),
"Enter place!",
Toast.LENGTH_LONG).show();
}else{
ArrayList<String> l = QueryYahooAPIs();

ArrayAdapter<String> aa = new ArrayAdapter<String>(
getBaseContext(), android.R.layout.simple_list_item_1, l);

listviewWOEID.setAdapter(aa);
}
}

};

private ArrayList<String> QueryYahooAPIs(){

String uriPlace = Uri.encode(place.getText().toString());

yahooAPIsQuery = yahooapisBase
+ "%22" + uriPlace + "%22"
+ yahooapisFormat;

String woeidString = QueryYahooWeather(yahooAPIsQuery);
Document woeidDoc = convertStringToDocument(woeidString);
return parseWOEID(woeidDoc);

}

private ArrayList<String> parseWOEID(Document srcDoc){

ArrayList<String> listWOEID = new ArrayList<String>();

NodeList nodeListDescription = srcDoc.getElementsByTagName("woeid");
if(nodeListDescription.getLength()>=0){
for(int i=0; i<nodeListDescription.getLength(); i++){
listWOEID.add(nodeListDescription.item(i).getTextContent());
}
}else{
listWOEID.clear();
}

return listWOEID;
}

private Document convertStringToDocument(String src){
Document dest = null;

DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder parser;

try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
Toast.makeText(getBaseContext(),
e1.toString(), Toast.LENGTH_LONG).show();
} catch (SAXException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(),
e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(),
e.toString(), Toast.LENGTH_LONG).show();
}

return dest;

}

private String QueryYahooWeather(String queryString){

String qResult = "";

HttpClient httpClient = new DefaultHttpClient();

//return Uri.encode(queryString);

HttpGet httpGet = new HttpGet(queryString);

try {
HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();

if (httpEntity != null){
InputStream inputStream = httpEntity.getContent();
Reader in = new InputStreamReader(inputStream);
BufferedReader bufferedreader = new BufferedReader(in);
StringBuilder stringBuilder = new StringBuilder();

String stringReadLine = null;

while ((stringReadLine = bufferedreader.readLine()) != null) {
stringBuilder.append(stringReadLine + "\n");
}

qResult = stringBuilder.toString();
}

} catch (ClientProtocolException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
}

return qResult;

}

}


main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<EditText
android:id="@+id/place"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Search WOEID by place" />
<ListView
android:id="@+id/woeidlist"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

</LinearLayout>


You have to modify AndroidManifest.xml to grand permission of "android.permission.INTERNET"

Download the files.

Sunday, 25 March 2012

iPad 3/new iPad One Week Review

iPhone iPad pictureWell it has been about a week with the new iPad, here are my impressions.



Retina Display

It does indeed look great. But not "that" great. I still think my old iPad looks pretty good. Also, some web sites are freaking microscopic on this thing. There does not seem to be a simple way to make the default view for all web pages a 110% or 120% zoom level. This is a great feature on Safari, Chrome, and Firefox on the desktop. You can use the built in Accessibility Zoom feature to help with this. But I feel like this make web browsing so much clunkier.



Voice Dictation

Yes, you have have voice dictation available any place you can use a keyboard. It seems to work very well. This seems like a big deal and I don't remember it getting much coverage in the media. This is much bigger than full Siri support if you ask me.



Wifi Hotspot

In the US, you can make your iPad into a Wifi hotspot if you get the Verizon 4G version. Sure my iPhone can do this too. But not nearly as long as it has a lot less batteries in it. AT&T is not supporting this feature and has no ETA for its availability. (Complete madness! They must have known for months about the feature. Not to offer it and then no ETA. Unbelievable!) Originally, I purchased an AT&T 4G iPad, only to find out on launch day this feature would not work. But fear not, you can take your crappy AT&T 4G iPad to an Apple store and exchange it for a Verizon version. That is exactly what I did.



So far so good. More updates to come.

Get description from Yahoo! Weather RSS feed, and display in WebView.

Last exercise "Get weather info from Yahoo! Weather RSS Feed" get information from Yahoo! Weather RSS feed, and display in simple text form. Inside the returned feed, there are elements with Tag Name of "description". The second one is in html coded form.

example:
<description>
<![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/26.gif"/><br /> <b>Current Conditions:</b><br /> Cloudy, 47 F<BR /> <BR /><b>Forecast:</b><BR /> Sun - Few Showers. High: 57 Low: 47<br /> Mon - Sunny/Wind. High: 53 Low: 30<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/New_York__NY/*http://weather.yahoo.com/forecast/USNY0996_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/> (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]>
</description>


This example demonstrate how to retrieve description elements from Yahoo! Weather RSS feed, and display on a WebView.

Get description from Yahoo! Weather RSS feed, and display in WebView.

package com.exercise.AndroidYahooWeatherDOM;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Toast;

public class AndroidYahooWeatherDOMActivity extends Activity {

WebView webView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//weather = (TextView)findViewById(R.id.weather);
webView = (WebView)findViewById(R.id.webview);

String weatherString = QueryYahooWeather();
Document weatherDoc = convertStringToDocument(weatherString);

String weatherResult = parseWeatherDescription(weatherDoc);
webView.loadData(weatherResult, "text/html", "UTF-8");

}
private String parseWeatherDescription(Document srcDoc){
String weatherDescription="";

NodeList nodeListDescription = srcDoc.getElementsByTagName("description");
if(nodeListDescription.getLength()>=0){
for(int i=0; i<nodeListDescription.getLength(); i++){
weatherDescription += nodeListDescription.item(i).getTextContent()+"<br/>";
}
}else{
weatherDescription = ("No Description!");
}

return weatherDescription;
}

private Document convertStringToDocument(String src){
Document dest = null;

DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder parser;

try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this,
e1.toString(), Toast.LENGTH_LONG).show();
} catch (SAXException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
}

return dest;
}

private String QueryYahooWeather(){

String qResult = "";
String queryString = "http://weather.yahooapis.com/forecastrss?w=2459115";

HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(queryString);

try {
HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();

if (httpEntity != null){
InputStream inputStream = httpEntity.getContent();
Reader in = new InputStreamReader(inputStream);
BufferedReader bufferedreader = new BufferedReader(in);
StringBuilder stringBuilder = new StringBuilder();

String stringReadLine = null;

while ((stringReadLine = bufferedreader.readLine()) != null) {
stringBuilder.append(stringReadLine + "\n");
}

qResult = stringBuilder.toString();
}

} catch (ClientProtocolException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
}

return qResult;
}
}


Modify main.xml to add a WebView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

</LinearLayout>



You have to modify AndroidManifest.xml to grand permission of "android.permission.INTERNET"

Download the files.


Related:
- Search WOEID from http://query.yahooapis.com/.
- Get Google Weather

Saturday, 24 March 2012

HP ENVY 14-3017nr Spectre 14.0" Laptops Review, Space and Price

HP ENVY 14-3017nr Spectre
HP one of the welk-know notebook maker has announced the lauch of its new laptops namely, HP ENVY 14-3017nr Spectre. The ENVY 14-3017nr uniquely sets itself apart from the ultrabook crowd. Its lid, display, palm rest, and trackpad are all made of extremely durable and scratch-resistant Gorilla Glass, while Beats Audio, HP Wireless Audio, Intel Wireless Display (WiDi), and a 14-inch HP Radiance display pump up your multimedia options.

The Spectre also boasts enough multimedia features to make it your entertainment hub. With WiDi, you can mirror your desktop by streaming your favorite PC and online content to your HDTV or monitor (separate adapter required). HDMI connectivity lets you watch movies on your TV for a home-theater feel, and you get top-notch sound to match with crystal-clear and bass-heavy Beats Audio. And for those times you want to listen in other rooms, built-in HP Wireless Audio lets you stream your tunes to up to four external devices.

The Spectre is powered by the Intel Core i5 processor with Turbo Boost and 4 GB of RAM to give you plenty of speed and smooth efficiency for multitasking. Enhancing that is a 128 GB solid state drive that enables faster bootup and shutdown times compared to traditional hard disk drives. And when you need to keep working and playing when the lights go down, a backlit keyboard with individual LEDS under each key gives you maximum brightness. It also lights up row by row when you approach and dims down when you're away to save power. The details related to the specs of the device are discussed below.HP ENVY 14-3017nr SpectreHP ENVY 14-3017nr Spectre 14.0" laptops Specification :
  • DISPLAY : 14.0 in diagonal Radiance HD Infinity LED-backlit (1600 x 900)
  • PROCESSOR : Intel Core i5-2467M 1.60 GHz with Turbo Boost Technology up to 2.30 GHz MEMORY : 4 GB DDR3 1333 MHz
  • HARD DRIVE SIZE : 128 GB SSD
  • OPERATING SYSTEM : Windows 7 Home Premium PC
  • DRIVE : SD/MMC
  • AUDIO : Beats Audio and HP Wireless Audio
  • VIDEO : Intel HD Graphics 3000 with shared graphics memory
  • PORTS :
  • 1 USB 3.0
  • � 1 USB 2.0
  • � HDMI
  • � Headphone output/Microphone input combo
  • � RJ-45 (10/100/1000)
  • � Mini DisplayPort
  • BATTERY : 6-cell lithium-ion (up to 9.5 hours)*
  • CAMERA : HP TrueVision HD webcam with integrated digital microphone
  • WIRELESS : 802.11a/g/n
  • � Intel Wireless Display (WiDi) capable (separate adapter required)
  • BLUETOOTH : Yes
  • DIMENSIONS : 12.88 x 8.70 x 0.79 in (327.15 x 220.98 x 20.06 mm)
  • WEIGHT : 3.97 lbs (1.80 kg)

Price Range : $1,399.00 [microsoftstore.com]


Friday, 23 March 2012

Get weather info from Yahoo! Weather RSS Feed

The Yahoo! Weather RSS feed enables you to get up-to-date weather information, http://developer.yahoo.com/weather/.

The Weather RSS feed request follows simple HTTP GET syntax: start with a base URL and then add parameters and values after a question mark (?).

ex: Weather RSS feed for New York
http://weather.yahooapis.com/forecastrss?w=2459115

where 2459115 is WOEID for New York. You can find the code for any location from http://weather.yahoo.com/.

The another exercise show how to Search WOEID from http://query.yahooapis.com/.

The returned XML will like it:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>

<title>Yahoo! Weather - New York, NY</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/New_York__NY/*http://weather.yahoo.com/forecast/USNY0996_f.html</link>
<description>Yahoo! Weather for New York, NY</description>
<language>en-us</language>
<lastBuildDate>Fri, 23 Mar 2012 8:49 pm EDT</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="New York" region="NY" country="United States"/>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
<yweather:wind chill="60" direction="0" speed="0" />
<yweather:atmosphere humidity="49" visibility="10" pressure="30.08" rising="0" />
<yweather:astronomy sunrise="6:52 am" sunset="7:10 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url>
</image>
<item>
<title>Conditions for New York, NY at 8:49 pm EDT</title>
<geo:lat>40.71</geo:lat>
<geo:long>-74.01</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/New_York__NY/*http://weather.yahoo.com/forecast/USNY0996_f.html</link>
<pubDate>Fri, 23 Mar 2012 8:49 pm EDT</pubDate>
<yweather:condition text="Fair" code="33" temp="60" date="Fri, 23 Mar 2012 8:49 pm EDT" />
<description><![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/33.gif"/><br />
<b>Current Conditions:</b><br />
Fair, 60 F<BR />
<BR /><b>Forecast:</b><BR />
Fri - Mostly Cloudy. High: 72 Low: 52<br />
Sat - PM Showers. High: 61 Low: 49<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/New_York__NY/*http://weather.yahoo.com/forecast/USNY0996_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]></description>
<yweather:forecast day="Fri" date="23 Mar 2012" low="52" high="72" text="Mostly Cloudy" code="27" />
<yweather:forecast day="Sat" date="24 Mar 2012" low="49" high="61" text="PM Showers" code="39" />
<guid isPermaLink="false">USNY0996_2012_03_24_7_00_EDT</guid>
</item>
</channel>
</rss>
<!-- api1.weather.sg1.yahoo.com compressed/chunked Fri Mar 23 18:50:03 PDT 2012 -->


Yahoo! Weather RSS Feed

It's a example to get Get weather info from Yahoo! Weather RSS Feed. Query Yahoo using HttpGet, then parse the returned XML using DOM. Please note that I only parse the returned RSS partially for demonstration, NOT ALL.

Get weather info from Yahoo! Weather RSS Feed

package com.exercise.AndroidYahooWeatherDOM;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class AndroidYahooWeatherDOMActivity extends Activity {

TextView weather;

class MyWeather{
String description;
String city;
String region;
String country;

String windChill;
String windDirection;
String windSpeed;

String sunrise;
String sunset;

String conditiontext;
String conditiondate;

public String toString(){

return "\n- " + description + " -\n\n"
+ "city: " + city + "\n"
+ "region: " + region + "\n"
+ "country: " + country + "\n\n"

+ "Wind\n"
+ "chill: " + windChill + "\n"
+ "direction: " + windDirection + "\n"
+ "speed: " + windSpeed + "\n\n"

+ "Sunrise: " + sunrise + "\n"
+ "Sunset: " + sunset + "\n\n"

+ "Condition: " + conditiontext + "\n"
+ conditiondate +"\n";

}
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
weather = (TextView)findViewById(R.id.weather);


String weatherString = QueryYahooWeather();
Document weatherDoc = convertStringToDocument(weatherString);

MyWeather weatherResult = parseWeather(weatherDoc);
weather.setText(weatherResult.toString());
}

private MyWeather parseWeather(Document srcDoc){

MyWeather myWeather = new MyWeather();

//<description>Yahoo! Weather for New York, NY</description>
myWeather.description = srcDoc.getElementsByTagName("description")
.item(0)
.getTextContent();

//<yweather:location city="New York" region="NY" country="United States"/>
Node locationNode = srcDoc.getElementsByTagName("yweather:location").item(0);
myWeather.city = locationNode.getAttributes()
.getNamedItem("city")
.getNodeValue()
.toString();
myWeather.region = locationNode.getAttributes()
.getNamedItem("region")
.getNodeValue()
.toString();
myWeather.country = locationNode.getAttributes()
.getNamedItem("country")
.getNodeValue()
.toString();

//<yweather:wind chill="60" direction="0" speed="0"/>
Node windNode = srcDoc.getElementsByTagName("yweather:wind").item(0);
myWeather.windChill = windNode.getAttributes()
.getNamedItem("chill")
.getNodeValue()
.toString();
myWeather.windDirection = windNode.getAttributes()
.getNamedItem("direction")
.getNodeValue()
.toString();
myWeather.windSpeed = windNode.getAttributes()
.getNamedItem("speed")
.getNodeValue()
.toString();

//<yweather:astronomy sunrise="6:52 am" sunset="7:10 pm"/>
Node astronomyNode = srcDoc.getElementsByTagName("yweather:astronomy").item(0);
myWeather.sunrise = astronomyNode.getAttributes()
.getNamedItem("sunrise")
.getNodeValue()
.toString();
myWeather.sunset = astronomyNode.getAttributes()
.getNamedItem("sunset")
.getNodeValue()
.toString();

//<yweather:condition text="Fair" code="33" temp="60" date="Fri, 23 Mar 2012 8:49 pm EDT"/>
Node conditionNode = srcDoc.getElementsByTagName("yweather:condition").item(0);
myWeather.conditiontext = conditionNode.getAttributes()
.getNamedItem("text")
.getNodeValue()
.toString();
myWeather.conditiondate = conditionNode.getAttributes()
.getNamedItem("date")
.getNodeValue()
.toString();

return myWeather;
}

private Document convertStringToDocument(String src){
Document dest = null;

DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder parser;

try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this,
e1.toString(), Toast.LENGTH_LONG).show();
} catch (SAXException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
}

return dest;
}

private String QueryYahooWeather(){

String qResult = "";
String queryString = "http://weather.yahooapis.com/forecastrss?w=2459115";

HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(queryString);

try {
HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();

if (httpEntity != null){
InputStream inputStream = httpEntity.getContent();
Reader in = new InputStreamReader(inputStream);
BufferedReader bufferedreader = new BufferedReader(in);
StringBuilder stringBuilder = new StringBuilder();

String stringReadLine = null;

while ((stringReadLine = bufferedreader.readLine()) != null) {
stringBuilder.append(stringReadLine + "\n");
}

qResult = stringBuilder.toString();
}

} catch (ClientProtocolException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this,
e.toString(), Toast.LENGTH_LONG).show();
}

return qResult;
}
}


main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/weather"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>

</LinearLayout>


You have to modify AndroidManifest.xml to grand permission of "android.permission.INTERNET"

Download the files.

Next:
- Get description from Yahoo! Weather RSS feed, and display in WebView.
- Search WOEID from http://query.yahooapis.com/.
- Get Google Weather

Samsung Series 9 900X3B-A02 13.3" Laptops Review, Specs and Price

new Samsung Series 9 900X3B-A02Samsung is going to launch its new laptops namely, Samsum Series 9 900X3B-A02. The Series 9 which has powered by features13.3-inch notebook is one of the thinnest, lightest, and most elegantly designed notebooks you'll find. It's an amazing half-inch thick and has been updated with a sandblasted aluminum finish (forget about scratches and fingerprints) and has a 1600 x 900 resolution display that delivers outstanding vibrancy and sharpness with wide viewing angles.

The Series 9 was already a winning combination of form and function, but Samsung raised the bar even higher with this updated version. It's lighter and slimmer than its predecessor at 0.51 inches and 2.5 pounds, down from 0.64 and 2.8. It also fits its 13.3-inch display into a 12-inch frame to give you more screen for edge-to-edge views. And that's where this PC really shines�the display's 1600 x 900 gives you excellent picture quality in a PC this size, perfect for viewing everything from photos to movies to work documents. Reflections are also kept to a minimum thanks to a matte finish.

Performance-wise, the Intel Core i5 processor with Turbo Boost and 4 GB of RAM easily handle heavy loads of work and play. Multimedia options are equally solid with Intel Wireless Display which lets you stream PC content to a monitor or big-screen TV (separate adapter required), and Micro HDMI for watching movies on your HDTV. Portability is further enhanced with up to seven hours of battery life* which will keep you going on long flights and jam-packed days of meetings and classes. And, with Samsung's Battery Life Plus technology, the battery will retain 80 percent of its original capacity for up to 1,500 charges�up to five times more than other notebooks. The details related to the specs of the device are discussed below.Samsung Series 9 900X3B-A02

Samsung Series 9 900X3B-A02 13.3" Laptops Specification :
  • DISPLAY : 13.3 in LED backlit (1600 x 900)
  • PROCESSOR : Intel Core i5-2467M 1.60 GHz with Turbo Boost Technology up to 2.30 GHz MEMORY : 4 GB DDR3 1333 MHz HARD
  • DRIVE SIZE : 128 GB SSD
  • OPERATING SYSTEM : Windows 7 Home Premium PC
  • MEDIA DRIVE : 4-in-1 memory card reader
  • AUDIO : Integrated audio
  • VIDEO : Intel HD Graphics 3000 with shared graphics memory
  • PORTS :
  • � 1 USB 3.0
  • � 1 USB 2.0
  • � Micro HDMI
  • � Headphone output/Microphone input combo
  • � VGA
  • � RJ-45 (10/100/1000 via included dongle)
  • BATTERY : 6-cell lithium-polymer (up to 7 hours)*
  • CAMERA : Integrated webcam
  • WIRELESS : 802.11a/b/g/n
  • � Intel Wireless Display (WiDi) capable (separate adapter required)
  • BLUETOOTH : Yes
  • DIMENSIONS : 12.40 x 8.60 x 0.51 in (314.96 x 218.44 x 12.95 mm)
  • WEIGHT : 2.56 lbs (1.16 kg)
Price Range : $1,399.00 [microsoftstore.com]

Thursday, 22 March 2012

SDK Tools and ADT updated revision 17

Updated SDK Tools and ADT revision 17, with a lot of new features and bug fixes in various areas such as Lint, the build system as well as the emulator.

Details: Android Developers BLog - http://android-developers.blogspot.com/2012/03/updated-sdk-tools-and-adt-revision-17.html

Sony VAIO VPCYB33KX/S 11.6 Inch Laptop Review, Specs ans Price

new Sony VAIO VPCSE23FX/S
Sony one of the well-known laptop maker has announced the launch of its new notebook namely, Sony VAIO VPCYB33KX/S. The VAIO VPCYB33KX/S has powered by features a 1.65 GHz AMD processor with up to 2GB of system memory ensuring your notebook will faster and smoothly when you runs more than an applications at the same time. The new mobility computer packs an integrate web camera with built-in microphone allow you see and hear together whenever you make online chat with your friends.

Also Sony VAIO VPCYB33KX/S Notebook PC is sports a 11.6" widescreen display that provides 1366 x 768 pixels resolution with LED technology for saving energy and save your money on electric bills. It is powered by an Mobile AMD Duron processor at 1.65 GHz, up to 2GB of system memory, 320GB hard drive and Genuine Windows 7 Home Premium 64-bit OS pre-installed. For more details go through the below mentioned points.Sony VAIO VPCSE23FX/SSony VAIO VPCSE23FX/S 15.5 Inch Laptop Specification :
  • 2.5GHz Intel Core i5-2450M Dual-Core
  • 4GB of DDR3 RAM (Onboard)
  • 640GB Hard Drive (5400rpm)
  • AMD Radeon HD 6470M Graphics (512MB)
  • 15.5" HD IPS LED-Backlit Display
  • 1920 x 1080 Native Resolution
  • SuperMulti DVD Burner
  • 802.11b/g/n Wi-Fi, Bluetooth 2.1+EDR
  • Integrated Webcam & Microphone
  • Windows 7 Home Premium (64-bit)

Price Range : $999.99 [on Amazon]

Wednesday, 21 March 2012

AndEngine - FREE 2D OpenGL Game Engine for Android platform

AndEngine
AndEngine is a free Open Source 2D OpenGL Game Engine for the Android platform.

Website: http://www.andengine.org/

Try it on your Android device by installing AndEngine - Examples in Google Play, the application contains various Examples that showcase what developers can do with this engine.

Install this to stay tuned with the progress.

Join the AndEngine-Community at:
http://www.andengine.org/forums/


AndEngine - Examples

Create your own app. No coding required - with Andromo

With Andromo, anyone can make a pro-quality Android app. There's no programming required, plus Andromo generates 100% pure native Android apps. Use your app to promote your business, share events and news, or launch your million dollar idea. It's quick, easy and free.

http://andromo.com/


Create Android Apps for Free with Andromo from Indigo Rose Software on Vimeo.




Asus Zenbook UX31E-ESL8 Laptop Review, Specs and Price

new ASUS Zenbook UX31E-ESL8



Asus one of the well-known laptops maker has announced the launch of its new notebook namely, Asus Zenbook UX31E-ESL8 . The ZENBOOK UX31E 13.3-inch ultrabook is a PC that's hard to top in the looks department. Its strong but light aluminum body is accentuated by a unique "spun" finish on its polished surfaces, and it's a razor-thin 0.70 inches thick and weighs just 2.9 pounds.

The Asus UX31E is comfortable to use with an oversized chiclet-style keyboard and glass, click-anywhere touchpad. It comes with the second-generation Intel Core i5 processor for powerful and speedy system performance, and a 128 GB solid state drive that gives you durable storage, faster boot-up times, and quicker application launching. Audio is supplied by Bang & Olufsen's renowned ICEpower, which delivers deep bass and clear, natural sound with less background noise. The details related to the specs of the device are discussed below.ASUS Zenbook UX31E-ESL8

Asus ZENBOOK UX31E-ESL8 Laptops Specification :
  • PROCESSOR : Intel Core i5-2467M 1.60 GHz
  • DISPLAY : 13.3 in LED (1600 x 900)
  • MEMORY : 4 GB DDR3 1333 MHz HARD
  • DRIVE SIZE : 128 GB SSD
  • OPERATING SYSTEM : Windows 7 Home Premium
  • MEDIA DRIVE : 4-in-1 memory card reader
  • AUDIO : Bang & Olufsen ICEpower
  • VIDEO : Intel HD Graphics 3000 with shared graphics memory
  • PORTS :
    � 1 USB 3.0
    � 1 USB 2.0
    � Micro HDMI
    � Headphone output
    � Mini VGA via included Mini VGA to VGA adapter
    � RJ-45 via included USB to RJ-45 dongle
  • BATTERY : Lithium-polymer, 50Whr (6.5 hours)*
  • CAMERA : Integrated 0.3 MP webcam
  • WIRELESS : 802.11b/g/n
  • BLUETOOTH : Yes
  • DIMENSIONS : 12.80 x 8.80 x 0.70 in (325.12 x 223.52 x 17.78 mm)
  • WEIGHT : 2.90 lbs (1.31 kg)

Price Range : $1,099.00 [on microsoftstore.com]

Tuesday, 20 March 2012

Programming Your Home: Automate with Arduino, Android, and Your Computer


In Programming Your Home, technology enthusiast Mike Riley walks you through a variety of custom home automation projects, ranging from a phone application that alerts you to package deliveries at your front door to an electronic guard dog that will prevent unwanted visitors.

Open locked doors using your smartphone. Assemble a bird feeder that posts Twitter tweets to tell you when the birds are feeding or when bird seed runs low. Have your home speak to you when you receive email or tell you about important events such as the arrival of visitors, and much more!

You'll learn how to use Android smartphones, Arduinos, X10 controllers and a wide array of sensors, servos, programming languages, web frameworks and mobile SDKs. Programming Your Home is written for smartphone programmers, web developers, technology tinkerers, and anyone who enjoys building cutting-edge, Do-It-Yourself electronic projects.

This book will give you the inspiration and understanding to construct amazing automation capabilities that will transform your residence into the smartest home in your neighborhood!

What You Need:

To get the most out of Programming Your Home, you should have some familiarity with the Arduino hardware platform along with a passion for tinkering. You should enjoy innovative thinking and learning exercises as well as have some practical application development experience. The projects use a variety of hardware components including sensors and actuators, mobile devices, and wireless radios, and we'll even tell you where you can get them.