34 |
35 |
36 |
--------------------------------------------------------------------------------
/Documents/Notes.txt:
--------------------------------------------------------------------------------
1 | Key graphics are drawn from the stock Android open-source keyboard.
2 |
3 | Unpressed key background: btn_keyboard_key_normal_holo_light
4 | Pressed key background: btn_keyboard_key_pressed_klp_light
5 | Shift "on" indicator: btn_keyboard_key_normal_on_ics_dark
6 | Shift "off" indicator: btn_keyboard_key_pressed_off_klp_dark
7 | Whole keyboard background: keyboard_background_holo
8 |
9 | Many of these stock images are semi-transparent, and contain a translucent glow or shadow around the
10 | on/off indicator. To pull that translucent outline from the original image and copy it onto a new
11 | one, I used the Gimp "set color to alpha" tool. The general technique is this:
12 |
13 | 1. Open the original image with the shift indicator in Gimp.
14 | 2. In a layer below it, create a layer filled with the color from keyboard_background_holo
15 | 3. Merge the two layers together (so the combined image is no longer transparent)
16 | 4. Select and cut out the central, opaque part of the indicator.
17 | 5. Now, you'll have the key itself, which is mostly a solid background color, and a bit of it will
18 | have the translucent glow/shadow on it.
19 | 6. Use the color picker to pick the color of the solid background of the key.
20 | 7. Now use the Select By Color tool to delete all of the solid colored part of the key
21 | 8. Now you have an image of just the background glow, and you have the key's solid color picked as
22 | your foreground color.
23 | 9. Do "Colors -> Color to Alpha...". This will turn the opaque background glow into a transparency,
24 | essentially pulling out the tint that had been placed over the original background color of the key.
25 | 10. Now you can paste this transparent glow onto a new background color and it will tint it
26 | correctly.
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dotdash_key.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
16 |
21 |
26 |
31 |
32 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/dotdash.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
26 |
27 |
32 |
37 |
42 |
43 |
44 |
49 |
55 |
61 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/app/src/main/res/values-h480dp/style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
14 |
19 |
22 |
28 |
35 |
38 |
41 |
--------------------------------------------------------------------------------
/app/src/main/java/org/pocketworkstation/pckeyboard/AutoSummaryListPreference.java:
--------------------------------------------------------------------------------
1 | package org.pocketworkstation.pckeyboard;
2 |
3 | /*
4 | * Copyright (C) 2010, authors of the Hacker's Keyboard project: http://code.google.com/p/hackerskeyboard/
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 | * use this file except in compliance with the License. You may obtain a copy of
8 | * the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 | * License for the specific language governing permissions and limitations under
16 | * the License.
17 | */
18 |
19 | import android.content.Context;
20 | import android.preference.ListPreference;
21 | import android.util.AttributeSet;
22 | import android.util.Log;
23 |
24 | public class AutoSummaryListPreference extends ListPreference {
25 | private static final String TAG = "DotDash/AutoSumListPref";
26 |
27 | public AutoSummaryListPreference(Context context) {
28 | super(context);
29 | }
30 |
31 | public AutoSummaryListPreference(Context context, AttributeSet attrs) {
32 | super(context, attrs);
33 | }
34 |
35 | private void trySetSummary() {
36 | CharSequence entry = null;
37 | try {
38 | entry = getEntry();
39 | } catch (ArrayIndexOutOfBoundsException e) {
40 | Log.i(TAG, "Malfunctioning ListPreference, can't get entry");
41 | }
42 | if (entry != null) {
43 | // String percent = getResources().getString(R.string.percent);
44 | String percent = "percent";
45 | setSummary(entry.toString().replace("%", " " + percent));
46 | }
47 | }
48 |
49 | @Override
50 | public void setEntries(CharSequence[] entries) {
51 | super.setEntries(entries);
52 | trySetSummary();
53 | }
54 |
55 | @Override
56 | public void setEntryValues(CharSequence[] entryValues) {
57 | super.setEntryValues(entryValues);
58 | trySetSummary();
59 | }
60 |
61 | @Override
62 | public void setValue(String value) {
63 | super.setValue(value);
64 | trySetSummary();
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/utilitykeyboard.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
31 |
32 |
34 |
36 |
38 |
39 |
40 |
41 |
44 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/java/net/iowaline/dotdash/DotDashKeyboard.java:
--------------------------------------------------------------------------------
1 | package net.iowaline.dotdash;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.content.res.XmlResourceParser;
6 | import android.graphics.drawable.Drawable;
7 | import android.inputmethodservice.Keyboard;
8 |
9 | public class DotDashKeyboard extends Keyboard {
10 |
11 | public static final int KEYCODE_DOT = 0;
12 | public static final int KEYCODE_DASH = 1;
13 |
14 | public DotDashKeyboard(Context context, int xmlLayoutResId) {
15 | super(context, xmlLayoutResId);
16 | }
17 |
18 | public Keyboard.Key spaceKey;
19 | public Keyboard.Key capsLockKey;
20 | public Keyboard.Key leftDotdashKey;
21 | public Keyboard.Key rightDotdashKey;
22 |
23 | @Override
24 | protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
25 | XmlResourceParser parser) {
26 | // TODO Auto-generated method stub
27 | Key k = super.createKeyFromXml(res, parent, x, y, parser);
28 | switch (k.codes[0]) {
29 | case 0:
30 | leftDotdashKey = k;
31 | break;
32 | case 1:
33 | rightDotdashKey = k;
34 | break;
35 | case 62:
36 | spaceKey = k;
37 | break;
38 | case 59:
39 | capsLockKey = k;
40 | break;
41 | }
42 | return k;
43 | }
44 |
45 | /**
46 | * Sets up the dot & dash keys to match the user's preference.
47 | * By default, the dot key is on the left and the dash key is
48 | * on the right.
49 | *
50 | * @param dashKeyOnLeft True if the dash key should be on the left
51 | * @return boolean True if the keys changed position
52 | */
53 | public boolean setupDotDashKeys(boolean dashKeyOnLeft) {
54 | if (dashKeyOnLeft != (leftDotdashKey.codes[0] == DotDashKeyboard.KEYCODE_DASH)) {
55 | // Swap 'em!
56 | int[] code_tmp = leftDotdashKey.codes;
57 | leftDotdashKey.codes = rightDotdashKey.codes;
58 | rightDotdashKey.codes = code_tmp;
59 |
60 | Drawable icon_tmp = leftDotdashKey.icon;
61 | leftDotdashKey.icon = rightDotdashKey.icon;
62 | rightDotdashKey.icon = icon_tmp;
63 | return true;
64 | }
65 |
66 | return false;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | DotDash Keyboard
2 |
3 | The world's most popular open source Morse code keyboard for Android! (probably)
4 |
5 | 
6 |
7 | DotDash Keyboard is also available in:
8 | - Google Play: https://play.google.com/store/apps/details?id=net.iowaline.dotdash&hl=en
9 | - F-Droid: https://f-droid.org/repository/browse/?fdfilter=dotdash&fdid=net.iowaline.dotdash
10 |
11 | Are you looking for an on-screen keyboard that will work with your phone's small screen and slow CPU?
12 | Do you know or are you willing to learn Morse code? If you answered "yes" to both of these questions,
13 | then this may be the keyboard for you!
14 |
15 | DotDash Keyboard is a drop-in replacement for Android's on-screen keyboard. It allows you to enter text
16 | via un-timed Morse code, using three main buttons: Dot, Dash, and Space (as well as Shift and Delete).
17 |
18 | DotDash features an extended version of Morse code which replicates all of the characters on a standard
19 | QWERTY keyboard. For more information see the DotDash Keyboard wiki:
20 | - https://github.com/agwells/dotdash-keyboard-android/wiki
21 |
22 | Nightly builds
23 | --------------
24 | If you'd like to try the nightly build of DotDash Keyboard via the Google Play store, use this link to opt-in to the alpha version: https://play.google.com/apps/testing/net.iowaline.dotdash
25 |
26 | Note, this version is likely to be unstable!
27 |
28 | Copyright notice
29 | ----------------
30 |
31 | Copyright (C) 2012-2015 Aaron Wells
32 | Copyright (c) 2008, The Android Open Source Project
33 | Copyright (c) 2010, Authors of the "Hacker's Keyboard" project https://code.google.com/p/hackerskeyboard/
34 |
35 | This program is free software: you can redistribute it and/or modify
36 | it under the terms of the GNU General Public License as published by
37 | the Free Software Foundation, version 3 or later of the License.
38 |
39 | This program is distributed in the hope that it will be useful,
40 | but WITHOUT ANY WARRANTY; without even the implied warranty of
41 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 | GNU General Public License for more details.
43 |
44 | You should have received a copy of the GNU General Public License
45 | along with this program. (See the included LICENSE file.)
46 | If not, see .
47 |
48 | Additionally, portions of this program are licensed under the
49 | Apache License, Version 2.0; you may not use these files except in
50 | compliance with the Apache License. See the included NOTICE file
51 | for more details. You may obtain a copy of the Apache License
52 | at
53 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/prefs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
19 |
20 |
28 |
29 |
37 |
38 |
45 |
46 |
52 |
53 |
60 |
61 |
67 |
68 |
75 |
76 |
82 |
83 |
--------------------------------------------------------------------------------
/app/src/main/res/values/style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
14 |
19 |
22 |
28 |
35 |
38 |
41 |
42 |
63 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/cheatsheet2.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
11 |
12 |
17 |
18 |
22 |
23 |
27 |
28 |
29 |
30 |
31 |
35 |
36 |
40 |
41 |
45 |
46 |
50 |
51 |
52 |
53 |
54 |
58 |
59 |
63 |
64 |
68 |
69 |
73 |
74 |
75 |
76 |
77 |
81 |
82 |
86 |
87 |
91 |
92 |
96 |
97 |
98 |
99 |
100 |
104 |
105 |
109 |
110 |
114 |
115 |
119 |
120 |
121 |
122 |
123 |
127 |
128 |
132 |
133 |
137 |
138 |
142 |
143 |
144 |
145 |
146 |
150 |
151 |
155 |
156 |
160 |
161 |
165 |
166 |
167 |
168 |
169 |
173 |
174 |
178 |
179 |
183 |
184 |
188 |
189 |
190 |
191 |
192 |
196 |
197 |
201 |
202 |
206 |
207 |
211 |
212 |
213 |
214 |
215 |
219 |
220 |
224 |
225 |
229 |
230 |
234 |
235 |
236 |
237 |
238 |
242 |
243 |
247 |
248 |
252 |
253 |
257 |
258 |
259 |
260 |
261 |
265 |
266 |
270 |
271 |
275 |
276 |
280 |
281 |
282 |
283 |
284 |
288 |
289 |
293 |
294 |
298 |
299 |
303 |
304 |
305 |
306 |
307 |
311 |
312 |
316 |
317 |
321 |
322 |
326 |
327 |
328 |
329 |
330 |
334 |
335 |
339 |
340 |
344 |
345 |
349 |
350 |
351 |
352 |
353 |
357 |
358 |
362 |
363 |
367 |
368 |
372 |
373 |
374 |
375 |
376 |
380 |
381 |
382 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | Some components of this program are derived from the Android Open Source Project
2 | (specifically the LatinIMEKeyboard), and the Hacker's Keyboard project. As such, those
3 | portions are distributed under the terms of the Apache License. Non-binary files
4 | that meet this description have a relevant notice at the top of the file.
5 |
6 | The following binary files (which cannot contain a notice) are derived from the
7 | AOSP and distributed under the terms of the Apache License:
8 |
9 | 1. All .xcf files under /Documents (derived from graphics in the AOSP)
10 | 2. All .png files under /res EXCEPT for:
11 | 2a. ic_launcher.png
12 | 2b. sym_keyboard_dot.png
13 | 2c. sym_keyboard_dash.png
14 |
15 | Additionally, the .xcf files, and the .png files with names starting with "dotdash", have
16 | been modified by me.
17 |
18 | The following notice applies to the portions of this project that are
19 | distributed under the terms of the Apache License.
20 |
21 | Copyright (c) 2008, The Android Open Source Project
22 | Copyright (c) 2010, authors of the Hacker's Keyboard
23 |
24 | Licensed under the Apache License, Version 2.0 (the "License");
25 | you may not use this file except in compliance with the License.
26 |
27 | Unless required by applicable law or agreed to in writing, software
28 | distributed under the License is distributed on an "AS IS" BASIS,
29 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 | See the License for the specific language governing permissions and
31 | limitations under the License.
32 |
33 |
34 | Apache License
35 | Version 2.0, January 2004
36 | http://www.apache.org/licenses/
37 |
38 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
39 |
40 | 1. Definitions.
41 |
42 | "License" shall mean the terms and conditions for use, reproduction,
43 | and distribution as defined by Sections 1 through 9 of this document.
44 |
45 | "Licensor" shall mean the copyright owner or entity authorized by
46 | the copyright owner that is granting the License.
47 |
48 | "Legal Entity" shall mean the union of the acting entity and all
49 | other entities that control, are controlled by, or are under common
50 | control with that entity. For the purposes of this definition,
51 | "control" means (i) the power, direct or indirect, to cause the
52 | direction or management of such entity, whether by contract or
53 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
54 | outstanding shares, or (iii) beneficial ownership of such entity.
55 |
56 | "You" (or "Your") shall mean an individual or Legal Entity
57 | exercising permissions granted by this License.
58 |
59 | "Source" form shall mean the preferred form for making modifications,
60 | including but not limited to software source code, documentation
61 | source, and configuration files.
62 |
63 | "Object" form shall mean any form resulting from mechanical
64 | transformation or translation of a Source form, including but
65 | not limited to compiled object code, generated documentation,
66 | and conversions to other media types.
67 |
68 | "Work" shall mean the work of authorship, whether in Source or
69 | Object form, made available under the License, as indicated by a
70 | copyright notice that is included in or attached to the work
71 | (an example is provided in the Appendix below).
72 |
73 | "Derivative Works" shall mean any work, whether in Source or Object
74 | form, that is based on (or derived from) the Work and for which the
75 | editorial revisions, annotations, elaborations, or other modifications
76 | represent, as a whole, an original work of authorship. For the purposes
77 | of this License, Derivative Works shall not include works that remain
78 | separable from, or merely link (or bind by name) to the interfaces of,
79 | the Work and Derivative Works thereof.
80 |
81 | "Contribution" shall mean any work of authorship, including
82 | the original version of the Work and any modifications or additions
83 | to that Work or Derivative Works thereof, that is intentionally
84 | submitted to Licensor for inclusion in the Work by the copyright owner
85 | or by an individual or Legal Entity authorized to submit on behalf of
86 | the copyright owner. For the purposes of this definition, "submitted"
87 | means any form of electronic, verbal, or written communication sent
88 | to the Licensor or its representatives, including but not limited to
89 | communication on electronic mailing lists, source code control systems,
90 | and issue tracking systems that are managed by, or on behalf of, the
91 | Licensor for the purpose of discussing and improving the Work, but
92 | excluding communication that is conspicuously marked or otherwise
93 | designated in writing by the copyright owner as "Not a Contribution."
94 |
95 | "Contributor" shall mean Licensor and any individual or Legal Entity
96 | on behalf of whom a Contribution has been received by Licensor and
97 | subsequently incorporated within the Work.
98 |
99 | 2. Grant of Copyright License. Subject to the terms and conditions of
100 | this License, each Contributor hereby grants to You a perpetual,
101 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
102 | copyright license to reproduce, prepare Derivative Works of,
103 | publicly display, publicly perform, sublicense, and distribute the
104 | Work and such Derivative Works in Source or Object form.
105 |
106 | 3. Grant of Patent License. Subject to the terms and conditions of
107 | this License, each Contributor hereby grants to You a perpetual,
108 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
109 | (except as stated in this section) patent license to make, have made,
110 | use, offer to sell, sell, import, and otherwise transfer the Work,
111 | where such license applies only to those patent claims licensable
112 | by such Contributor that are necessarily infringed by their
113 | Contribution(s) alone or by combination of their Contribution(s)
114 | with the Work to which such Contribution(s) was submitted. If You
115 | institute patent litigation against any entity (including a
116 | cross-claim or counterclaim in a lawsuit) alleging that the Work
117 | or a Contribution incorporated within the Work constitutes direct
118 | or contributory patent infringement, then any patent licenses
119 | granted to You under this License for that Work shall terminate
120 | as of the date such litigation is filed.
121 |
122 | 4. Redistribution. You may reproduce and distribute copies of the
123 | Work or Derivative Works thereof in any medium, with or without
124 | modifications, and in Source or Object form, provided that You
125 | meet the following conditions:
126 |
127 | (a) You must give any other recipients of the Work or
128 | Derivative Works a copy of this License; and
129 |
130 | (b) You must cause any modified files to carry prominent notices
131 | stating that You changed the files; and
132 |
133 | (c) You must retain, in the Source form of any Derivative Works
134 | that You distribute, all copyright, patent, trademark, and
135 | attribution notices from the Source form of the Work,
136 | excluding those notices that do not pertain to any part of
137 | the Derivative Works; and
138 |
139 | (d) If the Work includes a "NOTICE" text file as part of its
140 | distribution, then any Derivative Works that You distribute must
141 | include a readable copy of the attribution notices contained
142 | within such NOTICE file, excluding those notices that do not
143 | pertain to any part of the Derivative Works, in at least one
144 | of the following places: within a NOTICE text file distributed
145 | as part of the Derivative Works; within the Source form or
146 | documentation, if provided along with the Derivative Works; or,
147 | within a display generated by the Derivative Works, if and
148 | wherever such third-party notices normally appear. The contents
149 | of the NOTICE file are for informational purposes only and
150 | do not modify the License. You may add Your own attribution
151 | notices within Derivative Works that You distribute, alongside
152 | or as an addendum to the NOTICE text from the Work, provided
153 | that such additional attribution notices cannot be construed
154 | as modifying the License.
155 |
156 | You may add Your own copyright statement to Your modifications and
157 | may provide additional or different license terms and conditions
158 | for use, reproduction, or distribution of Your modifications, or
159 | for any such Derivative Works as a whole, provided Your use,
160 | reproduction, and distribution of the Work otherwise complies with
161 | the conditions stated in this License.
162 |
163 | 5. Submission of Contributions. Unless You explicitly state otherwise,
164 | any Contribution intentionally submitted for inclusion in the Work
165 | by You to the Licensor shall be under the terms and conditions of
166 | this License, without any additional terms or conditions.
167 | Notwithstanding the above, nothing herein shall supersede or modify
168 | the terms of any separate license agreement you may have executed
169 | with Licensor regarding such Contributions.
170 |
171 | 6. Trademarks. This License does not grant permission to use the trade
172 | names, trademarks, service marks, or product names of the Licensor,
173 | except as required for reasonable and customary use in describing the
174 | origin of the Work and reproducing the content of the NOTICE file.
175 |
176 | 7. Disclaimer of Warranty. Unless required by applicable law or
177 | agreed to in writing, Licensor provides the Work (and each
178 | Contributor provides its Contributions) on an "AS IS" BASIS,
179 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
180 | implied, including, without limitation, any warranties or conditions
181 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
182 | PARTICULAR PURPOSE. You are solely responsible for determining the
183 | appropriateness of using or redistributing the Work and assume any
184 | risks associated with Your exercise of permissions under this License.
185 |
186 | 8. Limitation of Liability. In no event and under no legal theory,
187 | whether in tort (including negligence), contract, or otherwise,
188 | unless required by applicable law (such as deliberate and grossly
189 | negligent acts) or agreed to in writing, shall any Contributor be
190 | liable to You for damages, including any direct, indirect, special,
191 | incidental, or consequential damages of any character arising as a
192 | result of this License or out of the use or inability to use the
193 | Work (including but not limited to damages for loss of goodwill,
194 | work stoppage, computer failure or malfunction, or any and all
195 | other commercial damages or losses), even if such Contributor
196 | has been advised of the possibility of such damages.
197 |
198 | 9. Accepting Warranty or Additional Liability. While redistributing
199 | the Work or Derivative Works thereof, You may choose to offer,
200 | and charge a fee for, acceptance of support, warranty, indemnity,
201 | or other liability obligations and/or rights consistent with this
202 | License. However, in accepting such obligations, You may act only
203 | on Your own behalf and on Your sole responsibility, not on behalf
204 | of any other Contributor, and only if You agree to indemnify,
205 | defend, and hold each Contributor harmless for any liability
206 | incurred by, or claims asserted against, such Contributor by reason
207 | of your accepting any such warranty or additional liability.
208 |
209 | END OF TERMS AND CONDITIONS
210 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/cheatsheet1.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
22 |
23 |
27 |
28 |
32 |
33 |
37 |
38 |
39 |
40 |
41 |
45 |
46 |
50 |
51 |
55 |
56 |
60 |
61 |
65 |
66 |
70 |
71 |
72 |
73 |
74 |
78 |
79 |
83 |
84 |
88 |
89 |
93 |
94 |
98 |
99 |
103 |
104 |
105 |
106 |
107 |
111 |
112 |
116 |
117 |
121 |
122 |
126 |
127 |
131 |
132 |
136 |
137 |
138 |
139 |
140 |
144 |
145 |
149 |
150 |
154 |
155 |
159 |
160 |
164 |
165 |
169 |
170 |
171 |
172 |
173 |
177 |
178 |
182 |
183 |
187 |
188 |
192 |
193 |
197 |
198 |
202 |
203 |
204 |
205 |
206 |
210 |
211 |
215 |
216 |
220 |
221 |
225 |
226 |
230 |
231 |
235 |
236 |
237 |
238 |
239 |
243 |
244 |
248 |
249 |
253 |
254 |
258 |
259 |
263 |
264 |
268 |
269 |
270 |
271 |
272 |
276 |
277 |
281 |
282 |
286 |
287 |
291 |
292 |
296 |
297 |
301 |
302 |
303 |
304 |
305 |
309 |
310 |
314 |
315 |
319 |
320 |
324 |
325 |
329 |
330 |
334 |
335 |
336 |
337 |
338 |
342 |
343 |
347 |
348 |
352 |
353 |
357 |
358 |
359 |
360 |
361 |
365 |
366 |
370 |
371 |
375 |
376 |
380 |
381 |
382 |
383 |
384 |
388 |
389 |
393 |
394 |
398 |
399 |
403 |
404 |
405 |
406 |
407 |
411 |
412 |
413 |
--------------------------------------------------------------------------------
/app/src/main/java/net/iowaline/dotdash/DotDashKeyboardView.java:
--------------------------------------------------------------------------------
1 | package net.iowaline.dotdash;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.inputmethodservice.Keyboard;
7 | import android.inputmethodservice.KeyboardView;
8 | import android.os.Handler;
9 | import android.os.Message;
10 | import android.os.SystemClock;
11 | import android.util.AttributeSet;
12 | import android.util.Log;
13 | import android.view.GestureDetector;
14 | import android.view.MotionEvent;
15 | import android.view.View;
16 | import android.view.ViewConfiguration;
17 | import android.view.Window;
18 | import android.view.WindowManager;
19 | import android.widget.TableLayout;
20 | import android.widget.TableRow;
21 | import android.widget.TextView;
22 |
23 | import java.util.HashMap;
24 | import java.util.HashSet;
25 | import java.util.Map;
26 | import java.util.Set;
27 |
28 | @SuppressWarnings("JavaDoc")
29 | @SuppressLint("ClickableViewAccessibility")
30 | public class DotDashKeyboardView extends KeyboardView {
31 |
32 | private final String TAG = this.getClass().getSimpleName();
33 | private DotDashIMEService service;
34 | private Dialog cheatSheetDialog;
35 | private TableLayout cheatSheet1;
36 | private TableLayout cheatSheet2;
37 | private int mSwipeThreshold;
38 | private GestureDetector gestureDetector;
39 |
40 | private Set pressedKeys = new HashSet<>();
41 |
42 | private static final int KBD_NONE = 0;
43 | public static final int KBD_DOTDASH = 1;
44 | public static final int KBD_UTILITY = 2;
45 |
46 | public boolean mEnableUtilityKeyboard = false;
47 |
48 | private static final int REPEAT_INTERVAL = 50; // ~20 keys per second
49 | private static final int REPEAT_START_DELAY = 400;
50 | @SuppressWarnings("unused")
51 | private static final int LONG_PRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout();
52 | private static final int DEBOUNCE_TIMEOUT = 50; //70;
53 | private static final int IAMBIC_DOT_LENGTH = 100;
54 | private static final long AUTOCOMMIT_DELAY = IAMBIC_DOT_LENGTH * 4;
55 | // TODO: Make this into a SparseArray somehow?
56 | private final Map bounceWaits = new HashMap<>();
57 |
58 | private static final int MSG_KEY_REPEAT = 1;
59 | public static final int MSG_IAMBIC_PLAYING = 2;
60 | public static final int MSG_AUTOCOMMIT = 3;
61 | // TODO: according to this documentation: http://www.morsecode.nl/iambic.PDF
62 | // ... it appears that the logic is supposed to be that it "locks" if the
63 | // opposite key is still held down at the halfway point of the preceding
64 | // signal. So I will need to add some more logic there to get the timing
65 | // just right.
66 | boolean iambic_both_pressed = false;
67 |
68 | final Handler handler = new Handler(
69 | new Handler.Callback() {
70 |
71 | @Override
72 | public boolean handleMessage(Message msg) {
73 | switch (msg.what) {
74 | case MSG_KEY_REPEAT:
75 | Keyboard.Key repeatKey = (Keyboard.Key) msg.obj;
76 | if (!repeatKey.pressed) {
77 | return true;
78 | }
79 |
80 | if (!(repeatKey == service.dotDashKeyboard.leftDotdashKey || repeatKey == service.dotDashKeyboard.rightDotdashKey)) {
81 | getOnKeyboardActionListener().onKey(repeatKey.codes[0], repeatKey.codes);
82 | handler.sendMessageDelayed(handler.obtainMessage(MSG_KEY_REPEAT, repeatKey), REPEAT_INTERVAL);
83 | }
84 | break;
85 | case MSG_IAMBIC_PLAYING:
86 | Keyboard.Key lastKeySent = (Keyboard.Key) msg.obj;
87 | Keyboard.Key nextKeyToSend = null;
88 | boolean leftKeyPressed = service.dotDashKeyboard.leftDotdashKey.pressed;
89 | boolean rightKeyPressed = service.dotDashKeyboard.rightDotdashKey.pressed;
90 |
91 | // Iambic signal has just ended. Check to see if dot and/or dash are still held down
92 | if (leftKeyPressed && rightKeyPressed) {
93 | // Both are pressed, so send the opposite signal from what we just sent
94 | if (lastKeySent == service.dotDashKeyboard.leftDotdashKey) {
95 | nextKeyToSend = service.dotDashKeyboard.rightDotdashKey;
96 | } else {
97 | nextKeyToSend = service.dotDashKeyboard.leftDotdashKey;
98 | }
99 | } else if (leftKeyPressed || rightKeyPressed) {
100 | // Only one is pressed. Send its signal.
101 | if (leftKeyPressed) {
102 | nextKeyToSend = service.dotDashKeyboard.leftDotdashKey;
103 | } else {
104 | nextKeyToSend = service.dotDashKeyboard.rightDotdashKey;
105 | }
106 | iambic_both_pressed = false;
107 | } else if (service.iambicModeB && iambic_both_pressed) {
108 | // Mode b. Send one more signal, with the opposite of the last key
109 | if (lastKeySent == service.dotDashKeyboard.leftDotdashKey) {
110 | nextKeyToSend = service.dotDashKeyboard.rightDotdashKey;
111 | } else {
112 | nextKeyToSend = service.dotDashKeyboard.leftDotdashKey;
113 | }
114 | iambic_both_pressed = false;
115 | }
116 |
117 | if (nextKeyToSend != null) {
118 | getOnKeyboardActionListener().onKey(nextKeyToSend.codes[0], nextKeyToSend.codes);
119 | handler.sendMessageDelayed(handler.obtainMessage(MSG_IAMBIC_PLAYING, nextKeyToSend),
120 | DotDashKeyboardView.get_iambic_delay(nextKeyToSend));
121 | } else {
122 | // Iambic is done, so start the autocommit timer.
123 | if (service.autocommit) {
124 | long delay = DotDashKeyboardView.AUTOCOMMIT_DELAY;
125 | // If audio is playing, we want to wait until the end of the tone before
126 | // we start counting down for autocommit.
127 | if (service.isAudio()) {
128 | delay += DotDashKeyboardView.get_iambic_delay(lastKeySent);
129 | }
130 | handler.removeMessages(DotDashKeyboardView.MSG_AUTOCOMMIT);
131 | handler.sendMessageDelayed(
132 | handler.obtainMessage(DotDashKeyboardView.MSG_AUTOCOMMIT),
133 | delay
134 | );
135 | }
136 | }
137 | break;
138 | case MSG_AUTOCOMMIT:
139 | service.commitCodeGroup(true);
140 | break;
141 | }
142 |
143 | return true;
144 | }
145 | }
146 | );
147 |
148 | public void setService(DotDashIMEService service) {
149 | this.service = service;
150 | }
151 |
152 | public DotDashKeyboardView(Context context, AttributeSet attrs) {
153 | super(context, attrs);
154 | setEverythingUp();
155 | }
156 |
157 | public DotDashKeyboardView(Context context, AttributeSet attrs, int defStyle) {
158 | super(context, attrs, defStyle);
159 | setEverythingUp();
160 | }
161 |
162 | @SuppressWarnings("deprecation")
163 | private void setEverythingUp() {
164 | mSwipeThreshold = (int) (300 * getResources().getDisplayMetrics().density);
165 | setPreviewEnabled(false);
166 | gestureDetector = new GestureDetector(
167 | new GestureDetector.SimpleOnGestureListener() {
168 |
169 | /**
170 | * This function mostly copied from LatinKeyboardBaseView in
171 | * the Hacker's Keyboard project: http://code.google.com/p/hackerskeyboard/
172 | *
173 | * Copyright (C) 2010, authors of the Hacker's Keyboard project: http://code.google.com/p/hackerskeyboard/
174 | * Copyright (c) 2011, Aaron Wells
175 | *
176 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
177 | * use this file except in compliance with the License. You may obtain a copy of
178 | * the License at
179 | *
180 | * http://www.apache.org/licenses/LICENSE-2.0
181 | */
182 | @Override
183 | public boolean onFling(MotionEvent e1, MotionEvent e2,
184 | float velocityX, float velocityY) {
185 |
186 | // If they swipe up off the keyboard, launch the cheat
187 | // sheet. This was originally a check for e2.getY() < 0,
188 | // but that didn't work in ICS. Possibly ICS stops
189 | // sending you events after you go past the edge of the
190 | // window. So I changed it to 10 instead.
191 | if (e2.getY() <= 10) {
192 | // If they swipe up off the keyboard, launch the
193 | // cheat sheet
194 | showCheatSheet();
195 | return true;
196 | } else if (mEnableUtilityKeyboard) {
197 | final float absX = Math.abs(velocityX);
198 | final float absY = Math.abs(velocityY);
199 | float deltaX = e2.getX() - e1.getX();
200 | int travelMin = Math.min((getWidth() / 3),
201 | (getHeight() / 3));
202 |
203 | if (velocityX > mSwipeThreshold && absY < absX
204 | && deltaX > travelMin) {
205 | toggleKeyboard();
206 | return true;
207 | } else if (velocityX < -mSwipeThreshold
208 | && absY < absX && deltaX < -travelMin) {
209 | toggleKeyboard();
210 | return true;
211 | }
212 | }
213 | return false;
214 | }
215 | });
216 |
217 | // View.OnTouchListener gestureListener = new View.OnTouchListener() {
218 | // @Override
219 | // public boolean onTouch(View v, MotionEvent event) {
220 | // if (gestureDetector.onTouchEvent(event)) {
221 | // // Tell the underlying KeyboardView to cancel its
222 | // // touch event if we've initiated a gesture.
223 | // MotionEvent cancel = MotionEvent.obtain(event);
224 | // cancel.setAction(MotionEvent.ACTION_CANCEL);
225 | // DotDashKeyboardView.this.onTouchEvent(cancel);
226 | // cancel.recycle();
227 | // return true;
228 | // } else {
229 | // return false;
230 | // }
231 | // }
232 | // };
233 | // setOnTouchListener(gestureListener);
234 | }
235 |
236 | private void toggleKeyboard() {
237 | if (getKeyboard() == service.dotDashKeyboard) {
238 | setKeyboard(service.utilityKeyboard);
239 | // TODO: Make this work. I think it's a layout issue...
240 | // setPreviewEnabled(true);
241 | } else {
242 | setKeyboard(service.dotDashKeyboard);
243 | // setPreviewEnabled(false);
244 | }
245 | }
246 |
247 | @SuppressLint("InflateParams")
248 | private void createCheatSheet() {
249 | boolean updateTouchListeners = false;
250 | if (this.cheatSheetDialog == null) {
251 | this.cheatSheetDialog = new Dialog(this.service);
252 |
253 | cheatSheetDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
254 |
255 | cheatSheetDialog.setCancelable(true);
256 | cheatSheetDialog.setCanceledOnTouchOutside(true);
257 | updateTouchListeners = true;
258 | }
259 | if (this.cheatSheet1 == null) {
260 | this.cheatSheet1 = (TableLayout) this.service.getLayoutInflater().inflate(
261 | R.layout.cheatsheet1, null);
262 | this.prettifyCheatSheet(this.cheatSheet1);
263 | updateTouchListeners = true;
264 | }
265 | if (this.cheatSheet2 == null) {
266 | this.cheatSheet2 = (TableLayout) this.service.getLayoutInflater().inflate(
267 | R.layout.cheatsheet2, null);
268 | updateNewlineCode();
269 | this.prettifyCheatSheet(this.cheatSheet2);
270 | updateTouchListeners = true;
271 | }
272 |
273 | if (updateTouchListeners) {
274 | cheatSheetDialog.setContentView(cheatSheet1);
275 | cheatSheet1.setOnTouchListener(new OnTouchListener() {
276 | @Override
277 | public boolean onTouch(View v, MotionEvent event) {
278 | cheatSheetDialog.setContentView(cheatSheet2);
279 | return true;
280 | }
281 | });
282 | cheatSheet2.setOnTouchListener(new OnTouchListener() {
283 | @Override
284 | public boolean onTouch(View v, MotionEvent event) {
285 | cheatSheetDialog.setContentView(cheatSheet1);
286 | return true;
287 | }
288 | });
289 | Window window = this.cheatSheetDialog.getWindow();
290 | if (window != null) {
291 | WindowManager.LayoutParams lp = window.getAttributes();
292 | lp.token = this.getWindowToken();
293 | lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
294 | window.setAttributes(lp);
295 | window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
296 | }
297 | }
298 | }
299 |
300 | /**
301 | * Update the characters in the cheat sheet dialogue to match the user's preference
302 | *
303 | * @param cheatSheet
304 | * @todo Probably better performance if I replaced this with two hard-coded versions
305 | * of the sheet...
306 | */
307 | private void prettifyCheatSheet(TableLayout cheatSheet) {
308 | // No action necessary.
309 | if (service.ditDahCharsPref == DotDashIMEService.DIT_DAH_CHARS_UNICODE) {
310 | return;
311 | }
312 |
313 | for (int i = 0; i < cheatSheet.getChildCount(); i++) {
314 | TableRow row = (TableRow) cheatSheet.getChildAt(i);
315 |
316 | // On my cheat sheets, only the even-number columns
317 | // contain code groups
318 | for (int j = 1; j < row.getChildCount(); j += 2) {
319 | TextView cell = (TextView) row.getChildAt(j);
320 | cell.setText(service.convertDitDahUnicodeToAscii(cell.getText().toString()));
321 | }
322 | }
323 | }
324 |
325 | private void showCheatSheet() {
326 | createCheatSheet();
327 | cheatSheetDialog.show();
328 | }
329 |
330 | public void closeCheatSheet() {
331 | if (cheatSheetDialog != null) {
332 | cheatSheetDialog.dismiss();
333 | }
334 | }
335 |
336 | public void clearCheatSheet() {
337 | closeCheatSheet();
338 | this.cheatSheet1 = null;
339 | this.cheatSheet2 = null;
340 | }
341 |
342 | /**
343 | * Updates the newline code printed in the cheat sheet, based on the user's
344 | * current preference.
345 | */
346 | public void updateNewlineCode() {
347 | if (cheatSheet2 == null) {
348 | return;
349 | }
350 |
351 | String newCode = service.getText(R.string.newline_disabled).toString();
352 | if (service.newlineGroups != null && service.newlineGroups.length > 0) {
353 | newCode = service.newlineGroups[0].replace(".", DotDashIMEService.UNICODE_DOT).replace("-", DotDashIMEService.UNICODE_DASH);
354 | }
355 | ((TextView) cheatSheet2.findViewById(R.id.newline_code))
356 | .setText(newCode);
357 | }
358 |
359 | public int whichKeyboard() {
360 | Keyboard kbd = getKeyboard();
361 | if (kbd == service.dotDashKeyboard) {
362 | return KBD_DOTDASH;
363 | } else if (kbd == service.utilityKeyboard) {
364 | return KBD_UTILITY;
365 | } else
366 | return KBD_NONE;
367 | }
368 |
369 | @Override
370 | public boolean onTouchEvent(MotionEvent me) {
371 | Log.d(TAG, "onTouchEvent");
372 |
373 | // TODO: Unfortunately, since I send the character when you first press
374 | // the key, all the keys you press while swiping still count as getting
375 | // pressed.
376 | //
377 | // Not sure what I could do about that... maybe a more sensitive
378 | // swipe detector?
379 | if (gestureDetector.onTouchEvent(me)) {
380 | for (Keyboard.Key k : pressedKeys) {
381 | k.onReleased(false);
382 | }
383 | invalidateAllKeys();
384 | pressedKeys.clear();
385 | return true;
386 | }
387 |
388 | // Let KeyboardView handle the utility keyboard.
389 | if (whichKeyboard() == DotDashKeyboardView.KBD_UTILITY) {
390 | return super.onTouchEvent(me);
391 | }
392 |
393 | int actionMasked = me.getActionMasked();
394 | int actionIndex = me.getActionIndex();
395 | Set curPressedKeys = new HashSet<>();
396 |
397 | for (int i = 0; i < me.getPointerCount(); i++) {
398 |
399 | // Find out which key the pointer is on
400 | int x = (int) me.getX(i);
401 | int y = (int) me.getY(i);
402 | int[] keys = service.dotDashKeyboard.getNearestKeys(x, y);
403 | Keyboard.Key touchedKey = null;
404 | for (int k : keys) {
405 | Keyboard.Key key = service.dotDashKeyboard.getKeys().get(k);
406 | // TODO: This continues to detect it even after you've moved off the keyboard. :-P
407 | if (key.isInside(x, y)) {
408 | touchedKey = key;
409 | }
410 | }
411 |
412 | if (touchedKey != null) {
413 | if (i == actionIndex) {
414 | switch (actionMasked) {
415 | case MotionEvent.ACTION_DOWN:
416 | case MotionEvent.ACTION_MOVE:
417 | case MotionEvent.ACTION_POINTER_DOWN:
418 | curPressedKeys.add(touchedKey);
419 | break;
420 | case MotionEvent.ACTION_UP:
421 | case MotionEvent.ACTION_POINTER_UP:
422 | case MotionEvent.ACTION_OUTSIDE:
423 | // TODO: The docs say about ACTION_CANCEL: "You should treat this as an
424 | // up event, but not perform any action that you normally would".
425 | // So to really do that I'll need to put some further logic into this.
426 | // (How do you cancel a keypress?)
427 | case MotionEvent.ACTION_CANCEL:
428 | curPressedKeys.remove(touchedKey);
429 | break;
430 | }
431 | } else {
432 | curPressedKeys.add(touchedKey);
433 | }
434 | }
435 | }
436 |
437 | // Now that we know which keys have fingers on 'em this time,
438 | // let's check to see how that has changed from last time.
439 |
440 | // Keys that are in curPressedKeys but not in pressedKeys
441 | // are newly pressed.
442 | Set newlyPressed = new HashSet<>(curPressedKeys);
443 | newlyPressed.removeAll(pressedKeys);
444 | for (Keyboard.Key k : newlyPressed) {
445 | if (k.pressed) {
446 | continue;
447 | }
448 | Long bounceWait = this.bounceWaits.get(k);
449 | if (bounceWait != null && bounceWait > SystemClock.elapsedRealtime()) {
450 | continue;
451 | }
452 |
453 | // k.onPressed();
454 | k.pressed = true;
455 |
456 | getOnKeyboardActionListener().onPress(k.codes[0]);
457 |
458 | if (service.iambic && (k == service.dotDashKeyboard.leftDotdashKey || k == service.dotDashKeyboard.rightDotdashKey)) {
459 | // In iambic mode, we only process the key if there's not already a signal going
460 | // What matters is in the message handler, where we check the state of the keys
461 | // when the current message ends.
462 | //
463 | // TODO: Actually... it might make more sense if the iambic timing was
464 | // over in DotDashIMEService, using the onPress() method to trigger it.
465 | if (!handler.hasMessages(MSG_IAMBIC_PLAYING)) {
466 | getOnKeyboardActionListener().onKey(k.codes[0], k.codes);
467 |
468 | handler.sendMessageDelayed(
469 | handler.obtainMessage(MSG_IAMBIC_PLAYING, k),
470 | DotDashKeyboardView.get_iambic_delay(k)
471 | );
472 | }
473 |
474 | // Iambic mode B needs to know if both keys got pressed simultaneously while an Iambic message
475 | // was in progress.
476 | if (service.iambicModeB && service.dotDashKeyboard.leftDotdashKey.pressed && service.dotDashKeyboard.rightDotdashKey.pressed) {
477 | this.iambic_both_pressed = true;
478 | }
479 | } else {
480 | getOnKeyboardActionListener().onKey(k.codes[0], k.codes);
481 |
482 | if (k.repeatable && !handler.hasMessages(MSG_KEY_REPEAT, k)) {
483 | handler.sendMessageDelayed(
484 | handler.obtainMessage(MSG_KEY_REPEAT, k),
485 | REPEAT_START_DELAY
486 | );
487 | }
488 | }
489 |
490 | invalidateKey(service.dotDashKeyboard.getKeys().indexOf(k));
491 | }
492 |
493 | // Keys that are in pressedKeys but not curPressedKeys
494 | // are newly released.
495 | Set newlyReleased = new HashSet<>(pressedKeys);
496 | newlyReleased.removeAll(curPressedKeys);
497 | for (Keyboard.Key k : newlyReleased) {
498 | if (!k.pressed) {
499 | continue;
500 | }
501 |
502 | k.pressed = false;
503 | getOnKeyboardActionListener().onRelease(k.codes[0]);
504 | if (k.repeatable) {
505 | handler.removeMessages(MSG_KEY_REPEAT, k);
506 | }
507 | this.bounceWaits.put(k, SystemClock.elapsedRealtime() + DotDashKeyboardView.DEBOUNCE_TIMEOUT);
508 | invalidateKey(service.dotDashKeyboard.getKeys().indexOf(k));
509 |
510 | // If we're not in iambic mode, then the release of a key is probably a decent time to start
511 | // the autocommit timer.
512 | if (
513 | !service.iambic
514 | && service.isAudio()
515 | && (k == service.dotDashKeyboard.leftDotdashKey || k == service.dotDashKeyboard.rightDotdashKey)
516 | && !service.dotDashKeyboard.leftDotdashKey.pressed
517 | && !service.dotDashKeyboard.rightDotdashKey.pressed
518 | ) {
519 | long delay = DotDashKeyboardView.AUTOCOMMIT_DELAY;
520 | // If audio is playing, we want to wait until the end of the tone before
521 | // we start counting down for autocommit.
522 | if (service.isAudio()) {
523 | delay += DotDashKeyboardView.get_iambic_delay(k);
524 | }
525 | handler.removeMessages(DotDashKeyboardView.MSG_AUTOCOMMIT);
526 | handler.sendMessageDelayed(
527 | handler.obtainMessage(DotDashKeyboardView.MSG_AUTOCOMMIT),
528 | delay
529 | );
530 | }
531 | }
532 |
533 | pressedKeys = curPressedKeys;
534 |
535 | for (Keyboard.Key k : service.dotDashKeyboard.getKeys()) {
536 | Log.d(TAG, "Key " + String.valueOf(k.codes[0]) + " " + (k.pressed ? "down" : "up"));
537 | }
538 |
539 | return true;
540 | }
541 |
542 | private static long get_iambic_delay(Keyboard.Key k) {
543 | if (k.codes[0] == DotDashKeyboard.KEYCODE_DOT) {
544 | // a dot and the space after it
545 | return IAMBIC_DOT_LENGTH * 2;
546 | } else {
547 | // a dash (three dot lengths) and the space after it
548 | return IAMBIC_DOT_LENGTH * 4;
549 | }
550 | }
551 | }
552 |
--------------------------------------------------------------------------------
/app/src/main/java/net/iowaline/dotdash/DotDashIMEService.java:
--------------------------------------------------------------------------------
1 | package net.iowaline.dotdash;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
7 | import android.content.res.AssetFileDescriptor;
8 | import android.inputmethodservice.InputMethodService;
9 | import android.inputmethodservice.Keyboard;
10 | import android.inputmethodservice.KeyboardView;
11 | import android.media.AudioManager;
12 | import android.media.SoundPool;
13 | import android.preference.PreferenceManager;
14 | import android.view.KeyEvent;
15 | import android.view.View;
16 | import android.view.inputmethod.EditorInfo;
17 | import android.view.inputmethod.ExtractedText;
18 | import android.view.inputmethod.ExtractedTextRequest;
19 | import android.view.inputmethod.InputConnection;
20 |
21 | import java.util.Hashtable;
22 | import java.util.List;
23 | import java.util.Locale;
24 |
25 | @SuppressWarnings("JavaDoc")
26 | public class DotDashIMEService extends InputMethodService implements
27 | KeyboardView.OnKeyboardActionListener, OnSharedPreferenceChangeListener {
28 | // private String TAG = "DotDashIMEService";
29 | private DotDashKeyboardView inputView;
30 | public DotDashKeyboard dotDashKeyboard;
31 | public Keyboard utilityKeyboard;
32 | private Keyboard.Key spaceKey;
33 | private int spaceKeyIndex;
34 | private Keyboard.Key capsLockKey;
35 | private int capsLockKeyIndex;
36 | private Hashtable morseMap;
37 | private StringBuilder charInProgress;
38 |
39 | private static final int CAPS_LOCK_OFF = 0;
40 | private static final int CAPS_LOCK_NEXT = 1;
41 | private static final int CAPS_LOCK_ALL = 2;
42 | private int capsLockState = CAPS_LOCK_OFF;
43 |
44 | // private static final String BULLET = "∙";
45 | // private static final String BULLET_OPERATOR="∙";
46 | // private static final String BLACK_CIRCLE="●";
47 | private static final String INTERPUNCT = "·";
48 | // private static final String UNICODE_HYPHEN="‐";
49 | // private static final String NONBREAKING_HYPHEN="‑";
50 | // private static final String HYPHEN_BULLET="⁃"; // Weird; round
51 | // private static final String MINUS_SIGN="−";
52 | // private static final String HORIZ_LINE_EXT="⎯";
53 | // private static final String HEAVY_MINUS="➖"; // Weird; looks gray
54 | private static final String EN_DASH = "–";
55 | // private static final String EM_DASH="—";
56 |
57 | public static final String UNICODE_DOT = INTERPUNCT;
58 | public static final String UNICODE_DASH = EN_DASH;
59 |
60 | // Keycodes used in the utility keyboard
61 | private static final int KEYCODE_UP = -10;
62 | private static final int KEYCODE_LEFT = -11;
63 | private static final int KEYCODE_RIGHT = -12;
64 | private static final int KEYCODE_DOWN = -13;
65 | private static final int KEYCODE_HOME = -20;
66 | private static final int KEYCODE_END = -21;
67 | private static final int KEYCODE_DEL = -30;
68 |
69 | // Sync these with dit_dah_chars_values in arrays.xml
70 | public static final int DIT_DAH_CHARS_UNICODE = 1;
71 | @SuppressWarnings("unused")
72 | public static final int DIT_DAH_CHARS_ASCII = 2;
73 |
74 | private SharedPreferences prefs;
75 | public String[] newlineGroups;
76 | public int ditDahCharsPref;
77 | private int maxCodeLength;
78 |
79 | private SoundPool soundpool;
80 | private boolean loaded = false;
81 | private int dotSound;
82 | private int dashSound;
83 | public boolean iambic = false;
84 | public boolean iambicModeB = false;
85 | public boolean autocommit = false;
86 |
87 | @Override
88 | public void onCreate() {
89 | super.onCreate();
90 | PreferenceManager.setDefaultValues(this, R.xml.prefs, false);
91 |
92 | // TODO: Fetch prefs via a background thread, as described here:
93 | // http://stackoverflow.com/questions/4371273/should-accessing-sharedpreferences-be-done-off-the-ui-thread
94 | this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
95 | this.prefs.registerOnSharedPreferenceChangeListener(this);
96 | this.ditDahCharsPref = Integer.valueOf(this.prefs.getString(DotDashPrefs.DIT_DAH_CHARS, Integer.toString(DIT_DAH_CHARS_UNICODE)));
97 | this.iambic = this.prefs.getBoolean("iambic", false);
98 | this.iambicModeB = this.prefs.getBoolean("iambicModeB", false);
99 | this.autocommit = this.prefs.getBoolean("autocommit", false);
100 |
101 | // TODO Replace this with an XML file
102 | morseMap = new Hashtable<>();
103 | morseMap.put(".-", "a");
104 | morseMap.put("-...", "b");
105 | morseMap.put("-.-.", "c");
106 | morseMap.put("-..", "d");
107 | morseMap.put(".", "e");
108 | morseMap.put("..-.", "f");
109 | morseMap.put("--.", "g");
110 | morseMap.put("....", "h");
111 | morseMap.put("..", "i");
112 | morseMap.put(".---", "j");
113 | morseMap.put("-.-", "k");
114 | morseMap.put(".-..", "l");
115 | morseMap.put("--", "m");
116 | morseMap.put("-.", "n");
117 | morseMap.put("---", "o");
118 | morseMap.put(".--.", "p");
119 | morseMap.put("--.-", "q");
120 | morseMap.put(".-.", "r");
121 | morseMap.put("...", "s");
122 | morseMap.put("-", "t");
123 | morseMap.put("..-", "u");
124 | morseMap.put("...-", "v");
125 | morseMap.put(".--", "w");
126 | morseMap.put("-..-", "x");
127 | morseMap.put("-.--", "y");
128 | morseMap.put("--..", "z");
129 | morseMap.put(".----", "1");
130 | morseMap.put("..---", "2");
131 | morseMap.put("...--", "3");
132 | morseMap.put("....-", "4");
133 | morseMap.put(".....", "5");
134 | morseMap.put("-....", "6");
135 | morseMap.put("--...", "7");
136 | morseMap.put("---..", "8");
137 | morseMap.put("----.", "9");
138 | morseMap.put("-----", "0");
139 | morseMap.put(".----.", "\'");
140 | morseMap.put(".--.-.", "@");
141 | morseMap.put(".-...", "&");
142 | morseMap.put("---...", ":");
143 | morseMap.put("--..--", ",");
144 | morseMap.put("...-..-", "$");
145 | morseMap.put("-...-", "=");
146 | morseMap.put("---.", "!");
147 | morseMap.put("-.-.--", "!");
148 | morseMap.put("-....-", "-");
149 | morseMap.put("-.--.", "(");
150 | morseMap.put("-.--.-", ")");
151 | morseMap.put(".-.-.-", ".");
152 | morseMap.put(".-.-.", "+");
153 | morseMap.put("..--..", "?");
154 | morseMap.put(".-..-.", "\"");
155 | morseMap.put("-.-.-.", ";");
156 | morseMap.put("-..-.", "/");
157 | morseMap.put("..--.-", "_");
158 | // Aaron Wells' custom additions to Morse code
159 | morseMap.put("....--", "#");
160 | morseMap.put("-.-.-", "*");
161 | morseMap.put("..-..", "[");
162 | morseMap.put("..-..-", "]");
163 | morseMap.put(".--.-", "{");
164 | morseMap.put(".--.--", "}");
165 | morseMap.put("--.--", "<");
166 | morseMap.put("--.--.", ">");
167 | morseMap.put("...--.-", "~");
168 | morseMap.put(".--..-.", "%");
169 | morseMap.put(".--.---", "^");
170 | morseMap.put(".-..-", "\\");
171 | morseMap.put(".--...", "|");
172 |
173 | updateNewlinePref();
174 |
175 | // This variable is used in onKey to determine how many
176 | // dots and dashes we need to keep track of (no need recording
177 | // more than the total number that make up a valid code group)
178 | maxCodeLength = 0;
179 | for (String codeGroup : morseMap.keySet()) {
180 | if (codeGroup.length() > maxCodeLength) {
181 | maxCodeLength = codeGroup.length();
182 | }
183 | }
184 | charInProgress = new StringBuilder(maxCodeLength);
185 | }
186 |
187 | /**
188 | * Create (or nullify) the utility keyboard, depending on user's preferences.
189 | */
190 | private void setupUtilityKeyboard() {
191 | if (this.prefs.getBoolean(DotDashPrefs.DASH_KEY_ON_LEFT, false)) {
192 | utilityKeyboard = new Keyboard(this, R.xml.utilitykeyboard);
193 | } else {
194 | utilityKeyboard = null;
195 | }
196 |
197 | }
198 |
199 | @Override
200 | public void onInitializeInterface() {
201 | // TODO Auto-generated method stub
202 | super.onInitializeInterface();
203 | this.setupUtilityKeyboard();
204 | dotDashKeyboard = new DotDashKeyboard(this, R.xml.dotdash);
205 | dotDashKeyboard.setupDotDashKeys(this.prefs.getBoolean(DotDashPrefs.DASH_KEY_ON_LEFT, false));
206 |
207 | spaceKey = dotDashKeyboard.spaceKey;
208 | capsLockKey = dotDashKeyboard.capsLockKey;
209 | List keys = dotDashKeyboard.getKeys();
210 | spaceKeyIndex = keys.indexOf(spaceKey);
211 | capsLockKeyIndex = keys.indexOf(capsLockKey);
212 | if (isAudio()) {
213 | loadSoundPool();
214 | }
215 | }
216 |
217 | private void loadSoundPool() {
218 | soundpool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
219 | soundpool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
220 |
221 | @Override
222 | public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
223 | loaded = true;
224 | }
225 | });
226 | AssetFileDescriptor fd = getResources().openRawResourceFd(R.raw.tone800hz);
227 | dotSound = soundpool.load(fd.getFileDescriptor(), fd.getStartOffset(), (long) (fd.getLength() * 0.1), 1);
228 | dashSound = soundpool.load(fd.getFileDescriptor(), fd.getStartOffset(), (long) (fd.getLength() * 0.3), 1);
229 | }
230 |
231 | @SuppressLint("InflateParams")
232 | @Override
233 | public View onCreateInputView() {
234 | inputView = (DotDashKeyboardView) getLayoutInflater().inflate(
235 | R.layout.input, null);
236 | inputView.setOnKeyboardActionListener(this);
237 | inputView.setKeyboard(dotDashKeyboard);
238 | inputView.setService(this);
239 | inputView.mEnableUtilityKeyboard = prefs.getBoolean(
240 | DotDashPrefs.ENABLE_UTIL_KBD, false);
241 | return inputView;
242 | }
243 |
244 | public void onKey(int primaryCode, int[] keyCodes) {
245 | int kbd = inputView.whichKeyboard();
246 | if (kbd == DotDashKeyboardView.KBD_DOTDASH) {
247 | onKeyMorse(primaryCode);
248 | } else if (kbd == DotDashKeyboardView.KBD_UTILITY) {
249 | onKeyUtility(primaryCode);
250 | }
251 | }
252 |
253 | /**
254 | * Handle key input on the utility keyboard. Keys with a positive keycode
255 | * are meant to be passed through String.valueOf(), while keys with negative
256 | * keycodes must be specially processed
257 | *
258 | * @param primaryCode
259 | */
260 | private void onKeyUtility(int primaryCode) {
261 | if (primaryCode > 0) {
262 | getCurrentInputConnection().commitText(
263 | String.valueOf((char) primaryCode), 1);
264 | } else {
265 | switch (primaryCode) {
266 | case KEYCODE_UP:
267 | sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_UP);
268 | break;
269 | case KEYCODE_LEFT:
270 | sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
271 | break;
272 | case KEYCODE_RIGHT:
273 | sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
274 | break;
275 | case KEYCODE_DOWN:
276 | sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_DOWN);
277 | break;
278 | case KEYCODE_DEL:
279 | sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
280 | break;
281 | case KEYCODE_HOME:
282 | getCurrentInputConnection().setSelection(0, 0);
283 | break;
284 | case KEYCODE_END:
285 | ExtractedText et = getCurrentInputConnection()
286 | .getExtractedText(new ExtractedTextRequest(), 0);
287 | if (et != null) {
288 | int length = et.text.length();
289 | getCurrentInputConnection().setSelection(length, length);
290 | }
291 | break;
292 | }
293 |
294 | }
295 | }
296 |
297 | /**
298 | * Handle key input on the Morse Code keyboard. It has 5 keys and each of
299 | * them does something different.
300 | *
301 | * @param primaryCode
302 | */
303 | private void onKeyMorse(int primaryCode) {
304 | // Log.d(TAG, "primaryCode: " + Integer.toString(primaryCode));
305 | //String curCharMatch = morseMap.get(charInProgress.toString());
306 |
307 | switch (primaryCode) {
308 |
309 | // 0 represents a dot, 1 represents a dash
310 | // TODO The documentation for Keyboard.Key says I should be
311 | // able to give a key a string as a keycode, but it
312 | // errors out every time I try it.
313 | case DotDashKeyboard.KEYCODE_DOT:
314 | case DotDashKeyboard.KEYCODE_DASH:
315 |
316 | if (charInProgress.length() < maxCodeLength) {
317 | charInProgress.append(primaryCode == DotDashKeyboard.KEYCODE_DASH ? "-" : ".");
318 | updateSpaceKey(true);
319 | }
320 |
321 | if (loaded && isAudio()) {
322 | int soundId;
323 | if (primaryCode == DotDashKeyboard.KEYCODE_DOT) {
324 | soundId = dotSound;
325 | } else {
326 | soundId = dashSound;
327 | }
328 |
329 | AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
330 | if (audioManager != null && (!prefs.getBoolean("audio_only_on_headphones", true) || audioManager.isWiredHeadsetOn())) {
331 | float actualVolume = (float) audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM);
332 | float maxVolume = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_SYSTEM);
333 | float volume = actualVolume / maxVolume;
334 | soundpool.play(soundId, volume, volume, 1, 0, 1f);
335 | }
336 | }
337 |
338 | // Log.d(TAG, "charInProgress: " + charInProgress);
339 | break;
340 |
341 | // Space button ends the current dotdash sequence
342 | // Space twice in a row sends through a standard space character
343 | case KeyEvent.KEYCODE_SPACE:
344 | inputView.handler.removeMessages(DotDashKeyboardView.MSG_AUTOCOMMIT);
345 | inputView.handler.removeMessages(DotDashKeyboardView.MSG_IAMBIC_PLAYING);
346 | inputView.iambic_both_pressed = false;
347 |
348 | if (charInProgress.length() == 0) {
349 | getCurrentInputConnection().commitText(" ", 1);
350 | } else {
351 | commitCodeGroup(false);
352 | }
353 | break;
354 |
355 | // If there's a character in progress, clear it
356 | // otherwise, send through a backspace keypress
357 | case KeyEvent.KEYCODE_DEL:
358 | inputView.handler.removeMessages(DotDashKeyboardView.MSG_AUTOCOMMIT);
359 | inputView.handler.removeMessages(DotDashKeyboardView.MSG_IAMBIC_PLAYING);
360 | inputView.iambic_both_pressed = false;
361 |
362 | if (charInProgress.length() > 0) {
363 | clearCharInProgress();
364 | updateSpaceKey(true);
365 | } else {
366 | sendDownUpKeyEvents(primaryCode);
367 |
368 | if (capsLockState == CAPS_LOCK_NEXT) {
369 | // If you've hit delete and you were in caps_next state,
370 | // then caps_off
371 | capsLockState = CAPS_LOCK_OFF;
372 | updateCapsLockKey(true);
373 | }
374 | }
375 | break;
376 |
377 | case KeyEvent.KEYCODE_SHIFT_LEFT:
378 | switch (capsLockState) {
379 | case CAPS_LOCK_OFF:
380 | capsLockState = CAPS_LOCK_NEXT;
381 | break;
382 | case CAPS_LOCK_NEXT:
383 | capsLockState = CAPS_LOCK_ALL;
384 | break;
385 | default:
386 | capsLockState = CAPS_LOCK_OFF;
387 | }
388 | updateCapsLockKey(false);
389 | break;
390 | }
391 | }
392 |
393 | public boolean isAudio() {
394 | return prefs.getBoolean("audio", false);
395 | }
396 |
397 | public void commitCodeGroup(boolean refreshScreen) {
398 | if (charInProgress.length() == 0) {
399 | return;
400 | }
401 |
402 | String curCharMatch = morseMap.get(charInProgress.toString());
403 | if (curCharMatch == null) {
404 | return;
405 | }
406 |
407 | if (curCharMatch.contentEquals("\n")) {
408 | sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
409 | } else if (curCharMatch.contentEquals("END")) {
410 | requestHideSelf(0);
411 | inputView.closing();
412 | } else {
413 |
414 | boolean uppercase = false;
415 | if (capsLockState == CAPS_LOCK_NEXT) {
416 | uppercase = true;
417 | capsLockState = CAPS_LOCK_OFF;
418 | updateCapsLockKey(true);
419 | } else if (capsLockState == CAPS_LOCK_ALL) {
420 | uppercase = true;
421 | }
422 | if (uppercase) {
423 | // Since we only support the Latin alphabet, I may as well use Locale.US
424 | curCharMatch = curCharMatch.toUpperCase(Locale.US);
425 | }
426 |
427 | // Log.d(TAG, "Char identified as " + curCharMatch);
428 | InputConnection ic = getCurrentInputConnection();
429 | if (ic != null) {
430 | ic.commitText(curCharMatch, curCharMatch.length());
431 | }
432 |
433 | }
434 |
435 | clearCharInProgress();
436 | updateSpaceKey(refreshScreen);
437 | }
438 |
439 | private void clearCharInProgress() {
440 | charInProgress.setLength(0);
441 | }
442 |
443 | public void onPress(int arg0) {
444 | // TODO Auto-generated method stub
445 |
446 | }
447 |
448 | public void onRelease(int arg0) {
449 | // TODO Auto-generated method stub
450 |
451 | }
452 |
453 | public void onText(CharSequence arg0) {
454 | // TODO Auto-generated method stub
455 |
456 | }
457 |
458 | public void swipeDown() {
459 | // TODO Auto-generated method stub
460 |
461 | }
462 |
463 | public void swipeLeft() {
464 | // TODO Auto-generated method stub
465 |
466 | }
467 |
468 | public void swipeRight() {
469 | // TODO Auto-generated method stub
470 |
471 | }
472 |
473 | public void swipeUp() {
474 | // TODO Auto-generated method stub
475 |
476 | }
477 |
478 | private void clearEverything() {
479 | clearCharInProgress();
480 | capsLockState = CAPS_LOCK_OFF;
481 | updateCapsLockKey(false);
482 | updateSpaceKey(false);
483 | }
484 |
485 | private void updateCapsLockKey(boolean refreshScreen) {
486 |
487 | Context context = this.getApplicationContext();
488 | switch (capsLockState) {
489 | case CAPS_LOCK_OFF:
490 | capsLockKey.on = false;
491 | capsLockKey.label = context.getText(R.string.caps_lock_off);
492 | break;
493 | case CAPS_LOCK_NEXT:
494 | capsLockKey.on = false;
495 | capsLockKey.label = context.getText(R.string.caps_lock_next);
496 | break;
497 | case CAPS_LOCK_ALL:
498 | capsLockKey.on = true;
499 | capsLockKey.label = context.getText(R.string.caps_lock_all);
500 | break;
501 | }
502 |
503 | if (refreshScreen) {
504 |
505 | // Wrapping this in a try/catch block to avoid crashes in Android
506 | // 2.1 and earlier, and inexplicable NullPointerExceptions
507 | try {
508 | inputView.invalidateKey(capsLockKeyIndex);
509 | } catch (Exception e) {
510 | // It doesn't matter if the operation failed, so just ignore
511 | // this
512 | }
513 | }
514 | }
515 |
516 | /**
517 | * Updates the space bar to display the current character in progress
518 | *
519 | * @param refreshScreen
520 | */
521 | private void updateSpaceKey(boolean refreshScreen) {
522 | String newLabel = charInProgress.toString();
523 |
524 | // Workaround to maintain consistent styling. Android puts multi-character
525 | // labels in bold, and single-characters in non-bold. To make the bold state
526 | // consistent, we turn our single-character label into a three-character one
527 | // by padding it with spaces.
528 | if (newLabel.length() == 1) {
529 | newLabel = " " + newLabel + " ";
530 | }
531 |
532 | if (!spaceKey.label.toString().equals(newLabel)) {
533 | // Log.d(TAG, "!spaceKey.label.equals(charInProgress)");
534 | if (newLabel.length() > 0 && ditDahCharsPref == DIT_DAH_CHARS_UNICODE) {
535 | newLabel = convertDitDahAsciiToUnicode(newLabel);
536 | }
537 | spaceKey.label = newLabel;
538 | if (refreshScreen) {
539 | // Wrapping this in a try/catch block to avoid crashes in
540 | // Android 2.1 and earlier
541 | try {
542 | inputView.invalidateKey(spaceKeyIndex);
543 | } catch (IllegalArgumentException iae) {
544 | // It doesn't matter if the operation failed, so just ignore
545 | // this
546 | }
547 | }
548 | }
549 | }
550 |
551 | public void onStartInputView(android.view.inputmethod.EditorInfo info,
552 | boolean restarting) {
553 | // Log.d(TAG, "onStartInputView");
554 | super.onStartInputView(info, restarting);
555 |
556 | // // Wrapping this in a try/catch block to avoid crashes in Android 2.1
557 | // // and earlier
558 | updateAutoCap();
559 | updateCapsLockKey(true);
560 | updateSpaceKey(true);
561 | }
562 |
563 | @Override
564 | public void onFinishInputView(boolean finishingInput) {
565 | // Log.d(TAG, "onFinishInputView");
566 | this.inputView.closeCheatSheet();
567 | super.onFinishInputView(finishingInput);
568 | clearEverything();
569 | }
570 |
571 | @Override
572 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
573 | String key) {
574 | if (key.contentEquals(DotDashPrefs.NEWLINE_CODE)) {
575 | updateNewlinePref();
576 | } else if (key.contentEquals(DotDashPrefs.ENABLE_UTIL_KBD)) {
577 | this.setupUtilityKeyboard();
578 | if (this.inputView != null) {
579 | inputView.mEnableUtilityKeyboard = prefs.getBoolean(key, false);
580 | if (!prefs.getBoolean(key, false)) {
581 | inputView.setKeyboard(dotDashKeyboard);
582 | }
583 | }
584 | } else if (key.contentEquals(DotDashPrefs.DIT_DAH_CHARS)) {
585 | this.ditDahCharsPref = Integer.valueOf(this.prefs.getString(DotDashPrefs.DIT_DAH_CHARS, Integer.toString(DIT_DAH_CHARS_UNICODE)));
586 | if (inputView != null) {
587 | inputView.clearCheatSheet();
588 | }
589 | } else if (key.contentEquals(DotDashPrefs.DASH_KEY_ON_LEFT)) {
590 | boolean changed = this.dotDashKeyboard.setupDotDashKeys(this.prefs.getBoolean(key, false));
591 | if (changed && this.inputView != null) {
592 | this.inputView.invalidateAllKeys();
593 | }
594 | } else if (key.contentEquals("audio")) {
595 | if (prefs.getBoolean(key, false)) {
596 | loaded = false;
597 | loadSoundPool();
598 | } else {
599 | if (soundpool != null) {
600 | soundpool.release();
601 | soundpool = null;
602 | loaded = false;
603 | }
604 | }
605 | } else if (key.contentEquals("iambic")) {
606 | this.iambic = prefs.getBoolean(key, false);
607 | } else if (key.contentEquals("iambicModeB")) {
608 | this.iambicModeB = prefs.getBoolean(key, false);
609 | } else if (key.contentEquals("autocommit")) {
610 | this.autocommit = prefs.getBoolean(key, false);
611 | }
612 | }
613 |
614 | /**
615 | * Updates the newline character stored in morseMap, based on the user's
616 | * current preferences.
617 | *
618 | * Not sure how I'm going to support this when I switch the codes to a
619 | * selectable XML system...
620 | */
621 | private void updateNewlinePref() {
622 | // Remove the old ones
623 | if (newlineGroups != null) {
624 | for (String s : newlineGroups) {
625 | morseMap.remove(s);
626 | }
627 | }
628 |
629 | // Add the new ones
630 | // TODO: When we make the morse codes into XML, this'll have to be
631 | // updated
632 | String rawPref = this.prefs.getString(DotDashPrefs.NEWLINE_CODE, ".-.-");
633 | // Log.d(TAG, "rawPref: "+rawPref);
634 | if (rawPref.contentEquals(DotDashPrefs.NEWLINE_CODE_NONE)) {
635 | newlineGroups = null;
636 | } else {
637 | newlineGroups = rawPref.split("\\|");
638 | // Log.d(TAG, "nl: " + newlineGroups[0]);
639 | }
640 |
641 | if (newlineGroups != null) {
642 | for (String s : newlineGroups) {
643 | morseMap.put(s, "\n");
644 | }
645 | }
646 | if (inputView != null) {
647 | inputView.updateNewlineCode();
648 | }
649 | }
650 |
651 | /**
652 | * The cursor position (selection position) has changed
653 | */
654 | @Override
655 | public void onUpdateSelection(int oldSelStart, int oldSelEnd,
656 | int newSelStart, int newSelEnd, int candidatesStart,
657 | int candidatesEnd) {
658 | super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
659 | candidatesStart, candidatesEnd);
660 | updateAutoCap();
661 | }
662 |
663 | /**
664 | * Update the shift state if autocap is turned on, based on current cursor
665 | * position (using InputConnection.getCursorCapsMode())
666 | */
667 | private void updateAutoCap() {
668 |
669 | // Autocap has no effect if Caps Lock is on
670 | if (capsLockState == CAPS_LOCK_ALL) {
671 | return;
672 | }
673 |
674 | // Don't bother with any of this is autocap is turned off
675 | if (!prefs.getBoolean(DotDashPrefs.AUTOCAP, false)) {
676 | return;
677 | }
678 |
679 | int origCapsLockState = capsLockState;
680 | int newCapsLockState = CAPS_LOCK_OFF;
681 |
682 | EditorInfo ei = getCurrentInputEditorInfo();
683 | if (ei != null
684 | && ei.inputType != EditorInfo.TYPE_NULL
685 | && getCurrentInputConnection().getCursorCapsMode(ei.inputType) > 0) {
686 | newCapsLockState = CAPS_LOCK_NEXT;
687 | }
688 | capsLockState = newCapsLockState;
689 | if (capsLockState != origCapsLockState) {
690 | updateCapsLockKey(true);
691 | }
692 | }
693 |
694 | /**
695 | * Converts a string of ASCII ditdahs to Unicode
696 | *
697 | * @param ascii
698 | * @return
699 | */
700 | private String convertDitDahAsciiToUnicode(String ascii) {
701 | return ascii
702 | .replace(".", DotDashIMEService.UNICODE_DOT)
703 | .replace("-", DotDashIMEService.UNICODE_DASH);
704 | }
705 |
706 | /**
707 | * Converts a string of Unicode ditdahs to ASCII
708 | *
709 | * @param unicode The original string with unicode ditdahs
710 | * @return
711 | */
712 | String convertDitDahUnicodeToAscii(String unicode) {
713 | return unicode
714 | .replace(DotDashIMEService.UNICODE_DOT, (". "))
715 | .replace(DotDashIMEService.UNICODE_DASH, ("- "))
716 | .trim();
717 | }
718 | }
719 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------