Java Code Examples for android.widget.ImageView#setOnTouchListener()

The following examples show how to use android.widget.ImageView#setOnTouchListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SvgAndroidSampleActivity.java    From android-opensource-library-56 with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_svg_android_sample);

    mMatrix = new Matrix();
    mImageView = (ImageView) findViewById(R.id.image);
    checkLayer(mImageView);

    SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.cute_fox);
    mImageView.setImageDrawable(svg.createPictureDrawable());
    mImageView.setImageMatrix(mMatrix);

    final ScaleGestureDetector detector = new ScaleGestureDetector(this,
            this);
    mImageView.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return detector.onTouchEvent(event);
        }
    });
}
 
Example 2
Source File: ZhihuItemFragment.java    From catnut with MIT License 6 votes vote down vote up
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);
	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;
}
 
Example 3
Source File: SortCategoryAdapter.java    From v9porn with MIT License 6 votes vote down vote up
@Override
protected void convert(final BaseViewHolder helper, final Category category) {
    helper.setText(R.id.tv_sort_category_name, category.getCategoryName());
    SwitchCompat switchCompat = helper.getView(R.id.sw_sort_category);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            category.setIsShow(isChecked);
        }
    });
    switchCompat.setChecked(category.getIsShow());
    ImageView imageView = helper.getView(R.id.iv_drag_handle);

    imageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (onStartDragListener != null) {
                //注意:这里down和up都会回调该方法
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    onStartDragListener.startDragItem(helper);
                }
            }
            return false;
        }
    });
}
 
Example 4
Source File: PhotoViewAttacher.java    From star-zone-android with Apache License 2.0 5 votes vote down vote up
/**
 * Clean-up the resources attached to this object. This needs to be called when the ImageView is
 * no longer used. A good example is from {@link android.view.View#onDetachedFromWindow()} or
 * from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using
 * {@link uk.co.senab.photoview.PhotoView}.
 */
@SuppressWarnings("deprecation")
public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView's reference to this
        imageView.setOnTouchListener(null);

        // make sure a pending fling runnable won't be run
        cancelFling();
    }

    if (null != mGestureDetector) {
        mGestureDetector.setOnDoubleTapListener(null);
    }

    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;

    // Finally, clear ImageView
    mImageView = null;
}
 
Example 5
Source File: LoginPopupWindow.java    From fangzhuishushenqi with Apache License 2.0 5 votes vote down vote up
public LoginPopupWindow(Activity activity) {
    mActivity = activity;
    setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

    mContentView = LayoutInflater.from(activity).inflate(R.layout.layout_login_popup_window, null);
    setContentView(mContentView);

    qq = (ImageView) mContentView.findViewById(R.id.ivQQ);
    weibo = (ImageView) mContentView.findViewById(R.id.ivWeibo);
    wechat = (ImageView) mContentView.findViewById(R.id.ivWechat);

    qq.setOnTouchListener(this);
    weibo.setOnTouchListener(this);
    wechat.setOnTouchListener(this);

    setFocusable(true);
    setOutsideTouchable(true);
    setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));

    setAnimationStyle(R.style.LoginPopup);

    setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss() {
            lighton();
        }
    });
}
 
Example 6
Source File: PhotoViewAttacher.java    From WifiChat with GNU General Public License v2.0 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setOnTouchListener(this);

    mViewTreeObserver = imageView.getViewTreeObserver();
    mViewTreeObserver.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (!imageView.isInEditMode()) {
        // Create Gesture Detectors...
        mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

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

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

        mGestureDetector.setOnDoubleTapListener(this);

        // Finally, update the UI so that we're zoomable
        setZoomable(true);
    }
}
 
Example 7
Source File: PhotoViewAttacher.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

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

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

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}
 
Example 8
Source File: PhotoViewAttacher.java    From jmessage-android-uikit with MIT License 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView, boolean fromChatActivity, Context context) {
	mImageView = new WeakReference<ImageView>(imageView);
       mFromChatActivity = fromChatActivity;
       mContext = context;
	imageView.setOnTouchListener(this);

	mViewTreeObserver = imageView.getViewTreeObserver();
	mViewTreeObserver.addOnGlobalLayoutListener(this);

	// Make sure we using MATRIX Scale Type
	setImageViewScaleTypeMatrix(imageView);

	if (!imageView.isInEditMode()) {
		// Create Gesture Detectors...
		mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

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

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

		mGestureDetector.setOnDoubleTapListener(this);

		// Finally, update the UI so that we're zoomable
		setZoomable(true);
	}
}
 
Example 9
Source File: PhotoViewAttacher.java    From jmessage-android-uikit with MIT License 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView, Context context) {
	mImageView = new WeakReference<ImageView>(imageView);
       mContext = context;
	imageView.setOnTouchListener(this);

	mViewTreeObserver = imageView.getViewTreeObserver();
	mViewTreeObserver.addOnGlobalLayoutListener(this);

	// Make sure we using MATRIX Scale Type
	setImageViewScaleTypeMatrix(imageView);

	if (!imageView.isInEditMode()) {
		// Create Gesture Detectors...
		mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

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

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

		mGestureDetector.setOnDoubleTapListener(this);

		// Finally, update the UI so that we're zoomable
		setZoomable(true);
	}
}
 
Example 10
Source File: PhotoViewAttacher.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

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

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

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}
 
Example 11
Source File: PhotoViewAttacher.java    From AndroidPickPhotoDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Clean-up the resources attached to this object. This needs to be called when the ImageView is
 * no longer used. A good example is from {@link View#onDetachedFromWindow()} or
 * from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using
 * {@link uk.co.senab.photoview.PhotoView}.
 */
@SuppressWarnings("deprecation")
public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView's reference to this
        imageView.setOnTouchListener(null);

        // make sure a pending fling runnable won't be run
        cancelFling();
    }

    if (null != mGestureDetector) {
        mGestureDetector.setOnDoubleTapListener(null);
    }

    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;

    // Finally, clear ImageView
    mImageView = null;
}
 
Example 12
Source File: ImageViewScaler.java    From MultiView with Apache License 2.0 5 votes vote down vote up
public ImageViewScaler(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

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

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

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}
 
Example 13
Source File: PhotoViewAttacher.java    From Favorite-Android-Client with Apache License 2.0 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

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

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

    mGestureDetector.setOnDoubleTapListener(this);

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}
 
Example 14
Source File: PhotoViewAttacher.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * Clean-up the resources attached to this object. This needs to be called when the ImageView is
 * no longer used. A good example is from {@link android.view.View#onDetachedFromWindow()} or
 * from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using
 * {@link com.marshalchen.common.uimodule.photoview.PhotoView}.
 */
@SuppressWarnings("deprecation")
public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView's reference to this
        imageView.setOnTouchListener(null);

        // make sure a pending fling runnable won't be run
        cancelFling();
    }

    if (null != mGestureDetector) {
        mGestureDetector.setOnDoubleTapListener(null);
    }

    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;

    // Finally, clear ImageView
    mImageView = null;
}
 
Example 15
Source File: GlideLoader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
@Override
public void debug(final SingleConfig config) {
    if(config.getTarget() instanceof ImageView) {
         ImageView imageView = (ImageView) config.getTarget();
        imageView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if(event.getAction() != MotionEvent.ACTION_DOWN){
                    return false;
                }

                Object o = v.getTag(R.drawable.im_item_list_opt);
                if(!(o instanceof SingleConfig)){
                    return false;
                }
                if(event.getX() > MyUtil.dip2px(40) || event.getY() > MyUtil.dip2px(40)){
                    return false;
                }

                SingleConfig singleConfig = (SingleConfig) o;
                showPop((ImageView)v,singleConfig);
                return false;
            }
        });

    }
}
 
Example 16
Source File: ItemTouchAdapter.java    From Xrv with Apache License 2.0 5 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
private void linearConvert(final CommonHolder holder, Bean item) {
    holder.setText(R.id.tv_style0, item.content);
    ImageView ivHandler = holder.getView(R.id.iv_style0_handler);
    ivHandler.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN && getItemCount() > 1 && startDragListener != null) {
                // Step 9-5: 只有调用onStartDrag才会触发拖拽 (这里在touch时开始拖拽,当然也可以单击或长按时才开始拖拽)
                startDragListener.onStartDrag(holder);
                return true;
            }
            return false;
        }
    });
    // Step 9-7: 设置ItemTouchListener
    holder.setOnItemTouchListener(new ItemTouchHelperViewHolder() {
        @Override
        public void onItemSelected() {
            // 触发拖拽时回调
            holder.itemView.setBackgroundColor(colorSelected);
        }

        @Override
        public void onItemClear() {
            // 手指松开时回调
            holder.itemView.setBackgroundColor(0);
        }
    });
}
 
Example 17
Source File: MainActivity.java    From PinchToZoom with MIT License 5 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
    Context context = container.getContext();
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    View view = layoutInflater.inflate(R.layout.page_image, null);
    container.addView(view);

    ImageView imageView = view.findViewById(R.id.image);
    imageView.setImageDrawable(drawables.get(position));

    ImageMatrixTouchHandler imageMatrixTouchHandler = new ImageMatrixTouchHandler(context);
    imageView.setOnTouchListener(imageMatrixTouchHandler);

    return view;
}
 
Example 18
Source File: AdapterAccounts.java    From fingen with Apache License 2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int position) {

    Account account = accountList.get(position);

    AccountViewHolder avh = (AccountViewHolder) viewHolder;

    ImageView icon = avh.imageViewIcon;

    avh.itemView.setLongClickable(true);

    avh.textViewName.setText(account.getName());

    String[] accountTypes = mActivity.getResources().getStringArray(R.array.account_types);
    String accountType = accountTypes[account.getAccountType().ordinal()];

    Cabbage cabbage = AccountManager.getCabbage(account, mActivity);
    avh.textViewType.setText(String.format("%s (%s)", accountType, cabbage.getCode()));

    CabbageFormatter cabbageFormatter = new CabbageFormatter(cabbage);
    Boolean showInEx = PreferenceManager.getDefaultSharedPreferences(mActivity).getBoolean(FgConst.PREF_SHOW_INCOME_EXPENSE_FOR_ACCOUNTS, true);
    if (showInEx) {
        mActivity.unsubscribeOnDestroy(
                cabbageFormatter.formatRx(account.getIncome())
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(s -> {
                            avh.textViewIncome.setText(s);
                            avh.textViewIncome.setVisibility(View.VISIBLE);
                        }));
        mActivity.unsubscribeOnDestroy(
                cabbageFormatter.formatRx(account.getExpense())
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(s -> {
                            avh.textViewOutcome.setText(s);
                            avh.textViewOutcome.setVisibility(View.VISIBLE);
                        }));
        avh.textViewOutcome.setVisibility(View.VISIBLE);
    } else {
        avh.textViewIncome.setVisibility(View.GONE);
        avh.textViewOutcome.setVisibility(View.GONE);
    }

    mActivity.unsubscribeOnDestroy(
            cabbageFormatter.formatRx(account.getCurrentBalance())
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                .subscribe(s -> avh.textViewCurBalance.setText(s))
    );

    int compareToZero = account.getCurrentBalance().setScale(cabbage.getDecimalCount(), RoundingMode.HALF_EVEN).compareTo(BigDecimal.ZERO);

    switch (compareToZero) {
        case -1:
            avh.textViewCurBalance.setTextColor(ContextCompat.getColor(mActivity, R.color.negative_color));
            break;
        case 0:
            avh.textViewCurBalance.setTextColor(ContextCompat.getColor(mActivity, R.color.light_gray_text));
            break;
        case 1:
            avh.textViewCurBalance.setTextColor(ContextCompat.getColor(mActivity, R.color.positive_color));
            break;
    }

    if (mDragMode) {
        icon.setImageDrawable(mActivity.getDrawable(R.drawable.ic_drag));
        icon.setOnTouchListener((v, event) -> {
            if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                mDragStartListener.onStartDrag(viewHolder);
                return true;
            } else {
                return false;
            }
        });
    } else {
        icon.setImageDrawable(IconGenerator.getAccountIcon(account.getAccountType(), compareToZero, account.getIsClosed(), mActivity));
        icon.setOnTouchListener((view, motionEvent) -> false);
    }

    if (position == accountList.size() - 1) {
        avh.mSpaceBottom.setVisibility(View.GONE);
        avh.mSpaceBottomFinal.setVisibility(View.VISIBLE);
    } else {
        avh.mSpaceBottom.setVisibility(View.VISIBLE);
        avh.mSpaceBottomFinal.setVisibility(View.GONE);
    }

    if (account.getCreditLimit().compareTo(BigDecimal.ZERO) < 0) {
        avh.mProgresBarLayout.setVisibility(View.VISIBLE);
        buildProgresBar(avh, account, cabbage, mActivity);
    } else {
        avh.mProgresBarLayout.setVisibility(View.GONE);
    }

    avh.account = account;

}
 
Example 19
Source File: InputPanel.java    From Android with MIT License 4 votes vote down vote up
public InputPanel(View rootview) {
    context = rootview.getContext();
    inputView = rootview.findViewById(R.id.layout_inputbottom);
    exBottomLayout = (ExBottomLayout) rootview.findViewById(R.id.layout_exbottom);
    recordView = (RecordView) rootview.findViewById(R.id.recordview);

    inputMore = (ImageView) inputView.findViewById(R.id.inputmore);
    inputEdit = (ChatEditText) inputView.findViewById(R.id.inputedit);
    inputFace = (ImageView) inputView.findViewById(R.id.inputface);
    inputVoice = (ImageView) inputView.findViewById(R.id.inputvoice);
    inputTxt = (TextView) inputView.findViewById(R.id.inputtxt);

    recordView.setVisibility(View.GONE);
    initEdit();

    inputMore.setOnClickListener(clickListener);
    inputFace.setOnClickListener(clickListener);
    inputTxt.setOnClickListener(clickListener);
    inputVoice.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if( !((ChatActivity)context).isOpenRecord()){
                return true;
            }

            inputView.setVisibility(View.INVISIBLE);
            recordView.setVisibility(View.VISIBLE);
            int[] location = new int[2];
            inputVoice.getLocationOnScreen(location);
            recordView.slideVRecord(event, location);
            if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) {
                inputView.setVisibility(View.VISIBLE);
                recordView.setVisibility(View.GONE);
            }
            return true;
        }
    });
    exBottomLayout.getEmojiPanel().setiEmojiClickListener(new IEmojiClickListener() {
        @Override
        public void onEmjClick(String emi) {
            Editable mEditable = inputEdit.getText();

            if (emi.equals("[DEL]")) {
                inputEdit.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            } else {
                int start = inputEdit.getSelectionStart();
                int end = inputEdit.getSelectionEnd();
                start = (start < 0 ? 0 : start);
                end = (start < 0 ? 0 : end);
                mEditable.replace(start, end, emi);
            }
        }

        @Override
        public void onEmtClick(String emt) {
            MsgSend.sendOuterMsg(MsgType.Emotion, emt);
        }
    });
}
 
Example 20
Source File: MainActivity.java    From Android-Basics-Codes with Artistic License 2.0 4 votes vote down vote up
@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//��ȡ����ͼƬ
		Bitmap bmSrc = BitmapFactory.decodeResource(getResources(), R.drawable.bg);
		bmCopy = Bitmap.createBitmap(bmSrc.getWidth(), bmSrc.getHeight(), bmSrc.getConfig());
		paint = new Paint();
		canvas = new Canvas(bmCopy);
		//����
		canvas.drawBitmap(bmSrc, new Matrix(), paint);
		
		iv = (ImageView) findViewById(R.id.iv);
		iv.setImageBitmap(bmCopy);
		
		iv.setOnTouchListener(new OnTouchListener() {
			

			//����imageviewʱ����
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
				//��ָ������Ļ
				case MotionEvent.ACTION_DOWN:
					//��ȡ���������ImageView������
					startX = (int) event.getX();
					startY = (int) event.getY();
//					System.out.println(startX + ";" + startY);
					break;
					//��ָ�뿪��Ļ
				case MotionEvent.ACTION_UP:
					break;
					//��ָ����
				case MotionEvent.ACTION_MOVE:
					int newX = (int) event.getX();
					int newY = (int) event.getY();
//					System.out.println(newX + ";" + newY);
					
					//���ݻ�ȡ�����꣬����ֱ��
					canvas.drawLine(startX, startY, newX, newY, paint);
					startX = newX;
					startY = newY;
					iv.setImageBitmap(bmCopy);
					break;
				}
				//����true��ʾ����iv������������¼��������false����ʾ���¼����ݸ����ڵ�
				return true;
			}
		});
	}