Ejemplo n.º 1
0
  public void setRootActivity(TiRootActivity rootActivity) {
    // TODO consider weakRef
    this.rootActivity = rootActivity;
    this.windowHandler = rootActivity;

    // calculate the display density
    DisplayMetrics dm = new DisplayMetrics();
    rootActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    switch (dm.densityDpi) {
      case DisplayMetrics.DENSITY_HIGH:
        {
          density = "high";
          break;
        }
      case DisplayMetrics.DENSITY_MEDIUM:
        {
          density = "medium";
          break;
        }
      case DisplayMetrics.DENSITY_LOW:
        {
          density = "low";
          break;
        }
    }

    if (collectAnalytics()) {
      analyticsIntent = new Intent(this, TiAnalyticsService.class);
      analyticsModel = new TiAnalyticsModel(this);
      needsEnrollEvent = analyticsModel.needsEnrollEvent();

      if (needsEnrollEvent()) {
        String deployType = systemProperties.getString("ti.deploytype", "unknown");
        postAnalyticsEvent(TiAnalyticsEventFactory.createAppEnrollEvent(this, deployType));
      }

      if (needsStartEvent()) {
        String deployType = systemProperties.getString("ti.deploytype", "unknown");

        postAnalyticsEvent(TiAnalyticsEventFactory.createAppStartEvent(this, deployType));
      }

    } else {
      needsEnrollEvent = false;
      needsStartEvent = false;
      Log.i(LCAT, "Analytics have been disabled");
    }
  }
Ejemplo n.º 2
0
  @Override
  /**
   * When this activity pauses, this method sets the current activity to null, fires a javascript
   * 'pause' event, and if the activity is finishing, remove all dialogs associated with it.
   */
  protected void onPause() {
    inForeground = false;
    super.onPause();
    isResumed = false;

    Log.d(TAG, "Activity " + this + " onPause", Log.DEBUG_MODE);

    TiApplication tiApp = getTiApp();
    if (tiApp.isRestartPending()) {
      releaseDialogs(true);
      if (!isFinishing()) {
        finish();
      }
      return;
    }

    if (!windowStack.empty()) {
      windowStack.peek().onWindowFocusChange(false);
    }

    TiApplication.updateActivityTransitionState(true);
    tiApp.setCurrentActivity(this, null);
    TiUIHelper.showSoftKeyboard(getWindow().getDecorView(), false);

    if (this.isFinishing()) {
      releaseDialogs(true);
    } else {
      // release non-persistent dialogs when activity hides
      releaseDialogs(false);
    }

    if (activityProxy != null) {
      activityProxy.fireSyncEvent(TiC.EVENT_PAUSE, null);
    }

    synchronized (lifecycleListeners.synchronizedList()) {
      for (OnLifecycleEvent listener : lifecycleListeners.nonNull()) {
        try {
          TiLifecycle.fireLifecycleEvent(this, listener, TiLifecycle.LIFECYCLE_ON_PAUSE);

        } catch (Throwable t) {
          Log.e(TAG, "Error dispatching lifecycle event: " + t.getMessage(), t);
        }
      }
    }

    // Checkpoint for ti.end event
    if (tiApp != null) {
      tiApp.postAnalyticsEvent(TiAnalyticsEventFactory.createAppEndEvent());
    }
  }
Ejemplo n.º 3
0
  @Override
  /**
   * When the activity resumes, this method updates the current activity to this and fires a
   * javascript 'resume' event.
   */
  protected void onResume() {
    inForeground = true;
    super.onResume();
    if (isFinishing()) {
      return;
    }

    Log.d(TAG, "Activity " + this + " onResume", Log.DEBUG_MODE);

    TiApplication tiApp = getTiApp();
    if (tiApp.isRestartPending()) {
      if (!isFinishing()) {
        finish();
      }
      return;
    }

    if (!windowStack.empty()) {
      windowStack.peek().onWindowFocusChange(true);
    }

    tiApp.setCurrentActivity(this, this);
    TiApplication.updateActivityTransitionState(false);

    if (activityProxy != null) {
      // Fire the sync event with a timeout, so the main thread won't be blocked too long to get an
      // ANR. (TIMOB-13253)
      activityProxy.fireSyncEvent(TiC.EVENT_RESUME, null, 4000);
    }

    synchronized (lifecycleListeners.synchronizedList()) {
      for (OnLifecycleEvent listener : lifecycleListeners.nonNull()) {
        try {
          TiLifecycle.fireLifecycleEvent(this, listener, TiLifecycle.LIFECYCLE_ON_RESUME);

        } catch (Throwable t) {
          Log.e(TAG, "Error dispatching lifecycle event: " + t.getMessage(), t);
        }
      }
    }

    isResumed = true;

    // Checkpoint for ti.start event
    String deployType = tiApp.getAppProperties().getString("ti.deploytype", "unknown");
    tiApp.postAnalyticsEvent(TiAnalyticsEventFactory.createAppStartEvent(tiApp, deployType));
  }