diff options
Diffstat (limited to 'android/src/org/rockbox/RockboxActivity.java')
-rw-r--r-- | android/src/org/rockbox/RockboxActivity.java | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java index 76535687f9..f3f0d2151c 100644 --- a/android/src/org/rockbox/RockboxActivity.java +++ b/android/src/org/rockbox/RockboxActivity.java | |||
@@ -66,10 +66,9 @@ public class RockboxActivity extends Activity | |||
66 | protected void onReceiveResult(final int resultCode, final Bundle resultData) | 66 | protected void onReceiveResult(final int resultCode, final Bundle resultData) |
67 | { | 67 | { |
68 | switch (resultCode) { | 68 | switch (resultCode) { |
69 | case RockboxService.RESULT_LIB_LOADED: | 69 | case RockboxService.RESULT_INVOKING_MAIN: |
70 | rbservice = RockboxService.get_instance(); | ||
71 | if (loadingdialog != null) | 70 | if (loadingdialog != null) |
72 | loadingdialog.setIndeterminate(true); | 71 | loadingdialog.dismiss(); |
73 | break; | 72 | break; |
74 | case RockboxService.RESULT_LIB_LOAD_PROGRESS: | 73 | case RockboxService.RESULT_LIB_LOAD_PROGRESS: |
75 | if (loadingdialog == null) | 74 | if (loadingdialog == null) |
@@ -79,10 +78,10 @@ public class RockboxActivity extends Activity | |||
79 | loadingdialog.setMax(resultData.getInt("max", 100)); | 78 | loadingdialog.setMax(resultData.getInt("max", 100)); |
80 | loadingdialog.setProgress(resultData.getInt("value", 0)); | 79 | loadingdialog.setProgress(resultData.getInt("value", 0)); |
81 | break; | 80 | break; |
82 | case RockboxService.RESULT_FB_INITIALIZED: | 81 | case RockboxService.RESULT_SERVICE_RUNNING: |
82 | rbservice = RockboxService.get_instance(); | ||
83 | setServiceActivity(true); | ||
83 | attachFramebuffer(); | 84 | attachFramebuffer(); |
84 | if (loadingdialog != null) | ||
85 | loadingdialog.dismiss(); | ||
86 | break; | 85 | break; |
87 | case RockboxService.RESULT_ERROR_OCCURED: | 86 | case RockboxService.RESULT_ERROR_OCCURED: |
88 | Toast.makeText(RockboxActivity.this, resultData.getString("error"), Toast.LENGTH_LONG); | 87 | Toast.makeText(RockboxActivity.this, resultData.getString("error"), Toast.LENGTH_LONG); |
@@ -93,17 +92,17 @@ public class RockboxActivity extends Activity | |||
93 | startService(intent); | 92 | startService(intent); |
94 | } | 93 | } |
95 | 94 | ||
96 | private boolean isRockboxRunning() | 95 | private void setServiceActivity(boolean set) |
97 | { | 96 | { |
98 | if (rbservice == null) | 97 | if (rbservice != null) |
99 | rbservice = RockboxService.get_instance(); | 98 | rbservice.set_activity(this); |
100 | return (rbservice!= null && rbservice.isRockboxRunning() == true); | ||
101 | } | 99 | } |
102 | 100 | ||
103 | private void attachFramebuffer() | 101 | private void attachFramebuffer() |
104 | { | 102 | { |
105 | View rbFramebuffer = rbservice.get_fb(); | 103 | View rbFramebuffer = null; |
106 | try { | 104 | try { |
105 | rbFramebuffer = rbservice.get_fb(); | ||
107 | setContentView(rbFramebuffer); | 106 | setContentView(rbFramebuffer); |
108 | } catch (IllegalStateException e) { | 107 | } catch (IllegalStateException e) { |
109 | /* we are already using the View, | 108 | /* we are already using the View, |
@@ -111,17 +110,17 @@ public class RockboxActivity extends Activity | |||
111 | ViewGroup g = (ViewGroup) rbFramebuffer.getParent(); | 110 | ViewGroup g = (ViewGroup) rbFramebuffer.getParent(); |
112 | g.removeView(rbFramebuffer); | 111 | g.removeView(rbFramebuffer); |
113 | setContentView(rbFramebuffer); | 112 | setContentView(rbFramebuffer); |
114 | } finally { | 113 | } catch (NullPointerException e) { |
115 | rbFramebuffer.requestFocus(); | 114 | return; |
116 | rbservice.set_activity(this); | ||
117 | } | 115 | } |
116 | rbFramebuffer.requestFocus(); | ||
118 | } | 117 | } |
119 | 118 | ||
120 | public void onResume() | 119 | public void onResume() |
121 | { | 120 | { |
122 | super.onResume(); | 121 | super.onResume(); |
123 | if (isRockboxRunning()) | 122 | setVisible(true); |
124 | attachFramebuffer(); | 123 | attachFramebuffer(); |
125 | } | 124 | } |
126 | 125 | ||
127 | /* this is also called when the backlight goes off, | 126 | /* this is also called when the backlight goes off, |
@@ -131,27 +130,23 @@ public class RockboxActivity extends Activity | |||
131 | protected void onPause() | 130 | protected void onPause() |
132 | { | 131 | { |
133 | super.onPause(); | 132 | super.onPause(); |
134 | if (rbservice != null) | 133 | /* this will cause the framebuffer's Surface to be destroyed, enabling |
135 | { | 134 | * us to disable drawing */ |
136 | rbservice.set_activity(null); | 135 | setVisible(false); |
137 | rbservice.get_fb().dispatchWindowVisibilityChanged(View.INVISIBLE); | ||
138 | } | ||
139 | } | 136 | } |
140 | 137 | ||
141 | @Override | 138 | @Override |
142 | protected void onStop() | 139 | protected void onStop() |
143 | { | 140 | { |
144 | super.onStop(); | 141 | super.onStop(); |
145 | if (rbservice != null) | 142 | setServiceActivity(false); |
146 | rbservice.set_activity(null); | ||
147 | } | 143 | } |
148 | 144 | ||
149 | @Override | 145 | @Override |
150 | protected void onDestroy() | 146 | protected void onDestroy() |
151 | { | 147 | { |
152 | super.onDestroy(); | 148 | super.onDestroy(); |
153 | if (rbservice != null) | 149 | setServiceActivity(false); |
154 | rbservice.set_activity(null); | ||
155 | } | 150 | } |
156 | 151 | ||
157 | private void LOG(CharSequence text) | 152 | private void LOG(CharSequence text) |