Beispiel #1
0
  public static boolean copy(String path) {
    // Log.d(TAG, "Copy " + path + " to FS");
    InputStream is = null;
    OutputStream os = null;
    try {
      RhodesService r = RhodesService.getInstance();

      is = am.open(path);

      File dst = new File(r.getRootPath(), path);
      File parent = dst.getParentFile();
      if (parent == null) return false;
      parent.mkdirs();

      os = new FileOutputStream(dst);
      byte[] buf = new byte[4096];
      int len;
      while ((len = is.read(buf)) > 0) os.write(buf, 0, len);

      // Log.d(TAG, "File " + path + " copied");
      return true;
    } catch (Exception e) {
      // Log.e(TAG, "Can not copy " + path + " to FS");
      return false;
    } finally {
      try {
        if (is != null) is.close();
        if (os != null) os.close();
      } catch (Exception e1) {
        // Ignore
      }
    }
  }
Beispiel #2
0
  @Override
  public void navigate(String url, int index) {
    if (DEBUG) Log.d(TAG, "navigate: url=" + url);

    RhodesService r = RhodesService.getInstance();
    MainView mainView = r.getMainView();
    SimpleMainView v = new SimpleMainView(mainView);
    r.setMainView(v);
    // getWebView(0).loadUrl(url);
    v.navigate(url, 0);
  }
Beispiel #3
0
  public static void init() throws IOException {
    nativeInit();

    am = RhodesService.getInstance().getAssets();

    fillStatTable();
  }
Beispiel #4
0
 public void navigate(String url, int index) {
   String cleared_url = processForNativeView(url);
   if (cleared_url.length() > 0) {
     // check for handle because if we call loadUrl - WebView do not check this url for handle
     if (!RhodesService.getInstance().handleUrlLoading(cleared_url)) {
       webView.loadUrl(cleared_url);
     }
   }
 }
Beispiel #5
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 #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;
  }
Beispiel #7
0
  public static String[] getChildren(String path) {
    try {
      // Merge children from both packed assets and file system
      String[] list1 = am.list(path);
      File f = new File(RhodesService.getInstance().getRootPath(), path);
      String[] list2 = f.list();

      List<String> list = new ArrayList<String>();
      if (list1 != null) for (String child : list1) list.add(child);
      if (list2 != null)
        for (String child : list2) {
          if (list.contains(child)) continue;
          list.add(child);
        }

      return list.toArray(new String[] {});
    } catch (IOException e) {
      return null;
    }
  }
Beispiel #8
0
    private void onTabChangedIndex(int index, boolean byself) {
      // Utils.platformLog("#$#$#$#$#$#$#$#$#$", "onTabChangedIndex( "+String.valueOf(index)+" )");
      int new_tabIndex = index;
      sel_col = 0;
      sel_col_enable = false;
      TabData data = tabData.elementAt(new_tabIndex);
      if (data == null) {
        return;
      }
      if (data.disabled) {
        // return to previous selected
        tabHost.setCurrentTab(tabIndex);
        return;
      }
      boolean real_change = (tabIndex != new_tabIndex);
      if (real_change && byself) {
        tabHost.setCurrentTab(new_tabIndex);
        // all will processed when onTabChanged received
        return;
      }
      tabIndex = new_tabIndex;

      if (real_change && (mChangeTabCallback != null)) {
        callChangeTabCallback(tabIndex);
      }

      if ((data.reload /*|| real_change*/) || !data.loaded) {
        if (mIsReallyOnScreen) {
          RhodesService.loadUrl(data.url);
          data.loaded = true;
        }
      }
      sel_col = data.selected_color;
      sel_col_enable = data.selected_color_enabled;

      if (mIsReallyOnScreen && real_change) {
        processTabHostColors(tabHost, sel_col, sel_col_enable);
      }
    }
Beispiel #9
0
 public void goBack() {
   RhodesService.navigateBack();
 }
Beispiel #10
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 #11
0
 public void onClick(View v) {
   restoreWebView();
   RhodesService.exit();
 }
Beispiel #12
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 #13
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);
  }