New test build of Android-x86 released, based on the Android 4.2.2



Android-x86 is a project to port Android open source project to x86 platform, Run Android on Your PC.

The test build 20130228 is based on the latest Android 4.2.2 release (JB-MR1.1 branch). We have fixed and added x86 specified code to let the system runs smoothly on most x86 platforms, especially for tablets and netbooks.

The key features in this release are:
  • Use the latest kernel 3.8.0 to support more drivers.
  • OpenGL ES hardware acceleration for AMD Radeon and Intel chipsets (not included chips with PVR). You may disable it by adding HWACCEL=0 to the cmdline if you have trouble to use it.
  • Support Multi-touch, Wifi, Audio, G-sensor, Camera and Backlight control.
  • Simulate SDCard by internal storage.
  • Auto mount usb driver and sdcard on plugging.
  • Multi-user support (max 8).
  • Support Ethernet (DHCP only).
  • Support VM like Virtual Box.

Google Maps Android API v2 now support anti-clockwise polygons

With Google Play services v3.0 and Android SDK Platform-tools updated. Google Maps Android API v2 now support anti-clockwise polygons.



The code is here: Google Maps Android API v2 example: Draw Polygon on GoogleMap. With video of playing in old version Google Play Services without support of anti-clockwise polygons.

Android SDK Platform-tools updated

To update Android SDK in Eclipse, click Window -> Android SDK Manager. Updates of Android SDK Platform-tools, Extras of Google Play Services, and a number of features are available.

Android SDK Platform-tools updated

Over-The-Air Installs - stay connected to users across their devices



With Google Play services v3.0, now you can drive automatic Android downloads from your website sign-ins. After signing in with Google on the web, users have the option to send your Android app to their device instantly, without them ever leaving your website. Direct installs from the Google Play Store are limited to free apps that exceed a quality threshold.

Link: https://developers.google.com/+/features/play-installs



Google Play services updated v3.0



Google roll out Google Play services v3.0, includes great Google+ Sign-In and Google Maps Android API improvements.

Know more: Android Developers Blog - Google+ Sign-In Now Part of Google Play Services

Get memory information

Example to get memory information using Runtime.

memory information


package com.example.androidmem;

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

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

TextView memInfo = (TextView)findViewById(R.id.meminfo);

String info = "";

info += "Total memory: " + Runtime.getRuntime().totalMemory() + "\n";
info += "Free memory: " + Runtime.getRuntime().freeMemory() + "\n";
info += "Max memory: " + Runtime.getRuntime().maxMemory() + "\n";

memInfo.setText(info);
}

}


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/meminfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>


Instant Android Fragmentation Management How-to


There are currently 7 different versions of operating systems for Android. A growing issue is fragmentation. With the number of Android users and the variety of versions available, Android fragmentation is a huge problem. This little book is the solution.

Android Fragmentation Management How-to is a step-by-step guide to writing applications that can run on all devices starting from Android 1.6. With simple solutions for complex problems, this book will walk you through the biggest issues facing Android developers today.

This book will take you through the newest features in the latest version of Android, and shows you how to utilize them in the older versions using the compatibility library. This practical guide allows you to focus on  creating the best application possible without worrying about compatibility.

All the heavy lifting is done for you. Using user interface, adapting your application will work perfectly on any Android operating system. Asynchronous data management will also allow your applications to run smoothly on any device.

Everything you need to run your app on any version of Android is right here.

Approach
Filled with practical, step-by-step instructions and clear explanations for the most important and useful tasks. Get the job done and learn as you go. Written in the easy to understand Packt How-to format, this book offers the solution to the big issues in Android application development.

Who this book is for
If you want the best possible reviews for your apps, regardless of device or Android operating system, then this book is for you.


Instructions for flashing a phone or tablet device with Ubuntu

Ubuntu Wiki post Instructions for flashing a phone or tablet device with Ubuntu.

The Ubuntu Touch Developer Preview is intended to be used for development and evaluation purposes only. It does not provide all of the features and services of a retail phone and cannot replace your current handset. This preview is the first release of a very new and unfinished version of Ubuntu and it will evolve quickly. If you want to install this release, please follow the guide provided, which details the available features and how to navigate the user experience.

This process will delete all data from the device. Restoring Android will not restore this data.




Android SDK Tools and ADT plugin updated Revision 21.1.0



Android SDK Tools updated Revision 21.1.0, you can now update it in Eclipse by select Windows -> Android SDK Manager.

The SDK Tools r21.1.0 is designed for use with ADT 21.1.0 and later, to update ADT in Eclipse, select Help -> Check for updates.

Remark: if you cannot update ADT (No updates were found), double check the setting of your software site (in Help -> Install New Software...), make sure https://dl-ssl.google.com/android/eclipse/ is included. In my case, the default included site is http://dl-ssl.google.com/android/eclipse/, no updates were found at this moment!

HTC One, full press conference led by HTC CEO Peter Chou in London.

HTC One - The Unveiling

introduced the brand new HTC One to the world in London and New York on 19 February, 2013. This is the full press conference led by HTC CEO Peter Chou in London.

Demo video of Google Glass


SharedPreferences.Editor for RadioButton in RadioGroup

Last post demonstrate how to "Read index of the checked RadioButton in RadioGroup" and explain why you cannot save in SharedPreferences.Editor base on IDs. This exercise demonstrate how to save the checked index of RadioButton in RadioGroup using SharedPreferences.Editor.

save the checked index of RadioButton in RadioGroup using SharedPreferences.Editor.


package com.example.androidradiogroup;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.app.Activity;
import android.content.SharedPreferences;

public class MainActivity extends Activity {

RadioGroup radioGroup;
TextView textCheckedID, textCheckedIndex;

final String KEY_SAVED_RADIO_BUTTON_INDEX = "SAVED_RADIO_BUTTON_INDEX";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioGroup = (RadioGroup)findViewById(R.id.radiogroup);
radioGroup.setOnCheckedChangeListener(radioGroupOnCheckedChangeListener);

textCheckedID = (TextView)findViewById(R.id.checkedid);
textCheckedIndex = (TextView)findViewById(R.id.checkedindex);

LoadPreferences();
}

OnCheckedChangeListener radioGroupOnCheckedChangeListener =
new OnCheckedChangeListener(){

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {

RadioButton checkedRadioButton = (RadioButton)radioGroup.findViewById(checkedId);
int checkedIndex = radioGroup.indexOfChild(checkedRadioButton);

textCheckedID.setText("checkedID = " + checkedId);
textCheckedIndex.setText("checkedIndex = " + checkedIndex);
SavePreferences(KEY_SAVED_RADIO_BUTTON_INDEX, checkedIndex);
}};

private void SavePreferences(String key, int value){
SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(key, value);
editor.commit();
}

private void LoadPreferences(){
SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
int savedRadioIndex = sharedPreferences.getInt(KEY_SAVED_RADIO_BUTTON_INDEX, 0);
RadioButton savedCheckedRadioButton = (RadioButton)radioGroup.getChildAt(savedRadioIndex);
savedCheckedRadioButton.setChecked(true);
}
}


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

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

<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/option1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />
<RadioButton
android:id="@+id/option2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2" />
<RadioButton
android:id="@+id/option3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3" />
</RadioGroup>

<TextView
android:id="@+id/checkedid"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/checkedindex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

Related:
- Example of using SharedPreferences.Editor; getPreferences() for a single activity.
- Use getSharedPreferences() to retrieve a preferences object shared across multiple activity.


Read index of the checked RadioButton in RadioGroup

This example demonstrate how to get the index of the checked RadioButton in RadioGroup.

Read index of the checked RadioButton in RadioGroup


package com.example.androidradiogroup;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.app.Activity;

public class MainActivity extends Activity {

RadioGroup radioGroup;
TextView textCheckedID, textCheckedIndex;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioGroup = (RadioGroup)findViewById(R.id.radiogroup);
radioGroup.setOnCheckedChangeListener(radioGroupOnCheckedChangeListener);

textCheckedID = (TextView)findViewById(R.id.checkedid);
textCheckedIndex = (TextView)findViewById(R.id.checkedindex);

}

OnCheckedChangeListener radioGroupOnCheckedChangeListener =
new OnCheckedChangeListener(){

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {

RadioButton checkedRadioButton = (RadioButton)radioGroup.findViewById(checkedId);
int checkedIndex = radioGroup.indexOfChild(checkedRadioButton);

textCheckedID.setText("checkedID = " + checkedId);
textCheckedIndex.setText("checkedIndex = " + checkedIndex);
}};

}


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

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

<TextView
android:id="@+id/checkedid"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/checkedindex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/option1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />
<RadioButton
android:id="@+id/option2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2" />
<RadioButton
android:id="@+id/option3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3" />
</RadioGroup>

</LinearLayout>


Please note that you cannot assume the checkedId passed to onCheckedChanged() of OnCheckedChangeListener always same for the same button. Specially when you want to set Preference for RadioButton in RadioGroup. The ADT will re-generate the IDs base on your layout. So, after you modify the layout, the IDs will be changed. I read some posts advise keep preference of RadioButton in RadioGroup base on the checkID. Yes, it work if you will not update your APK in the furture.

The IDs changed after re-layout


Next:
- SharedPreferences.Editor for RadioButton in RadioGroup


Back to Home Screen directly using ACTION_MAIN with category CATEGORY_HOME

If you want to go to Home Screen directly, using the code:


Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);



Python for Android

Python for android is a project to create your own Python distribution including the modules you want, and create an apk including python, libs, and your application.

know more: http://python-for-android.readthedocs.org/

The Copy Protection feature of Android App is being deprecated

Google is standardizing on two primary tools for helping developers protect against unauthorized copying: app encryption in Jelly Bean and the Licensing Service for all platforms. The older Copy Protection feature, which announced have be deprecating back in 2010, is now going away in favor of these more advanced tools. The Copy Protection feature will no longer be available in the Developer Console starting February 27, 2013 and will no longer be applied on new downloads in Google Play very soon after that. If your app has been using this feature and you would like to continue to protect against unauthorized copying, please begin using the Licensing Service. 

Learn more.

Convert between LatLng and Location

This example demonstrate how to convert between LatLng and Location. Refer onMapClick() in the code.

Convert between LatLng and Location


package com.example.androidmapsv2;

import java.util.Date;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.location.Location;
import android.os.Bundle;
import android.app.Activity;
import android.app.FragmentManager;
import android.widget.TextView;

public class MainActivity extends Activity
implements OnMapClickListener{

private GoogleMap myMap;

TextView info;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

FragmentManager myFragmentManager = getFragmentManager();
MapFragment myMapFragment =
(MapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = myMapFragment.getMap();

myMap.setOnMapClickListener(this);

info = (TextView)findViewById(R.id.info);

myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
myMap.getUiSettings().setZoomControlsEnabled(true);
myMap.getUiSettings().setCompassEnabled(true);
myMap.getUiSettings().setAllGesturesEnabled(true);
}



@Override
public void onMapClick(LatLng point) {
//myMap.addMarker(new MarkerOptions().position(point).title(point.toString()));

//The code below demonstrate how to convert between LatLng and Location

//Convert LatLng to Location
Location location = new Location("Test");
location.setLatitude(point.latitude);
location.setLongitude(point.longitude);
location.setTime(new Date().getTime()); //Set time as current Date
info.setText(location.toString());

//Convert Location to LatLng
LatLng newLatLng = new LatLng(location.getLatitude(), location.getLongitude());

MarkerOptions markerOptions = new MarkerOptions()
.position(newLatLng)
.title(newLatLng.toString());

myMap.addMarker(markerOptions);

}

}


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>

</LinearLayout>


The series:
A simple example using Google Maps Android API v2, step by step.

Implement shape of oval using XML

Last exercise demonstrate how to "Implement shape of rounded-rect using XML", with little bit of modification, we can shape of oval. Like this:

shape of oval


/res/drawable/oval.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<gradient
android:angle="90"
android:startColor="#FF000000"
android:endColor="#FFFFFFFF"
android:type= "linear" />
<stroke
android:width="1dp"
android:color="#FF000000" />
<padding
android:left="15dp"
android:top="15dp"
android:right="15dp"
android:bottom="15dp" />
</shape>


Layout with shape of oval.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity" >

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/oval" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:background="@drawable/oval" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="normal TextView"
android:layout_margin="5dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView with roundrect"
android:layout_margin="5dp"
android:background="@drawable/oval" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="normal EditText"
android:layout_margin="5dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText with roundrect"
android:text="Hello"
android:layout_margin="5dp"
android:background="@drawable/oval" />
</LinearLayout>

</LinearLayout>


Define shape of rounded-rect for View using XML

This example demonstrate how to define rounded-rect shape for View, in XML; to implement layout as shown here:

rounded-rect shape


Create /res/drawable/roundrect.xml to define our custom shape.
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="15dp" />
<gradient
android:angle="90"
android:startColor="#FF000000"
android:endColor="#FFFFFFFF"
android:type= "linear" />
<stroke
android:width="1dp"
android:color="#FF000000" />
<padding
android:left="15dp"
android:top="15dp"
android:right="15dp"
android:bottom="15dp" />
</shape>


Include View using the custom shape, with android:background="@drawable/roundrect".
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity" >

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/roundrect" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:background="@drawable/roundrect" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="normal TextView"
android:layout_margin="5dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView with roundrect"
android:layout_margin="5dp"
android:background="@drawable/roundrect" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="normal EditText"
android:layout_margin="5dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText with roundrect"
android:text="Hello"
android:layout_margin="5dp"
android:background="@drawable/roundrect" />
</LinearLayout>

</LinearLayout>


Related: Implement shape of oval using XML


android.widget.Space

android.widget.Space added in API level 14, is a lightweight View subclass that may be used to create gaps between components in general purpose layouts.

Example:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="3"
tools:context=".MainActivity" >

<TextView
android:textSize="28sp"
android:text="@string/hello_world" />
<TextView
android:textSize="28sp"
android:background="#D0D0D0"
android:text="Cell 2" />
<TextView
android:textSize="28sp"
android:background="#B0B0B0"
android:layout_rowSpan="2"
android:text="Double Row Cell 3" />
<TextView
android:textSize="28sp"
android:background="#909090"
android:layout_columnSpan="2"
android:text="Double Column Cell 4" />
<Space
android:layout_columnSpan="2" />
<TextView
android:textSize="28sp"
android:background="#00FF00"
android:text="Cell 9" />
<TextView
android:textSize="28sp"
android:background="#0000FF"
android:layout_columnSpan="2"
android:text="Double Column Cell 10" />
<TextView
android:textSize="28sp"
android:background="#E0E0E0"
android:text="Cell 12" />
</GridLayout>


Space in GridLayout

GridLayout

android.widget.GridLayout added in API level 14, is a layout that places its children in a rectangular grid.

Example:

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="3"
tools:context=".MainActivity" >

<TextView
android:textSize="28sp"
android:text="@string/hello_world" />
<TextView
android:textSize="28sp"
android:background="#D0D0D0"
android:text="Cell 2" />
<TextView
android:textSize="28sp"
android:background="#B0B0B0"
android:layout_rowSpan="2"
android:text="Double Row Cell 3" />
<TextView
android:textSize="28sp"
android:background="#909090"
android:layout_columnSpan="2"
android:text="Double Column Cell 4" />
<TextView
android:textSize="28sp"
android:background="#505050"
android:text="Cell 7" />
<TextView
android:textSize="28sp"
android:background="#FF0000"
android:text="Cell 8" />
<TextView
android:textSize="28sp"
android:background="#00FF00"
android:text="Cell 9" />
<TextView
android:textSize="28sp"
android:background="#0000FF"
android:layout_columnSpan="2"
android:text="Double Column Cell 10" />
<TextView
android:textSize="28sp"
android:background="#E0E0E0"
android:text="Cell 12" />
</GridLayout>


GridLayout example

Get bearing between two location using android.location.Location

android.location.Location provide bearingTo(Location dest) method the approximate initial bearing in degrees East of true North when traveling along the shortest path between this location and the given location. The shortest path is defined using the WGS84 ellipsoid. Locations that are (nearly) antipodal may produce meaningless results.

Example:
      //Get the current location
Location startingLocation = new Location("starting point");
startingLocation.setLatitude(myMap.getCameraPosition().target.latitude);
startingLocation.setLongitude(myMap.getCameraPosition().target.longitude);

//Get the target location
Location endingLocation = new Location("ending point");
endingLocation.setLatitude(<target>.latitude);
endingLocation.setLongitude(<target>.longitude);

//Find the Bearing from current location to next location
float targetBearing = startingLocation.bearingTo(endingLocation);