Wednesday, September 11, 2013

Common user experience issues

Android Design in Action: Common UX Issues

This video run through a top-ten-style list of the most common user experience issues.

Monday, September 9, 2013

Html.ImageGetter load image from internet

Last example "Display HTML String with multi images on TextView, with Html.ImageGetter" load image from local drawable. This example demonstrate how to implement Html.ImageGetter() to load image from internet, and also how to handle images from difference source, local drawable and internet.

Html.ImageGetter load image from internet
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.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

String htmlString = "<img src='ic_launcher'><i>Welcome to<i> <b><a href='http://android-coding.blogspot.com'>Android Coding</a></b>"
+ "<br/><br/>"
+ "another image load from internet<br/>"
+ "<img src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0J1W8wEzUTSjkADjFpEGDdnDPs7Jfr21NrP_mjkwwSr18tDcZEBsI2aFCaECLc7e9Pl-Npl8xs-ysiFn8gHj4wynHZPP8dpi2oUShCsM152RYOCquF5L96lR-Y68tvhmzzYuZnkszOtcb/s400/AndroidHtmlTextView_multi_images.png'><br/>";

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

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

htmlTextView.setText(Html.fromHtml(htmlString, new Html.ImageGetter() {

@Override
public Drawable getDrawable(String source) {

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

Drawable drawable = null;
if (source.startsWith("http")) {
// load from internet

URL sourceURL;
try {
sourceURL = new URL(source);
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();
}

} else {
// load from local drawable

int dourceId = getApplicationContext()
.getResources()
.getIdentifier(source, "drawable", getPackageName());

drawable = getApplicationContext().getResources()
.getDrawable(dourceId);

drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
}

return drawable;
}

}, null));

htmlTextView.setMovementMethod(LinkMovementMethod.getInstance());

}

}


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

To solve error of android.os.NetworkOnMainThreadException, read Html.ImageGetter load image from internet, in AsyncTask.

Display HTML String with multi images on TextView, with Html.ImageGetter

Previous example load single image in HTML String with Html.ImageGetter. This example load two different images in HTML String. Because both images in drawable, so we can use a common Html.ImageGetter.

Display HTML String with multi images on TextView, with Html.ImageGetter
Display HTML String with multi images on TextView, with Html.ImageGetter


package com.example.androidhtmltextview;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

String htmlString = "<img src='ic_launcher'><i>Welcome to<i> <b><a href='http://android-coding.blogspot.com'>Android Coding</a></b>" +
"<br/>" +
"<img src='page'><b><a href='https://plus.google.com/b/113141750089533146251/'>My G+ Page</a></b><br/>";

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

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

htmlTextView.setText(Html.fromHtml(htmlString, new Html.ImageGetter(){

@Override
public Drawable getDrawable(String source) {

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

Drawable drawable;
int dourceId =
getApplicationContext()
.getResources()
.getIdentifier(source, "drawable", getPackageName());

drawable =
getApplicationContext()
.getResources()
.getDrawable(dourceId);

drawable.setBounds(
0,
0,
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());

return drawable;
}

}, null));

htmlTextView.setMovementMethod(LinkMovementMethod.getInstance());

}

}


Next: Html.ImageGetter load image from internet

Sunday, September 8, 2013

zxing, multi-format 1D/2D barcode image processing library with clients for Android, Java

ZXing (pronounced "zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages. Our focus is on using the built-in camera on mobile phones to scan and decode barcodes on the device, without communicating with a server. However the project can be used to encode and decode barcodes on desktops and servers as well. We currently support these formats:
  • UPC-A and UPC-E
  • EAN-8 and EAN-13
  • Code 39
  • Code 93
  • Code 128
  • ITF
  • Codabar
  • RSS-14 (all variants)
  • RSS Expanded (most variants)
  • QR Code
  • Data Matrix
  • Aztec ('beta' quality)
  • PDF 417 ('alpha' quality)

link: https://code.google.com/p/zxing/


Android-Universal-Image-Loader, a powerful image loading library for Android

The project Universal Image Loader for Android (Android-Universal-Image-Loader) aims to provide a reusable instrument for asynchronous image loading, caching and displaying. It support Android 2.0+ with tje features:
  • Multithread image loading
  • Possibility of wide tuning ImageLoader's configuration (thread executors, downlaoder, decoder, memory and disc cache, display image options, and others)
  • Possibility of image caching in memory and/or on device's file sysytem (or SD card)
  • Possibility to "listen" loading process
  • Possibility to customize every display image call with separated options
  • Widget support

Android-Universal-Image-Loader screenshoots
Android-Universal-Image-Loader screenshoots

Friday, September 6, 2013

Cardflip Animation

DevBytes: Cardflip Animation

This video shows how the basic graphics and animation APIs can be used to rotate and flip views from different perspectives, as well as how to apply darkening shadow effects onto a View. code: http://developer.android.com/shareables/devbytes/CardFlip.zip

Tuesday, September 3, 2013

Sliding Fragments: animate transition between two fragments

DevBytes Sliding Fragments

How to animate Fragment Transitions.This video discusses several different methods how animations can be incorporated into the transition between two fragments.

code: http://developer.android.com/shareables/devbytes/SlidingFragments.zip