Search in sources :

Example 1 with OnTouchListener

use of android.view.View.OnTouchListener in project AnimeTaste by daimajia.

the class StartActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mContext = this;
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    mVideoList = (ListView) findViewById(R.id.videoList);
    mDrawerList = (ListView) findViewById(R.id.function_list);
    mDrawer = (LinearLayout) findViewById(R.id.drawer);
    mLayoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mCategoryList = (ListView) findViewById(R.id.category_list);
    mFooterView = mLayoutInflater.inflate(R.layout.load_item, null);
    mLoadProgress = (ProgressBar) mFooterView.findViewById(R.id.loading);
    mLoadText = (TextView) mFooterView.findViewById(R.id.load_text);
    mVideoList.addFooterView(mFooterView);
    mVideoList.setOnScrollListener(this);
    mDrawer.setOnTouchListener(this);
    View headerView = mLayoutInflater.inflate(R.layout.gallery_item, null, false);
    mVideoList.addHeaderView(headerView);
    mRecommendPager = (ViewPager) headerView.findViewById(R.id.pager);
    mRecommendPager.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            PointF downP = new PointF();
            PointF curP = new PointF();
            int act = event.getAction();
            if (act == MotionEvent.ACTION_DOWN || act == MotionEvent.ACTION_MOVE || act == MotionEvent.ACTION_UP) {
                ((ViewGroup) v).requestDisallowInterceptTouchEvent(true);
                if (downP.x == curP.x && downP.y == curP.y) {
                    return false;
                }
            }
            return false;
        }
    });
    mRecommendIndicator = (UnderlinePageIndicator) headerView.findViewById(R.id.indicator);
    if (getIntent().hasExtra("Success")) {
        init(getIntent());
    } else {
        Toast.makeText(mContext, R.string.init_failed, Toast.LENGTH_SHORT).show();
        finish();
    }
    mDrawerAapter = new SimpleAdapter(this, getDrawerItems(), R.layout.drawer_item, new String[] { "img", "title" }, new int[] { R.id.item_icon, R.id.item_name });
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_action_navigation_menu, R.string.app_name, R.string.app_name) {

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (mPreviousType != mType || mPreviousCategoryId != mCategoryId) {
                mCurrentPage = 1;
                mIsEnd = false;
                mVideoAdapter.removeAllData();
                mFooterView.findViewById(R.id.loading).setVisibility(View.VISIBLE);
                mFooterView.findViewById(R.id.load_text).setVisibility(View.INVISIBLE);
                triggerApiConnector();
            }
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            mPreviousType = mType;
            mPreviousCategoryId = mCategoryId;
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerList.setAdapter(mDrawerAapter);
    mDrawerList.setOnItemClickListener(this);
    ViewUtils.setListViewHeightBasedOnChildren(mDrawerList);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);
    getSupportActionBar().setLogo(R.drawable.rsz_ab_icon);
    rateForUsOrCheckUpdate();
    showWhatsNew();
}
Also used : OnTouchListener(android.view.View.OnTouchListener) PointF(android.graphics.PointF) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) SimpleAdapter(android.widget.SimpleAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) MotionEvent(android.view.MotionEvent)

Example 2 with OnTouchListener

use of android.view.View.OnTouchListener in project subsampling-scale-image-view by davemorrissey.

the class AdvancedEventHandlingActivity method initialiseImage.

private void initialiseImage() {
    final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) findViewById(id.imageView);
    final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (imageView.isReady()) {
                PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY());
                Toast.makeText(getApplicationContext(), "Single tap: " + ((int) sCoord.x) + ", " + ((int) sCoord.y), Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "Single tap: Image not ready", Toast.LENGTH_SHORT).show();
            }
            return true;
        }

        @Override
        public void onLongPress(MotionEvent e) {
            if (imageView.isReady()) {
                PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY());
                Toast.makeText(getApplicationContext(), "Long press: " + ((int) sCoord.x) + ", " + ((int) sCoord.y), Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "Long press: Image not ready", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (imageView.isReady()) {
                PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY());
                Toast.makeText(getApplicationContext(), "Double tap: " + ((int) sCoord.x) + ", " + ((int) sCoord.y), Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "Double tap: Image not ready", Toast.LENGTH_SHORT).show();
            }
            return true;
        }
    });
    imageView.setImage(ImageSource.asset("squirrel.jpg"));
    imageView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            return gestureDetector.onTouchEvent(motionEvent);
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) PointF(android.graphics.PointF) SubsamplingScaleImageView(com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView) GestureDetector(android.view.GestureDetector) SubsamplingScaleImageView(com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView) TextView(android.widget.TextView) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 3 with OnTouchListener

use of android.view.View.OnTouchListener in project UltimateAndroid by cymcsg.

the class ImageProcessingVideotoImageActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    view = new FastImageProcessingView(this);
    pipeline = new FastImageProcessingPipeline();
    video = new VideoResourceInput(view, this, R.raw.image_processing_birds);
    edgeDetect = new SobelEdgeDetectionFilter();
    image = new JPGFileEndpoint(this, false, Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/outputImage", false);
    screen = new ScreenEndpoint(pipeline);
    video.addTarget(edgeDetect);
    edgeDetect.addTarget(image);
    edgeDetect.addTarget(screen);
    pipeline.addRootRenderer(video);
    view.setPipeline(pipeline);
    setContentView(view);
    pipeline.startRendering();
    video.startWhenReady();
    view.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent me) {
            if (System.currentTimeMillis() - 100 > touchTime) {
                touchTime = System.currentTimeMillis();
                if (video.isPlaying()) {
                    video.stop();
                } else {
                    video.startWhenReady();
                }
            }
            return true;
        }
    });
}
Also used : JPGFileEndpoint(com.marshalchen.common.uimodule.imageprocessing.outputs.JPGFileEndpoint) OnTouchListener(android.view.View.OnTouchListener) SobelEdgeDetectionFilter(com.marshalchen.common.uimodule.imageprocessing.filter.processing.SobelEdgeDetectionFilter) FastImageProcessingView(com.marshalchen.common.uimodule.imageprocessing.FastImageProcessingView) ScreenEndpoint(com.marshalchen.common.uimodule.imageprocessing.outputs.ScreenEndpoint) FastImageProcessingView(com.marshalchen.common.uimodule.imageprocessing.FastImageProcessingView) View(android.view.View) FastImageProcessingPipeline(com.marshalchen.common.uimodule.imageprocessing.FastImageProcessingPipeline) VideoResourceInput(com.marshalchen.common.uimodule.imageprocessing.input.VideoResourceInput) MotionEvent(android.view.MotionEvent)

Example 4 with OnTouchListener

use of android.view.View.OnTouchListener in project android_frameworks_base by DirtyUnicorns.

the class VolumeDialog method initRow.

@SuppressLint("InflateParams")
private void initRow(final VolumeRow row, final int stream, int iconRes, int iconMuteRes, boolean important) {
    row.stream = stream;
    row.iconRes = iconRes;
    row.iconMuteRes = iconMuteRes;
    row.important = important;
    row.view = mDialog.getLayoutInflater().inflate(R.layout.volume_dialog_row, null);
    row.view.setId(row.stream);
    row.view.setTag(row);
    row.header = (TextView) row.view.findViewById(R.id.volume_row_header);
    row.header.setId(20 * row.stream);
    mSpTexts.add(row.header);
    row.slider = (SeekBar) row.view.findViewById(R.id.volume_row_slider);
    row.slider.setOnSeekBarChangeListener(new VolumeSeekBarChangeListener(row));
    row.anim = null;
    row.cachedShowHeaders = VolumePrefs.DEFAULT_SHOW_HEADERS;
    // forward events above the slider into the slider
    row.view.setOnTouchListener(new OnTouchListener() {

        private final Rect mSliderHitRect = new Rect();

        private boolean mDragging;

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            row.slider.getHitRect(mSliderHitRect);
            if (!mDragging && event.getActionMasked() == MotionEvent.ACTION_DOWN && event.getY() < mSliderHitRect.top) {
                mDragging = true;
            }
            if (mDragging) {
                event.offsetLocation(-mSliderHitRect.left, -mSliderHitRect.top);
                row.slider.dispatchTouchEvent(event);
                if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
                    mDragging = false;
                }
                return true;
            }
            return false;
        }
    });
    row.icon = (ImageButton) row.view.findViewById(R.id.volume_row_icon);
    row.icon.setImageResource(iconRes);
    row.icon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Events.writeEvent(mContext, Events.EVENT_ICON_CLICK, row.stream, row.iconState);
            mController.setActiveStream(row.stream);
            if (row.stream == AudioManager.STREAM_RING) {
                final boolean hasVibrator = mController.hasVibrator();
                if (mState.ringerModeInternal == AudioManager.RINGER_MODE_NORMAL) {
                    if (hasVibrator) {
                        mController.setRingerMode(AudioManager.RINGER_MODE_VIBRATE, false);
                    } else {
                        final boolean wasZero = row.ss.level == 0;
                        mController.setStreamVolume(stream, wasZero ? row.lastAudibleLevel : 0);
                    }
                } else {
                    mController.setRingerMode(AudioManager.RINGER_MODE_NORMAL, false);
                    if (row.ss.level == 0) {
                        mController.setStreamVolume(stream, 1);
                    }
                }
            } else if (row.stream == AudioManager.STREAM_NOTIFICATION) {
                // only ringer icon can change silent or vibrate mode
                if (mState.ringerModeInternal == AudioManager.RINGER_MODE_NORMAL) {
                    final boolean vmute = row.ss.level == 0;
                    mController.setStreamVolume(stream, vmute ? row.lastAudibleLevel : 0);
                }
            } else {
                final boolean vmute = row.ss.level == row.ss.levelMin;
                mController.setStreamVolume(stream, vmute ? row.lastAudibleLevel : row.ss.levelMin);
            }
            // reset the grace period, slider should update immediately
            row.userAttempt = 0;
        }
    });
}
Also used : Rect(android.graphics.Rect) OnTouchListener(android.view.View.OnTouchListener) SuppressLint(android.annotation.SuppressLint) OnClickListener(android.view.View.OnClickListener) View(android.view.View) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) SuppressLint(android.annotation.SuppressLint)

Example 5 with OnTouchListener

use of android.view.View.OnTouchListener in project platform_frameworks_base by android.

the class Interaction method register.

public static void register(View v, final Callback callback) {
    v.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            callback.onInteraction();
            return false;
        }
    });
    v.setOnGenericMotionListener(new OnGenericMotionListener() {

        @Override
        public boolean onGenericMotion(View v, MotionEvent event) {
            callback.onInteraction();
            return false;
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) OnGenericMotionListener(android.view.View.OnGenericMotionListener) View(android.view.View) MotionEvent(android.view.MotionEvent)

Aggregations

OnTouchListener (android.view.View.OnTouchListener)71 MotionEvent (android.view.MotionEvent)69 View (android.view.View)69 TextView (android.widget.TextView)41 OnClickListener (android.view.View.OnClickListener)21 ImageView (android.widget.ImageView)19 ListView (android.widget.ListView)17 AdapterView (android.widget.AdapterView)16 SuppressLint (android.annotation.SuppressLint)13 KeyEvent (android.view.KeyEvent)9 GestureDetector (android.view.GestureDetector)8 Intent (android.content.Intent)7 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)7 AbsListView (android.widget.AbsListView)6 Rect (android.graphics.Rect)5 Handler (android.os.Handler)5 Editable (android.text.Editable)5 TextWatcher (android.text.TextWatcher)5 OnGenericMotionListener (android.view.View.OnGenericMotionListener)5 ViewGroup (android.view.ViewGroup)5