Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. var r = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "getUserNames", "(V)Ljava/lang/String;");
  2. cc.log("Check this out" + r);
  3.  
  4. package org.cocos2dx.javascript;
  5.  
  6. import java.security.MessageDigest;
  7. import java.security.NoSuchAlgorithmException;
  8.  
  9. import org.cocos2dx.lib.Cocos2dxActivity;
  10. import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
  11. import android.content.pm.ActivityInfo;
  12. import android.content.pm.PackageInfo;
  13. import android.content.pm.PackageManager;
  14. import android.content.pm.Signature;
  15. import android.content.pm.PackageManager.NameNotFoundException;
  16. import android.net.wifi.WifiInfo;
  17. import android.net.wifi.WifiManager;
  18. import android.os.Bundle;
  19. import android.util.Base64;
  20. import android.util.Log;
  21. import android.view.WindowManager;
  22. import org.cocos2dx.plugin.PluginWrapper;
  23. import org.cocos2dx.plugin.FacebookWrapper;
  24. import android.content.Intent;
  25. import android.provider.Settings.Secure;
  26. import android.telephony.TelephonyManager;
  27. import android.util.Log;
  28.  
  29. // The name of .so is specified in AndroidMenifest.xml. NativityActivity will load it automatically for you.
  30. // You can use "System.loadLibrary()" to load other .so files.
  31.  
  32. public class AppActivity extends Cocos2dxActivity{
  33.  
  34. static String hostIPAdress = "0.0.0.0";
  35. // Get the instance of TelephonyManager
  36. TelephonyManager tm;;
  37.  
  38. // Calling the methods of TelephonyManager the returns the information
  39. static String IMEINumber;
  40.  
  41. @Override
  42. protected void onCreate(Bundle savedInstanceState) {
  43. // TODO Auto-generated method stub
  44. super.onCreate(savedInstanceState);
  45.  
  46. if(nativeIsLandScape()) {
  47. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
  48. } else {
  49. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
  50. }
  51. if(nativeIsDebug()){
  52. getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  53. }
  54. hostIPAdress = getHostIpAddress();
  55. IMEINumber = retrieveUserName();
  56. }
  57.  
  58. @Override
  59. public Cocos2dxGLSurfaceView onCreateView() {
  60. Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
  61. // TestCpp should create stencil buffer
  62. glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);
  63.  
  64. PluginWrapper.init(this);
  65. PluginWrapper.setGLSurfaceView(glSurfaceView);
  66. FacebookWrapper.onCreate(this);
  67.  
  68. return glSurfaceView;
  69. }
  70.  
  71. public String getHostIpAddress() {
  72. WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
  73. WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
  74. int ip = wifiInfo.getIpAddress();
  75. return ((ip & 0xFF) + "." + ((ip >>>= 8) & 0xFF) + "." + ((ip >>>= 8) & 0xFF) + "." + ((ip >>>= 8) & 0xFF));
  76. }
  77.  
  78. public String retrieveUserName(){
  79.  
  80. tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
  81. String im = tm.getDeviceId();
  82. if (im == "") {
  83. im = Secure.getString(getContentResolver(),
  84. Secure.ANDROID_ID);
  85. }
  86.  
  87. return im;
  88. }
  89.  
  90. public static String getLocalIpAddress() {
  91. return hostIPAdress;
  92. }
  93. public static String getUserNames() {
  94. return IMEINumber;
  95. }
  96.  
  97. @Override
  98. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  99. super.onActivityResult(requestCode, resultCode, data);
  100. FacebookWrapper.onAcitivityResult(requestCode, resultCode, data);
  101. }
  102.  
  103. @Override
  104. public void onSaveInstanceState(Bundle outState) {
  105. super.onSaveInstanceState(outState);
  106. FacebookWrapper.onSaveInstanceState(outState);
  107. }
  108.  
  109. private static native boolean nativeIsLandScape();
  110. private static native boolean nativeIsDebug();
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement