コード例 #1
0
 public void testGetColorWithAlpha() {
   assertEquals(
       Color.parseColor("#00123456"),
       ScrollUtils.getColorWithAlpha(0, Color.parseColor("#FF123456")));
   assertEquals(
       Color.parseColor("#FF123456"),
       ScrollUtils.getColorWithAlpha(1, Color.parseColor("#FF123456")));
 }
コード例 #2
0
  @Override
  public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
    // Translate overlay and image
    float flexibleRange = mFlexibleSpaceImageHeight - mActionBarSize;
    int minOverlayTransitionY = mActionBarSize - mOverlayView.getHeight();
    ViewHelper.setTranslationY(
        mOverlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0));
    ViewHelper.setTranslationY(
        mImageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0));

    // Change alpha of overlay
    ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1));

    // Scale title text
    float scale =
        1
            + ScrollUtils.getFloat(
                (flexibleRange - scrollY) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA);
    ViewHelper.setPivotX(mTitleView, 0);
    ViewHelper.setPivotY(mTitleView, 0);
    ViewHelper.setScaleX(mTitleView, scale);
    ViewHelper.setScaleY(mTitleView, scale);

    // Translate title text
    int maxTitleTranslationY = (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale);
    int titleTranslationY = maxTitleTranslationY - scrollY;
    ViewHelper.setTranslationY(mTitleView, titleTranslationY);

    // Translate FAB
    int maxFabTranslationY = mFlexibleSpaceImageHeight - mFab.getHeight() / 2;
    float fabTranslationY =
        ScrollUtils.getFloat(
            -scrollY + mFlexibleSpaceImageHeight - mFab.getHeight() / 2,
            mActionBarSize - mFab.getHeight() / 2,
            maxFabTranslationY);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      // On pre-honeycomb, ViewHelper.setTranslationX/Y does not set margin,
      // which causes FAB's OnClickListener not working.
      FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFab.getLayoutParams();
      lp.leftMargin = mOverlayView.getWidth() - mFabMargin - mFab.getWidth();
      lp.topMargin = (int) fabTranslationY;
      mFab.requestLayout();
    } else {
      ViewHelper.setTranslationX(mFab, mOverlayView.getWidth() - mFabMargin - mFab.getWidth());
      ViewHelper.setTranslationY(mFab, fabTranslationY);
    }

    // Show/hide FAB
    if (fabTranslationY < mFlexibleSpaceShowFabOffset) {
      hideFab();
    } else {
      showFab();
    }
  }
  private void translateTab(int scrollY, boolean animated) {
    int flexibleSpaceImageHeight =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    int tabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height);
    View imageView = findViewById(R.id.image);
    View overlayView = findViewById(R.id.overlay);
    TextView titleView = (TextView) findViewById(R.id.title);

    // Translate overlay and image
    float flexibleRange = flexibleSpaceImageHeight - getActionBarSize();
    int minOverlayTransitionY = tabHeight - overlayView.getHeight();
    ViewHelper.setTranslationY(
        overlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0));
    ViewHelper.setTranslationY(
        imageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0));

    // Change alpha of overlay
    ViewHelper.setAlpha(overlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1));

    // Scale title text
    float scale =
        1
            + ScrollUtils.getFloat(
                (flexibleRange - scrollY - tabHeight) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA);
    setPivotXToTitle(titleView);
    ViewHelper.setPivotY(titleView, 0);
    ViewHelper.setScaleX(titleView, scale);
    ViewHelper.setScaleY(titleView, scale);

    // Translate title text
    int maxTitleTranslationY = flexibleSpaceImageHeight - tabHeight - getActionBarSize();
    int titleTranslationY = maxTitleTranslationY - scrollY;
    ViewHelper.setTranslationY(titleView, titleTranslationY);

    // If tabs are moving, cancel it to start a new animation.
    ViewPropertyAnimator.animate(mSlidingTabLayout).cancel();
    // Tabs will move between the top of the screen to the bottom of the image.
    float translationY =
        ScrollUtils.getFloat(
            -scrollY + mFlexibleSpaceHeight - mTabHeight, 0, mFlexibleSpaceHeight - mTabHeight);
    if (animated) {
      // Animation will be invoked only when the current tab is changed.
      ViewPropertyAnimator.animate(mSlidingTabLayout)
          .translationY(translationY)
          .setDuration(200)
          .start();
    } else {
      // When Fragments' scroll, translate tabs immediately (without animation).
      ViewHelper.setTranslationY(mSlidingTabLayout, translationY);
    }
  }
コード例 #4
0
  /* TOOLBAR ANIMATIONS */
  private void updateScroll(int scrollY) {
    float alpha =
        Math.min(
            1,
            (float) scrollY / (flexibleSpaceHeight - binding.rlAdvertisementInfo.getHeight() - 25));
    binding.toolbar.setBackgroundColor(ScrollUtils.getColorWithAlpha(alpha, toolbarColor));
    binding.toolbar.setTitleTextColor(ScrollUtils.getColorWithAlpha(alpha, titleColor));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      detailsView.changeStatusBarColor(ScrollUtils.getColorWithAlpha(alpha / 4, statusBarColor));
    }

    binding.rlAdvertisementInfo.setAlpha(1 - ((float) scrollY / (flexibleSpaceHeight / 3)));
  }
コード例 #5
0
ファイル: Page2Fragment.java プロジェクト: LivvyM/Breeze
 @Override
 public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
   int baseColor = getResources().getColor(R.color.Dark);
   float alpha = Math.min(1, (float) scrollY / mParallaxImageHeight);
   mToolbarView.setBackgroundColor(ScrollUtils.getColorWithAlpha(alpha, baseColor));
   ViewHelper.setTranslationY(convenientBanner, scrollY / 2);
 }
コード例 #6
0
ファイル: artFragment.java プロジェクト: CNadam/Pearl2015
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_art, container, false);

    final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
    Activity parentActivity = getActivity();
    if (parentActivity instanceof ObservableScrollViewCallbacks) {
      // Scroll to the specified offset after layout
      Bundle args = getArguments();
      if (args != null && args.containsKey(ARG_SCROLL_Y)) {
        final int scrollY = args.getInt(ARG_SCROLL_Y, 0);
        ScrollUtils.addOnGlobalLayoutListener(
            scrollView,
            new Runnable() {
              @Override
              public void run() {
                scrollView.scrollTo(0, scrollY);
              }
            });
      }
      scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
  }
コード例 #7
0
ファイル: Page2Fragment.java プロジェクト: LivvyM/Breeze
  private void initViews(View itemView) {
    convenientBanner = (ConvenientBanner) itemView.findViewById(R.id.convenientBanner);
    mToolbarView = itemView.findViewById(R.id.toolbar);
    mToolbarView.setBackgroundColor(
        ScrollUtils.getColorWithAlpha(0, getActivity().getResources().getColor(R.color.Dark)));

    mScrollView = (ObservableScrollView) itemView.findViewById(R.id.scroll);
    mScrollView.setScrollViewCallbacks(this);

    mParallaxImageHeight = getResources().getDimensionPixelSize(R.dimen.parallax_image_height);
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view =
        inflater.inflate(R.layout.fragment_flexiblespacewithimagelistview, container, false);

    final ObservableListView listView = (ObservableListView) view.findViewById(R.id.scroll);
    // Set padding view for ListView. This is the flexible space.
    View paddingView = new View(getActivity());
    final int flexibleSpaceImageHeight =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    AbsListView.LayoutParams lp =
        new AbsListView.LayoutParams(
            AbsListView.LayoutParams.MATCH_PARENT, flexibleSpaceImageHeight);
    paddingView.setLayoutParams(lp);

    // This is required to disable header's list selector effect
    paddingView.setClickable(true);

    listView.addHeaderView(paddingView);
    setDummyData(listView);
    // TouchInterceptionViewGroup should be a parent view other than ViewPager.
    // This is a workaround for the issue #117:
    // https://github.com/ksoichiro/Android-ObservableScrollView/issues/117
    listView.setTouchInterceptionViewGroup((ViewGroup) view.findViewById(R.id.fragment_root));

    // Scroll to the specified offset after layout
    Bundle args = getArguments();
    if (args != null && args.containsKey(ARG_SCROLL_Y)) {
      final int scrollY = args.getInt(ARG_SCROLL_Y, 0);
      ScrollUtils.addOnGlobalLayoutListener(
          listView,
          new Runnable() {
            @SuppressLint("NewApi")
            @Override
            public void run() {
              int offset = scrollY % flexibleSpaceImageHeight;
              listView.setSelectionFromTop(0, -offset);
            }
          });
      updateFlexibleSpace(scrollY, view);
    } else {
      updateFlexibleSpace(0, view);
    }

    listView.setScrollViewCallbacks(this);

    updateFlexibleSpace(0, view);

    return view;
  }
コード例 #9
0
  @Override
  public void initialize(Context context, ActivityDetailsBinding binding) {
    /* STORES CONTEXT */
    this.context = context;

    /* STORES BINDING */
    this.binding = binding;

    /* INITIALIZE VIEWS */
    binding.setAdvertisement(advertisement);

    Picasso.with(context)
        .load(advertisement.getImageLarge())
        .placeholder(R.mipmap.ic_image)
        .centerCrop()
        .fit()
        .into(binding.ivAdvertisement);

    binding.svActivityDetails.setScrollViewCallbacks(new ObservableScrollListener());
    ScrollUtils.addOnGlobalLayoutListener(binding.getRoot(), new GlobalLayoutListener());

    /* DEFINES VARIABLES USED TO CREATE TOOLBAR ANIMATION ON SCROLL */
    flexibleSpaceHeight =
        context.getResources().getDimensionPixelSize(R.dimen.activity_details_image_height);
    toolbarColor = ContextCompat.getColor(context, R.color.color_primary);
    titleColor = ContextCompat.getColor(context, R.color.white);
    statusBarColor = ContextCompat.getColor(context, R.color.black);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      /* CREATES THE LINK TO THE TRANSITION ANIMATION */
      ViewCompat.setTransitionName(binding.ivAdvertisement, CallManager.TRANSITION_IMAGE);
      ViewCompat.setTransitionName(
          binding.viewAdvertisementInfo.rlViewAdvertisementInfo, CallManager.TRANSITION_DETAILS);

      /* MAKES STATUS BAR TRANSPARENT */
      detailsView.initializeStatusBar();
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    cid = intent.getStringExtra("cid");
    uid = intent.getStringExtra("uid");
    tit = intent.getStringExtra("tit");
    setContentView(R.layout.activity_flexiblespacewithimagewithviewpagertab);
    ImageView image = (ImageView) findViewById(R.id.image);
    image.setImageResource(Util.bgrd(Integer.parseInt(cid)));
    mPagerAdapter = new NavigationAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mFlexibleSpaceHeight =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mTabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height);

    TextView titleView = (TextView) findViewById(R.id.title);
    titleView.setText(tit);

    mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
    mSlidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1);
    mSlidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.white));
    mSlidingTabLayout.setDistributeEvenly(true);
    mSlidingTabLayout.setViewPager(mPager);

    // Initialize the first Fragment's state when layout is completed.
    ScrollUtils.addOnGlobalLayoutListener(
        mSlidingTabLayout,
        new Runnable() {
          @Override
          public void run() {
            translateTab(0, false);
          }
        });
  }
コード例 #11
0
 public void testMixColors() {
   assertEquals(
       Color.parseColor("#000000"),
       ScrollUtils.mixColors(Color.parseColor("#000000"), Color.parseColor("#FFFFFF"), 0));
 }
コード例 #12
0
 public void testGetFloat() {
   Assert.assertEquals(1.0f, ScrollUtils.getFloat(1, 0, 2));
   assertEquals(0.0f, ScrollUtils.getFloat(-1, 0, 2));
   assertEquals(2.0f, ScrollUtils.getFloat(3, 0, 2));
 }
コード例 #13
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_profile);

    mFlexibleSpaceImageHeight =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mFlexibleSpaceShowFabOffset =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_show_fab_offset);
    mActionBarSize = getActionBarSize();
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mImageView = findViewById(R.id.image);
    mOverlayView = findViewById(R.id.overlay);
    mScrollView = (ObservableScrollView) findViewById(R.id.scroll);
    mScrollView.setScrollViewCallbacks(this);
    mTitleView = (TextView) findViewById(R.id.title);
    mTitleView.setText(getTitle());
    setTitle(null);
    mFab = findViewById(R.id.fab);
    mFab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), EditProfile.class);
            startActivity(intent);
          }
        });
    mFabMargin = getResources().getDimensionPixelSize(R.dimen.margin_standard);
    ViewHelper.setScaleX(mFab, 0);
    ViewHelper.setScaleY(mFab, 0);

    ScrollUtils.addOnGlobalLayoutListener(
        mScrollView,
        new Runnable() {
          @Override
          public void run() {
            mScrollView.scrollTo(0, mFlexibleSpaceImageHeight - mActionBarSize);

            // If you'd like to start from scrollY == 0, don't write like this:
            // mScrollView.scrollTo(0, 0);
            // The initial scrollY is 0, so it won't invoke onScrollChanged().
            // To do this, use the following:
            // onScrollChanged(0, false, false);

            // You can also achieve it with the following codes.
            // This causes scroll change from 1 to 0.
            mScrollView.scrollTo(0, 1);
            mScrollView.scrollTo(0, 0);
          }
        });

    File path =
        new File(Environment.getExternalStorageDirectory(), "/weHappening/profile_image.png");
    Bitmap b = null;
    if (path.exists()) {
      try {
        b = BitmapFactory.decodeStream(new FileInputStream(path));
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
      CircularImageView img = (CircularImageView) findViewById(R.id.imgPicker);
      img.setImageBitmap(b);
    } else {
      CircularImageView img = (CircularImageView) findViewById(R.id.imgPicker);
      img.setImageDrawable(getResources().getDrawable(R.drawable.ic_person));
    }
  }