Android Open Source - FootyNews Parallax Scroll View






From Project

Back to project page FootyNews.

License

The source code is released under:

MIT License

If you think the Android project FootyNews listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nirhart.parallaxscroll.views;
/* ww w.  j av a2 s.  co  m*/
import java.util.ArrayList;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;

import com.nirhart.parallaxscroll.R;

public class ParallaxScrollView extends ScrollView {

  private static final int DEFAULT_PARALLAX_VIEWS = 1;
  private static final float DEFAULT_INNER_PARALLAX_FACTOR = 1.9F;
  private static final float DEFAULT_PARALLAX_FACTOR = 1.9F;
  private int numOfParallaxViews = DEFAULT_PARALLAX_VIEWS;
  private float innerParallaxFactor = DEFAULT_PARALLAX_FACTOR;
  private float parallaxFactor = DEFAULT_PARALLAX_FACTOR;
  private ArrayList<ParallaxedView> parallaxedViews = new ArrayList<ParallaxedView>();

  public ParallaxScrollView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(context, attrs);
  }

  public ParallaxScrollView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context, attrs);
  }

  public ParallaxScrollView(Context context) {
    super(context);
  }
  
  protected void init(Context context, AttributeSet attrs) {
    TypedArray typeArray = context.obtainStyledAttributes(attrs, R.styleable.ParallaxScroll);
    this.parallaxFactor = typeArray.getFloat(R.styleable.ParallaxScroll_parallax_factor, DEFAULT_PARALLAX_FACTOR);
    this.innerParallaxFactor = typeArray.getFloat(R.styleable.ParallaxScroll_inner_parallax_factor, DEFAULT_INNER_PARALLAX_FACTOR);
    this.numOfParallaxViews = typeArray.getInt(R.styleable.ParallaxScroll_parallax_views_num, DEFAULT_PARALLAX_VIEWS);
    typeArray.recycle();
  }
  
  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();
    makeViewsParallax();
  }

  private void makeViewsParallax() {
    if (getChildCount() > 0 && getChildAt(0) instanceof ViewGroup) {
      ViewGroup viewsHolder = (ViewGroup) getChildAt(0);
      int numOfParallaxViews = Math.min(this.numOfParallaxViews, viewsHolder.getChildCount());
      for (int i = 0; i < numOfParallaxViews; i++) {
        ParallaxedView parallaxedView = new ScrollViewParallaxedItem(viewsHolder.getChildAt(i));
        parallaxedViews.add(parallaxedView);
      }
    }
  }
  
  @Override
  protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    super.onScrollChanged(l, t, oldl, oldt);
    float factor = parallaxFactor;
    for (ParallaxedView parallaxedView : parallaxedViews) {
      parallaxedView.setOffset((float)t / factor);
      factor *= innerParallaxFactor;
    }
  }
  
  protected class ScrollViewParallaxedItem extends ParallaxedView{

    public ScrollViewParallaxedItem(View view) {
      super(view);
    }

    @Override
    protected void translatePreICS(View view, float offset) {
      view.offsetTopAndBottom((int)offset - lastOffset);
      lastOffset = (int)offset;
    }
  }
}




Java Source Code List

com.nirhart.parallaxscroll.BuildConfig.java
com.nirhart.parallaxscroll.BuildConfig.java
com.nirhart.parallaxscroll.views.ParallaxExpandableListView.java
com.nirhart.parallaxscroll.views.ParallaxListViewHelper.java
com.nirhart.parallaxscroll.views.ParallaxListView.java
com.nirhart.parallaxscroll.views.ParallaxScrollView.java
com.nirhart.parallaxscroll.views.ParallaxedView.java
org.arasthel.googlenavdrawermenu.adapters.GoogleNavigationDrawerAdapter.java
org.arasthel.googlenavdrawermenu.utils.Utils.java
org.arasthel.googlenavdrawermenu.views.CheckableImageView.java
org.arasthel.googlenavdrawermenu.views.CheckableRelativeLayout.java
org.arasthel.googlenavdrawermenu.views.CheckedTextView.java
org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer.java
shared.ui.actionscontentview.ActionsContentView.java
shared.ui.actionscontentview.ActionsLayout.java
shared.ui.actionscontentview.BaseContainerController.java
shared.ui.actionscontentview.BuildConfig.java
shared.ui.actionscontentview.ContainerController.java
shared.ui.actionscontentview.ContentLayout.java
shared.ui.actionscontentview.EffectsController.java
taz.starz.footynews.MainActivity.java
taz.starz.footynews.OfflineReadActivity.java
taz.starz.footynews.SplashScreen.java
taz.starz.footynews.ViewOfflineActivity.java
taz.starz.footynews.ViewStoryActivity.java
taz.starz.footynews.adapter.CustomListAdapter.java
taz.starz.footynews.adapter.CustomOfflineReaderAdapter.java
taz.starz.footynews.fragments.BundesLigaFragment.java
taz.starz.footynews.fragments.LigaBBVAFragment.java
taz.starz.footynews.fragments.PremierLeagueFragment.java
taz.starz.footynews.fragments.SerieAFragment.java
taz.starz.footynews.library.DatabaseHandler.java
taz.starz.footynews.library.JSONParser.java
taz.starz.footynews.library.NetworkFunctions.java
taz.starz.footynews.library.NewsItem.java
taz.starz.footynews.library.SharedPref.java