コード例 #1
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    if (mScrollView != null) {
      measureChild(
          mScrollView,
          MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST),
          MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.AT_MOST));

      mScrollContentHeight = mScrollView.getChildAt(0).getMeasuredHeight();
      mScrollViewHeight = mScrollView.getMeasuredHeight();
    }
    if (mBackground != null) {
      int minHeight = 0;
      minHeight =
          (int) (mScrollViewHeight + mParallaxOffset * (mScrollContentHeight - mScrollViewHeight));
      minHeight = Math.max(minHeight, MeasureSpec.getSize(heightMeasureSpec));

      measureChild(
          mBackground,
          MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY),
          MeasureSpec.makeMeasureSpec(minHeight, MeasureSpec.EXACTLY));

      mBackgroundRight = getLeft() + mBackground.getMeasuredWidth();
      mBackgroundBottom = getTop() + mBackground.getMeasuredHeight();

      mScrollDiff =
          (float) (mBackground.getMeasuredHeight() - mScrollViewHeight)
              / (float) (mScrollContentHeight - mScrollViewHeight);
    }
  }
コード例 #2
0
  public QuranPageLayout(Context context) {
    super(context);
    this.context = context;
    ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR);
    Resources resources = context.getResources();
    final boolean isLandscape =
        resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    innerView = generateContentView(context, isLandscape);
    viewPaddingSmall = resources.getDimensionPixelSize(R.dimen.page_margin_small);
    viewPaddingLarge = resources.getDimensionPixelSize(R.dimen.page_margin_large);

    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    if (isLandscape && shouldWrapWithScrollView()) {
      scrollView = new ObservableScrollView(context);
      scrollView.setFillViewport(true);
      addView(scrollView, lp);
      scrollView.addView(innerView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
      scrollView.setOnScrollListener(this);
    } else {
      addView(innerView, lp);
    }

    if (areGradientsLandscape != isLandscape) {
      leftGradient = null;
      rightGradient = null;
      areGradientsLandscape = isLandscape;
    }

    if (lineDrawable == null) {
      lineDrawable = new ShapeDrawable(new RectShape());
      lineDrawable.setIntrinsicWidth(1);
      lineDrawable.setIntrinsicHeight(1);

      // these bitmaps are 11x1, so fairly small to keep both day and night versions around
      leftPageBorder =
          new BitmapDrawable(
              resources, BitmapFactory.decodeResource(resources, R.drawable.border_left));
      leftPageBorderNight =
          new BitmapDrawable(
              resources, BitmapFactory.decodeResource(resources, R.drawable.night_left_border));
      rightPageBorder =
          new BitmapDrawable(
              resources, BitmapFactory.decodeResource(resources, R.drawable.border_right));
      rightPageBorderNight =
          new BitmapDrawable(
              resources, BitmapFactory.decodeResource(resources, R.drawable.night_right_border));
    }
    setWillNotDraw(false);
  }
コード例 #3
0
 public void attachToScrollView(
     @NonNull ObservableScrollView scrollView, ScrollDirectionListener listener) {
   ScrollViewScrollDetectorImpl scrollDetector = new ScrollViewScrollDetectorImpl();
   scrollDetector.setListener(listener);
   scrollDetector.setScrollThreshold(mScrollThreshold);
   scrollView.setOnScrollChangedListener(scrollDetector);
 }
コード例 #4
0
ファイル: DetailActivity.java プロジェクト: lubeast/Flipper
 @Override
 public void onWindowFocusChanged(boolean hasFocus) {
     super.onWindowFocusChanged(hasFocus);
     if (hasFocus) {
         showTop = layoutReason.getTop();
         scrollViewTop = winchanceScrollView.getTop();
         int height = outRect.height() - 2 * linearLayoutShowContent.getHeight();
         stickyTop = linearLayoutShowContent.getTop() - height;
     }
 }
コード例 #5
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRootView = inflater.inflate(R.layout.fragment_article_detail, container, false);
    mDrawInsetsFrameLayout =
        (DrawInsetsFrameLayout) mRootView.findViewById(R.id.draw_insets_frame_layout);
    mDrawInsetsFrameLayout.setOnInsetsCallback(
        new DrawInsetsFrameLayout.OnInsetsCallback() {
          @Override
          public void onInsetsChanged(Rect insets) {
            mTopInset = insets.top;
          }
        });

    mScrollView = (ObservableScrollView) mRootView.findViewById(R.id.scrollview);
    mScrollView.setCallbacks(
        new ObservableScrollView.Callbacks() {
          @Override
          public void onScrollChanged() {
            mScrollY = mScrollView.getScrollY();
            getActivityCast().onUpButtonFloorChanged(mItemId, ArticleDetailFragment.this);
            mPhotoContainerView.setTranslationY((int) (mScrollY - mScrollY / PARALLAX_FACTOR));
            updateStatusBar();
          }
        });

    mPhotoView = (ImageView) mRootView.findViewById(R.id.photo);
    mPhotoContainerView = mRootView.findViewById(R.id.photo_container);

    mStatusBarColorDrawable = new ColorDrawable(0);

    mRootView
        .findViewById(R.id.share_fab)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                startActivity(
                    Intent.createChooser(
                        ShareCompat.IntentBuilder.from(getActivity())
                            .setType("text/plain")
                            .setText("Some sample text")
                            .getIntent(),
                        getString(R.string.action_share)));
              }
            });

    bindViews();
    updateStatusBar();
    return mRootView;
  }
コード例 #6
0
ファイル: MainActivity.java プロジェクト: lzbfeng/WeatherShow
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Global.myAsset = getAssets();
    setContentView(R.layout.activity_main);
    scrollView = (ObservableScrollView) findViewById(R.id.scrollview);
    scrollView.setScrollViewListener(this);
    initBaseInfo();
    initViewPager();

    Intent intent = new Intent();
    intent.setClass(this, MyService.class);
    startService(intent);

    broadcastMain = new BroadcastMain();
    IntentFilter filter = new IntentFilter();
    filter.addAction(MyService.BROADCASTACTION);
    registerReceiver(broadcastMain, filter);
  }
コード例 #7
0
ファイル: DetailActivity.java プロジェクト: lubeast/Flipper
    private void setOnclickListener() {
        ImageView likeImageView = (ImageView)findViewById(R.id.imageview_comment_select_like);
        likeImageView.setOnClickListener(commentSelectOnclickListener());
        ImageView unlikeImageView = (ImageView)findViewById(R.id.imageview_comment_select_unlike);
        unlikeImageView.setOnClickListener(commentSelectOnclickListener());
        RelativeLayout leftWatch = (RelativeLayout)findViewById(R.id.relativelayout_left_watch);
        leftWatch.setOnClickListener(watchOnclickListener());
        RelativeLayout leftApprove = (RelativeLayout) findViewById(R.id.relativelayout_left_approve);
        leftApprove.setOnClickListener(watchOnclickListener());
        RelativeLayout rightWatch = (RelativeLayout) findViewById(R.id.relativelayout_right_watch);
        rightWatch.setOnClickListener(watchOnclickListener());
        RelativeLayout rightApprove = (RelativeLayout)findViewById(R.id.relativelayout_right_approve);
        rightApprove.setOnClickListener(watchOnclickListener());
        relativeLayoutSeemore.setOnClickListener(watchOnclickListener());
        winchanceScrollView.setOnScrollListener(this);

        imageViewLike = (ImageView) findViewById(R.id.imageview_comment_select_like1);
        imageViewLike.setOnClickListener(commentSelectOnclickListener());
        imageViewUnlike = (ImageView) findViewById(R.id.imageview_comment_select_unlike1);
        imageViewUnlike.setOnClickListener(commentSelectOnclickListener());
    }
コード例 #8
0
  private void organiseForgroundView(final View forground) {
    final int insertPos = getChildCount() - 1;

    // See if its a observable scroll view?
    if (forground instanceof ObservableScrollView) {
      // Attach the callback to it.
      mScrollView = (ObservableScrollView) forground;
    } else if (forground instanceof ViewGroup && !(forground instanceof ScrollView)) {
      // See if it is a view group but not a scroll view and wrap it
      // with an observable ScrollView
      mScrollView = new ObservableScrollView(getContext(), null);
      removeView(forground);
      mScrollView.addView(forground);
      addView(mScrollView, insertPos);
    } else if (forground instanceof ScrollView) {
      final View child;
      if (((ScrollView) forground).getChildCount() > 0)
        child = ((ScrollView) forground).getChildAt(0);
      else child = null;

      mScrollView = new ObservableScrollView(getContext(), null);
      removeView(forground);
      if (child != null) mScrollView.addView(child);
      addView(mScrollView, insertPos);
    } else if (forground instanceof View) {
      mScrollView = new ObservableScrollView(getContext(), null);
      removeView(forground);
      mScrollView.addView(forground);
      addView(mScrollView, insertPos);
    }
    if (mScrollView != null) {
      mScrollView.setLayoutParams(forground.getLayoutParams());
      mScrollView.setCallbacks(mScrollCallbacks);
      mScrollView.setFillViewport(true);
    }
  }
コード例 #9
0
 public void smoothScrollLayoutTo(int y) {
   scrollView.smoothScrollTo(scrollView.getScrollX(), y);
 }
コード例 #10
0
 public int getCurrentScrollY() {
   return scrollView == null ? 0 : scrollView.getScrollY();
 }
コード例 #11
0
ファイル: DetailActivity.java プロジェクト: lubeast/Flipper
 /**
  * 得到高度
  */
 private void getTopDistance() {
     showTop = layoutReason.getTop();
     scrollViewTop = winchanceScrollView.getTop();
     int height = outRect.height() - 2 * linearLayoutShowContent.getHeight();
     stickyTop = linearLayoutShowContent.getTop() - height;
 }
コード例 #12
0
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    final int parentLeft = getPaddingLeft();
    final int parentRight = right - left - getPaddingRight();
    final int parentTop = getPaddingTop();
    final int parentBottom = bottom - top - getPaddingBottom();
    if (mScrollView != null && mScrollView.getVisibility() != GONE) {
      final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mScrollView.getLayoutParams();

      final int width = mScrollView.getMeasuredWidth();
      final int height = mScrollView.getMeasuredHeight();

      int childLeft;
      int childTop;

      int gravity = lp.gravity;
      if (gravity == -1) {
        gravity = DEFAULT_CHILD_GRAVITY;
      }

      final int horizontalGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
      final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

      switch (horizontalGravity) {
        case Gravity.LEFT:
          childLeft = parentLeft + lp.leftMargin;
          break;
        case Gravity.CENTER_HORIZONTAL:
          childLeft =
              parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin;
          break;
        case Gravity.RIGHT:
          childLeft = parentRight - width - lp.rightMargin;
          break;
        default:
          childLeft = parentLeft + lp.leftMargin;
      }

      switch (verticalGravity) {
        case Gravity.TOP:
          childTop = parentTop + lp.topMargin;
          break;
        case Gravity.CENTER_VERTICAL:
          childTop =
              parentTop + (parentBottom - parentTop - height) / 2 + lp.topMargin - lp.bottomMargin;
          break;
        case Gravity.BOTTOM:
          childTop = parentBottom - height - lp.bottomMargin;
          break;
        default:
          childTop = parentTop + lp.topMargin;
      }

      mScrollView.layout(childLeft, childTop, childLeft + width, childTop + height);
    }

    if (mBackground != null) {
      final int scrollYCenterOffset = -mScrollView.getScrollY();
      final int offset = (int) (scrollYCenterOffset * mScrollDiff);
      // Log.d(TAG, "Layout Scroll Y: " + scrollYCenterOffset +
      // " ScrollDiff: " + mScrollDiff
      // + " Background Offset:" + offset);
      mBackground.layout(getLeft(), offset, mBackgroundRight, offset + mBackgroundBottom);
    }
  }