Android UI and User Experience has changed dramatically in the recent version(s) and while users generally enjoy the new features, there are still several areas that are left to application-level-DIY-patterns. For developers, this is double challenge, they want to provide users with the bleeding edge UI patterns and at the same time, they have to deal with evolving API, that sometimes changes dramatically.
Presentation covers the gotchas developer might face dealing with ever-moving Android API, and how to utilize Java language and the tools it have to make the experience for developer more pleasant. Typical trends in the API will get analyzed and divided into several areas or "patterns", discussing typical scenarios how these components are designed and implemented.
This talk will propose several such UI patterns, that will compete to become "de facto" standards and details on the implementation, including possible impact on existing API as we have both end users and developers in mind.
The list of patterns/areas discussed in the talk include following :
ActionBar
ListView
TimePicker
KineticGestureComponent
16. @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSpecSize = View.MeasureSpec.getSize(widthMeasureSpec);
tinyGap = widthSpecSize/100;
myComponent.measure(View.MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, View.MeasureSpec.EXACTLY));
// more component’s measuring goes there
setMeasuredDimension(widthSpecSize, newHeight);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
myComponent.layout(x, y, x+myComponent.getMeasuredWidth(), y+titleLabel.getMeasuredHeight());
// more component’s layout goes there
}
36. ACTIONBAR BEHAVIOR
Touch here shows
a menu with options
Touch here moves up in hierarchy
Touch here performs action
Touch here show a menu with options
Any extension should stay consistent with this
57. interface ViewAdapterBinder<T, V> {
public void bindViewToData(V view, T data);
}
public class ArrayViewGroupAdapter<T, V extends ViewGroup> extends ArrayAdapter<T>
BIND DATATOVIEW
58. public View getView(int position, View convertView, ViewGroup parent){
// assign the view we are converting to a local variable
V v = null;
try {
v = (V) convertView;
} catch(ClassCastException ccex) {}
// safe to ignore, keep null to force new instance to be created
// first check to see if the view is null. if so, we have to inflate it.
// to inflate it basically means to render, or show, the view.
if (v == null) {
v = getInstanceOfV();
}
T data = getItem(position);
if (data != null && binder != null) {
binder.bindViewToData(v, data);
} else {
// signal error here
prn.log("Can't bind data to view " + position);
}
// the view must be returned to our activity
return v;
}
59. private V getInstanceOfV() {
ParameterizedType superClass = (ParameterizedType)
getClass().getGenericSuperclass();
Class<V> type = (Class<V>) superClass.getActualTypeArguments()[1];
try {
return type.getDeclaredConstructor(Context.class).newInstance(getContext());
} catch (Exception ex) {
// Oops, no default constructor
throw new RuntimeException(ex);
}
}
60. public class SampleArrayAdapter extends ArrayViewGroupAdapter<SampleData, SampleListItem> {
public SampleArrayAdapter(Context context) {
super(context, new ArrayViewGroupAdapter.ViewAdapterBinder<SampleData, SampleListItem>() {
@Override
public void bindViewToData(SampleListItem view, SampleData data) {
view.setTitle(data.getTitle());
view.setDetails(data.getDetails());
}
});
}
}