gui: PatternPassword: allow any N*N grid

Rather than only supporting a 3x3 grid, allow for multiple grid sizes
(using the CyanogenMod method of generating passphrases for non-3x3
grids). Also fix the detection of touches, as the old code was far too
sensitive for larger grids (and also didn't make much sense).

Change-Id: I343ef654e6d29ce0cb790a28281be7c7c9b171d9
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
diff --git a/gui/devices/portrait/res/portrait.xml b/gui/devices/portrait/res/portrait.xml
index 9c23067..b7e79e9 100644
--- a/gui/devices/portrait/res/portrait.xml
+++ b/gui/devices/portrait/res/portrait.xml
@@ -58,6 +58,10 @@
 			<sort name="tw_gui_sort_order" />
 		</style>
 
+		<style name="patternpassword">
+			<size name="tw_gui_pattern_grid_size" default="3" />
+		</style>
+
 		<style name="partitionlist">
 			<style name="scrolllist" />
 			<icon selected="checkbox_true" unselected="checkbox_false" />
@@ -3382,10 +3386,12 @@
 			<object type="text">
 				<condition var1="tw_password_fail" var2="1" />
 				<font resource="font" color="%text_fail_color%"/>
-				<placement x="%center_x%" y="%row2_text_y%" placement="5" />
+				<placement x="%center_x%" y="%row1_text_y%" placement="5" />
 				<text>Pattern Failed, Please Try Again</text>
 			</object>
 
+			<object type="template" name="pattern_options" />
+
 			<object type="patternpassword">
 				<placement x="%pattern_x%" y="%pattern_y%" w="%pattern_width%" h="%pattern_width%" />
 				<dot color="%pattern_dot_color%" activecolor="%pattern_dot_color_active%" radius="%pattern_dot_radius%" />
@@ -3395,7 +3401,7 @@
 			</object>
 
 			<object type="button">
-				<placement x="%col_center_x%" y="%row4_y%" />
+				<placement x="%col_center_x%" y="%pattern_cancel_y%" />
 				<text>Cancel</text>
 				<actions>
 					<action function="set">tw_page_done=1</action>