Android Open Source - custom-touch-examples Touch Intercept Activity






From Project

Back to project page custom-touch-examples.

License

The source code is released under:

Copyright (c) 2012 Wireless Designs, LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in ...

If you think the Android project custom-touch-examples 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.examples.customtouch;
/*ww w . j  ava2  s .  co  m*/
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

/**
 * Created by Dave Smith
 * Double Encore, Inc.
 * Date: 1/19/13
 * TouchInterceptActivity
 */
public class TouchInterceptActivity extends Activity implements ViewPager.OnPageChangeListener {

    private ViewPager mViewPager;
    private ListView mListView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.touch_intercept);

        mViewPager = new ViewPager(this);
        mViewPager.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT,
                getResources().getDimensionPixelSize(R.dimen.header_height)));
        mListView = (ListView) findViewById(R.id.list);

        mListView.addHeaderView(mViewPager);
        mListView.setAdapter(new ItemsAdapter(this));

        mViewPager.setOnPageChangeListener(this);
        mViewPager.setAdapter(new HeaderAdapter(this));
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { }

    @Override
    public void onPageSelected(int position) { }

    @Override
    public void onPageScrollStateChanged(int state) {
        //While the ViewPager is scrolling, disable the ScrollView touch intercept
        // so it cannot take over and try to vertical scroll
        boolean isScrolling = state != ViewPager.SCROLL_STATE_IDLE;
        mListView.requestDisallowInterceptTouchEvent(isScrolling);
    }

    /*
     * Simple ListAdapter that draws a series of row items
     */
    private static class ItemsAdapter extends BaseAdapter {

        private LayoutInflater mInflater;

        public ItemsAdapter(Context context) {
            mInflater = LayoutInflater.from(context);
        }

        @Override
        public int getCount() {
            return 25;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.intercept_row, parent, false);
            }

            TextView v = (TextView) convertView.findViewById(R.id.text);
            v.setText(String.format("Item Row %d", position + 1));

            return convertView;
        }
    }

    /*
     * Simple PagerAdapter that just draws a small group of colored views
     */
    private static class HeaderAdapter extends PagerAdapter {
        private static final int[] COLORS = {0xFF555500, 0xFF770077, 0xFF007777, 0xFF777777};

        private Context mContext;

        public HeaderAdapter(Context context) {
            mContext = context;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            TextView v = new TextView(mContext);
            v.setBackgroundColor(COLORS[position]);
            v.setText(String.format("Header Card %d", position + 1));
            v.setGravity(Gravity.CENTER);
            container.addView(v);

            return v;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public int getCount() {
            return COLORS.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return (view == object);
        }
    }
}




Java Source Code List

com.examples.customtouch.MainActivity.java
com.examples.customtouch.MoveLoggerActivity.java
com.examples.customtouch.MultitouchActivity.java
com.examples.customtouch.TouchDelegateActivity.java
com.examples.customtouch.TouchForwardActivity.java
com.examples.customtouch.TouchInterceptActivity.java
com.examples.customtouch.TouchListenerActivity.java
com.examples.customtouch.TwoDimensionGestureScrollActivity.java
com.examples.customtouch.TwoDimensionScrollActivity.java
com.examples.customtouch.widget.RotateZoomImageView.java
com.examples.customtouch.widget.TouchDelegateLayout.java
com.examples.customtouch.widget.TouchForwardLayout.java
com.examples.customtouch.widget.TwoDimensionGestureScrollView.java
com.examples.customtouch.widget.TwoDimensionScrollView.java