Tuesday, July 29, 2014

Generate random number and display in various radix

This example generate random number, in the range between 0 and user selected progress value of SeekBar (If progress of 0 is selected, the upper limit is open). Then display the value in variou radix, same as the method used in last exercise "Convert String to int to String base on various radix".


package com.example.androidstringformat;

import java.util.Locale;
import java.util.Random;

import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity {
 
 SeekBar seekbarRange;
 TextView textOut;
 Button buttonGen;
 
 Spinner spAvailableLocale;
 Locale[] availableLocales;
 
 Random random;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        seekbarRange = (SeekBar)findViewById(R.id.seekbarrange);
     textOut = (TextView)findViewById(R.id.printout);
     buttonGen = (Button)findViewById(R.id.buttongen);
     
     buttonGen.setOnClickListener(onClickListener);

     random = new Random();
    }
    
    OnClickListener onClickListener =
     new OnClickListener(){

   @Override
   public void onClick(View arg0) {
    
    int range = seekbarRange.getProgress();
    int randomNum;
    
    if(range==0){
     randomNum = random.nextInt();
    }else{
     randomNum = random.nextInt(range+1);
    }
    
    String result 
    = "default: " + Integer.toString(randomNum) + "\n"
    + "Binary: " + Integer.toBinaryString(randomNum) + "\n"
    + "Binary: " + Integer.toOctalString(randomNum) + "\n"
    + "Radix 10: " + Integer.toString(randomNum, 10) + "\n"
    + "Hex: " + Integer.toHexString(randomNum) + "\n"
    + "Radix 32: " + Integer.toString(randomNum, 32);
   
   textOut.setText(result);

   }};

}


<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="com.example.androidstringformat.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold" />
    
    <SeekBar
        android:id="@+id/seekbarrange"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="0"/>

    <Button
        android:id="@+id/buttongen"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=" - Generate Random number - " />
    <TextView
        android:id="@+id/printout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold" />

</LinearLayout>


Bluetooth Low Energy



Bluetooth Low Energy is an incredibly exciting technology with the promise of unlocking a myriad of use cases. This session will focus on new Bluetooth Low Energy features, including improved scanning and newly added support for peripheral mode, in Android.

Monday, July 28, 2014

Convert String to int to String base on various radix

This example show how to 
  • Convert String (user enter in EditText) to integer base on radix, using parseInt(String string) and parseInt(String string, int radix).
  • Convert from integer back to String base on various radix using  toString(int i), toString(int i, int radix), toBinaryString(int i), toOctalString(int i) and toHexString(int i).


package com.example.androidstringformat;

import java.util.Locale;

import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity {
 
 RadioButton radioDefault, radioBinary, radioOctal, radio10, radioHex, radio32;
 EditText edit1;
 TextView textOut;
 Button buttonPrint;
 
 Spinner spAvailableLocale;
 Locale[] availableLocales;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        radioDefault = (RadioButton)findViewById(R.id.optDefault);
        radioBinary = (RadioButton)findViewById(R.id.optBinary);
        radioOctal = (RadioButton)findViewById(R.id.optOctal);
        radio10 = (RadioButton)findViewById(R.id.opt10);
        radioHex = (RadioButton)findViewById(R.id.optHex);
        radio32 = (RadioButton)findViewById(R.id.opt32);
        
        edit1 = (EditText)findViewById(R.id.edit1);
     textOut = (TextView)findViewById(R.id.printout);
     buttonPrint = (Button)findViewById(R.id.buttonprint);
     
     buttonPrint.setOnClickListener(onClickListener);

    }
    
    OnClickListener onClickListener =
     new OnClickListener(){

   @Override
   public void onClick(View arg0) {
    String strIn = edit1.getText().toString();

    if(!strIn.equals("")){

     int intIn = 0;
     
     try{
      if(radioDefault.isChecked()){
       intIn = Integer.parseInt(strIn);
      }else if(radioBinary.isChecked()){
       intIn = Integer.parseInt(strIn, 2);
      }else if(radioOctal.isChecked()){
       intIn = Integer.parseInt(strIn, 8);
      }else if(radio10.isChecked()){
       intIn = Integer.parseInt(strIn, 10);
      }else if(radioHex.isChecked()){
       intIn = Integer.parseInt(strIn, 16);
      }else if(radio32.isChecked()){
       intIn = Integer.parseInt(strIn, 32);
      }
      
      String result 
       = "default: " + Integer.toString(intIn) + "\n"
       + "Binary: " + Integer.toBinaryString(intIn) + "\n"
       + "Binary: " + Integer.toOctalString(intIn) + "\n"
       + "Radix 10: " + Integer.toString(intIn, 10) + "\n"
       + "Hex: " + Integer.toHexString(intIn) + "\n"
       + "Radix 32: " + Integer.toString(intIn, 32);
      
      textOut.setText(result);
     }catch(NumberFormatException ex){
      textOut.setText(ex.toString());
     }
     
    }
    
   }};

}


<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="com.example.androidstringformat.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold" />
        
 <RadioGroup
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal" >
     <RadioButton
         android:id="@+id/optDefault"
         android:layout_width="0dp"
         android:layout_weight="1"
         android:layout_height="wrap_content"
         android:text="default" 
         android:checked="true" />
     <RadioButton
         android:id="@+id/optBinary"
         android:layout_width="0dp"
         android:layout_weight="1"
         android:layout_height="wrap_content"
         android:text="Binary" />
     <RadioButton
         android:id="@+id/optOctal"
         android:layout_width="0dp"
         android:layout_weight="1"
         android:layout_height="wrap_content"
         android:text="Octal" />
     <RadioButton
         android:id="@+id/opt10"
         android:layout_width="0dp"
         android:layout_weight="1"
         android:layout_height="wrap_content"
         android:text="Radix 10" />
     <RadioButton
         android:id="@+id/optHex"
         android:layout_width="0dp"
         android:layout_weight="1"
         android:layout_height="wrap_content"
         android:text="Hex" />
     <RadioButton
         android:id="@+id/opt32"
         android:layout_width="0dp"
         android:layout_weight="1"
         android:layout_height="wrap_content"
         android:text="Radix 32" />
 </RadioGroup>

    <EditText
        android:id="@+id/edit1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/buttonprint"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=" - Print - " />
    <TextView
        android:id="@+id/printout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold" />

</LinearLayout>


Accept negative number in EditText

In last exercise "Display formated number in decimal, octal and hexadecimal using String.format", EditText defined in XML with android:inputType="number". It will not accept minus sign, so the input number is always positive.

To accept minus sign to enter negative number, change it to android:inputType="numberSigned".


<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="com.example.androidstringformat.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold" />
    <EditText
        android:id="@+id/edit1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="numberSigned" />
    <Button
        android:id="@+id/buttonprint"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=" - Print - " />
    <TextView
        android:id="@+id/printout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>


Display formated number in decimal, octal and hexadecimal using String.format

How to display formated number in decimal, octal and hexadecimal using String.format, with %d, %o, %x and %X.


In layout file, add android:inputType="number" to EditText to limit the user input to number only.
<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="com.example.androidstringformat.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold" />
    <EditText
        android:id="@+id/edit1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number" />
    <Button
        android:id="@+id/buttonprint"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=" - Print - " />
    <TextView
        android:id="@+id/printout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>


MainActivity.java
package com.example.androidstringformat;

import java.util.Locale;

import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity {
 
 EditText edit1;
 TextView textOut;
 Button buttonPrint;
 
 Spinner spAvailableLocale;
 Locale[] availableLocales;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        edit1 = (EditText)findViewById(R.id.edit1);
     textOut = (TextView)findViewById(R.id.printout);
     buttonPrint = (Button)findViewById(R.id.buttonprint);
     
     buttonPrint.setOnClickListener(onClickListener);
    }
    
    OnClickListener onClickListener =
     new OnClickListener(){

   @Override
   public void onClick(View arg0) {
    String strIn = edit1.getText().toString();

    if(!strIn.equals("")){
     //convert String to integer
     int inInt = Integer.parseInt(strIn);

     textOut.setText(
      String.format("parse to Integer\n(Decimal): %d\n", inInt) +
      String.format("(Octal): %o\n", inInt) +
      String.format("(hexadecimal): %x\n(HEXADECIMAL): %X\n", inInt, inInt));
    }
    
   }};

}




Next: Accept negative number in EditText

Sunday, July 27, 2014

Display formated currency using DecimalFormat.getCurrencyInstance(locale)

This example show how to display currency for a specified locale, using DecimalFormat.getCurrencyInstance(locale).format().

   


package com.example.androidstringformat;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity {
 
 TextView textOut;
 TextView localeInfo;
 
 Spinner spAvailableLocale;
 Locale[] availableLocales;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
     textOut = (TextView)findViewById(R.id.printout);
     localeInfo = (TextView)findViewById(R.id.localeinfo);
     
     //get installed locales
     availableLocales = Locale.getAvailableLocales();
     spAvailableLocale = (Spinner)findViewById(R.id.spavlocale);
     
     ArrayAdapter<Locale> adapter = 
      new ArrayAdapter<Locale>(this, 
       android.R.layout.simple_spinner_item, 
       availableLocales);
     adapter.setDropDownViewResource(
       android.R.layout.simple_spinner_dropdown_item);
     spAvailableLocale.setAdapter(adapter);
     spAvailableLocale.setOnItemSelectedListener(onItemSelectedListener);
    }

    OnItemSelectedListener onItemSelectedListener =
     new OnItemSelectedListener(){

   @Override
   public void onItemSelected(AdapterView<?> parent, View view,
     int position, long id) {
    Locale locale = (Locale)parent.getItemAtPosition(position);
    localeInfo.setText(String.format(
     "DisplayCountry: %s\nDisplayLanguage: %s\nDisplayName: %s\n\n", 
     locale.getDisplayCountry(), 
     locale.getDisplayLanguage(),
     locale.getDisplayName()));
    
    NumberFormat numberFormat = DecimalFormat.getCurrencyInstance(locale);
    String strNum = numberFormat.format(12345.6789f);
    
    textOut.setText(strNum);
   }

   @Override
   public void onNothingSelected(AdapterView<?> arg0) {}
     
    };
    
}


Usign the same layout as in last example of "Display Date formated using String.format() with Locale".

Display Date formated using String.format() with Locale

This example show how to display formated Date using String.format() with Locale.


package com.example.androidstringformat;

import java.util.Date;
import java.util.Locale;

import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity {
 
 TextView textOut;
 TextView localeInfo;
 
 Spinner spAvailableLocale;
 Locale[] availableLocales;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
     textOut = (TextView)findViewById(R.id.printout);
     localeInfo = (TextView)findViewById(R.id.localeinfo);
     
     //get installed locales
     availableLocales = Locale.getAvailableLocales();
     spAvailableLocale = (Spinner)findViewById(R.id.spavlocale);
     
     ArrayAdapter<Locale> adapter = 
      new ArrayAdapter<Locale>(this, 
       android.R.layout.simple_spinner_item, 
       availableLocales);
     adapter.setDropDownViewResource(
       android.R.layout.simple_spinner_dropdown_item);
     spAvailableLocale.setAdapter(adapter);
     spAvailableLocale.setOnItemSelectedListener(onItemSelectedListener);
    }

    OnItemSelectedListener onItemSelectedListener =
     new OnItemSelectedListener(){

   @Override
   public void onItemSelected(AdapterView<?> parent, View view,
     int position, long id) {
    Locale locale = (Locale)parent.getItemAtPosition(position);
    localeInfo.setText(String.format(
     "DisplayCountry: %s\nDisplayLanguage: %s\nDisplayName: %s\n\n", 
     locale.getDisplayCountry(), 
     locale.getDisplayLanguage(),
     locale.getDisplayName()));
    
    Date now = new Date();
    textOut.setText(
     String.format(locale, "%tc\n", now) + //C library asctime(3)-like output.
     String.format(locale, "%tD\n", now) + //(MM/DD/YY)
     String.format(locale, "%tF\n", now) + //(YYYY-MM-DD)
     String.format(locale, "%tr\n", now) + //Full 12-hour time
     String.format(locale, "%tz\n", now) + //Time zone GMT offset 
     String.format(locale, "%tZ\n", now)  //Localized time zone abbreviation 
     );
   }

   @Override
   public void onNothingSelected(AdapterView<?> arg0) {}
     
    };
    
}


<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="com.example.androidstringformat.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold" />
    <Spinner
        android:id="@+id/spavlocale"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/localeinfo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/printout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>


Saturday, July 26, 2014

String.format()

Simple example using String.format().


package com.example.androidstringformat;

import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.os.Bundle;


public class MainActivity extends ActionBarActivity {
 
 EditText edit1, edit2;
 TextView textOut;
 Button buttonPrint;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        edit1 = (EditText)findViewById(R.id.edit1);
        edit2 = (EditText)findViewById(R.id.edit2);
     textOut = (TextView)findViewById(R.id.printout);
     buttonPrint = (Button)findViewById(R.id.buttonprint);
     
     buttonPrint.setOnClickListener(new OnClickListener(){

   @Override
   public void onClick(View arg0) {
    String str1 = edit1.getText().toString();
    String str2 = edit2.getText().toString();
    String strOut = String.format("%s\n%S", str1, str2);
    
    textOut.setText(strOut);
   }});
    }

}


<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="com.example.androidstringformat.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold" />
    <EditText
        android:id="@+id/edit1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/edit2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/buttonprint"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=" - Print - " />
    <TextView
        android:id="@+id/printout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

'Android SDK Content Loader' has encountered a problem - parseSdkContent failed

After install fresh Ubuntu 14.04.1 and Eclipse ADT with Android SDK, 'Android SDK Content Loader' has encountered a problem of parseSdkContent failed, Could not initialize class android.graphics.Typeface.


To fix it, delete Android L (API 20, L preview) in Android SDK Manager and restart Eclipse. It work in my case. Even re-install Android L (API 20, L preview).

Friday, July 25, 2014

Android SDK-Eclipse crash when Content Assist provide suggestion

Recently, install Android SDK on updated Ubuntu 14.04. But it always crash when Content Assist try to provide suggestion. And report error like this:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x6115b86d, pid=4231, tid=3076355840
#
# JRE version: Java(TM) SE Runtime Environment (8.0_11-b12) (build 1.8.0_11-b12)
# Java VM: Java HotSpot(TM) Client VM (25.11-b03 mixed mode linux-x86 )
# Problematic frame:
# C  [libsoup-2.4.so.1+0x5486d]  soup_session_feature_detach+0x1d
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/u/Android/eclipse/hs_err_pid4231.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#


This solution work for me:
  • Edit the file <Android SDK-Eclipse folder>/eclipse/eclipse.ini.
  • Insert the line:
    -Dorg.eclipse.swt.browser.DefaultType=mozilla


Tuesday, July 22, 2014

"Hello World" try on Android Studio

This video try "Hello World" on Android Studio:

Linux All-in-One For Dummies, 5th Edition

Eight minibooks in one volume cover every important aspect of Linux and everything you need to know to pass level-1 certification

Linux All-in-One For Dummies (For Dummies (Computer/Tech))

Linux All-in-One For Dummies explains everything you need to get up and running with the popular Linux operating system. Written in the friendly and accessible For Dummies style, the book ideal for new and intermediate Linux users, as well as anyone studying for level-1 Linux certification. The eight minibooks inside cover the basics of Linux, interacting with it, networking issues, Internet services, administration, security, scripting, and level-1 certification.
  • Covers every major topic for anyone just getting familiar with Linux
  • Includes a test-prep section for passing the level-1 Linux certification exam
  • Written by the expert author of more than thirty books, including CompTIA Security+ Study Guide, 3rd Edition
Including everything beginners need to know to get started with Linux, Linux All-in-One For Dummies, 5th Edition is the ultimate resource and reference for aspiring professionals.

Monday, July 21, 2014

Install and update Android Studio (Beta) on Ubuntu 14.04



Before you set up Android Studio, be sure you have installed JDK 6 or greater (the JRE alone is not sufficient), or Install Oracle JDK 8 on Ubuntu 14.04.

The installation is very straightforward:
  • Download Android Studio Beta v0.8.0 with the Android SDK for Linux HERE.
  • Unpack the downloaded Tar file, android-studio-bundle-.tgz, into an appropriate location for your applications.
  • To launch Android Studio, navigate to the android-studio/bin/ directory in a terminal and execute studio.sh.



Update Android Studio:

If you are running Android Studio 0.8.x, simple restart it, or manually check Help > Check for Update...



Update Android SDK in Android Studio:

- Click Configure

- Click SDK Manager


Setup 51-android.rules for Android SDK

After Install Android SDK on Ubuntu 14.04, you have to setup 51-android.rules, otherwise you cannot connect, download and run your code on real devices.


Refer to the document http://developer.android.com/tools/device.html#setting-up:

- Make sure enable something like Developer options, USB debugging...on your device.

- As root, create/modify the file /etc/udev/rules.d/51-android.rules in your Ubuntu system.

- Add a line in the file
SUBSYSTEM=="usb", ATTR{idVendor}=="xxxx", MODE="0666", GROUP="plugdev"

where xxxx is the vendor id of your device. You can use the Linux command lsusb to get the vendor id of your device, refer 2:05 of the below video to know how to.

- Run the command to execute it:
$ chmod a+r /etc/udev/rules.d/51-android.rules


After setup /etc/udev/rules.d/51-android.rules, you can download and run your apps on real devices.

Install Android SDK on Ubuntu 14.04

Before install Android SDK on Ubuntu, you have to Install Oracle JDK 8 on Ubuntu 14.04.

Visit http://developer.android.com/sdk/index.html, to download Eclipse ADT with the Android SDK for Linux. Simple unzip the downloaded file and move to the folder you want. Simple run the file <installed folder>/eclipse/eclipse to start the Eclipse with Android SDK.

As mentioned in SYSTEM REQUIREMENTS of Android SDK document, JDK 6 is needed. To select Java compiler compliance level:
- click Window in Eclipse menu, -> Preferences.
- Extend Java on left box, and select Compiler.
- Select 1.6 in Compiler compliance level.

Now you can create "Hello World" to verify your setup.



In order to connect your Android SDK to real devices to test your apps, you have to setup 51-android.rules for your devices.

If your Android SDK-Eclipse crash when Content Assist try to provide suggestion, read HERE.


Install Oracle JDK 8 on Ubuntu 14.04

This post describe how to download and install Oracle JDK 8 on Ubuntu 14.04, and also update alternatives to correct the links.

Download Oracle JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html.

Accept License Agreement and download the corresponding .tar.gz file, jdk-8u11-linux-i586.tar.gz in my case.

Unpack the downloaded tarball (.tar.gz) and move unpacked folder to where you want, /home/u/jdk1.8.0_11/ in my case.

Run the following commands in terminal to update the alternatives of javac and java. Where /home/u/jdk1.8.0_11/ is the installed folder of jdk.

$ sudo update-alternatives --install /usr/bin/javac javac /home/u/jdk1.8.0_11/bin/javac 1
$ sudo update-alternatives --install /usr/bin/java java /home/u/jdk1.8.0_11/bin/java 1

$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java

After installed and setup

Step-by-step:

Sunday, July 20, 2014

Install Cinnamon on Ubuntu 14.04

Against Unity, Cinnamon can seem fairly performance orientated.



To install Cinnamon on Ubuntu 14.04, enter the commands in Terminal:

$ sudo add-apt-repository ppa:lestcape/cinnamon
$ sudo apt-get update
$ sudo apt-get install cinnamon




reference: OMG!Ubuntu! - How to Install Cinnamon from a PPA on Ubuntu 14.04


Note for using RecordMyDesktop on Cinnamon:

By default, the bottom bar will disappear when running RecordMyDesktop to record your screen activity. To fix it, run with Extra Options of --no-frame.

- Click Advanced button.


- Select Misc tab.
- Enter "--no-frame" in Extra Options box.


Edit /etc/default/grub to set GRUB_CMDLINE_LINUX="acpi=off"/"pci=noacpi" options

As mentioned, Ubuntu 14.04 is installed on my old/legacy PC, with option "acpi=off". In my legacy Fujitsu M2010 Netbook, it display in 800x600 only. Alternatively, it can be set "pci=noacpi" to recognize the true resolution of 1024x600, but cannot set brightness and always in dark.

The default generated /etc/default/grub file is:
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX="acpi=off"

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"


To set option "pci=noacpi", modify to GRUB_CMDLINE_LINUX="pci=noacpi" in /etc/default/grub. Like this:
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
#GRUB_CMDLINE_LINUX="acpi=off"
GRUB_CMDLINE_LINUX="pci=noacpi"

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

After the file /etc/default/grub edited, run the following command to update /boot/grub/grub.cfg
$ sudo update-grub

And restart to make the new setting take effect.


Install lubuntu-desktop on Ubuntu

lubuntu-desktop is a lightweight LXDE desktop alternative to Unity, GNOME and KDE. It’s good for old computers. To install it, enter the command:

$ sudo apt-get install lubuntu-desktop

After installed and log-out, your get extra desktop option of Lubuntu, Lubuntu Netbook and Openbox.


Install gnome-session-flashback

To install gnome-session-flashback, to make your Ubuntu run on classic desktop, enter the command in Terminal:

$ sudo apt-get install gnome-session-flashback


After installed, logout your session. You can get more options of GNOME Flashback (Compiz) and GNOME Flashback (Metacity) in login. Select GNOME Flashback (Metacity) for best performance.

Saturday, July 19, 2014

Install Ubuntu 14.04 on old/legacy PC, with "Disabling IRQ #9"

This post describe how to install Ubuntu 14.04 on a old/legacy Netbook, Fujitsu M2010 Netbook with CPU of Intel Atom N280 and GMA 950 graphics processor.

Prepare a Installation/Live-USB of Ubuntu, 14.04 LTS, 32-bit Desktop version.

With the default options, the boot-up sequency will stop in "Disabling IRQ #9".


To by pass it, we can make it boot with option "acpi=off".
- Press F6 while the Live-USB booting, untill you see the selection page.
- Press F6 and select option of "acpi=off".
- Then follow the normal installation steps.


Once finished, remove USB and restart the system. Suppose it can be run with "acpi=off" in the new setup.


Then, the first thing you should do is updating your system, just search and run "System Updater".


Up to here, it run the new Ubuntu UI very slow! You can install other lightweight desktop to improve the performance greatly.
- Install gnome-session-flashback
- Install lubuntu-desktop
Install Cinnamon on Ubuntu 14.04

With option of "acpi=off", my legacy Fujitsu M2010 always show in 800x600. Alternatively, it can be set "pci=noacpi" to recognize the true resolution 1024x600. But with this setting, the display brightness cannot be set and in little bit dark!
-  Edit /etc/default/grub to set GRUB_CMDLINE_LINUX="acpi=off"/"pci=noacpi" options

Anybody know how to fix it, please advise.

Fail to run Linux Mint on old/legacy PC!

Just tried to run Linux Mint on old/legacy PC, Fujitsu M2010 Netbook with CPU of Intel Atom N280 and GMA 950 graphics processor. Due to some compatibility problem, I have to run with option "acpi=off" or "pci=noacpi".

Prepare Live USB of Linux Mint of 32-bit Cinnamon.

With default boot-up setting, the system will hang-up with "Disabling IRQ #9".

In order to boot it up with option setting, press F6 while 10 seconds counting. Then press [Tab] to edit boot option. Press [Enter] to boot.

With option of "acpi=off", the system can run. But cannot recognize the resolution. Always set 800x600, not the true resolution of 1024x600.


With option of "pci=noacpi", it can detect the resolution of 1024x600, but cannot adjust screen brightness - always in dark.

Tried to install with option of "acpi=off", the error of "Disabling IRQ #9" happen again after finished and rebooted!

Friday, July 18, 2014

Chrome Apps on Android and iOS

Chrome Apps can now run on both Android and iOS using a toolchain based on Apache Cordova. This provides developers a strong incentive to adopt web technology to build native-like apps targeting desktop as well as mobile platforms.

This video talk about the ease of development and the differentiating capabilities provided by the platform.

Chrome Apps on Android and iOS

Thursday, July 17, 2014

Wednesday, July 16, 2014

Set color scheme of the progress animation in SwipeRefreshLayout

The methods setColorSchemeColors (int color1, int color2, int color3, int color4) and setColorSchemeResources(int colorRes1, int colorRes2, int colorRes3, int colorRes4) of SwipeRefreshLayout set the four colors used in the progress animation. The first color will also be the color of the bar that grows in response to a user swipe gesture.


package com.example.androidswiperefresh;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;

public class MainActivity extends ActionBarActivity {
 
 SwipeRefreshLayout swipeRefreshLayout;
 TextView textInfo;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  textInfo = (TextView)findViewById(R.id.info);
  
  swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipelayout);
  swipeRefreshLayout.setOnRefreshListener(onRefreshListener);
  
  swipeRefreshLayout.setColorSchemeColors(
   Color.RED, Color.GREEN, Color.BLUE, Color.CYAN);
 }
 
 OnRefreshListener onRefreshListener = new OnRefreshListener(){

  @Override
  public void onRefresh() {
   textInfo.setText("WAIT: doing something");
   
   //simulate doing something
   new Handler().postDelayed(new Runnable() {

    @Override
    public void run() {
     swipeRefreshLayout.setRefreshing(false);
     textInfo.setText("DONE");
    }

   }, 2000);
  }};
}

Use the same layout file in last exercise of SwipeRefreshLayout example.

Tuesday, July 15, 2014

SwipeRefreshLayout example

android.support.v4.widget.SwipeRefreshLayout can be used to detect user's vertical swipe gesture, to refresh the contents. It is a simple example of SwipeRefreshLayout, to detect user swipe to do something.


Layout, /res/layout/activity_main.xml.
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.androidswiperefresh.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold" />

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#A0A0A0" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="#808080" >

            <TextView
                android:id="@+id/info"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher"/>
            
        </LinearLayout>
        
    </android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>


MainActivity.java
package com.example.androidswiperefresh;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;
import android.os.Bundle;
import android.os.Handler;

public class MainActivity extends ActionBarActivity {
 
 SwipeRefreshLayout swipeRefreshLayout;
 TextView textInfo;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  textInfo = (TextView)findViewById(R.id.info);
  
  swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipelayout);
  swipeRefreshLayout.setOnRefreshListener(onRefreshListener);
 }
 
 OnRefreshListener onRefreshListener = new OnRefreshListener(){

  @Override
  public void onRefresh() {
   textInfo.setText("WAIT: doing something");
   
   //simulate doing something
   new Handler().postDelayed(new Runnable() {

    @Override
    public void run() {
     swipeRefreshLayout.setRefreshing(false);
     textInfo.setText("DONE");
    }

   }, 2000);
  }};
}


Next: Set color scheme of the progress animation in SwipeRefreshLayout

Monday, July 14, 2014

Takee - world's first holographic 3D smartphone



Takee is a sub brand of the Chinese manufacturer Estar and will be remembered as a creator of the world's first 3D holographic smartphone.

Nokia X software platform 2.0

This video will give developers a short overview of the new Nokia X software platform 2.0 and the new Nokia X2 smartphone. In live demonstrations we show what is new in the development environment and the related Nokia tools and examples.

Thursday, July 10, 2014

Keep the project appcompat_v7 opened

If you New a Android Project in Android-Eclipse using android.support.v7.app, an extra project appcompat_v7 will be created automatically, if it is not exist. And, if you mis-think that it is un-related and close the project appcompat_v7, you project will have Errors occurred during the build.

Errors running builder 'Android Pre Compiler' on project 'xxx'.
java.lang.NullPointerException

and/or

R cannot be resolved to a variable.

If your project have to import android.support.v7.app. just keep the project appcompat_v7 opened.

Wednesday, July 9, 2014

Create AVD for Android Wear

The video show how to create AVD (Android Virtual Device) for Android Wear:

The Android Virtual Device is currently running in an emulator and cannot be deleted

I want to delete a AVD(Android Virtual Device), but it cannot be deleted with the error message "The Android Virtual Device XXX is currently running in an emulator and cannot be deleted". In fact that it is not running.

To delete the AVD manually (in Linux):
  • Switch to /.android/avd folder in your HOME directory.
  • Delete the corresponding .avd folder and .ini file.
  • Delete it in Eclipse.


Friday, July 4, 2014

How alpha pixel affect performance

This video, Don't Alpha That Pixel!, we will cover the difference between alpha blending/ alpha testing , how each one effects content pipeline, and peel back the layers to see the performance differences in these techniques on various types of mobile hardware. Alpha isn't free, and as a developer, maximizing every pixel for performance can make a day and night difference in the look and feel of your app.

Thursday, July 3, 2014

Cannot update ADT 23.0.2 because of conflicting dependency...!

Updated@2014-07-08: Fixed by re-install updated Eclipse ADT Bundle with Android SDK 20140702.



After updated Android SDK Tools 23.0.2, I cannot update ADT 23.0.2 because of a conflicting dependency.

Cannot complete the install because of a conflicting dependency.
  Software being installed: Android Hierarchy Viewer 23.0.2.1259578 (com.android.ide.eclipse.hierarchyviewer.feature.feature.group 23.0.2.1259578)
  Software currently installed: eclipse 23.0.0.1245622 (adtproduct 23.0.0.1245622)
  Only one of the following can be installed at once: 
    Hierarchy Viewer 23.0.2.1259578 (com.android.ide.eclipse.hierarchyviewer 23.0.2.1259578)
    Hierarchy Viewer 23.0.0.1245622 (com.android.ide.eclipse.hierarchyviewer 23.0.0.1245622)
  Cannot satisfy dependency:
    From: eclipse 23.0.0.1245622 (adtproduct 23.0.0.1245622)
    To: com.android.ide.eclipse.hierarchyviewer.feature.feature.group [23.0.0.1245622]
  Cannot satisfy dependency:
    From: Android Hierarchy Viewer 23.0.0.1245622 (com.android.ide.eclipse.hierarchyviewer.feature.feature.group 23.0.0.1245622)
    To: com.android.ide.eclipse.hierarchyviewer [23.0.0.1245622]
  Cannot satisfy dependency:
    From: Android Hierarchy Viewer 23.0.2.1259578 (com.android.ide.eclipse.hierarchyviewer.feature.feature.group 23.0.2.1259578)
    To: com.android.ide.eclipse.hierarchyviewer [23.0.2.1259578]


Cannot fix it! no matter how to change Software Site, un-install installed software, even re-install adt-bundle-linux-x86-20140624.zip. May be I have to wait further update from Google :(


What's new in WebView in the Android KitKat/L

This video introduce the new features of WebView that shipped in the KitKat/L release of Android.


Wednesday, July 2, 2014

Google Play Services 5.0

Google Play Services 5.0 is one of our biggest releases to date including new APIs like Android Wear, the Dynamic Security provider and a major set of additions to Google Play Games services. We've also added new APIs for Google Cast, Google Drive, Google Wallet, Analytics, App Indexing and Mobile Ads.

Chrome Dev Editor (developer preview)

Chrome Dev Editor (CDE) is a developer tool for building apps on the Chrome platform - Chrome Apps and Web Apps. CDE has support for writing applications in JavaScript or Dart, and has Polymer templates to help you get started building your UI. CDE also has built-in support for Git.





Google I/O 2014 - How we built Chrome Dev Editor with the Chrome platform