예제 #1
0
  @Kroll.getProperty
  @Kroll.method
  public Object getWidth() {
    if (hasProperty(TiC.PROPERTY_WIDTH)) {
      return getProperty(TiC.PROPERTY_WIDTH);
    }

    KrollDict size = getSize();
    return size.getInt(TiC.PROPERTY_WIDTH);
  }
예제 #2
0
  @Kroll.getProperty
  @Kroll.method
  public Object getHeight() {
    if (hasProperty(TiC.PROPERTY_HEIGHT)) {
      return getProperty(TiC.PROPERTY_HEIGHT);
    }

    KrollDict size = getSize();
    return size.getInt(TiC.PROPERTY_HEIGHT);
  }
 private Calendar getMinuteBasedCalendar(KrollDict args) {
   int interval = args.getInt("minute");
   Calendar cal = Calendar.getInstance();
   cal.add(Calendar.MINUTE, interval);
   return cal;
 }
 private Calendar getSecondBasedCalendar(KrollDict args) {
   int interval = args.getInt("second");
   Calendar cal = Calendar.getInstance();
   cal.add(Calendar.SECOND, interval);
   return cal;
 }
  @Override
  public boolean handleMessage(Message msg) {
    switch (msg.what) {
      case MSG_SET_ITEMS:
        {
          AsyncResult result = (AsyncResult) msg.obj;
          handleSetItems(result.getArg());
          result.setResult(null);
          return true;
        }

      case MSG_GET_ITEMS:
        {
          AsyncResult result = (AsyncResult) msg.obj;
          result.setResult(itemProperties.toArray());
          return true;
        }

      case MSG_APPEND_ITEMS:
        {
          AsyncResult result = (AsyncResult) msg.obj;
          handleAppendItems(result.getArg());
          result.setResult(null);
          return true;
        }

      case MSG_INSERT_ITEMS_AT:
        {
          AsyncResult result = (AsyncResult) msg.obj;
          KrollDict data = (KrollDict) result.getArg();
          int index = data.getInt(TiC.EVENT_PROPERTY_INDEX);
          handleInsertItemsAt(index, data.get(TiC.PROPERTY_DATA));
          result.setResult(null);
          return true;
        }

      case MSG_DELETE_ITEMS_AT:
        {
          AsyncResult result = (AsyncResult) msg.obj;
          KrollDict data = (KrollDict) result.getArg();
          int index = data.getInt(TiC.EVENT_PROPERTY_INDEX);
          int count = data.getInt(TiC.PROPERTY_COUNT);
          handleDeleteItemsAt(index, count);
          result.setResult(null);
          return true;
        }

      case MSG_REPLACE_ITEMS_AT:
        {
          AsyncResult result = (AsyncResult) msg.obj;
          KrollDict data = (KrollDict) result.getArg();
          int index = data.getInt(TiC.EVENT_PROPERTY_INDEX);
          int count = data.getInt(TiC.PROPERTY_COUNT);
          handleReplaceItemsAt(index, count, data.get(TiC.PROPERTY_DATA));
          result.setResult(null);
          return true;
        }

      case MSG_GET_ITEM_AT:
        {
          AsyncResult result = (AsyncResult) msg.obj;
          KrollDict item = handleGetItemAt(TiConvert.toInt(result.getArg()));
          result.setResult(item);
          return true;
        }

      case MSG_UPDATE_ITEM_AT:
        {
          AsyncResult result = (AsyncResult) msg.obj;
          KrollDict data = (KrollDict) result.getArg();
          int index = data.getInt(TiC.EVENT_PROPERTY_INDEX);
          handleUpdateItemAt(index, data.get(TiC.PROPERTY_DATA));
          result.setResult(null);
          return true;
        }

      default:
        {
          return super.handleMessage(msg);
        }
    }
  }
  // ----------- Private Methods ----------//
  private LinkProperties createLinkPropertiesDict(KrollDict options, KrollDict controlParams) {
    Log.d(LCAT, "start createLinkPropertiesDict");
    LinkProperties linkProperties = new LinkProperties();

    if (options.containsKey("feature")) {
      linkProperties.setFeature(options.getString("feature"));
    }
    if (options.containsKey("alias")) {
      linkProperties.setAlias(options.getString("alias"));
    }
    if (options.containsKey("channel")) {
      linkProperties.setChannel(options.getString("channel"));
    }
    if (options.containsKey("stage")) {
      linkProperties.setStage(options.getString("stage"));
    }
    if (options.containsKey("duration")) {
      linkProperties.setDuration(options.getInt("duration"));
    }

    if (options.containsKey("tags")) {
      ArrayList<String> tags = (ArrayList<String>) options.get("tags");
      for (String tag : tags) {
        linkProperties.addTag(tag);
      }
    }

    if (controlParams.containsKey("$fallback_url")) {
      Log.d(LCAT, "addControlParameter $fallback_url");
      linkProperties.addControlParameter("$fallback_url", controlParams.getString("$fallback_url"));
    }
    if (controlParams.containsKey("$desktop_url")) {
      Log.d(LCAT, "addControlParameter $desktop_url");
      linkProperties.addControlParameter("$desktop_url", controlParams.getString("$desktop_url"));
    }
    if (controlParams.containsKey("$android_url")) {
      Log.d(LCAT, "addControlParameter $android_url");
      linkProperties.addControlParameter("$android_url", controlParams.getString("$android_url"));
    }
    if (controlParams.containsKey("$ios_url")) {
      Log.d(LCAT, "addControlParameter $ios_url");
      linkProperties.addControlParameter("$ios_url", controlParams.getString("$ios_url"));
    }
    if (controlParams.containsKey("$ipad_url")) {
      Log.d(LCAT, "addControlParameter $ipad_url");
      linkProperties.addControlParameter("$ipad_url", controlParams.getString("$ipad_url"));
    }
    if (controlParams.containsKey("$fire_url")) {
      Log.d(LCAT, "addControlParameter $fire_url");
      linkProperties.addControlParameter("$fire_url", controlParams.getString("$fire_url"));
    }
    if (controlParams.containsKey("$blackberry_url")) {
      Log.d(LCAT, "addControlParameter $blackberry_url");
      linkProperties.addControlParameter(
          "$blackberry_url", controlParams.getString("$blackberry_url"));
    }
    if (controlParams.containsKey("$windows_phone_url")) {
      Log.d(LCAT, "addControlParameter $windows_phone_url");
      linkProperties.addControlParameter(
          "$windows_phone_url", controlParams.getString("$windows_phone_url"));
    }

    return linkProperties;
  }
  @Kroll.method
  public void generateShortUrl(KrollDict options, KrollDict controlParams) {
    Log.d(LCAT, "start generateShortUrl");
    LinkProperties linkProperties = new LinkProperties();

    if (options.containsKey("feature")) {
      linkProperties.setFeature(options.getString("feature"));
    }
    if (options.containsKey("alias")) {
      linkProperties.setAlias(options.getString("alias"));
    }
    if (options.containsKey("channel")) {
      linkProperties.setChannel(options.getString("channel"));
    }
    if (options.containsKey("stage")) {
      linkProperties.setStage(options.getString("stage"));
    }
    if (options.containsKey("duration")) {
      linkProperties.setDuration(options.getInt("duration"));
    }

    if (options.containsKey("tags")) {
      ArrayList<String> tags = (ArrayList<String>) options.get("tags");
      for (String tag : tags) {
        linkProperties.addTag(tag);
      }
    }

    if (controlParams.containsKey("$fallback_url")) {
      Log.d(LCAT, "addControlParameter $fallback_url");
      linkProperties.addControlParameter("$fallback_url", controlParams.getString("$fallback_url"));
    }
    if (controlParams.containsKey("$desktop_url")) {
      Log.d(LCAT, "addControlParameter $desktop_url");
      linkProperties.addControlParameter("$desktop_url", controlParams.getString("$desktop_url"));
    }
    if (controlParams.containsKey("$android_url")) {
      Log.d(LCAT, "addControlParameter $android_url");
      linkProperties.addControlParameter("$android_url", controlParams.getString("$android_url"));
    }
    if (controlParams.containsKey("$ios_url")) {
      Log.d(LCAT, "addControlParameter $ios_url");
      linkProperties.addControlParameter("$ios_url", controlParams.getString("$ios_url"));
    }
    if (controlParams.containsKey("$ipad_url")) {
      Log.d(LCAT, "addControlParameter $ipad_url");
      linkProperties.addControlParameter("$ipad_url", controlParams.getString("$ipad_url"));
    }
    if (controlParams.containsKey("$fire_url")) {
      Log.d(LCAT, "addControlParameter $fire_url");
      linkProperties.addControlParameter("$fire_url", controlParams.getString("$fire_url"));
    }
    if (controlParams.containsKey("$blackberry_url")) {
      Log.d(LCAT, "addControlParameter $blackberry_url");
      linkProperties.addControlParameter(
          "$blackberry_url", controlParams.getString("$blackberry_url"));
    }
    if (controlParams.containsKey("$windows_phone_url")) {
      Log.d(LCAT, "addControlParameter $windows_phone_url");
      linkProperties.addControlParameter(
          "$windows_phone_url", controlParams.getString("$windows_phone_url"));
    }

    final Activity activity = this.getActivity();
    branchUniversalObject.generateShortUrl(
        activity, linkProperties, new GenerateShortUrlListener());
  }
예제 #8
0
  @Override
  public void processProperties(KrollDict d) {
    super.processProperties(d);

    boolean valueExistsInProxy = false;
    Calendar calendar = Calendar.getInstance();
    DatePicker picker = (DatePicker) getNativeView();

    if (d.containsKey("value")) {
      calendar.setTime((Date) d.get("value"));
      valueExistsInProxy = true;
    }
    if (d.containsKey(TiC.PROPERTY_MIN_DATE)) {
      Calendar minDateCalendar = Calendar.getInstance();
      minDateCalendar.setTime((Date) d.get(TiC.PROPERTY_MIN_DATE));
      minDateCalendar.set(Calendar.HOUR_OF_DAY, 0);
      minDateCalendar.set(Calendar.MINUTE, 0);
      minDateCalendar.set(Calendar.SECOND, 0);
      minDateCalendar.set(Calendar.MILLISECOND, 0);

      this.minDate = minDateCalendar.getTime();
      picker.setMinDate(minDateCalendar.getTimeInMillis());
    }
    if (d.containsKey(TiC.PROPERTY_CALENDAR_VIEW_SHOWN)) {
      setCalendarView(TiConvert.toBoolean(d, TiC.PROPERTY_CALENDAR_VIEW_SHOWN));
    }
    if (d.containsKey(TiC.PROPERTY_MAX_DATE)) {
      Calendar maxDateCalendar = Calendar.getInstance();
      maxDateCalendar.setTime((Date) d.get(TiC.PROPERTY_MAX_DATE));
      maxDateCalendar.set(Calendar.HOUR_OF_DAY, 0);
      maxDateCalendar.set(Calendar.MINUTE, 0);
      maxDateCalendar.set(Calendar.SECOND, 0);
      maxDateCalendar.set(Calendar.MILLISECOND, 0);

      this.maxDate = maxDateCalendar.getTime();
      picker.setMaxDate(maxDateCalendar.getTimeInMillis());
    }
    if (d.containsKey("minuteInterval")) {
      int mi = d.getInt("minuteInterval");
      if (mi >= 1 && mi <= 30 && mi % 60 == 0) {
        this.minuteInterval = mi;
      }
    }
    suppressChangeEvent = true;
    currentYear = calendar.get(Calendar.YEAR);
    currentMonth = calendar.get(Calendar.MONTH);
    currentDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
    picker.init(currentYear, currentMonth, currentDayOfMonth, this);
    suppressChangeEvent = false;

    if (!valueExistsInProxy) {
      proxy.setProperty("value", calendar.getTime());
    }

    // iPhone ignores both values if max <= min
    if (minDate != null && maxDate != null) {
      if (maxDate.compareTo(minDate) <= 0) {
        Log.w(TAG, "maxDate is less or equal minDate, ignoring both settings.");
        minDate = null;
        maxDate = null;
      }
    }
  }
예제 #9
0
  public static TiAnnotation fromDict(final KrollDict dict) {
    TiAnnotation a = null;
    if (dict.containsKeyAndNotNull(TiC.PROPERTY_ID)) {
      a = new TiAnnotation(dict.getString(TiC.PROPERTY_ID));
    } else {
      a = new TiAnnotation();
      dict.put(TiC.PROPERTY_ID, a.getId());
    }

    if (dict.containsKeyAndNotNull(TiC.PROPERTY_TITLE)) {
      a.setTitle(dict.getString(TiC.PROPERTY_TITLE));
    }
    if (dict.containsKeyAndNotNull(TiC.PROPERTY_SUBTITLE)) {
      a.setSubtitle(dict.getString(TiC.PROPERTY_SUBTITLE));
    }

    if (dict.containsKeyAndNotNull(TiC.PROPERTY_LATITUDE)) {
      a.setLatitude(dict.getDouble(TiC.PROPERTY_LATITUDE));
    }
    if (dict.containsKeyAndNotNull(TiC.PROPERTY_LONGITUDE)) {
      a.setLongitude(dict.getDouble(TiC.PROPERTY_LONGITUDE));
    }

    if (dict.containsKeyAndNotNull(TiC.PROPERTY_IMAGE)
        || dict.containsKeyAndNotNull(TiC.PROPERTY_PIN_IMAGE)) {
      a.setImage(dict.getString(TiC.PROPERTY_IMAGE));
      if (a.getImage() == null) {
        a.setImage(dict.getString(TiC.PROPERTY_PIN_IMAGE));
      }
    }

    if (dict.containsKeyAndNotNull(TiC.PROPERTY_PINCOLOR)) {
      Object pinColor = dict.get(TiC.PROPERTY_PINCOLOR);
      if (pinColor instanceof String) {
        a.setPinColor((String) pinColor);
      } else {
        a.setPinColor(dict.getInt(TiC.PROPERTY_PINCOLOR));
      }
    }

    if (dict.containsKeyAndNotNull(TiC.PROPERTY_LEFT_BUTTON)) {
      a.setLeftButton(TiConvert.toString(dict, TiC.PROPERTY_LEFT_BUTTON));
    }
    if (dict.containsKeyAndNotNull(TiC.PROPERTY_RIGHT_BUTTON)) {
      a.setRightButton(TiConvert.toString(dict, TiC.PROPERTY_RIGHT_BUTTON));
    }

    if (dict.containsKeyAndNotNull(TiC.PROPERTY_LEFT_VIEW)) {
      Object leftView = dict.get(TiC.PROPERTY_LEFT_VIEW);
      if (leftView instanceof TiViewProxy) {
        a.setLeftView((TiViewProxy) leftView);
      }
    }
    if (dict.containsKeyAndNotNull(TiC.PROPERTY_RIGHT_VIEW)) {
      Object rightView = dict.get(TiC.PROPERTY_RIGHT_VIEW);
      if (rightView instanceof TiViewProxy) {
        a.setRightView((TiViewProxy) rightView);
      }
    }

    if (dict.containsKeyAndNotNull(TiC.PROPERTY_ANIMATE)) {
      a.setAnimate(dict.getBoolean(TiC.PROPERTY_ANIMATE));
    } else {
      a.setAnimate(Boolean.FALSE);
    }

    if (dict.containsKeyAndNotNull(TiC.PROPERTY_CENTER)) {
      a.setCenter(dict.getBoolean(TiC.PROPERTY_CENTER));
    } else {
      a.setCenter(Boolean.TRUE);
    }
    return a;
  }