Mercurial > repos > blastem
annotate android/src/org/libsdl/app/SDLActivity.java @ 2515:0775f5e0c468 default tip
Clear EDT on DTTRG. Fixes Cliffhanger and OrionNavattan's Mode 1 demo
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 05 Sep 2024 23:44:01 -0700 |
parents | 78abbabfd58d |
children | 13abdc98379e |
rev | line source |
---|---|
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 package org.libsdl.app; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
3 import java.io.IOException; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
4 import java.io.InputStream; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 import java.util.Arrays; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
6 import java.lang.reflect.Method; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
7 import java.util.Objects; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 import android.app.*; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 import android.content.*; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
11 import android.text.InputType; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 import android.view.*; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 import android.view.inputmethod.BaseInputConnection; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 import android.view.inputmethod.EditorInfo; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 import android.view.inputmethod.InputConnection; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 import android.view.inputmethod.InputMethodManager; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
17 import android.widget.RelativeLayout; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
18 import android.widget.Button; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
19 import android.widget.LinearLayout; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
20 import android.widget.TextView; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 import android.os.*; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 import android.util.Log; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
23 import android.util.SparseArray; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 import android.graphics.*; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
25 import android.graphics.drawable.Drawable; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 import android.hardware.*; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
27 import android.content.pm.ActivityInfo; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 /** |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 SDL Activity |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 */ |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 public class SDLActivity extends Activity { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 private static final String TAG = "SDL"; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
35 public static boolean mIsResumedCalled, mIsSurfaceReady, mHasFocus; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
36 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
37 // Handle the state of the native layer |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
38 public enum NativeState { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
39 INIT, RESUMED, PAUSED |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
40 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
41 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
42 public static NativeState mNextNativeState; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
43 public static NativeState mCurrentNativeState; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
44 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 public static boolean mExitCalledFromJava; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
47 /** If shared libraries (e.g. SDL or the native application) could not be loaded. */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
48 public static boolean mBrokenLibraries; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
49 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
50 // If we want to separate mouse and touch events. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
51 // This is only toggled in native code when a hint is set! |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
52 public static boolean mSeparateMouseAndTouch; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
53 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 // Main components |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 protected static SDLActivity mSingleton; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 protected static SDLSurface mSurface; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 protected static View mTextEdit; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
58 protected static boolean mScreenKeyboardShown; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 protected static ViewGroup mLayout; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
60 protected static SDLClipboardHandler mClipboardHandler; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
61 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 // This is what SDL runs in. It invokes SDL_main(), eventually |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 protected static Thread mSDLThread; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
65 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
66 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
67 * This method returns the name of the shared object with the application entry point |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
68 * It can be overridden by derived classes. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
69 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
70 protected String getMainSharedObject() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
71 String library; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
72 String[] libraries = SDLActivity.mSingleton.getLibraries(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
73 if (libraries.length > 0) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
74 library = "lib" + libraries[libraries.length - 1] + ".so"; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
75 } else { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
76 library = "libmain.so"; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
77 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
78 return library; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
79 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
80 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
81 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
82 * This method returns the name of the application entry point |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
83 * It can be overridden by derived classes. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
84 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
85 protected String getMainFunction() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
86 return "SDL_main"; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
87 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
88 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
89 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
90 * This method is called by SDL before loading the native shared libraries. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
91 * It can be overridden to provide names of shared libraries to be loaded. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
92 * The default implementation returns the defaults. It never returns null. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
93 * An array returned by a new implementation must at least contain "SDL2". |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
94 * Also keep in mind that the order the libraries are loaded may matter. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
95 * @return names of shared libraries to be loaded (e.g. "SDL2", "main"). |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
96 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
97 protected String[] getLibraries() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
98 return new String[] { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
99 "SDL2", |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
100 // "SDL2_image", |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
101 // "SDL2_mixer", |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
102 // "SDL2_net", |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
103 // "SDL2_ttf", |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
104 "main" |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
105 }; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
106 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 // Load the .so |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
109 public void loadLibraries() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
110 for (String lib : getLibraries()) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
111 System.loadLibrary(lib); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
112 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
114 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
115 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
116 * This method is called by SDL before starting the native application thread. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
117 * It can be overridden to provide the arguments after the application name. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
118 * The default implementation returns an empty array. It never returns null. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
119 * @return arguments for the native application. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
120 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
121 protected String[] getArguments() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
122 return new String[0]; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
123 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
124 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 public static void initialize() { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 // The static nature of the singleton and Android quirkyness force us to initialize everything here |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 // Otherwise, when exiting the app and returning to it, these variables *keep* their pre exit values |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 mSingleton = null; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 mSurface = null; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 mTextEdit = null; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 mLayout = null; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
132 mClipboardHandler = null; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 mSDLThread = null; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 mExitCalledFromJava = false; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
135 mBrokenLibraries = false; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
136 mIsResumedCalled = false; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 mIsSurfaceReady = false; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 mHasFocus = true; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
139 mNextNativeState = NativeState.INIT; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
140 mCurrentNativeState = NativeState.INIT; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 // Setup |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 protected void onCreate(Bundle savedInstanceState) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
146 Log.v(TAG, "Device: " + android.os.Build.DEVICE); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
147 Log.v(TAG, "Model: " + android.os.Build.MODEL); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
148 Log.v(TAG, "onCreate()"); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 super.onCreate(savedInstanceState); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
150 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
151 // Load shared libraries |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
152 String errorMsgBrokenLib = ""; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
153 try { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
154 loadLibraries(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
155 } catch(UnsatisfiedLinkError e) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
156 System.err.println(e.getMessage()); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
157 mBrokenLibraries = true; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
158 errorMsgBrokenLib = e.getMessage(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
159 } catch(Exception e) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
160 System.err.println(e.getMessage()); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
161 mBrokenLibraries = true; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
162 errorMsgBrokenLib = e.getMessage(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
163 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
164 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
165 if (mBrokenLibraries) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
166 { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
167 AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
168 dlgAlert.setMessage("An error occurred while trying to start the application. Please try again and/or reinstall." |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
169 + System.getProperty("line.separator") |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
170 + System.getProperty("line.separator") |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
171 + "Error: " + errorMsgBrokenLib); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
172 dlgAlert.setTitle("SDL Error"); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
173 dlgAlert.setPositiveButton("Exit", |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
174 new DialogInterface.OnClickListener() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
175 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
176 public void onClick(DialogInterface dialog,int id) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
177 // if this button is clicked, close current activity |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
178 SDLActivity.mSingleton.finish(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
179 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
180 }); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
181 dlgAlert.setCancelable(false); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
182 dlgAlert.create().show(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
183 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
184 return; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
185 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
186 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
187 // Set up JNI |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
188 SDL.setupJNI(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
189 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
190 // Initialize state |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
191 SDL.initialize(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
192 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 // So we can call stuff from static callbacks |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 mSingleton = this; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
195 SDL.setContext(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
196 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
197 if (Build.VERSION.SDK_INT >= 11) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
198 mClipboardHandler = new SDLClipboardHandler_API11(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
199 } else { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
200 /* Before API 11, no clipboard notification (eg no SDL_CLIPBOARDUPDATE) */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
201 mClipboardHandler = new SDLClipboardHandler_Old(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
202 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 // Set up the surface |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 mSurface = new SDLSurface(getApplication()); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
207 mLayout = new RelativeLayout(this); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 mLayout.addView(mSurface); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 setContentView(mLayout); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
211 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
212 // Get filename from "Open with" of another application |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
213 Intent intent = getIntent(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
214 if (intent != null && intent.getData() != null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
215 String filename = intent.getData().getPath(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
216 if (filename != null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
217 Log.v(TAG, "Got filename: " + filename); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
218 SDLActivity.onNativeDropFile(filename); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
219 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
220 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 // Events |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 protected void onPause() { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
226 Log.v(TAG, "onPause()"); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 super.onPause(); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
228 mNextNativeState = NativeState.PAUSED; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
229 mIsResumedCalled = false; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
230 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
231 if (SDLActivity.mBrokenLibraries) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
232 return; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
233 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
234 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
235 SDLActivity.handleNativeState(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 protected void onResume() { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
240 Log.v(TAG, "onResume()"); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 super.onResume(); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
242 mNextNativeState = NativeState.RESUMED; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
243 mIsResumedCalled = true; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
244 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
245 if (SDLActivity.mBrokenLibraries) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
246 return; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
247 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
248 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
249 SDLActivity.handleNativeState(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 public void onWindowFocusChanged(boolean hasFocus) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 super.onWindowFocusChanged(hasFocus); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
256 Log.v(TAG, "onWindowFocusChanged(): " + hasFocus); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
257 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
258 if (SDLActivity.mBrokenLibraries) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
259 return; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
260 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 SDLActivity.mHasFocus = hasFocus; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 if (hasFocus) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
264 mNextNativeState = NativeState.RESUMED; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
265 } else { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
266 mNextNativeState = NativeState.PAUSED; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
268 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
269 SDLActivity.handleNativeState(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 public void onLowMemory() { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
274 Log.v(TAG, "onLowMemory()"); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 super.onLowMemory(); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
276 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
277 if (SDLActivity.mBrokenLibraries) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
278 return; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
279 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
280 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 SDLActivity.nativeLowMemory(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 protected void onDestroy() { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
286 Log.v(TAG, "onDestroy()"); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
287 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
288 if (SDLActivity.mBrokenLibraries) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
289 super.onDestroy(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
290 // Reset everything in case the user re opens the app |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
291 SDLActivity.initialize(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
292 return; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
293 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
294 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
295 mNextNativeState = NativeState.PAUSED; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
296 SDLActivity.handleNativeState(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
297 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
298 // Send a quit message to the application |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 SDLActivity.mExitCalledFromJava = true; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 SDLActivity.nativeQuit(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 // Now wait for the SDL thread to quit |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 if (SDLActivity.mSDLThread != null) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 try { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 SDLActivity.mSDLThread.join(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 } catch(Exception e) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
307 Log.v(TAG, "Problem stopping thread: " + e); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 SDLActivity.mSDLThread = null; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
311 //Log.v(TAG, "Finished waiting for SDL thread"); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
313 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 super.onDestroy(); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
315 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 // Reset everything in case the user re opens the app |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 SDLActivity.initialize(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 public boolean dispatchKeyEvent(KeyEvent event) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
322 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
323 if (SDLActivity.mBrokenLibraries) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
324 return false; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
325 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
326 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 int keyCode = event.getKeyCode(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 // Ignore certain special keys so they're handled by Android |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 keyCode == KeyEvent.KEYCODE_VOLUME_UP || |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
331 keyCode == KeyEvent.KEYCODE_CAMERA || |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
332 keyCode == KeyEvent.KEYCODE_ZOOM_IN || /* API 11 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
333 keyCode == KeyEvent.KEYCODE_ZOOM_OUT /* API 11 */ |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 ) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 return false; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 return super.dispatchKeyEvent(event); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
339 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
340 /* Transition to next state */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
341 public static void handleNativeState() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
342 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
343 if (mNextNativeState == mCurrentNativeState) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
344 // Already in same state, discard. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
345 return; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
346 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
347 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
348 // Try a transition to init state |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
349 if (mNextNativeState == NativeState.INIT) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
350 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
351 mCurrentNativeState = mNextNativeState; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
352 return; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
353 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
354 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
355 // Try a transition to paused state |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
356 if (mNextNativeState == NativeState.PAUSED) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
357 nativePause(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
358 mSurface.handlePause(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
359 mCurrentNativeState = mNextNativeState; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
360 return; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
361 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
362 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
363 // Try a transition to resumed state |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
364 if (mNextNativeState == NativeState.RESUMED) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
365 if (mIsSurfaceReady && mHasFocus && mIsResumedCalled) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
366 if (mSDLThread == null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
367 // This is the entry point to the C app. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
368 // Start up the C app thread and enable sensor input for the first time |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
369 // FIXME: Why aren't we enabling sensor input at start? |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
370 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
371 final Thread sdlThread = new Thread(new SDLMain(), "SDLThread"); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
372 mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
373 sdlThread.start(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
374 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
375 // Set up a listener thread to catch when the native thread ends |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
376 mSDLThread = new Thread(new Runnable() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
377 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
378 public void run() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
379 try { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
380 sdlThread.join(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
381 } catch (Exception e) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
382 // Ignore any exception |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
383 } finally { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
384 // Native thread has finished |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
385 if (!mExitCalledFromJava) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
386 handleNativeExit(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
387 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
388 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
389 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
390 }, "SDLThreadListener"); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
391 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
392 mSDLThread.start(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
393 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
394 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
395 nativeResume(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
396 mSurface.handleResume(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
397 mCurrentNativeState = mNextNativeState; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
398 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 /* The native thread has finished */ |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 public static void handleNativeExit() { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 SDLActivity.mSDLThread = null; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 mSingleton.finish(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
409 // Messages from the SDLMain thread |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 static final int COMMAND_CHANGE_TITLE = 1; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 static final int COMMAND_UNUSED = 2; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 static final int COMMAND_TEXTEDIT_HIDE = 3; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
413 static final int COMMAND_SET_KEEP_SCREEN_ON = 5; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
414 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
415 protected static final int COMMAND_USER = 0x8000; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
416 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
417 /** |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
418 * This method is called by SDL if SDL did not handle a message itself. |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
419 * This happens if a received message contains an unsupported command. |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 * Method can be overwritten to handle Messages in a different class. |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 * @param command the command of the message. |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 * @param param the parameter of the message. May be null. |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 * @return if the message was handled in overridden method. |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 */ |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 protected boolean onUnhandledMessage(int command, Object param) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 return false; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
427 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 /** |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 * A Handler class for Messages from native SDL applications. |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
431 * It uses current Activities as target (e.g. for the title). |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
432 * static to prevent implicit references to enclosing object. |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 */ |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 protected static class SDLCommandHandler extends Handler { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 public void handleMessage(Message msg) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
437 Context context = SDL.getContext(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 if (context == null) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
439 Log.e(TAG, "error handling message, getContext() returned null"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
440 return; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
441 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 switch (msg.arg1) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
443 case COMMAND_CHANGE_TITLE: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
444 if (context instanceof Activity) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
445 ((Activity) context).setTitle((String)msg.obj); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
446 } else { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
447 Log.e(TAG, "error handling message, getContext() returned no Activity"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
448 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
449 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
450 case COMMAND_TEXTEDIT_HIDE: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
451 if (mTextEdit != null) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
452 // Note: On some devices setting view to GONE creates a flicker in landscape. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
453 // Setting the View's sizes to 0 is similar to GONE but without the flicker. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
454 // The sizes will be set to useful values when the keyboard is shown again. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
455 mTextEdit.setLayoutParams(new RelativeLayout.LayoutParams(0, 0)); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
456 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
458 imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
459 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
460 mScreenKeyboardShown = false; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 break; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
463 case COMMAND_SET_KEEP_SCREEN_ON: |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
464 { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
465 if (context instanceof Activity) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
466 Window window = ((Activity) context).getWindow(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
467 if (window != null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
468 if ((msg.obj instanceof Integer) && (((Integer) msg.obj).intValue() != 0)) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
469 window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
470 } else { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
471 window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
472 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
473 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
474 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
475 break; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
476 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 default: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 if ((context instanceof SDLActivity) && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 Log.e(TAG, "error handling message, command is " + msg.arg1); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 // Handler for the messages |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 Handler commandHandler = new SDLCommandHandler(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 // Send a message from the SDLMain thread |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 boolean sendCommand(int command, Object data) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 Message msg = commandHandler.obtainMessage(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 msg.arg1 = command; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
492 msg.obj = data; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 return commandHandler.sendMessage(msg); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 // C functions we call |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
497 public static native int nativeSetupJNI(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
498 public static native int nativeRunMain(String library, String function, Object arguments); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 public static native void nativeLowMemory(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 public static native void nativeQuit(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 public static native void nativePause(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 public static native void nativeResume(); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
503 public static native void onNativeDropFile(String filename); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
504 public static native void onNativeResize(int x, int y, int format, float rate); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 public static native void onNativeKeyDown(int keycode); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
506 public static native void onNativeKeyUp(int keycode); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 public static native void onNativeKeyboardFocusLost(); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
508 public static native void onNativeMouse(int button, int action, float x, float y); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
509 public static native void onNativeTouch(int touchDevId, int pointerFingerId, |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
510 int action, float x, |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
511 float y, float p); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
512 public static native void onNativeAccel(float x, float y, float z); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
513 public static native void onNativeClipboardChanged(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
514 public static native void onNativeSurfaceChanged(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
515 public static native void onNativeSurfaceDestroyed(); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
516 public static native String nativeGetHint(String name); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
517 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
518 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
519 * This method is called by SDL using JNI. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
520 */ |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
521 public static boolean setActivityTitle(String title) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
522 // Called from SDLMain() thread and can't directly affect the view |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
523 return mSingleton.sendCommand(COMMAND_CHANGE_TITLE, title); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
524 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
525 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
526 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
527 * This method is called by SDL using JNI. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
528 * This is a static method for JNI convenience, it calls a non-static method |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
529 * so that is can be overridden |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
530 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
531 public static void setOrientation(int w, int h, boolean resizable, String hint) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
532 { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
533 if (mSingleton != null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
534 mSingleton.setOrientationBis(w, h, resizable, hint); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
535 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
536 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
537 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
538 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
539 * This can be overridden |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
540 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
541 public void setOrientationBis(int w, int h, boolean resizable, String hint) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
542 { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
543 int orientation = -1; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
544 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
545 if (!Objects.equals(hint, "")) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
546 if (hint.contains("LandscapeRight") && hint.contains("LandscapeLeft")) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
547 orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
548 } else if (hint.contains("LandscapeRight")) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
549 orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
550 } else if (hint.contains("LandscapeLeft")) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
551 orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
552 } else if (hint.contains("Portrait") && hint.contains("PortraitUpsideDown")) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
553 orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
554 } else if (hint.contains("Portrait")) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
555 orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
556 } else if (hint.contains("PortraitUpsideDown")) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
557 orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
558 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
559 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
560 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
561 /* no valid hint */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
562 if (orientation == -1) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
563 if (resizable) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
564 /* no fixed orientation */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
565 } else { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
566 if (w > h) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
567 orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
568 } else { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
569 orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
570 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
571 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
572 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
573 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
574 Log.v("SDL", "setOrientation() orientation=" + orientation + " width=" + w +" height="+ h +" resizable=" + resizable + " hint=" + hint); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
575 if (orientation != -1) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
576 mSingleton.setRequestedOrientation(orientation); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
577 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
578 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
579 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
580 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
581 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
582 * This method is called by SDL using JNI. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
583 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
584 public static boolean isScreenKeyboardShown() |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
585 { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
586 if (mTextEdit == null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
587 return false; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
588 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
589 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
590 if (!mScreenKeyboardShown) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
591 return false; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
592 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
593 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
594 InputMethodManager imm = (InputMethodManager) SDL.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
595 return imm.isAcceptingText(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
596 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
597 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
598 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
599 /** |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
600 * This method is called by SDL using JNI. |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
601 */ |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
602 public static boolean sendMessage(int command, int param) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
603 if (mSingleton == null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
604 return false; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
605 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
606 return mSingleton.sendCommand(command, Integer.valueOf(param)); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
607 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
608 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
609 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
610 * This method is called by SDL using JNI. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
611 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
612 public static Context getContext() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
613 return SDL.getContext(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
614 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
615 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
616 static class ShowTextInputTask implements Runnable { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
617 /* |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
618 * This is used to regulate the pan&scan method to have some offset from |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
619 * the bottom edge of the input region and the top edge of an input |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
620 * method (soft keyboard) |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
621 */ |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
622 static final int HEIGHT_PADDING = 15; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
623 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
624 public int x, y, w, h; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
625 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
626 public ShowTextInputTask(int x, int y, int w, int h) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
627 this.x = x; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
628 this.y = y; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
629 this.w = w; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
630 this.h = h; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
631 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
632 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
633 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
634 public void run() { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
635 RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(w, h + HEIGHT_PADDING); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
636 params.leftMargin = x; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
637 params.topMargin = y; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
638 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
639 if (mTextEdit == null) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
640 mTextEdit = new DummyEdit(SDL.getContext()); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
641 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
642 mLayout.addView(mTextEdit, params); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
643 } else { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
644 mTextEdit.setLayoutParams(params); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
645 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
646 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
647 mTextEdit.setVisibility(View.VISIBLE); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
648 mTextEdit.requestFocus(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
649 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
650 InputMethodManager imm = (InputMethodManager) SDL.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
651 imm.showSoftInput(mTextEdit, 0); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
652 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
653 mScreenKeyboardShown = true; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
654 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
655 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
656 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
657 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
658 * This method is called by SDL using JNI. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
659 */ |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
660 public static boolean showTextInput(int x, int y, int w, int h) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
661 // Transfer the task to the main thread as a Runnable |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
662 return mSingleton.commandHandler.post(new ShowTextInputTask(x, y, w, h)); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
663 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
664 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
665 public static boolean isTextInputEvent(KeyEvent event) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
666 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
667 // Key pressed with Ctrl should be sent as SDL_KEYDOWN/SDL_KEYUP and not SDL_TEXTINPUT |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
668 if (android.os.Build.VERSION.SDK_INT >= 11) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
669 if (event.isCtrlPressed()) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
670 return false; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
671 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
672 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
673 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
674 return event.isPrintingKey() || event.getKeyCode() == KeyEvent.KEYCODE_SPACE; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
675 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
676 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
677 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
678 * This method is called by SDL using JNI. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
679 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
680 public static Surface getNativeSurface() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
681 if (SDLActivity.mSurface == null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
682 return null; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
683 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
684 return SDLActivity.mSurface.getNativeSurface(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
685 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
686 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
687 // Input |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
688 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
689 /** |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
690 * This method is called by SDL using JNI. |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
691 * @return an array which may be empty but is never null. |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
692 */ |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
693 public static int[] inputGetInputDeviceIds(int sources) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
694 int[] ids = InputDevice.getDeviceIds(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
695 int[] filtered = new int[ids.length]; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
696 int used = 0; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
697 for (int i = 0; i < ids.length; ++i) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
698 InputDevice device = InputDevice.getDevice(ids[i]); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
699 if ((device != null) && ((device.getSources() & sources) != 0)) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
700 filtered[used++] = device.getId(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
701 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
702 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
703 return Arrays.copyOf(filtered, used); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
704 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
705 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
706 // APK expansion files support |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
707 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
708 /** com.android.vending.expansion.zipfile.ZipResourceFile object or null. */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
709 private static Object expansionFile; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
710 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
711 /** com.android.vending.expansion.zipfile.ZipResourceFile's getInputStream() or null. */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
712 private static Method expansionFileMethod; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
713 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
714 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
715 * This method is called by SDL using JNI. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
716 * @return an InputStream on success or null if no expansion file was used. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
717 * @throws IOException on errors. Message is set for the SDL error message. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
718 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
719 public static InputStream openAPKExpansionInputStream(String fileName) throws IOException { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
720 // Get a ZipResourceFile representing a merger of both the main and patch files |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
721 if (expansionFile == null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
722 String mainHint = nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
723 if (mainHint == null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
724 return null; // no expansion use if no main version was set |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
725 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
726 String patchHint = nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
727 if (patchHint == null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
728 return null; // no expansion use if no patch version was set |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
729 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
730 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
731 Integer mainVersion; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
732 Integer patchVersion; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
733 try { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
734 mainVersion = Integer.valueOf(mainHint); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
735 patchVersion = Integer.valueOf(patchHint); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
736 } catch (NumberFormatException ex) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
737 ex.printStackTrace(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
738 throw new IOException("No valid file versions set for APK expansion files", ex); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
739 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
740 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
741 try { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
742 // To avoid direct dependency on Google APK expansion library that is |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
743 // not a part of Android SDK we access it using reflection |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
744 expansionFile = Class.forName("com.android.vending.expansion.zipfile.APKExpansionSupport") |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
745 .getMethod("getAPKExpansionZipFile", Context.class, int.class, int.class) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
746 .invoke(null, SDL.getContext(), mainVersion, patchVersion); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
747 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
748 expansionFileMethod = expansionFile.getClass() |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
749 .getMethod("getInputStream", String.class); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
750 } catch (Exception ex) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
751 ex.printStackTrace(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
752 expansionFile = null; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
753 expansionFileMethod = null; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
754 throw new IOException("Could not access APK expansion support library", ex); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
755 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
756 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
757 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
758 // Get an input stream for a known file inside the expansion file ZIPs |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
759 InputStream fileStream; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
760 try { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
761 fileStream = (InputStream)expansionFileMethod.invoke(expansionFile, fileName); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
762 } catch (Exception ex) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
763 // calling "getInputStream" failed |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
764 ex.printStackTrace(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
765 throw new IOException("Could not open stream from APK expansion file", ex); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
766 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
767 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
768 if (fileStream == null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
769 // calling "getInputStream" was successful but null was returned |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
770 throw new IOException("Could not find path in APK expansion file"); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
771 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
772 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
773 return fileStream; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
774 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
775 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
776 // Messagebox |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
777 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
778 /** Result of current messagebox. Also used for blocking the calling thread. */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
779 protected final int[] messageboxSelection = new int[1]; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
780 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
781 /** Id of current dialog. */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
782 protected int dialogs = 0; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
783 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
784 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
785 * This method is called by SDL using JNI. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
786 * Shows the messagebox from UI thread and block calling thread. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
787 * buttonFlags, buttonIds and buttonTexts must have same length. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
788 * @param buttonFlags array containing flags for every button. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
789 * @param buttonIds array containing id for every button. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
790 * @param buttonTexts array containing text for every button. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
791 * @param colors null for default or array of length 5 containing colors. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
792 * @return button id or -1. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
793 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
794 public int messageboxShowMessageBox( |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
795 final int flags, |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
796 final String title, |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
797 final String message, |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
798 final int[] buttonFlags, |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
799 final int[] buttonIds, |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
800 final String[] buttonTexts, |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
801 final int[] colors) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
802 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
803 messageboxSelection[0] = -1; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
804 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
805 // sanity checks |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
806 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
807 if ((buttonFlags.length != buttonIds.length) && (buttonIds.length != buttonTexts.length)) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
808 return -1; // implementation broken |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
809 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
810 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
811 // collect arguments for Dialog |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
812 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
813 final Bundle args = new Bundle(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
814 args.putInt("flags", flags); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
815 args.putString("title", title); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
816 args.putString("message", message); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
817 args.putIntArray("buttonFlags", buttonFlags); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
818 args.putIntArray("buttonIds", buttonIds); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
819 args.putStringArray("buttonTexts", buttonTexts); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
820 args.putIntArray("colors", colors); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
821 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
822 // trigger Dialog creation on UI thread |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
823 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
824 runOnUiThread(new Runnable() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
825 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
826 public void run() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
827 showDialog(dialogs++, args); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
828 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
829 }); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
830 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
831 // block the calling thread |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
832 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
833 synchronized (messageboxSelection) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
834 try { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
835 messageboxSelection.wait(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
836 } catch (InterruptedException ex) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
837 ex.printStackTrace(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
838 return -1; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
839 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
840 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
841 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
842 // return selected value |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
843 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
844 return messageboxSelection[0]; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
845 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
846 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
847 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
848 protected Dialog onCreateDialog(int ignore, Bundle args) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
849 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
850 // TODO set values from "flags" to messagebox dialog |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
851 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
852 // get colors |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
853 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
854 int[] colors = args.getIntArray("colors"); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
855 int backgroundColor; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
856 int textColor; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
857 int buttonBorderColor; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
858 int buttonBackgroundColor; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
859 int buttonSelectedColor; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
860 if (colors != null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
861 int i = -1; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
862 backgroundColor = colors[++i]; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
863 textColor = colors[++i]; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
864 buttonBorderColor = colors[++i]; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
865 buttonBackgroundColor = colors[++i]; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
866 buttonSelectedColor = colors[++i]; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
867 } else { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
868 backgroundColor = Color.TRANSPARENT; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
869 textColor = Color.TRANSPARENT; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
870 buttonBorderColor = Color.TRANSPARENT; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
871 buttonBackgroundColor = Color.TRANSPARENT; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
872 buttonSelectedColor = Color.TRANSPARENT; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
873 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
874 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
875 // create dialog with title and a listener to wake up calling thread |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
876 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
877 final Dialog dialog = new Dialog(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
878 dialog.setTitle(args.getString("title")); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
879 dialog.setCancelable(false); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
880 dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
881 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
882 public void onDismiss(DialogInterface unused) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
883 synchronized (messageboxSelection) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
884 messageboxSelection.notify(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
885 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
886 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
887 }); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
888 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
889 // create text |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
890 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
891 TextView message = new TextView(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
892 message.setGravity(Gravity.CENTER); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
893 message.setText(args.getString("message")); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
894 if (textColor != Color.TRANSPARENT) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
895 message.setTextColor(textColor); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
896 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
897 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
898 // create buttons |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
899 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
900 int[] buttonFlags = args.getIntArray("buttonFlags"); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
901 int[] buttonIds = args.getIntArray("buttonIds"); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
902 String[] buttonTexts = args.getStringArray("buttonTexts"); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
903 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
904 final SparseArray<Button> mapping = new SparseArray<Button>(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
905 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
906 LinearLayout buttons = new LinearLayout(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
907 buttons.setOrientation(LinearLayout.HORIZONTAL); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
908 buttons.setGravity(Gravity.CENTER); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
909 for (int i = 0; i < buttonTexts.length; ++i) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
910 Button button = new Button(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
911 final int id = buttonIds[i]; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
912 button.setOnClickListener(new View.OnClickListener() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
913 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
914 public void onClick(View v) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
915 messageboxSelection[0] = id; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
916 dialog.dismiss(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
917 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
918 }); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
919 if (buttonFlags[i] != 0) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
920 // see SDL_messagebox.h |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
921 if ((buttonFlags[i] & 0x00000001) != 0) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
922 mapping.put(KeyEvent.KEYCODE_ENTER, button); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
923 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
924 if ((buttonFlags[i] & 0x00000002) != 0) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
925 mapping.put(KeyEvent.KEYCODE_ESCAPE, button); /* API 11 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
926 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
927 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
928 button.setText(buttonTexts[i]); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
929 if (textColor != Color.TRANSPARENT) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
930 button.setTextColor(textColor); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
931 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
932 if (buttonBorderColor != Color.TRANSPARENT) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
933 // TODO set color for border of messagebox button |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
934 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
935 if (buttonBackgroundColor != Color.TRANSPARENT) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
936 Drawable drawable = button.getBackground(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
937 if (drawable == null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
938 // setting the color this way removes the style |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
939 button.setBackgroundColor(buttonBackgroundColor); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
940 } else { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
941 // setting the color this way keeps the style (gradient, padding, etc.) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
942 drawable.setColorFilter(buttonBackgroundColor, PorterDuff.Mode.MULTIPLY); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
943 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
944 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
945 if (buttonSelectedColor != Color.TRANSPARENT) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
946 // TODO set color for selected messagebox button |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
947 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
948 buttons.addView(button); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
949 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
950 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
951 // create content |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
952 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
953 LinearLayout content = new LinearLayout(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
954 content.setOrientation(LinearLayout.VERTICAL); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
955 content.addView(message); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
956 content.addView(buttons); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
957 if (backgroundColor != Color.TRANSPARENT) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
958 content.setBackgroundColor(backgroundColor); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
959 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
960 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
961 // add content to dialog and return |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
962 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
963 dialog.setContentView(content); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
964 dialog.setOnKeyListener(new Dialog.OnKeyListener() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
965 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
966 public boolean onKey(DialogInterface d, int keyCode, KeyEvent event) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
967 Button button = mapping.get(keyCode); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
968 if (button != null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
969 if (event.getAction() == KeyEvent.ACTION_UP) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
970 button.performClick(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
971 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
972 return true; // also for ignored actions |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
973 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
974 return false; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
975 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
976 }); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
977 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
978 return dialog; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
979 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
980 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
981 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
982 * This method is called by SDL using JNI. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
983 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
984 public static boolean clipboardHasText() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
985 return mClipboardHandler.clipboardHasText(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
986 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
987 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
988 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
989 * This method is called by SDL using JNI. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
990 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
991 public static String clipboardGetText() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
992 return mClipboardHandler.clipboardGetText(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
993 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
994 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
995 /** |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
996 * This method is called by SDL using JNI. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
997 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
998 public static void clipboardSetText(String string) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
999 mClipboardHandler.clipboardSetText(string); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1000 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1001 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1002 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1003 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1004 /** |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1005 Simple runnable to start the SDL application |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1006 */ |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1007 class SDLMain implements Runnable { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1008 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1009 public void run() { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1010 // Runs SDL_main() |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1011 String library = SDLActivity.mSingleton.getMainSharedObject(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1012 String function = SDLActivity.mSingleton.getMainFunction(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1013 String[] arguments = SDLActivity.mSingleton.getArguments(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1014 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1015 Log.v("SDL", "Running main function " + function + " from library " + library); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1016 SDLActivity.nativeRunMain(library, function, arguments); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1017 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1018 Log.v("SDL", "Finished main function"); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1019 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1020 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1021 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1022 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1023 /** |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1024 SDLSurface. This is what we draw on, so we need to know when it's created |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1025 in order to do anything useful. |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1026 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1027 Because of this, that's where we set up the SDL thread |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1028 */ |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1029 class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1030 View.OnKeyListener, View.OnTouchListener, SensorEventListener { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1031 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1032 // Sensors |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1033 protected static SensorManager mSensorManager; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1034 protected static Display mDisplay; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1035 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1036 // Keep track of the surface size to normalize touch events |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1037 protected static float mWidth, mHeight; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1038 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1039 // Startup |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1040 public SDLSurface(Context context) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1041 super(context); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1042 getHolder().addCallback(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1043 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1044 setFocusable(true); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1045 setFocusableInTouchMode(true); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1046 requestFocus(); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1047 setOnKeyListener(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1048 setOnTouchListener(this); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1049 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1050 mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1051 mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1052 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1053 if (Build.VERSION.SDK_INT >= 12) { |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1054 setOnGenericMotionListener(new SDLGenericMotionListener_API12()); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1055 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1056 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1057 // Some arbitrary defaults to avoid a potential division by zero |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1058 mWidth = 1.0f; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1059 mHeight = 1.0f; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1060 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1061 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1062 public void handlePause() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1063 enableSensor(Sensor.TYPE_ACCELEROMETER, false); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1064 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1065 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1066 public void handleResume() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1067 setFocusable(true); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1068 setFocusableInTouchMode(true); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1069 requestFocus(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1070 setOnKeyListener(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1071 setOnTouchListener(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1072 enableSensor(Sensor.TYPE_ACCELEROMETER, true); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1073 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1074 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1075 public Surface getNativeSurface() { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1076 return getHolder().getSurface(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1077 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1078 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1079 // Called when we have a valid drawing surface |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1080 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1081 public void surfaceCreated(SurfaceHolder holder) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1082 Log.v("SDL", "surfaceCreated()"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1083 holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1084 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1085 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1086 // Called when we lose the surface |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1087 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1088 public void surfaceDestroyed(SurfaceHolder holder) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1089 Log.v("SDL", "surfaceDestroyed()"); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1090 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1091 // Transition to pause, if needed |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1092 SDLActivity.mNextNativeState = SDLActivity.NativeState.PAUSED; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1093 SDLActivity.handleNativeState(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1094 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1095 SDLActivity.mIsSurfaceReady = false; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1096 SDLActivity.onNativeSurfaceDestroyed(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1097 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1098 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1099 // Called when the surface is resized |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1100 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1101 public void surfaceChanged(SurfaceHolder holder, |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1102 int format, int width, int height) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1103 Log.v("SDL", "surfaceChanged()"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1104 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1105 int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1106 switch (format) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1107 case PixelFormat.A_8: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1108 Log.v("SDL", "pixel format A_8"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1109 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1110 case PixelFormat.LA_88: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1111 Log.v("SDL", "pixel format LA_88"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1112 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1113 case PixelFormat.L_8: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1114 Log.v("SDL", "pixel format L_8"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1115 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1116 case PixelFormat.RGBA_4444: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1117 Log.v("SDL", "pixel format RGBA_4444"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1118 sdlFormat = 0x15421002; // SDL_PIXELFORMAT_RGBA4444 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1119 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1120 case PixelFormat.RGBA_5551: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1121 Log.v("SDL", "pixel format RGBA_5551"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1122 sdlFormat = 0x15441002; // SDL_PIXELFORMAT_RGBA5551 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1123 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1124 case PixelFormat.RGBA_8888: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1125 Log.v("SDL", "pixel format RGBA_8888"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1126 sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1127 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1128 case PixelFormat.RGBX_8888: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1129 Log.v("SDL", "pixel format RGBX_8888"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1130 sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1131 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1132 case PixelFormat.RGB_332: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1133 Log.v("SDL", "pixel format RGB_332"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1134 sdlFormat = 0x14110801; // SDL_PIXELFORMAT_RGB332 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1135 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1136 case PixelFormat.RGB_565: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1137 Log.v("SDL", "pixel format RGB_565"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1138 sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1139 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1140 case PixelFormat.RGB_888: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1141 Log.v("SDL", "pixel format RGB_888"); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1142 // Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead? |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1143 sdlFormat = 0x16161804; // SDL_PIXELFORMAT_RGB888 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1144 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1145 default: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1146 Log.v("SDL", "pixel format unknown " + format); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1147 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1148 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1149 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1150 mWidth = width; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1151 mHeight = height; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1152 SDLActivity.onNativeResize(width, height, sdlFormat, mDisplay.getRefreshRate()); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1153 Log.v("SDL", "Window size: " + width + "x" + height); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1154 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1155 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1156 boolean skip = false; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1157 int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1158 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1159 if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1160 { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1161 // Accept any |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1162 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1163 else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1164 { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1165 if (mWidth > mHeight) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1166 skip = true; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1167 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1168 } else if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1169 if (mWidth < mHeight) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1170 skip = true; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1171 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1172 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1173 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1174 // Special Patch for Square Resolution: Black Berry Passport |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1175 if (skip) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1176 double min = Math.min(mWidth, mHeight); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1177 double max = Math.max(mWidth, mHeight); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1178 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1179 if (max / min < 1.20) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1180 Log.v("SDL", "Don't skip on such aspect-ratio. Could be a square resolution."); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1181 skip = false; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1182 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1183 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1184 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1185 if (skip) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1186 Log.v("SDL", "Skip .. Surface is not ready."); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1187 SDLActivity.mIsSurfaceReady = false; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1188 return; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1189 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1190 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1191 /* Surface is ready */ |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1192 SDLActivity.mIsSurfaceReady = true; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1193 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1194 /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */ |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1195 SDLActivity.onNativeSurfaceChanged(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1196 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1197 SDLActivity.handleNativeState(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1198 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1199 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1200 // Key events |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1201 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1202 public boolean onKey(View v, int keyCode, KeyEvent event) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1203 // Dispatch the different events depending on where they come from |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1204 // Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1205 // So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1206 // |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1207 // Furthermore, it's possible a game controller has SOURCE_KEYBOARD and |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1208 // SOURCE_JOYSTICK, while its key events arrive from the keyboard source |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1209 // So, retrieve the device itself and check all of its sources |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1210 if (SDLControllerManager.isDeviceSDLJoystick(event.getDeviceId())) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1211 // Note that we process events with specific key codes here |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1212 if (event.getAction() == KeyEvent.ACTION_DOWN) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1213 if (SDLControllerManager.onNativePadDown(event.getDeviceId(), keyCode) == 0) { |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1214 return true; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1215 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1216 } else if (event.getAction() == KeyEvent.ACTION_UP) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1217 if (SDLControllerManager.onNativePadUp(event.getDeviceId(), keyCode) == 0) { |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1218 return true; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1219 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1220 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1221 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1222 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1223 if ((event.getSource() & InputDevice.SOURCE_KEYBOARD) != 0) { |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1224 if (event.getAction() == KeyEvent.ACTION_DOWN) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1225 //Log.v("SDL", "key down: " + keyCode); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1226 SDLActivity.onNativeKeyDown(keyCode); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1227 return true; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1228 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1229 else if (event.getAction() == KeyEvent.ACTION_UP) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1230 //Log.v("SDL", "key up: " + keyCode); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1231 SDLActivity.onNativeKeyUp(keyCode); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1232 return true; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1233 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1234 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1235 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1236 if ((event.getSource() & InputDevice.SOURCE_MOUSE) != 0) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1237 // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1238 // they are ignored here because sending them as mouse input to SDL is messy |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1239 if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1240 switch (event.getAction()) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1241 case KeyEvent.ACTION_DOWN: |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1242 case KeyEvent.ACTION_UP: |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1243 // mark the event as handled or it will be handled by system |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1244 // handling KEYCODE_BACK by system will call onBackPressed() |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1245 return true; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1246 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1247 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1248 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1249 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1250 return false; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1251 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1252 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1253 // Touch events |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1254 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1255 public boolean onTouch(View v, MotionEvent event) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1256 /* Ref: http://developer.android.com/training/gestures/multi.html */ |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1257 final int touchDevId = event.getDeviceId(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1258 final int pointerCount = event.getPointerCount(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1259 int action = event.getActionMasked(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1260 int pointerFingerId; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1261 int mouseButton; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1262 int i = -1; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1263 float x,y,p; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1264 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1265 // !!! FIXME: dump this SDK check after 2.0.4 ships and require API14. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1266 if (event.getSource() == InputDevice.SOURCE_MOUSE && SDLActivity.mSeparateMouseAndTouch) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1267 if (Build.VERSION.SDK_INT < 14) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1268 mouseButton = 1; // all mouse buttons are the left button |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1269 } else { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1270 try { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1271 mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1272 } catch(Exception e) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1273 mouseButton = 1; // oh well. |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1274 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1275 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1276 SDLActivity.onNativeMouse(mouseButton, action, event.getX(0), event.getY(0)); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1277 } else { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1278 switch(action) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1279 case MotionEvent.ACTION_MOVE: |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1280 for (i = 0; i < pointerCount; i++) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1281 pointerFingerId = event.getPointerId(i); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1282 x = event.getX(i) / mWidth; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1283 y = event.getY(i) / mHeight; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1284 p = event.getPressure(i); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1285 if (p > 1.0f) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1286 // may be larger than 1.0f on some devices |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1287 // see the documentation of getPressure(i) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1288 p = 1.0f; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1289 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1290 SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1291 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1292 break; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1293 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1294 case MotionEvent.ACTION_UP: |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1295 case MotionEvent.ACTION_DOWN: |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1296 // Primary pointer up/down, the index is always zero |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1297 i = 0; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1298 case MotionEvent.ACTION_POINTER_UP: |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1299 case MotionEvent.ACTION_POINTER_DOWN: |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1300 // Non primary pointer up/down |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1301 if (i == -1) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1302 i = event.getActionIndex(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1303 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1304 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1305 pointerFingerId = event.getPointerId(i); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1306 x = event.getX(i) / mWidth; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1307 y = event.getY(i) / mHeight; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1308 p = event.getPressure(i); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1309 if (p > 1.0f) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1310 // may be larger than 1.0f on some devices |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1311 // see the documentation of getPressure(i) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1312 p = 1.0f; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1313 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1314 SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1315 break; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1316 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1317 case MotionEvent.ACTION_CANCEL: |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1318 for (i = 0; i < pointerCount; i++) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1319 pointerFingerId = event.getPointerId(i); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1320 x = event.getX(i) / mWidth; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1321 y = event.getY(i) / mHeight; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1322 p = event.getPressure(i); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1323 if (p > 1.0f) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1324 // may be larger than 1.0f on some devices |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1325 // see the documentation of getPressure(i) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1326 p = 1.0f; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1327 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1328 SDLActivity.onNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1329 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1330 break; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1331 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1332 default: |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1333 break; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1334 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1335 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1336 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1337 return true; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1338 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1339 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1340 // Sensor events |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1341 public void enableSensor(int sensortype, boolean enabled) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1342 // TODO: This uses getDefaultSensor - what if we have >1 accels? |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1343 if (enabled) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1344 mSensorManager.registerListener(this, |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1345 mSensorManager.getDefaultSensor(sensortype), |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1346 SensorManager.SENSOR_DELAY_GAME, null); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1347 } else { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1348 mSensorManager.unregisterListener(this, |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1349 mSensorManager.getDefaultSensor(sensortype)); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1350 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1351 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1352 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1353 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1354 public void onAccuracyChanged(Sensor sensor, int accuracy) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1355 // TODO |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1356 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1357 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1358 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1359 public void onSensorChanged(SensorEvent event) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1360 if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1361 float x, y; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1362 switch (mDisplay.getRotation()) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1363 case Surface.ROTATION_90: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1364 x = -event.values[1]; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1365 y = event.values[0]; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1366 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1367 case Surface.ROTATION_270: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1368 x = event.values[1]; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1369 y = -event.values[0]; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1370 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1371 case Surface.ROTATION_180: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1372 x = -event.values[1]; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1373 y = -event.values[0]; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1374 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1375 default: |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1376 x = event.values[0]; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1377 y = event.values[1]; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1378 break; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1379 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1380 SDLActivity.onNativeAccel(-x / SensorManager.GRAVITY_EARTH, |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1381 y / SensorManager.GRAVITY_EARTH, |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1382 event.values[2] / SensorManager.GRAVITY_EARTH); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1383 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1384 } |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1385 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1386 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1387 /* This is a fake invisible editor view that receives the input and defines the |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1388 * pan&scan region |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1389 */ |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1390 class DummyEdit extends View implements View.OnKeyListener { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1391 InputConnection ic; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1392 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1393 public DummyEdit(Context context) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1394 super(context); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1395 setFocusableInTouchMode(true); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1396 setFocusable(true); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1397 setOnKeyListener(this); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1398 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1399 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1400 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1401 public boolean onCheckIsTextEditor() { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1402 return true; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1403 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1404 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1405 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1406 public boolean onKey(View v, int keyCode, KeyEvent event) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1407 /* |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1408 * This handles the hardware keyboard input |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1409 */ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1410 if (event.getAction() == KeyEvent.ACTION_DOWN) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1411 if (SDLActivity.isTextInputEvent(event)) { |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1412 ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1413 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1414 SDLActivity.onNativeKeyDown(keyCode); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1415 return true; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1416 } else if (event.getAction() == KeyEvent.ACTION_UP) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1417 SDLActivity.onNativeKeyUp(keyCode); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1418 return true; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1419 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1420 return false; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1421 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1422 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1423 // |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1424 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1425 public boolean onKeyPreIme (int keyCode, KeyEvent event) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1426 // As seen on StackOverflow: http://stackoverflow.com/questions/7634346/keyboard-hide-event |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1427 // FIXME: Discussion at http://bugzilla.libsdl.org/show_bug.cgi?id=1639 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1428 // FIXME: This is not a 100% effective solution to the problem of detecting if the keyboard is showing or not |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1429 // FIXME: A more effective solution would be to assume our Layout to be RelativeLayout or LinearLayout |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1430 // FIXME: And determine the keyboard presence doing this: http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1431 // FIXME: An even more effective way would be if Android provided this out of the box, but where would the fun be in that :) |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1432 if (event.getAction()==KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1433 if (SDLActivity.mTextEdit != null && SDLActivity.mTextEdit.getVisibility() == View.VISIBLE) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1434 SDLActivity.onNativeKeyboardFocusLost(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1435 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1436 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1437 return super.onKeyPreIme(keyCode, event); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1438 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1439 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1440 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1441 public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1442 ic = new SDLInputConnection(this, true); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1443 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1444 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1445 outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1446 | EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1447 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1448 return ic; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1449 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1450 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1451 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1452 class SDLInputConnection extends BaseInputConnection { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1453 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1454 public SDLInputConnection(View targetView, boolean fullEditor) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1455 super(targetView, fullEditor); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1456 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1457 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1458 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1459 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1460 public boolean sendKeyEvent(KeyEvent event) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1461 /* |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1462 * This handles the keycodes from soft keyboard (and IME-translated input from hardkeyboard) |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1463 */ |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1464 int keyCode = event.getKeyCode(); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1465 if (event.getAction() == KeyEvent.ACTION_DOWN) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1466 if (SDLActivity.isTextInputEvent(event)) { |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1467 commitText(String.valueOf((char) event.getUnicodeChar()), 1); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1468 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1469 SDLActivity.onNativeKeyDown(keyCode); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1470 return true; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1471 } else if (event.getAction() == KeyEvent.ACTION_UP) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1472 SDLActivity.onNativeKeyUp(keyCode); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1473 return true; |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1474 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1475 return super.sendKeyEvent(event); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1476 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1477 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1478 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1479 public boolean commitText(CharSequence text, int newCursorPosition) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1480 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1481 nativeCommitText(text.toString(), newCursorPosition); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1482 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1483 return super.commitText(text, newCursorPosition); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1484 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1485 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1486 @Override |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1487 public boolean setComposingText(CharSequence text, int newCursorPosition) { |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1488 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1489 nativeSetComposingText(text.toString(), newCursorPosition); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1490 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1491 return super.setComposingText(text, newCursorPosition); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1492 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1493 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1494 public native void nativeCommitText(String text, int newCursorPosition); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1495 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1496 public native void nativeSetComposingText(String text, int newCursorPosition); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1497 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1498 @Override |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1499 public boolean deleteSurroundingText(int beforeLength, int afterLength) { |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1500 // Workaround to capture backspace key. Ref: http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1501 // and https://bugzilla.libsdl.org/show_bug.cgi?id=2265 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1502 if (beforeLength > 0 && afterLength == 0) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1503 boolean ret = true; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1504 // backspace(s) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1505 while (beforeLength-- > 0) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1506 boolean ret_key = sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)) |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1507 && sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL)); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1508 ret = ret && ret_key; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1509 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1510 return ret; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1511 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1512 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1513 return super.deleteSurroundingText(beforeLength, afterLength); |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1514 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1515 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1516 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1517 interface SDLClipboardHandler { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1518 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1519 public boolean clipboardHasText(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1520 public String clipboardGetText(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1521 public void clipboardSetText(String string); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1522 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1523 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1524 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1525 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1526 class SDLClipboardHandler_API11 implements |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1527 SDLClipboardHandler, |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1528 android.content.ClipboardManager.OnPrimaryClipChangedListener { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1529 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1530 protected android.content.ClipboardManager mClipMgr; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1531 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1532 SDLClipboardHandler_API11() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1533 mClipMgr = (android.content.ClipboardManager) SDL.getContext().getSystemService(Context.CLIPBOARD_SERVICE); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1534 mClipMgr.addPrimaryClipChangedListener(this); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1535 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1536 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1537 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1538 public boolean clipboardHasText() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1539 return mClipMgr.hasText(); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1540 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1541 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1542 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1543 public String clipboardGetText() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1544 CharSequence text; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1545 text = mClipMgr.getText(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1546 if (text != null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1547 return text.toString(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1548 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1549 return null; |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1550 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1551 |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1552 @Override |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1553 public void clipboardSetText(String string) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1554 mClipMgr.removePrimaryClipChangedListener(this); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1555 mClipMgr.setText(string); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1556 mClipMgr.addPrimaryClipChangedListener(this); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1557 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1558 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1559 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1560 public void onPrimaryClipChanged() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1561 SDLActivity.onNativeClipboardChanged(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1562 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1563 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1564 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1565 |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1566 class SDLClipboardHandler_Old implements |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1567 SDLClipboardHandler { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1568 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1569 protected android.text.ClipboardManager mClipMgrOld; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1570 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1571 SDLClipboardHandler_Old() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1572 mClipMgrOld = (android.text.ClipboardManager) SDL.getContext().getSystemService(Context.CLIPBOARD_SERVICE); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1573 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1574 |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1575 @Override |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1576 public boolean clipboardHasText() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1577 return mClipMgrOld.hasText(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1578 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1579 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1580 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1581 public String clipboardGetText() { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1582 CharSequence text; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1583 text = mClipMgrOld.getText(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1584 if (text != null) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1585 return text.toString(); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1586 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1587 return null; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1588 } |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1589 |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1590 @Override |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1591 public void clipboardSetText(String string) { |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1592 mClipMgrOld.setText(string); |
856
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1593 } |
09f5a349e881
Added android project layout
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1594 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1595 |