Android Open Source - JiangHomeStyle_Android_Phone Custom Scroll View






From Project

Back to project page JiangHomeStyle_Android_Phone.

License

The source code is released under:

Apache License

If you think the Android project JiangHomeStyle_Android_Phone 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.cidesign.jianghomestylephone.widget;
// ww  w.  j a v  a 2 s.c  o  m
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;

public class CustomScrollView extends ScrollView
{
  private static final String TAG = CustomScrollView.class.getSimpleName();

  private RelativeLayout landscapeAnimPanel;
  private RelativeLayout humanityAnimPanel;
  private RelativeLayout storyAnimPanel;
  private RelativeLayout communityAnimPanel;

  // ????????????
  private float xDistance, yDistance, xLast, yLast;

  private boolean landscapeIsAnimation = true;
  private boolean humanityIsAnimation = true;
  private boolean storyIsAnimation = true;
  private boolean communityIsAnimation = true;

  private int animHeight = 0;

  public void setLandscapeAnimPanel(RelativeLayout landscapeAnimPanel)
  {
    this.landscapeAnimPanel = landscapeAnimPanel;
  }

  public void setHumanityAnimPanel(RelativeLayout humanityAnimPanel)
  {
    this.humanityAnimPanel = humanityAnimPanel;
  }

  public void setStoryAnimPanel(RelativeLayout storyAnimPanel)
  {
    this.storyAnimPanel = storyAnimPanel;
  }

  public void setCommunityAnimPanel(RelativeLayout communityAnimPanel)
  {
    this.communityAnimPanel = communityAnimPanel;
  }

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

  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev)
  {
    switch (ev.getAction())
    {
    case MotionEvent.ACTION_DOWN:
      xDistance = yDistance = 0f;
      xLast = ev.getX();
      yLast = ev.getY();
      break;
    case MotionEvent.ACTION_MOVE:
      final float curX = ev.getX();
      final float curY = ev.getY();

      xDistance += Math.abs(curX - xLast);
      yDistance += Math.abs(curY - yLast);
      xLast = curX;
      yLast = curY;
      if (xDistance > yDistance)
      {
        return false;
      }
    }

    return super.onInterceptTouchEvent(ev);
  }

  @Override
  public boolean onTouchEvent(MotionEvent ev)
  {
    if (animHeight == 0)
    {
      animHeight = 100;
    }

    if (landscapeIsAnimation && landscapeAnimPanel != null && (this.getScrollY() + 800 >= landscapeAnimPanel.getY()))
    {
      landscapeIsAnimation = false;
      Animation animation = new TranslateAnimation(0, 0, 0, -animHeight);
      animation.setDuration(1000);
      animation.setAnimationListener(new UpPushAnimation(landscapeAnimPanel, animHeight));
      landscapeAnimPanel.startAnimation(animation);
    }

    if (humanityIsAnimation && humanityAnimPanel != null && (this.getScrollY() + 800 >= humanityAnimPanel.getY()))
    {
      humanityIsAnimation = false;
      Animation animation = new TranslateAnimation(0, 0, 0, -animHeight);
      animation.setDuration(1000);
      animation.setAnimationListener(new UpPushAnimation(humanityAnimPanel, animHeight));
      humanityAnimPanel.startAnimation(animation);
    }

    if (storyIsAnimation && storyAnimPanel != null && (this.getScrollY() + 800 >= storyAnimPanel.getY()))
    {
      storyIsAnimation = false;
      Animation animation = new TranslateAnimation(0, 0, 0, -animHeight);
      animation.setDuration(1000);
      animation.setAnimationListener(new UpPushAnimation(storyAnimPanel, animHeight));
      storyAnimPanel.startAnimation(animation);
    }

    if (communityIsAnimation && communityAnimPanel != null && (this.getScrollY() + 800 >= communityAnimPanel.getY()))
    {
      communityIsAnimation = false;
      Animation animation = new TranslateAnimation(0, 0, 0, -animHeight);
      animation.setDuration(1000);
      animation.setAnimationListener(new UpPushAnimation(communityAnimPanel, animHeight));
      communityAnimPanel.startAnimation(animation);
    }

    return super.onTouchEvent(ev);
  }

  class UpPushAnimation implements AnimationListener
  {
    private View view;
    private int animHeight;

    public UpPushAnimation(View view, int animHeight)
    {
      this.view = view;
      this.animHeight = animHeight;
    }

    @Override
    public void onAnimationEnd(Animation animation)
    {
      view.clearAnimation();
      LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) view.getLayoutParams();
      lp.setMargins(lp.leftMargin, lp.topMargin - animHeight, lp.rightMargin, lp.bottomMargin);
      view.setLayoutParams(lp);
    }

    @Override
    public void onAnimationRepeat(Animation animation)
    {
      // TODO Auto-generated method stub

    }

    @Override
    public void onAnimationStart(Animation animation)
    {
      // TODO Auto-generated method stub

    }

  }
}




Java Source Code List

com.cidesign.jianghomestylephone.DetailActivity.java
com.cidesign.jianghomestylephone.JiangActivity.java
com.cidesign.jianghomestylephone.MainActivity.java
com.cidesign.jianghomestylephone.SplashActivity.java
com.cidesign.jianghomestylephone.adapter.CommunityViewpagerAdapter.java
com.cidesign.jianghomestylephone.adapter.HumanityViewpagerAdapter.java
com.cidesign.jianghomestylephone.adapter.LandscapeViewpagerAdapter.java
com.cidesign.jianghomestylephone.adapter.LayoutCaculateAdapter.java
com.cidesign.jianghomestylephone.adapter.StoryViewpagerAdapter.java
com.cidesign.jianghomestylephone.async.AsyncDownTask.java
com.cidesign.jianghomestylephone.async.AsyncInitCommunityData.java
com.cidesign.jianghomestylephone.async.AsyncInitData.java
com.cidesign.jianghomestylephone.async.AsyncInitHomeData.java
com.cidesign.jianghomestylephone.async.AsyncInitHumanityData.java
com.cidesign.jianghomestylephone.async.AsyncInitLandscapeData.java
com.cidesign.jianghomestylephone.async.AsyncInitStoryData.java
com.cidesign.jianghomestylephone.db.DatabaseConfigUtil.java
com.cidesign.jianghomestylephone.db.DatabaseHelper.java
com.cidesign.jianghomestylephone.entity.ArticleEntity.java
com.cidesign.jianghomestylephone.entity.FileListEntity.java
com.cidesign.jianghomestylephone.entity.LayoutEntity.java
com.cidesign.jianghomestylephone.entity.RelativeLayoutRulesEntity.java
com.cidesign.jianghomestylephone.http.ArticalOperation.java
com.cidesign.jianghomestylephone.http.DownLoadThread.java
com.cidesign.jianghomestylephone.service.DownloadService.java
com.cidesign.jianghomestylephone.tools.CategoryDataLoadingLogic.java
com.cidesign.jianghomestylephone.tools.FileOperationTools.java
com.cidesign.jianghomestylephone.tools.JiangCategory.java
com.cidesign.jianghomestylephone.tools.LayoutMarginSetting.java
com.cidesign.jianghomestylephone.tools.LoadingDataFromDB.java
com.cidesign.jianghomestylephone.tools.LoadingImageTools.java
com.cidesign.jianghomestylephone.tools.MD5Tools.java
com.cidesign.jianghomestylephone.tools.StorageUtils.java
com.cidesign.jianghomestylephone.tools.TimeTools.java
com.cidesign.jianghomestylephone.tools.WidgetCache.java
com.cidesign.jianghomestylephone.tools.XmlParseTools.java
com.cidesign.jianghomestylephone.version.NetworkTool.java
com.cidesign.jianghomestylephone.version.VersionConfig.java
com.cidesign.jianghomestylephone.version.VersionUpdate.java
com.cidesign.jianghomestylephone.widget.CommunityRelativeLayout.java
com.cidesign.jianghomestylephone.widget.CustomScrollView.java
com.cidesign.jianghomestylephone.widget.HScrollViewTouchLogic.java
com.cidesign.jianghomestylephone.widget.HumanityRelativeLayout.java
com.cidesign.jianghomestylephone.widget.LandscapeRelativeLayout.java
com.cidesign.jianghomestylephone.widget.PopMenu.java
com.cidesign.jianghomestylephone.widget.StoryRelativeLayout.java
org.apache.tools.zip.AbstractUnicodeExtraField.java
org.apache.tools.zip.AsiExtraField.java
org.apache.tools.zip.CentralDirectoryParsingZipExtraField.java
org.apache.tools.zip.ExtraFieldUtils.java
org.apache.tools.zip.FallbackZipEncoding.java
org.apache.tools.zip.GeneralPurposeBit.java
org.apache.tools.zip.JarMarker.java
org.apache.tools.zip.NioZipEncoding.java
org.apache.tools.zip.Simple8BitZipEncoding.java
org.apache.tools.zip.UnicodeCommentExtraField.java
org.apache.tools.zip.UnicodePathExtraField.java
org.apache.tools.zip.UnixStat.java
org.apache.tools.zip.UnparseableExtraFieldData.java
org.apache.tools.zip.UnrecognizedExtraField.java
org.apache.tools.zip.UnsupportedZipFeatureException.java
org.apache.tools.zip.Zip64ExtendedInformationExtraField.java
org.apache.tools.zip.Zip64Mode.java
org.apache.tools.zip.Zip64RequiredException.java
org.apache.tools.zip.ZipConstants.java
org.apache.tools.zip.ZipEightByteInteger.java
org.apache.tools.zip.ZipEncodingHelper.java
org.apache.tools.zip.ZipEncoding.java
org.apache.tools.zip.ZipEntry.java
org.apache.tools.zip.ZipExtraField.java
org.apache.tools.zip.ZipFile.java
org.apache.tools.zip.ZipLong.java
org.apache.tools.zip.ZipOutputStream.java
org.apache.tools.zip.ZipShort.java
org.apache.tools.zip.ZipUtil.java