Disable Android 2.3 View overscrolling on prior versions

Android Gingerbread enables by default overscrolling in default orange style, which could be disturbing in many layouts.
To disable it you can use the setOverScrollMode method with the OVER_SCROLL_NEVER parameter, however it is not available on prior Android versions.
Here is a safe solution for all Android versions:

public static void disableOverscroll(View view) {
Class viewCls = view.getClass();
try {
Method m = viewCls.getMethod("setOverScrollMode",
new Class[] { int.class });
int OVER_SCROLL_NEVER = (Integer) viewCls.getField(
"OVER_SCROLL_NEVER").get(view);
m.invoke(view, OVER_SCROLL_NEVER);
} catch (Exception e) {
// swallow
}
}

By alex on Stackoverflow.com

EmailShare

Display only mail apps when calling ACTION_SEND intent

Maybe you have already noticed, that if you invoke the mail sender intent on Android, it may display a lot of installed apps, which can handle text/plain MIME-types, that may confuse the user.
To display only mail-capable apps, use message/rfc822 as the parameter of setType method.

Via Stackoverflow.com

EmailShare

Android 3.x Action Bar customization

The ActionBar UI component has been introduced in Android 3.0 and above, and it seems to become the standard way to use tabs and context/action menus in Android applications.
You may also customize the ActionBar associated to your application in different ways through this great tutorial, however you might run into errors when you wish to override Tab item styles, to resolve this issue,
check this blog for a very straightforward solution. (due to private API issues)

EmailShare

Android push messaging – C2DM

From Android 2.2 and above, push messaging is supported like on Apple iPhone through the C2DM service. The official developer site and blog features a good client example, but this article features a complete guide with server side PHP examples as well.

EmailShare

Hide Android soft keyboard when Activity starts

If you have an EditText on your Activity layout, you might encounter on real devices, that the soft keyboard annoyingly shows up.
The easiest solution to hide it, is to set soft input mode in Activity.onCreate method:
this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

EmailShare

Faster Singleton method in Java

The fastest Singleton design pattern implementation by Bill Pugh:

public class Singleton
{
protected Singleton()
{
// ...
}

private static class SingletonHolder
{
private final static Singleton INSTANCE = new Singleton();
}

public static Singleton getInstance()
{
return SingletonHolder.INSTANCE;
}
}

EmailShare

Easy shadow making around ImageView

If you want a realistic, nice shadow around an image in an ImageView you might configure it with the following layout:

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="6px"
android:paddingTop="4px"
android:paddingRight="8px"
android:paddingBottom="9px"
android:src="@drawable/pic1"/>

Source with shadow image: Stackoverflow.com

Note This solution works best with fitXY scaleType, it does not apply to aspect corrected images. (it can be done with custom Drawable object)

EmailShare

Pull-to-Refresh ListView for Android

Although this kind of list refreshing is rather an iPhone feature, and not really used on Android platform, sometimes it is requested to use.
An easy to use listener-based implementation can be found here by Johan Nilsson.
Alternative version thanks to Guille Polito.

EmailShare

Disabling Edittext input on Android

Disabling Edittext item in Android is not straightforward, because the setDisabled method does allow text input by user.
To prevent user editing use one of the followings:
setKeyListener(null);
or
android:inputType="none"

Source: Stackoverflow.com

EmailShare