Something about processing images in Android

I will do some trial experience about image in Android programming. The list here will be updated once posted.

Related demo video:

The exercises have not take care the bitmap size, and any resizing. So don't test with big picture, otherwise OutOfMemoryError or "Bitmap too large to be uploaded into a texture" will happen.

Rename Package in Eclipse

To rename Package in Eclipse for Android SDK, right click your package to be rename (NOT project), select Refactor > Rename...


Enter your new name of package, make sure the check box of Update references is checked (otherwise you will get numbers of in-correct reference), and click OK to finish.


Ketai: library for the Android Mode in Processing.


Ketai Library for Android Mode in Processing makes it easy to work with hardware devices and sensors built into Android phones and tablets. The library focus specifically on mobile Android features, including cameras, sensors, multi-touch gestures, peer-to-peer networking via Bluetooth and WiFi Direct, Near Field Communication (NFC), and SQLite for local databases.

Project home of ketai

Learn Java for Android Development, Second Edition


February 20, 2013  1430257229  978-1430257226 2

Android development is hot, and many programmers are interested in joining the fun. However, because this technology is based on Java, you should first obtain a solid grasp of the Java language and its foundational APIs to improve your chances of succeeding as an Android app developer. After all, you will be busy learning the architecture of an Android app, the various Android-specific APIs, and Android-specific tools. If you do not already know Java fundamentals, you will probably end up with a massive headache from also having to quickly cram those fundamentals into your knowledge base.

Learn Java for Android Development, Second Edition teaches programmers of any skill level the essential Java language and foundational Java API skills that must be learned to improve the programmer’s chances of succeeding as an Android app developer. Each of the book’s 14 chapters provides an exercise section that gives you the opportunity to reinforce your understanding of the chapter’s material. Answers to the book’s more than 500 exercises are provided in an appendix. A second appendix provides a significant game-oriented Java application, which you can convert into an Android app.

Once you complete this book, you should be ready to dive into beginning Android app development.  Maybe, start that journey with Apress'Beginning Android.

What you’ll learn

  • The Java language:  This book provides complete coverage of nearly every pre-Java version 7 language feature (native methods are briefly mentioned but not formally covered). Starting with basic language features (e.g., comments, types, expressions, and statements), you progress to those features related to classes and objects, followed by object-oriented features related to inheritance, polymorphism, and interfaces. You then explore the advanced language features for nested types, packages, static imports, exceptions, assertions, annotations, generics, and enums. Continuing, you investigate strictfp, synchronized, volatile, the enhanced for loop statement, autoboxing/unboxing, and transient fields.
  • Java APIs:  In addition to Object and APIs related to exceptions, you explore Math, StrictMath, BigDecimal, BigInteger, String, StringBuffer/StringBuilder, Boolean, Character, Byte, Short, Integer, Long, Float, Double, Number, the Threads API, System, Runtime, Process, the Collections Framework, the Concurrency Utilities, Date, Formatter, Random, Scanner, the ZIP and JAR APIs, File, RandomAccessFile, stream classes, and writer/reader classes, InetAddress, SocketOptions, Socket, ServerSocket, DatagramSocket, MulticastSocket, URL, URLConnection, URLEncoder, URLDecoder, NetWorkInterface, InterfaceAddress, CookieHandler, CookieManager, CookieStore, CookiePolicy, Buffer, ByteBuffer, CharBuffer, DoubleBuffer,FloatBuffer, IntBuffer, LongBuffer, ShortBuffer, MappedByteBuffer, Channel, WritableByteChannel, ReadableByteChannel,ScatteringByteChannel, GatheringByteChannel, FileChannel, the Regular Expressions API, JDBC, and more.
  • Applying these:  You will learn how to use the JDK’s javac (compiler), java (application launcher), javadoc (Java documentation generator), and jar (Java archive creator, updater, and extractor) tools. You will also receive an introduction to the Eclipse integrated development environment, which is the official standard for developing Android apps.

Who this book is for

This book is for any programmer - including existing Java programmers and Objective-C-based iPhone and iPad programmers - of any skill level who needs to obtain a solid understanding of the Java language and foundational Java APIs before jumping into Android app development.

Table of Contents

1. Getting Started with Java
2. Learning Language Fundamentals
3. Discovering Classes and Objects
4. Discovering Inheritance, Polymorphism, and Interfaces
5. Mastering Advanced Language Features Part 1
6. Mastering Advanced Language Features Part 2
7. Exploring the Basic APIs Part 1
8. Exploring the Basic APIs Part 2
9. Exploring the Collections Framework
10. Exploring Additional Utility APIs
11. Performing Classic I/O
12. Accessing Networks
13. Migrating to New I/O
14. Accessing Databases
A. Appendix A: Solutions to Exercises
B. Appendix B: Four of a Kind
C. Appendix C: Odds and Ends***


***NOTE:  Appendix C is not included in the physical book. Instead, it's distributed as a PDF file that's bundled with the book's code.  As well as covering updated topics from the previous edition of this book (e.g., References, Reflection, and Preferences), this 138-page appendix includes new content.

Building Hybrid Android Apps with Java and JavaScript: Applying Native Device APIs


Building Hybrid Android Apps with Java and JavaScript: Applying Native Device APIs
Build HTML5-based hybrid applications for Android with a mix of native Java and JavaScript components, without using third-party libraries and wrappers such as PhoneGap or Titanium. This concise, hands-on book takes you through the entire process, from setting up your development environment to deploying your product to an app store.
Learn how to create apps that have access to native APIs, such as location, vibrator, sensors, and the camera, using a JavaScript/Java bridge—and choose the language that gives you better performance for each task. If you have experience with HTML5 and JavaScript, you’ll quickly discover why hybrid app development is the wave of the future.
  • Set up a development environment with HTML, CSS, and JavaScript tools
  • Create your first hybrid Android project, using Eclipse IDE
  • Use the WebView control to host your hybrid application
  • Explore hybrid application architecture, including JavaScript/Java communication
  • Build single-page applications, using JavaScript libraries such as Backbone and Underscore
  • Get optimization tips and useful snippets for CSS, DOM, and JavaScript
  • Distribute your application to Google Play and the Amazon Appstore

YouTube Easter egg that lets you go retro

Youtube go retro
To delebrate the upcoming Geek Week (August 4 - 10), YouTube has released an Easter egg that lets you switch Youtube to retro mode.


answer: enter "/ geekweek" in Youtube search box. Just do it.

New Moto X from Motorola

New Moto X from Motorola

The new Moto X from Motorola is a 4G LTE Android smartphone and features a customizable display, 10 megapixel camera and touchless control.

Android Emulator error libGL.so: cannot open shared object file: No such file or directory

If you run Android Emulator with the error of "libGL.so: cannot open shared object file: No such file or directory", you have to make link for libGL.so.

My machine run Ubuntu 12.04. The following is my solution to fix it. (assume libGL is installed in somewhere in your system)

- Locate your installed libGL:
$locate libGL

- make link to installed libGL.so
$sudo ln -s /usr/lib/i386-linux-gnu/libGLU.so.1 /usr/lib/libGL.so

locate and ln libGL.so


Remark:
Thanks comment by Anonymous:
~ If your system is 64 bit one, you must link to the 64 bit libGL

Android Emulator now support Google Play services SDK

As in the beginning of the year "Google Play services is not supported on the Android emulator". With Android SDK updated, Google Play services SDK is now supported in Android Emulator with AVD that runs the Google APIs platform based on Android 4.2.2 or higher.

If you want to test your app on the emulator, run Android SDK Manager, expand the directory for Android 4.2.2 (API 17) or a higher version, select Google APIs, and install it. Then create a new AVD with Google APIs as the platform target.

Note: Only Android 4.2.2 and higher versions of the Google APIs platform include Google Play services.

Reference: Setup Google Play Services SDK

Remark: Unfortunately, I cannot run my Google Maps Android API V2 examples on Emulator caused by "Google Play services out of date..."!

Make app with translucent background

To make your app with translucent background, apply the following code in your theme.

<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>


For example, modify /res/values/styles.xml (the auto-generated style):
<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->

<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>

</style>

</resources>

Translucent background

Intro to ActionBarCompat Support Library

DevBytes: Intro to ActionBarCompat Support Library

An introduction to this new support library, which allows you to add a compatible Action Bar to your application, targeting Android v2.1 or newer. This DevByte covers integrating the library, from adding it as a dependency to modifying your resources and code. For more information you can visit - http://developer.android.com/guide/topics/ui/actionbar.html

Google Cast Developer Preview

Google Cast is a screen-sharing technology that lets a user send and control content like video from a small computing device like a phone, tablet, or laptop to a large display device like a television.

A sender application running on the sender device uses the Google Cast API appropriate to its operating system to discover and transmit to the receiver application running on the receiver device. You can use the sender APIs to enable your Android, iOS, or Chrome app to send content to a large display.

The receiver device runs a scaled-down Chrome browser with a receiver application that receives data over Internet Protocol and transmits it to the television via HDMI. The receiver API lets you customize the messaging between the sender and receiver applications for authentication and other scenarios.

Google Cast Developer Preview lets you experiment with this unique second-screen functionality in your applications.

You can develop sender applications for Android, iOS, and Chrome which "cast" their content to a receiver device connected to a large display (television), and you can develop a receiver app that extends the default receiver functionality.

Note: You may not publicly distribute or ship your Google Cast application without written permission from Google, per the terms of service described on the Downloads page.

The APIs in this preview release are subject to change. This preview supports the same three platforms that are intended for the released product: Android, iOS, and Chrome. If you are developing a Chrome application, Google will need to whitelist your website for development. This process usually takes only a few days.

Visit Google Cast Developers Site

Bluetooth Low Energy API in Android 4.3

With Android 4.3 comes the Bluetooth Low Energy API. In this DevBytes Fred Chung gives a brief overview of the technology, and how Android supports it at the platform level.


Google Chromecast HDMI Streaming Media Player available at Amazon, $35.00 only


  • Stream online video, music and more to your TV using your smartphone, tablet, or laptop
  • Supports Netflix, YouTube, Google Play, as well as anything on the web through Chrome browser
  • Works with Android, iOS, Chrome for Mac, and Chrome for Windows
  • Easy setup: Plug into any HDTV and connect to your home WiFi network
  • Box includes Chromecast, HDMI extender, USB power cable, and power adapter


Android 4.3 announced and Developer Tools updated

Android 4.3 of Jelly Bean announced, includes great new features for users and developers. Android 4.3 powers the new Nexus 7 tablet and it’s rolling out now as an update to Nexus 4, Nexus 7, Nexus 10, and Galaxy Nexus HSPA+ devices across the world.

For developers, Android 4.3 includes the latest performance enhancements to keep your apps fast, smooth, and efficient, together with new APIs and capabilities to use in your apps.

Know more: http://android-developers.blogspot.hk/2013/07/android-43-and-updated-developer-tools.html

Determine event source in event listener

Last example demonstrate a "Simple example of Button and OnClickListener", with individual OnClickListener for each View. Alternatively, we can have a common OnClickListener for more than one View, then determine event source in event listener, and perform the correspond operation accordingly.

Determine event source in event listener


package com.example.androidbutton;

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

public class MainActivity extends Activity implements OnClickListener{

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

LinearLayout myBackGround = (LinearLayout)findViewById(R.id.mybackground);
myBackGround.setOnClickListener(this);

TextView myWeb = (TextView)findViewById(R.id.myweb);
myWeb.setOnClickListener(this);

Button button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(this);

Button button2 = (Button)findViewById(R.id.button2);
button2.setOnClickListener(this);

ImageView myImage =(ImageView)findViewById(R.id.myimage);
myImage.setOnClickListener(this);
}

@Override
public void onClick(View v) {
if(v.getClass() == TextView.class){
Toast.makeText(getApplicationContext(),
"It's TextView:\n" + ((TextView)v).getText(),
Toast.LENGTH_SHORT).show();
}else if(v.getClass() == Button.class){
Toast.makeText(getApplicationContext(),
"It's Button:\n" + ((Button)v).getText(),
Toast.LENGTH_SHORT).show();
}else if(v.getClass() == ImageView.class){
Toast.makeText(getApplicationContext(),
"It's ImageView:",
Toast.LENGTH_SHORT).show();

//setRotation require API Level 11
float rot = ((ImageView)v).getRotation() + 90;
((ImageView)v).setRotation(rot);

}else{
Toast.makeText(getApplicationContext(),
"Background clicked",
Toast.LENGTH_SHORT).show();
}
}

}


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

<TextView
android:id="@+id/myweb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-er.blogspot.com" />

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 1"/>
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 2"/>
<ImageView
android:id="@+id/myimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>

</LinearLayout>


Simple example of Button and OnClickListener

Basic example of Button and OnClickListener to handle button click:

package com.example.androidbutton;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

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

Button button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(),
"Button 1 clicked",
Toast.LENGTH_LONG).show();
}});

Button button2 = (Button)findViewById(R.id.button2);
button2.setOnClickListener(button2OnClickListener);
}

OnClickListener button2OnClickListener =
new OnClickListener(){

@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),
"Button 2 clicked",
Toast.LENGTH_LONG).show();
}};

}


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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-er.blogspot.com" />

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

</LinearLayout>

Simple example of Button


Next:
- Determine event source in event listener

OpenWeatherMap - free weather data and forecast API

The OpenWeatherMap service provides free weather data and forecast API suitable for any cartographic services like web and smartphones applications. Ideology is inspired by OpenStreetMap and Wikipedia that make information free and available for everybody. OpenWeatherMap provides wide range of weather data such as map with current weather, week forecast, precipitation, wind, clouds, data from weather Stations and many others. Weather data is received from global Meteorological broadcast services and more than 40 000 weather stations.

OpenWeatherMap

Gradle Beyond the Basics - read online for FREE

Gradle Beyond the Basics

If you’re familiar with Gradle’s basics elements—possibly through the author’s previous O’Reilly book, Building and Testing with Gradle—this more advanced guide provides the recipes, techniques, and syntax to help you master this build automation tool. With clear, concise explanations and lots of ready-to-use code examples, you’ll explore four discrete areas of Gradle functionality: file operations, custom Gradle plugins, build lifecycle hooks, and dependency management.

Learn how to use Gradle’s rich set of APIs and Groovy-based Domain Specific Language to customize build software that actually conforms to your product. By using the techniques in this book, you’ll be able to write domain-specific builds that support every other line of code your team creates.




  • Examine Gradle’s file API, including copy tasks, pattern matching, content filtering, and the FileCollection interface
  • Understand the process for building and packaging a custom Gradle plug-in
  • Manage build complexity with hook methods and Gradle’s rule feature
  • Learn how Gradle handles dependency management natively and through customization
  • Explore Gradle’s core plug-ins as well as key examples from the Gradle community

read online: http://chimera.labs.oreilly.com/books/1234000001741

Require more memory for App to run

To request more memory for App to run, you can specify android:largeHeap="true" in <application>. android:largeHeap specify Whether your application's processes should be created with a large Dalvik heap.

reference: http://developer.android.com/guide/topics/manifest/application-element.html#largeHeap

Android Studio 0.2.1 Released with Gradle fix

Example to specify View with half width




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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="http://android-er.blogspot.com/"
android:background="#D0D0D0" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="<Space> require API 14"
android:background="#B0B0B0" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Use weightSum and layout_weight"
android:background="#909090" />
</LinearLayout>

</LinearLayout>


50 Android Hacks



50 Android Hacks

The best programming techniques are often the shortest and simplest—the hacks. In this compact and infinitely useful book, Android expert Carlos Sessa delivers 50 hacks that will save you time, stretch your skills, and maybe even make you smile.

About this Book

Hacks. Clever programming techniques to solve thorny little problems. Ten lines of code that save you two days of work. The little gems you learn from the old guy in the next cube or from the geniuses on Stack Overflow. That's just what you'll find in this compact and useful book.
The name 50 Android Hacks says it all. Ranging from the mundane to the spectacular, each self-contained, fully illustrated hack is just a couple of pages long and includes annotated source code. These practical techniques are organized into twelve collections covering layout, animations, patterns, and more.

What's Inside
  • Hack 3 Creating a custom ViewGroup
  • Hack 8 Slideshow using the Ken Burns effect
  • Hack 20 The Model-View-Presenter pattern
  • Hack 23 The SyncAdapter pattern
  • Hack 31 Aspect-oriented programming in Android
  • Hack 34 Using Scala inside Android
  • Hack 43 Batching database operations
  • Plus 43 more hacks!
Most hacks work with Android 2.x and greater. Version-specific hacks are clearly marked.
Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the Author


Carlos Sessa is a passionate professional Android developer. He's active on Stack Overflow and is an avid hack collector.

Table of Contents
  1. Working your way around layouts
  2. Creating cool animations
  3. View tips and tricks
  4. Tools
  5. Patterns
  6. Working with lists and adapters
  7. Useful libraries
  8. Interacting with other languages
  9. Ready-to-use snippets
  10. Beyond database basics
  11. Avoiding fragmentation
  12. Building tools

Apply animation on TextView

Apply animation on TextView


To create animation, create xml file to define animation in /res/anim/ folder, /res/anim/myanimation.xml.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<scale
android:fromXScale="1.0"
android:toXScale="0.8"
android:fromYScale="1.0"
android:toYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
android:duration="100"
android:repeatCount="4"
android:repeatMode="reverse" />
</set>


In Java code, create Animation of the anim resource file with AnimationUtils.loadAnimation() method, and start the animation with startAnimation() method of the target view.
package com.example.androidtextview;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
import android.app.Activity;

public class MainActivity extends Activity {

Animation myAnimation;
TextView myText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myText = (TextView)findViewById(R.id.mytext);

myAnimation = AnimationUtils.loadAnimation(this, R.anim.myanimation);

myText.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
myText.startAnimation(myAnimation);
}});
}

}


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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal" />

<TextView
android:id="@+id/mytext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="#0000ff" />

</LinearLayout>



Implement auto-running TextView



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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal" />

<TextView
android:id="@+id/shadowtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
android:textSize="50sp"
android:textColor="#0000ff"

android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever" />

</LinearLayout>




Updated@2016-08-30:
Have to set the TextView selected also, refer "Auto scrolling (horizontal running) TextView".

Add shadow for TextView, using Java code.


To add shadow on TextView using Java code, call setShadowLayer() method.

package com.example.androidtextview;

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

public class MainActivity extends Activity {

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

TextView shadowText = (TextView)findViewById(R.id.shadowtext);
shadowText.setShadowLayer(30, 10, 10, 0xFF303030);

}

}


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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal" />

<TextView
android:id="@+id/shadowtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="#0000ff" />

</LinearLayout>


Related: compare to Add shadow for TextView, using XML.

Add shadow for TextView, using XML.

TextView with shadow

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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="#0000ff"
android:shadowColor="#303030"
android:shadowDx="10"
android:shadowDy="10"
android:shadowRadius="30" />

</LinearLayout>


Related: compare with Add shadow for TextView, using Java code.


Example to implement shape of oval with gradient color

shape of oval

To implement shape using "oval", create /res/drawable/myshape.xml to define the shape.
<shape 
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid
android:color="#e0e0e0" />
<stroke
android:width="5dip"
android:color="#505050"/>
<gradient
android:startColor="#FFFF0000"
android:endColor="#800000FF"
android:angle="45"/>
</shape>


Apply the shape on layout background, modify /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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal"
android:background="#B0B0B0" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:gravity="center_horizontal"
android:background="@drawable/myshape"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
android:textColor="@android:color/black"
android:gravity="center"
android:background="@drawable/myshape" />

</LinearLayout>


Android Security: Attacks and Defenses



Android Security: Attacks and Defenses is for anyone interested in learning about the strengths and weaknesses of the Android platform from a security perspective. Starting with an introduction to Android OS architecture and application programming, it will help readers get up to speed on the basics of the Android platform and its security issues.

Explaining the Android security model and architecture, the book describes Android permissions, including Manifest permissions, to help readers analyze applications and understand permission requirements. It also rates the Android permissions based on security implications and covers JEB Decompiler.

The authors describe how to write Android bots in JAVA and how to use reversing tools to decompile any Android application. They also cover the Android file system, including import directories and files, so readers can perform basic forensic analysis on file system and SD cards. The book includes access to a wealth of resources on its website: www.androidinsecurity.com. It explains how to crack SecureApp.apk discussed in the text and also makes the application available on its site.

The book includes coverage of advanced topics such as reverse engineering and forensics, mobile device pen-testing methodology, malware analysis, secure coding, and hardening guidelines for Android. It also explains how to analyze security implications for Android mobile devices/applications and incorporate them into enterprise SDLC processes.

The book’s site includes a resource section where readers can access downloads for applications, tools created by users, and sample applications created by the authors under the Resource section. Readers can easily download the files and use them in conjunction with the text, wherever needed. Visit www.androidinsecurity.com for more information.

Android Studio upgrade 0.2.0

download updated Android Studio and installation instruction: http://developer.android.com/sdk/installing/studio.html

Graphical Layout Editor of ADT

ADT provides many features to allow you to design and build your application's user interface. Many of these features are in the graphical layout editor, which you can access by opening one of your application's XML layout files in Eclipse.

Graphical Layout Editor of ADT


Know more: Android Developer Tools - Graphical Layout Editor

Learn about the new Google Maps app for Android

Implement custom shape for background

custom shape for background


To implement our custom shape, create xml file to define our shape in res/drawable/ folder, /res/drawable/myshape.xml.
<shape 
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#e0e0e0" />
<stroke
android:width="5dip"
android:color="#505050"/>
</shape>


Apply the shape on view with android:background="@drawable/myshape" in layout xml file.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal"
android:background="#B0B0B0" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:gravity="center_horizontal"
android:background="@drawable/myshape"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
android:textColor="@android:color/black"
android:gravity="center"
android:background="@drawable/myshape" />

</LinearLayout>


Implement vertical TextView by calling setRotation()

API Level 11 provide setRotation(float rotation) method to rotate a View. We can call the method of TextView object to make it display in vertical.

vertical TextView

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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal"
android:background="#B0B0B0" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<TextView
android:id="@+id/verticaltextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android-er"
android:textStyle="bold"
android:textColor="#00FF00"
android:layout_gravity="center"
android:background="#808080" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
android:textColor="@android:color/white"
android:gravity="center"
android:background="#505050" />

</LinearLayout>

</LinearLayout>


Java code, call setRotation() to display the TextView (verticalTextView) in vertical.
package com.example.androidtextview;

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

public class MainActivity extends Activity {

TextView verticalTextView;

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

verticalTextView = (TextView)findViewById(R.id.verticaltextview);
verticalTextView.setRotation(90);
}


}


remark: Have to modify AndroidManifest.xml to set android:minSdkVersion="11" or higher.

GPS / Database ANDROID Programming


This book is a step-by-step guide for developing 'gps', a full-fledged Android app. It also can be used as an intro book on Android programming. 

The gps app:
• locates the user's position on the map
• e-mails the location in a URL form that positions the location on the Google Maps Web page
• inserts the current location of the user into the SQLite database
• retrieves locations from the database and places them in a list view. The user then chooses to view locations from the list on the map.
• allows the user to tap on the screen to place markers and find the latitude, longitude pair of the point pressed
• translates the name of a city or place to latitude, longitude and marks the location on the map

Topics covered are:
• Basics of the Eclipse IDE 
• XML and Java Programming 
• Screen layouts
• Global Positioning System (GPS)
• Google Maps
• SQLite Database development
• Marker and Overlays design
• App installation on the smartphone device

The book Includes complete source code commentary and a companion site for downloading the .java, .xml and .png files and the gps.apk.

Examples to center TextView

Examples to center TextView with XML:

Examples to center TextView


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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal"
android:background="#B0B0B0" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Android-er"
android:textStyle="bold"
android:gravity="center_horizontal"
android:background="#808080" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
android:textColor="@android:color/white"
android:gravity="center"
android:background="#505050" />

</LinearLayout>


VirtualBox 4.2.16 released with Windows 8.1 Preview supported

VirtualBox 4.2.16 released with Windows 8.1 Preview supported.

See the changelog for what has changed.

eBook: Android 4 App Development Essentials

Android 4 App Development Essentials

The goal of this book is to teach the skills necessary to develop Android based applications using the Eclipse Integrated Development Environment (IDE) and the Android 4.2 Software Development Kit (SDK).

Beginning with the basics, this book provides an outline of the steps necessary to set up an Android development and testing environment. An introduction to the architecture of Android is followed by an in-depth look at the design of Android applications and user interfaces. More advanced topics such as database management, content providers, intents and services are also covered, as are touch screen handling, gesture recognition, camera access and the playback and recording of both video and audio.

In addition to covering general Android development techniques, the book also includes Google Play specific topics such as using the Google Play In-App Billing API, implementing maps using the Google Maps Android API and submitting apps to the Google Play Developer Console.

Assuming you already have some Java programming experience, are ready to download Eclipse and the Android SDK, have access to a Windows, Mac or Linux system and ideas for some apps to develop, you are ready to get started.

Table of Contents

  • Setting up an Android Development Environment
  • Creating an Android Virtual Device (AVD)
  • Creating an Example Android Application
  • Testing Android Applications on a Physical Android Device with ADB
  • An Overview of the Android Architecture
  • The Anatomy of an Android Application
  • Understanding Android Application and Activity Lifecycles
  • Handling Android Activity State Changes
  • Android Activity State Changes – An Example Application
  • Saving and Restoring the User Interface State of an Android Activity
  • Understanding Android Views, View Groups and Layouts
  • Designing an Android User Interface using the Graphical Layout Tool
  • Creating an Android User Interface in Java Code
  • Using the Android GridLayout Manager in the Graphical Layout Tool
  • Working with the Android GridLayout in XML Layout Resources
  • An Overview and Example of Android Event Handling
  • Detecting Common Gestures using the Android Gesture Detector Class
  • Implementing Android Custom Gesture and Pinch Recognition
  • An Introduction to Android Fragments
  • Using Fragments in Android – A Worked Example
  • An Android Master/Detail Flow Tutorial
  • Creating and Managing Overflow Menus on Android
  • An Overview of Android Intents
  • Android Explicit Intents – A Worked Example
  • Android Implicit Intents – A Worked Example
  • Android Broadcast Intents and Broadcast Receivers
  • A Basic Overview of Android Threads and Thread handlers
  • An Overview of Android Started and Bound Services
  • Implementing an Android Started Service – A Worked Example
  • Android Local Bound Services – A Worked Example
  • Android Remote Bound Services – A Worked Example
  • An Overview of Android SQLite Databases
  • An Android TableLayout and TableRow Tutorial
  • An Android SQLite Database Tutorial
  • Understanding Android Content Providers
  • An Android Content Provider Tutorial
  • Implementing Video Playback on Android using the VideoView and MediaController Classes
  • Video Recording and Image Capture on Android using Camera Intents
  • Android Audio Recording and Playback using MediaPlayer and MediaRecorder
  • Working with the Google Maps Android API
  • Handling Different Android Devices and Displays
  • Signing and Preparing an Android Application for Release
  • Integrating Google Play In-app Billing into an Android Application . A Tutorial

  • Read online for free: Android 4 App Development Essentials