private void performClickOnButton( int btnResourceId, final RecordingButtonInterface mockBtnInterface) { final VideoCaptureView videoCaptureView = new VideoCaptureView(InstrumentationRegistry.getTargetContext()); videoCaptureView.setRecordingButtonInterface(mockBtnInterface); final View btn = videoCaptureView.findViewById(btnResourceId); btn.performClick(); }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { int x = (int) ev.getX(); int y = (int) ev.getY(); int pos = pointToPosition(x, y); if (mHeaderView != null && y >= mHeaderView.getTop() && y <= mHeaderView.getBottom()) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { mTouchTarget = getTouchTarget(mHeaderView, x, y); mActionDownHappened = true; } else if (ev.getAction() == MotionEvent.ACTION_UP) { View touchTarget = getTouchTarget(mHeaderView, x, y); if (touchTarget == mTouchTarget && mTouchTarget.isClickable()) { mTouchTarget.performClick(); invalidate(new Rect(0, 0, mHeaderWidth, mHeaderHeight)); } else if (mIsHeaderGroupClickable) { int groupPosition = getPackedPositionGroup(getExpandableListPosition(pos)); if (groupPosition != INVALID_POSITION && mActionDownHappened) { if (isGroupExpanded(groupPosition)) { collapseGroup(groupPosition); } else { expandGroup(groupPosition); } } } mActionDownHappened = false; } return true; } return super.dispatchTouchEvent(ev); }
@Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (v.getId() == R.id.txtPwd && btnLogin.isEnabled()) { btnLogin.performClick(); } return true; }
private void performViewClick(int x, int y) { if (null == mHeaderView) return; final ViewGroup container = (ViewGroup) mHeaderView; for (int i = 0; i < container.getChildCount(); i++) { View view = container.getChildAt(i); /** * transform coordinate to find the child view we clicked getGlobalVisibleRect used for * android 2.x, getLocalVisibleRect user for 3.x or above, maybe it's a bug */ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { view.getGlobalVisibleRect(mRect); } else { view.getLocalVisibleRect(mRect); int width = mRect.right - mRect.left; mRect.left = Math.abs(mRect.left); mRect.right = mRect.left + width; } if (mRect.contains(x, y)) { view.performClick(); break; } } }
@Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: return true; case MotionEvent.ACTION_UP: if (event.getRawX() >= (v.getRight() - ((TextView) v).getCompoundDrawables()[2].getBounds().width())) { // 响应右侧图标点击事件 Intent intent = new Intent(context, TerminalSubmitActivity.class); intent.putExtra("operate", "modify"); intent.putExtra("terminalid", ((String) v.getTag()).split(",")[0]); ((Activity) context).startActivityForResult(intent, 0); } else { // 响应自己的点击事件 if (!v.performClick()) { // 响应ListView点击事件 int position = Integer.parseInt(((String) v.getTag()).split(",")[1]) + 1; listView.performItemClick( listView.getChildAt(position - listView.getFirstVisiblePosition()), position, listView.getItemIdAtPosition(position)); } } } return false; }
private void clickPressedItem() { if (mPressedChild == null) { return; } mPressedChild.performClick(); clearPressedItem(); }
@UiThreadTest @Test public void shouldNotCrashWhenListenerIsNull() { final VideoCaptureView videoCaptureView = new VideoCaptureView(InstrumentationRegistry.getTargetContext()); final View recordBtn = videoCaptureView.findViewById(R.id.videocapture_recordbtn_iv); recordBtn.performClick(); }
@Override public boolean onSingleTapUp(MotionEvent e) { View view = getViewFromEvent(e); if (view != null) { view.performClick(); } return false; }
@Override public boolean onTouch(View v, MotionEvent event) { // Change the background color on touch if (MotionEvent.ACTION_DOWN == event.getAction()) { text.setBackgroundColor(row.getResources().getColor(android.R.color.holo_blue_light)); // Act on events } else if (MotionEvent.ACTION_UP == event.getAction()) { text.setBackgroundColor(row.getResources().getColor(android.R.color.white)); // Remove default entry if (entry.equals(row.getResources().getString(R.string.cmenu_remstd))) { Preferences.setDefaultFile(row.getContext(), ""); dialog.dismiss(); // Start navigation } else if (entry.equals(row.getResources().getString(R.string.cmenu_nav))) { building.showNavigation(); dialog.dismiss(); // Display share options } else if (entry.equals(row.getResources().getString(R.string.cmenu_share))) { building.showShareOptions(); dialog.dismiss(); // Show Building information } else if (entry.equals(row.getResources().getString(R.string.cmenu_info))) { building.showBuildingInformation(); dialog.dismiss(); // Display the legende } else if (entry.equals(row.getResources().getString(R.string.cmenu_legende))) { building.showSymbolLegend(); dialog.dismiss(); // Set filter } else if (entry.equals(row.getResources().getString(R.string.cmenu_filter))) { building.showFilterOptions(); dialog.dismiss(); } v.performClick(); // Change the background color back to normal when leaving the touch area } else if (MotionEvent.ACTION_CANCEL == event.getAction()) { text.setBackgroundColor(row.getResources().getColor(android.R.color.transparent)); } return true; }
private void propagateClicked() { ViewParent parent = getParent(); while (parent != null && parent instanceof View) { if (((View) parent).isClickable()) { ((View) parent).performClick(); break; } parent = parent.getParent(); } }
/** * Utility method for clicking on views exposing testing scenarios that are not possible when * using the actual app. * * @throws RuntimeException if the view is disabled or if the view or any of its parents are not * visible. */ public boolean checkedPerformClick() { if (!isShown()) { throw new RuntimeException("View is not visible and cannot be clicked"); } if (!realView.isEnabled()) { throw new RuntimeException("View is not enabled and cannot be clicked"); } return realView.performClick(); }
/** * Utility method for clicking on views exposing testing scenarios that are not possible when * using the actual app. * * @throws RuntimeException if the view is disabled or if the view or any of its parents are not * visible. * @return Return value of the underlying click operation. */ public boolean checkedPerformClick() { if (!realView.isShown()) { throw new RuntimeException("View is not visible and cannot be clicked"); } if (!realView.isEnabled()) { throw new RuntimeException("View is not enabled and cannot be clicked"); } AccessibilityUtil.checkViewIfCheckingEnabled(realView); return realView.performClick(); }
public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { downX = event.getX(); downY = event.getY(); return true; } case MotionEvent.ACTION_UP: { upX = event.getX(); upY = event.getY(); float deltaX = downX - upX; float deltaY = downY - upY; // swipe horizontal? if (Math.abs(deltaX) > MIN_DISTANCE) { // left or right if (deltaX < 0) { this.onLeftToRightSwipe(v); return true; } if (deltaX > 0) { this.onRightToLeftSwipe(v); return true; } } else { Log.i( logTag, "Swipe was only " + Math.abs(deltaX) + " long, need at least " + MIN_DISTANCE); } // swipe vertical? if (Math.abs(deltaY) > MIN_DISTANCE) { // top or down if (deltaY < 0) { this.onTopToBottomSwipe(v); return true; } if (deltaY > 0) { this.onBottomToTopSwipe(v); return true; } } else { Log.i( logTag, "Swipe was only " + Math.abs(deltaX) + " long, need at least " + MIN_DISTANCE); v.performClick(); } } } return false; }
public boolean onTouch(View paramView, MotionEvent paramMotionEvent) { if (paramMotionEvent.getAction() == 0) { paramView.setAlpha(0.2F); } while (paramMotionEvent.getAction() != 1) { return false; } paramView.setAlpha(1.0F); paramView.performClick(); return true; }
@Test public void testOnItemClick_startsFullPhotoViewIntent() { subject.setupPhotoList(); RecyclerView recyclerView = subject.getPhotoRecyclerView(); recyclerView.measure(0, 0); recyclerView.layout(0, 0, 100, 1000); RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(0); View view = viewHolder.itemView; view.performClick(); Intent expectedIntent = new Intent(subject, PhotoFullScreenActivity.class); ShadowActivity shadowActivity = Shadows.shadowOf(subject); Intent actualIntent = shadowActivity.getNextStartedActivity(); Assertions.assertThat(actualIntent).isNotNull(); assertTrue(actualIntent.filterEquals(expectedIntent)); }
// Touch @Override public boolean onTouch(View view, MotionEvent event) { int eventCase = event.getAction() & MotionEvent.ACTION_MASK; if (eventCase == MotionEvent.ACTION_DOWN) { // keep track of where on the button we originally pressed in order // to tell if we've swiped touchX = event.getX(); } else { if (eventCase == MotionEvent.ACTION_CANCEL) { return true; } float distanceFromTouchX = Math.abs(touchX - event.getX()); // if we release our click without swiping much if (eventCase == MotionEvent.ACTION_UP) { if (distanceFromTouchX < DRAG_THRESHOLD_X) { onClick(view); view.performClick(); return true; } else { return true; } } // if we swipe our a certain amount either left or right else if (eventCase == MotionEvent.ACTION_MOVE) { if (distanceFromTouchX > DRAG_THRESHOLD_X) { WordTrain entry = m_section.WordEntry(m_id); // if swipe right if (touchX < event.getX()) { entry.SetScore(DataTrainWord.TRAIN_LEVELS - 1); } else { // swipe left entry.SetScore(0); } // update the color on the view m_color_level = entry.Score(); TextView view_score = (TextView) view.findViewById(R.id.score); updateViewColor(view_score); view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); return true; } } } return true; }
private boolean clickOnText(View view, String text) { if (text.equals(shadowOf(view).innerText())) { view.performClick(); return true; } if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); if (clickOnText(child, text)) { return true; } } } return false; }
@Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { v.requestLayout(); border.setImageResource(R.drawable.game_detail_focus); // name.requestFocus(); cover.setScaleX(1.1f); cover.setScaleY(1.1f); if (v.isInTouchMode()) { v.performClick(); } } else { v.requestLayout(); border.setImageResource(R.color.transparent); cover.setScaleX(1.0f); cover.setScaleY(1.0f); } }
@Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { ImageView view = (ImageView) v.findViewById(R.id.image); // overlay is black with transparency of 0x77 (119) view.getDrawable().setColorFilter(0x99000000, PorterDuff.Mode.SRC_ATOP); Log.d("check", " " + view.getId()); view.invalidate(); TextView text = (TextView) v.findViewById(R.id.text); text.setBackgroundColor(Color.LTGRAY); text.invalidate(); break; } case MotionEvent.ACTION_UP: { ImageView view = (ImageView) v.findViewById(R.id.image); // clear the overlay view.getDrawable().clearColorFilter(); view.invalidate(); TextView text = (TextView) v.findViewById(R.id.text); text.setBackgroundColor(Color.TRANSPARENT); text.invalidate(); v.performClick(); break; } case MotionEvent.ACTION_CANCEL: { ImageView view = (ImageView) v.findViewById(R.id.image); // clear the overlay view.getDrawable().clearColorFilter(); view.invalidate(); TextView text = (TextView) v.findViewById(R.id.text); text.setBackgroundColor(Color.TRANSPARENT); text.invalidate(); break; } } return true; }
@Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { if (v.isInTouchMode()) { v.performClick(); } int[] location = new int[2]; v.getLocationOnScreen(location); /* * if (location[0] - v.getWidth() < mRecyclerView.getLeft() ) { * mRecyclerView.smoothScrollBy(- 400, 0); } */ if (location[0] + (v.getWidth() * 1.3) > mRecyclerView.getRight()) { mRecyclerView.smoothScrollBy(300, 0); } if (v.getId() == R.id.more_game) { panel.getMore_game_shadow().setImageResource(R.drawable.white_focus); panel.getMore_game_content().setScaleX(1.1f); panel.getMore_game_content().setScaleY(1.1f); panel.getMore_game().setNextFocusUpId(R.id.tab_gamecenter); panel.getMore_game().setNextFocusDownId(panel.getMore_game().getId()); if (adInfo != null) { if (adInfo.getVideoUrl() != null && !adInfo.getVideoUrl().isEmpty()) { panel.getMore_game_video().setVisibility(View.VISIBLE); } } } } else { if (v.getId() == R.id.more_game) { panel.getMore_game_shadow().setImageResource(android.R.color.transparent); panel.getMore_game_content().setScaleX(1.0f); panel.getMore_game_content().setScaleY(1.0f); panel.getMore_game_video().setVisibility(View.INVISIBLE); } } }
private void emulateSendButtonClick() // Not used at the moment { View v = findViewById(R.id.btnSendComment); v.performClick(); }
public MQuery click() { if (view != null) { view.performClick(); } return this; }
@Override public boolean onTouch(View v, MotionEvent event) { // detector.onTouchEvent(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: startX = event.getX(); downX = event.getX(); break; case MotionEvent.ACTION_UP: v.performClick(); break; case MotionEvent.ACTION_MOVE: // 是否已滚动到无法继续滑动 boolean isEnable = false; // 手指move的像素值超过系统判定判定滚动的最小临界值,避免手指抖动造成chart图抖动 if (Math.abs(event.getX() - downX) > ViewConfiguration.get(context).getScaledTouchSlop()) { int transValue = (int) (event.getX() - startX); if (axesData.size() > 1) { int max = axesData.get(axesData.size() - 1).X; int min = axesData.get(0).X; int maxLimit = width - rightPadding - POINT_PADDING; int minLimit = leftPadding + yTextWidth + POINT_PADDING; if (min + transValue > minLimit) { // 滑动以后左边界判断 if (min < minLimit) { transValue = minLimit - min; isEnable = true; } else { transValue = 0; if (loadMore != null) { loadMore.onLoad(); } } } else { isEnable = true; } if (max + transValue < maxLimit) { // 滑动后右边界判断 if (max > maxLimit) { transValue = maxLimit - max; isEnable = true; } else { transValue = 0; } } else { isEnable = true; } Log.d("min", min + ""); Log.d("minLimit", minLimit + ""); Log.d("transValue", transValue + ""); if (isEnable) { startX = event.getX(); refreshChart(transValue); } } } break; default: break; } return true; }
private void startGame() { mStart.performClick(); }
/** @Description 初始化布局 @Author blue @Time 2015-9-6 */ private void initView() { /* * title bar */ setTitle(R.string.title_iam_roomer); mTitleBar.showRightIcon( TitleBar.ICON_INDEX_SEARCH, new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(IamRoomerActivity.this, SingleSelectActivity.class); intent.putExtra(EXTRA_KEY_TITLE, "租金"); intent.putExtra( SingleSelectActivity.EXTRA_KEY_PAGE_INDEX, SingleSelectActivity.PAGE_INDEX_CHOOSE_PRICE); startActivityForResult(intent, 0); } }); /* * 上拉加载ListView */ mRefreshListFragment = new RefreshListFragment(); mRefreshListFragment.setAdapter(mAdapter); mRefreshListFragment.setOnRefreshLisenter( new OnRefreshLisenter() { @Override public void onRefresh() { loadData(); mRefreshListFragment.setSelection(1); mRefreshListFragment.onRefreshComplete(); } }); mRefreshListFragment.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { startActivity(new Intent(IamRoomerActivity.this, HouseDetailActivity.class)); } }); getSupportFragmentManager() .beginTransaction() .replace(R.id.container, mRefreshListFragment) .commit(); /* * 城市 */ mTabLayoutCity = findViewById(R.id.tab_city_llayout); mTabLayoutCity.setOnClickListener(this); mTabLayoutCity.setTag(0); ImageView imageview = (ImageView) findViewById(R.id.tab_city_imageview); TextView textview = (TextView) findViewById(R.id.tab_city_textview); mTabCity = new TabView(); mTabCity.setView(imageview, textview); mTabCity.setIcon(R.drawable.spinner_down, R.drawable.spinner_down); mTabCity.setTextColor( getResources().getColor(R.color.red), getResources().getColor(R.color.black)); mTabCity.clickIn(); /* * 类型 */ mTabLayoutCategory = findViewById(R.id.tab_category_llayout); mTabLayoutCategory.setOnClickListener(this); mTabLayoutCity.setTag(1); imageview = (ImageView) findViewById(R.id.tab_category_imageview); textview = (TextView) findViewById(R.id.tab_category_textview); mTabCategory = new TabView(); mTabCategory.setView(imageview, textview); mTabCategory.setIcon(R.drawable.spinner_down, R.drawable.spinner_down); mTabCategory.setTextColor( getResources().getColor(R.color.red), getResources().getColor(R.color.black)); mTabCategory.clickOn(); /* * 面积 */ mTabLayoutArea = findViewById(R.id.tab_area_llayout); mTabLayoutArea.setOnClickListener(this); mTabLayoutCity.setTag(2); imageview = (ImageView) findViewById(R.id.tab_area_imageview); textview = (TextView) findViewById(R.id.tab_area_textview); mTabArea = new TabView(); mTabArea.setView(imageview, textview); mTabArea.setIcon(R.drawable.spinner_down, R.drawable.spinner_down); mTabArea.setTextColor( getResources().getColor(R.color.red), getResources().getColor(R.color.black)); mTabArea.clickOn(); /* * 来源 */ mTabLayoutSource = findViewById(R.id.tab_source_llayout); mTabLayoutSource.setOnClickListener(this); mTabLayoutCity.setTag(3); imageview = (ImageView) findViewById(R.id.tab_source_imageview); textview = (TextView) findViewById(R.id.tab_source_textview); mTabSource = new TabView(); mTabSource.setView(imageview, textview); mTabSource.setIcon(R.drawable.spinner_down, R.drawable.spinner_down); mTabSource.setTextColor( getResources().getColor(R.color.red), getResources().getColor(R.color.black)); mTabSource.clickOn(); /* * 附近 */ mTabLayoutNear = findViewById(R.id.tab_near_llayout); mTabLayoutNear.setOnClickListener(this); mTabLayoutCity.setTag(0); imageview = (ImageView) findViewById(R.id.tab_near_imageview); textview = (TextView) findViewById(R.id.tab_near_textview); mTabNear = new TabView(); mTabNear.setView(imageview, textview); mTabNear.setIcon(R.drawable.ic_happyliving_near_sel, R.drawable.ic_happyliving_near); mTabNear.setTextColor( getResources().getColor(R.color.red), getResources().getColor(R.color.black)); mTabNear.clickOn(); /* * 地图 */ mTabLayoutMap = findViewById(R.id.tab_map_llayout); mTabLayoutMap.setOnClickListener(this); mTabLayoutCity.setTag(2); imageview = (ImageView) findViewById(R.id.tab_map_imageview); textview = (TextView) findViewById(R.id.tab_map_textview); mTabMap = new TabView(); mTabMap.setView(imageview, textview); mTabMap.setIcon(R.drawable.ic_happyliving_map_sel, R.drawable.ic_happyliving_map); mTabMap.setTextColor( getResources().getColor(R.color.red), getResources().getColor(R.color.black)); mTabArea.clickOn(); /* * 我要发布 */ mTabLayoutRelease = findViewById(R.id.tab_release_llayout); mTabLayoutRelease.setOnClickListener(this); imageview = (ImageView) findViewById(R.id.tab_release_imageview); textview = (TextView) findViewById(R.id.tab_release_textview); mTabRelease = new TabView(); mTabRelease.setView(imageview, textview); mTabRelease.setIcon(R.drawable.ic_happyliving_release_sel, R.drawable.ic_happyliving_release); mTabRelease.setTextColor( getResources().getColor(R.color.red), getResources().getColor(R.color.black)); mTabRelease.clickOn(); mCurBottomTabView = mTabNear; mCurTopTabView = mTabCity; mTabLayoutMap.performClick(); // 这个Tab显示不正常,模拟一次点击显示正常了 mTabLayoutCity.performClick(); }
public void notifyClosed() { View v = getView(); if (v == null) return; View dropdown = v.findViewById(R.id.dropdown); if (dropdown.getTag() != null) dropdown.performClick(); }
@Override public void run() { mView.performClick(); }
@Override public boolean onTouch(final View v, MotionEvent event) { mWindowManager.getDefaultDisplay().getMetrics(mDisplayMetrics); int xGrid = mDisplayMetrics.widthPixels / xGrids; int yGrid = mDisplayMetrics.heightPixels / yGrids; float xOffset = ((float) xGrids - 1) / 2; float yOffset = ((float) yGrids - 1) / 2; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: initialX = navigatorLayoutParams.x; initialY = navigatorLayoutParams.y; initialTouchX = event.getRawX(); initialTouchY = event.getRawY(); onLongClickLauncher = new TimerTask() { @Override public void run() { onLongClickHandler.sendEmptyMessage(0); } }; timer.schedule(onLongClickLauncher, longClickDelay); return true; case MotionEvent.ACTION_UP: if (!isMoving) { navigatorLayoutParams.x = initialX; navigatorLayoutParams.y = initialY; mWindowManager.updateViewLayout(navigator, navigatorLayoutParams); if (onLongClickLauncher.cancel()) v.performClick(); } else { int xPos = Math.round((navigatorLayoutParams.x + xOffset * xGrid) / xGrid); int yPos = Math.round((navigatorLayoutParams.y + yOffset * yGrid) / yGrid); navigatorLayoutParams.x = (int) ((xPos - xOffset) * xGrid); navigatorLayoutParams.y = (int) ((yPos - yOffset) * yGrid); mWindowManager.updateViewLayout(navigator, navigatorLayoutParams); menuHandler.obtainMessage(menuId, xPos, yPos).sendToTarget(); onLongClickLauncher.cancel(); isMoving = false; } if (!isMoving) for (int x = 0; x < xGrids; x++) for (int y = 0; y < yGrids; y++) if (menuItems[y * xGrids + x] != null) { menuItems[y * xGrids + x].setVisibility(View.GONE); } return true; case MotionEvent.ACTION_MOVE: navigatorLayoutParams.x = initialX + (int) (event.getRawX() - initialTouchX); navigatorLayoutParams.y = initialY + (int) (event.getRawY() - initialTouchY); mWindowManager.updateViewLayout(navigator, navigatorLayoutParams); if (!isMoving) { int deltaX = navigatorLayoutParams.x - initialX; int deltaY = navigatorLayoutParams.y - initialY; if (!((Math.abs(deltaX) < (xGrid / 4)) && (Math.abs(deltaY) < (yGrid / 4)))) { onLongClickLauncher.cancel(); isMoving = true; } } if (isMoving) for (int x = 0; x < xGrids; x++) for (int y = 0; y < yGrids; y++) if (menuItems[y * xGrids + x] != null) { itemLayoutParams.x = (int) ((x - xOffset) * xGrid); itemLayoutParams.y = (int) ((y - yOffset) * yGrid); menuItems[y * xGrids + x].setVisibility(View.VISIBLE); mWindowManager.updateViewLayout(menuItems[y * xGrids + x], itemLayoutParams); } return true; } return false; }