diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2010-10-31 10:35:55 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2010-10-31 10:35:55 +0000 |
commit | eaff333bf526225cfca84cd686fe5332b852e506 (patch) | |
tree | 98fda966dfe1091295928cfa0f660e4ce9bc7f6b /android/src/org | |
parent | 26f7ee13ce024b21c83cf68ca7fd27306a0bf5be (diff) | |
download | rockbox-eaff333bf526225cfca84cd686fe5332b852e506.tar.gz rockbox-eaff333bf526225cfca84cd686fe5332b852e506.zip |
Use a Native keyboard GUI instead of rockbox's internal one on android
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28407 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'android/src/org')
-rw-r--r-- | android/src/org/rockbox/HostCallback.java | 7 | ||||
-rw-r--r-- | android/src/org/rockbox/KeyboardActivity.java | 41 | ||||
-rw-r--r-- | android/src/org/rockbox/RockboxActivity.java | 33 | ||||
-rw-r--r-- | android/src/org/rockbox/RockboxFramebuffer.java | 3 | ||||
-rw-r--r-- | android/src/org/rockbox/RockboxKeyboardInput.java | 69 | ||||
-rw-r--r-- | android/src/org/rockbox/RockboxService.java | 12 |
6 files changed, 162 insertions, 3 deletions
diff --git a/android/src/org/rockbox/HostCallback.java b/android/src/org/rockbox/HostCallback.java new file mode 100644 index 0000000000..0e69b3f283 --- /dev/null +++ b/android/src/org/rockbox/HostCallback.java | |||
@@ -0,0 +1,7 @@ | |||
1 | package org.rockbox; | ||
2 | |||
3 | import android.content.Intent; | ||
4 | |||
5 | public interface HostCallback { | ||
6 | public void onComplete(int resultCode, Intent data); | ||
7 | } | ||
diff --git a/android/src/org/rockbox/KeyboardActivity.java b/android/src/org/rockbox/KeyboardActivity.java new file mode 100644 index 0000000000..f32aae28f8 --- /dev/null +++ b/android/src/org/rockbox/KeyboardActivity.java | |||
@@ -0,0 +1,41 @@ | |||
1 | package org.rockbox; | ||
2 | |||
3 | import android.app.Activity; | ||
4 | import android.app.AlertDialog; | ||
5 | import android.app.Dialog; | ||
6 | import android.content.DialogInterface; | ||
7 | import android.os.Bundle; | ||
8 | import android.text.Editable; | ||
9 | import android.view.LayoutInflater; | ||
10 | import android.view.View; | ||
11 | import android.widget.EditText; | ||
12 | |||
13 | public class KeyboardActivity extends Activity { | ||
14 | public void onCreate(Bundle savedInstanceState) { | ||
15 | super.onCreate(savedInstanceState); | ||
16 | LayoutInflater inflater=LayoutInflater.from(this); | ||
17 | View addView=inflater.inflate(R.layout.keyboardinput, null); | ||
18 | EditText input = (EditText) addView.findViewById(R.id.KbdInput); | ||
19 | input.setText(getIntent().getStringExtra("value")); | ||
20 | new AlertDialog.Builder(this) | ||
21 | .setTitle(R.string.KbdInputTitle) | ||
22 | .setView(addView) | ||
23 | .setIcon(R.drawable.icon) | ||
24 | .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() { | ||
25 | public void onClick(DialogInterface dialog, int whichButton) { | ||
26 | EditText input = (EditText)((Dialog)dialog).findViewById(R.id.KbdInput); | ||
27 | Editable s = input.getText(); | ||
28 | getIntent().putExtra("value", s.toString()); | ||
29 | setResult(RESULT_OK, getIntent()); | ||
30 | finish(); | ||
31 | } | ||
32 | }) | ||
33 | .setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() { | ||
34 | public void onClick(DialogInterface dialog, int whichButton) { | ||
35 | setResult(RESULT_CANCELED, getIntent()); | ||
36 | finish(); | ||
37 | } | ||
38 | }) | ||
39 | .show(); | ||
40 | } | ||
41 | } | ||
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java index f775597d30..9eed3f48dc 100644 --- a/android/src/org/rockbox/RockboxActivity.java +++ b/android/src/org/rockbox/RockboxActivity.java | |||
@@ -24,7 +24,9 @@ package org.rockbox; | |||
24 | import android.app.Activity; | 24 | import android.app.Activity; |
25 | import android.app.ProgressDialog; | 25 | import android.app.ProgressDialog; |
26 | import android.content.Intent; | 26 | import android.content.Intent; |
27 | import android.content.IntentFilter; | ||
27 | import android.os.Bundle; | 28 | import android.os.Bundle; |
29 | import android.util.Log; | ||
28 | import android.view.ViewGroup; | 30 | import android.view.ViewGroup; |
29 | import android.view.Window; | 31 | import android.view.Window; |
30 | import android.view.WindowManager; | 32 | import android.view.WindowManager; |
@@ -41,6 +43,7 @@ public class RockboxActivity extends Activity | |||
41 | requestWindowFeature(Window.FEATURE_NO_TITLE); | 43 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
42 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | 44 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
43 | ,WindowManager.LayoutParams.FLAG_FULLSCREEN); | 45 | ,WindowManager.LayoutParams.FLAG_FULLSCREEN); |
46 | final Activity thisActivity = this; | ||
44 | final Intent intent = new Intent(this, RockboxService.class); | 47 | final Intent intent = new Intent(this, RockboxService.class); |
45 | /* prepare a please wait dialog in case we need | 48 | /* prepare a please wait dialog in case we need |
46 | * to wait for unzipping libmisc.so | 49 | * to wait for unzipping libmisc.so |
@@ -95,7 +98,8 @@ public class RockboxActivity extends Activity | |||
95 | loadingdialog.dismiss(); | 98 | loadingdialog.dismiss(); |
96 | if (rbservice.get_fb() == null) | 99 | if (rbservice.get_fb() == null) |
97 | throw new IllegalStateException("FB NULL"); | 100 | throw new IllegalStateException("FB NULL"); |
98 | setContentView(rbservice.get_fb()); | 101 | rbservice.set_activity(thisActivity); |
102 | setContentView(rbservice.get_fb()); | ||
99 | rbservice.get_fb().invalidate(); | 103 | rbservice.get_fb().invalidate(); |
100 | } | 104 | } |
101 | }); | 105 | }); |
@@ -111,6 +115,7 @@ public class RockboxActivity extends Activity | |||
111 | 115 | ||
112 | public void onResume() | 116 | public void onResume() |
113 | { | 117 | { |
118 | |||
114 | super.onResume(); | 119 | super.onResume(); |
115 | if (isRockboxRunning()) | 120 | if (isRockboxRunning()) |
116 | { | 121 | { |
@@ -123,6 +128,7 @@ public class RockboxActivity extends Activity | |||
123 | g.removeView(rbservice.get_fb()); | 128 | g.removeView(rbservice.get_fb()); |
124 | setContentView(rbservice.get_fb()); | 129 | setContentView(rbservice.get_fb()); |
125 | } finally { | 130 | } finally { |
131 | rbservice.set_activity(this); | ||
126 | rbservice.get_fb().resume(); | 132 | rbservice.get_fb().resume(); |
127 | } | 133 | } |
128 | } | 134 | } |
@@ -135,6 +141,7 @@ public class RockboxActivity extends Activity | |||
135 | protected void onPause() | 141 | protected void onPause() |
136 | { | 142 | { |
137 | super.onPause(); | 143 | super.onPause(); |
144 | rbservice.set_activity(null); | ||
138 | rbservice.get_fb().suspend(); | 145 | rbservice.get_fb().suspend(); |
139 | } | 146 | } |
140 | 147 | ||
@@ -142,6 +149,7 @@ public class RockboxActivity extends Activity | |||
142 | protected void onStop() | 149 | protected void onStop() |
143 | { | 150 | { |
144 | super.onStop(); | 151 | super.onStop(); |
152 | rbservice.set_activity(null); | ||
145 | rbservice.get_fb().suspend(); | 153 | rbservice.get_fb().suspend(); |
146 | } | 154 | } |
147 | 155 | ||
@@ -149,6 +157,29 @@ public class RockboxActivity extends Activity | |||
149 | protected void onDestroy() | 157 | protected void onDestroy() |
150 | { | 158 | { |
151 | super.onDestroy(); | 159 | super.onDestroy(); |
160 | rbservice.set_activity(null); | ||
152 | rbservice.get_fb().suspend(); | 161 | rbservice.get_fb().suspend(); |
153 | } | 162 | } |
163 | |||
164 | private HostCallback hostcallback = null; | ||
165 | public void waitForActivity(Intent i, HostCallback callback) | ||
166 | { | ||
167 | if (hostcallback != null) | ||
168 | { | ||
169 | LOG("Something has gone wrong"); | ||
170 | } | ||
171 | hostcallback = callback; | ||
172 | startActivityForResult(i, 0); | ||
173 | } | ||
174 | |||
175 | public void onActivityResult(int requestCode, int resultCode, Intent data) | ||
176 | { | ||
177 | hostcallback.onComplete(resultCode, data); | ||
178 | hostcallback = null; | ||
179 | } | ||
180 | |||
181 | private void LOG(CharSequence text) | ||
182 | { | ||
183 | Log.d("Rockbox", (String) text); | ||
184 | } | ||
154 | } | 185 | } |
diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java index e90eb86dbd..20311a8790 100644 --- a/android/src/org/rockbox/RockboxFramebuffer.java +++ b/android/src/org/rockbox/RockboxFramebuffer.java | |||
@@ -118,12 +118,11 @@ public class RockboxFramebuffer extends View | |||
118 | setFocusableInTouchMode(true); | 118 | setFocusableInTouchMode(true); |
119 | setClickable(true); | 119 | setClickable(true); |
120 | requestFocus(); | 120 | requestFocus(); |
121 | /* make updates again, the underlying function will | ||
122 | * send an event */ | ||
123 | set_lcd_active(1); | 121 | set_lcd_active(1); |
124 | } | 122 | } |
125 | 123 | ||
126 | public native void set_lcd_active(int active); | 124 | public native void set_lcd_active(int active); |
127 | public native void touchHandler(boolean down, int x, int y); | 125 | public native void touchHandler(boolean down, int x, int y); |
128 | public native boolean buttonHandler(int keycode, boolean state); | 126 | public native boolean buttonHandler(int keycode, boolean state); |
127 | |||
129 | } | 128 | } |
diff --git a/android/src/org/rockbox/RockboxKeyboardInput.java b/android/src/org/rockbox/RockboxKeyboardInput.java new file mode 100644 index 0000000000..b037f6c4bb --- /dev/null +++ b/android/src/org/rockbox/RockboxKeyboardInput.java | |||
@@ -0,0 +1,69 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Jonathan Gordon | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | package org.rockbox; | ||
23 | |||
24 | import android.app.Activity; | ||
25 | import android.content.BroadcastReceiver; | ||
26 | import android.content.Intent; | ||
27 | import android.util.Log; | ||
28 | |||
29 | public class RockboxKeyboardInput | ||
30 | { | ||
31 | private BroadcastReceiver b; | ||
32 | private String result; | ||
33 | |||
34 | public RockboxKeyboardInput() | ||
35 | { | ||
36 | result = null; | ||
37 | } | ||
38 | |||
39 | public void kbd_input(String text) | ||
40 | { | ||
41 | RockboxActivity a = (RockboxActivity) RockboxService.get_instance().get_activity(); | ||
42 | Intent kbd = new Intent(a, KeyboardActivity.class); | ||
43 | kbd.putExtra("value", text); | ||
44 | a.waitForActivity(kbd, new HostCallback(){ | ||
45 | |||
46 | @Override | ||
47 | public void onComplete(int resultCode, Intent data) { | ||
48 | if (resultCode == Activity.RESULT_OK) | ||
49 | { | ||
50 | result = data.getStringExtra("value"); | ||
51 | } | ||
52 | else { | ||
53 | result = ""; | ||
54 | } | ||
55 | } | ||
56 | }); | ||
57 | } | ||
58 | public String get_result() | ||
59 | { | ||
60 | return result; | ||
61 | } | ||
62 | |||
63 | public boolean is_usable() | ||
64 | { | ||
65 | return RockboxService.get_instance().get_activity() != null; | ||
66 | } | ||
67 | |||
68 | |||
69 | } | ||
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java index c403736c72..bbcdfec4a7 100644 --- a/android/src/org/rockbox/RockboxService.java +++ b/android/src/org/rockbox/RockboxService.java | |||
@@ -35,6 +35,7 @@ import java.util.TimerTask; | |||
35 | import java.util.zip.ZipEntry; | 35 | import java.util.zip.ZipEntry; |
36 | import java.util.zip.ZipFile; | 36 | import java.util.zip.ZipFile; |
37 | 37 | ||
38 | import android.app.Activity; | ||
38 | import android.app.Notification; | 39 | import android.app.Notification; |
39 | import android.app.NotificationManager; | 40 | import android.app.NotificationManager; |
40 | import android.app.PendingIntent; | 41 | import android.app.PendingIntent; |
@@ -61,6 +62,7 @@ public class RockboxService extends Service | |||
61 | /* locals needed for the c code and rockbox state */ | 62 | /* locals needed for the c code and rockbox state */ |
62 | private RockboxFramebuffer fb = null; | 63 | private RockboxFramebuffer fb = null; |
63 | private boolean mRockboxRunning = false; | 64 | private boolean mRockboxRunning = false; |
65 | private Activity current_activity = null; | ||
64 | 66 | ||
65 | private Notification notification; | 67 | private Notification notification; |
66 | private static final Class<?>[] mStartForegroundSignature = | 68 | private static final Class<?>[] mStartForegroundSignature = |
@@ -113,6 +115,16 @@ public class RockboxService extends Service | |||
113 | fb = newfb; | 115 | fb = newfb; |
114 | mRockboxRunning = true; | 116 | mRockboxRunning = true; |
115 | } | 117 | } |
118 | |||
119 | public Activity get_activity() | ||
120 | { | ||
121 | return current_activity; | ||
122 | } | ||
123 | public void set_activity(Activity a) | ||
124 | { | ||
125 | current_activity = a; | ||
126 | } | ||
127 | |||
116 | 128 | ||
117 | private void do_start(Intent intent) | 129 | private void do_start(Intent intent) |
118 | { | 130 | { |