From 8a9dab5a8faa9659f8ba610b1b176ceb09a16640 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 5 May 2014 01:49:10 -0400 Subject: Load the default gestures --- src/us/minak/SettingsUtil.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src') diff --git a/src/us/minak/SettingsUtil.java b/src/us/minak/SettingsUtil.java index c3c0603..8fe710f 100644 --- a/src/us/minak/SettingsUtil.java +++ b/src/us/minak/SettingsUtil.java @@ -3,7 +3,11 @@ package us.minak; import android.content.ContextWrapper; import android.gesture.GestureLibrary; import android.gesture.GestureLibraries; + import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; public class SettingsUtil { private static File sGestureFile = null; @@ -12,6 +16,21 @@ public class SettingsUtil { public static File getGestureFile(ContextWrapper context) { if (sGestureFile == null) sGestureFile = new File(context.getExternalFilesDir(null), "gestures.ttf"); + // If the gestures file doesn't exist, copy the default gestures to it + if (!sGestureFile.exists()) { + try { + InputStream in = context.getResources().openRawResource(R.raw.gestures); + OutputStream out = new FileOutputStream(sGestureFile); + byte[] buf = new byte[1024]; + int len; + while ( (len = in.read(buf, 0, buf.length)) != -1) + out.write(buf, 0, len); + in.close(); + out.close(); + } catch (Exception e) { + // TODO: better error handling + } + } return sGestureFile; } public static GestureLibrary getGestureLibrary(ContextWrapper context) { -- cgit v1.2.3