initial functionality

based on port from Objective-C. Need to improve rotation handling