forked from ruboto/ruboto
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,47 @@ | ||
package THE_PACKAGE; | ||
|
||
import java.io.IOException; | ||
|
||
public abstract class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS { | ||
public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS { | ||
private String scriptName; | ||
private String remoteVariable = ""; | ||
|
||
THE_CONSTANTS | ||
|
||
private Object[] callbackProcs = new Object[CONSTANTS_COUNT]; | ||
private boolean initialized = false; | ||
|
||
public void setCallbackProc(int id, Object obj) { | ||
callbackProcs[id] = obj; | ||
// Error: no callbacks | ||
throw new RuntimeException("RubotoBroadcastReceiver does not accept callbacks"); | ||
} | ||
|
||
public THE_RUBOTO_CLASS setRemoteVariable(String var) { | ||
remoteVariable = ((var == null) ? "" : (var + ".")); | ||
return this; | ||
} | ||
|
||
public void setScriptName(String name){ | ||
scriptName = name; | ||
} | ||
|
||
public THE_RUBOTO_CLASS(String scriptName) { | ||
setScriptName(scriptName); | ||
if (Script.isInitialized()) { | ||
loadScript(); | ||
} | ||
} | ||
|
||
protected void loadScript() { | ||
Script.put("$broadcast_receiver", this); | ||
try { | ||
new Script(scriptName).execute(); | ||
} catch(IOException e) { | ||
throw new RuntimeException("IOException loading broadcast receiver script", e); | ||
} | ||
public THE_RUBOTO_CLASS() { | ||
this(null); | ||
} | ||
|
||
/**************************************************************************************** | ||
* | ||
* Generated Methods | ||
*/ | ||
public THE_RUBOTO_CLASS(String name) { | ||
super(); | ||
|
||
THE_METHODS | ||
if (name != null) | ||
setScriptName(name); | ||
} | ||
|
||
public void onReceive(android.content.Context context, android.content.Intent intent) { | ||
if (Script.setUpJRuby(context)) { | ||
Script.defineGlobalVariable("$context", context); | ||
Script.defineGlobalVariable("$broadcast_receiver", this); | ||
Script.defineGlobalVariable("$intent", intent); | ||
|
||
try { | ||
if (scriptName != null && !initialized) { | ||
new Script(scriptName).execute(); | ||
initialized = true; | ||
} else { | ||
Script.execute("$broadcast_receiver.on_receive($context, $intent)"); | ||
} | ||
} catch(Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters