示例#1
0
  private void initializeBorder(KrollDict d, Integer bgColor) {
    if (d.containsKey(TiC.PROPERTY_BORDER_RADIUS)
        || d.containsKey(TiC.PROPERTY_BORDER_COLOR)
        || d.containsKey(TiC.PROPERTY_BORDER_WIDTH)) {

      if (nativeView != null) {
        if (background == null) {
          applyCustomBackground();
        }

        if (background.getBorder() == null) {
          background.setBorder(new TiBackgroundDrawable.Border());
        }

        TiBackgroundDrawable.Border border = background.getBorder();

        if (d.containsKey(TiC.PROPERTY_BORDER_RADIUS)) {
          border.setRadius(TiConvert.toFloat(d, TiC.PROPERTY_BORDER_RADIUS));
        }
        if (d.containsKey(TiC.PROPERTY_BORDER_COLOR) || d.containsKey(TiC.PROPERTY_BORDER_WIDTH)) {
          if (d.containsKey(TiC.PROPERTY_BORDER_COLOR)) {
            border.setColor(TiConvert.toColor(d, TiC.PROPERTY_BORDER_COLOR));
          } else {
            if (bgColor != null) {
              border.setColor(bgColor);
            }
          }
          if (d.containsKey(TiC.PROPERTY_BORDER_WIDTH)) {
            border.setWidth(TiConvert.toFloat(d, TiC.PROPERTY_BORDER_WIDTH));
          }
        }
        // applyCustomBackground();
      }
    }
  }
示例#2
0
  private void handleBorderProperty(String property, Object value) {
    if (background.getBorder() == null) {
      background.setBorder(new TiBackgroundDrawable.Border());
    }
    TiBackgroundDrawable.Border border = background.getBorder();

    if (property.equals(TiC.PROPERTY_BORDER_COLOR)) {
      border.setColor(TiConvert.toColor(value.toString()));
    } else if (property.equals(TiC.PROPERTY_BORDER_RADIUS)) {
      border.setRadius(TiConvert.toFloat(value));
    } else if (property.equals(TiC.PROPERTY_BORDER_WIDTH)) {
      border.setWidth(TiConvert.toFloat(value));
    }
    applyCustomBackground();
  }
示例#3
0
 public void release() {
   if (DBG) {
     Log.d(LCAT, "Releasing: " + this);
   }
   View nv = getNativeView();
   if (nv != null) {
     if (nv instanceof ViewGroup) {
       ViewGroup vg = (ViewGroup) nv;
       if (DBG) {
         Log.d(LCAT, "Group has: " + vg.getChildCount());
       }
       if (!(vg instanceof AdapterView<?>)) {
         vg.removeAllViews();
       }
     }
     Drawable d = nv.getBackground();
     if (d != null) {
       nv.setBackgroundDrawable(null);
       d.setCallback(null);
       if (d instanceof TiBackgroundDrawable) {
         ((TiBackgroundDrawable) d).releaseDelegate();
       }
       d = null;
     }
     nativeView = null;
     if (proxy != null) {
       proxy.setModelListener(null);
     }
   }
 }
示例#4
0
  private void handleBorderProperty(String property, Object value) {
    if (background.getBorder() == null) {
      background.setBorder(new TiBackgroundDrawable.Border());
    }
    TiBackgroundDrawable.Border border = background.getBorder();

    if (property.equals(TiC.PROPERTY_BORDER_COLOR)) {
      border.setColor(TiConvert.toColor(value.toString()));
    } else if (property.equals(TiC.PROPERTY_BORDER_RADIUS)) {
      float radius = TiConvert.toFloat(value);
      if (radius > 0f && HONEYCOMB_OR_GREATER) {
        disableHWAcceleration();
      }
      border.setRadius(radius);
    } else if (property.equals(TiC.PROPERTY_BORDER_WIDTH)) {
      border.setWidth(TiConvert.toFloat(value));
    }
    applyCustomBackground();
  }
示例#5
0
  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);
    }
  }
示例#6
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);
    }
  }
示例#7
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);
    }
  }
示例#8
0
  public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {
    if (key.equals(TiC.PROPERTY_LEFT)) {
      if (newValue != null) {
        layoutParams.optionLeft =
            TiConvert.toTiDimension(TiConvert.toString(newValue), TiDimension.TYPE_LEFT);
      } else {
        layoutParams.optionLeft = null;
      }
      layoutNativeView();
    } else if (key.equals(TiC.PROPERTY_TOP)) {
      if (newValue != null) {
        layoutParams.optionTop =
            TiConvert.toTiDimension(TiConvert.toString(newValue), TiDimension.TYPE_TOP);
      } else {
        layoutParams.optionTop = null;
      }
      layoutNativeView();
    } else if (key.equals(TiC.PROPERTY_CENTER)) {
      TiConvert.updateLayoutCenter(newValue, layoutParams);
      layoutNativeView();
    } else if (key.equals(TiC.PROPERTY_RIGHT)) {
      if (newValue != null) {
        layoutParams.optionRight =
            TiConvert.toTiDimension(TiConvert.toString(newValue), TiDimension.TYPE_RIGHT);
      } else {
        layoutParams.optionRight = null;
      }
      layoutNativeView();
    } else if (key.equals(TiC.PROPERTY_BOTTOM)) {
      if (newValue != null) {
        layoutParams.optionBottom =
            TiConvert.toTiDimension(TiConvert.toString(newValue), TiDimension.TYPE_BOTTOM);
      } else {
        layoutParams.optionBottom = null;
      }
      layoutNativeView();
    } else if (key.equals(TiC.PROPERTY_SIZE)) {
      if (newValue instanceof HashMap) {
        HashMap<String, Object> d = (HashMap) newValue;
        propertyChanged(TiC.PROPERTY_WIDTH, oldValue, d.get(TiC.PROPERTY_WIDTH), proxy);
        propertyChanged(TiC.PROPERTY_HEIGHT, oldValue, d.get(TiC.PROPERTY_HEIGHT), proxy);
      } else if (newValue != null) {
        Log.w(
            LCAT,
            "Unsupported property type ("
                + (newValue.getClass().getSimpleName())
                + ") for key: "
                + key
                + ". Must be an object/dictionary");
      }
    } else if (key.equals(TiC.PROPERTY_HEIGHT)) {
      if (newValue != null) {
        if (!newValue.equals(TiC.SIZE_AUTO)) {
          layoutParams.optionHeight =
              TiConvert.toTiDimension(TiConvert.toString(newValue), TiDimension.TYPE_HEIGHT);
          layoutParams.autoHeight = false;
        } else {
          layoutParams.optionHeight = null;
          layoutParams.autoHeight = true;
        }
      } else {
        layoutParams.optionHeight = null;
      }
      layoutNativeView();
    } else if (key.equals(TiC.PROPERTY_WIDTH)) {
      if (newValue != null) {
        if (!newValue.equals(TiC.SIZE_AUTO)) {
          layoutParams.optionWidth =
              TiConvert.toTiDimension(TiConvert.toString(newValue), TiDimension.TYPE_WIDTH);
          layoutParams.autoWidth = false;
        } else {
          layoutParams.optionWidth = null;
          layoutParams.autoWidth = true;
        }
      } else {
        layoutParams.optionWidth = null;
      }
      layoutNativeView();
    } else if (key.equals(TiC.PROPERTY_ZINDEX)) {
      if (newValue != null) {
        layoutParams.optionZIndex = TiConvert.toInt(newValue);
      } else {
        layoutParams.optionZIndex = 0;
      }
      layoutNativeView(true);
    } else if (key.equals(TiC.PROPERTY_FOCUSABLE)) {
      boolean focusable = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_FOCUSABLE));
      nativeView.setFocusable(focusable);
      if (focusable) {
        registerForKeyClick(nativeView);
      } else {
        // nativeView.setOnClickListener(null); // ? mistake? I assume OnKeyListener was meant
        nativeView.setOnKeyListener(null);
      }
    } else if (key.equals(TiC.PROPERTY_TOUCH_ENABLED)) {
      doSetClickable(TiConvert.toBoolean(newValue));
    } else if (key.equals(TiC.PROPERTY_VISIBLE)) {
      nativeView.setVisibility(TiConvert.toBoolean(newValue) ? View.VISIBLE : View.INVISIBLE);
    } else if (key.equals(TiC.PROPERTY_ENABLED)) {
      nativeView.setEnabled(TiConvert.toBoolean(newValue));
    } else if (key.startsWith(TiC.PROPERTY_BACKGROUND_PADDING)) {
      Log.i(LCAT, key + " not yet implemented.");
    } else if (key.equals(TiC.PROPERTY_OPACITY)
        || key.startsWith(TiC.PROPERTY_BACKGROUND_PREFIX)
        || key.startsWith(TiC.PROPERTY_BORDER_PREFIX)) {
      // Update first before querying.
      proxy.setProperty(key, newValue);

      KrollDict d = proxy.getProperties();

      boolean hasImage = hasImage(d);
      boolean hasColorState = hasColorState(d);
      boolean hasBorder = hasBorder(d);

      boolean requiresCustomBackground = hasImage || hasColorState || hasBorder;

      if (!requiresCustomBackground) {
        if (background != null) {
          background.releaseDelegate();
          background.setCallback(null);
          background = null;
        }

        if (d.containsKeyAndNotNull(TiC.PROPERTY_BACKGROUND_COLOR)) {
          Integer bgColor = TiConvert.toColor(d, TiC.PROPERTY_BACKGROUND_COLOR);
          if (nativeView != null) {
            nativeView.setBackgroundColor(bgColor);
            nativeView.postInvalidate();
          }
        } else {
          if (key.equals(TiC.PROPERTY_OPACITY)) {
            setOpacity(TiConvert.toFloat(newValue));
          }
          if (nativeView != null) {
            nativeView.setBackgroundDrawable(null);
            nativeView.postInvalidate();
          }
        }
      } else {
        boolean newBackground = background == null;
        if (newBackground) {
          background = new TiBackgroundDrawable();
        }

        Integer bgColor = null;

        if (!hasColorState) {
          if (d.get(TiC.PROPERTY_BACKGROUND_COLOR) != null) {
            bgColor = TiConvert.toColor(d, TiC.PROPERTY_BACKGROUND_COLOR);
            if (newBackground
                || (key.equals(TiC.PROPERTY_OPACITY)
                    || key.equals(TiC.PROPERTY_BACKGROUND_COLOR))) {
              background.setBackgroundColor(bgColor);
            }
          }
        }

        if (hasImage || hasColorState) {
          if (newBackground || key.startsWith(TiC.PROPERTY_BACKGROUND_PREFIX)) {
            handleBackgroundImage(d);
          }
        }

        if (hasBorder) {
          if (newBackground) {
            initializeBorder(d, bgColor);
          } else if (key.startsWith(TiC.PROPERTY_BORDER_PREFIX)) {
            handleBorderProperty(key, newValue);
          }
        }
        applyCustomBackground();
      }
      if (nativeView != null) {
        nativeView.postInvalidate();
      }
    } else if (key.equals(TiC.PROPERTY_SOFT_KEYBOARD_ON_FOCUS)) {
      Log.w(
          LCAT,
          "Focus state changed to "
              + TiConvert.toString(newValue)
              + " not honored until next focus event.");
    } else if (key.equals(TiC.PROPERTY_TRANSFORM)) {
      if (nativeView != null) {
        applyTransform((Ti2DMatrix) newValue);
      }
    } else if (key.equals(TiC.PROPERTY_KEEP_SCREEN_ON)) {
      if (nativeView != null) {
        nativeView.setKeepScreenOn(TiConvert.toBoolean(newValue));
      }
    } else {
      TiViewProxy viewProxy = getProxy();
      if (viewProxy != null && viewProxy.isLocalizedTextId(key)) {
        viewProxy.setLocalizedText(key, TiConvert.toString(newValue));
      } else {
        if (DBG) {
          Log.d(LCAT, "Unhandled property key: " + key);
        }
      }
    }
  }