Skip to content

Commit 3b137f2

Browse files
committed
added a few missing key constants
1 parent 5dc5a2a commit 3b137f2

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

core/src/processing/android/CompatUtils.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@
2222

2323
package processing.android;
2424

25+
import java.nio.charset.Charset;
26+
import java.nio.charset.StandardCharsets;
2527
import java.util.concurrent.atomic.AtomicInteger;
2628
import android.annotation.SuppressLint;
2729
import android.os.Build;
2830
import android.util.DisplayMetrics;
2931
import android.view.Display;
3032
import android.view.View;
3133
import android.graphics.Point;
32-
34+
import android.view.PixelCopy;
3335

3436
/**
3537
* Compatibility utilities that work across versions of Android. Even though
@@ -55,7 +57,7 @@ static public void getDisplayParams(Display display,
5557
if (Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT) {
5658
display.getRealMetrics(metrics);
5759
display.getRealSize(size);
58-
} if (Build.VERSION_CODES.ICE_CREAM_SANDWICH <= Build.VERSION.SDK_INT) {
60+
} if (Build.VERSION_CODES.ICE_CREAM_SANDWICH <= Build.VERSION.SDK_INT) {
5961
display.getMetrics(metrics);
6062
// Use undocumented methods getRawWidth, getRawHeight
6163
try {
@@ -79,7 +81,7 @@ static public void getDisplayParams(Display display,
7981
*/
8082
@SuppressLint("NewApi")
8183
static public int getUniqueViewId() {
82-
if (Build.VERSION_CODES.JELLY_BEAN_MR1 < Build.VERSION.SDK_INT) {
84+
if (Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT) {
8385
return View.generateViewId();
8486
} else {
8587
for (;;) {
@@ -93,4 +95,18 @@ static public int getUniqueViewId() {
9395
}
9496
}
9597
}
98+
99+
100+
/**
101+
* This method returns the UTF-8 charset
102+
* @return UTF-8 charset
103+
*/
104+
@SuppressLint("NewApi")
105+
static public Charset getCharsetUTF8() {
106+
if (Build.VERSION_CODES.KITKAT <= Build.VERSION.SDK_INT) {
107+
return StandardCharsets.UTF_8;
108+
} else {
109+
return Charset.forName("UTF-8");
110+
}
111+
}
96112
}

core/src/processing/core/PApplet.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import processing.a2d.PGraphicsAndroid2D;
5959
import processing.android.ActivityAPI;
6060
import processing.android.AppComponent;
61+
import processing.android.CompatUtils;
6162
import processing.data.*;
6263
import processing.event.*;
6364
import processing.opengl.*;
@@ -2492,8 +2493,6 @@ protected void nativeKeyEvent(android.view.KeyEvent event) {
24922493
// TODO set up proper key modifier handling
24932494
int keModifiers = 0;
24942495

2495-
// KeyEvent ke = new KeyEvent(event, event.getEventTime(),
2496-
// keAction, keModifiers, key, keyCode);
24972496
KeyEvent ke = new KeyEvent(event, event.getEventTime(),
24982497
keAction, keModifiers, key, keyCode, 0 < event.getRepeatCount());
24992498

@@ -4776,7 +4775,7 @@ static public BufferedReader createReader(File file) {
47764775
*/
47774776
static public BufferedReader createReader(InputStream input) {
47784777
InputStreamReader isr =
4779-
new InputStreamReader(input, StandardCharsets.UTF_8);
4778+
new InputStreamReader(input, CompatUtils.getCharsetUTF8());
47804779

47814780
BufferedReader reader = new BufferedReader(isr);
47824781
// consume the Unicode BOM (byte order marker) if present
@@ -4834,7 +4833,7 @@ static public PrintWriter createWriter(File file) {
48344833
static public PrintWriter createWriter(OutputStream output) {
48354834
BufferedOutputStream bos = new BufferedOutputStream(output, 8192);
48364835
OutputStreamWriter osw =
4837-
new OutputStreamWriter(bos, StandardCharsets.UTF_8);
4836+
new OutputStreamWriter(bos, CompatUtils.getCharsetUTF8());
48384837
return new PrintWriter(osw);
48394838
}
48404839

core/src/processing/core/PConstants.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,12 @@ public interface PConstants {
349349
// for 0125, these were changed to 'char' values, because they
350350
// can be upgraded to ints automatically by Java, but having them
351351
// as ints prevented split(blah, TAB) from working
352-
static final char BACKSPACE = 8;
353-
static final char TAB = 9;
354-
static final char ENTER = 10;
355-
static final char RETURN = 13;
356-
static final char ESC = 27;
357-
static final char DELETE = 127;
352+
static final char BACKSPACE = KeyEvent.KEYCODE_DEL;
353+
static final char TAB = KeyEvent.KEYCODE_TAB;
354+
static final char ENTER = KeyEvent.KEYCODE_ENTER;
355+
static final char RETURN = KeyEvent.KEYCODE_ENTER;
356+
static final char ESC = KeyEvent.KEYCODE_ESCAPE;
357+
static final char DELETE = KeyEvent.KEYCODE_DEL;
358358

359359
// i.e. if ((key == CODED) && (keyCode == UP))
360360
static final int CODED = 0xffff;
@@ -376,8 +376,7 @@ public interface PConstants {
376376
// key will be CODED and keyCode will be this value
377377
// static final int ALT = KeyEvent.VK_ALT;
378378
// static final int CONTROL = KeyEvent.VK_CONTROL;
379-
// static final int SHIFT = KeyEvent.VK_SHIFT;
380-
379+
static final int SHIFT = KeyEvent.KEYCODE_SHIFT_LEFT;
381380

382381
// cursor types
383382

0 commit comments

Comments
 (0)