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 WebView getWebView(int index) {
   if (mWebView == null) {
     RhodesActivity ra = RhodesActivity.getInstance();
     mWebView = ra.createWebView();
   }
   return mWebView;
 }
Beispiel #3
0
  public void back(int index) {
    restoreWebView();

    boolean bStartPage = RhodesService.isOnStartPage();

    if (!bStartPage && webView.canGoBack()) webView.goBack();
    else {
      RhodesActivity ra = RhodesActivity.getInstance();
      if (ra != null) ra.moveTaskToBack(true);
    }
  }
Beispiel #4
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 #5
0
  public void addNavBar(String title, Map<Object, Object> left, Map<Object, Object> right) {
    removeNavBar();

    Context ctx = RhodesActivity.getContext();

    LinearLayout top = new LinearLayout(ctx);
    top.setOrientation(LinearLayout.HORIZONTAL);
    top.setBackgroundColor(Color.GRAY);
    top.setGravity(Gravity.CENTER);
    top.setLayoutParams(new LinearLayout.LayoutParams(FILL_PARENT, WRAP_CONTENT, 0));

    View leftButton = createButton(left);
    leftButton.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1));
    top.addView(leftButton);

    TextView label = new TextView(ctx);
    label.setText(title);
    label.setGravity(Gravity.CENTER);
    label.setTextSize((float) 30.0);
    label.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 2));
    top.addView(label);

    if (right != null) {
      View rightButton = createButton(right);
      rightButton.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1));
      top.addView(rightButton);
    }

    navBar = top;
    view.addView(navBar, 0);
  }
Beispiel #6
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 #7
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 #8
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 #9
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 #10
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 #11
0
  @SuppressWarnings("unchecked")
  public TabbedMainView(Object params) {
    Context ctx = RhodesActivity.getContext();

    mBackgroundColorEnable = false;

    Vector<Object> tabs = null;
    boolean place_tabs_bottom = false;
    if (params instanceof Vector<?>) tabs = (Vector<Object>) params;
    else if (params instanceof Map<?, ?>) {
      Map<Object, Object> settings = (Map<Object, Object>) params;

      Object bkgObj = settings.get("background_color");
      if ((bkgObj != null) && (bkgObj instanceof String)) {
        int color = Integer.parseInt((String) bkgObj) | 0xFF000000;
        mBackgroundColor = color;
        mBackgroundColorEnable = true;
      }

      Object callbackObj = settings.get("on_change_tab_callback");
      if ((callbackObj != null) && (callbackObj instanceof String)) {
        mChangeTabCallback = new String(((String) callbackObj));
      }

      Object placeBottomObj = settings.get("place_tabs_bottom");
      if ((placeBottomObj != null) && (placeBottomObj instanceof String)) {
        place_tabs_bottom = ((String) placeBottomObj).equalsIgnoreCase("true");
      }

      Object tabsObj = settings.get("tabs");
      if (tabsObj != null && (tabsObj instanceof Vector<?>)) tabs = (Vector<Object>) tabsObj;
    }

    if (tabs == null) throw new IllegalArgumentException("No tabs specified");

    int size = tabs.size();

    host = new TabHost(ctx, null);

    tabData = new Vector<TabData>(size);
    tabIndex = 0;

    TabWidget tabWidget = new TabWidget(ctx);
    tabWidget.setId(android.R.id.tabs);

    FrameLayout frame = new FrameLayout(ctx);
    FrameLayout.LayoutParams lpf = null;
    TabHost.LayoutParams lpt = null;
    if (place_tabs_bottom) {
      frame.setId(android.R.id.tabcontent);
      lpf =
          new FrameLayout.LayoutParams(
              LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.TOP);
      host.addView(frame, lpf);

      lpt =
          new TabHost.LayoutParams(
              LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
      host.addView(tabWidget, lpt);
    } else {
      lpt =
          new TabHost.LayoutParams(
              LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.TOP);
      host.addView(tabWidget, lpt);

      frame = new FrameLayout(ctx);
      frame.setId(android.R.id.tabcontent);
      lpf =
          new FrameLayout.LayoutParams(
              LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.BOTTOM);
      host.addView(frame, lpf);
    }

    host.setup();

    TabHost.TabSpec spec;
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(metrics);

    int selected_color = 0;
    boolean selected_color_enable = false;

    for (int i = 0; i < size; ++i) {
      Object param = tabs.elementAt(i);
      if (!(param instanceof Map<?, ?>)) throw new IllegalArgumentException("Hash expected");

      Map<Object, Object> hash = (Map<Object, Object>) param;

      Object labelObj = hash.get("label");
      if (labelObj == null || !(labelObj instanceof String))
        throw new IllegalArgumentException("'label' should be String");

      Object actionObj = hash.get("action");

      boolean use_current_view_for_tab = false;
      Object use_current_view_for_tab_Obj = hash.get("use_current_view_for_tab");
      if (use_current_view_for_tab_Obj != null) {
        use_current_view_for_tab = ((String) use_current_view_for_tab_Obj).equalsIgnoreCase("true");
      }

      if (use_current_view_for_tab) {
        actionObj = new String("none");
      }
      if (actionObj == null || !(actionObj instanceof String))
        throw new IllegalArgumentException("'action' should be String");

      String label = (String) labelObj;
      String action = (String) actionObj;
      String icon = null;
      boolean reload = false;
      boolean disabled = false;
      int web_bkg_color = 0xFFFFFFFF;

      Object iconObj = hash.get("icon");
      if (iconObj != null && (iconObj instanceof String)) icon = "apps/" + (String) iconObj;

      Object reloadObj = hash.get("reload");
      if (reloadObj != null && (reloadObj instanceof String))
        reload = ((String) reloadObj).equalsIgnoreCase("true");

      Object selected_color_Obj = hash.get("selected_color");
      if ((selected_color_Obj != null) && (selected_color_Obj instanceof String)) {
        selected_color_enable = true;
        selected_color = Integer.parseInt((String) selected_color_Obj) | 0xFF000000;
      }

      Object disabled_Obj = hash.get("disabled");
      if (disabled_Obj != null && (disabled_Obj instanceof String))
        disabled = ((String) disabled_Obj).equalsIgnoreCase("true");

      Object web_bkg_color_Obj = hash.get("web_bkg_color");
      if (web_bkg_color_Obj != null && (web_bkg_color_Obj instanceof String)) {
        web_bkg_color = Integer.parseInt((String) web_bkg_color_Obj) | 0xFF000000;
      }

      spec = host.newTabSpec(Integer.toString(i));

      // Set label and icon
      BitmapDrawable drawable = null;

      if (icon != null) {
        String iconPath = RhoFileApi.normalizePath(icon);
        Bitmap bitmap = BitmapFactory.decodeStream(RhoFileApi.open(iconPath));
        if (disabled && (bitmap != null)) {
          // replace Bitmap to gray
          bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); // prepare mutable bitmap
          int x;
          int y;
          int bw = bitmap.getWidth();
          int bh = bitmap.getHeight();
          int nc = DISABLED_IMG_COLOR & 0xFFFFFF;
          int c;
          for (y = 0; y < bh; y++) {
            for (x = 0; x < bw; x++) {
              c = bitmap.getPixel(x, y);
              c = nc | (c & 0xFF000000);
              bitmap.setPixel(x, y, c);
            }
          }
        }

        if (bitmap != null)
          bitmap.setDensity(DisplayMetrics.DENSITY_MEDIUM); // Bitmap.DENSITY_NONE);
        drawable = new BitmapDrawable(bitmap);
        drawable.setTargetDensity(metrics);
      }
      if (drawable == null) spec.setIndicator(label);
      else spec.setIndicator(label, drawable);

      SimpleMainView view = null;
      if (use_current_view_for_tab) {
        RhodesService r = RhodesService.getInstance();
        MainView mainView = r.getMainView();
        action = mainView.currentLocation(-1);
        view = new SimpleMainView(mainView);
      } else {
        view = new SimpleMainView();
      }
      // Set view factory

      if (web_bkg_color_Obj != null) {
        if (!use_current_view_for_tab) {
          view.setWebBackgroundColor(web_bkg_color);
        }
        host.setBackgroundColor(web_bkg_color);
      }

      TabData data = new TabData();
      data.view = view;
      data.url = action;
      data.reload = reload;

      if (use_current_view_for_tab) {
        data.loaded = true;
        tabIndex = i;
      }

      data.selected_color = selected_color;
      data.selected_color_enabled = selected_color_enable;
      data.disabled = disabled;

      TabViewFactory factory = new TabViewFactory(data);
      spec.setContent(factory);

      tabData.addElement(data);
      host.addTab(spec);
    }

    tabWidget.measure(host.getWidth(), host.getHeight());
    int hh = tabWidget.getMeasuredHeight();
    // if (hh < 64) {
    //	hh = 64;
    // }
    if (place_tabs_bottom) {
      lpf.setMargins(0, 0, 0, hh);
    } else {
      lpf.setMargins(0, hh, 0, 0);
    }
    host.updateViewLayout(frame, lpf);
  }
Beispiel #12
0
 @Override
 public void back(int index) {
   RhodesActivity ra = RhodesActivity.getInstance();
   if (ra != null) ra.moveTaskToBack(true);
 }
Beispiel #13
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;
              }
            });
  }
Beispiel #14
0
  @SuppressWarnings("unchecked")
  private void setupToolbar(LinearLayout tool_bar, Object params) {
    Context ctx = RhodesActivity.getContext();

    mCustomBackgroundColorEnable = false;

    Vector<Object> buttons = null;
    if (params != null) {
      if (params instanceof Vector<?>) {
        buttons = (Vector<Object>) params;
      } else if (params instanceof Map<?, ?>) {
        Map<Object, Object> settings = (Map<Object, Object>) params;

        Object colorObj = settings.get("color");
        if (colorObj != null && (colorObj instanceof Map<?, ?>)) {
          Map<Object, Object> color = (Map<Object, Object>) colorObj;

          Object redObj = color.get("red");
          Object greenObj = color.get("green");
          Object blueObj = color.get("blue");

          if (redObj != null
              && greenObj != null
              && blueObj != null
              && (redObj instanceof String)
              && (greenObj instanceof String)
              && (blueObj instanceof String)) {
            try {
              int red = Integer.parseInt((String) redObj);
              int green = Integer.parseInt((String) greenObj);
              int blue = Integer.parseInt((String) blueObj);

              mCustomBackgroundColor =
                  ((red & 0xFF) << 16) | ((green & 0xFF) << 8) | ((blue & 0xFF)) | 0xFF000000;
              mCustomBackgroundColorEnable = true;

              tool_bar.setBackgroundColor(Color.rgb(red, green, blue));
            } catch (NumberFormatException e) {
              // Do nothing here
            }
          }
        }

        Object bkgObj = settings.get("background_color");
        if ((bkgObj != null) && (bkgObj instanceof String)) {
          int color = Integer.decode(((String) bkgObj)).intValue();
          int red = (color & 0xFF0000) >> 16;
          int green = (color & 0xFF00) >> 8;
          int blue = (color & 0xFF);
          tool_bar.setBackgroundColor(Color.rgb(red, green, blue));
          mCustomBackgroundColor = color | 0xFF000000;
          mCustomBackgroundColorEnable = true;
        }

        Object buttonsObj = settings.get("buttons");
        if (buttonsObj != null && (buttonsObj instanceof Vector<?>))
          buttons = (Vector<Object>) buttonsObj;
      }
    }

    if (params != null) {
      LinearLayout group = null;
      // First group should have gravity LEFT
      int gravity = Gravity.LEFT;
      for (int i = 0, lim = buttons.size(); i < lim; ++i) {
        Object param = buttons.elementAt(i);
        if (!(param instanceof Map<?, ?>)) throw new IllegalArgumentException("Hash expected");

        Map<Object, Object> hash = (Map<Object, Object>) param;

        View button = createButton(hash);
        if (button == null) {
          group = null;
          gravity = Gravity.CENTER;
          continue;
        }

        button.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
        if (group == null) {
          group = new LinearLayout(ctx);
          group.setGravity(gravity);
          group.setOrientation(LinearLayout.HORIZONTAL);
          group.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, FILL_PARENT, 1));
          tool_bar.addView(group);
        }
        group.addView(button);
      }

      // Last group should have gravity RIGHT
      if (group != null) {
        group.setGravity(Gravity.RIGHT);
        tool_bar.requestLayout();
      }
    }
  }
Beispiel #15
0
  private View createButton(Map<Object, Object> hash) {
    Context ctx = RhodesActivity.getContext();

    Object actionObj = hash.get("action");
    if (actionObj == null || !(actionObj instanceof String))
      throw new IllegalArgumentException("'action' should be String");

    String action = (String) actionObj;
    if (action.length() == 0) throw new IllegalArgumentException("'action' should not be empty");

    Drawable icon = null;
    String label = null;
    View.OnClickListener onClick = null;

    if (action.equalsIgnoreCase("back")) {
      icon = ctx.getResources().getDrawable(AndroidR.drawable.back);
      onClick = new ActionBack();
    } else if (action.equalsIgnoreCase("forward")) {
      if (RhodesService.isJQTouch_mode()) {
        return null;
      }
      icon = ctx.getResources().getDrawable(AndroidR.drawable.next);
      onClick = new ActionForward();
    } else if (action.equalsIgnoreCase("home")) {
      icon = ctx.getResources().getDrawable(AndroidR.drawable.home);
      onClick = new ActionHome();
    } else if (action.equalsIgnoreCase("options")) {
      icon = ctx.getResources().getDrawable(AndroidR.drawable.options);
      onClick = new ActionOptions();
    } else if (action.equalsIgnoreCase("refresh")) {
      icon = ctx.getResources().getDrawable(AndroidR.drawable.refresh);
      onClick = new ActionRefresh();
    } else if (action.equalsIgnoreCase("close") || action.equalsIgnoreCase("exit")) {
      icon = ctx.getResources().getDrawable(AndroidR.drawable.exit);
      onClick = new ActionExit();
    } else if (action.equalsIgnoreCase("separator")) return null;

    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(metrics);

    Object iconObj = hash.get("icon");
    if (iconObj != null) {
      if (!(iconObj instanceof String))
        throw new IllegalArgumentException("'icon' should be String");
      String iconPath = "apps/" + (String) iconObj;
      iconPath = RhoFileApi.normalizePath(iconPath);
      Bitmap bitmap = BitmapFactory.decodeStream(RhoFileApi.open(iconPath));
      if (bitmap == null) throw new IllegalArgumentException("Can't find icon: " + iconPath);
      bitmap.setDensity(DisplayMetrics.DENSITY_MEDIUM);
      icon = new BitmapDrawable(bitmap);
    }

    if (icon == null) {
      Object labelObj = hash.get("label");
      if (labelObj == null || !(labelObj instanceof String))
        throw new IllegalArgumentException("'label' should be String");
      label = (String) labelObj;
    }

    if (icon == null && label == null)
      throw new IllegalArgumentException("One of 'icon' or 'label' should be specified");

    if (onClick == null) onClick = new ActionCustom(action);

    View button;
    if (icon != null) {
      ImageButton btn = new ImageButton(ctx);
      btn.setImageDrawable(icon);
      button = btn;
      if (mCustomBackgroundColorEnable) {
        Drawable d = btn.getBackground();
        if (d != null) {
          d.setColorFilter(mCustomBackgroundColor, android.graphics.PorterDuff.Mode.SRC_OVER);
        } else {
          btn.setBackgroundColor(mCustomBackgroundColor);
        }
      }
    } else {
      Button btn = new Button(ctx);
      btn.setText(label);
      if (mCustomBackgroundColorEnable) {
        btn.setBackgroundColor(mCustomBackgroundColor);
        int gray =
            (((mCustomBackgroundColor & 0xFF0000) >> 16)
                    + ((mCustomBackgroundColor & 0xFF00) >> 8)
                    + ((mCustomBackgroundColor & 0xFF)))
                / 3;
        if (gray > 128) {
          btn.setTextColor(0xFF000000);
        } else {
          btn.setTextColor(0xFFFFFFFF);
        }
      }
      button = btn;
    }

    button.setOnClickListener(onClick);

    return button;
  }
Beispiel #16
0
 public static Context getContext() {
   RhodesActivity ra = RhodesActivity.getInstance();
   if (ra == null) throw new IllegalStateException("No rhodes activity instance at this moment");
   return ra;
 }
Beispiel #17
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 #18
0
    public void draw(Canvas canvas) {
      Rect rect = getBounds();

      int c_R = (color & 0xFF0000) >> 16;
      int c_G = (color & 0xFF00) >> 8;
      int c_B = (color & 0xFF);
      int height = rect.bottom - rect.top + 1;

      int gap = 3;

      Context ctx = RhodesActivity.getContext();
      DisplayMetrics metrics = new DisplayMetrics();
      WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
      wm.getDefaultDisplay().getMetrics(metrics);

      int lcd_density = metrics.densityDpi;
      if (lcd_density > 200) gap = 4;
      int left_gap = gap;
      int right_gap = gap;
      if (lcd_density > 200) left_gap += 1;
      if (lcd_density > 200) right_gap += 1;
      if (first_tab) left_gap = 0;
      if (last_tab) right_gap = 0;

      switch (style) {
        case NORMAL:
          {
            int dark_k = 16;
            int dark_k2 = 128;
            int c_dark_R = modifyColorComponent(c_R, -dark_k);
            int c_dark_G = modifyColorComponent(c_G, -dark_k);
            int c_dark_B = modifyColorComponent(c_B, -dark_k);

            int c_dark2_R = modifyColorComponent(c_R, -dark_k2);
            int c_dark2_G = modifyColorComponent(c_G, -dark_k2);
            int c_dark2_B = modifyColorComponent(c_B, -dark_k2);

            int y0 = rect.top;
            int y1 = rect.top + ((height - gap) / 10);
            int y2 = rect.top + ((height - gap) / 2);
            int y3 = rect.bottom - ((height - gap) / 10) - gap;
            int y4 = rect.bottom - gap;

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y0,
                rect.right - right_gap,
                y1,
                c_dark2_R,
                c_dark2_G,
                c_dark2_B,
                c_dark_R,
                c_dark_G,
                c_dark_B);

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y1,
                rect.right - right_gap,
                y2,
                c_dark_R,
                c_dark_G,
                c_dark_B,
                c_R,
                c_G,
                c_B);

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y2,
                rect.right - right_gap,
                y3,
                c_R,
                c_G,
                c_B,
                c_dark_R,
                c_dark_G,
                c_dark_B);

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y3,
                rect.right - right_gap,
                y4,
                c_dark_R,
                c_dark_G,
                c_dark_B,
                c_dark2_R,
                c_dark2_G,
                c_dark2_B);

            Paint paint = new Paint();
            paint.setAntiAlias(false);
            paint.setARGB(32, 0, 0, 0);
            canvas.drawRect(
                rect.left + left_gap, rect.top, rect.left + left_gap + 1, rect.bottom - gap, paint);
            canvas.drawRect(
                rect.right - right_gap - 1,
                rect.top,
                rect.right - right_gap,
                rect.bottom - gap,
                paint);
          }
          break;
        case SELECTED:
          {
            int light_k = 16;
            int dark_k = 16;
            int light_k2 = 64;
            int dark_k2 = 64;

            int c_0_R = modifyColorComponent(c_R, light_k2);
            int c_0_G = modifyColorComponent(c_G, light_k2);
            int c_0_B = modifyColorComponent(c_B, light_k2);

            int c_1_R = modifyColorComponent(c_R, light_k);
            int c_1_G = modifyColorComponent(c_G, light_k);
            int c_1_B = modifyColorComponent(c_B, light_k);

            int c_3_R = modifyColorComponent(c_R, -dark_k);
            int c_3_G = modifyColorComponent(c_G, -dark_k);
            int c_3_B = modifyColorComponent(c_B, -dark_k);

            int c_4_R = modifyColorComponent(c_R, -dark_k2);
            int c_4_G = modifyColorComponent(c_G, -dark_k2);
            int c_4_B = modifyColorComponent(c_B, -dark_k2);

            int y0 = rect.top;
            int y1 = rect.top + ((height - gap) / 4);
            int y2 = rect.top + ((height - gap) / 2);
            int y3 = rect.bottom - ((height - gap) / 4) - gap;
            int y4 = rect.bottom - gap;

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y0,
                rect.right - right_gap,
                y1,
                c_0_R,
                c_0_G,
                c_0_B,
                c_1_R,
                c_1_G,
                c_1_B);

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y1,
                rect.right - right_gap,
                y2,
                c_1_R,
                c_1_G,
                c_1_B,
                c_R,
                c_G,
                c_B);

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y2,
                rect.right - right_gap,
                y3,
                c_R,
                c_G,
                c_B,
                c_3_R,
                c_3_G,
                c_3_B);

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y3,
                rect.right - right_gap,
                y4,
                c_3_R,
                c_3_G,
                c_3_B,
                c_4_R,
                c_4_G,
                c_4_B);

            Paint paint = new Paint();
            paint.setAntiAlias(false);
            paint.setARGB(32, 0, 0, 0);
            canvas.drawRect(
                rect.left + left_gap, rect.top, rect.left + left_gap + 1, rect.bottom, paint);
            canvas.drawRect(
                rect.right - right_gap - 1, rect.top, rect.right - right_gap, rect.bottom, paint);
            paint.setARGB(255, c_4_R, c_4_G, c_4_B);
            canvas.drawRect(rect.left, rect.bottom - gap, rect.right, rect.bottom - 1, paint);
          }
          break;
        case DISABLED:
          {
            c_R = (DISABLED_BKG_COLOR & 0xFF0000) >> 16;
            c_G = (DISABLED_BKG_COLOR & 0xFF00) >> 8;
            c_B = (DISABLED_BKG_COLOR & 0xFF);

            int dark_k = 0;
            int dark_k2 = 32;
            int c_dark_R = modifyColorComponent(c_R, -dark_k);
            int c_dark_G = modifyColorComponent(c_G, -dark_k);
            int c_dark_B = modifyColorComponent(c_B, -dark_k);

            int c_dark2_R = modifyColorComponent(c_R, -dark_k2);
            int c_dark2_G = modifyColorComponent(c_G, -dark_k2);
            int c_dark2_B = modifyColorComponent(c_B, -dark_k2);

            int y0 = rect.top;
            int y1 = rect.top + ((height - gap) / 10);
            int y2 = rect.top + ((height - gap) / 2);
            int y3 = rect.bottom - ((height - gap) / 10) - gap;
            int y4 = rect.bottom - gap;

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y0,
                rect.right - right_gap,
                y1,
                c_dark2_R,
                c_dark2_G,
                c_dark2_B,
                c_dark_R,
                c_dark_G,
                c_dark_B);

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y1,
                rect.right - right_gap,
                y2,
                c_dark_R,
                c_dark_G,
                c_dark_B,
                c_R,
                c_G,
                c_B);

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y2,
                rect.right - right_gap,
                y3,
                c_R,
                c_G,
                c_B,
                c_dark_R,
                c_dark_G,
                c_dark_B);

            drawVerticalGradient(
                canvas,
                rect.left + left_gap,
                y3,
                rect.right - right_gap,
                y4,
                c_dark_R,
                c_dark_G,
                c_dark_B,
                c_dark2_R,
                c_dark2_G,
                c_dark2_B);

            Paint paint = new Paint();
            paint.setAntiAlias(false);
            paint.setARGB(32, 0, 0, 0);
            canvas.drawRect(
                rect.left + left_gap, rect.top, rect.left + left_gap + 1, rect.bottom - gap, paint);
            canvas.drawRect(
                rect.right - right_gap - 1,
                rect.top,
                rect.right - right_gap,
                rect.bottom - gap,
                paint);
          }
          break;
      }
    }