@Override
 protected KrollDict getLangConversionTable() {
   KrollDict table = new KrollDict();
   table.put("prompt", "promptid");
   table.put("hintText", "hinttextid");
   return table;
 }
Esempio n. 2
0
  @Override
  public boolean onInfo(MediaPlayer mp, int what, int extra) {
    String msg = "Unknown media issue.";

    switch (what) {
      case MediaPlayer.MEDIA_INFO_BAD_INTERLEAVING:
        msg = "Stream not interleaved or interleaved improperly.";
        break;
      case MediaPlayer.MEDIA_INFO_NOT_SEEKABLE:
        msg = "Stream does not support seeking";
        break;
      case MediaPlayer.MEDIA_INFO_UNKNOWN:
        msg = "Unknown media issue";
        break;
      case MediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING:
        msg = "Video is too complex for decoder, video lagging."; // shouldn't occur, but covering
        // bases.
        break;
    }

    KrollDict data = new KrollDict();
    data.put("code", 0);
    data.put("message", msg);
    proxy.fireEvent(EVENT_ERROR, data);

    return true;
  }
  public void appendExtraEventData(
      TiUIView view, int itemIndex, int sectionIndex, String bindId, String itemId) {
    KrollDict existingData = view.getAdditionalEventData();
    if (existingData == null) {
      existingData = new KrollDict();
      view.setAdditionalEventData(existingData);
    }

    // itemIndex = realItemIndex + header (if exists). We want the real item index.
    if (headerTitle != null || headerView != null) {
      itemIndex -= 1;
    }

    existingData.put(TiC.PROPERTY_SECTION, this);
    existingData.put(TiC.PROPERTY_SECTION_INDEX, sectionIndex);
    existingData.put(TiC.PROPERTY_ITEM_INDEX, itemIndex);

    if (!bindId.startsWith(TiListViewTemplate.GENERATED_BINDING)
        && !bindId.equals(TiC.PROPERTY_PROPERTIES)) {
      existingData.put(TiC.PROPERTY_BIND_ID, bindId);
    } else if (existingData.containsKey(TiC.PROPERTY_BIND_ID)) {
      existingData.remove(TiC.PROPERTY_BIND_ID);
    }

    if (itemId != null) {
      existingData.put(TiC.PROPERTY_ITEM_ID, itemId);
    } else if (existingData.containsKey(TiC.PROPERTY_ITEM_ID)) {
      existingData.remove(TiC.PROPERTY_ITEM_ID);
    }
  }
Esempio n. 4
0
 private KrollDict dictFromEvent(MotionEvent e) {
   KrollDict data = new KrollDict();
   data.put(TiC.EVENT_PROPERTY_X, (double) e.getX());
   data.put(TiC.EVENT_PROPERTY_Y, (double) e.getY());
   data.put(TiC.EVENT_PROPERTY_SOURCE, proxy);
   return data;
 }
Esempio n. 5
0
  public static KrollDict createDictForImage(TiBlob imageData, String mimeType) {
    KrollDict d = new KrollDict();
    d.putCodeAndMessage(NO_ERROR, null);

    int width = -1;
    int height = -1;

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inJustDecodeBounds = true;

    // We only need the ContentResolver so it doesn't matter if the root or current activity is used
    // for
    // accessing it
    BitmapFactory.decodeStream(imageData.getInputStream(), null, opts);

    width = opts.outWidth;
    height = opts.outHeight;

    d.put("x", 0);
    d.put("y", 0);
    d.put("width", width);
    d.put("height", height);

    KrollDict cropRect = new KrollDict();
    cropRect.put("x", 0);
    cropRect.put("y", 0);
    cropRect.put("width", width);
    cropRect.put("height", height);
    d.put("cropRect", cropRect);

    d.put("mediaType", MEDIA_TYPE_PHOTO);
    d.put("media", imageData);

    return d;
  }
  public boolean dispatchEvent(String eventName, KrollDict data) {
    boolean dispatched = false;
    if (eventName != null) {
      Map<Integer, KrollListener> listeners = eventListeners.get(eventName);
      if (listeners != null) {
        if (data == null) {
          data = new KrollDict();
        }
        if (!data.containsKey("type")) {
          data.put("type", eventName);
        }

        Set<Entry<Integer, KrollListener>> listenerSet = listeners.entrySet();
        synchronized (eventListeners) {
          for (Entry<Integer, KrollListener> entry : listenerSet) {
            KrollListener listener = entry.getValue();
            if (proxy == null || (proxy != null && listener.isSameProxy(proxy))) {
              boolean invoked = false;
              try {
                if (listener.weakProxy.get() != null) {
                  if (!data.containsKey("source")) {
                    data.put("source", listener.weakProxy.get());
                  }
                  invoked = listener.invoke(eventName, data);
                }
              } catch (Exception e) {
                Log.e(
                    TAG,
                    "Error invoking listener with id "
                        + entry.getKey()
                        + " on eventName '"
                        + eventName
                        + "'",
                    e);
              }
              dispatched = dispatched || invoked;
            }
          }
        }
      } else {
        if (TRACE) {
          Log.w(TAG, "No listeners for eventName: " + eventName);
        }
      }
    } else {
      throw new IllegalStateException("dispatchEvent expects a non-null eventName");
    }
    return dispatched;
  }
Esempio n. 7
0
 private KrollDict dictFromEvent(KrollDict dictToCopy) {
   KrollDict data = new KrollDict();
   if (dictToCopy.containsKey(TiC.EVENT_PROPERTY_X)) {
     data.put(TiC.EVENT_PROPERTY_X, dictToCopy.get(TiC.EVENT_PROPERTY_X));
   } else {
     data.put(TiC.EVENT_PROPERTY_X, (double) 0);
   }
   if (dictToCopy.containsKey(TiC.EVENT_PROPERTY_Y)) {
     data.put(TiC.EVENT_PROPERTY_Y, dictToCopy.get(TiC.EVENT_PROPERTY_Y));
   } else {
     data.put(TiC.EVENT_PROPERTY_Y, (double) 0);
   }
   data.put(TiC.EVENT_PROPERTY_SOURCE, proxy);
   return data;
 }
  @Kroll.method
  public void deleteItemsAt(int index, int count) {
    if (!isIndexValid(index)) {
      return;
    }

    if (TiApplication.isUIThread()) {
      handleDeleteItemsAt(index, count);
    } else {
      KrollDict d = new KrollDict();
      d.put(TiC.EVENT_PROPERTY_INDEX, index);
      d.put(TiC.PROPERTY_COUNT, count);
      TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_DELETE_ITEMS_AT), d);
    }
  }
  @Kroll.method
  public void updateItemAt(int index, Object data) {
    if (!isIndexValid(index) || !(data instanceof HashMap)) {
      return;
    }

    if (TiApplication.isUIThread()) {
      handleUpdateItemAt(index, new Object[] {data});
    } else {
      KrollDict d = new KrollDict();
      d.put(TiC.EVENT_PROPERTY_INDEX, index);
      d.put(TiC.PROPERTY_DATA, new Object[] {data});
      TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_UPDATE_ITEM_AT), d);
    }
  }
 @Override
 public void onLinkCreate(String url, BranchError error) {
   Log.d(LCAT, "inside onLinkCreate");
   BranchUniversalObjectProxy self = BranchUniversalObjectProxy.this;
   KrollDict response = new KrollDict();
   if (error == null) {
     Log.d(LCAT, "link to share: " + url);
     response.put("generatedLink", url);
   } else {
     String errorMessage = error.getMessage();
     Log.d(LCAT, errorMessage);
     response.put("error", errorMessage);
   }
   self.fireEvent("bio:generateShortUrl", response);
 }
  @Kroll.method
  public void insertItemsAt(int index, Object data) {
    if (!isIndexValid(index)) {
      return;
    }

    if (TiApplication.isUIThread()) {
      handleInsertItemsAt(index, data);
    } else {
      KrollDict d = new KrollDict();
      d.put(TiC.PROPERTY_DATA, data);
      d.put(TiC.EVENT_PROPERTY_INDEX, index);
      TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_INSERT_ITEMS_AT), d);
    }
  }
Esempio n. 12
0
  @Override
  public void handleCreationDict(KrollDict options) {
    options = handleStyleOptions(options);
    if (langConversionTable != null) {
      KrollDict foundStrings = new KrollDict();
      for (String key : langConversionTable.keySet()) {
        // if we have it already, ignore
        if (!options.containsKey(key)) {
          String convertKey = (String) langConversionTable.get(key);
          String langKey = (String) options.get(convertKey);
          if (langKey != null) {
            try {
              String localText = getLocalizedText(langKey);
              foundStrings.put(key, localText);
            } catch (TiRHelper.ResourceNotFoundException e) {
              Log.w(LCAT, "Localized text key '" + langKey + "' is invalid.");
            }
          }
        }
      }

      if (!(foundStrings.isEmpty())) {
        extend(foundStrings);
        options.putAll(foundStrings);
      }
    }
    options = handleStyleOptions(options);
    super.handleCreationDict(options);

    // TODO eventManager.addOnEventChangeListener(this);
  }
Esempio n. 13
0
 @Override
 public void onPageStarted(WebView view, String url, Bitmap favicon) {
   super.onPageStarted(view, url, favicon);
   KrollDict data = new KrollDict();
   data.put("url", url);
   webView.getProxy().fireEvent("beforeload", data);
 }
Esempio n. 14
0
  @Override
  public boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent) {
    String value = tv.getText().toString();
    KrollDict data = new KrollDict();
    data.put(TiC.PROPERTY_VALUE, value);

    proxy.setProperty(TiC.PROPERTY_VALUE, value);
    Log.d(
        TAG,
        "ActionID: " + actionId + " KeyEvent: " + (keyEvent != null ? keyEvent.getKeyCode() : null),
        Log.DEBUG_MODE);

    // This is to prevent 'return' event from being fired twice when return key is hit. In other
    // words, when return key is clicked,
    // this callback is triggered twice (except for keys that are mapped to
    // EditorInfo.IME_ACTION_NEXT or EditorInfo.IME_ACTION_DONE). The first check is to deal with
    // those keys - filter out
    // one of the two callbacks, and the next checks deal with 'Next' and 'Done' callbacks,
    // respectively.
    // Refer to TiUIText.handleReturnKeyType(int) for a list of return keys that are mapped to
    // EditorInfo.IME_ACTION_NEXT and EditorInfo.IME_ACTION_DONE.
    if ((actionId == EditorInfo.IME_NULL && keyEvent != null)
        || actionId == EditorInfo.IME_ACTION_NEXT
        || actionId == EditorInfo.IME_ACTION_DONE) {
      fireEvent(TiC.EVENT_RETURN, data);
    }

    Boolean enableReturnKey =
        TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_RETURN_KEY));
    if (enableReturnKey != null && enableReturnKey && v.getText().length() == 0) {
      return true;
    }
    return false;
  }
Esempio n. 15
0
  public void onRegistrered(Context context, String registrationId) throws IOException {
    Log.d(LCAT, "Registered: " + registrationId);

    KrollDict data = new KrollDict();
    data.put("registrationId", registrationId);
    C2dmModule.getInstance().fireEvent(REGISTER_EVENT, data);
  }
Esempio n. 16
0
  @Override
  public boolean onError(MediaPlayer mp, int what, int extra) {
    int code = 0;
    String msg = "Unknown media error.";
    if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
      msg = "Media server died";
    }
    release();

    KrollDict data = new KrollDict();
    data.put("code", code);
    data.put("message", msg);
    proxy.fireEvent(EVENT_ERROR, data);

    return true;
  }
Esempio n. 17
0
 /** Always invoked on UI thread. */
 @Override
 protected void onPostExecute(TiBlob blobImage) {
   KrollDict result = new KrollDict();
   if (blobImage != null) {
     result.put("image", blobImage);
   }
   this.callback.callAsync(this.proxy.getKrollObject(), new Object[] {result});
 }
Esempio n. 18
0
 @Override
 public void onPageFinished(WebView view, String url) {
   super.onPageFinished(view, url);
   webView.changeProxyUrl(url);
   KrollDict data = new KrollDict();
   data.put("url", url);
   webView.getProxy().fireEvent("load", data);
 }
 @Override
 public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchError error) {
   Log.d(LCAT, "inside onLinkCreate");
   BranchUniversalObjectProxy self = BranchUniversalObjectProxy.this;
   KrollDict response = new KrollDict();
   if (error == null) {
     response.put("sharedLink", sharedLink);
     response.put("sharedChannel", sharedChannel);
     Log.d(LCAT, "sharedLink: " + sharedLink);
     Log.d(LCAT, "sharedChannel: " + sharedChannel);
   } else {
     String errorMessage = error.getMessage();
     Log.d(LCAT, errorMessage);
     response.put("error", errorMessage);
   }
   self.fireEvent("bio:shareLinkResponse", response);
 }
Esempio n. 20
0
  @Override
  public void onError(Context context, String errorId) {
    Log.e(LCAT, "Error: " + errorId);

    KrollDict data = new KrollDict();
    data.put("errorId", errorId);
    C2dmModule.getInstance().fireEvent(ERROR_EVENT, data);
  }
Esempio n. 21
0
  @Override
  public void onTextReceived(LinphoneAddress from, String message) {
    //		Object[] obj = {from.toString(), message};
    Log.d("ALModule", "onTextReceived");
    Log.d("ALModule", from.toString());
    Log.d("ALModule", message);

    JSONObject json;
    String type = null;

    try {
      json = new JSONObject(message);
      type = json.getString("type");
    } catch (JSONException e) {
      //	e.printStackTrace();
      json = null;
      type = null;
    }

    if (json != null && type != null) {
      if (type.equals("invite") == true) {
        try {

          String fromUrl = json.getString("fromUrl");
          String fromName = json.getString("fromName");
          String callType = json.getString("callType");

          postInfo(fromUrl, fromName, callType);
        } catch (JSONException e) {
          e.printStackTrace();
        }

        return;
      }
    }

    //
    ALModuleProxy alModuleProxy = ALModuleProxy.getInstance();
    if (alModuleProxy != null) {
      KrollDict dict = new KrollDict();
      dict.put("from", from.toString());
      dict.put("message", message);
      alModuleProxy.fireEvent(dict, "TextReceived");
    }
  }
    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
      super.onScrollChanged(l, t, oldl, oldt);

      KrollDict data = new KrollDict();
      data.put("x", l);
      data.put("y", t);
      getProxy().fireEvent("scroll", data);
    }
 @Override
 public void onChannelSelected(String channelName) {
   Log.d(LCAT, "inside onChannelSelected");
   Log.d(LCAT, "channelName: " + channelName);
   BranchUniversalObjectProxy self = BranchUniversalObjectProxy.this;
   KrollDict response = new KrollDict();
   response.put("channelName", channelName);
   self.fireEvent("bio:shareChannelSelected", response);
 }
Esempio n. 24
0
  private void setState(int state) {
    proxy.setProperty("state", state);
    String stateDescription = "";

    switch (state) {
      case STATE_BUFFERING:
        stateDescription = STATE_BUFFERING_DESC;
        break;
      case STATE_INITIALIZED:
        stateDescription = STATE_INITIALIZED_DESC;
        break;
      case STATE_PAUSED:
        stateDescription = STATE_PAUSED_DESC;
        break;
      case STATE_PLAYING:
        stateDescription = STATE_PLAYING_DESC;
        break;
      case STATE_STARTING:
        stateDescription = STATE_STARTING_DESC;
        break;
      case STATE_STOPPED:
        stateDescription = STATE_STOPPED_DESC;
        break;
      case STATE_STOPPING:
        stateDescription = STATE_STOPPING_DESC;
        break;
      case STATE_WAITING_FOR_DATA:
        stateDescription = STATE_WAITING_FOR_DATA_DESC;
        break;
      case STATE_WAITING_FOR_QUEUE:
        stateDescription = STATE_WAITING_FOR_QUEUE_DESC;
        break;
    }

    proxy.setProperty("stateDescription", stateDescription);
    if (DBG) {
      Log.d(LCAT, "Audio state changed: " + stateDescription);
    }

    KrollDict data = new KrollDict();
    data.put("state", state);
    data.put("description", stateDescription);
    proxy.fireEvent(EVENT_CHANGE, data);
  }
Esempio n. 25
0
 public void handleEvent(int id, final boolean isOption) {
   KrollDict data = new KrollDict();
   if (id != -1 && (id & BUTTON_MASK) != 0) {
     data.put(TiC.PROPERTY_BUTTON, true);
     id &= ~BUTTON_MASK;
   } else {
     data.put(TiC.PROPERTY_BUTTON, false);
     // If an option was selected and the user accepted it, update the proxy.
     if (id != -1 && proxy.hasProperty(TiC.PROPERTY_OPTIONS)) {
       proxy.setProperty(TiC.PROPERTY_SELECTED_INDEX, id);
     }
   }
   int realcancelIndex = cancelIndex;
   if (realcancelIndex != -1 && isOption) {
     realcancelIndex += optionsCount;
   }
   data.put(TiC.EVENT_PROPERTY_INDEX, id);
   data.put(TiC.PROPERTY_CANCEL, (id == realcancelIndex));
   fireEvent(TiC.EVENT_CLICK, data, false);
 }
Esempio n. 26
0
  @Override
  protected void onMessage(Context context, Intent intent) {
    Log.d(LCAT, "Message received: " + intent.getExtras().getString("data.message"));

    KrollDict data = new KrollDict();
    for (String key : intent.getExtras().keySet()) {
      String eventKey = key.startsWith("data.") ? key.substring(5) : key;
      data.put(eventKey, intent.getExtras().getString(key));
    }

    C2dmModule.getInstance().fireEvent(MESSAGE_EVENT, data);
  }
Esempio n. 27
0
  @Kroll.method
  public KrollDict generateKeyPair() {
    // generate key pair
    //
    KrollDict arg = new KrollDict();

    try {
      KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
      kpg.initialize(1024);
      KeyPair kp = kpg.genKeyPair();
      publicKey = kp.getPublic();
      privateKey = kp.getPrivate();

      arg.put("privateKey", Base64.encodeToString(privateKey.getEncoded(), Base64.NO_WRAP));
      arg.put("publicKey", Base64.encodeToString(publicKey.getEncoded(), Base64.NO_WRAP));

    } catch (Exception e) {
      Log.e(TAG, "RSA key pair error");
    }

    return arg;
  }
Esempio n. 28
0
  KrollDict createDictForImage(int width, int height, byte[] data) {
    KrollDict d = new KrollDict();

    d.put("x", 0);
    d.put("y", 0);
    d.put("width", width);
    d.put("height", height);

    KrollDict cropRect = new KrollDict();
    cropRect.put("x", 0);
    cropRect.put("y", 0);
    cropRect.put("width", width);
    cropRect.put("height", height);
    d.put("cropRect", cropRect);
    d.put("mediaType", MEDIA_TYPE_PHOTO);
    d.put("media", TiBlob.blobFromData(data, "image/png"));

    return d;
  }
Esempio n. 29
0
 @Override
 public void onTextChanged(CharSequence s, int start, int before, int count) {
   // Since Jelly Bean, pressing the 'return' key won't trigger onEditorAction callback
   // http://stackoverflow.com/questions/11311790/oneditoraction-is-not-called-after-enter-key-has-been-pressed-on-jelly-bean-em
   // So here we need to handle the 'return' key manually
   if (Build.VERSION.SDK_INT >= 16
       && before == 0
       && s.length() > start
       && s.charAt(start) == '\n') {
     // We use the previous value to make it consistent with pre Jelly Bean behavior
     // (onEditorAction is called before
     // onTextChanged.
     String value = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_VALUE));
     KrollDict data = new KrollDict();
     data.put(TiC.PROPERTY_VALUE, value);
     fireEvent(TiC.EVENT_RETURN, data);
   }
   /**
    * There is an Android bug regarding setting filter on EditText that impacts auto completion.
    * Therefore we can't use filters to implement "maxLength" property. Instead we manipulate the
    * text to achieve perfect parity with other platforms. Android bug url for reference:
    * http://code.google.com/p/android/issues/detail?id=35757
    */
   if (maxLength >= 0 && s.length() > maxLength) {
     // Can only set truncated text in afterTextChanged. Otherwise, it will crash.
     return;
   }
   String newText = tv.getText().toString();
   if (!disableChangeEvent
       && (!isTruncatingText
           || (isTruncatingText
               && proxy.shouldFireChange(proxy.getProperty(TiC.PROPERTY_VALUE), newText)))) {
     KrollDict data = new KrollDict();
     data.put(TiC.PROPERTY_VALUE, newText);
     proxy.setProperty(TiC.PROPERTY_VALUE, newText);
     fireEvent(TiC.EVENT_CHANGE, data);
   }
 }
Esempio n. 30
0
 @Kroll.setProperty
 @Kroll.method
 protected KrollDict getSensorInfos(int type) {
   Sensor sensor = sensorManager.getDefaultSensor(type);
   KrollDict data = new KrollDict();
   if (null != sensor) {
     data.put("name", sensor.getName());
     data.put("constant", sensor.getType());
     data.put("version", sensor.getVersion());
     data.put("resolution", sensor.getResolution());
     data.put("power", sensor.getPower());
     data.put("vendor", sensor.getVendor());
     data.put("maximumRange", sensor.getMaximumRange());
     data.put("minDelay", sensor.getMinDelay());
   }
   return data;
 }