summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/src/org/rockbox/RockboxActivity.java43
-rw-r--r--android/src/org/rockbox/RockboxFramebuffer.java41
2 files changed, 41 insertions, 43 deletions
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java
index d8c1307ff3..2e13a034c7 100644
--- a/android/src/org/rockbox/RockboxActivity.java
+++ b/android/src/org/rockbox/RockboxActivity.java
@@ -27,6 +27,7 @@ import android.app.ProgressDialog;
27import android.content.Intent; 27import android.content.Intent;
28import android.os.Bundle; 28import android.os.Bundle;
29import android.util.Log; 29import android.util.Log;
30import android.view.View;
30import android.view.ViewGroup; 31import android.view.ViewGroup;
31import android.view.Window; 32import android.view.Window;
32import android.view.WindowManager; 33import android.view.WindowManager;
@@ -98,9 +99,7 @@ public class RockboxActivity extends Activity
98 loadingdialog.dismiss(); 99 loadingdialog.dismiss();
99 if (rbservice.get_fb() == null) 100 if (rbservice.get_fb() == null)
100 throw new IllegalStateException("FB NULL"); 101 throw new IllegalStateException("FB NULL");
101 rbservice.set_activity(thisActivity); 102 attachFramebuffer();
102 setContentView(rbservice.get_fb());
103 rbservice.get_fb().invalidate();
104 } 103 }
105 }); 104 });
106 } 105 }
@@ -112,26 +111,29 @@ public class RockboxActivity extends Activity
112 rbservice = RockboxService.get_instance(); 111 rbservice = RockboxService.get_instance();
113 return (rbservice!= null && rbservice.isRockboxRunning() == true); 112 return (rbservice!= null && rbservice.isRockboxRunning() == true);
114 } 113 }
115 114
115 private void attachFramebuffer()
116 {
117 View rbFramebuffer = rbservice.get_fb();
118 try {
119 setContentView(rbFramebuffer);
120 } catch (IllegalStateException e) {
121 /* we are already using the View,
122 * need to remove it and re-attach it */
123 ViewGroup g = (ViewGroup) rbFramebuffer.getParent();
124 g.removeView(rbFramebuffer);
125 setContentView(rbFramebuffer);
126 } finally {
127 rbFramebuffer.requestFocus();
128 rbservice.set_activity(this);
129 }
130 }
131
116 public void onResume() 132 public void onResume()
117 { 133 {
118
119 super.onResume(); 134 super.onResume();
120 if (isRockboxRunning()) 135 if (isRockboxRunning())
121 { 136 attachFramebuffer();
122 try {
123 setContentView(rbservice.get_fb());
124 } catch (IllegalStateException e) {
125 /* we are already using the View,
126 * need to remove it and re-attach it */
127 ViewGroup g = (ViewGroup)rbservice.get_fb().getParent();
128 g.removeView(rbservice.get_fb());
129 setContentView(rbservice.get_fb());
130 } finally {
131 rbservice.set_activity(this);
132 rbservice.get_fb().resume();
133 }
134 }
135 } 137 }
136 138
137 /* this is also called when the backlight goes off, 139 /* this is also called when the backlight goes off,
@@ -142,7 +144,6 @@ public class RockboxActivity extends Activity
142 { 144 {
143 super.onPause(); 145 super.onPause();
144 rbservice.set_activity(null); 146 rbservice.set_activity(null);
145 rbservice.get_fb().suspend();
146 } 147 }
147 148
148 @Override 149 @Override
@@ -150,7 +151,6 @@ public class RockboxActivity extends Activity
150 { 151 {
151 super.onStop(); 152 super.onStop();
152 rbservice.set_activity(null); 153 rbservice.set_activity(null);
153 rbservice.get_fb().suspend();
154 } 154 }
155 155
156 @Override 156 @Override
@@ -158,7 +158,6 @@ public class RockboxActivity extends Activity
158 { 158 {
159 super.onDestroy(); 159 super.onDestroy();
160 rbservice.set_activity(null); 160 rbservice.set_activity(null);
161 rbservice.get_fb().suspend();
162 } 161 }
163 162
164 private HostCallback hostcallback = null; 163 private HostCallback hostcallback = null;
diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java
index 84974d627a..0a60182502 100644
--- a/android/src/org/rockbox/RockboxFramebuffer.java
+++ b/android/src/org/rockbox/RockboxFramebuffer.java
@@ -49,7 +49,6 @@ public class RockboxFramebuffer extends View
49 setClickable(true); 49 setClickable(true);
50 btm = Bitmap.createBitmap(lcd_width, lcd_height, Bitmap.Config.RGB_565); 50 btm = Bitmap.createBitmap(lcd_width, lcd_height, Bitmap.Config.RGB_565);
51 native_buf = native_fb; 51 native_buf = native_fb;
52 requestFocus();
53 media_monitor = new MediaButtonReceiver(c); 52 media_monitor = new MediaButtonReceiver(c);
54 media_monitor.register(); 53 media_monitor.register();
55 /* the service needs to know the about us */ 54 /* the service needs to know the about us */
@@ -60,7 +59,7 @@ public class RockboxFramebuffer extends View
60 { 59 {
61 c.drawBitmap(btm, 0.0f, 0.0f, null); 60 c.drawBitmap(btm, 0.0f, 0.0f, null);
62 } 61 }
63 62
64 @SuppressWarnings("unused") 63 @SuppressWarnings("unused")
65 private void java_lcd_update() 64 private void java_lcd_update()
66 { 65 {
@@ -112,29 +111,29 @@ public class RockboxFramebuffer extends View
112 return buttonHandler(keyCode, false); 111 return buttonHandler(keyCode, false);
113 } 112 }
114 113
115 /* the two below should only be called from the activity thread */ 114 public void destroy()
116 public void suspend() 115 {
117 { /* suspend, Rockbox will not make any lcd updates */
118 set_lcd_active(0); 116 set_lcd_active(0);
119 } 117 media_monitor.unregister();
120 public void resume()
121 {
122 /* Needed so we can catch KeyEvents */
123 setFocusable(true);
124 setFocusableInTouchMode(true);
125 setClickable(true);
126 requestFocus();
127 set_lcd_active(1);
128 } 118 }
129 119
130 public void destroy() 120 @Override
121 protected void onWindowVisibilityChanged(int visibility)
131 { 122 {
132 suspend(); 123 super.onWindowVisibilityChanged(visibility);
133 media_monitor.unregister(); 124
125 switch (visibility) {
126 case VISIBLE:
127 set_lcd_active(1);
128 break;
129 case GONE:
130 case INVISIBLE:
131 set_lcd_active(0);
132 break;
133 }
134 } 134 }
135 135
136 public native void set_lcd_active(int active); 136 private native void set_lcd_active(int active);
137 public native void touchHandler(boolean down, int x, int y); 137 private native void touchHandler(boolean down, int x, int y);
138 public native boolean buttonHandler(int keycode, boolean state); 138 private native boolean buttonHandler(int keycode, boolean state);
139
140} 139}