Пример #1
0
 public void sendError(String error) {
   Log.i(LCAT, "Sending error " + error);
   TiDict event = new TiDict();
   event.put("error", error);
   event.put("source", proxy);
   fireCallback(ON_ERROR, new Object[] {event});
 }
 public void fireScroll(int to) {
   if (hasListeners(EVENT_SCROLL)) {
     TiDict options = new TiDict();
     options.put("index", to);
     options.put("view", this);
     options.put("currentPage", getView().getCurrentPage());
     TiEventHelper.fireViewEvent(this, EVENT_SCROLL, options);
   }
 }
Пример #3
0
  public void onTextChanged(CharSequence s, int start, int before, int count) {
    String value = tv.getText().toString();
    TiDict data = new TiDict();
    data.put("value", value);

    proxy.internalSetDynamicValue("value", value, false);
    proxy.fireEvent("change", data);
  }
Пример #4
0
  public boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent) {
    String value = tv.getText().toString();
    TiDict data = new TiDict();
    data.put("value", value);

    proxy.internalSetDynamicValue("value", value, false);
    proxy.fireEvent("return", data);

    Boolean enableReturnKey = (Boolean) proxy.getDynamicValue("enableReturnKey");
    if (enableReturnKey != null && enableReturnKey && v.getText().length() == 0) {
      return true;
    }
    return false;
  }
Пример #5
0
  protected TiDict eventToTiDict(SensorEvent event, long ts) {
    float x = event.values[0];
    float y = event.values[1];
    float z = event.values[2];

    TiDict heading = new TiDict();
    heading.put("type", EVENT_HEADING);
    heading.put("timestamp", ts);
    heading.put("x", x);
    heading.put("y", y);
    heading.put("z", z);
    heading.put("magneticHeading", x);
    heading.put("accuracy", event.accuracy);
    if (DBG) {
      switch (event.accuracy) {
        case SensorManager.SENSOR_STATUS_UNRELIABLE:
          Log.i(LCAT, "Compass accuracy unreliable");
          break;
        case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
          Log.i(LCAT, "Compass accuracy low");
          break;
        case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
          Log.i(LCAT, "Compass accuracy medium");
          break;
        case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
          Log.i(LCAT, "Compass accuracy high");
          break;
        default:
          Log.w(LCAT, "Unknown compass accuracy value: " + event.accuracy);
      }
    }
    if (geomagneticField != null) {
      float trueHeading = x - geomagneticField.getDeclination();
      if (trueHeading < 0) {
        trueHeading = 360 - trueHeading;
      }

      heading.put("trueHeading", trueHeading);
    }
    TiDict data = new TiDict();
    data.put("heading", heading);

    return data;
  }
Пример #6
0
  @Override
  public void processProperties(TiDict d) {
    TiImageView view = getView();

    if (d.containsKey("images")) {
      Object o = d.get("images");
      if (o instanceof Object[]) {
        setImages((Object[]) o);
      }
    } else if (d.containsKey("url")) {
      Log.w(LCAT, "The url property of ImageView is deprecated, use image instead.");
      if (!d.containsKey("image")) {
        d.put("image", d.get("url"));
      }
    }
    if (d.containsKey("canScale")) {
      view.setCanScaleImage(TiConvert.toBoolean(d, "canScale"));
    }
    if (d.containsKey("enableZoomControls")) {
      view.setEnableZoomControls(TiConvert.toBoolean(d, "enableZoomControls"));
    }
    if (d.containsKey("image")) {
      Object image = d.get("image");
      if (image instanceof String) {
        String imageURL = TiConvert.toString(d, "image");
        if (URLUtil.isNetworkUrl(imageURL)) {
          synchronized (imageTokenGenerator) {
            token = imageTokenGenerator.incrementAndGet();
            getView().setImageDrawable(null);
            new BgImageLoader(getProxy().getTiContext(), null, null, token).load(imageURL);
          }
        } else {
          setImage(createBitmap(imageURL));
        }
      } else {
        setImage(createBitmap(image));
      }

    } else {
      getProxy().internalSetDynamicValue("image", null, false);
    }

    super.processProperties(d);
  }
Пример #7
0
  protected Object toNative(Object value, Class<?> target) {
    Object o = null;

    if (value instanceof String) {
      o = Context.jsToJava(value, target);
    } else if (value instanceof Double || value instanceof Integer) {
      o = Context.jsToJava(value, target);
    } else if (value instanceof Boolean) {
      o = Context.jsToJava(value, target);
    } else if (value instanceof Function) {
      if (DBG) {
        Log.i(LCAT, "Is a Function");
      }
      o = new KrollCallback(weakKrollContext.get(), this, (Function) value);
    } else if (value == null) {
      o = null;
    } else if (value instanceof Scriptable) {
      Scriptable svalue = (Scriptable) value;
      if (isArrayLike(svalue)) {
        o = toArray(svalue);
      } else if (value instanceof KrollObject) {
        o = ((KrollObject) value).target;
      } else if (svalue.getClassName().equals("Date")) {
        double time = (Double) ScriptableObject.callMethod(svalue, "getTime", new Object[0]);
        o = new Date((long) time);
      } else {
        TiDict args = new TiDict();
        o = args;

        Scriptable so = (Scriptable) value;
        for (Object key : so.getIds()) {
          Object v = so.get((String) key, so);
          v = toNative(v, Object.class);
          //					if (v instanceof Scriptable && isArrayLike((Scriptable) v)) {
          //						v = toArray((Scriptable) v);
          //					}
          if (DBG) {
            Log.i(LCAT, "Key: " + key + " value: " + v + " type: " + v.getClass().getName());
          }
          args.put((String) key, v);
        }
        // Log.w(LCAT, "Unhandled type conversion of Scriptable: value: " + value.toString() + "
        // type: " + value.getClass().getName());
      }
    } else {
      if (value.getClass().isArray()) {
        Object[] values = (Object[]) value;
        Object[] newValues = new Object[values.length];
        for (int i = 0; i < values.length; i++) {
          newValues[i] = toNative(values[i], Object.class);
        }
        o = newValues;
      } else {
        Log.w(
            LCAT,
            "Unhandled type conversion: value: "
                + value.toString()
                + " type: "
                + value.getClass().getName());
      }
    }

    return o;
  }
Пример #8
0
    public String handleResponse(HttpResponse response) throws HttpResponseException, IOException {
      connected = true;
      String clientResponse = null;

      if (client != null) {
        TiHTTPClient c = client.get();
        if (c != null) {
          c.response = response;
          c.setReadyState(READY_STATE_HEADERS_RECEIVED);
          c.setStatus(response.getStatusLine().getStatusCode());
          c.setStatusText(response.getStatusLine().getReasonPhrase());
          c.setReadyState(READY_STATE_LOADING);
        }

        if (DBG) {
          try {
            Log.w(LCAT, "Entity Type: " + response.getEntity().getClass());
            Log.w(LCAT, "Entity Content Type: " + response.getEntity().getContentType().getValue());
            Log.w(LCAT, "Entity isChunked: " + response.getEntity().isChunked());
            Log.w(LCAT, "Entity isStreaming: " + response.getEntity().isStreaming());
          } catch (Throwable t) {
            // Ignore
          }
        }

        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() >= 300) {
          setResponseText(response.getEntity());
          throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
        }

        entity = response.getEntity();
        if (entity.getContentType() != null) {
          contentType = entity.getContentType().getValue();
        }
        KrollCallback onDataStreamCallback = c.getCallback(ON_DATA_STREAM);
        if (onDataStreamCallback != null) {
          is = entity.getContent();
          charset = EntityUtils.getContentCharSet(entity);

          responseData = null;

          if (is != null) {
            final KrollCallback cb = onDataStreamCallback;
            long contentLength = entity.getContentLength();
            if (DBG) {
              Log.d(LCAT, "Content length: " + contentLength);
            }
            int count = 0;
            int totalSize = 0;
            byte[] buf = new byte[4096];
            if (DBG) {
              Log.d(LCAT, "Available: " + is.available());
            }
            if (aborted) {
              if (entity != null) {
                entity.consumeContent();
              }
            } else {
              while ((count = is.read(buf)) != -1) {
                totalSize += count;
                TiDict o = new TiDict();
                o.put("totalCount", contentLength);
                o.put("totalSize", totalSize);
                o.put("size", count);

                byte[] newbuf = new byte[count];
                System.arraycopy(buf, 0, newbuf, 0, count);
                if (responseData == null) {
                  responseData = TiBlob.blobFromData(proxy.getTiContext(), newbuf, contentType);
                } else {
                  responseData.append(TiBlob.blobFromData(proxy.getTiContext(), newbuf));
                }

                TiBlob blob = TiBlob.blobFromData(proxy.getTiContext(), newbuf);
                o.put("blob", blob);
                o.put("progress", ((double) totalSize) / ((double) contentLength));

                cb.callWithProperties(o);
              }
              if (entity != null) {
                try {
                  entity.consumeContent();
                } catch (IOException e) {
                  e.printStackTrace();
                }
              }
            }
          }
        } else {
          setResponseData(entity);
        }
      }
      return clientResponse;
    }
Пример #9
0
 private void fireChange(int index) {
   TiDict data = new TiDict();
   data.put("index", index);
   proxy.fireEvent("change", data);
 }
Пример #10
0
 private void fireLoad(String state) {
   TiDict data = new TiDict();
   data.put("state", state);
   proxy.fireEvent("load", data);
 }
Пример #11
0
 @Override
 protected TiDict getFocusEventObject(boolean hasFocus) {
   TiDict event = new TiDict();
   event.put("value", tv.getText().toString());
   return event;
 }