List of usage examples for android.view ViewConfiguration getLongPressTimeout
public static int getLongPressTimeout()
From source file:com.example.alyshia.customsimplelauncher.launcher.GridFragment.java
private void postCheckForLongClick(int delayOffset) { mHasPerformedLongPress = false;/*from w w w . ja v a2 s.c o m*/ timeout = false; if (mPendingCheckForLongPress == null) { mPendingCheckForLongPress = new CheckForLongPress(); } if (mPendingTimeout == null) { mPendingTimeout = new CheckForTimeOut(); } mHandler.postDelayed(mPendingTimeout, ViewConfiguration.getLongPressTimeout()); mHandler.postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout() + delayOffset); }
From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (chanSelectMode) { return listView.startSorting(2, chans.size(), position); }/*from www. j av a 2 s . c o m*/ final ListItem listItem = getItem(position); if (listItem != null) { if (listItem.type == ListItem.ITEM_FAVORITE && listItem.threadNumber != null && FavoritesStorage.getInstance().canSortManually()) { long time = multipleFingersTime + (multipleFingersCountingTime ? System.currentTimeMillis() - multipleFingersStartTime : 0L); if (time >= ViewConfiguration.getLongPressTimeout() / 10) { int start = position; int end = position; for (int i = position - 1;; i--) { ListItem checkingListItem = getItem(i); if (checkingListItem == null) { break; } if (checkingListItem.type != ListItem.ITEM_FAVORITE || !listItem.chanName.equals(checkingListItem.chanName)) { start = i + 1; break; } } for (int i = position + 1;; i++) { ListItem checkingListItem = getItem(i); if (checkingListItem == null) { break; } if (checkingListItem.type != ListItem.ITEM_FAVORITE || !listItem.chanName.equals(checkingListItem.chanName)) { end = i - 1; break; } } listView.startSorting(start, end, position); return true; } } switch (listItem.type) { case ListItem.ITEM_PAGE: case ListItem.ITEM_FAVORITE: { DialogMenu dialogMenu = new DialogMenu(context, new DialogMenu.Callback() { @Override public void onItemClick(Context context, int id, Map<String, Object> extra) { switch (id) { case MENU_COPY_LINK: case MENU_SHARE_LINK: { ChanLocator locator = ChanLocator.get(listItem.chanName); Uri uri = listItem.isThreadItem() ? locator.safe(true).createThreadUri(listItem.boardName, listItem.threadNumber) : locator.safe(true).createBoardUri(listItem.boardName, 0); if (uri != null) { switch (id) { case MENU_COPY_LINK: { StringUtils.copyToClipboard(context, uri.toString()); break; } case MENU_SHARE_LINK: { String subject = listItem.title; if (StringUtils.isEmptyOrWhitespace(subject)) { subject = uri.toString(); } NavigationUtils.share(context, subject, null, uri); break; } } } break; } case MENU_ADD_TO_FAVORITES: { if (listItem.isThreadItem()) { FavoritesStorage.getInstance().add(listItem.chanName, listItem.boardName, listItem.threadNumber, listItem.title, 0); } else { FavoritesStorage.getInstance().add(listItem.chanName, listItem.boardName); } break; } case MENU_REMOVE_FROM_FAVORITES: { FavoritesStorage.getInstance().remove(listItem.chanName, listItem.boardName, listItem.threadNumber); break; } case MENU_RENAME: { final EditText editText = new SafePasteEditText(context); editText.setSingleLine(true); editText.setText(listItem.title); editText.setSelection(editText.length()); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(editText, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); int padding = context.getResources().getDimensionPixelSize(R.dimen.dialog_padding_view); linearLayout.setPadding(padding, padding, padding, padding); AlertDialog dialog = new AlertDialog.Builder(context).setView(linearLayout) .setTitle(R.string.action_rename) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, (d, which) -> { String newTitle = editText.getText().toString(); FavoritesStorage.getInstance().modifyTitle(listItem.chanName, listItem.boardName, listItem.threadNumber, newTitle, true); }).create(); dialog.getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); dialog.show(); break; } } } }); dialogMenu.addItem(MENU_COPY_LINK, R.string.action_copy_link); if (listItem.isThreadItem()) { dialogMenu.addItem(MENU_SHARE_LINK, R.string.action_share_link); } if (listItem.type != ListItem.ITEM_FAVORITE && !FavoritesStorage.getInstance() .hasFavorite(listItem.chanName, listItem.boardName, listItem.threadNumber)) { dialogMenu.addItem(MENU_ADD_TO_FAVORITES, R.string.action_add_to_favorites); } if (listItem.type == ListItem.ITEM_FAVORITE) { dialogMenu.addItem(MENU_REMOVE_FROM_FAVORITES, R.string.action_remove_from_favorites); if (listItem.threadNumber != null) { dialogMenu.addItem(MENU_RENAME, R.string.action_rename); } } dialogMenu.show(); return true; } } } return false; }
From source file:com.ruesga.timelinechart.TimelineChartView.java
private void init(Context ctx, AttributeSet attrs, int defStyleAttr, int defStyleRes) { mUiHandler = new Handler(Looper.getMainLooper(), mMessenger); if (!isInEditMode()) { mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); }/*from ww w . j a va2s .c om*/ final Resources res = getResources(); final Resources.Theme theme = ctx.getTheme(); mTickFormats = getResources().getStringArray(R.array.tlcDefTickLabelFormats); mTickLabels = getResources().getStringArray(R.array.tlcDefTickLabelValues); final DisplayMetrics dp = getResources().getDisplayMetrics(); mSize8 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 8, dp); mSize12 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, dp); mSize20 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20, dp); final ViewConfiguration vc = ViewConfiguration.get(ctx); mLongPressTimeout = ViewConfiguration.getLongPressTimeout(); mTouchSlop = vc.getScaledTouchSlop() / 2; mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity(); mScroller = new OverScroller(ctx); int graphBgColor = ContextCompat.getColor(ctx, R.color.tlcDefGraphBackgroundColor); int footerBgColor = ContextCompat.getColor(ctx, R.color.tlcDefFooterBackgroundColor); mDefFooterBarHeight = mFooterBarHeight = res.getDimension(R.dimen.tlcDefFooterBarHeight); mShowFooter = res.getBoolean(R.bool.tlcDefShowFooter); mGraphMode = res.getInteger(R.integer.tlcDefGraphMode); mPlaySelectionSoundEffect = res.getBoolean(R.bool.tlcDefPlaySelectionSoundEffect); mSelectionSoundEffectSource = res.getInteger(R.integer.tlcDefSelectionSoundEffectSource); mAnimateCursorTransition = res.getBoolean(R.bool.tlcDefAnimateCursorTransition); mFollowCursorPosition = res.getBoolean(R.bool.tlcDefFollowCursorPosition); mAlwaysEnsureSelection = res.getBoolean(R.bool.tlcDefAlwaysEnsureSelection); mGraphAreaBgPaint = new Paint(); mGraphAreaBgPaint.setColor(graphBgColor); mFooterAreaBgPaint = new Paint(); mFooterAreaBgPaint.setColor(footerBgColor); mTickLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mTickLabelFgPaint.setFakeBoldText(true); mTickLabelFgPaint.setColor(MaterialPaletteHelper.isDarkColor(footerBgColor) ? Color.LTGRAY : Color.DKGRAY); mBarItemWidth = res.getDimension(R.dimen.tlcDefBarItemWidth); mBarItemSpace = res.getDimension(R.dimen.tlcDefBarItemSpace); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.tlcTimelineChartView, defStyleAttr, defStyleRes); try { int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); if (attr == R.styleable.tlcTimelineChartView_tlcGraphBackground) { graphBgColor = a.getColor(attr, graphBgColor); mGraphAreaBgPaint.setColor(graphBgColor); } else if (attr == R.styleable.tlcTimelineChartView_tlcShowFooter) { mShowFooter = a.getBoolean(attr, mShowFooter); } else if (attr == R.styleable.tlcTimelineChartView_tlcFooterBackground) { footerBgColor = a.getColor(attr, footerBgColor); mFooterAreaBgPaint.setColor(footerBgColor); } else if (attr == R.styleable.tlcTimelineChartView_tlcFooterBarHeight) { mFooterBarHeight = a.getDimension(attr, mFooterBarHeight); } else if (attr == R.styleable.tlcTimelineChartView_tlcGraphMode) { mGraphMode = a.getInt(attr, mGraphMode); } else if (attr == R.styleable.tlcTimelineChartView_tlcAnimateCursorTransition) { mAnimateCursorTransition = a.getBoolean(attr, mAnimateCursorTransition); } else if (attr == R.styleable.tlcTimelineChartView_tlcFollowCursorPosition) { mFollowCursorPosition = a.getBoolean(attr, mFollowCursorPosition); } else if (attr == R.styleable.tlcTimelineChartView_tlcAlwaysEnsureSelection) { mAlwaysEnsureSelection = a.getBoolean(attr, mAlwaysEnsureSelection); } else if (attr == R.styleable.tlcTimelineChartView_tlcBarItemWidth) { mBarItemWidth = a.getDimension(attr, mBarItemWidth); } else if (attr == R.styleable.tlcTimelineChartView_tlcBarItemSpace) { mBarItemSpace = a.getDimension(attr, mBarItemSpace); } else if (attr == R.styleable.tlcTimelineChartView_tlcPlaySelectionSoundEffect) { mPlaySelectionSoundEffect = a.getBoolean(attr, mPlaySelectionSoundEffect); } else if (attr == R.styleable.tlcTimelineChartView_tlcSelectionSoundEffectSource) { mSelectionSoundEffectSource = a.getInt(attr, mSelectionSoundEffectSource); } } } finally { a.recycle(); } // SurfaceView requires a background if (getBackground() == null) { setBackgroundColor(ContextCompat.getColor(ctx, android.R.color.transparent)); } // Minimize the impact of create dynamic layouts by assume that in most case // we will have a day formatter mTickHasDayFormat = true; // Initialize stuff setupBackgroundHandler(); setupTickLabels(); if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) { setupEdgeEffects(); } setupAnimators(); setupSoundEffects(); // Initialize the drawing refs (this will be update when we have // the real size of the canvas) computeBoundAreas(); // Create a fake data for the edit mode if (isInEditMode()) { setupViewInEditMode(); } }
From source file:org.mdc.chess.MDChess.java
private void initUI() { leftHanded = leftHandedView();/*w ww . ja va 2 s. c om*/ setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.main_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_main); navigationView.setNavigationItemSelectedListener(this); // title lines need to be regenerated every time due to layout changes (rotations) View firstTitleLine = findViewById(R.id.title_line); whiteTitleText = (TextView) findViewById(R.id.txt_first); whiteTitleText.setSelected(true); blackTitleText = (TextView) findViewById(R.id.txt_third); blackTitleText.setSelected(true); engineTitleText = (TextView) findViewById(R.id.txt_second); whiteFigText = (TextView) findViewById(R.id.white_pieces); whiteFigText.setTypeface(figNotation); whiteFigText.setSelected(true); whiteFigText.setTextColor(whiteTitleText.getTextColors()); blackFigText = (TextView) findViewById(R.id.black_pieces); blackFigText.setTypeface(figNotation); blackFigText.setSelected(true); blackFigText.setTextColor(blackTitleText.getTextColors()); status = (TextView) findViewById(R.id.status); moveListScroll = (ScrollView) findViewById(R.id.scrollView); moveList = (MoveListView) findViewById(R.id.moveList); thinking = (TextView) findViewById(R.id.thinking); defaultThinkingListTypeFace = thinking.getTypeface(); status.setFocusable(false); moveListScroll.setFocusable(false); moveList.setFocusable(false); thinking.setFocusable(false); class ClickListener implements OnClickListener, OnTouchListener { // --Commented out by Inspection (31/10/2016 10:41 PM):private float touchX = -1; @Override public void onClick(View v) { //boolean left = touchX <= v.getWidth() / 2.0; //drawerLayout.openDrawer(left ? GravityCompat.START : GravityCompat.END); //touchX = -1; } @Override public boolean onTouch(View v, MotionEvent event) { //touchX = event.getX(); return false; } } ClickListener listener = new ClickListener(); firstTitleLine.setOnClickListener(listener); firstTitleLine.setOnTouchListener(listener); cb = (ChessBoardPlay) findViewById(R.id.chessboard); cb.setFocusable(true); cb.requestFocus(); cb.setClickable(true); cb.setPgnOptions(pgnOptions); cb.setOnTouchListener(new OnTouchListener() { private final Handler handler = new Handler(); private boolean pending = false; private final Runnable runnable = new Runnable() { public void run() { pending = false; handler.removeCallbacks(runnable); ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(20); boardMenuDialog(); } }; private boolean pendingClick = false; private int sq0 = -1; private float scrollX = 0; private float scrollY = 0; private float prevX = 0; private float prevY = 0; @Override public boolean onTouch(View v, MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: handler.postDelayed(runnable, ViewConfiguration.getLongPressTimeout()); pending = true; pendingClick = true; sq0 = cb.eventToSquare(event); scrollX = 0; scrollY = 0; prevX = event.getX(); prevY = event.getY(); break; case MotionEvent.ACTION_MOVE: if (pending) { int sq = cb.eventToSquare(event); if (sq != sq0) { handler.removeCallbacks(runnable); pendingClick = false; } float currX = event.getX(); float currY = event.getY(); if (onScroll(currX - prevX, currY - prevY)) { handler.removeCallbacks(runnable); pendingClick = false; } prevX = currX; prevY = currY; } break; case MotionEvent.ACTION_UP: if (pending) { pending = false; handler.removeCallbacks(runnable); if (!pendingClick) { break; } int sq = cb.eventToSquare(event); if (sq == sq0) { if (ctrl.humansTurn()) { Move m = cb.mousePressed(sq); if (m != null) { setAutoMode(AutoMode.OFF); ctrl.makeHumanMove(m); } setEgtbHints(cb.getSelectedSquare()); } } } break; case MotionEvent.ACTION_CANCEL: pending = false; handler.removeCallbacks(runnable); break; } return true; } private boolean onScroll(float distanceX, float distanceY) { if (invertScrollDirection) { distanceX = -distanceX; distanceY = -distanceY; } if ((scrollSensitivity > 0) && (cb.sqSize > 0)) { scrollX += distanceX; scrollY += distanceY; final float scrollUnit = cb.sqSize * scrollSensitivity; if (Math.abs(scrollX) >= Math.abs(scrollY)) { // Undo/redo int nRedo = 0, nUndo = 0; while (scrollX > scrollUnit) { nRedo++; scrollX -= scrollUnit; } while (scrollX < -scrollUnit) { nUndo++; scrollX += scrollUnit; } if (nUndo + nRedo > 0) { scrollY = 0; setAutoMode(AutoMode.OFF); } if (nRedo + nUndo > 1) { boolean analysis = gameMode.analysisMode(); boolean human = gameMode.playerWhite() || gameMode.playerBlack(); if (analysis || !human) { ctrl.setGameMode(new GameMode(GameMode.TWO_PLAYERS)); } } for (int i = 0; i < nRedo; i++) ctrl.redoMove(); for (int i = 0; i < nUndo; i++) ctrl.undoMove(); ctrl.setGameMode(gameMode); return nRedo + nUndo > 0; } else { // Next/previous variation int varDelta = 0; while (scrollY > scrollUnit) { varDelta++; scrollY -= scrollUnit; } while (scrollY < -scrollUnit) { varDelta--; scrollY += scrollUnit; } if (varDelta != 0) { scrollX = 0; setAutoMode(AutoMode.OFF); ctrl.changeVariation(varDelta); } return varDelta != 0; } } return false; } }); /*cb.setOnTrackballListener(new ChessBoard.OnTrackballListener() { public void onTrackballEvent(MotionEvent event) { if (ctrl.humansTurn()) { Move m = cb.handleTrackballEvent(event); if (m != null) { setAutoMode(AutoMode.OFF); ctrl.makeHumanMove(m); } setEgtbHints(cb.getSelectedSquare()); } } });*/ moveList.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { moveListMenuDialog(); return true; } }); thinking.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { if (mShowThinking || gameMode.analysisMode()) { if (!pvMoves.isEmpty()) { thinkingMenuDialog(); } } return true; } }); }
From source file:org.petero.droidfish.DroidFish.java
private final void initUI() { leftHanded = leftHandedView();// w ww .ja va 2 s. co m setContentView(leftHanded ? R.layout.main_left_handed : R.layout.main); Util.overrideFonts(findViewById(android.R.id.content)); // title lines need to be regenerated every time due to layout changes (rotations) firstTitleLine = findViewById(R.id.first_title_line); secondTitleLine = findViewById(R.id.second_title_line); whiteTitleText = (TextView) findViewById(R.id.white_clock); whiteTitleText.setSelected(true); blackTitleText = (TextView) findViewById(R.id.black_clock); blackTitleText.setSelected(true); engineTitleText = (TextView) findViewById(R.id.title_text); whiteFigText = (TextView) findViewById(R.id.white_pieces); whiteFigText.setTypeface(figNotation); whiteFigText.setSelected(true); whiteFigText.setTextColor(whiteTitleText.getTextColors()); blackFigText = (TextView) findViewById(R.id.black_pieces); blackFigText.setTypeface(figNotation); blackFigText.setSelected(true); blackFigText.setTextColor(blackTitleText.getTextColors()); summaryTitleText = (TextView) findViewById(R.id.title_text_summary); status = (TextView) findViewById(R.id.status); moveListScroll = (ScrollView) findViewById(R.id.scrollView); moveList = (TextView) findViewById(R.id.moveList); defaultMoveListTypeFace = moveList.getTypeface(); thinking = (TextView) findViewById(R.id.thinking); defaultThinkingListTypeFace = thinking.getTypeface(); status.setFocusable(false); moveListScroll.setFocusable(false); moveList.setFocusable(false); moveList.setMovementMethod(LinkMovementMethod.getInstance()); thinking.setFocusable(false); firstTitleLine.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { openOptionsMenu(); } }); secondTitleLine.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { openOptionsMenu(); } }); cb = (ChessBoardPlay) findViewById(R.id.chessboard); cb.setFocusable(true); cb.requestFocus(); cb.setClickable(true); cb.setPgnOptions(pgnOptions); cb.setOnTouchListener(new OnTouchListener() { private boolean pending = false; private boolean pendingClick = false; private int sq0 = -1; private float scrollX = 0; private float scrollY = 0; private float prevX = 0; private float prevY = 0; private Handler handler = new Handler(); private Runnable runnable = new Runnable() { public void run() { pending = false; handler.removeCallbacks(runnable); ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(20); removeDialog(BOARD_MENU_DIALOG); showDialog(BOARD_MENU_DIALOG); } }; @Override public boolean onTouch(View v, MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: handler.postDelayed(runnable, ViewConfiguration.getLongPressTimeout()); pending = true; pendingClick = true; sq0 = cb.eventToSquare(event); scrollX = 0; scrollY = 0; prevX = event.getX(); prevY = event.getY(); break; case MotionEvent.ACTION_MOVE: if (pending) { int sq = cb.eventToSquare(event); if (sq != sq0) { handler.removeCallbacks(runnable); pendingClick = false; } float currX = event.getX(); float currY = event.getY(); if (onScroll(currX - prevX, currY - prevY)) { handler.removeCallbacks(runnable); pendingClick = false; } prevX = currX; prevY = currY; } break; case MotionEvent.ACTION_UP: if (pending) { pending = false; handler.removeCallbacks(runnable); if (!pendingClick) break; int sq = cb.eventToSquare(event); if (sq == sq0) { if (ctrl.humansTurn()) { Move m = cb.mousePressed(sq); if (m != null) { setAutoMode(AutoMode.OFF); ctrl.makeHumanMove(m); } setEgtbHints(cb.getSelectedSquare()); } } } break; case MotionEvent.ACTION_CANCEL: pending = false; handler.removeCallbacks(runnable); break; } return true; } private boolean onScroll(float distanceX, float distanceY) { if (invertScrollDirection) { distanceX = -distanceX; distanceY = -distanceY; } if ((scrollSensitivity > 0) && (cb.sqSize > 0)) { scrollX += distanceX; scrollY += distanceY; final float scrollUnit = cb.sqSize * scrollSensitivity; if (Math.abs(scrollX) >= Math.abs(scrollY)) { // Undo/redo int nRedo = 0, nUndo = 0; while (scrollX > scrollUnit) { nRedo++; scrollX -= scrollUnit; } while (scrollX < -scrollUnit) { nUndo++; scrollX += scrollUnit; } if (nUndo + nRedo > 0) { scrollY = 0; setAutoMode(AutoMode.OFF); } if (nRedo + nUndo > 1) { boolean analysis = gameMode.analysisMode(); boolean human = gameMode.playerWhite() || gameMode.playerBlack(); if (analysis || !human) ctrl.setGameMode(new GameMode(GameMode.TWO_PLAYERS)); } for (int i = 0; i < nRedo; i++) ctrl.redoMove(); for (int i = 0; i < nUndo; i++) ctrl.undoMove(); ctrl.setGameMode(gameMode); return nRedo + nUndo > 0; } else { // Next/previous variation int varDelta = 0; while (scrollY > scrollUnit) { varDelta++; scrollY -= scrollUnit; } while (scrollY < -scrollUnit) { varDelta--; scrollY += scrollUnit; } if (varDelta != 0) { scrollX = 0; setAutoMode(AutoMode.OFF); ctrl.changeVariation(varDelta); } return varDelta != 0; } } return false; } }); cb.setOnTrackballListener(new ChessBoard.OnTrackballListener() { public void onTrackballEvent(MotionEvent event) { if (ctrl.humansTurn()) { Move m = cb.handleTrackballEvent(event); if (m != null) { setAutoMode(AutoMode.OFF); ctrl.makeHumanMove(m); } setEgtbHints(cb.getSelectedSquare()); } } }); moveList.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { removeDialog(MOVELIST_MENU_DIALOG); showDialog(MOVELIST_MENU_DIALOG); return true; } }); thinking.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { if (mShowThinking || gameMode.analysisMode()) { if (!pvMoves.isEmpty()) { removeDialog(THINKING_MENU_DIALOG); showDialog(THINKING_MENU_DIALOG); } } return true; } }); custom1Button = (ImageButton) findViewById(R.id.custom1Button); custom1ButtonActions.setImageButton(custom1Button, this); custom2Button = (ImageButton) findViewById(R.id.custom2Button); custom2ButtonActions.setImageButton(custom2Button, this); custom3Button = (ImageButton) findViewById(R.id.custom3Button); custom3ButtonActions.setImageButton(custom3Button, this); modeButton = (ImageButton) findViewById(R.id.modeButton); modeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showDialog(GAME_MODE_DIALOG); } }); modeButton.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { openOptionsMenu(); return true; } }); undoButton = (ImageButton) findViewById(R.id.undoButton); undoButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setAutoMode(AutoMode.OFF); ctrl.undoMove(); } }); undoButton.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { removeDialog(GO_BACK_MENU_DIALOG); showDialog(GO_BACK_MENU_DIALOG); return true; } }); redoButton = (ImageButton) findViewById(R.id.redoButton); redoButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setAutoMode(AutoMode.OFF); ctrl.redoMove(); } }); redoButton.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { removeDialog(GO_FORWARD_MENU_DIALOG); showDialog(GO_FORWARD_MENU_DIALOG); return true; } }); }
From source file:org.catrobat.catroid.uitest.util.UiTestUtils.java
public static void longClickAndDrag(final Solo solo, final float xFrom, final float yFrom, final float xTo, final float yTo, final int steps) { final Activity activity = solo.getCurrentActivity(); Handler handler = new Handler(activity.getMainLooper()); handler.post(new Runnable() { public void run() { MotionEvent downEvent = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, xFrom, yFrom, 0); activity.dispatchTouchEvent(downEvent); downEvent.recycle();/*from w ww.ja va 2s .c o m*/ } }); solo.sleep(ViewConfiguration.getLongPressTimeout() + 200); handler.post(new Runnable() { public void run() { double offsetX = xTo - xFrom; offsetX /= steps; double offsetY = yTo - yFrom; offsetY /= steps; for (int i = 0; i <= steps; i++) { float x = xFrom + (float) (offsetX * i); float y = yFrom + (float) (offsetY * i); MotionEvent moveEvent = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, x, y, 0); activity.dispatchTouchEvent(moveEvent); solo.sleep(20); moveEvent.recycle(); } } }); solo.sleep(steps * 20 + 200); handler.post(new Runnable() { public void run() { MotionEvent upEvent = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, xTo, yTo, 0); activity.dispatchTouchEvent(upEvent); upEvent.recycle(); Log.d(TAG, "longClickAndDrag finished: " + (int) yTo); } }); solo.sleep(1000); }
From source file:com.appunite.list.AbsHorizontalListView.java
/** * Sets the selector state to "pressed" and posts a CheckForKeyLongPress to see if * this is a long press./*from www .ja v a 2 s .c o m*/ */ void keyPressed() { if (!isEnabled() || !isClickable()) { return; } Drawable selector = mSelector; Rect selectorRect = mSelectorRect; if (selector != null && (isFocused() || touchModeDrawsInPressedState()) && !selectorRect.isEmpty()) { final View v = getChildAt(mSelectedPosition - mFirstPosition); if (v != null) { if (v.hasFocusable()) return; v.setPressed(true); } setPressed(true); final boolean longClickable = isLongClickable(); Drawable d = selector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { if (longClickable) { ((TransitionDrawable) d).startTransition(ViewConfiguration.getLongPressTimeout()); } else { ((TransitionDrawable) d).resetTransition(); } } if (longClickable && !mDataChanged) { if (mPendingCheckForKeyLongPress == null) { mPendingCheckForKeyLongPress = new CheckForKeyLongPress(); } mPendingCheckForKeyLongPress.rememberWindowAttachCount(); postDelayed(mPendingCheckForKeyLongPress, ViewConfiguration.getLongPressTimeout()); } } }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private void triggerCheckForLongPress() { if (mPendingCheckForLongPress == null) { mPendingCheckForLongPress = new CheckForLongPress(); }// w w w .java 2s .co m mPendingCheckForLongPress.rememberWindowAttachCount(); postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout()); }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
/** * Sets the selector state to "pressed" and posts a CheckForKeyLongPress to see if * this is a long press.//from w w w . java2s . co m */ private void keyPressed() { if (!isEnabled() || !isClickable()) { return; } final Drawable selector = mSelector; final Rect selectorRect = mSelectorRect; if (selector != null && (isFocused() || touchModeDrawsInPressedState()) && !selectorRect.isEmpty()) { final View child = getChildAt(mSelectedPosition - mFirstPosition); if (child != null) { if (child.hasFocusable()) { return; } child.setPressed(true); } setPressed(true); final boolean longClickable = isLongClickable(); final Drawable d = selector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { if (longClickable) { ((TransitionDrawable) d).startTransition(ViewConfiguration.getLongPressTimeout()); } else { ((TransitionDrawable) d).resetTransition(); } } if (longClickable && !mDataChanged) { if (mPendingCheckForKeyLongPress == null) { mPendingCheckForKeyLongPress = new CheckForKeyLongPress(); } mPendingCheckForKeyLongPress.rememberWindowAttachCount(); postDelayed(mPendingCheckForKeyLongPress, ViewConfiguration.getLongPressTimeout()); } } }