Wednesday, November 26, 2014

fplutil - libraries and tools help developing for Android and other platforms

fplutil is a set of small libraries and tools that can be useful when developing applications for Android and other platforms.

Components
  • build_all_android is an all-in-one build script that allows you to build, install and run native (C/C++) Android apps from the command line. This is ideal for build automation, but can also be in a developer’s compile/run loop.
  • buildutil performs the configuration, build and archive steps of Android and Linux C/C++ applications using a suite of Python modules. This suite of modules can automate builds in a continuous integration environment.
  • android_ndk_perf is a desktop tool that enables native (C/C++) developers to measure the CPU utilization of their applications on Android, guiding their optimization efforts.
  • libfplutil enables C/C++ developers to write traditional applications (like Hello World) using "main()" and "printf()" on Android.
Visit: http://google.github.io/fplutil/



Monday, November 24, 2014

Customize Toast to show longer duration

This example show how to customize Toast to show longer duration, by using CountDownTimer to call toast.show() repeatly. And also show how to make the toast counting.


package com.example.androidtoastduration;

import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import android.os.Bundle;
import android.os.CountDownTimer;


public class MainActivity extends ActionBarActivity {

Button text1, text2, text3, text4;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text1 = (Button)findViewById(R.id.text1);
text2 = (Button)findViewById(R.id.text2);
text3 = (Button)findViewById(R.id.text3);
text4 = (Button)findViewById(R.id.text4);

text1.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
Toast.makeText(
MainActivity.this,
"LENGTH_SHORT",
Toast.LENGTH_SHORT).show();
}});

text2.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
Toast toast = Toast.makeText(
MainActivity.this,
"10 second - Not Work!",
Toast.LENGTH_SHORT);
toast.setDuration(10000); //set duration, not work
toast.show();
}});

text3.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
final Toast toast = Toast.makeText(
MainActivity.this,
"10 second",
Toast.LENGTH_SHORT);
toast.show();

new CountDownTimer(10000, 1000)
{
public void onTick(long millisUntilFinished) {
toast.show();
}

public void onFinish() {
toast.cancel();

}
}.start();
}});

text4.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
final Toast toast = Toast.makeText(
MainActivity.this,
"10 second",
Toast.LENGTH_SHORT);
toast.show();

new CountDownTimer(10000, 1000)
{
int count = 10;

public void onTick(long millisUntilFinished) {
toast.show();
count--;
toast.setText(count + " sec");
}

public void onFinish() {
toast.cancel();

}
}.start();
}});
}

}

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

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

<Button
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:textStyle="bold"
android:text="LENGTH_SHORT" />

<Button
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:textStyle="bold"
android:text="10 sec Toast - NOT Work!" />

<Button
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:textStyle="bold"
android:text="10 sec Toast" />

<Button
android:id="@+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:textStyle="bold"
android:text="10 sec counting Toast" />

</LinearLayout>

Thursday, November 20, 2014

Introduction to Android Auto


Timothy Jordan Introduces Android Auto. Android Auto brings the Android platform to the car in a way that's optimized for the driving experience. It's the same Google platform you already use for phones, tablets, televisions, watches, and more. In fact, all these experiences will often be in the same APK. But now, your app can also extend to the car in a way that's safer and more efficient for the driver. So drivers can stay connected with their hands on the wheel and their eyes on the road.

Using Android Auto is easy. Users go to the Google Play store and download apps that support Android Auto onto their phone.. When they connect their phone to the car, the phone goes into car mode and casts the Android Auto experience to the car's screen. This means that although all the apps and services are actually running on the phone, they're displayed in the car's dash. Users interact with them using the vehicle's controls such as a built-in touchscreen and microphone.

Wednesday, October 29, 2014

Android TV - Using the Leanback library

The LeanBack Support Library makes it easy and fast to build great looking Android TV apps. Ankur Kotwal covers the key components to get you started building apps for Android TV using this library.

DevBytes: Android TV - Using the Leanback library

Thursday, October 9, 2014

Google Play services 6.1

Learn about Google Play services 6.1 in this DevByte from Magnus Hyttsten. Google Play services 6.1 adds Enhanced Ecommerce analytics support from Google Tag Manager and offers new improvements to the Google Drive Android API. With this release, we're also including a refresh of the Google Fit developer preview, so that you can test your fitness apps on any Android device.

Google Play services 6.1

Wednesday, October 8, 2014

Html.ImageGetter load image from internet, in AsyncTask

This example code use Html.ImageGetter load image from internet, in AsyncTask, to solve error of android.os.NetworkOnMainThreadException in the old example Html.ImageGetter load image from internet.

package com.example.androidhtmltextview;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import android.support.v7.app.ActionBarActivity;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

public class HttpGetDrawableTask extends AsyncTask<String, Void, Drawable> {

TextView taskTextView;
String taskHtmlString;

HttpGetDrawableTask(TextView v, String s) {
taskTextView = v;
taskHtmlString = s;
}

@Override
protected Drawable doInBackground(String... params) {
Drawable drawable = null;
URL sourceURL;
try {
sourceURL = new URL(params[0]);
URLConnection urlConnection = sourceURL.openConnection();
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
BufferedInputStream bufferedInputStream = new BufferedInputStream(
inputStream);
Bitmap bm = BitmapFactory.decodeStream(bufferedInputStream);

// convert Bitmap to Drawable
drawable = new BitmapDrawable(getResources(), bm);

drawable.setBounds(0, 0, bm.getWidth(), bm.getHeight());

} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return drawable;
}

@Override
protected void onPostExecute(Drawable result) {

final Drawable taskDrawable = result;

if (taskDrawable != null) {
taskTextView.setText(Html.fromHtml(taskHtmlString,
new Html.ImageGetter() {

@Override
public Drawable getDrawable(String source) {
return taskDrawable;
}
}, null));
}

}

}

TextView htmlTextViewRemote;

String htmlStringRemote = "Image load from internet"
+ "<img src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0J1W8wEzUTSjkADjFpEGDdnDPs7Jfr21NrP_mjkwwSr18tDcZEBsI2aFCaECLc7e9Pl-Npl8xs-ysiFn8gHj4wynHZPP8dpi2oUShCsM152RYOCquF5L96lR-Y68tvhmzzYuZnkszOtcb/s400/AndroidHtmlTextView_multi_images.png'>";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

htmlTextViewRemote = new TextView(this);
setContentView(htmlTextViewRemote);

htmlTextViewRemote.setText(Html.fromHtml(htmlStringRemote,
new Html.ImageGetter() {

@Override
public Drawable getDrawable(String source) {

Toast.makeText(getApplicationContext(), source,
Toast.LENGTH_LONG).show();

HttpGetDrawableTask httpGetDrawableTask = new HttpGetDrawableTask(
htmlTextViewRemote, htmlStringRemote);
httpGetDrawableTask.execute(source);

return null;
}

}, null));

htmlTextViewRemote.setMovementMethod(LinkMovementMethod.getInstance());

}

}

In order to load image from internet, permission of "android.permission.INTERNET" have to be added in AndroidManifest.xml.