예제 #1
0
  /**
   * Check if this activity was launched from a local notification, and send details to application
   */
  private void checkLaunchedFromNotification() {
    if (this.lastIntentExtras != null) {
      LOG.Log(Module.GUI, "Activity was launched from Notification Manager... ");
      final String message = lastIntentExtras.getString(NotificationUtils.EXTRA_MESSAGE);
      final String notificationSound =
          this.lastIntentExtras.getString(NotificationUtils.EXTRA_SOUND);
      final String customJSONString =
          this.lastIntentExtras.getString(NotificationUtils.EXTRA_CUSTOM_JSON);
      final String notificationId =
          lastIntentExtras.getString(NotificationUtils.EXTRA_NOTIFICATION_ID);
      final String notificationType = lastIntentExtras.getString(NotificationUtils.EXTRA_TYPE);
      LOG.Log(Module.GUI, notificationType + " Notification ID = " + notificationId);

      NotificationData notif = new NotificationData();
      notif.setAlertMessage(message);
      notif.setSound(notificationSound);
      notif.setCustomDataJsonString(customJSONString);

      if (notificationType != null
          && notificationType.equals(NotificationUtils.NOTIFICATION_TYPE_LOCAL)) {
        appView.loadUrl(
            "javascript:try{Unity.OnLocalNotificationReceived("
                + JSONSerializer.serialize(notif)
                + ")}catch(e){}");
      } else if (notificationType != null
          && notificationType.equals(NotificationUtils.NOTIFICATION_TYPE_REMOTE)) {
        appView.loadUrl(
            "javascript:try{Unity.OnRemoteNotificationReceived("
                + JSONSerializer.serialize(notif)
                + ")}catch(e){}");
      }

      this.lastIntentExtras = null;
    }
  }
예제 #2
0
  private void startServer() {

    if (server == null) {
      AssetManager am =
          (AssetManager)
              AndroidServiceLocator.GetInstance()
                  .GetService(AndroidServiceLocator.SERVICE_ANDROID_ASSET_MANAGER);
      if (serverProperties == null) {
        serverProperties = new Properties();
        try {
          serverProperties.load(am.open(SERVER_PROPERTIES));
        } catch (IOException ex) {
          LOG.Log(Module.GUI, ex.toString());
        }
      }
      LOG.Log(
          Module.GUI,
          "The Port is: " + serverProperties.getProperty(SERVER_PORT_PROPERTY, "Missing"));
      try {
        serverPort = Integer.parseInt(serverProperties.getProperty(SERVER_PORT_PROPERTY));
        server = new HttpServer(serverPort, this, this.appView);
        server.start();
      } catch (Exception ex) {
        LOG.Log(Module.GUI, ex.toString());
      }
      LOG.Log(Module.GUI, "Server started.");
    }
  }
예제 #3
0
  @Override
  protected void onDestroy() {
    LOG.Log(Module.GUI, "onDestroy");

    // Stop HTTP server
    stopServer();
    super.onDestroy();

    LOG.Log(Module.GUI, "killing process...");
    android.os.Process.killProcess(android.os.Process.myPid());
  }
예제 #4
0
  private boolean checkUnityProperty(String propertyName) {
    int resourceIdentifier = getResources().getIdentifier(propertyName, "string", getPackageName());
    try {
      boolean propertyValue = Boolean.parseBoolean(getResources().getString(resourceIdentifier));
      LOG.Log(Module.GUI, propertyName + "? " + propertyValue);
      return propertyValue;

    } catch (Exception ex) {
      LOG.Log(Module.GUI, "Exception getting value for " + propertyName + ": " + ex.getMessage());
      return false;
    }
  }
예제 #5
0
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    AndroidSystem system =
        (AndroidSystem)
            AndroidServiceLocator.GetInstance()
                .GetService(AndroidServiceLocator.SERVICE_TYPE_SYSTEM);
    boolean locked = system.IsOrientationLocked();
    if (locked) {
      int configOrientation;
      DisplayOrientation lockedOrientation = system.GetLockedOrientation();
      if (DisplayOrientation.Portrait.equals(lockedOrientation)) {
        configOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
      } else if (DisplayOrientation.Landscape.equals(lockedOrientation)) {
        configOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
      } else {
        // Portrait as default orientation
        configOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
      }
      if (newConfig.orientation != configOrientation) {
        LOG.Log(
            Module.GUI,
            "Main Activity onConfigurationChanged setting requested orientation: "
                + configOrientation);

        setRequestedOrientation(configOrientation);
      }
    } else {
      activityManager.layoutSplashscreen();
      appView.requestLayout();
    }
  }
예제 #6
0
  @Override
  protected void onResume() {
    super.onResume();

    if (ProxySettings.checkSystemProxyProperties()) {
      ProxySettings.shouldSetProxySetting = true;
    }

    // Save the context for further access
    AndroidServiceLocator.setContext(this);
    NotificationManager nMngr =
        (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    nMngr.cancelAll();
    LOG.Log(Module.GUI, "onResume");

    /*
    // security reasons
    if(splashShownOnBackground) {
    	activityManager.dismissSplashScreen();
    	splashShownOnBackground = false;
    }
    */
    // Start HTTP server
    startServer();

    appView.loadUrl("javascript:try{Unity._toForeground()}catch(e){}");

    // storing last intent extras
    if (this.getIntent() != null) {
      this.lastIntentExtras = this.getIntent().getExtras();
      Bundle nullExtras = null;
      this.getIntent().replaceExtras(nullExtras);
    }
  }
예제 #7
0
  private void stopServer() {

    if (server != null) {
      server.shutdown();
      server = null;
      LOG.Log(Module.GUI, "Server stopped.");
    }
  }
예제 #8
0
  @Override
  protected void onStop() {
    LOG.Log(Module.GUI, "onStop");

    // Stop HTTP server
    stopServer();
    super.onStop();
  }
예제 #9
0
 @Override
 public boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas) {
   LOG.Log(Module.GUI, "onCreateThumbnail");
   if (!disableThumbnails) {
     return super.onCreateThumbnail(outBitmap, canvas);
   } else {
     return true; // for security reasons, thumbnails are not allowed
   }
 }
예제 #10
0
  @Override
  protected void onPause() {
    LOG.Log(Module.GUI, "onPause");

    appView.loadUrl("javascript:try{Unity._toBackground()}catch(e){}");

    // Stop HTTP server
    stopServer();
    super.onPause();
  }
예제 #11
0
  @Override
  public void onWindowFocusChanged(boolean hasFocus) {
    LOG.Log(Module.GUI, "onWindowFocusChanged");
    if (hasFocus) {
      LOG.Log(Module.GUI, "application has focus; calling foreground listener");
      appView.loadUrl("javascript:try{Unity._toForeground()}catch(e){}");

      // check for notification details
      this.checkLaunchedFromNotification();

    } else {
      LOG.Log(Module.GUI, "application lost focus; calling background listener");
      appView.loadUrl("javascript:try{Unity._toBackground()}catch(e){}");
      /*
      if (server == null) {
      	// security reasons; the splash screen is shown when application enters in background (hiding sensitive data)
      	// it will be dismissed "onResume" method
      	if(!splashShownOnBackground) {
      		splashShownOnBackground = activityManager.showSplashScreen(appView);
      	}
      }
      */
    }
  }
예제 #12
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LOG.Log(Module.GUI, "onCreate");

    // GUI initialization code
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    disableThumbnails = checkUnityProperty("Unity_DisableThumbnails");

    // security reasons; don't allow screen shots while this window is displayed
    /* not valid for builds under level 14 */
    if (disableThumbnails && Build.VERSION.SDK_INT >= 14) {
      getWindow()
          .setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    }

    appView = new WebView(this);
    appView.enablePlatformNotifications();
    setGlobalProxy();

    appView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    appView.setId(APPVIEW_ID);
    appView.setWebViewClient(new UnityWebViewClient());
    appView.getSettings().setJavaScriptEnabled(true);
    appView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    appView.getSettings().setAllowFileAccess(true);
    appView.getSettings().setSupportZoom(false);
    appView.getSettings().setAppCacheEnabled(false);
    appView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    appView.getSettings().setAppCacheMaxSize(0);
    appView.getSettings().setSavePassword(false);
    appView.getSettings().setSaveFormData(false);
    appView.getSettings().setDefaultTextEncodingName("UTF-8");
    appView.getSettings().setGeolocationEnabled(true);
    appView.getSettings().setLightTouchEnabled(true);
    appView.getSettings().setRenderPriority(RenderPriority.HIGH);
    appView.getSettings().setDomStorageEnabled(true); // [MOBPLAT-129] enable HTML5 local storage

    appView.setVerticalScrollBarEnabled(false);

    // Required settings to enable HTML5 database storage
    appView.getSettings().setDatabaseEnabled(true);
    String databasePath =
        this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    appView.getSettings().setDatabasePath(databasePath);

    webChromeClient =
        new WebChromeClient() {

          // Required settings to enable HTML5 database storage
          @Override
          public void onExceededDatabaseQuota(
              String url,
              String databaseIdentifier,
              long currentQuota,
              long estimatedSize,
              long totalUsedQuota,
              WebStorage.QuotaUpdater quotaUpdater) {
            quotaUpdater.updateQuota(estimatedSize * 2);
          };

          @Override
          public void onReachedMaxAppCacheSize(
              long spaceNeeded,
              long totalUsedQuota,
              android.webkit.WebStorage.QuotaUpdater quotaUpdater) {
            quotaUpdater.updateQuota(0);
          };

          @Override
          public boolean onConsoleMessage(ConsoleMessage cm) {
            LOG.Log(
                Module.GUI,
                cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
          }
        };

    appView.setWebChromeClient(webChromeClient);

    // create the application logger
    LogManager.setDelegate(new AndroidLoggerDelegate());

    // save the context for further access
    AndroidServiceLocator.setContext(this);

    // initialize the service locator
    activityManager = new AndroidActivityManager(this, appView);

    // killing previous background processes from the same package
    activityManager.killBackgroundProcesses();

    AndroidServiceLocator serviceLocator =
        (AndroidServiceLocator) AndroidServiceLocator.GetInstance();
    serviceLocator.RegisterService(
        this.getAssets(), AndroidServiceLocator.SERVICE_ANDROID_ASSET_MANAGER);
    serviceLocator.RegisterService(
        activityManager, AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
    startServer();

    /* THIS COULD NOT BE CHECKED ON API LEVEL < 11; NO suchmethodexception
    boolean hwAccelerated = appView.isHardwareAccelerated();
    if(hwAccelerated)
    	LOG.Log(Module.GUI,"Application View is HARDWARE ACCELERATED");
    else
    	LOG.Log(Module.GUI,"Application View is NOT hardware accelerated");
    */

    final IntentFilter actionFilter = new IntentFilter();
    actionFilter.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION);
    // actionFilter.addAction("android.intent.action.SERVICE_STATE");
    registerReceiver(new AndroidNetworkReceiver(appView), actionFilter);

    final Activity currentContext = this;
    new Thread(
            new Runnable() {
              public void run() {
                currentContext.runOnUiThread(
                    new Runnable() {
                      public void run() {
                        appView.loadUrl(WEBVIEW_MAIN_URL);
                      }
                    });
              }
            })
        .start();

    holdSplashScreenOnStartup = checkUnityProperty("Unity_HoldSplashScreenOnStartup");
    hasSplash = activityManager.showSplashScreen(appView);
    RemoteNotificationIntentService.loadNotificationOptions(getResources(), appView, this);
    LocalNotificationReceiver.initialize(appView, this);
  }
예제 #13
0
public class MainActivity extends Activity {

  private static final SystemLogger LOG = SystemLogger.getInstance();

  // private static final String WEBVIEW_MAIN_URL =
  // "file:///android_asset/WebResources/www/index.html";
  private static final String WEBVIEW_MAIN_URL =
      "http://127.0.0.1:8080/WebResources/www/index.html";

  private static final String SERVER_PROPERTIES = "Settings.bundle/Root.properties";
  private static final String SERVER_PORT_PROPERTY = "IPC_DefaultPort";

  private WebView appView;
  private WebChromeClient webChromeClient;
  private boolean hasSplash = false;
  // private boolean splashShownOnBackground = false;
  private AndroidActivityManager activityManager = null;
  private boolean holdSplashScreenOnStartup = false;
  private boolean disableThumbnails = false;

  private HttpServer server = null;
  private Properties serverProperties;
  private int serverPort;

  private static final int APPVIEW_ID = 10;

  private Bundle lastIntentExtras = null;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LOG.Log(Module.GUI, "onCreate");

    // GUI initialization code
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    disableThumbnails = checkUnityProperty("Unity_DisableThumbnails");

    // security reasons; don't allow screen shots while this window is displayed
    /* not valid for builds under level 14 */
    if (disableThumbnails && Build.VERSION.SDK_INT >= 14) {
      getWindow()
          .setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    }

    appView = new WebView(this);
    appView.enablePlatformNotifications();
    setGlobalProxy();

    appView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    appView.setId(APPVIEW_ID);
    appView.setWebViewClient(new UnityWebViewClient());
    appView.getSettings().setJavaScriptEnabled(true);
    appView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    appView.getSettings().setAllowFileAccess(true);
    appView.getSettings().setSupportZoom(false);
    appView.getSettings().setAppCacheEnabled(false);
    appView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    appView.getSettings().setAppCacheMaxSize(0);
    appView.getSettings().setSavePassword(false);
    appView.getSettings().setSaveFormData(false);
    appView.getSettings().setDefaultTextEncodingName("UTF-8");
    appView.getSettings().setGeolocationEnabled(true);
    appView.getSettings().setLightTouchEnabled(true);
    appView.getSettings().setRenderPriority(RenderPriority.HIGH);
    appView.getSettings().setDomStorageEnabled(true); // [MOBPLAT-129] enable HTML5 local storage

    appView.setVerticalScrollBarEnabled(false);

    // Required settings to enable HTML5 database storage
    appView.getSettings().setDatabaseEnabled(true);
    String databasePath =
        this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    appView.getSettings().setDatabasePath(databasePath);

    webChromeClient =
        new WebChromeClient() {

          // Required settings to enable HTML5 database storage
          @Override
          public void onExceededDatabaseQuota(
              String url,
              String databaseIdentifier,
              long currentQuota,
              long estimatedSize,
              long totalUsedQuota,
              WebStorage.QuotaUpdater quotaUpdater) {
            quotaUpdater.updateQuota(estimatedSize * 2);
          };

          @Override
          public void onReachedMaxAppCacheSize(
              long spaceNeeded,
              long totalUsedQuota,
              android.webkit.WebStorage.QuotaUpdater quotaUpdater) {
            quotaUpdater.updateQuota(0);
          };

          @Override
          public boolean onConsoleMessage(ConsoleMessage cm) {
            LOG.Log(
                Module.GUI,
                cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
          }
        };

    appView.setWebChromeClient(webChromeClient);

    // create the application logger
    LogManager.setDelegate(new AndroidLoggerDelegate());

    // save the context for further access
    AndroidServiceLocator.setContext(this);

    // initialize the service locator
    activityManager = new AndroidActivityManager(this, appView);

    // killing previous background processes from the same package
    activityManager.killBackgroundProcesses();

    AndroidServiceLocator serviceLocator =
        (AndroidServiceLocator) AndroidServiceLocator.GetInstance();
    serviceLocator.RegisterService(
        this.getAssets(), AndroidServiceLocator.SERVICE_ANDROID_ASSET_MANAGER);
    serviceLocator.RegisterService(
        activityManager, AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
    startServer();

    /* THIS COULD NOT BE CHECKED ON API LEVEL < 11; NO suchmethodexception
    boolean hwAccelerated = appView.isHardwareAccelerated();
    if(hwAccelerated)
    	LOG.Log(Module.GUI,"Application View is HARDWARE ACCELERATED");
    else
    	LOG.Log(Module.GUI,"Application View is NOT hardware accelerated");
    */

    final IntentFilter actionFilter = new IntentFilter();
    actionFilter.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION);
    // actionFilter.addAction("android.intent.action.SERVICE_STATE");
    registerReceiver(new AndroidNetworkReceiver(appView), actionFilter);

    final Activity currentContext = this;
    new Thread(
            new Runnable() {
              public void run() {
                currentContext.runOnUiThread(
                    new Runnable() {
                      public void run() {
                        appView.loadUrl(WEBVIEW_MAIN_URL);
                      }
                    });
              }
            })
        .start();

    holdSplashScreenOnStartup = checkUnityProperty("Unity_HoldSplashScreenOnStartup");
    hasSplash = activityManager.showSplashScreen(appView);
    RemoteNotificationIntentService.loadNotificationOptions(getResources(), appView, this);
    LocalNotificationReceiver.initialize(appView, this);
  }

  private boolean checkUnityProperty(String propertyName) {
    int resourceIdentifier = getResources().getIdentifier(propertyName, "string", getPackageName());
    try {
      boolean propertyValue = Boolean.parseBoolean(getResources().getString(resourceIdentifier));
      LOG.Log(Module.GUI, propertyName + "? " + propertyValue);
      return propertyValue;

    } catch (Exception ex) {
      LOG.Log(Module.GUI, "Exception getting value for " + propertyName + ": " + ex.getMessage());
      return false;
    }
  }

  @Override
  public boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas) {
    LOG.Log(Module.GUI, "onCreateThumbnail");
    if (!disableThumbnails) {
      return super.onCreateThumbnail(outBitmap, canvas);
    } else {
      return true; // for security reasons, thumbnails are not allowed
    }
  }

  @Override
  public void onWindowFocusChanged(boolean hasFocus) {
    LOG.Log(Module.GUI, "onWindowFocusChanged");
    if (hasFocus) {
      LOG.Log(Module.GUI, "application has focus; calling foreground listener");
      appView.loadUrl("javascript:try{Unity._toForeground()}catch(e){}");

      // check for notification details
      this.checkLaunchedFromNotification();

    } else {
      LOG.Log(Module.GUI, "application lost focus; calling background listener");
      appView.loadUrl("javascript:try{Unity._toBackground()}catch(e){}");
      /*
      if (server == null) {
      	// security reasons; the splash screen is shown when application enters in background (hiding sensitive data)
      	// it will be dismissed "onResume" method
      	if(!splashShownOnBackground) {
      		splashShownOnBackground = activityManager.showSplashScreen(appView);
      	}
      }
      */
    }
  }

  @Override
  protected void onPause() {
    LOG.Log(Module.GUI, "onPause");

    appView.loadUrl("javascript:try{Unity._toBackground()}catch(e){}");

    // Stop HTTP server
    stopServer();
    super.onPause();
  }

  @Override
  protected void onResume() {
    super.onResume();

    if (ProxySettings.checkSystemProxyProperties()) {
      ProxySettings.shouldSetProxySetting = true;
    }

    // Save the context for further access
    AndroidServiceLocator.setContext(this);
    NotificationManager nMngr =
        (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    nMngr.cancelAll();
    LOG.Log(Module.GUI, "onResume");

    /*
    // security reasons
    if(splashShownOnBackground) {
    	activityManager.dismissSplashScreen();
    	splashShownOnBackground = false;
    }
    */
    // Start HTTP server
    startServer();

    appView.loadUrl("javascript:try{Unity._toForeground()}catch(e){}");

    // storing last intent extras
    if (this.getIntent() != null) {
      this.lastIntentExtras = this.getIntent().getExtras();
      Bundle nullExtras = null;
      this.getIntent().replaceExtras(nullExtras);
    }
  }

  @Override
  protected void finalize() throws Throwable {
    LOG.Log(Module.GUI, "on finalize method. Stopping server...");
    stopServer();
    super.finalize();
  }

  @Override
  protected void onDestroy() {
    LOG.Log(Module.GUI, "onDestroy");

    // Stop HTTP server
    stopServer();
    super.onDestroy();

    LOG.Log(Module.GUI, "killing process...");
    android.os.Process.killProcess(android.os.Process.myPid());
  }

  @Override
  protected void onStop() {
    LOG.Log(Module.GUI, "onStop");

    // Stop HTTP server
    stopServer();
    super.onStop();
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    AndroidActivityManager aam =
        (AndroidActivityManager)
            AndroidServiceLocator.GetInstance()
                .GetService(AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
    if (aam != null) {
      aam.publishActivityResult(requestCode, resultCode, data);
    }
  }

  private void startServer() {

    if (server == null) {
      AssetManager am =
          (AssetManager)
              AndroidServiceLocator.GetInstance()
                  .GetService(AndroidServiceLocator.SERVICE_ANDROID_ASSET_MANAGER);
      if (serverProperties == null) {
        serverProperties = new Properties();
        try {
          serverProperties.load(am.open(SERVER_PROPERTIES));
        } catch (IOException ex) {
          LOG.Log(Module.GUI, ex.toString());
        }
      }
      LOG.Log(
          Module.GUI,
          "The Port is: " + serverProperties.getProperty(SERVER_PORT_PROPERTY, "Missing"));
      try {
        serverPort = Integer.parseInt(serverProperties.getProperty(SERVER_PORT_PROPERTY));
        server = new HttpServer(serverPort, this, this.appView);
        server.start();
      } catch (Exception ex) {
        LOG.Log(Module.GUI, ex.toString());
      }
      LOG.Log(Module.GUI, "Server started.");
    }
  }

  /**
   * Check if this activity was launched from a local notification, and send details to application
   */
  private void checkLaunchedFromNotification() {
    if (this.lastIntentExtras != null) {
      LOG.Log(Module.GUI, "Activity was launched from Notification Manager... ");
      final String message = lastIntentExtras.getString(NotificationUtils.EXTRA_MESSAGE);
      final String notificationSound =
          this.lastIntentExtras.getString(NotificationUtils.EXTRA_SOUND);
      final String customJSONString =
          this.lastIntentExtras.getString(NotificationUtils.EXTRA_CUSTOM_JSON);
      final String notificationId =
          lastIntentExtras.getString(NotificationUtils.EXTRA_NOTIFICATION_ID);
      final String notificationType = lastIntentExtras.getString(NotificationUtils.EXTRA_TYPE);
      LOG.Log(Module.GUI, notificationType + " Notification ID = " + notificationId);

      NotificationData notif = new NotificationData();
      notif.setAlertMessage(message);
      notif.setSound(notificationSound);
      notif.setCustomDataJsonString(customJSONString);

      if (notificationType != null
          && notificationType.equals(NotificationUtils.NOTIFICATION_TYPE_LOCAL)) {
        appView.loadUrl(
            "javascript:try{Unity.OnLocalNotificationReceived("
                + JSONSerializer.serialize(notif)
                + ")}catch(e){}");
      } else if (notificationType != null
          && notificationType.equals(NotificationUtils.NOTIFICATION_TYPE_REMOTE)) {
        appView.loadUrl(
            "javascript:try{Unity.OnRemoteNotificationReceived("
                + JSONSerializer.serialize(notif)
                + ")}catch(e){}");
      }

      this.lastIntentExtras = null;
    }
  }

  private void stopServer() {

    if (server != null) {
      server.shutdown();
      server = null;
      LOG.Log(Module.GUI, "Server stopped.");
    }
  }

  private void setGlobalProxy() {
    final WebView view = this.appView;
    ProxySettings.shouldSetProxySetting = true;
    ProxySettings.setProxy(view.getContext(), view, "", 0);
  }

  private class UnityWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
      LOG.Log(Module.GUI, "should override url loading [" + url + "]");
      view.loadUrl(url);
      return true;
    }

    @Override
    public void onLoadResource(WebView view, String url) {
      LOG.Log(Module.GUI, "loading resource [" + url + "]");
      super.onLoadResource(view, url);
    }

    @Override
    public void onReceivedError(
        WebView view, int errorCode, String description, String failingUrl) {
      LOG.Log(
          Module.GUI,
          "UnityWebViewClient failed loading: "
              + failingUrl
              + ", error code: "
              + errorCode
              + " ["
              + description
              + "]");
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
      LOG.Log(Module.GUI, "UnityWebViewClient onPageStarted [" + url + "]");
      super.onPageStarted(view, url, favicon);
    }

    @Override
    public void onPageFinished(WebView view, String url) {
      LOG.Log(Module.GUI, "UnityWebViewClient onPageFinished.");

      if (hasSplash && !holdSplashScreenOnStartup) {
        LOG.Log(Module.GUI, "UnityWebViewClient Dismissing SplashScreen (default)");
        activityManager.dismissSplashScreen();
      }

      super.onPageFinished(view, url);
    }
  }

  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {
      appView.loadUrl("javascript:try{Unity._backButtonPressed()}catch(e){}");
      return false;
    }

    return super.onKeyDown(keyCode, event);
  }

  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    AndroidSystem system =
        (AndroidSystem)
            AndroidServiceLocator.GetInstance()
                .GetService(AndroidServiceLocator.SERVICE_TYPE_SYSTEM);
    boolean locked = system.IsOrientationLocked();
    if (locked) {
      int configOrientation;
      DisplayOrientation lockedOrientation = system.GetLockedOrientation();
      if (DisplayOrientation.Portrait.equals(lockedOrientation)) {
        configOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
      } else if (DisplayOrientation.Landscape.equals(lockedOrientation)) {
        configOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
      } else {
        // Portrait as default orientation
        configOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
      }
      if (newConfig.orientation != configOrientation) {
        LOG.Log(
            Module.GUI,
            "Main Activity onConfigurationChanged setting requested orientation: "
                + configOrientation);

        setRequestedOrientation(configOrientation);
      }
    } else {
      activityManager.layoutSplashscreen();
      appView.requestLayout();
    }
  }
}
예제 #14
0
 @Override
 protected void finalize() throws Throwable {
   LOG.Log(Module.GUI, "on finalize method. Stopping server...");
   stopServer();
   super.finalize();
 }