This plugin allow you to generate Android graphics from sketch.
How to install plugin
If you want determine click from not rectangle figures.
Create complicated custom view.
Text
Rectangle (Not supported, but you can convert it in vector path)
Circle
Vector
Line
Fill and border
Styles
Shadow (Not supported)
Change your paths in options.js
var options = {
template : {
path : '/Users/{user}/Library/Application\ Support/com.bohemiancoding.sketch3/Plugins/android-custom-view.sketchplugin/Contents/Sketch/templates/ScrollView.java'
} ,
out :{
path : '/Users/{user}/Documents/' ,
packageName : 'com.example.plugin' ,
viewName : 'CustomScrollView'
}
} ;
Create new sketch file, add artboard with positions (0,0).
Make names your shapes with '#'
Select your shapes.
Plugins -> AndroidVectorView -> Generate custom view.
Find you custom view in path witch your determine in (3).
For default all shapes added for click listener. Default template.
//handle clicks
@ Override public boolean onSingleTapConfirmed (MotionEvent e ) {
mPoint .x = (int ) e .getX () + mScroll .x ;
mPoint .y = (int ) e .getY () + mScroll .y ;
boolean handled = false ;
//check in all shapes
for (int i = 0 ; i < mRegions .size (); i ++) {
//if touched any shape
if (mRegions .valueAt (i ).contains (mPoint .x , mPoint .y )) {
showMessage ("Click on " + mRegions .keyAt (i ));
handled = true ;
}
}
return handled ;
}
You can determine custom template for class view and set it in options.js