Exemple #1
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);
    }
  }
Exemple #2
0
 public static void inline_signature_capture(String callback_url) {
   if (ourInlineSignatureView != null) {
     ImageCapture.takeSignature(
         callback_url,
         getSharedInstance().mProperties.imageFormat,
         ourInlineSignatureView.makeBitmap());
   }
   inlineSignatureHide(RhoExtManager.getInstance());
 }
Exemple #3
0
  @Override
  public void onPageStarted(WebView view, String url, Bitmap favicon) {
    super.onPageStarted(view, url, favicon);

    RhoExtManager.getImplementationInstance().onNavigateStarted(view, url);

    if (mWebView.getConfig() != null && mWebView.getConfig().getBool("enablePageLoadingIndication"))
      RhodesActivity.safeGetInstance().getWindow().setFeatureInt(Window.FEATURE_PROGRESS, 0);
  }
Exemple #4
0
  @Override
  public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);

    Logger.profStop("BROWSER_PAGE");

    StringBuilder msg = new StringBuilder(failingUrl != null ? failingUrl : "null");
    msg.append(" failed: ");
    msg.append(errorCode);
    msg.append(" - " + description);
    Logger.E(TAG, msg.toString());

    RhoExtManager.getImplementationInstance()
        .onLoadError(view, IRhoExtension.LoadErrorReason.INTERNAL_ERROR);
  }
Exemple #5
0
  @Override
  public void onPageFinished(WebView view, String url) {

    Logger.profStop("BROWSER_PAGE");

    // Set title
    String title = view.getTitle();
    RhodesActivity.safeGetInstance().setTitle(title);
    if (mWebView.getConfig() != null && mWebView.getConfig().getBool("enablePageLoadingIndication"))
      RhodesActivity.safeGetInstance()
          .getWindow()
          .setFeatureInt(Window.FEATURE_PROGRESS, RhodesActivity.MAX_PROGRESS);

    RhoExtManager.getImplementationInstance().onNavigateComplete(view, url);

    super.onPageFinished(view, url);
  }
Exemple #6
0
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Logger.I(TAG, "Loading URL: " + url);
    boolean res = RhodesService.getInstance().handleUrlLoading(url);
    if (!res) {
      Logger.profStart("BROWSER_PAGE");

      RhoExtManager.getImplementationInstance().onBeforeNavigate(view, url);

      Uri localUri = LocalFileProvider.overrideUri(Uri.parse(url));
      if (localUri != null) {
        url = Uri.decode(localUri.toString());
        Logger.T(TAG, "Override URL: " + url);
        view.loadUrl(url);
        return true;
      }
    }
    return res;
  }
  @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());
    }
  }
Exemple #8
0
  private void loadRegex(boolean useDefaults) {
    // Set up the Regex Patterns/Replacements ArrayLists
    cTPatterns = new ArrayList<Matcher>();
    cTReplacers = new ArrayList<String>();
    hEPatterns = new ArrayList<Matcher>();
    hEReplacers = new ArrayList<String>();
    try {
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      XmlPullParser parser = factory.newPullParser();

      if (useDefaults) {
        parser.setInput(
            Common.mainActivity
                .getResources()
                .openRawResource(RhoExtManager.getResourceId("raw", "regex")),
            null);
      } else {
        String regexFile = Common.config.getSetting(Config.SETTING_REGEX_FILE);
        if (regexFile == null) {
          Common.logger.add(
              new LogEntry(
                  LogEntry.PB_LOG_WARNING,
                  Config.SETTING_REGEX_FILE
                      + " not defined in Config.xml. Using default regex patterns."));
          loadRegex(true);
          return;
        }
        parser.setInput(new FileReader(new File(Common.parseAndroidURI(regexFile))));
      }
      String currentSection = "";
      for (int event = parser.getEventType();
          event != XmlPullParser.END_DOCUMENT;
          event = parser.next()) {
        switch (event) {
          case XmlPullParser.START_TAG:
            if (parser.getName().equalsIgnoreCase("Expression")) {
              String patternEx = null;
              String replaceEx = null;
              for (int i = 0; i < parser.getAttributeCount(); i++) {
                String name = parser.getAttributeName(i);
                if (name.equalsIgnoreCase("patternex")) {
                  patternEx = parser.getAttributeValue(i);
                }
                if (name.equalsIgnoreCase("replaceex")) {
                  replaceEx = parser.getAttributeValue(i).replaceAll("\\\\([0-9]+)", "\\$$1");
                }
              }

              if (patternEx == null || replaceEx == null) {
                /*if(!Oem.testmode)*/ Common.logger.add(
                    new LogEntry(
                        LogEntry.PB_LOG_WARNING,
                        "Incorrect regex tag. Cannot find PatternEX/replaceEX attribute on line: "
                            + parser.getLineNumber()));
                break;
              }
              if (currentSection.equals("Equivs")) {
                addRegExPair_HE(patternEx, replaceEx);
              } else if (currentSection.equals("Contents")) {
                addRegExPair_CT(patternEx, replaceEx);
              } else {
                /*if(!Oem.testmode)*/ Common.logger.add(
                    new LogEntry(
                        LogEntry.PB_LOG_WARNING,
                        "Badly formed regex.xml. Regex pair outside of Equivs/Contents tags on line: "
                            + parser.getLineNumber()));
              }
            } else if (parser.getName().equalsIgnoreCase("Equivs")) {
              currentSection = "Equivs";
            } else if (parser.getName().equalsIgnoreCase("Contents")) {
              currentSection = "Contents";
            }
            break;
          default:
            break;
        }
      }
    } catch (XmlPullParserException e) {
      if (!useDefaults) {
        /*if(!Oem.testmode)*/ Common.logger.add(
            new LogEntry(
                LogEntry.PB_LOG_WARNING,
                "regex.xml error. Could not parse. Using default regex patterns."));
        loadRegex(true);
      } else {
        /*if(!Oem.testmode)*/ Common.logger.add(
            new LogEntry(LogEntry.PB_LOG_ERROR, "Could not parse default regex patterns."));
      }
    } catch (FileNotFoundException e) {
      if (!useDefaults) {
        /*if(!Oem.testmode)*/ Common.logger.add(
            new LogEntry(
                LogEntry.PB_LOG_WARNING,
                "regex.xml file not found. Using default regex patterns."));
        loadRegex(true);
      } else {
        // Will never happen
        /*if(!Oem.testmode)*/ Common.logger.add(
            new LogEntry(LogEntry.PB_LOG_ERROR, "Could not parse default regex patterns."));
      }
    } catch (IOException e) {
      if (!useDefaults) {
        /*if(!Oem.testmode)*/ Common.logger.add(
            new LogEntry(
                LogEntry.PB_LOG_WARNING, "Cannot read regex.xml. Using default regex patterns."));
        loadRegex(true);
      } else {
        // Should never happen
        /*if(!Oem.testmode)*/ Common.logger.add(
            new LogEntry(LogEntry.PB_LOG_ERROR, "Could not parse default regex patterns."));
      }
    } catch (URISyntaxException e) {
      if (!useDefaults) {
        /*if(!Oem.testmode)*/ Common.logger.add(
            new LogEntry(
                LogEntry.PB_LOG_WARNING,
                "regex.xml URL is invalid in Config.xml. Using default regex patterns."));
        loadRegex(true);
      } else {
        // Will never happen
        /*if(!Oem.testmode)*/ Common.logger.add(
            new LogEntry(LogEntry.PB_LOG_ERROR, "Could not parse default regex patterns."));
      }
    }
  }
Exemple #9
0
 public static void registerSignatureCaptureExtension() {
   RhoExtManager.getInstance().registerExtension(SIGNATURE_EXT, getSharedInstance());
 }
Exemple #10
0
 public static void inline_signature_clear() {
   inlineSignatureClear(RhoExtManager.getInstance());
 }
Exemple #11
0
 public static void inline_signature_visible(int visible, Object params) {
   inlineSignatureVisible(RhoExtManager.getInstance(), (visible != 0), params);
 }