Exemplo n.º 1
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);
  }
 @Override
 protected KrollDict getLangConversionTable() {
   KrollDict table = new KrollDict();
   table.put("prompt", "promptid");
   table.put("hintText", "hinttextid");
   return table;
 }
Exemplo n.º 3
0
  @Kroll.method
  public String decode(HashMap args) {
    // decode string back to plain text
    //
    KrollDict arg = new KrollDict(args);
    String txt = arg.getString("cipherText");
    byte[] bytesEncoded = Base64.decode(txt, 0);
    String keyString = arg.getString("privateKey");
    PrivateKey key;

    try {
      byte[] encodedKey = Base64.decode(keyString, 0);
      PKCS8EncodedKeySpec x509KeySpec = new PKCS8EncodedKeySpec(encodedKey);
      KeyFactory keyFact = KeyFactory.getInstance("RSA", "BC");
      key = keyFact.generatePrivate(x509KeySpec);
    } catch (Exception e) {
      return "error key";
    }

    byte[] decodedBytes = null;

    try {
      Cipher c = Cipher.getInstance("RSA");
      c.init(Cipher.DECRYPT_MODE, key);
      decodedBytes = c.doFinal(bytesEncoded);
    } catch (Exception e) {
      Log.e(TAG, "RSA decryption error " + e.toString());
      return "error";
    }
    return new String(decodedBytes);
  }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
  private Bitmap tintImage(Bitmap image, Bitmap image2, KrollDict args) {
    String col = args.optString("color", "");
    String mod1 = args.optString("modeColor", "multiply");
    String mod2 = args.optString("modeImage", "multiply");
    Boolean grad = args.optBoolean("vignette", false);

    if (image != null) {

      Mode filterMode1 = getFilter(mod1);
      Mode filterMode2 = getFilter(mod2);
      int width = image.getWidth();
      int height = image.getHeight();

      Bitmap workingBitmap = Bitmap.createScaledBitmap(image, width, height, true);
      Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
      Canvas canvas = new Canvas(mutableBitmap);

      Bitmap resultBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
      Canvas canvas2 = new Canvas(resultBitmap);

      // add second image
      if (image2 != null) {
        Paint Compose = new Paint();
        Compose.setXfermode(
            new PorterDuffXfermode(filterMode2)); // KAI: fixed error in the original code
        canvas.drawBitmap(image2, 0, 0, Compose);
      }

      Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

      // add color filter
      if (col != "") {
        PorterDuffColorFilter cf =
            new PorterDuffColorFilter(
                Color.parseColor(col), filterMode1); // KAI: fixed error in the original code
        paint.setColorFilter(cf);
      }

      // gradient
      if (grad) {
        int[] Colors = {0x00000000, 0xFF000000};
        float[] ColorPosition = {0.10f, 0.99f};
        RadialGradient gradient =
            new RadialGradient(
                width / 2,
                height / 2,
                width - width / 2,
                Colors,
                ColorPosition,
                android.graphics.Shader.TileMode.CLAMP);
        paint.setDither(true);
        paint.setShader(gradient);
      }

      canvas2.drawBitmap(mutableBitmap, 0, 0, paint);
      return resultBitmap;
    }

    return null;
  }
  private void bindProxiesAndProperties(KrollDict properties, boolean isRootTemplate) {
    String id = null;
    Object props = null;
    DataItem item = null;

    // Get/generate random bind id
    if (isRootTemplate) {
      id = itemID;
    } else if (properties.containsKey(TiC.PROPERTY_BIND_ID)) {
      id = TiConvert.toString(properties, TiC.PROPERTY_BIND_ID);
    }

    if (id == null) return;

    if (isRootTemplate) {
      rootItem = item = new DataItem(TiC.PROPERTY_PROPERTIES);
    } else {
      item = new DataItem(id);
    }
    dataItems.put(id, item);

    if (properties.get(TiC.PROPERTY_PROPERTIES) != null) {
      props = properties.get(TiC.PROPERTY_PROPERTIES);
    }

    if (props instanceof HashMap) {
      item.setDefaultProperties(new KrollDict((HashMap) props));
    }
  }
Exemplo n.º 7
0
  @Kroll.method
  public String encode(HashMap args) {
    // encode text to cipher text
    //
    KrollDict arg = new KrollDict(args);
    String txt = arg.getString("plainText");
    String keyString = arg.getString("publicKey");
    byte[] encodedBytes = null;
    Key key;

    try {
      byte[] encodedKey = Base64.decode(keyString, 0);
      X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(encodedKey);
      KeyFactory keyFact = KeyFactory.getInstance("RSA", "BC");
      key = keyFact.generatePublic(x509KeySpec);
    } catch (Exception e) {
      return "error key";
    }

    try {
      Cipher c = Cipher.getInstance("RSA");
      c.init(Cipher.ENCRYPT_MODE, key);
      encodedBytes = c.doFinal(txt.getBytes());
    } catch (Exception e) {
      Log.e(TAG, "RSA encryption error " + e.toString());
    }

    return Base64.encodeToString(encodedBytes, Base64.NO_WRAP);
  }
  private Intent createAlarmServiceIntent(KrollDict args) {
    String serviceName = args.getString("service");
    Intent intent =
        new Intent(TiApplication.getInstance().getApplicationContext(), AlarmServiceListener.class);
    intent.putExtra("alarm_service_name", serviceName);
    // Pass in flag if we need to restart the service on each call
    intent.putExtra("alarm_service_force_restart", (optionIsEnabled(args, "forceRestart")));
    // Check if the user has selected to use intervals
    boolean hasInterval = (args.containsKeyAndNotNull("interval"));
    long intervalValue = 0;
    if (hasInterval) {
      Object interval = args.get("interval");
      if (interval instanceof Number) {
        intervalValue = ((Number) interval).longValue();
      } else {
        hasInterval = false;
      }
    }
    intent.putExtra("alarm_service_has_interval", hasInterval);
    if (hasInterval) {
      intent.putExtra("alarm_service_interval", intervalValue);
    }

    utils.debugLog(
        "created alarm service intent for "
            + serviceName
            + "(forceRestart: "
            + (optionIsEnabled(args, "forceRestart") ? "true" : "false")
            + ", intervalValue: "
            + intervalValue
            + ")");

    return intent;
  }
Exemplo n.º 9
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;
  }
Exemplo n.º 10
0
  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);
    }
  }
Exemplo n.º 11
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;
 }
  private void fillIntent(Activity activity, Intent intent) {
    KrollDict props = getProperties();

    if (props != null) {
      if (props.containsKey(TiC.PROPERTY_FULLSCREEN)) {
        intent.putExtra(
            TiC.PROPERTY_FULLSCREEN, TiConvert.toBoolean(props, TiC.PROPERTY_FULLSCREEN));
      }
      if (props.containsKey(TiC.PROPERTY_NAV_BAR_HIDDEN)) {
        intent.putExtra(
            TiC.PROPERTY_NAV_BAR_HIDDEN, TiConvert.toBoolean(props, TiC.PROPERTY_NAV_BAR_HIDDEN));
      }
    }

    if (props != null && props.containsKey(TiC.PROPERTY_EXIT_ON_CLOSE)) {
      intent.putExtra(
          TiC.INTENT_PROPERTY_FINISH_ROOT, TiConvert.toBoolean(props, TiC.PROPERTY_EXIT_ON_CLOSE));
    } else {
      intent.putExtra(TiC.INTENT_PROPERTY_FINISH_ROOT, activity.isTaskRoot());
    }

    Messenger messenger = new Messenger(getUIHandler());
    intent.putExtra(TiC.INTENT_PROPERTY_MESSENGER, messenger);
    intent.putExtra(TiC.INTENT_PROPERTY_MSG_ID, MSG_FINISH_OPEN);
  }
Exemplo n.º 13
0
  private void processData(Object[] items, int offset) {
    if (listItemData == null) {
      return;
    }

    TiListViewTemplate[] temps = new TiListViewTemplate[items.length];
    // First pass through data, we process template and update
    // default properties based data given
    for (int i = 0; i < items.length; i++) {
      Object itemData = items[i];
      if (itemData instanceof HashMap) {
        KrollDict d = new KrollDict((HashMap) itemData);
        TiListViewTemplate template = processTemplate(d, i + offset);
        template.updateOrMergeWithDefaultProperties(d, true);
        temps[i] = template;
      }
    }
    // Second pass we would merge properties
    for (int i = 0; i < items.length; i++) {
      Object itemData = items[i];
      if (itemData instanceof HashMap) {
        KrollDict d = new KrollDict((HashMap) itemData);
        TiListViewTemplate template = temps[i];
        if (template != null) {
          template.updateOrMergeWithDefaultProperties(d, false);
        }
        ListItemData itemD = new ListItemData(d, template);
        d.remove(TiC.PROPERTY_TEMPLATE);
        listItemData.add(i + offset, itemD);
      }
    }
    // Notify adapter that data has changed.
    adapter.notifyDataSetChanged();
  }
Exemplo n.º 14
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;
  }
  // Handle creation options
  @Override
  public void handleCreationDict(KrollDict options) {
    super.handleCreationDict(options);

    if (options.containsKey("message")) {
      Log.d(TAG, "example created with message: " + options.get("message"));
    }
  }
 private boolean optionIsEnabled(KrollDict args, String paramName) {
   if (args.containsKeyAndNotNull(paramName)) {
     Object value = args.get(paramName);
     return TiConvert.toBoolean(value);
   } else {
     return false;
   }
 }
Exemplo 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});
 }
Exemplo 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);
 }
Exemplo n.º 19
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);
  }
 // Methods
 @SuppressWarnings("deprecation")
 private KrollFunction getCallback(final KrollDict options, final String name) throws Exception {
   if (options.containsKey(name)) {
     return (KrollFunction) options.get(name);
   } else {
     Log.d(LCAT, "Callback not found: " + name);
     throw new Exception("Callback not found: " + name);
   }
 }
    @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);
 }
Exemplo n.º 23
0
 public boolean equalsKrollDict(KrollDict otherDict) {
   if (otherDict.size() != size()) return false;
   for (Entry<String, Object> e : entrySet()) {
     String key = e.getKey();
     Object newvalue = e.getValue();
     if (!otherDict.containsKeyWithValue(key, newvalue)) return false;
   }
   return true;
 }
Exemplo n.º 24
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);
  }
Exemplo n.º 25
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 KrollDict filterProperties(KrollDict d) {
    if (d == null) return new KrollDict();

    KrollDict filtered = new KrollDict(d);
    for (int i = 0; i < filteredProperties.length; i++) {
      if (filtered.containsKey(filteredProperties[i])) {
        filtered.remove(filteredProperties[i]);
      }
    }
    return filtered;
  }
Exemplo n.º 27
0
  @Override
  public void processProperties(KrollDict d) {
    tableView = new TiTableView(proxy.getTiContext(), (TableViewProxy) proxy);
    tableView.setOnItemClickListener(this);

    if (d.containsKey(TiC.PROPERTY_SEARCH)) {
      RelativeLayout layout = new RelativeLayout(proxy.getTiContext().getActivity());
      layout.setGravity(Gravity.NO_GRAVITY);
      layout.setPadding(0, 0, 0, 0);

      TiViewProxy searchView = (TiViewProxy) d.get(TiC.PROPERTY_SEARCH);
      TiUISearchBar searchBar =
          (TiUISearchBar) searchView.getView(proxy.getTiContext().getActivity());
      searchBar.setOnSearchChangeListener(tableView);
      searchBar.getNativeView().setId(102);

      RelativeLayout.LayoutParams p =
          new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
      p.addRule(RelativeLayout.ALIGN_PARENT_TOP);
      p.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
      p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
      p.height = 52;

      layout.addView(searchBar.getNativeView(), p);

      p =
          new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
      p.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
      p.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
      p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
      p.addRule(RelativeLayout.BELOW, 102);
      layout.addView(tableView, p);
      setNativeView(layout);
    } else {
      setNativeView(tableView);
    }

    if (d.containsKey(TiC.PROPERTY_FILTER_ATTRIBUTE)) {
      tableView.setFilterAttribute(TiConvert.toString(d, TiC.PROPERTY_FILTER_ATTRIBUTE));
    } else {
      // Default to title to match iPhone default.
      proxy.setProperty(TiC.PROPERTY_FILTER_ATTRIBUTE, TiC.PROPERTY_TITLE, false);
      tableView.setFilterAttribute(TiC.PROPERTY_TITLE);
    }

    boolean filterCaseInsensitive = true;
    if (d.containsKey(TiC.PROPERTY_FILTER_CASE_INSENSITIVE)) {
      filterCaseInsensitive = TiConvert.toBoolean(d, TiC.PROPERTY_FILTER_CASE_INSENSITIVE);
    }
    tableView.setFilterCaseInsensitive(filterCaseInsensitive);
    super.processProperties(d);
  }
 @Override
 public void processProperties(KrollDict d) {
   // TODO Auto-generated method stub
   super.processProperties(d);
   if (d.containsKey(TiC.PROPERTY_TITLE)) {
     actionBar.setTitle(d.getString(TiC.PROPERTY_TITLE));
   }
   if (d.containsKey(TiC.PROPERTY_SWIPEABLE)) {
     swipeable = d.getBoolean(TiC.PROPERTY_SWIPEABLE);
   }
 }
Exemplo n.º 29
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);
  }
Exemplo n.º 30
0
  @Override
  public void processProperties(KrollDict d) {
    if (d.containsKey("volume")) {
      setVolume(TiConvert.toFloat(d, "volume"));
    } else {
      setVolume(0.5f);
    }

    if (d.containsKey("time")) {
      setTime(TiConvert.toInt(d, "time"));
    }
  }