public TiUIScrollableView(ScrollableViewProxy proxy, TiBaseActivity activity) {
    super(proxy);
    //		activity.addConfigurationChangedListener(this);

    mViews = new ArrayList<TiViewProxy>();
    viewsLock = new Object();
    buildViewPager(activity);
    TiCompositeLayout.LayoutParams params = new LayoutParams();
    params.optionWidth = new TiDimension("100%", TiDimension.TYPE_WIDTH);
    params.optionHeight = new TiDimension("100%", TiDimension.TYPE_HEIGHT);
    mPager.setLayoutParams(params);
    mContainer =
        new TiViewPagerLayout(activity) {
          @Override
          public boolean dispatchTouchEvent(MotionEvent event) {
            if (touchPassThrough == true) return false;
            return super.dispatchTouchEvent(event);
          }
        };
    mContainer.addView((View) mPager, params);
    mPagingControl = buildPagingControl(activity);
    mContainer.addView(mPagingControl, buildFillLayoutParams());

    setNativeView(mContainer);
  }
  public TiUIActionBarTabGroup(TabGroupProxy proxy, TiBaseActivity activity) {
    super(proxy, activity);

    tabActivity = new WeakReference<TiBaseActivity>(activity);

    activity.addOnLifecycleEventListener(this);

    // Setup the action bar for navigation tabs.
    actionBar = activity.getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(true);

    swipeable = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_SWIPEABLE), true);

    tabGroupPagerAdapter =
        new TabGroupPagerAdapter(((ActionBarActivity) activity).getSupportFragmentManager());

    tabGroupViewPager =
        (new ViewPager(proxy.getActivity()) {
          @Override
          public boolean onTouchEvent(MotionEvent event) {
            return swipeable ? super.onTouchEvent(event) : false;
          }

          @Override
          public boolean onInterceptTouchEvent(MotionEvent event) {
            return swipeable ? super.onInterceptTouchEvent(event) : false;
          }
        });

    tabGroupViewPager.setAdapter(tabGroupPagerAdapter);

    tabGroupViewPager.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {

          @Override
          public void onPageSelected(int position) {
            // on changing the page simply select the tab
            actionBar.setSelectedNavigationItem(position);
          }

          @Override
          public void onPageScrolled(int arg0, float arg1, int arg2) {}

          @Override
          public void onPageScrollStateChanged(int arg0) {}
        });

    TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
    params.autoFillsHeight = true;
    params.autoFillsWidth = true;
    ((ViewGroup) activity.getLayout()).addView(tabGroupViewPager, params);
    setNativeView(tabGroupViewPager);
  }
 private void setPageOffset(Object value) {
   if (verticalLayout) {
     TiCompositeLayout.LayoutParams params = (LayoutParams) mPager.getLayoutParams();
     params.optionHeight =
         TiConvert.toTiDimension(TiConvert.toString(value), TiDimension.TYPE_TOP);
     mPager.setLayoutParams(params);
   } else {
     TiCompositeLayout.LayoutParams params = (LayoutParams) mPager.getLayoutParams();
     params.optionWidth =
         TiConvert.toTiDimension(TiConvert.toString(value), TiDimension.TYPE_LEFT);
     mPager.setLayoutParams(params);
   }
 }
  private void setPageWidth(Object value) {
    if (verticalLayout) {
      TiCompositeLayout.LayoutParams params = (LayoutParams) mPager.getLayoutParams();
      params.optionHeight =
          TiConvert.toTiDimension(TiConvert.toString(value), TiDimension.TYPE_HEIGHT);
      mPager.setLayoutParams(params);
    } else {
      TiCompositeLayout.LayoutParams params = (LayoutParams) mPager.getLayoutParams();
      params.optionWidth =
          TiConvert.toTiDimension(TiConvert.toString(value), TiDimension.TYPE_WIDTH);
      mPager.setLayoutParams(params);
    }
    ((ViewGroup) nativeView).setClipChildren(false);

    hardwaredDisabled = true;
    disableHWAcceleration(nativeView); // we ll reenable it later because of a glitch
  }
 protected void refreshOldStyleRow() {
   TableViewRowProxy rp = getRowProxy();
   if (!rp.hasProperty(TiC.PROPERTY_TOUCH_ENABLED)) {
     rp.setProperty(TiC.PROPERTY_TOUCH_ENABLED, false);
   }
   if (views == null) {
     views = new ArrayList<TiUIView>();
     views.add(new TiUILabel(rp));
   }
   TiUILabel t = (TiUILabel) views.get(0);
   t.setProxy(rp);
   t.processProperties(filterProperties(rp.getProperties()));
   View v = t.getNativeView();
   if (v.getParent() == null) {
     TiCompositeLayout.LayoutParams params = (TiCompositeLayout.LayoutParams) t.getLayoutParams();
     params.optionLeft = new TiDimension(5, TiDimension.TYPE_LEFT);
     params.optionRight = new TiDimension(5, TiDimension.TYPE_RIGHT);
     params.autoFillsWidth = true;
     content.addView(v, params);
   }
 }
 private TiCompositeLayout.LayoutParams buildFillLayoutParams() {
   TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
   params.autoFillsHeight = true;
   params.autoFillsWidth = true;
   return params;
 }
예제 #7
0
  public TiUIWebView(TiViewProxy proxy) {
    super(proxy);
    this.isFocusable = true;
    TiWebView webView =
        isHTCSenseDevice()
            ? new TiWebView(proxy.getActivity())
            : new NonHTCWebView(proxy.getActivity());
    webView.setVerticalScrollbarOverlay(true);

    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setJavaScriptEnabled(true);
    settings.setSupportMultipleWindows(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setAllowFileAccess(true);
    settings.setDomStorageEnabled(
        true); // Required by some sites such as Twitter. This is in our iOS WebView too.
    File path = TiApplication.getInstance().getFilesDir();
    if (path != null) {
      settings.setDatabasePath(path.getAbsolutePath());
      settings.setDatabaseEnabled(true);
    }

    File cacheDir = TiApplication.getInstance().getCacheDir();
    if (cacheDir != null) {
      settings.setAppCacheEnabled(true);
      settings.setAppCachePath(cacheDir.getAbsolutePath());
    }

    // enable zoom controls by default
    boolean enableZoom = true;

    if (proxy.hasProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)) {
      enableZoom = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS));
    }

    settings.setBuiltInZoomControls(enableZoom);
    settings.setSupportZoom(enableZoom);

    if (TiC.JELLY_BEAN_OR_GREATER) {
      settings.setAllowUniversalAccessFromFileURLs(
          true); // default is "false" for JellyBean, TIMOB-13065
    }

    // We can only support webview settings for plugin/flash in API 8 and higher.
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ECLAIR_MR1) {
      initializePluginAPI(webView);
    }

    boolean enableJavascriptInterface =
        TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_JAVASCRIPT_INTERFACE), true);
    chromeClient = new TiWebChromeClient(this);
    webView.setWebChromeClient(chromeClient);
    client = new TiWebViewClient(this, webView);
    webView.setWebViewClient(client);
    if (Build.VERSION.SDK_INT > 16 || enableJavascriptInterface) {
      client.getBinding().addJavascriptInterfaces();
    }
    webView.client = client;

    if (proxy instanceof WebViewProxy) {
      WebViewProxy webProxy = (WebViewProxy) proxy;
      String username = webProxy.getBasicAuthenticationUserName();
      String password = webProxy.getBasicAuthenticationPassword();
      if (username != null && password != null) {
        setBasicAuthentication(username, password);
      }
      webProxy.clearBasicAuthentication();
    }

    TiCompositeLayout.LayoutParams params = getLayoutParams();
    params.autoFillsHeight = true;
    params.autoFillsWidth = true;

    setNativeView(webView);
  }
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int count = getChildCount();

    int left = 0;
    int top = 0;
    int right = r - l;
    int bottom = b - t;

    if (needsSort) {
      if (count > 1) { // No need to sort one item.
        viewSorter.clear();
        for (int i = 0; i < count; i++) {
          View child = getChildAt(i);
          TiCompositeLayout.LayoutParams params =
              (TiCompositeLayout.LayoutParams) child.getLayoutParams();
          params.index = i;
          viewSorter.add(child);
        }

        detachAllViewsFromParent();
        int i = 0;
        for (View child : viewSorter) {
          attachViewToParent(child, i++, child.getLayoutParams());
        }
      }
      needsSort = false;
    }

    int[] horizontal = new int[2];
    int[] vertical = new int[2];

    int currentHeight = 0;
    for (int i = 0; i < count; i++) {
      View child = getChildAt(i);
      TiCompositeLayout.LayoutParams params =
          (TiCompositeLayout.LayoutParams) child.getLayoutParams();
      if (child.getVisibility() != View.GONE) {
        // Dimension is required from Measure. Positioning is determined here.
        int childMeasuredWidth = child.getMeasuredWidth();
        int childMeasuredHeight = child.getMeasuredHeight();

        computePosition(
            params.optionLeft, params.optionRight, childMeasuredWidth, left, right, horizontal);

        if (this.vertical) {
          computeVerticalLayoutPosition(
              currentHeight,
              params.optionTop,
              params.optionBottom,
              childMeasuredHeight,
              top,
              bottom,
              vertical);
        } else {
          computePosition(
              params.optionTop, params.optionBottom, childMeasuredHeight, top, bottom, vertical);
        }

        if (DBG) {
          Log.d(
              TAG,
              child.getClass().getName()
                  + " {"
                  + horizontal[0]
                  + ","
                  + vertical[0]
                  + ","
                  + horizontal[1]
                  + ","
                  + vertical[1]
                  + "}");
        }

        int newWidth = horizontal[1] - horizontal[0];
        int newHeight = vertical[1] - vertical[0];
        if (newWidth != childMeasuredWidth || newHeight != childMeasuredHeight) {

          int newWidthSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
          int newHeightSpec = MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY);
          child.measure(newWidthSpec, newHeightSpec);
        }

        child.layout(horizontal[0], vertical[0], horizontal[1], vertical[1]);

        currentHeight += newHeight;
        if (params.optionTop != NOT_SET) {
          currentHeight += params.optionTop;
        }
      }
    }
  }