public void addTitaniumFileAsPostData(String name, ITitaniumFile value) {
   if (value instanceof TitaniumDelegate) {
     value = (ITitaniumFile) ((TitaniumDelegate) value).getObject();
   }
   if (value instanceof TitaniumBlob) {
     TitaniumBlob blob = (TitaniumBlob) value;
     FileBody body = new FileBody(blob.getFile(), blob.getContentType());
     parts.put(name, body);
   } else if (value instanceof TitaniumFile) {
     Log.e(LCAT, name + " is a TitaniumFile");
   } else if (value instanceof TitaniumResourceFile) {
     Log.e(LCAT, name + " is a TitaniumResourceFile");
   } else {
     if (value != null) {
       Log.e(LCAT, name + " is a " + value.getClass().getSimpleName());
     } else {
       Log.e(LCAT, name + " is null");
     }
   }
 }
Пример #2
0
  public void previewImage(
      final String successCallback, final String errorCallback, final ITitaniumFile file) {
    if (DBG) {
      Log.d(LCAT, "previewImage");
    }

    if (!(file instanceof TitaniumBlob)) {
      throw new IllegalArgumentException("blob parameter must be of type TitaniumBlob");
    }

    final TitaniumBlob blob = (TitaniumBlob) file;

    TitaniumActivity activity = getActivity();
    Uri uri = Uri.parse(blob.nativePath());

    String type = activity.getContentResolver().getType(uri);

    TitaniumIntentWrapper previewIntent = new TitaniumIntentWrapper(new Intent());
    previewIntent.getIntent().setAction(Intent.ACTION_VIEW);
    previewIntent.getIntent().setType(type);
    previewIntent.getIntent().setData(uri);
    previewIntent.setWindowId(TitaniumIntentWrapper.createActivityName("PREVIEW"));

    final int code = activity.getUniqueResultCode();
    activity.launchActivityForResult(
        previewIntent,
        code,
        new TitaniumResultHandler() {

          public void onResult(
              TitaniumActivity activity, int requestCode, int resultCode, Intent data) {
            invokeUserCallback(successCallback, null);
          }

          public void onError(TitaniumActivity activity, int requestCode, Exception e) {
            Log.e(LCAT, "preview problem: ", e);
            invokeUserCallback(errorCallback, createJSONError(0, e.getMessage()));
          }
        });
  }
Пример #3
0
  String fillBlob(TitaniumActivity activity, TitaniumBlob blob, String path) {
    blob.setUrl(path);
    // Get image attributes
    int width = -1;
    int height = -1;
    try {
      Bitmap b =
          BitmapFactory.decodeStream(
              activity.getContentResolver().openInputStream(Uri.parse(path)));
      if (b != null) {
        width = b.getWidth();
        height = b.getHeight();
        b.recycle();
        b = null;
      }
    } catch (FileNotFoundException e) {
      Log.w(LCAT, "bitmap not found: " + path);
    }
    StringBuilder sb = new StringBuilder(32);
    sb.append("{ w : ").append(width).append(", h : ").append(height).append("}");

    return sb.toString();
  }