Beispiel #1
0
  private void init(MainView v, Object params) {
    Context ctx = RhodesActivity.getContext();

    view = new MyView(ctx);
    view.setOrientation(LinearLayout.VERTICAL);
    view.setGravity(Gravity.BOTTOM);
    view.setLayoutParams(new LinearLayout.LayoutParams(FILL_PARENT, FILL_PARENT));

    webView = null;
    if (v != null) webView = v.detachWebView();
    if (webView == null) webView = RhodesActivity.safeGetInstance().createWebView();
    view.addView(webView, new LinearLayout.LayoutParams(FILL_PARENT, 0, 1));

    LinearLayout bottom = new LinearLayout(ctx);
    bottom.setOrientation(LinearLayout.HORIZONTAL);
    bottom.setBackgroundColor(Color.GRAY);
    bottom.setLayoutParams(new LinearLayout.LayoutParams(FILL_PARENT, WRAP_CONTENT, 0));
    view.addView(bottom);

    toolBar = bottom;

    setupToolbar(toolBar, params);

    webView.requestFocus();
  }
Beispiel #2
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);
  }
Beispiel #3
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);
    }
  }
Beispiel #4
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);
  }
Beispiel #5
0
  @SuppressWarnings("deprecation")
  @SuppressLint("NewApi")
  @Override
  public ISize setPreviewSize(int width, int height) {
    Camera camera = getCamera();
    Camera.Parameters parameters = camera.getParameters();
    List<android.hardware.Camera.Size> sizes = camera.getParameters().getSupportedPictureSizes();
    android.hardware.Camera.Size maxSize = sizes.get(0);
    if (getActualPropertyMap().containsKey("desiredWidth")
        || getActualPropertyMap().containsKey("desiredHeight")) {
      int desired_width = Integer.parseInt(getActualPropertyMap().get("desiredWidth"));
      int desired_height = Integer.parseInt(getActualPropertyMap().get("desiredHeight"));
      if (desired_width > 0
          && desired_width <= maxSize.width
          && desired_height > 0
          && desired_height <= maxSize.height) {
        Camera.Size previewSize =
            getOptimalPreviewSize(
                parameters.getSupportedPictureSizes(), desired_width, desired_height);
        Logger.T(TAG, "Selected size: " + previewSize.width + "x" + previewSize.height);
        parameters.setPreviewSize(previewSize.width, previewSize.height);
      } else if (desired_width > maxSize.width || desired_height > maxSize.height) {
        final Camera.Parameters newParam = parameters;
        final android.hardware.Camera.Size newMaxSize = sizes.get(0);
        RhodesActivity.safeGetInstance()
            .runOnUiThread(
                new Runnable() {

                  @Override
                  public void run() {
                    // TODO Auto-generated method stub
                    newParam.setPreviewSize(newMaxSize.width, newMaxSize.height);
                  }
                });
      } else {
        parameters.setPreviewSize(320, 240);
      }
    } else {
      Camera.Size previewSize =
          getOptimalPreviewSize(parameters.getSupportedPictureSizes(), width, height);
      Logger.T(TAG, "Selected size: " + previewSize.width + "x" + previewSize.height);
      parameters.setPreviewSize(previewSize.width, previewSize.height);
    }
    camera.stopPreview();
    try {
      camera.setParameters(parameters);
    } catch (RuntimeException e) {
      e.printStackTrace();
    }
    camera.startPreview();

    return new CameraSize(camera.getParameters().getPreviewSize());
  }
Beispiel #6
0
 public void run() {
   init();
   RhodesActivity ra = RhodesActivity.safeGetInstance();
   Intent intent = new Intent(ra, klass);
   intent.putExtra(
       INTENT_EXTRA_PREFIX + "callback", getSharedInstance().mProperties.callbackUrl);
   intent.putExtra(
       INTENT_EXTRA_PREFIX + "imageFormat", getSharedInstance().mProperties.imageFormat);
   intent.putExtra(INTENT_EXTRA_PREFIX + "penColor", getSharedInstance().mProperties.penColor);
   intent.putExtra(INTENT_EXTRA_PREFIX + "penWidth", getSharedInstance().mProperties.penWidth);
   intent.putExtra(INTENT_EXTRA_PREFIX + "bgColor", getSharedInstance().mProperties.bgColor);
   ra.startActivity(intent);
 }
Beispiel #7
0
  // Special exec edition for RhoBluetoothManager
  // TODO: Use future pattern to return result and wait
  @Deprecated
  public static void sync_exec(final Runnable r) {
    try {
      RhodesActivity ra = RhodesActivity.safeGetInstance();

      long thrId = Thread.currentThread().getId();
      if (ra.getUiThreadId() == thrId) {
        // We are already in UI thread
        r.run();
      } else {
        // Post request to UI thread and wait when it would be done
        synchronized (r) {
          ra.post(new PerformOnUiThread(r));
          r.wait();
        }
      }
    } catch (Exception e) {
      Logger.E(TAG, "exec failed: " + e.getMessage());
      Thread.dumpStack();
    }
  }
Beispiel #8
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());
    }
  }
Beispiel #9
0
  public void loadFirstPage() {

    int sel_col = 0;
    boolean sel_col_enable = false;

    int cur_tabIndex = 0;
    TabData data = null;
    boolean founded_not_disabled = false;

    while ((!founded_not_disabled) && (cur_tabIndex < tabData.size())) {
      data = tabData.elementAt(cur_tabIndex);
      if ((data != null) && (!data.disabled)) {
        founded_not_disabled = true;
      } else {
        cur_tabIndex++;
      }
    }
    if (!founded_not_disabled) {
      Logger.E(TAG, "ERROR : All tabs is disabled !!! ");
    }

    if ((tabIndex != cur_tabIndex) && (tabIndex != 0)) {
      data = tabData.elementAt(tabIndex);
    } else {
      tabIndex = cur_tabIndex;
    }

    if (data != null) {
      sel_col = data.selected_color;
      sel_col_enable = data.selected_color_enabled;
    }
    // processTabHostColors(host, sel_col, sel_col_enable);

    host.requestLayout();

    TabHostClickListener listener = new TabHostClickListener();
    listener.tabHost = host;

    host.setOnTabChangedListener(listener);

    for (int i = 0; i < host.getTabWidget().getChildCount(); i++) {
      host.getTabWidget().getChildAt(i).setOnTouchListener(listener);
      host.getTabWidget().getChildAt(i).setOnClickListener(listener);
    }

    if (data != null) {
      try {
        if (!data.loaded) {
          RhodesService.loadUrl(data.url);
          data.loaded = true;
        }
        sel_col = data.selected_color;
        sel_col_enable = data.selected_color_enabled;
      } catch (NumberFormatException e) {
        Logger.E(TAG, e);
      }
      processTabHostColors(host, sel_col, sel_col_enable);
    }

    host.setCurrentTab(tabIndex);

    RhodesActivity.safeGetInstance()
        .post(
            new Runnable() {
              public void run() {
                // Utils.platformLog("TabbedMainView", "invoke post setup code in UI thread");

                // invoke in UI thread
                int i;
                for (i = 0; i < tabData.size(); i++) {
                  TabData data = tabData.elementAt(i);
                  if (i != tabIndex) {
                    data.loaded = false;
                  }
                  if (i != tabIndex) {
                    WebView wv = getWebView(i);
                    wv.clearView();
                    wv.clearCache(true);
                    wv.invalidate();
                    wv.loadData("", "", "");
                  }
                }
                TabData selected_data = tabData.elementAt(tabIndex);
                if (!selected_data.loaded) {
                  RhodesService.loadUrl(selected_data.url);
                  selected_data.loaded = true;
                }
                mIsReallyOnScreen = true;
              }
            });
  }