Monday, 18 June 2012

Microsoft announces Surface Tablet

Microsoft Logo

Well the big Microsoft announcement is here, and what do we find behind the curtain... a tablet! (see details on the Verge) The Microsoft Surface is a 10.6 widescreen tablet with an optional keyboard cover (very slick). Unlike most tablets, it is running Windows 8 on Intel chips. So what was missing from the be launch event?



Price

Microsoft stated the new tablet would be priced competitively with other ultrabook offerings. That is very interesting given that you can get an iPad starting at $399 and most ultrabooks cost around $999. If the device is overpriced I just don't see it selling.



Voice

No mention of a Siri type agent or anything like that. That would seem to be a big oversight.



Battery Life

Running Intel chips, one wonders what the battery life will be. But given that the new Macbook Air runs for about 7 hrs on battery, I would think this is probably not gonna be an issue.



Summary

An interesting device. Will it dethrone the iPad, probably not. Will we get some slick keyboard covers for our iPads? Hopefully!


Firefox coming to the iPad

Firefox Logo

Well not Firefox exactly, but the Verge has a story that the Mozilla foundation is working on a browser for the Ipdad. Based on the article, this sounds very interesting.



Tablet browsers could use a rethink. It seems like gestures usage could be a whole lot better. Their idea of combining tabs with browser history also seems to have some merit. I'm looking forward to at seeing what they come up with.

Sunday, 17 June 2012

Split Action Bar for Android 4

The old article demonstrate how to "Create ActionBar using XML" for Android 3.

When your application is running on Android 4.0 (API level 14) and higher, there's an extra mode available for the action bar called "split action bar." When you enable split action bar, a separate bar appears at the bottom of the screen to display all action items when the activity is running on a narrow screen (such as a portrait-oriented handset). Splitting the action bar to separate the action items ensures that a reasonable amount of space is available to display all your action items on a narrow screen, while leaving room for navigation and title elements at the top.

To enable split action bar, simply add uiOptions="splitActionBarWhenNarrow" to your <activity> or <application> manifest element.


Split Action Bar:
Split Action Bar


Normal Action Bar:
Normal Action Bar


- Add android:uiOptions="splitActionBarWhenNarrow" in AndroidManifest.xml.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exercise.AndroidSplitActionBar"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="14" />

<application

android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:uiOptions="splitActionBarWhenNarrow"
android:name=".AndroidSplitActionBarActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>


- /res/menu/menu.xml define the items in Action Bar.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/itemid_0"
android:title="Action Item 0"
android:icon="@drawable/ic_launcher"
android:orderInCategory="0"
android:showAsAction="ifRoom|withText" />
<item android:id="@+id/itemid_1"
android:title="Action Item 1"
android:orderInCategory="0"
android:showAsAction="ifRoom|withText" />
<item android:id="@+id/itemid_2"
android:title="Action Item 2"
android:orderInCategory="0"
android:showAsAction="ifRoom|withText" />

</menu>


- Override onCreateOptionsMenu() method to inflate menu.
package com.exercise.AndroidSplitActionBar;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu, menu);

return super.onCreateOptionsMenu(menu);
}
}



Saturday, 16 June 2012

Programmatically create layout and view, with ID assigned by setId().

This example demonstrate how to create layout and view at run time using Java code, instead of XML code. We can assign IDs for the layouts/views by calling setId() mdthod.

Programmatically create layout and view, with ID assigned by setId().

In order to call setId() with named id, create /res/values/ids.xml to define out ID resources.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="layout_id"/>
<item type="id" name="image_id" />
</resources>


Main code.
package com.exercise.AndroidSetId;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

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

LinearLayout layout = new LinearLayout(AndroidSetIdActivity.this);
layout.setId(R.id.layout_id);
LayoutParams layoutParams
= new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
layout.setLayoutParams(layoutParams);
layout.setOrientation(LinearLayout.VERTICAL);

ImageView imageView = new ImageView(AndroidSetIdActivity.this);
imageView.setId(R.id.image_id);
imageView.setImageResource(R.drawable.ic_launcher);
LayoutParams imageViewLayoutParams
= new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(imageViewLayoutParams);

layout.addView(imageView);

setContentView(layout);

layout.setOnClickListener(viewOnClickListener);
imageView.setOnClickListener(viewOnClickListener);
}

OnClickListener viewOnClickListener
= new OnClickListener(){

@Override
public void onClick(View v) {

int myId = v.getId();

Toast.makeText(AndroidSetIdActivity.this,
"ID: " + String.valueOf(myId) + " clicked",
Toast.LENGTH_LONG).show();
}};
}



Schedule of Android Sessions in Google IO 2012

Be among the first to see the latest demos and developments from Android. Watch the keynote and over 40 sessions live streamed from Google I/O! It all begins June 27, at 9am.

Check the Android sessions schedule.


Improve Android Emulator performance with Intel Atom x86 System Image

Back to the releasing of Android SDK r17, Intel Atom x86 System Image was included. AVD with Intel Atom x86 System Image can  access the host CPU natively and offer significantly faster execution.

Android emulator with Intel Atom x86 System Image


To install Intel Atom x86 System Image, click Window from Eclipse menu, select Android SDK Manager. Check to install package of Intel Atom x86 System Image, it's available on Android 4.0.3(API 15) and 2.3.3(API 10) currently.



Create emulator using Intel Atom x86 System Image

- Window -> AVD Manager. New a AVD.



- Select CPU/ABI of Intel Atom (x86). Enter others as needed. Click Create AVD.




Thursday, 14 June 2012

Add MyLocationOverlay on OpenStreetMap, to display user location and compass.

Modify the previous exercises "Implement OnItemGestureListener on OpenStreetMap to detect user touch and retrieve touched items properties" to add MyLocationOverlay on OpenStreetMap, to display user location and compass easily.

MyLocationOverlay on OpenStreetMap


Modify the main code, AndroidOpenStreetMapViewActivity.java. Add MyLocationOverlay in onCreate() method, enableMyLocation() and enableCompass() in onResume(), and disableMyLocation() and disableCompass() in onPause().

package com.exercise.OpenStreetMapView;

import java.util.ArrayList;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.ItemizedIconOverlay.OnItemGestureListener;
import org.osmdroid.views.overlay.MyLocationOverlay;
import org.osmdroid.views.overlay.OverlayItem;
import org.osmdroid.views.overlay.ScaleBarOverlay;

import android.app.Activity;
import android.content.Context;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

public class AndroidOpenStreetMapViewActivity extends Activity {

private MapView myOpenMapView;
private MapController myMapController;

ArrayList<OverlayItem> anotherOverlayItemArray;

MyLocationOverlay myLocationOverlay = null;

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

myOpenMapView = (MapView)findViewById(R.id.openmapview);
myOpenMapView.setBuiltInZoomControls(true);
myMapController = myOpenMapView.getController();
myMapController.setZoom(2);

//--- Create Another Overlay for multi marker
anotherOverlayItemArray = new ArrayList<OverlayItem>();
anotherOverlayItemArray.add(new OverlayItem(
"0, 0", "0, 0", new GeoPoint(0, 0)));
anotherOverlayItemArray.add(new OverlayItem(
"US", "US", new GeoPoint(38.883333, -77.016667)));
anotherOverlayItemArray.add(new OverlayItem(
"China", "China", new GeoPoint(39.916667, 116.383333)));
anotherOverlayItemArray.add(new OverlayItem(
"United Kingdom", "United Kingdom", new GeoPoint(51.5, -0.116667)));
anotherOverlayItemArray.add(new OverlayItem(
"Germany", "Germany", new GeoPoint(52.516667, 13.383333)));
anotherOverlayItemArray.add(new OverlayItem(
"Korea", "Korea", new GeoPoint(38.316667, 127.233333)));
anotherOverlayItemArray.add(new OverlayItem(
"India", "India", new GeoPoint(28.613333, 77.208333)));
anotherOverlayItemArray.add(new OverlayItem(
"Russia", "Russia", new GeoPoint(55.75, 37.616667)));
anotherOverlayItemArray.add(new OverlayItem(
"France", "France", new GeoPoint(48.856667, 2.350833)));
anotherOverlayItemArray.add(new OverlayItem(
"Canada", "Canada", new GeoPoint(45.4, -75.666667)));

ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay
= new ItemizedIconOverlay<OverlayItem>(
this, anotherOverlayItemArray, myOnItemGestureListener);
myOpenMapView.getOverlays().add(anotherItemizedIconOverlay);
//---

//Add Scale Bar
ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(this);
myOpenMapView.getOverlays().add(myScaleBarOverlay);

//Add MyLocationOverlay
myLocationOverlay = new MyLocationOverlay(this, myOpenMapView);
myOpenMapView.getOverlays().add(myLocationOverlay);
myOpenMapView.postInvalidate();
}

OnItemGestureListener<OverlayItem> myOnItemGestureListener
= new OnItemGestureListener<OverlayItem>(){

@Override
public boolean onItemLongPress(int arg0, OverlayItem arg1) {
// TODO Auto-generated method stub
return false;
}

@Override
public boolean onItemSingleTapUp(int index, OverlayItem item) {
Toast.makeText(AndroidOpenStreetMapViewActivity.this,
item.mDescription + "\n"
+ item.mTitle + "\n"
+ item.mGeoPoint.getLatitudeE6() + " : " + item.mGeoPoint.getLongitudeE6(),
Toast.LENGTH_LONG).show();
return true;
}

};

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
myLocationOverlay.enableMyLocation();
myLocationOverlay.enableCompass();
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
myLocationOverlay.disableMyLocation();
myLocationOverlay.disableCompass();
}

}


"android.permission.ACCESS_FINE_LOCATION" is needed in AndroidManifest.xml. (already added in previous steps.)

Download the files.