Friday, June 26, 2015

Android Developer Tools (ADT) in Eclipse will end at the end of the year

Google are ending development and official support for the Android Developer Tools (ADT) in Eclipse at the end of the year. This specifically includes the Eclipse ADT plugin and Android Ant build system.

source: Android Developers Blog - An update on Eclipse Android Developer Tools


Import Android code sample of BluetoothChat to Android Studio


The Android code sample of BluetoothChat shows how to implement two-way text chat over Bluetooth between two Android devices, using all the fundamental Bluetooth API capabilities.

The sample demonstrates the following, using the Bluetooth API:

  • Setting up Bluetooth
  • Scanning for other Bluetooth devices
  • Querying the local Bluetooth adapter for paired Bluetooth devices
  • Establishing RFCOMM channels/sockets
  • Connecting to a remote device
  • Transfering data over Bluetooth

This video show how to import the Android code sample of BluetoothChat to Android Studio.



updated@2016-04-29:
I re-tried this example and found problem: refer "Problem of BluetoothChat example".


Related:
- Test HC-06 Bluetooth Module with Android BluetoothChat

Wednesday, June 24, 2015

Display Donut Chart on Android WebView, using Google Charts


My former post show how to display Google Charts on Android WebView, with Capture image. To display Donut Chart (Pie Chart with pie hole), simple modify the HTML file of pie chart (/assets/pie_chart.html) to add options of pieHole.

Example:

      // Set chart options
      var options = {
        title:'Android-er: Google Charts example of Pie/Donut chart',
        pieHole: 0.4,
      };


AlarmManager trigger BroadcastReceiver, then start another activity to generate Ringtone

This example show how to choice date/time with DatePicker and TimePicker, then set AlarmManager to trigger BroadcastReceiver on specified date/time, then start another activity to generate Ringtone using RingtoneManager.




com.example.androidringtone.MainActivity.java
package com.example.androidringtone;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import java.util.Calendar;

public class MainActivity extends ActionBarActivity {

    DatePicker datePicker;
    TimePicker timePicker;

    RadioButton optAlarm, optNotification, optRingtone;
    RadioButton optRingTonePicker;
    Button btnStart;
    TextView info;

    Ringtone ringTone;

    Uri uriAlarm, uriNotification, uriRingtone;

    final static int RQS_RINGTONEPICKER = 1;

    final static int RQS_1 = 1;

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

        datePicker = (DatePicker)findViewById(R.id.datepicker);
        timePicker = (TimePicker)findViewById(R.id.timepicker);

        optAlarm = (RadioButton)findViewById(R.id.optAlarm);
        optNotification = (RadioButton)findViewById(R.id.optNotification);
        optRingtone = (RadioButton)findViewById(R.id.optRingtone);
        optRingTonePicker = (RadioButton)findViewById(R.id.optPicker);
        btnStart = (Button)findViewById(R.id.start);
        info = (TextView)findViewById(R.id.info);

        uriAlarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        uriNotification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        uriRingtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        optAlarm.setText("uriAlarm: " + uriAlarm);
        optNotification.setText("uriNotification: " + uriNotification);
        optRingtone.setText("uriRingtone: " + uriRingtone);

        btnStart.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                if (optAlarm.isChecked()) {
                    setAlarm(uriAlarm);
                } else if (optNotification.isChecked()) {
                    setAlarm(uriNotification);
                } else if (optRingtone.isChecked()) {
                    setAlarm(uriRingtone);
                } else if (optRingTonePicker.isChecked()) {
                    startRingTonePicker();
                }

            }
        });

    }

    private void startRingTonePicker(){
        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
        startActivityForResult(intent, RQS_RINGTONEPICKER);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == RQS_RINGTONEPICKER && resultCode == RESULT_OK){
            Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            setAlarm(uri);
        }
    }

    private void setAlarm(Uri passuri){

        Calendar cal = Calendar.getInstance();
        cal.set(datePicker.getYear(),
                datePicker.getMonth(),
                datePicker.getDayOfMonth(),
                timePicker.getCurrentHour(),
                timePicker.getCurrentMinute(),
                00);

        String passString = passuri.toString();
        info.setText("\n\n***\n"
                + "Alarm is set@ " + cal.getTime() + "\n"
                + "***\n"
                + "Uri: " + passString);

        Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
        intent.putExtra("KEY_TONE_URL", passString);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                getBaseContext(),
                RQS_1,
                intent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
    }
}


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:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:orientation="horizontal"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">

        <DatePicker
            android:id="@+id/datepicker"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"/>
        <TimePicker
            android:id="@+id/timepicker"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">

        <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="wrap_content"
            android:layout_height="wrap_content" >

            <RadioButton
                android:id="@+id/optAlarm"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Alarm"
                android:checked="true" />

            <RadioButton
                android:id="@+id/optNotification"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Notification" />

            <RadioButton
                android:id="@+id/optRingtone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Ringtone" />

            <RadioButton
                android:id="@+id/optPicker"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ACTION_RINGTONE_PICKER" />

        </RadioGroup>

        <Button
            android:id="@+id/start"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Start"/>

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

</LinearLayout>


com.example.androidringtone.AlarmReceiver.java
package com.example.androidringtone;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.

        String uriString = intent.getStringExtra("KEY_TONE_URL");

        Toast.makeText(context,
                "Alarm received!\n"
                + "uriString: " + uriString,
                Toast.LENGTH_LONG).show();

        Intent secIntent = new Intent(context, SecondActivity.class);
        secIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        secIntent.putExtra("SEC_RINGTONE_URI", uriString);
        context.startActivity(secIntent);

    }
}


com.example.androidringtone.SecondActivity.java
package com.example.androidringtone;

import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;


public class SecondActivity extends ActionBarActivity {

    TextView secInfo;
    Button btnStop;

    Ringtone ringTone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        secInfo = (TextView)findViewById(R.id.secinfo);
        btnStop = (Button)findViewById(R.id.stop);

        String stringUri = getIntent().getStringExtra("SEC_RINGTONE_URI");
        Uri uri = Uri.parse(stringUri);
        secInfo.setText("uri: " + uri + "\n");

        ringTone = RingtoneManager
                .getRingtone(getApplicationContext(), uri);

        secInfo.append(ringTone.getTitle(SecondActivity.this));

        ringTone.play();

        btnStop.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                if(ringTone != null){
                    ringTone.stop();
                    ringTone = null;
                }
            }
        });

    }

}


layout/activity_second.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:padding="20dp"
    android:orientation="vertical"
    tools:context="com.example.androidringtone.SecondActivity">

    <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" />

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

    <Button
        android:id="@+id/stop"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Stop"/>

</LinearLayout>


Modify src/main/AndroidManifest.xml to add receiver of ".AlarmReceiver" and activity of ".SecondActivity".
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidringtone" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <receiver
            android:name=".AlarmReceiver"
            android:process=":remote" >
        </receiver>

        <activity
            android:name=".SecondActivity"
            android:label="@string/title_activity_second" >
        </activity>
    </application>

</manifest>



download filesDownload the files (Android Studio Format).

download filesDownload the APK.

Tuesday, June 23, 2015

Android and Java Setup for App Development on Ubuntu: Save Yourself a Few Hours

Android and Java Setup for App Development on Ubuntu: Save Yourself a Few Hours

Android and Java Setup for App Development on Ubuntu deals with installation/upgrade of Ubuntu, and then installation of Java and Android on Ubuntu, with the goal of doing Android App Development. Each software will be configured and interconnected, and then changes will be verified. Configuration includes settings in /etc/environment and how to recover from errors resulting in a login-loop. Configuration also includes use of MultiArch, dpkg, and apt-get to provide Android SDK-compatible libraries on 64-bit CPU systems. Installation of the full Oracle Java Development Kit is followed by setting this Java as the system default by using update-alternatives and the setting of alternatives-mode to manual. Integrated Development Environments (IDEs) include both Android/Studio and Android/Eclipse. Android SDK Manager adds packages and downloads components and platforms for emulation. All along, recommendations of reference sites are given for further research.

Android example using ACTION_RINGTONE_PICKER

This example show how to start another activity of RingTone Picker using ACTION_RINGTONE_PICKER intent, further works on last exercise "Generate Alarm, Notification and Ringtone using RingtoneManager".


com.example.androidringtone.MainActivity.java
package com.example.androidringtone;

import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

    RadioButton optAlarm, optNotification, optRingtone;
    RadioButton optRingTonePicker;
    Button btnStart, btnStop;
    Ringtone ringTone;

    Uri uriAlarm, uriNotification, uriRingtone;

    final int RQS_RINGTONEPICKER = 1;

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

        optAlarm = (RadioButton)findViewById(R.id.optAlarm);
        optNotification = (RadioButton)findViewById(R.id.optNotification);
        optRingtone = (RadioButton)findViewById(R.id.optRingtone);
        optRingTonePicker = (RadioButton)findViewById(R.id.optPicker);
        btnStart = (Button)findViewById(R.id.start);
        btnStop = (Button)findViewById(R.id.stop);

        uriAlarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        uriNotification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        uriRingtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        optAlarm.setText("uriAlarm: " + uriAlarm);
        optNotification.setText("uriNotification: " + uriNotification);
        optRingtone.setText("uriRingtone: " + uriRingtone);

        btnStart.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ringTone != null) {
                    //previous ringTone is playing,
                    //stop it first
                    ringTone.stop();
                }

                if (optAlarm.isChecked()) {
                    ringTone = RingtoneManager
                            .getRingtone(getApplicationContext(), uriAlarm);
                } else if (optNotification.isChecked()) {
                    ringTone = RingtoneManager
                            .getRingtone(getApplicationContext(), uriNotification);
                } else if (optRingtone.isChecked()) {
                    ringTone = RingtoneManager
                            .getRingtone(getApplicationContext(), uriRingtone);
                } else if (optRingTonePicker.isChecked()) {
                    startRingTonePicker();
                    return; //skip Toast to display RingTone title
                }

                Toast.makeText(MainActivity.this,
                        ringTone.getTitle(MainActivity.this),
                        Toast.LENGTH_LONG).show();
                ringTone.play();
            }
        });

        btnStop.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                if(ringTone!=null){
                    ringTone.stop();
                    ringTone = null;
                }
            }
        });
    }

    private void startRingTonePicker(){
        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
        startActivityForResult(intent, RQS_RINGTONEPICKER);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == RQS_RINGTONEPICKER && resultCode == RESULT_OK){
            Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            ringTone = RingtoneManager.getRingtone(getApplicationContext(), uri);
            Toast.makeText(MainActivity.this,
                    ringTone.getTitle(MainActivity.this),
                    Toast.LENGTH_LONG).show();
            ringTone.play();
        }
    }
}


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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".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="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/optAlarm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Alarm"
            android:checked="true" />

        <RadioButton
            android:id="@+id/optNotification"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Notification" />

        <RadioButton
            android:id="@+id/optRingtone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Ringtone" />

        <RadioButton
            android:id="@+id/optPicker"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ACTION_RINGTONE_PICKER" />

    </RadioGroup>

    <Button
        android:id="@+id/start"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Start"/>

    <Button
        android:id="@+id/stop"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Stop"/>

</LinearLayout>



Monday, June 22, 2015

Generate Alarm, Notification and Ringtone using RingtoneManager

RingtoneManager provides access to ringtones, notification, and other types of sounds. Here is a example to play and stop sound of Alarm, Notification and Ringtone using RingtoneManager.


com.example.androidringtone.MainActivity.java
package com.example.androidringtone;

import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

    RadioButton optAlarm, optNotification, optRingtone;
    Button btnStart, btnStop;
    Ringtone ringTone;

    Uri uriAlarm, uriNotification, uriRingtone;

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

        optAlarm = (RadioButton)findViewById(R.id.optAlarm);
        optNotification = (RadioButton)findViewById(R.id.optNotification);
        optRingtone = (RadioButton)findViewById(R.id.optRingtone);
        btnStart = (Button)findViewById(R.id.start);
        btnStop = (Button)findViewById(R.id.stop);

        uriAlarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        uriNotification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        uriRingtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        optAlarm.setText("uriAlarm: " + uriAlarm);
        optNotification.setText("uriNotification: " + uriNotification);
        optRingtone.setText("uriRingtone: " + uriRingtone);

        btnStart.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                if(ringTone!=null){
                    //previous ringTone is playing,
                    //stop it first
                    ringTone.stop();
                }

                if(optAlarm.isChecked()){
                    ringTone = RingtoneManager
                        .getRingtone(getApplicationContext(), uriAlarm);
                }else if(optNotification.isChecked()){
                    ringTone = RingtoneManager
                        .getRingtone(getApplicationContext(), uriNotification);
                }else if(optRingtone.isChecked()){
                    ringTone = RingtoneManager
                        .getRingtone(getApplicationContext(), uriRingtone);
                }

                Toast.makeText(MainActivity.this,
                    ringTone.getTitle(MainActivity.this),
                    Toast.LENGTH_LONG).show();
                ringTone.play();
            }
        });

        btnStop.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                if(ringTone!=null){
                    ringTone.stop();
                    ringTone = null;
                }
            }
        });
    }

}


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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".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="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/optAlarm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Alarm"
            android:checked="true" />

        <RadioButton
            android:id="@+id/optNotification"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Notification" />

        <RadioButton
            android:id="@+id/optRingtone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Ringtone" />

    </RadioGroup>

    <Button
        android:id="@+id/start"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Start"/>

    <Button
        android:id="@+id/stop"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Stop"/>

</LinearLayout>



Next:
- Android example using ACTION_RINGTONE_PICKER

Head First Android Development

Head First Android Development

What will you learn from this book?

If you have an idea for a killer Android app, this book will help you build your first working application in a jiffy. You’ll learn hands-on how to structure your app, design interfaces, create a database, make your app work on various smartphones and tablets, and much more. It’s like having an experienced Android developer sitting right next to you! All you need is some Java know-how to get started.

Why does this book look so different?

Based on the latest research in cognitive science and learning theory, Head First Android Development uses a visually rich format to engage your mind, rather than a text-heavy approach that puts you to sleep. Why waste your time struggling with new concepts? This multi-sensory learning experience is designed for the way your brain really works.

Tuesday, June 16, 2015

Pro Android 5

Pro Android 5

Pro Android 5 shows you how to build real-world and fun mobile apps using the Android 5 SDK. This book updates the best-selling Pro Android and covers everything from the fundamentals of building apps for smartphones, tablets, and embedded devices to advanced concepts such as custom components, multi-tasking, sensors/augmented reality, better accessories support and much more.
  • Using the tutorials and expert advice, you'll quickly be able to build cool mobile apps and run them on dozens of Android-based smartphones.
  • You'll explore and use the Android APIs, including those for media and sensors.
  • And you'll check out what's new in Android, including the improved user interface across all Android platforms, integration with services, and more.
By reading this definitive tutorial and reference, you'll gain the knowledge and experience to create stunning, cutting-edge Android apps that can make you money, while keeping you agile enough to respond to changes in the future.

What you’ll learn
  • How to use Android to build Java-based mobile apps for Android smartphones and tablets
  • How to build irresistible user interfaces (UIs) and user experiences (UXs) across Android devices
  • How to populate your application with data from data sources, using Content Providers
  • How to build multimedia and game apps using Android's media APIs
  • How to use Android's location-based services, network-based services, and security
  • How to use key Android features, such as Fragments and the ActionBar
Who this book is for
This book is for professional software engineers and programmers looking to move their ideas and applications into the mobile space with Android. It assumes a passable understanding of Java, including how to write classes and handle basic inheritance structures.

Table of Contents
1 Hello, World
2 Introduction to Android Applications
3 Basic User Interface Controls
4 Adapters and List Controls
5 Making Advanced UI Layouts
6 Adding Menus and ActionBar
7 Styles and Themes
8 Fragments
9 Responding to Configuration Changes
10 Dialogs: Regular and Fragment
11 Working with Preferences and Saving State
12 Compatibility Library
13 Exploring Packages, Processes, Components, Threads and Handlers
14 Working with Services
15 Advanced Async Task & Progress Dialogs
16 Exploring Broadcast Receivers and Long Running Services
17 Exploring the Alarm Manager
18 Unveiling 2D Animation
19 Exploring Maps and Location Services
20 Understanding the Media Frameworks
21 Home Screen Widgets
22 Touchscreens
23 Drag and Drop
24 Using Sensors
25 Understanding Content Providers
26 Understanding the Contacts API
27 Loaders
28 Security and Permissions
29 Google Cloud messaging and services
30 Deploying Your Application: Google Play Store and Beyond

Thursday, June 11, 2015

Android Programming In a Day!: The Power Guide for Beginners In Android App Programming

Android Programming In a Day!: The Power Guide for Beginners In Android App Programming

Always had a great idea for an app?
Don't think you could ever do one yourself and the cost is too much to put your idea to market!
Intimidated with all the technical jargon that comes with programming that is keeping you from developing an app?
You do not need to stay out of android programming anymore! This book is for anyone who wants and needs to learn to develop and Android App
Develop an app right from the start! Easy, fast and no technical jargon! Book is written for dummies!

Monday, June 8, 2015

Java Programming 24-Hour Trainer, 2nd edition

Quick and painless Java programming with expert multimedia instruction

Java Programming 24-Hour Trainer

Java Programming 24-Hour Trainer, 2nd Edition is your complete beginner's guide to the Java programming language, with easy-to-follow lessons and supplemental exercises that help you get up and running quickly. Step-by-step instruction walks you through the basics of object-oriented programming, syntax, interfaces, and more, before building upon your skills to develop games, web apps, networks, and automations. This second edition has been updated to align with Java SE 8 and Java EE 7, and includes new information on GUI basics, lambda expressions, streaming API, WebSockets, and Gradle. Even if you have no programming experience at all, the more than six hours of Java programming screencasts will demonstrate major concepts and procedures in a way that facilitates learning and promotes a better understanding of the development process.

This is your quick and painless guide to mastering Java, whether you're starting from scratch or just looking to expand your skill set.
  • Master the building blocks that go into any Java project
  • Make writing code easier with the Eclipse tools
  • Learn to connect Java applications to databases
  • Design and build graphical user interfaces and web applications
  • Learn to develop GUIs with JavaFX
If you want to start programming quickly, Java Programming 24-Hour Trainer, 2nd Edition is your ideal solution.

The Beginner's Guide to Android Game Development

The Beginner's Guide to Android Game Development

Android Game Development Made Easy. If you've always wanted to make Android games but didn't know where to start, this book is for you. Whether you are an absolute beginner with no programming experience or an experienced Java developer wanting to get started with game development, this comprehensive book will help you accomplish your goals and teach you how to build your own games from scratch-no game engines needed.

In this beginner-friendly guide, you will find focused, step-by-step approaches designed to help you learn and practice one fundamental concept at a time. You will study Java and write object-oriented applications. You will experiment with the building blocks of Android and create fun, interactive 2D games with touch controls. You will even learn how to integrate social features such as a global leaderboard and publish your game to be shared with the billion Android users across the world.

This book provides access to an extensive library of sample Java and Android game projects via its companion website so that you can continue learning on your own and grow as a game programmer. With this up-to-date guide in your hand, you will be able to successfully navigate common pitfalls and get up and running with your own projects in no time. Tested on Android Lollipop. All the code in the book has been tested on the Android Lollipop SDK (5.0), and is available under the open source MIT license at the book’s companion site.

Table of Contents:

Unit 1: Java Basics
Chapter 1: The Fundamentals of Programming
Chapter 2: Beginning Java
Chapter 3: Designing Better Objects

Unit 2: Java Game Development
Chapter 4: Laying the Foundations
Chapter 5: Keeping It Simple
Chapter 6: The Next Level

Unit 3: Android Game Development
Chapter 7: Beginning Android Development
Chapter 8: The Android Game Framework
Chapter 9: Building the Game

Unit 4: Finishing Touches
Chapter 10: Releasing Your Game
Chapter 11: Continuing the Journey

Saturday, June 6, 2015

Android example: pass string between threads, in Bundler

This example show how to pass string between Threads, in Bundle, via Handler/Message.


com.example.androidthreadlooperhandler.MainActivity.java
package com.example.androidthreadlooperhandler;

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

public class MainActivity extends ActionBarActivity {

    static final String KEY_STRING_1 = "KEY_STRING_TO_THREAD";
    static final String KEY_STRING_2 = "KEY_STRING_TO_UI";

    public UiHandler uiHandler;

    EditText editText;
    Button btn;
    TextView textInfo;

    MyThread myThread;

    private class UiHandler extends Handler{
        @Override
        public void handleMessage(Message msg) {
            // ...Run in UI Thread
            String strUi = msg.getData().getString(KEY_STRING_2, "no string received from THREAD");
            textInfo.setText(strUi);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = (EditText)findViewById(R.id.edittext);
        btn = (Button)findViewById(R.id.button);
        textInfo = (TextView)findViewById(R.id.info);

        btn.setOnClickListener(btnOnClickListener);

        uiHandler = new UiHandler();
        myThread = new MyThread(uiHandler);
        myThread.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        //stop and quit the background Thread
        myThread.handler.getLooper().quit();
    }

    View.OnClickListener btnOnClickListener =
        new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                if(myThread.handler != null){
                    String str = editText.getText().toString();

                    Bundle bundle = new Bundle();
                    bundle.putString(KEY_STRING_1, str);
                    Message message = myThread.handler.obtainMessage();
                    message.setData(bundle);
                    myThread.handler.sendMessage(message);
                }
            }
        };

    private class MyThread extends Thread{

        public Handler handler;
        private UiHandler callbackHandler;

        MyThread(UiHandler handler){
            callbackHandler = handler;
        }

        public void run(){
            Looper.prepare();
            handler = new MyHandler();
            Looper.loop();
        }

        private class MyHandler extends Handler{
            @Override
            public void handleMessage(Message msg) {
                // ...Run in background

                String str = msg.getData().getString(KEY_STRING_1, "no string received from UI");
                String strRev = new StringBuilder(str).reverse().toString();

                Bundle bundleThread = new Bundle();
                bundleThread.putString(KEY_STRING_2, strRev);
                Message messageThread = callbackHandler.obtainMessage();
                messageThread.setData(bundleThread);
                callbackHandler.sendMessage(messageThread);

            }
        }
    }
}


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:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:orientation="vertical"
    tools:context=".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/edittext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="android-er.blogspot.com"/>

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button 1"/>

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

</LinearLayout>


Friday, June 5, 2015

Android example: bi-direction passing data between UI and background thread using Handler/Message.

Last example show how to use Thread, Handler and Looper in Android. In that example, UI thread pass data to background thread using Handler/Message, background thread update UI (TextView) via runOnUiThread(). It's modified in this example, background thread update UI via Handler/Message also.



In main activity, implement a custom Handler (UiHandler) and instantiate a object, then pass it to background thread via constructor.

com.example.androidthreadlooperhandler.MainActivity.java
package com.example.androidthreadlooperhandler;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

    static final int UIMSG3 = 3;
    static final int UIMSG4 = 4;

    public UiHandler uiHandler;

    Button btn1, btn2;
    TextView textInfo;

    MyThread myThread;

    private class UiHandler extends Handler{
        @Override
        public void handleMessage(Message msg) {
            // ...Run in UI Thread
            int what = msg.what;
            switch (what){
                case UIMSG3:
                    textInfo.setText("UI Message 3");
                    break;
                case UIMSG4:
                    textInfo.setText("UI Message 4");
                    break;
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1 = (Button)findViewById(R.id.button1);
        btn2 = (Button)findViewById(R.id.button2);
        textInfo = (TextView)findViewById(R.id.info);

        btn1.setOnClickListener(btnOnClickListener);
        btn2.setOnClickListener(btnOnClickListener);

        uiHandler = new UiHandler();
        myThread = new MyThread(uiHandler);
        myThread.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        //stop and quit the background Thread
        myThread.handler.getLooper().quit();
    }

    View.OnClickListener btnOnClickListener =
        new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                if(myThread.handler != null){
                    Message message;
                    if(v==btn1){
                        message = myThread.handler.obtainMessage(MyThread.MSG1);
                    }else{
                        message = myThread.handler.obtainMessage(MyThread.MSG2);
                    }
                    myThread.handler.sendMessage(message);
                }
            }
        };

    private class MyThread extends Thread{

        static final int MSG1 = 1;
        static final int MSG2 = 2;

        public Handler handler;
        private UiHandler callbackHandler;

        MyThread(UiHandler handler){
            callbackHandler = handler;
        }

        public void run(){
            Looper.prepare();
            handler = new MyHandler();
            Looper.loop();
        }

        private class MyHandler extends Handler{
            @Override
            public void handleMessage(Message msg) {
                // ...Run in background

                int what = msg.what;
                switch (what){
                    case MSG1:

                        //doing something...
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                        Message callbackMessage3;
                        callbackMessage3 = callbackHandler.obtainMessage(UIMSG3);
                        callbackHandler.sendMessage(callbackMessage3);

                        /*
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                textInfo.setText("Message 1");
                            }
                        });
                        */

                        break;
                    case MSG2:

                        //doing something...
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                        Message callbackMessage4;
                        callbackMessage4 = callbackHandler.obtainMessage(UIMSG4);
                        callbackHandler.sendMessage(callbackMessage4);

                        /*
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                textInfo.setText("Message 2");
                            }
                        });
                        */

                        break;

                }
            }
        }
    }
}


The layout file refer to last example Thread, Handler and Looper in Android.

Next:
Android example: pass string between threads, in Bundler

Wednesday, June 3, 2015

RxJava Essentials

Learn reactive programming to create awesome Android and Java apps

RxJava Essentials

About This Book
  • Create interactive Android apps with Java Reactive Extensions
  • Learn Reactive Programming through real-life examples that you can use in your Android app
  • Beat Android concurrency and threading issues to take your apps to a new level
Who This Book Is For
If you are an experienced Java developer, reactive programming will give you a new way to approach scalability and concurrency in your backend systems, without forcing you to switch programming languages.

In Detail
RxJava―Reactive Extensions for the JVM―is a library for composing asynchronous and event-based programs using Observable sequences for the Java VM, which will help you beat Android platform limitations to create astonishing Android apps.

Starting with some quick background information on the Rx .NET library, this book quickly moves on to your first example. You will understand Observables and learn to filter, transform, or merge them in detail. Next, you will learn how to get rid of Threads, AsyncTasks, and Handlers with Schedulers to create a smooth user experience. Develop an easy, ready-to-go approach to REST API communications and enrich your skills by working with new challenging examples.

By the end of the book, you will have explored the reactive programming world and will have created your first Android app without having to think about threading, networking, concurrency, and collection management.

Tuesday, June 2, 2015

Step-by-step Android Wear Application Development

Step-by-step tutorials that leads you through the essential concepts, tools, and techniques for developing applications for smart watches using the Android Wear SDK. 

Step-by-step Android Wear Application Development

Have you ever thought to yourself: “I wish I had learned to develop iPhone apps when the iPhone first came out”? Very few people had the foresight to act on the fact that computing platforms are continuously getting smaller, cheaper, faster, and more intimate. Computers have evolved from fixed room-sized machines to desktops, laptops, and handheld devices. The same disruptive transition is about to take place again. Only this time, instead of taking your smartphone out of your pocket, the computer has become wearable.

This is a great time to start learning Android Wearable development. Consumers will come to embrace smartwatches because they will be relatively unobtrusive and will allow them to do things that smartphones can’t.

Topics Covered
  • Create native wearable apps using the Android SDK
  • Build consistent UI layouts using Cards and CardFragments
  • Learn all about the Wearable UI Library to build exciting and engaging apps
  • Master the notification framework. Build notifications for handhelds apps that are automatically extended to Android Wear and learn how to build custom notifications on wearables to better support your brand
  • Working with wearable sensors
  • Use the Wearable Data Layer API to create native apps that can communicate securely with a paired smartphone
  • Includes three exciting projects: 1) Build a car catalog app to browse through vehicles, take notes on them, and schedule test drives all within arms reach, 2) Build a fitness app to start, pause or stop a workout session and 3) Build an animated dice game using the handheld device as a remote control or the wearable’s accelerometer sensor to detect shake gestures in order to roll a die. You will learn how to animate shapes, establish a data connection between the mobile and Wear devices, and display a history of dice roll outcomes on the handheld device.

“Alex has written a masterful collection of tutorials, patterns, tips & tricks, and helpful insider hints that developers at any level will appreciate. The example apps are easy yet challenging, fun yet practical, and put together using best practices. You’ll really come away with a strong sense of how to build effective experiences for Google wearables.” 
- Jason Salas, Co-author, Designing & Developing for Google Glass

Who is this book for?

This book is for intermediate developers who know the basics of Android application development and want to quickly get up to speed and start developing apps for Android Wear. If you are a complete beginner to Android, don’t worry. The step-by-step tutorials are easy to follow and each exercise is followed by an in-depth source code explanation. This book is the best way to get a head start now developing apps for Android Wear.

Monday, June 1, 2015

Windows 10 Feature Highlights



It’s the same desktop you know and love, only better. It's quick start up and more security. It's Cortana, a new browser, and a one stop Windows Store. Windows 10 is coming July 29, 2015. Reserve your free upgrade today: windows.com/windows10upgrade