Beispiel #1
0
  private void handleBackgroundImage(KrollDict d) {
    String bg = d.getString(TiC.PROPERTY_BACKGROUND_IMAGE);
    String bgSelected = d.getString(TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE);
    String bgFocused = d.getString(TiC.PROPERTY_BACKGROUND_FOCUSED_IMAGE);
    String bgDisabled = d.getString(TiC.PROPERTY_BACKGROUND_DISABLED_IMAGE);

    String bgColor = d.getString(TiC.PROPERTY_BACKGROUND_COLOR);
    String bgSelectedColor = d.getString(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR);
    String bgFocusedColor = d.getString(TiC.PROPERTY_BACKGROUND_FOCUSED_COLOR);
    String bgDisabledColor = d.getString(TiC.PROPERTY_BACKGROUND_DISABLED_COLOR);

    if (bg != null) {
      bg = resolveImageUrl(bg);
    }
    if (bgSelected != null) {
      bgSelected = resolveImageUrl(bgSelected);
    }
    if (bgFocused != null) {
      bgFocused = resolveImageUrl(bgFocused);
    }
    if (bgDisabled != null) {
      bgDisabled = resolveImageUrl(bgDisabled);
    }

    if (bg != null
        || bgSelected != null
        || bgFocused != null
        || bgDisabled != null
        || bgColor != null
        || bgSelectedColor != null
        || bgFocusedColor != null
        || bgDisabledColor != null) {
      if (background == null) {
        applyCustomBackground(false);
      }

      Drawable bgDrawable =
          TiUIHelper.buildBackgroundDrawable(
              bg,
              d.getBoolean(TiC.PROPERTY_BACKGROUND_REPEAT),
              bgColor,
              bgSelected,
              bgSelectedColor,
              bgDisabled,
              bgDisabledColor,
              bgFocused,
              bgFocusedColor);

      background.setBackgroundDrawable(bgDrawable);
    }
  }
Beispiel #2
0
  private void handleBackgroundImage(KrollDict d) {
    String bg = d.getString(TiC.PROPERTY_BACKGROUND_IMAGE);
    String bgSelected = d.getString(TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE);
    String bgFocused = d.getString(TiC.PROPERTY_BACKGROUND_FOCUSED_IMAGE);
    String bgDisabled = d.getString(TiC.PROPERTY_BACKGROUND_DISABLED_IMAGE);

    String bgColor = d.getString(TiC.PROPERTY_BACKGROUND_COLOR);
    String bgSelectedColor = d.getString(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR);
    String bgFocusedColor = d.getString(TiC.PROPERTY_BACKGROUND_FOCUSED_COLOR);
    String bgDisabledColor = d.getString(TiC.PROPERTY_BACKGROUND_DISABLED_COLOR);

    TiContext tiContext = getProxy().getTiContext();
    if (bg != null) {
      bg = tiContext.resolveUrl(null, bg);
    }
    if (bgSelected != null) {
      bgSelected = tiContext.resolveUrl(null, bgSelected);
    }
    if (bgFocused != null) {
      bgFocused = tiContext.resolveUrl(null, bgFocused);
    }
    if (bgDisabled != null) {
      bgDisabled = tiContext.resolveUrl(null, bgDisabled);
    }

    if (bg != null
        || bgSelected != null
        || bgFocused != null
        || bgDisabled != null
        || bgColor != null
        || bgSelectedColor != null
        || bgFocusedColor != null
        || bgDisabledColor != null) {
      if (background == null) {
        applyCustomBackground(false);
      }

      Drawable bgDrawable =
          TiUIHelper.buildBackgroundDrawable(
              tiContext,
              bg,
              bgColor,
              bgSelected,
              bgSelectedColor,
              bgDisabled,
              bgDisabledColor,
              bgFocused,
              bgFocusedColor);
      background.setBackgroundDrawable(bgDrawable);
    }
  }
  private void applyCustomBackground(boolean reuseCurrentDrawable) {
    if (nativeView != null) {
      if (background == null) {
        background = new TiBackgroundDrawable();

        Drawable currentDrawable = nativeView.getBackground();
        if (currentDrawable != null) {
          if (reuseCurrentDrawable) {
            background.setBackgroundDrawable(currentDrawable);
          } else {
            nativeView.setBackgroundDrawable(null);
            currentDrawable.setCallback(null);
            if (currentDrawable instanceof TiBackgroundDrawable) {
              ((TiBackgroundDrawable) currentDrawable).releaseDelegate();
            }
          }
        }
      }
      nativeView.setBackgroundDrawable(background);
    }
  }