コード例 #1
0
  @Override
  public void processProperties(KrollDict d) {

    if (d.containsKey(TiC.PROPERTY_PAGE_WIDTH)) {
      setPageWidth(d.get(TiC.PROPERTY_PAGE_WIDTH));
    }
    if (d.containsKey(TiC.PROPERTY_PAGE_OFFSET)) {
      setPageOffset(d.get(TiC.PROPERTY_PAGE_OFFSET));
    }

    if (d.containsKey(TiC.PROPERTY_VIEWS)) {
      setViews(d.get(TiC.PROPERTY_VIEWS));
    }

    if (d.containsKey(TiC.PROPERTY_CURRENT_PAGE)) {
      int page = d.optInt(TiC.PROPERTY_CURRENT_PAGE, 0);
      if (page > 0) {
        setCurrentPage(page);
      }
    }

    if (d.containsKey(TiC.PROPERTY_SHOW_PAGING_CONTROL)) {
      if (TiConvert.toBoolean(d, TiC.PROPERTY_SHOW_PAGING_CONTROL)) {
        showPager();
      }
    }

    if (d.containsKey(TiC.PROPERTY_SCROLLING_ENABLED)) {
      mEnabled = TiConvert.toBoolean(d, TiC.PROPERTY_SCROLLING_ENABLED);
    }

    if (d.containsKey(TiC.PROPERTY_OVER_SCROLL_MODE)) {
      if (Build.VERSION.SDK_INT >= 9) {
        mPager.setOverScrollMode(
            TiConvert.toInt(d.get(TiC.PROPERTY_OVER_SCROLL_MODE), View.OVER_SCROLL_ALWAYS));
      }
    }

    if (d.containsKey(TiC.PROPERTY_CACHE_SIZE)) {
      cacheSize = TiConvert.toInt(d, TiC.PROPERTY_CACHE_SIZE);
      if (cacheSize < 3) {
        // WHAT.  Let's make it something sensible.
        cacheSize = 3;
      }
      updateCacheSize();
    }

    if (d.containsKey(TiC.PROPERTY_TRANSITION)) {
      transition =
          TransitionHelper.transitionFromObject(
              (HashMap) d.get(TiC.PROPERTY_TRANSITION), null, null);
      mPager.updatePageTransformer();
    }
    super.processProperties(d);
  }
コード例 #2
0
 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);
   }
 }
コード例 #3
0
  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);
  }
コード例 #4
0
  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
  }
コード例 #5
0
 private void move(int index, boolean animated) {
   if (index < 0 || index >= mViews.size()) {
     Log.w(TAG, "Request to move to index " + index + " ignored, as it is out-of-bounds.");
     return;
   }
   // we dont to update page during scroll but immediately. Otherwise if we jump multiple page, we
   // will have multiple events!
   setCurrentPageIndex(index, animated);
   mPager.setCurrentItem(mCurIndex, animated);
 }
コード例 #6
0
  @Override
  public void onPageScrollStateChanged(int scrollState) {
    if (hardwaredDisabled) {
      hardwaredDisabled = false;
      enableHWAcceleration(nativeView);
    }
    mPager.requestDisallowInterceptTouchEvent(scrollState != ViewPager.SCROLL_STATE_IDLE);

    if (scrollState == ViewPager.SCROLL_STATE_DRAGGING) {
      updateCurrentPageDuringScroll = true;
      ((ScrollableViewProxy) proxy).fireScrollStart(mCurIndex, mViews.get(mCurIndex));
    } else if ((scrollState == ViewPager.SCROLL_STATE_IDLE) && isValidScroll) {
      int oldIndex = mCurIndex;
      {
        updateCurrentPageDuringScroll = false;
        ((ScrollableViewProxy) proxy).fireScrollEnd(mCurIndex, mViews.get(mCurIndex));
      }
      if (mCurIndex >= 0) {
        //				if (oldIndex >=0 && oldIndex != mCurIndex && oldIndex < mViews.size()) {
        //					// Don't know what these focused and unfocused
        //					// events are good for, but they were in our previous
        //					// scrollable implementation.
        //					// cf.
        // https://github.com/appcelerator/titanium_mobile/blob/20335d8603e2708b59a18bafbb91b7292278de8e/android/modules/ui/src/ti/modules/titanium/ui/widget/TiScrollableView.java#L260
        //					TiEventHelper.fireFocused(mViews.get(oldIndex));
        //				}
        //
        //				TiEventHelper.fireUnfocused(mViews.get(mCurIndex));
        if (oldIndex >= 0) {
          // oldIndex will be -1 if the view has just
          // been created and is setting currentPage
          // to something other than 0. In that case we
          // don't want a `scrollend` to fire.
          ((ScrollableViewProxy) proxy).fireScrollEnd(mCurIndex, mViews.get(mCurIndex));
        }

        if (shouldShowPager()) {
          showPager();
        }
      }

      // If we don't use this state variable to check if it's a valid
      // scroll, this event will fire when the view is first created
      // because on creation, the scroll state is initialized to
      // `idle` and this handler is called.
      isValidScroll = false;
    } else if (scrollState == ViewPager.SCROLL_STATE_SETTLING) {
      updateCurrentPageDuringScroll = false;
      ((ScrollableViewProxy) proxy).fireDragEnd(mCurIndex, mViews.get(mCurIndex));

      // Note that we just fired a `dragend` so the `onPageSelected`
      // handler below doesn't fire a `scrollend`.  Read below comment.
      justFiredDragEnd = true;
    }
  }
コード例 #7
0
 public void clearViewsList() {
   if (mViews == null || mViews.size() == 0) {
     return;
   }
   synchronized (viewsLock) {
     mPager.removeAllViews();
     for (TiViewProxy viewProxy : mViews) {
       viewProxy.releaseViews(true);
     }
     mViews.clear();
   }
 }
コード例 #8
0
 private void updateCacheSize() {
   //		if (cacheSize >= mViews.size()) {
   //			mPager.setOffscreenPageLimit(cacheSize);
   //			return;
   //		}
   int realCache = cacheSize / 2; // floored
   int rangeStart = mCurIndex - realCache;
   int rangeEnd = mCurIndex + realCache;
   if (rangeStart < 0) realCache -= rangeStart;
   if (rangeEnd > (mViews.size() - 1)) realCache += rangeEnd - mViews.size() + 1;
   mPager.setOffscreenPageLimit(realCache + 1);
 }
コード例 #9
0
 private void buildViewPager(Context context) {
   if (proxy.hasProperty(TiC.PROPERTY_LAYOUT)
       && TiConvert.toString(proxy.getProperty(TiC.PROPERTY_LAYOUT)).equals("vertical")) {
     mPager = new VViewPager(context);
     ((VViewPager) mPager).setOnPageChangeListener(this);
     mAdapter = new VViewPagerAdapter(mViews);
     verticalLayout = true;
   } else {
     mPager = new HViewPager(context);
     ((HViewPager) mPager).setOnPageChangeListener(this);
     mAdapter = new HViewPagerAdapter(mViews);
   }
   mPager.setAdapter(mAdapter);
 }
コード例 #10
0
 @Override
 public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {
   if (TiC.PROPERTY_CURRENT_PAGE.equals(key)) {
     setCurrentPage(TiConvert.toInt(newValue));
   } else if (TiC.PROPERTY_SHOW_PAGING_CONTROL.equals(key)) {
     boolean show = TiConvert.toBoolean(newValue);
     if (show) {
       showPager();
     } else {
       hidePager();
     }
   } else if (TiC.PROPERTY_SCROLLING_ENABLED.equals(key)) {
     mEnabled = TiConvert.toBoolean(newValue);
   } else if (TiC.PROPERTY_OVER_SCROLL_MODE.equals(key)) {
     if (Build.VERSION.SDK_INT >= 9) {
       mPager.setOverScrollMode(TiConvert.toInt(newValue, View.OVER_SCROLL_ALWAYS));
     }
   } else if (TiC.PROPERTY_CACHE_SIZE.equals(key)) {
     cacheSize = TiConvert.toInt(newValue);
     if (cacheSize < 3) {
       // WHAT.  Let's make it something sensible.
       cacheSize = 3;
     }
     updateCacheSize();
   } else if (TiC.PROPERTY_PAGE_WIDTH.equals(key)) {
     setPageWidth(newValue);
   } else if (TiC.PROPERTY_PAGE_OFFSET.equals(key)) {
     setPageOffset(newValue);
   } else if (TiC.PROPERTY_TRANSITION.equals(key)) {
     transition = TransitionHelper.transitionFromObject((HashMap) newValue, null, null);
     mPager.updatePageTransformer();
     nativeView.invalidate();
   } else {
     super.propertyChanged(key, oldValue, newValue, proxy);
   }
 }
コード例 #11
0
 @Override
 public void release() {
   if (mPager != null) {
     mPager.removeAllViews();
     //			for (int i = mPager.getChildCount() - 1; i >=  0; i--) {
     //				mPager.removeViewAt(i);
     //			}
   }
   if (mViews != null) {
     for (TiViewProxy viewProxy : mViews) {
       viewProxy.releaseViews(true);
     }
     mViews.clear();
   }
   super.release();
 }