Posted on

Navigation Drawer and AppCompat

ActionBarActivity is deprecated, but Android Studio is still using the one in NavigationDrawer pattern.

Lets try to convert NavigationDrawer to Material Design.

Using libraries (pdf)

Android 5.0 material design style navigation drawer for KitKat (pdf)

ActionBarDrawerToggle icon missing when using AppCompat v22 (pdf)

How do I use DrawerLayout to display over the ActionBar/Toolbar and under the status bar? (pdf)

How To Make Material Design Navigation Drawer With Header View (pdf)

Hello toolbar (pdf)


And I converted usual NavigationDrawer to Material Design: source

Posted on

InputFilter

[code language=”java”]
{
final InputFilter filter = new InputFilter() {
@Override
public CharSequence filter(CharSequence source,
int start, int end, Spanned dest, int dstart,
int dend)
{
for (int i = start; i < end; i++)
{
if (Character.isDigit(source.charAt(i))||Character.isLetter(source.charAt(i)))
{
return "";
}
}
return null;
}
};
answerTXT.setFilters(new InputFilter[]{filter});
[/code]

Posted on

ContextWrapper ContextImpl getBaseContext

ActivityThread casts Application.getBaseContext() to ContextImpl

[code language=”java”]
static ContextImpl getImpl(Context context) {
Context nextContext;
while ((context instanceof ContextWrapper) &&
(nextContext=((ContextWrapper)context).getBaseContext()) != null) {
context = nextContext;
}
return (ContextImpl)context;
}
[/code]

Potential crash when !(context instanceof Activity)

[code language=”java”]
public static Activity unwrap(Context context) {
while (!(context instanceof Activity)) {
ContextWrapper wrapper = (ContextWrapper) context;
context = wrapper.getBaseContext();
}
return context;
}
[/code]