Java Code Examples for android.view.View#performLongClick()

The following examples show how to use android.view.View#performLongClick() . 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: MessagesAdapter.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v, IAdapter<Item> adapter, Item item, int position) {

    if (item instanceof TimeItem || item instanceof LogItem || item instanceof LogWallet) {
        if (item.isSelected()) v.performLongClick();
    } else {
        if (iMessageItem != null && item.mMessage != null && item.mMessage.senderID != null && !item.mMessage.senderID.equalsIgnoreCase("-1")) {

            if (item.mMessage.status.equalsIgnoreCase(ProtoGlobal.RoomMessageStatus.SENDING.toString()) || item.mMessage.status.equalsIgnoreCase(ProtoGlobal.RoomMessageStatus.FAILED.toString())) {

                if (item.isSelected()) v.performLongClick();
                return true;
            }

            if (onChatMessageSelectionChanged != null) {
                onChatMessageSelectionChanged.onChatMessageSelectionChanged(getSelectedItems().size(), getSelectedItems());
            }
        }
    }

    return true;
}
 
Example 2
Source File: OnLongClickTest.java    From butterknife with Apache License 2.0 6 votes vote down vote up
@UiThreadTest
@Test public void optionalIdAbsent() {
  View tree = ViewTree.create(2);
  View view2 = tree.findViewById(2);

  OptionalId target = new OptionalId();
  Unbinder unbinder = ButterKnife.bind(target, tree);
  assertEquals(0, target.clicks);

  view2.performLongClick();
  assertEquals(0, target.clicks);

  unbinder.unbind();
  view2.performLongClick();
  assertEquals(0, target.clicks);
}
 
Example 3
Source File: OnLongClickTest.java    From butterknife with Apache License 2.0 6 votes vote down vote up
@UiThreadTest
@Test public void optionalIdPresent() {
  View tree = ViewTree.create(1);
  View view1 = tree.findViewById(1);

  OptionalId target = new OptionalId();
  Unbinder unbinder = ButterKnife.bind(target, tree);
  assertEquals(0, target.clicks);

  view1.performLongClick();
  assertEquals(1, target.clicks);

  unbinder.unbind();
  view1.performLongClick();
  assertEquals(1, target.clicks);
}
 
Example 4
Source File: BaseBrowserFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }
    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    setContextMenu(popupMenu.getMenuInflater(), popupMenu.getMenu(), position);

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example 5
Source File: AudioAlbumsSongsFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.audio_list_browser, popupMenu.getMenu());
    setContextMenuItems(popupMenu.getMenu(), anchor, position);

    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example 6
Source File: AudioAlbumFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.audio_list_browser, popupMenu.getMenu());
    setContextMenuItems(popupMenu.getMenu(), anchor, position);

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example 7
Source File: AudioBrowserFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.audio_list_browser, popupMenu.getMenu());
    setContextMenuItems(popupMenu.getMenu(), anchor);

    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example 8
Source File: VideoGridFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onContextPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.video_list, popupMenu.getMenu());
    MediaWrapper media = mVideoAdapter.getItem(position);
    if (media == null)
        return;
    setContextMenuItems(popupMenu.getMenu(), media);
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}
 
Example 9
Source File: OnLongClickTest.java    From butterknife with Apache License 2.0 6 votes vote down vote up
@UiThreadTest
@Test public void simple() {
  View tree = ViewTree.create(1);
  View view1 = tree.findViewById(1);

  Simple target = new Simple();
  Unbinder unbinder = ButterKnife.bind(target, tree);
  assertEquals(0, target.clicks);

  assertTrue(view1.performLongClick());
  assertEquals(1, target.clicks);

  target.returnValue = false;
  assertFalse(view1.performLongClick());
  assertEquals(2, target.clicks);

  unbinder.unbind();
  view1.performLongClick();
  assertEquals(2, target.clicks);
}
 
Example 10
Source File: OnLongClickTest.java    From butterknife with Apache License 2.0 6 votes vote down vote up
@UiThreadTest
@Test public void returnVoid() {
  View tree = ViewTree.create(1);
  View view1 = tree.findViewById(1);

  ReturnVoid target = new ReturnVoid();
  Unbinder unbinder = ButterKnife.bind(target, tree);
  assertEquals(0, target.clicks);

  assertTrue(view1.performLongClick());
  assertEquals(1, target.clicks);

  unbinder.unbind();
  view1.performLongClick();
  assertEquals(1, target.clicks);
}
 
Example 11
Source File: OnLongClickTest.java    From butterknife with Apache License 2.0 6 votes vote down vote up
@UiThreadTest
@Test public void visibilities() {
  View tree = ViewTree.create(1, 2, 3);
  View view1 = tree.findViewById(1);
  View view2 = tree.findViewById(2);
  View view3 = tree.findViewById(3);

  Visibilities target = new Visibilities();
  ButterKnife.bind(target, tree);
  assertEquals(0, target.clicks);

  view1.performLongClick();
  assertEquals(1, target.clicks);

  view2.performLongClick();
  assertEquals(2, target.clicks);

  view3.performLongClick();
  assertEquals(3, target.clicks);
}
 
Example 12
Source File: OnLongClickTest.java    From butterknife with Apache License 2.0 6 votes vote down vote up
@UiThreadTest
@Test public void multipleIds() {
  View tree = ViewTree.create(1, 2);
  View view1 = tree.findViewById(1);
  View view2 = tree.findViewById(2);

  MultipleIds target = new MultipleIds();
  Unbinder unbinder = ButterKnife.bind(target, tree);
  assertEquals(0, target.clicks);

  view1.performLongClick();
  assertEquals(1, target.clicks);

  view2.performLongClick();
  assertEquals(2, target.clicks);

  unbinder.unbind();
  view1.performLongClick();
  view2.performLongClick();
  assertEquals(2, target.clicks);
}
 
Example 13
Source File: OnLongClickTest.java    From butterknife with Apache License 2.0 5 votes vote down vote up
@UiThreadTest
@Test public void argumentCast() {
  class MyView extends Button implements ArgumentCast.MyInterface {
    MyView(Context context) {
      super(context);
    }
  }

  View view1 = new MyView(InstrumentationRegistry.getContext());
  view1.setId(1);
  View view2 = new MyView(InstrumentationRegistry.getContext());
  view2.setId(2);
  View view3 = new MyView(InstrumentationRegistry.getContext());
  view3.setId(3);
  View view4 = new MyView(InstrumentationRegistry.getContext());
  view4.setId(4);
  ViewGroup tree = new FrameLayout(InstrumentationRegistry.getContext());
  tree.addView(view1);
  tree.addView(view2);
  tree.addView(view3);
  tree.addView(view4);

  ArgumentCast target = new ArgumentCast();
  ButterKnife.bind(target, tree);

  view1.performLongClick();
  assertSame(view1, target.last);

  view2.performLongClick();
  assertSame(view2, target.last);

  view3.performLongClick();
  assertSame(view3, target.last);

  view4.performLongClick();
  assertSame(view4, target.last);
}
 
Example 14
Source File: LauncherAppWidgetHostView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onLongClick(View view) {
    if (mIsScrollable) {
        DragLayer dragLayer = Launcher.getLauncher(getContext()).getDragLayer();
        dragLayer.requestDisallowInterceptTouchEvent(false);
    }
    view.performLongClick();
    return true;
}
 
Example 15
Source File: TouchUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
public boolean onUtilsStop(View view, MotionEvent event) {
    int x = (int) event.getRawX();
    int y = (int) event.getRawY();

    int vx = 0, vy = 0;

    if (velocityTracker != null) {
        velocityTracker.computeCurrentVelocity(1000, maximumFlingVelocity);
        vx = (int) velocityTracker.getXVelocity();
        vy = (int) velocityTracker.getYVelocity();
        velocityTracker.recycle();
        if (Math.abs(vx) < minimumFlingVelocity) {
            vx = 0;
        }
        if (Math.abs(vy) < minimumFlingVelocity) {
            vy = 0;
        }
        velocityTracker = null;
    }

    view.setPressed(false);
    boolean consumeStop = onStop(view, direction, x, y, x - downX, y - downY, vx, vy, event);

    if (event.getAction() == MotionEvent.ACTION_UP) {
        if (state == STATE_DOWN) {
            if (event.getEventTime() - event.getDownTime() <= MIN_TAP_TIME) {
                view.performClick();
            } else {
                view.performLongClick();
            }
        }
    }

    resetTouch(-1, -1);

    return consumeStop;
}
 
Example 16
Source File: DonationActivity.java    From Virtual-Hosts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Donate with bitcoin by opening a bitcoin: intent if available.
 */
public void donateBitcoinOnClick(View view) {
    try {
        startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("bitcoin:" + BITCOIN_ADDRESS)));
    } catch (ActivityNotFoundException e) {
        view.performLongClick();
    }
}
 
Example 17
Source File: ViewTransformDelegater.java    From libcommon with Apache License 2.0 4 votes vote down vote up
/**
	 * View#onTouchEventの処理
	 * falseを返したときにはView#super.onTouchEventでデフォルトの処理をすること
	 * @param event
	 * @return
	 */
	@SuppressLint("SwitchIntDef")
	public boolean onTouchEvent(final MotionEvent event) {
//		if (DEBUG) Log.v(TAG, "onTouchEvent:");

		if (mHandleTouchEvent == TOUCH_DISABLED) {
			return false;
		}

		final View view = getTargetView();
		final int actionCode = event.getActionMasked();	// >= API8

		switch (actionCode) {
		case MotionEvent.ACTION_DOWN:
			// single touch
			startWaiting(event);
			return true;
		case MotionEvent.ACTION_POINTER_DOWN:
		{	// マルチタッチ時の処理
			switch (mState) {
			case STATE_WAITING:
				// 最初のマルチタッチ → 拡大縮小・回転操作待機開始
				view.removeCallbacks(mWaitImageReset);
				// pass through
			case STATE_DRAGGING:
				if (event.getPointerCount() > 1) {
					startCheck(event);
					return true;
				}
				break;
			}
			break;
		}
		case MotionEvent.ACTION_MOVE:
		{
			// moving with single and multi touch
			switch (mState) {
			case STATE_WAITING:
				if (((mHandleTouchEvent & TOUCH_ENABLED_MOVE) == TOUCH_ENABLED_MOVE)
					&& checkTouchMoved(event)) {

					view.removeCallbacks(mWaitImageReset);
					setState(STATE_DRAGGING);
					return true;
				}
				break;
			case STATE_DRAGGING:
				if (processDrag(event))
					return true;
				break;
			case STATE_CHECKING:
				if (checkTouchMoved(event)
					&& ((mHandleTouchEvent & TOUCH_ENABLED_ZOOM) == TOUCH_ENABLED_ZOOM)) {

					startZoom(event);
					return true;
				}
				break;
			case STATE_ZOOMING:
				if (processZoom(event))
					return true;
				break;
			case STATE_ROTATING:
				if (processRotate(event))
					return true;
				break;
			}
			break;
		}
		case MotionEvent.ACTION_CANCEL:
			// pass through
		case MotionEvent.ACTION_UP:
			view.removeCallbacks(mWaitImageReset);
			view.removeCallbacks(mStartCheckRotate);
			if ((actionCode == MotionEvent.ACTION_UP) && (mState == STATE_WAITING)) {
				final long downTime = SystemClock.uptimeMillis() - event.getDownTime();
				if (downTime > LONG_PRESS_TIMEOUT) {
					view.performLongClick();
				} else if (downTime < TAP_TIMEOUT) {
					view.performClick();
				}
			}
			// pass through
		case MotionEvent.ACTION_POINTER_UP:
			setState(STATE_NON);
			break;
		}
		return false;
	}