Droidcon2013 android experience lahoda
- 7. public static String cc(int depth) {
if(skipCallStackCode == true) {
return NA; // short-circuit for production
}
StackTraceElement[] ste = getStackTrace(null);
int depthCount = 0;
boolean shallowFlag = true;
for(StackTraceElement element : ste) {
if(prn.class.getName().equals(element.getClassName()) == true) {
// always ignore elements that are above this class in the stack
shallowFlag = false;
} else {
if(shallowFlag == false) {
if(depthCount >= depth) {
String name = element.getFileName();
if(name != null) {
if(name.endsWith(".java")) {
name = name.substring(0, name.length()-5);
}
} else {
name ="[?]";
}
return name;
} else {
depthCount++;
}
}
}
}
return NA_BUG;
}
HOW DOES IT WORK ?
- 17. @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
}
- 37. 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
- 47. 2D JUST ON OVERFLOW
ACTIONS ARE EITHERTOUCH
OR SWIPE DOWN
- 52. BROADCAST DETAILS
private Intent splitIntent;
splitIntent = new Intent();
splitIntent.setAction("actiwerks.intent.splitview");
splitIntent.removeExtra("APP_SPLIT_SIZE");
splitIntent.putExtra("APP_SPLIT_SIZE", windowVerticalOffset);
getContext().sendBroadcast(splitIntent);
- 53. RECEIVETHE BROADCAST
<receiver android:name="AppSplitViewReceiver" >
<intent-filter>
<action android:name="actiwerks.intent.splitview" />
</intent-filter>
</receiver>
public class AppSplitViewReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction() != null &&
intent.getAction().equals("actiwerks.intent.splitview")) {
int peekSize = intent.getIntExtra("APP_SPLIT_SIZE", -1);
// Handle the intent in the app, resize the window/layout accordingly
}
}
}
- 58. interface ViewAdapterBinder<T, V> {
public void bindViewToData(V view, T data);
}
public class ArrayViewGroupAdapter<T, V extends ViewGroup> extends ArrayAdapter<T>
BIND DATATOVIEW
- 59. 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;
}
- 60. 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);
}
}
- 61. 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());
}
});
}
}
- 76. SHAKE GESTURE
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake) {
[self showAlert];
}
}
//When a gesture is detected (and ended) the showAlert method is called.
-(IBAction)showAlert
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"ShakeGesture Demo"
message:@"Shake detected"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}