Example #1
0
 @Override
 public synchronized void startListening(IMethodResult result) {
   if (methodResult != null) {
     methodResult.release();
   }
   methodResult = result;
   methodResult.keepAlive();
 }
Example #2
0
  @Override
  public void send(Map<String, Object> params, final IMethodResult result) {
    Intent intent = makeIntent(params);
    Object type = params.get(HK_INTENT_TYPE);
    if (BROADCAST.equals(type)) {
      Object permissionObj = params.get(HK_PERMISSION);
      String permission = null;
      if (permissionObj != null) {
        if (String.class.isInstance(permissionObj)) {
          permission = (String) permissionObj;
        } else {
          result.setArgError("Wrong intent permission: " + permissionObj);
          return;
        }
      }
      Logger.T(TAG, "Send broadcast: " + intent);
      ContextFactory.getAppContext().sendBroadcast(intent, permission);
    } else if (START_ACTIVITY.equals(type)) {
      if (result.hasCallback()) {
        int request;
        synchronized (localMethodResults) {
          request = RhoExtManager.getInstance().getActivityResultNextRequestCode(this);
          final Integer finalKey = Integer.valueOf(request);
          Map.Entry<Integer, IMethodResult> entry =
              new Map.Entry<Integer, IMethodResult>() {
                Integer key = finalKey;
                IMethodResult value = result;

                @Override
                public Integer getKey() {
                  return key;
                }

                @Override
                public IMethodResult getValue() {
                  return value;
                }

                @Override
                public IMethodResult setValue(IMethodResult v) {
                  return result;
                }
              };
          localMethodResults.add(entry);
        }
        RhodesActivity.safeGetInstance().startActivityForResult(intent, request);
        Logger.T(TAG, "Start activity for result: " + intent);
      } else {
        Logger.T(TAG, "Start activity: " + intent);
        ContextFactory.getUiContext().startActivity(intent);
      }
    } else if (START_SERVICE.equals(type)) {
      Logger.T(TAG, "Start service: " + intent);
      ContextFactory.getContext().startService(intent);
    } else {
      result.setArgError("Wrong intent type: " + type);
    }
  }
  @Override
  public void getSDPath(IMethodResult res) {
    File sdCardRoot = Environment.getExternalStorageDirectory();
    String sdCardPath = sdCardRoot.getAbsolutePath();

    res.set(sdCardPath);
  }
Example #4
0
 @Override
 public synchronized void stopListening(IMethodResult result) {
   if (methodResult != null) {
     methodResult.release();
     methodResult = null;
   }
 }
Example #5
0
 @Override
 public void setProperties(Map<String, String> propertyMap, IMethodResult result) {
   // TODO Auto-generated method stub
   Map<String, String> temp = getPropertiesMap();
   temp.putAll(propertyMap);
   result.set(true);
 }
Example #6
0
 @Override
 public void setCompressionFormat(String compressionFormat, IMethodResult result) {
   if (!compressionFormat.equalsIgnoreCase("jpg")) {
     Logger.E(TAG, "Android does not support the compression format: " + compressionFormat);
     result.setError("Android does not support the compression format: " + compressionFormat);
   }
 }
Example #7
0
 public synchronized void onNewIntent(String type, Intent intent) {
   if (methodResult != null) {
     Logger.T(TAG, "New Intent: " + type);
     Map<String, Object> params = parseIntent(intent);
     params.put(HK_INTENT_TYPE, type);
     methodResult.set(params);
   }
 }
Example #8
0
 @Override
 public void getAllProperties(IMethodResult result) {
   // TODO Auto-generated method stub
   Map<String, Object> props = new HashMap<String, Object>();
   for (String key : getPropertiesMap().keySet()) {
     props.put(key, cameraPropGet(key));
   }
   result.set(props);
 }
Example #9
0
  @Override
  public void getProperties(List<String> arrayofNames, IMethodResult result) {

    // super.getProperties(arrayofNames, result);
    Map<String, Object> props = new HashMap<String, Object>();
    for (String name : arrayofNames) {
      props.put(name, cameraPropGet(name));
    }
    result.set(props);
  }
Example #10
0
 @Override
 public void onActivityResult(
     RhodesActivity activity, int requestCode, int resCode, Intent intent) {
   IMethodResult result = null;
   synchronized (localMethodResults) {
     Iterator<Map.Entry<Integer, IMethodResult>> iter = localMethodResults.iterator();
     while (iter.hasNext()) {
       // for (Map.Entry<Integer, IMethodResult> resultEntry : localMethodResults) {
       Map.Entry<Integer, IMethodResult> resultEntry = iter.next();
       if (resultEntry.getKey().intValue() == requestCode) {
         Logger.T(TAG, "Activity result request: " + requestCode);
         result = resultEntry.getValue();
         iter.remove();
       }
     }
   }
   if (result != null) {
     Map<String, Object> params = parseIntent(intent);
     params.put(HK_INTENT_TYPE, START_ACTIVITY);
     params.put(HK_RESPONSE_CODE, Integer.valueOf(resCode));
     result.set(params);
   }
 }
Example #11
0
  @Override
  public void takePicture(Map<String, String> propertyMap, IMethodResult result) {
    Logger.T(TAG, "takePicture");
    try {
      Map<String, String> actualPropertyMap = new HashMap<String, String>();
      actualPropertyMap.putAll(getPropertiesMap());
      actualPropertyMap.putAll(propertyMap);
      setActualPropertyMap(actualPropertyMap);

      String outputFormat = actualPropertyMap.get("outputFormat");
      String filePath = null;
      if (!actualPropertyMap.containsKey("fileName")) {
        filePath =
            "/sdcard/DCIM/Camera/IMG_"
                + dateFormat.format(new Date(System.currentTimeMillis()))
                + ".jpg";
      } else {
        filePath = actualPropertyMap.get("fileName");
      }
      if (outputFormat.equalsIgnoreCase("image")) {
        filePath = actualPropertyMap.get("fileName") + ".jpg";
        Logger.T(TAG, "outputFormat: " + outputFormat + ", path: " + filePath);
      } else if (outputFormat.equalsIgnoreCase("dataUri")) {
        Logger.T(TAG, "outputFormat: " + outputFormat);
      } else {
        throw new RuntimeException("Unknown 'outputFormat' value: " + outputFormat);
      }

      Intent intent = null;
      if (Boolean.parseBoolean(actualPropertyMap.get("useSystemViewfinder"))) {
        if (outputFormat.equalsIgnoreCase("image")) {
          values = new ContentValues();
          fileUri =
              RhodesActivity.getContext()
                  .getContentResolver()
                  .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
          intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          actualPropertyMap.put("captureUri", fileUri.toString());
          propertyMap.put("dataURI", "");
          // intent is null with MediaStore.EXTRA_OUTPUT so adding fileuri to map and get it with
          // same key
          // if instead of MediaStore.EXTRA_OUTPUT any other key is used then the bitmap is null
          // though the file is getting created
          intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        } else if (outputFormat.equalsIgnoreCase("dataUri")) {

        }
      } else {
        intent = new Intent(ContextFactory.getUiContext(), CameraActivity.class);
        intent.putExtra(CameraExtension.INTENT_EXTRA_PREFIX + "CAMERA_ID", getId());
      }
      ((CameraFactory) CameraFactorySingleton.getInstance())
          .getRhoListener()
          .setMethodResult(result);
      ((CameraFactory) CameraFactorySingleton.getInstance())
          .getRhoListener()
          .setActualPropertyMap(actualPropertyMap);

      RhodesActivity.safeGetInstance()
          .startActivityForResult(
              intent,
              RhoExtManager.getInstance()
                  .getActivityResultNextRequestCode(CameraRhoListener.getInstance()));
    } catch (RuntimeException e) {
      Logger.E(TAG, e);
      result.setError(e.getMessage());
    }
  }