Example usage for android.widget ImageView setOnTouchListener

List of usage examples for android.widget ImageView setOnTouchListener

Introduction

In this page you can find the example usage for android.widget ImageView setOnTouchListener.

Prototype

public void setOnTouchListener(OnTouchListener l) 

Source Link

Document

Register a callback to be invoked when a touch event is sent to this view.

Usage

From source file:com.openarc.nirmal.mytrack.LeaveUtilizationActivity.java

private void showLeaveDialog(LeaveUtilization leaveUtilization) {
    mawhDialogView = new MAWHDialogView();
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(LeaveUtilizationActivity.this);
    View dialogView = getLayoutInflater().inflate(R.layout.dialog_view_mawh, null);
    alertDialogBuilder.setView(dialogView);
    ImageView ivClose = (ImageView) dialogView.findViewById(R.id.ivClose);
    TextView tvDialogTitle = (TextView) dialogView.findViewById(R.id.tvDialogTitle);
    tvDialogTitle.setText(leaveUtilization.name);
    mawhDialogView.rvMawhDialog = (RecyclerView) dialogView.findViewById(R.id.rvMawhDialog);
    mawhDialogView.rlLoadingLayout = (RelativeLayout) dialogView.findViewById(R.id.rlLoadingLayout);
    final AlertDialog alertDialog = alertDialogBuilder.create();
    ivClose.setOnTouchListener(new View.OnTouchListener() {
        @Override/* w  w  w  .  j  a va2 s .c om*/
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                alertDialog.dismiss();
            }
            return false;
        }
    });
    new LeaveTask(mawhDialogView, alertDialog, leaveUtilization.name, LeaveUtilizationActivity.this).execute();
}

From source file:com.openarc.nirmal.mytrack.MainActivity.java

private void showMAWHDialog() {
    mawhDialogView = new MAWHDialogView();
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
    View dialogView = getLayoutInflater().inflate(R.layout.dialog_view_mawh, null);
    alertDialogBuilder.setView(dialogView);
    ImageView ivClose = (ImageView) dialogView.findViewById(R.id.ivClose);
    TextView tvDialogTitle = (TextView) dialogView.findViewById(R.id.tvDialogTitle);
    tvDialogTitle.setText("Monthly AWH");
    mawhDialogView.rvMawhDialog = (RecyclerView) dialogView.findViewById(R.id.rvMawhDialog);
    mawhDialogView.rlLoadingLayout = (RelativeLayout) dialogView.findViewById(R.id.rlLoadingLayout);
    final AlertDialog alertDialog = alertDialogBuilder.create();
    ivClose.setOnTouchListener(new View.OnTouchListener() {
        @Override//from   w  w  w.j  av a 2  s. c  om
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                alertDialog.dismiss();
            }
            return false;
        }
    });
    new MAWHTask(mawhDialogView, MainActivity.this, alertDialog).execute();
}

From source file:org.catnut.plugin.zhihu.ZhihuItemFragment.java

private ImageView getImageView() {
    ImageView image = new ImageView(getActivity());
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.setMargins(0, 10, 0, 10);//from  w w w .j  av  a 2  s. com
    image.setLayoutParams(lp);
    image.setAdjustViewBounds(true);
    image.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return CatnutUtils.imageOverlay(v, event);
        }
    });
    image.setOnClickListener(this);
    return image;
}

From source file:net.hyx.app.volumenotification.adapter.ListViewAdapter.java

@Override
public void onBindViewHolder(final ItemViewHolder holder, int position) {
    VolumeControl item = model.parseItem(items.get(position));

    View itemView = holder.itemView;
    LinearLayout itemWrapper = (LinearLayout) itemView.findViewById(R.id.list_item_wrapper);
    ImageView itemHandle = (ImageView) itemView.findViewById(R.id.list_item_handle);

    ImageView itemIcon = (ImageView) itemView.findViewById(R.id.list_item_icon);
    TextView itemLabel = (TextView) itemView.findViewById(R.id.list_item_label);
    TextView itemHint = (TextView) itemView.findViewById(R.id.list_item_hint);

    itemIcon.setImageResource(model.getIconDrawable(item.icon));
    itemLabel.setText(item.label);//from ww  w.j a  v a  2  s .  c om
    itemHint.setText(model.getDefaultLabel(item.id));

    if (item.status == 0) {
        itemWrapper.setAlpha(ALPHA_DISABLED);
    }

    itemHandle.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                dragStartListener.onStartDrag(holder);
            }
            return true;
        }
    });

    itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Context context = v.getContext();
            int position = holder.getAdapterPosition();
            Intent intent = new Intent(context, ItemViewActivity.class);
            VolumeControl item = items.get(position);
            intent.putExtra(EXTRA_ITEM, item);
            context.startActivity(intent);
        }
    });
}

From source file:com.huyn.demogroup.leaveblank.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;/*from   w w w. j  av  a2 s  .  c om*/
    imageView.setOnTouchListener(this);
    imageView.addOnLayoutChangeListener(this);

    if (imageView.isInEditMode()) {
        return;
    }

    mBaseRotation = 0.0f;

    // Create Gesture Detectors...
    mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (mLongClickListener != null) {
                        mLongClickListener.onLongClick(mImageView);
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });
}

From source file:de.skubware.opentraining.activity.start_training.FExDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_fex_detail, container, false);

    // show the current exercise
    ImageView imageview = (ImageView) rootView.findViewById(R.id.imageview);

    // set gesture detector
    this.mGestureScanner = new GestureDetector(this.getActivity(),
            new ExerciseDetailOnGestureListener(this, imageview, mExercise));

    // Images/*from ww  w .  j a  va  2s.  c  o  m*/
    if (!mExercise.getImagePaths().isEmpty()) {
        DataHelper data = new DataHelper(getActivity());
        imageview.setImageDrawable(data.getDrawable(mExercise.getImagePaths().get(0).toString()));
    } else {
        imageview.setImageResource(R.drawable.ic_launcher);
    }

    imageview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return mGestureScanner.onTouchEvent(event);
        }
    });

    // set adapter
    ListView listView = (ListView) rootView.findViewById(R.id.list);
    final TrainingEntryListAdapter mAdapter = new TrainingEntryListAdapter(
            (SherlockFragmentActivity) getActivity(), mExercise, mTrainingEntry);
    listView.setAdapter(mAdapter);

    SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(listView,
            new SwipeDismissListViewTouchListener.OnDismissCallback() {
                @Override
                public void onDismiss(ListView listView, int[] reverseSortedPositions) {
                    for (int position : reverseSortedPositions) {
                        mAdapter.remove(position);
                    }
                    mAdapter.notifyDataSetChanged();
                }
            });
    listView.setOnTouchListener(touchListener);
    // Setting this scroll listener is required to ensure that during
    // ListView scrolling,
    // we don't look for swipes.
    listView.setOnScrollListener(touchListener.makeScrollListener());

    return rootView;
}

From source file:de.damdi.fitness.activity.start_training.FExDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_fex_detail, container, false);

    // show the current exercise
    ImageView imageview = (ImageView) rootView.findViewById(R.id.imageview);

    // set gesture detector
    this.mGestureScanner = new GestureDetector(this.getActivity(),
            new ExerciseDetailOnGestureListener(this, imageview, mExercise));

    // Images/*  w  ww.  j  a va  2  s  .  c o m*/
    if (!mExercise.getImagePaths().isEmpty()) {
        DataHelper data = new DataHelper(getActivity());
        imageview.setImageDrawable(data.getDrawable(mExercise.getImagePaths().get(0).toString()));
    } else {
        imageview.setImageResource(R.drawable.ic_launcher);
    }

    imageview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return mGestureScanner.onTouchEvent(event);
        }
    });

    // set adapter
    ListView listView = (ListView) rootView.findViewById(R.id.list);
    final TrainingEntryListAdapter mAdapter = new TrainingEntryListAdapter((FragmentActivity) getActivity(),
            mExercise, mTrainingEntry);
    listView.setAdapter(mAdapter);

    SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(listView,
            new SwipeDismissListViewTouchListener.OnDismissCallback() {
                @Override
                public void onDismiss(ListView listView, int[] reverseSortedPositions) {
                    for (int position : reverseSortedPositions) {
                        mAdapter.remove(position);
                    }
                    mAdapter.notifyDataSetChanged();
                }
            });
    listView.setOnTouchListener(touchListener);
    // Setting this scroll listener is required to ensure that during
    // ListView scrolling,
    // we don't look for swipes.
    listView.setOnScrollListener(touchListener.makeScrollListener());

    return rootView;
}

From source file:com.android.inputmethod.keyboard.EmojiPalettesView.java

@Override
protected void onFinishInflate() {
    mTabHost = (TabHost) findViewById(R.id.emoji_category_tabhost);
    mTabHost.setup();/*from  w  w w  . j  a  va2s  .  co m*/
    for (final CategoryProperties properties : mEmojiCategory.getShownCategories()) {
        addTab(mTabHost, properties.mCategoryId);
    }
    mTabHost.setOnTabChangedListener(this);
    mTabHost.getTabWidget().setStripEnabled(true);

    mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, mLayoutSet, this);

    mEmojiPager = (ViewPager) findViewById(R.id.emoji_keyboard_pager);
    mEmojiPager.setAdapter(mEmojiPalettesAdapter);
    mEmojiPager.setOnPageChangeListener(this);
    mEmojiPager.setOffscreenPageLimit(0);
    mEmojiPager.setPersistentDrawingCache(ViewPager.PERSISTENT_NO_CACHE);
    final Resources res = getResources();
    final EmojiLayoutParams emojiLp = new EmojiLayoutParams(res);
    emojiLp.setPagerProperties(mEmojiPager);

    mEmojiCategoryPageIndicatorView = (EmojiCategoryPageIndicatorView) findViewById(
            R.id.emoji_category_page_id_view);
    emojiLp.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView);

    setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true /* force */);

    final LinearLayout actionBar = (LinearLayout) findViewById(R.id.emoji_action_bar);
    emojiLp.setActionBarProperties(actionBar);

    final ImageView deleteKey = (ImageView) findViewById(R.id.emoji_keyboard_delete);
    deleteKey.setTag(Constants.CODE_DELETE);
    deleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);
    final ImageView alphabetKey = (ImageView) findViewById(R.id.emoji_keyboard_alphabet);
    alphabetKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
    alphabetKey.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL);
    alphabetKey.setOnClickListener(this);
    final ImageView spaceKey = (ImageView) findViewById(R.id.emoji_keyboard_space);
    spaceKey.setBackgroundResource(mKeyBackgroundId);
    spaceKey.setTag(Constants.CODE_SPACE);
    spaceKey.setOnClickListener(this);
    emojiLp.setKeyProperties(spaceKey);
    final ImageView alphabetKey2 = (ImageView) findViewById(R.id.emoji_keyboard_alphabet2);
    alphabetKey2.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
    alphabetKey2.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL);
    alphabetKey2.setOnClickListener(this);
}

From source file:com.tjw.selectimage.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;/*from   ww w .j  a v  a  2 s .c  o m*/
    imageView.setOnTouchListener(this);
    imageView.addOnLayoutChangeListener(this);

    if (imageView.isInEditMode()) {
        return;
    }

    mBaseRotation = 0.0f;

    // Create Gesture Detectors...
    mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (mLongClickListener != null) {
                        mLongClickListener.onLongClick(mImageView);
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mOnClickListener != null) {
                mOnClickListener.onClick(mImageView);
            }
            final RectF displayRect = getDisplayRect();

            if (displayRect != null) {
                final float x = e.getX(), y = e.getY();

                // Check to see if the user tapped on the photo
                if (displayRect.contains(x, y)) {

                    float xResult = (x - displayRect.left) / displayRect.width();
                    float yResult = (y - displayRect.top) / displayRect.height();

                    if (mPhotoTapListener != null) {
                        mPhotoTapListener.onPhotoTap(mImageView, xResult, yResult);
                    }
                    return true;
                } else {
                    if (mOutsidePhotoTapListener != null) {
                        mOutsidePhotoTapListener.onOutsidePhotoTap(mImageView);
                    }
                }
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent ev) {
            try {
                float scale = getScale();
                float x = ev.getX();
                float y = ev.getY();

                if (scale < getMediumScale()) {
                    setScale(getMediumScale(), x, y, true);
                } else if (scale >= getMediumScale() && scale < getMaximumScale()) {
                    setScale(getMaximumScale(), x, y, true);
                } else {
                    setScale(getMinimumScale(), x, y, true);
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // Wait for the confirmed onDoubleTap() instead
            return false;
        }
    });
}

From source file:com.github.chrisbanes.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;//  w ww. ja v  a 2s.  c om
    imageView.setOnTouchListener(this);
    imageView.addOnLayoutChangeListener(this);

    if (imageView.isInEditMode()) {
        return;
    }

    mBaseRotation = 0.0f;

    // Create Gesture Detectors...
    mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (mLongClickListener != null) {
                        mLongClickListener.onLongClick(mImageView);
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mOnClickListener != null) {
                mOnClickListener.onClick(mImageView);
            }
            final RectF displayRect = getDisplayRect();

            final float x = e.getX(), y = e.getY();

            if (mViewTapListener != null) {
                mViewTapListener.onViewTap(mImageView, x, y);
            }

            if (displayRect != null) {

                // Check to see if the user tapped on the photo
                if (displayRect.contains(x, y)) {

                    float xResult = (x - displayRect.left) / displayRect.width();
                    float yResult = (y - displayRect.top) / displayRect.height();

                    if (mPhotoTapListener != null) {
                        mPhotoTapListener.onPhotoTap(mImageView, xResult, yResult);
                    }
                    return true;
                } else {
                    if (mOutsidePhotoTapListener != null) {
                        mOutsidePhotoTapListener.onOutsidePhotoTap(mImageView);
                    }
                }
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent ev) {
            try {
                float scale = getScale();
                float x = ev.getX();
                float y = ev.getY();

                if (scale < getMediumScale()) {
                    setScale(getMediumScale(), x, y, true);
                } else if (scale >= getMediumScale() && scale < getMaximumScale()) {
                    setScale(getMaximumScale(), x, y, true);
                } else {
                    setScale(getMinimumScale(), x, y, true);
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // Wait for the confirmed onDoubleTap() instead
            return false;
        }
    });
}