Esempio n. 1
0
  @Kroll.method
  @Kroll.getProperty
  public boolean getKeepScreenOn() {
    Boolean keepScreenOn = null;
    TiUIView v = peekView();
    if (v != null) {
      View nv = v.getNativeView();
      if (nv != null) {
        keepScreenOn = nv.getKeepScreenOn();
      }
    }

    // Keep the proxy in the correct state
    Object current = getProperty(TiC.PROPERTY_KEEP_SCREEN_ON);
    if (current != null) {
      boolean currentValue = TiConvert.toBoolean(current);
      if (keepScreenOn == null) {
        keepScreenOn = currentValue;
      } else {
        if (currentValue != keepScreenOn) {
          setProperty(TiC.PROPERTY_KEEP_SCREEN_ON, keepScreenOn);
        } else {
          keepScreenOn = currentValue;
        }
      }
    } else {
      if (keepScreenOn == null) {
        keepScreenOn = false; // Android default
      }

      setProperty(TiC.PROPERTY_KEEP_SCREEN_ON, keepScreenOn);
    }

    return keepScreenOn;
  }
  @Override
  /**
   * When the activity is created, this method adds it to the activity stack and fires a javascript
   * 'create' event.
   *
   * @param savedInstanceState Bundle of saved data.
   */
  protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "Activity " + this + " onCreate", Log.DEBUG_MODE);

    inForeground = true;
    TiApplication tiApp = getTiApp();

    if (tiApp.isRestartPending()) {
      super.onCreate(savedInstanceState);
      if (!isFinishing()) {
        finish();
      }
      return;
    }

    // If all the activities has been killed and the runtime has been disposed, we cannot recover
    // one
    // specific activity because the info of the top-most view proxy has been lost
    // (TiActivityWindows.dispose()).
    // In this case, we have to restart the app.
    if (TiBaseActivity.isUnsupportedReLaunch(this, savedInstanceState)) {
      Log.w(TAG, "Runtime has been disposed. Finishing.");
      super.onCreate(savedInstanceState);
      tiApp.scheduleRestart(250);
      finish();
      return;
    }

    TiApplication.addToActivityStack(this);

    // create the activity proxy here so that it is accessible from the activity in all cases
    activityProxy = new ActivityProxy(this);

    // Increment the reference count so we correctly clean up when all of our activities have been
    // destroyed
    KrollRuntime.incrementActivityRefCount();

    Intent intent = getIntent();
    if (intent != null) {
      if (intent.hasExtra(TiC.INTENT_PROPERTY_MESSENGER)) {
        messenger = (Messenger) intent.getParcelableExtra(TiC.INTENT_PROPERTY_MESSENGER);
        msgActivityCreatedId = intent.getIntExtra(TiC.INTENT_PROPERTY_MSG_ACTIVITY_CREATED_ID, -1);
        msgId = intent.getIntExtra(TiC.INTENT_PROPERTY_MSG_ID, -1);
      }

      if (intent.hasExtra(TiC.PROPERTY_WINDOW_PIXEL_FORMAT)) {
        getWindow()
            .setFormat(intent.getIntExtra(TiC.PROPERTY_WINDOW_PIXEL_FORMAT, PixelFormat.UNKNOWN));
      }
    }

    // Doing this on every create in case the activity is externally created.
    TiPlatformHelper.intializeDisplayMetrics(this);

    if (layout == null) {
      layout = createLayout();
    }
    if (intent != null && intent.hasExtra(TiC.PROPERTY_KEEP_SCREEN_ON)) {
      layout.setKeepScreenOn(
          intent.getBooleanExtra(TiC.PROPERTY_KEEP_SCREEN_ON, layout.getKeepScreenOn()));
    }

    super.onCreate(savedInstanceState);

    // we only want to set the current activity for good in the resume state but we need it right
    // now.
    // save off the existing current activity, set ourselves to be the new current activity
    // temporarily
    // so we don't run into problems when we give the proxy the event
    Activity tempCurrentActivity = tiApp.getCurrentActivity();
    tiApp.setCurrentActivity(this, this);

    windowCreated();

    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_CREATE, null, 4000);
    }

    // set the current activity back to what it was originally
    tiApp.setCurrentActivity(this, tempCurrentActivity);

    setContentView(layout);

    sendMessage(msgActivityCreatedId);
    // for backwards compatibility
    sendMessage(msgId);

    // store off the original orientation for the activity set in the AndroidManifest.xml
    // for later use
    originalOrientationMode = getRequestedOrientation();

    if (window != null) {
      window.onWindowActivityCreated();
    }
  }