List of usage examples for android.view MotionEvent getRawY
public final float getRawY()
From source file:com.spoiledmilk.ibikecph.navigation.SMRouteNavigationActivity.java
private void animateInstructions(MotionEvent event) { if (animationInstructions != null && animationInstructions.isInitialized()) { animationInstructions.cancel();//from w ww . java 2s. c o m } if (event.getAction() == MotionEvent.ACTION_DOWN) { if (System.currentTimeMillis() - lastDownTimestamp <= DOUBLE_TAP_PERIOD) { isDoubleTap = true; lastDownTimestamp = System.currentTimeMillis(); } else { lastDownTimestamp = 0; } lastDownTimestamp = System.currentTimeMillis(); mapFragment.locationOverlay.disableMyLocation(); lastY = event.getY(); instructionsView.setVisibility(View.GONE); instructionsViewMin.setVisibility(View.INVISIBLE); instructionsViewMax.setVisibility(View.VISIBLE); darkenedView.setVisibility(View.VISIBLE); darkenedView.getBackground().setAlpha(Util.yToAlpha((int) event.getRawY())); } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { if (isDoubleTap && System.currentTimeMillis() - lastDownTimestamp <= DOUBLE_TAP_PERIOD) { if (instructionsViewState == InstrcutionViewState.Normal) { setInstructionViewState(InstrcutionViewState.Maximized); } else if (instructionsViewState == InstrcutionViewState.Maximized) { setInstructionViewState(InstrcutionViewState.Normal); } else if (instructionsViewState == InstrcutionViewState.Minimized) { setInstructionViewState(InstrcutionViewState.Normal); } } else if (event.getRawY() < Util.getScreenHeight() / 2) { setInstructionViewState(InstrcutionViewState.Maximized); } else if (event.getRawY() < 9 * Util.getScreenHeight() / 10) { instructionList.smoothScrollToPosition(0); mapFragment.locationOverlay.enableMyLocation(mapFragment.locationProvider == null ? mapFragment.locationProvider = new GpsMyLocationProvider(this) : mapFragment.locationProvider); setInstructionViewState(InstrcutionViewState.Normal); } else { instructionList.smoothScrollToPosition(0); mapFragment.locationOverlay.enableMyLocation(mapFragment.locationProvider == null ? mapFragment.locationProvider = new GpsMyLocationProvider(this) : mapFragment.locationProvider); setInstructionViewState(InstrcutionViewState.Minimized); } instructionsViewMax.clearAnimation(); isDoubleTap = false; return; } if (event.getRawY() > Util.getScreenHeight() - Util.dp2px(40)) { pullHandleMax.setBackgroundColor(Color.TRANSPARENT); } else { pullHandleMax.setBackgroundColor(Color.rgb(26, 26, 26)); } darkenedView.getBackground().setAlpha(Util.yToAlpha((int) event.getRawY())); animationInstructions = new TranslateAnimation(0, 0, lastY, event.getY()); animationInstructions.setFillAfter(true); animationInstructions.setFillBefore(true); lastY = event.getY(); animationInstructions.setDuration(0); instructionsViewMax.startAnimation(animationInstructions); }
From source file:com.xpread.swipelistview.SwipeListViewTouchListener.java
/** * @see View.OnTouchListener#onTouch(android.view.View, * android.view.MotionEvent)// w w w.ja v a 2 s . c om */ @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (!isSwipeEnabled()) { return false; } if (viewWidth < 2) { viewWidth = swipeListView.getWidth(); } switch (MotionEventCompat.getActionMasked(motionEvent)) { case MotionEvent.ACTION_DOWN: { if (paused && downPosition != ListView.INVALID_POSITION) { return false; } swipeCurrentAction = SwipeListView.SWIPE_ACTION_NONE; int childCount = swipeListView.getChildCount(); int[] listViewCoords = new int[2]; swipeListView.getLocationOnScreen(listViewCoords); int x = (int) motionEvent.getRawX() - listViewCoords[0]; int y = (int) motionEvent.getRawY() - listViewCoords[1]; View child; for (int i = 0; i < childCount; i++) { child = swipeListView.getChildAt(i); child.getHitRect(rect); int childPosition = swipeListView.getPositionForView(child); // dont allow swiping if this is on the header or footer or // IGNORE_ITEM_VIEW_TYPE or enabled is false on the adapter boolean allowSwipe = swipeListView.getAdapter().isEnabled(childPosition) && swipeListView.getAdapter().getItemViewType(childPosition) >= 0; if (allowSwipe && rect.contains(x, y)) { setParentView(child); setFrontView(child.findViewById(swipeFrontView), childPosition); boolean result = downPosition == SwipeListView.INVALID_POSITION; downPosition = childPosition; frontView.setClickable(true); frontView.setLongClickable(!opened.get(downPosition)); changeSwipeMode = swipeListView.changeSwipeMode(downPosition); if (changeSwipeMode == SwipeListView.SWIPE_MODE_LEFT) { right2Open.set(downPosition, false); } else if (changeSwipeMode == SwipeListView.SWIPE_MODE_RIGHT) { right2Open.set(downPosition, true); } if (swipeBackView > 0) { setBackView(child.findViewById(swipeBackView)); } if (result) { velocityTracker = VelocityTracker.obtain(); velocityTracker.addMovement(motionEvent); downX = motionEvent.getRawX(); } break; } } view.onTouchEvent(motionEvent); return true; } case MotionEvent.ACTION_UP: { if (velocityTracker == null || !swiping || downPosition == ListView.INVALID_POSITION) { break; } float deltaX = motionEvent.getRawX() - downX; velocityTracker.addMovement(motionEvent); velocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(velocityTracker.getXVelocity()); if (!opened.get(downPosition)) { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && velocityTracker.getXVelocity() > 0) { velocityX = 0; } if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && velocityTracker.getXVelocity() < 0) { velocityX = 0; } } float velocityY = Math.abs(velocityTracker.getYVelocity()); boolean swap = false; boolean swapRight = false; if (minFlingVelocity <= velocityX && velocityX <= maxFlingVelocity && velocityY * 2 < velocityX) { swapRight = velocityTracker.getXVelocity() > 0; if (SwipeListView.DEBUG) { Log.d(SwipeListView.TAG, "swapRight: " + swapRight + " - swipingRight: " + swipingRight); } if (swapRight != swipingRight && swipeActionLeft != swipeActionRight) { swap = false; } else if (opened.get(downPosition) && openedRight.get(downPosition) && swapRight) { swap = false; } else if (opened.get(downPosition) && !openedRight.get(downPosition) && !swapRight) { swap = false; } else { int swipeMode = swipeListView.changeSwipeMode(downPosition); if (!opened.get(downPosition) && swipeMode == SwipeListView.SWIPE_MODE_RIGHT && !swapRight) { swap = false; } else if (!opened.get(downPosition) && swipeMode == SwipeListView.SWIPE_MODE_LEFT && swapRight) { swap = false; } else { swap = true; } } } else if (Math.abs(deltaX) > viewWidth / 2) { swap = true; swapRight = deltaX > 0; } initPos = true; generateAnimate(frontView, swap, swapRight, downPosition); if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { swapChoiceState(downPosition); } velocityTracker.recycle(); velocityTracker = null; downX = 0; swiping = false; break; } case MotionEvent.ACTION_MOVE: { if (velocityTracker == null || paused || downPosition == ListView.INVALID_POSITION) { break; } velocityTracker.addMovement(motionEvent); velocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(velocityTracker.getXVelocity()); float velocityY = Math.abs(velocityTracker.getYVelocity()); float deltaX = motionEvent.getRawX() - downX; float deltaMode = Math.abs(deltaX); int swipeMode = this.swipeMode; if (changeSwipeMode >= 0) { swipeMode = changeSwipeMode; } if (swipeMode == SwipeListView.SWIPE_MODE_NONE) { deltaMode = 0; } else if (swipeMode != SwipeListView.SWIPE_MODE_BOTH) { if (opened.get(downPosition)) { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX < 0) { deltaMode = 0; } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX > 0) { deltaMode = 0; } } else { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX > 0) { deltaMode = 0; } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX < 0) { deltaMode = 0; } } } if (deltaMode > slop && swipeCurrentAction == SwipeListView.SWIPE_ACTION_NONE && velocityY < velocityX) { swiping = true; swipingRight = (deltaX > 0); if (SwipeListView.DEBUG) { Log.d(SwipeListView.TAG, "deltaX: " + deltaX + " - swipingRight: " + swipingRight); } if (opened.get(downPosition)) { swipeListView.onStartClose(downPosition, swipingRight); swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } else { if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_DISMISS) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_DISMISS) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; } else if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_CHOICE) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_CHOICE) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; } else { swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } swipeListView.onStartOpen(downPosition, swipeCurrentAction, swipingRight); } swipeListView.requestDisallowInterceptTouchEvent(true); MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT)); swipeListView.onTouchEvent(cancelEvent); if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { backView.setVisibility(View.GONE); } } if (swiping && downPosition != ListView.INVALID_POSITION) { if (opened.get(downPosition)) { deltaX += openedRight.get(downPosition) ? viewWidth - rightOffset : -viewWidth + leftOffset; } move(deltaX); } return velocityY < velocityX; } } return false; }
From source file:com.android.ex.photo.PhotoViewPager.java
/** * {@inheritDoc}//from w w w . j a v a 2 s . c om * <p> * We intercept touch event intercepts so we can prevent switching views when the * current view is internally scrollable. */ @Override public boolean onInterceptTouchEvent(MotionEvent ev) { final InterceptType intercept = (mListener != null) ? mListener.onTouchIntercept(mActivatedX, mActivatedY) : InterceptType.NONE; final boolean ignoreScrollLeft = (intercept == InterceptType.BOTH || intercept == InterceptType.LEFT); final boolean ignoreScrollRight = (intercept == InterceptType.BOTH || intercept == InterceptType.RIGHT); // Only check ability to page if we can't scroll in one / both directions final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mActivePointerId = INVALID_POINTER; } switch (action) { case MotionEvent.ACTION_MOVE: { if (ignoreScrollLeft || ignoreScrollRight) { final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); if (ignoreScrollLeft && ignoreScrollRight) { mLastMotionX = x; return false; } else if (ignoreScrollLeft && (x > mLastMotionX)) { mLastMotionX = x; return false; } else if (ignoreScrollRight && (x < mLastMotionX)) { mLastMotionX = x; return false; } } break; } case MotionEvent.ACTION_DOWN: { mLastMotionX = ev.getX(); // Use the raw x/y as the children can be located anywhere and there isn't a // single offset that would be meaningful mActivatedX = ev.getRawX(); mActivatedY = ev.getRawY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { // Our active pointer going up; select a new active pointer final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex); mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } break; } } return super.onInterceptTouchEvent(ev); }
From source file:com.lowworker.android.views.custom_views.photo.PhotoViewPager.java
/** * {@inheritDoc}/*from w w w .ja va2 s . c om*/ * <p/> * We intercept touch event intercepts so we can prevent switching views when the * current view is internally scrollable. */ @Override public boolean onInterceptTouchEvent(MotionEvent ev) { final InterceptType intercept = (mListener != null) ? mListener.onTouchIntercept(mActivatedX, mActivatedY) : InterceptType.NONE; final boolean ignoreScrollLeft = (intercept == InterceptType.BOTH || intercept == InterceptType.LEFT); final boolean ignoreScrollRight = (intercept == InterceptType.BOTH || intercept == InterceptType.RIGHT); // Only check ability to page if we can't scroll in one / both directions final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mActivePointerId = INVALID_POINTER; } switch (action) { case MotionEvent.ACTION_MOVE: { if (ignoreScrollLeft || ignoreScrollRight) { final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); if (ignoreScrollLeft && ignoreScrollRight) { mLastMotionX = x; return false; } else if (ignoreScrollLeft && (x > mLastMotionX)) { mLastMotionX = x; return false; } else if (ignoreScrollRight && (x < mLastMotionX)) { mLastMotionX = x; return false; } } break; } case MotionEvent.ACTION_DOWN: { mLastMotionX = ev.getX(); // Use the raw x/y as the children can be located anywhere and there isn't a // single offset that would be meaningful mActivatedX = ev.getRawX(); mActivatedY = ev.getRawY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { // Our active pointer going up; select a new active pointer final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex); mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } break; } } return super.onInterceptTouchEvent(ev); }
From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabledInAdapterView() || !isEnabled()) return true; if (!isSwipeEnabled()) return super.onTouchEvent(event); int action = event.getActionMasked(); ViewParent parent = getParent();//w w w.ja v a2 s .com gestureDetector.onTouchEvent(event); Status status = getOpenStatus(); ViewGroup touching = null; if (status == Status.Close) { touching = getSurfaceView(); } else if (status == Status.Open) { touching = getBottomView(); } switch (action) { case MotionEvent.ACTION_DOWN: mDragHelper.processTouchEvent(event); parent.requestDisallowInterceptTouchEvent(true); sX = event.getRawX(); sY = event.getRawY(); if (touching != null) touching.setPressed(true); return true; case MotionEvent.ACTION_MOVE: { if (sX == -1 || sY == -1) { // Trick: // When in nested mode, we need to send a constructed ACTION_DOWN MotionEvent to mDragHelper, to help // it initialize itself. event.setAction(MotionEvent.ACTION_DOWN); mDragHelper.processTouchEvent(event); parent.requestDisallowInterceptTouchEvent(true); sX = event.getRawX(); sY = event.getRawY(); return true; } float distanceX = event.getRawX() - sX; float distanceY = event.getRawY() - sY; float angle = Math.abs(distanceY / distanceX); angle = (float) Math.toDegrees(Math.atan(angle)); boolean doNothing = false; if (mDragEdge == DragEdge.Right) { boolean suitable = (status == Status.Open && distanceX > 0) || (status == Status.Close && distanceX < 0); suitable = suitable || (status == Status.Middle); if (angle > 30 || !suitable) { doNothing = true; } } if (mDragEdge == DragEdge.Left) { boolean suitable = (status == Status.Open && distanceX < 0) || (status == Status.Close && distanceX > 0); suitable = suitable || status == Status.Middle; if (angle > 30 || !suitable) { doNothing = true; } } if (mDragEdge == DragEdge.Top) { boolean suitable = (status == Status.Open && distanceY < 0) || (status == Status.Close && distanceY > 0); suitable = suitable || status == Status.Middle; if (angle < 60 || !suitable) { doNothing = true; } } if (mDragEdge == DragEdge.Bottom) { boolean suitable = (status == Status.Open && distanceY > 0) || (status == Status.Close && distanceY < 0); suitable = suitable || status == Status.Middle; if (angle < 60 || !suitable) { doNothing = true; } } if (doNothing) { parent.requestDisallowInterceptTouchEvent(false); return false; } else { if (touching != null) { touching.setPressed(false); } parent.requestDisallowInterceptTouchEvent(true); mDragHelper.processTouchEvent(event); } break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { sX = -1; sY = -1; if (touching != null) { touching.setPressed(false); } } default: parent.requestDisallowInterceptTouchEvent(true); mDragHelper.processTouchEvent(event); } return true; }
From source file:com.popdeem.sdk.uikit.activity.PDUIClaimActivity.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { View v = getCurrentFocus();//from w ww . j av a 2s . c o m if (v != null && (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_MOVE) && v instanceof EditText && !v.getClass().getName().startsWith("android.webkit.")) { int scrcoords[] = new int[2]; v.getLocationOnScreen(scrcoords); float x = ev.getRawX() + v.getLeft() - scrcoords[0]; float y = ev.getRawY() + v.getTop() - scrcoords[1]; if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom()) hideKeyboard(this); } return super.dispatchTouchEvent(ev); }
From source file:github.daneren2005.dsub.fragments.NowPlayingFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { rootView = inflater.inflate(R.layout.download, container, false); setTitle(R.string.button_bar_now_playing); WindowManager w = context.getWindowManager(); Display d = w.getDefaultDisplay();/*from w w w . ja v a2 s. c om*/ swipeDistance = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100; swipeVelocity = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100; gestureScanner = new GestureDetector(this); playlistFlipper = (ViewFlipper) rootView.findViewById(R.id.download_playlist_flipper); emptyTextView = (TextView) rootView.findViewById(R.id.download_empty); songTitleTextView = (TextView) rootView.findViewById(R.id.download_song_title); albumArtImageView = (ImageView) rootView.findViewById(R.id.download_album_art_image); positionTextView = (TextView) rootView.findViewById(R.id.download_position); durationTextView = (TextView) rootView.findViewById(R.id.download_duration); statusTextView = (TextView) rootView.findViewById(R.id.download_status); progressBar = (SeekBar) rootView.findViewById(R.id.download_progress_bar); previousButton = (AutoRepeatButton) rootView.findViewById(R.id.download_previous); nextButton = (AutoRepeatButton) rootView.findViewById(R.id.download_next); pauseButton = rootView.findViewById(R.id.download_pause); stopButton = rootView.findViewById(R.id.download_stop); startButton = rootView.findViewById(R.id.download_start); repeatButton = (ImageButton) rootView.findViewById(R.id.download_repeat); bookmarkButton = (ImageButton) rootView.findViewById(R.id.download_bookmark); rateBadButton = (ImageButton) rootView.findViewById(R.id.download_rating_bad); rateGoodButton = (ImageButton) rootView.findViewById(R.id.download_rating_good); toggleListButton = rootView.findViewById(R.id.download_toggle_list); playlistView = (RecyclerView) rootView.findViewById(R.id.download_list); FastScroller fastScroller = (FastScroller) rootView.findViewById(R.id.download_fast_scroller); fastScroller.attachRecyclerView(playlistView); setupLayoutManager(playlistView, false); ItemTouchHelper touchHelper = new ItemTouchHelper(new DownloadFileItemHelperCallback(this, true)); touchHelper.attachToRecyclerView(playlistView); starButton = (ImageButton) rootView.findViewById(R.id.download_star); if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)) { starButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { DownloadFile currentDownload = getDownloadService().getCurrentPlaying(); if (currentDownload != null) { final Entry currentSong = currentDownload.getSong(); toggleStarred(currentSong, new OnStarChange() { @Override void starChange(boolean starred) { if (currentSong.isStarred()) { starButton.setImageDrawable( DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star)); } else { if (context.getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { starButton.setImageResource( DrawableTint.getDrawableRes(context, R.attr.star_outline)); } else { starButton.setImageResource(R.drawable.ic_toggle_star_outline_dark); } } } }); } } }); } else { starButton.setVisibility(View.GONE); } View.OnTouchListener touchListener = new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent me) { return gestureScanner.onTouchEvent(me); } }; pauseButton.setOnTouchListener(touchListener); stopButton.setOnTouchListener(touchListener); startButton.setOnTouchListener(touchListener); bookmarkButton.setOnTouchListener(touchListener); rateBadButton.setOnTouchListener(touchListener); rateGoodButton.setOnTouchListener(touchListener); emptyTextView.setOnTouchListener(touchListener); albumArtImageView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent me) { if (me.getAction() == MotionEvent.ACTION_DOWN) { lastY = (int) me.getRawY(); } return gestureScanner.onTouchEvent(me); } }); previousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { warnIfStorageUnavailable(); new SilentBackgroundTask<Void>(context) { @Override protected Void doInBackground() throws Throwable { getDownloadService().previous(); return null; } }.execute(); setControlsVisible(true); } }); previousButton.setOnRepeatListener(new Runnable() { public void run() { changeProgress(-INCREMENT_TIME); } }); nextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { warnIfStorageUnavailable(); new SilentBackgroundTask<Boolean>(context) { @Override protected Boolean doInBackground() throws Throwable { getDownloadService().next(); return true; } }.execute(); setControlsVisible(true); } }); nextButton.setOnRepeatListener(new Runnable() { public void run() { changeProgress(INCREMENT_TIME); } }); pauseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new SilentBackgroundTask<Void>(context) { @Override protected Void doInBackground() throws Throwable { getDownloadService().pause(); return null; } }.execute(); } }); stopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new SilentBackgroundTask<Void>(context) { @Override protected Void doInBackground() throws Throwable { getDownloadService().reset(); return null; } }.execute(); } }); startButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { warnIfStorageUnavailable(); new SilentBackgroundTask<Void>(context) { @Override protected Void doInBackground() throws Throwable { start(); return null; } }.execute(); } }); repeatButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { RepeatMode repeatMode = getDownloadService().getRepeatMode().next(); getDownloadService().setRepeatMode(repeatMode); switch (repeatMode) { case OFF: Util.toast(context, R.string.download_repeat_off); break; case ALL: Util.toast(context, R.string.download_repeat_all); break; case SINGLE: Util.toast(context, R.string.download_repeat_single); break; default: break; } updateRepeatButton(); setControlsVisible(true); } }); bookmarkButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { createBookmark(); } }); rateBadButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { DownloadService downloadService = getDownloadService(); if (downloadService == null) { return; } DownloadFile downloadFile = downloadService.getCurrentPlaying(); if (downloadFile == null) { return; } Entry entry = downloadFile.getSong(); // If rating == 1, already set so unset if (entry.getRating() == 1) { setRating(entry, 0); if (context.getResources() .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { rateBadButton.setImageResource(R.drawable.ic_action_rating_bad_dark); } else { rateBadButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_bad)); } } else { // Immediately skip to the next song downloadService.next(true); // Otherwise set rating to 1 setRating(entry, 1); rateBadButton.setImageDrawable( DrawableTint.getTintedDrawable(context, R.drawable.ic_action_rating_bad_selected)); // Make sure good rating is blank if (context.getResources() .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { rateGoodButton.setImageResource(R.drawable.ic_action_rating_good_dark); } else { rateGoodButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_good)); } } } }); rateGoodButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { DownloadService downloadService = getDownloadService(); if (downloadService == null) { return; } DownloadFile downloadFile = downloadService.getCurrentPlaying(); if (downloadFile == null) { return; } Entry entry = downloadFile.getSong(); // If rating == 5, already set so unset if (entry.getRating() == 5) { setRating(entry, 0); if (context.getResources() .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { rateGoodButton.setImageResource(R.drawable.ic_action_rating_good_dark); } else { rateGoodButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_good)); } } else { // Otherwise set rating to maximum setRating(entry, 5); rateGoodButton.setImageDrawable( DrawableTint.getTintedDrawable(context, R.drawable.ic_action_rating_good_selected)); // Make sure bad rating is blank if (context.getResources() .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { rateBadButton.setImageResource(R.drawable.ic_action_rating_bad_dark); } else { rateBadButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.rating_bad)); } } } }); toggleListButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { toggleFullscreenAlbumArt(); setControlsVisible(true); } }); View overlay = rootView.findViewById(R.id.download_overlay_buttons); final int overlayHeight = overlay != null ? overlay.getHeight() : -1; albumArtImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (overlayHeight == -1 || lastY < (view.getBottom() - overlayHeight)) { toggleFullscreenAlbumArt(); setControlsVisible(true); } } }); progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(final SeekBar seekBar) { new SilentBackgroundTask<Void>(context) { @Override protected Void doInBackground() throws Throwable { getDownloadService().seekTo(progressBar.getProgress()); return null; } @Override protected void done(Void result) { seekInProgress = false; } }.execute(); } @Override public void onStartTrackingTouch(final SeekBar seekBar) { seekInProgress = true; } @Override public void onProgressChanged(final SeekBar seekBar, final int position, final boolean fromUser) { if (fromUser) { positionTextView.setText(Util.formatDuration(position / 1000)); setControlsVisible(true); } } }); if (Build.MODEL.equals("Nexus 4") || Build.MODEL.equals("GT-I9100")) { View slider = rootView.findViewById(R.id.download_slider); slider.setPadding(0, 0, 0, 0); } return rootView; }
From source file:il.co.globes.android.swipeListView.SwipeListViewTouchListener.java
/** * @see View.OnTouchListener#onTouch(android.view.View, * android.view.MotionEvent)/* ww w . j a v a 2 s. c om*/ */ // @Override // public boolean onTouch(View view, MotionEvent motionEvent) // { // if (!isSwipeEnabled()) // { // return false; // } // // if (viewWidth < 2) // { // viewWidth = swipeListView.getWidth(); // } // // switch (MotionEventCompat.getActionMasked(motionEvent)) // { // case MotionEvent.ACTION_DOWN : // { // if (paused && downPosition != ListView.INVALID_POSITION) // { // return false; // } // swipeCurrentAction = SwipeListView.SWIPE_ACTION_NONE; // // int childCount = swipeListView.getChildCount(); // int[] listViewCoords = new int[2]; // swipeListView.getLocationOnScreen(listViewCoords); // int x = (int) motionEvent.getRawX() - listViewCoords[0]; // int y = (int) motionEvent.getRawY() - listViewCoords[1]; // View child; // for (int i = 0; i < childCount; i++) // { // child = swipeListView.getChildAt(i); // child.getHitRect(rect); // // int childPosition = swipeListView.getPositionForView(child); // // // dont allow swiping if this is on the header or footer or // // IGNORE_ITEM_VIEW_TYPE or enabled is false on the adapter // boolean allowSwipe = swipeListView.getAdapter().isEnabled(childPosition) // && swipeListView.getAdapter().getItemViewType(childPosition) >= 0; // // if (allowSwipe && rect.contains(x, y)) // { // setParentView(child); // setFrontView(child.findViewById(swipeFrontView)); // // downX = motionEvent.getRawX(); // downPosition = childPosition; // // frontView.setClickable(!opened.get(downPosition)); // frontView.setLongClickable(!opened.get(downPosition)); // // velocityTracker = VelocityTracker.obtain(); // velocityTracker.addMovement(motionEvent); // if (swipeBackView > 0) // { // setBackView(child.findViewById(swipeBackView)); // } // break; // } // } // view.onTouchEvent(motionEvent); // return true; // } // // case MotionEvent.ACTION_UP : // { // if (velocityTracker == null || !swiping || downPosition == // ListView.INVALID_POSITION) // { // break; // } // // float deltaX = motionEvent.getRawX() - downX; // velocityTracker.addMovement(motionEvent); // velocityTracker.computeCurrentVelocity(1000); // float velocityX = Math.abs(velocityTracker.getXVelocity()); // if (!opened.get(downPosition)) // { // if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && // velocityTracker.getXVelocity() > 0) // { // velocityX = 0; // } // if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && // velocityTracker.getXVelocity() < 0) // { // velocityX = 0; // } // } // float velocityY = Math.abs(velocityTracker.getYVelocity()); // boolean swap = false; // boolean swapRight = false; // if (minFlingVelocity <= velocityX && velocityX <= maxFlingVelocity && // velocityY * 2 < velocityX) // { // swapRight = velocityTracker.getXVelocity() > 0; // Log.d("SwipeListView", "swapRight: " + swapRight + " - swipingRight: " + // swipingRight); // if (swapRight != swipingRight && swipeActionLeft != swipeActionRight) // { // swap = false; // } // else if (opened.get(downPosition) && openedRight.get(downPosition) && // swapRight) // { // swap = false; // } // else if (opened.get(downPosition) && !openedRight.get(downPosition) && // !swapRight) // { // swap = false; // } // else // { // swap = true; // } // } // else if (Math.abs(deltaX) > viewWidth / 2) // { // swap = true; // swapRight = deltaX > 0; // } // generateAnimate(frontView, swap, swapRight, downPosition); // if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) // { // swapChoiceState(downPosition); // } // // velocityTracker.recycle(); // velocityTracker = null; // downX = 0; // // change clickable front view // // if (swap) { // // frontView.setClickable(opened.get(downPosition)); // // frontView.setLongClickable(opened.get(downPosition)); // // } // swiping = false; // break; // } // // case MotionEvent.ACTION_MOVE : // { // if (velocityTracker == null || paused || downPosition == // ListView.INVALID_POSITION) // { // break; // } // // velocityTracker.addMovement(motionEvent); // velocityTracker.computeCurrentVelocity(1000); // float velocityX = Math.abs(velocityTracker.getXVelocity()); // float velocityY = Math.abs(velocityTracker.getYVelocity()); // // float deltaX = motionEvent.getRawX() - downX; // float deltaMode = Math.abs(deltaX); // // int swipeMode = this.swipeMode; // int changeSwipeMode = swipeListView.changeSwipeMode(downPosition); // if (changeSwipeMode >= 0) // { // swipeMode = changeSwipeMode; // } // // if (swipeMode == SwipeListView.SWIPE_MODE_NONE) // { // deltaMode = 0; // } // else if (swipeMode != SwipeListView.SWIPE_MODE_BOTH) // { // if (opened.get(downPosition)) // { // if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX < 0) // { // deltaMode = 0; // } // else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX > 0) // { // deltaMode = 0; // } // } // else // { // if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX > 0) // { // deltaMode = 0; // } // else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX < 0) // { // deltaMode = 0; // } // } // } // if (deltaMode > slop && swipeCurrentAction == // SwipeListView.SWIPE_ACTION_NONE && velocityY < velocityX) // { // swiping = true; // swipingRight = (deltaX > 0); // Log.d("SwipeListView", "deltaX: " + deltaX + " - swipingRight: " + // swipingRight); // if (opened.get(downPosition)) // { // swipeListView.onStartClose(downPosition, swipingRight); // swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; // } // else // { // if (swipingRight && swipeActionRight == // SwipeListView.SWIPE_ACTION_DISMISS) // { // swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; // } // else if (!swipingRight && swipeActionLeft == // SwipeListView.SWIPE_ACTION_DISMISS) // { // swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; // } // else if (swipingRight && swipeActionRight == // SwipeListView.SWIPE_ACTION_CHOICE) // { // swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; // } // else if (!swipingRight && swipeActionLeft == // SwipeListView.SWIPE_ACTION_CHOICE) // { // swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; // } // else // { // swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; // } // swipeListView.onStartOpen(downPosition, swipeCurrentAction, // swipingRight); // } // swipeListView.requestDisallowInterceptTouchEvent(true); // MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); // cancelEvent.setAction(MotionEvent.ACTION_CANCEL // | (MotionEventCompat.getActionIndex(motionEvent) << // MotionEventCompat.ACTION_POINTER_INDEX_SHIFT)); // swipeListView.onTouchEvent(cancelEvent); // if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) // { // backView.setVisibility(View.GONE); // } // } // // if (swiping && downPosition != ListView.INVALID_POSITION) // { // if (opened.get(downPosition)) // { // deltaX += openedRight.get(downPosition) ? viewWidth - rightOffset : // -viewWidth + leftOffset; // } // move(deltaX); // return true; // } // break; // } // } // return false; // } // @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (!isSwipeEnabled()) { return false; } if (viewWidth < 2) { viewWidth = swipeListView.getWidth(); } switch (MotionEventCompat.getActionMasked(motionEvent)) { case MotionEvent.ACTION_DOWN: { if (paused && downPosition != ListView.INVALID_POSITION) { return false; } swipeCurrentAction = SwipeListView.SWIPE_ACTION_NONE; int childCount = swipeListView.getChildCount(); int[] listViewCoords = new int[2]; swipeListView.getLocationOnScreen(listViewCoords); int x = (int) motionEvent.getRawX() - listViewCoords[0]; int y = (int) motionEvent.getRawY() - listViewCoords[1]; View child; for (int i = 0; i < childCount; i++) { child = swipeListView.getChildAt(i); child.getHitRect(rect); int childPosition = swipeListView.getPositionForView(child); // dont allow swiping if this is on the header or footer or // IGNORE_ITEM_VIEW_TYPE or enabled is false on the adapter boolean allowSwipe = swipeListView.getAdapter().isEnabled(childPosition) && swipeListView.getAdapter().getItemViewType(childPosition) >= 0; if (allowSwipe && rect.contains(x, y)) { setParentView(child); setFrontView(child.findViewById(swipeFrontView)); downX = motionEvent.getRawX(); downPosition = childPosition; frontView.setClickable(!opened.get(downPosition)); frontView.setLongClickable(!opened.get(downPosition)); velocityTracker = VelocityTracker.obtain(); velocityTracker.addMovement(motionEvent); if (swipeBackView > 0) { setBackView(child.findViewById(swipeBackView)); } break; } } view.onTouchEvent(motionEvent); return true; } case MotionEvent.ACTION_UP: { if (velocityTracker == null || !swiping || downPosition == ListView.INVALID_POSITION) { break; } float deltaX = motionEvent.getRawX() - downX; velocityTracker.addMovement(motionEvent); velocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(velocityTracker.getXVelocity()); if (!opened.get(downPosition)) { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && velocityTracker.getXVelocity() > 0) { velocityX = 0; } if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && velocityTracker.getXVelocity() < 0) { velocityX = 0; } } float velocityY = Math.abs(velocityTracker.getYVelocity()); boolean swap = false; boolean swapRight = false; if (minFlingVelocity <= velocityX && velocityX <= maxFlingVelocity && velocityY * 2 < velocityX) { swapRight = velocityTracker.getXVelocity() > 0; Log.d("SwipeListView", "swapRight: " + swapRight + " - swipingRight: " + swipingRight); if (swapRight != swipingRight && swipeActionLeft != swipeActionRight) { swap = false; } else if (opened.get(downPosition) && openedRight.get(downPosition) && swapRight) { swap = false; } else if (opened.get(downPosition) && !openedRight.get(downPosition) && !swapRight) { swap = false; } else { swap = true; } } else if (Math.abs(deltaX) > viewWidth / 2) { swap = true; swapRight = deltaX > 0; } generateAnimate(frontView, swap, swapRight, downPosition); if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { swapChoiceState(downPosition); } velocityTracker.recycle(); velocityTracker = null; downX = 0; // change clickable front view // if (swap) { // frontView.setClickable(opened.get(downPosition)); // frontView.setLongClickable(opened.get(downPosition)); // } swiping = false; break; } case MotionEvent.ACTION_MOVE: { if (velocityTracker == null || paused || downPosition == ListView.INVALID_POSITION) { break; } velocityTracker.addMovement(motionEvent); velocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(velocityTracker.getXVelocity()); float velocityY = Math.abs(velocityTracker.getYVelocity()); float deltaX = motionEvent.getRawX() - downX; float deltaMode = Math.abs(deltaX); int swipeMode = this.swipeMode; int changeSwipeMode = swipeListView.changeSwipeMode(downPosition); if (changeSwipeMode >= 0) { swipeMode = changeSwipeMode; } if (swipeMode == SwipeListView.SWIPE_MODE_NONE) { deltaMode = 0; } else if (swipeMode != SwipeListView.SWIPE_MODE_BOTH) { if (opened.get(downPosition)) { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX < 0) { deltaMode = 0; } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX > 0) { deltaMode = 0; } } else { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX > 0) { deltaMode = 0; } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX < 0) { deltaMode = 0; } } } if (deltaMode > slop && swipeCurrentAction == SwipeListView.SWIPE_ACTION_NONE && velocityY < velocityX) { swiping = true; swipingRight = (deltaX > 0); Log.d("SwipeListView", "deltaX: " + deltaX + " - swipingRight: " + swipingRight); if (opened.get(downPosition)) { swipeListView.onStartClose(downPosition, swipingRight); swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } else { if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_DISMISS) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_DISMISS) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; } else if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_CHOICE) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_CHOICE) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; } else { swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } swipeListView.onStartOpen(downPosition, swipeCurrentAction, swipingRight); } swipeListView.requestDisallowInterceptTouchEvent(true); MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT)); swipeListView.onTouchEvent(cancelEvent); if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { backView.setVisibility(View.GONE); } } if (swiping && downPosition != ListView.INVALID_POSITION) { if (opened.get(downPosition)) { deltaX += openedRight.get(downPosition) ? viewWidth - rightOffset : -viewWidth + leftOffset; } move(deltaX); return true; } break; } } closeOtherOpenedItems(); view.onTouchEvent(motionEvent); return true; // return false; }
From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java
private void initGestureScanner(final Context context) { slop = ViewConfiguration.get(context).getScaledTouchSlop(); screenWidth = ScreenUtil.getScreenWidth(context); gestureDetector = new GestureDetectorCompat(context, new LilyGestureListener()); setOnTouchListener(new OnTouchListener() { @Override/*from w ww . ja v a 2 s. c om*/ public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_UP: if (adjustProgress) { adjustProgress = false; int newPosition = (int) (getCurrentPosition() + scrollX / screenWidth * 1000 * 90); if (newPosition < 0) { seekTo(0); } else { seekTo(newPosition); } start(); mAdjustProgressView.setVisibility(GONE); if (mMediaController.isShowing()) { showAllBoard(); } } scrollX = 0; scrollY = 0; level = 0; adjustVolume = false; adjustBrightness = false; break; case MotionEvent.ACTION_DOWN: lastX = motionEvent.getRawX(); lastY = motionEvent.getRawY(); if (motionEvent.getRawX() > screenWidth / 2 + 150) { adjustVolume = true; adjustBrightness = false; } else if (motionEvent.getRawX() < screenWidth / 2 - 150) { adjustBrightness = true; adjustVolume = false; } break; case MotionEvent.ACTION_MOVE: if (adjustProgress) { break; } if (Math.abs(motionEvent.getRawY() - lastY) > Math.abs(motionEvent.getRawX() - lastX)) { AudioManager audioManager = (AudioManager) mAppContext .getSystemService(Context.AUDIO_SERVICE); if (motionEvent.getRawY() > lastY) { level += motionEvent.getRawY() - lastY; if (level > slop) { if (adjustVolume) { audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); } else if (adjustBrightness) { float brightness = ScreenUtil.getScreenBrightness((Activity) context); if (brightness <= 0.1f) { ScreenUtil.setScreenBrightness((Activity) context, 0.0f); } else { ScreenUtil.setScreenBrightness((Activity) context, ScreenUtil.getScreenBrightness((Activity) context) - 0.1f); } } level = 0; } } else { level += lastY - motionEvent.getRawY(); if (level > slop) { if (adjustVolume) { audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); } else if (adjustBrightness) { float brightness = ScreenUtil.getScreenBrightness((Activity) context); if (brightness >= 0.9f) { ScreenUtil.setScreenBrightness((Activity) context, 1.0f); } else { ScreenUtil.setScreenBrightness((Activity) context, ScreenUtil.getScreenBrightness((Activity) context) + 0.1f); } } level = 0; } } } lastX = motionEvent.getRawX(); lastY = motionEvent.getRawY(); break; } return gestureDetector.onTouchEvent(motionEvent); } }); }
From source file:github.popeen.dsub.fragments.NowPlayingFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { rootView = inflater.inflate(R.layout.download, container, false); setTitle(R.string.button_bar_now_playing); WindowManager w = context.getWindowManager(); Display d = w.getDefaultDisplay();/*from w w w .jav a 2s . co m*/ swipeDistance = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100; swipeVelocity = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100; gestureScanner = new GestureDetector(this); playlistFlipper = (ViewFlipper) rootView.findViewById(R.id.download_playlist_flipper); emptyTextView = (TextView) rootView.findViewById(R.id.download_empty); songTitleTextView = (TextView) rootView.findViewById(R.id.download_song_title); albumArtImageView = (ImageView) rootView.findViewById(R.id.download_album_art_image); positionTextView = (TextView) rootView.findViewById(R.id.download_position); durationTextView = (TextView) rootView.findViewById(R.id.download_duration); statusTextView = (TextView) rootView.findViewById(R.id.download_status); progressBar = (SeekBar) rootView.findViewById(R.id.download_progress_bar); previousButton = (AutoRepeatButton) rootView.findViewById(R.id.download_previous); nextButton = (AutoRepeatButton) rootView.findViewById(R.id.download_next); rewindButton = (AutoRepeatButton) rootView.findViewById(R.id.download_rewind); fastforwardButton = (AutoRepeatButton) rootView.findViewById(R.id.download_fastforward); pauseButton = rootView.findViewById(R.id.download_pause); stopButton = rootView.findViewById(R.id.download_stop); startButton = rootView.findViewById(R.id.download_start); repeatButton = (ImageButton) rootView.findViewById(R.id.download_repeat); bookmarkButton = (ImageButton) rootView.findViewById(R.id.download_bookmark); rateBadButton = (ImageButton) rootView.findViewById(R.id.download_rating_bad); rateGoodButton = (ImageButton) rootView.findViewById(R.id.download_rating_good); playbackSpeedButton = (ImageButton) rootView.findViewById(R.id.download_playback_speed); toggleListButton = rootView.findViewById(R.id.download_toggle_list); playlistView = (RecyclerView) rootView.findViewById(R.id.download_list); FastScroller fastScroller = (FastScroller) rootView.findViewById(R.id.download_fast_scroller); fastScroller.attachRecyclerView(playlistView); setupLayoutManager(playlistView, false); ItemTouchHelper touchHelper = new ItemTouchHelper(new DownloadFileItemHelperCallback(this, true)); touchHelper.attachToRecyclerView(playlistView); starButton = (ImageButton) rootView.findViewById(R.id.download_star); if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)) { starButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getDownloadService().toggleStarred(); setControlsVisible(true); } }); } else { starButton.setVisibility(View.GONE); } View.OnTouchListener touchListener = new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent me) { return gestureScanner.onTouchEvent(me); } }; pauseButton.setOnTouchListener(touchListener); stopButton.setOnTouchListener(touchListener); startButton.setOnTouchListener(touchListener); bookmarkButton.setOnTouchListener(touchListener); rateBadButton.setOnTouchListener(touchListener); rateGoodButton.setOnTouchListener(touchListener); playbackSpeedButton.setOnTouchListener(touchListener); emptyTextView.setOnTouchListener(touchListener); albumArtImageView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent me) { if (me.getAction() == MotionEvent.ACTION_DOWN) { lastY = (int) me.getRawY(); } return gestureScanner.onTouchEvent(me); } }); previousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { warnIfStorageUnavailable(); new SilentBackgroundTask<Void>(context) { @Override protected Void doInBackground() throws Throwable { getDownloadService().previous(); return null; } }.execute(); setControlsVisible(true); } }); previousButton.setOnRepeatListener(new Runnable() { public void run() { changeProgress(true); } }); nextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { warnIfStorageUnavailable(); new SilentBackgroundTask<Boolean>(context) { @Override protected Boolean doInBackground() throws Throwable { getDownloadService().next(); return true; } }.execute(); setControlsVisible(true); } }); nextButton.setOnRepeatListener(new Runnable() { public void run() { changeProgress(false); } }); rewindButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { changeProgress(true); } }); rewindButton.setOnRepeatListener(new Runnable() { public void run() { changeProgress(true); } }); fastforwardButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { changeProgress(false); } }); fastforwardButton.setOnRepeatListener(new Runnable() { public void run() { changeProgress(false); } }); pauseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new SilentBackgroundTask<Void>(context) { @Override protected Void doInBackground() throws Throwable { getDownloadService().pause(); return null; } }.execute(); } }); stopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new SilentBackgroundTask<Void>(context) { @Override protected Void doInBackground() throws Throwable { getDownloadService().reset(); return null; } }.execute(); } }); startButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { warnIfStorageUnavailable(); new SilentBackgroundTask<Void>(context) { @Override protected Void doInBackground() throws Throwable { start(); return null; } }.execute(); } }); repeatButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { RepeatMode repeatMode = getDownloadService().getRepeatMode().next(); getDownloadService().setRepeatMode(repeatMode); switch (repeatMode) { case OFF: Util.toast(context, R.string.download_repeat_off); break; case ALL: Util.toast(context, R.string.download_repeat_all); break; case SINGLE: Util.toast(context, R.string.download_repeat_single); break; default: break; } updateRepeatButton(); setControlsVisible(true); } }); bookmarkButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { createBookmark(); setControlsVisible(true); } }); rateBadButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { DownloadService downloadService = getDownloadService(); if (downloadService == null) { return; } downloadService.toggleRating(1); setControlsVisible(true); } }); rateGoodButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { DownloadService downloadService = getDownloadService(); if (downloadService == null) { return; } downloadService.toggleRating(5); setControlsVisible(true); } }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setPlaybackSpeed(); } else { playbackSpeedButton.setVisibility(View.GONE); } toggleListButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { toggleFullscreenAlbumArt(); setControlsVisible(true); } }); View overlay = rootView.findViewById(R.id.download_overlay_buttons); final int overlayHeight = overlay != null ? overlay.getHeight() : -1; albumArtImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (overlayHeight == -1 || lastY < (view.getBottom() - overlayHeight)) { toggleFullscreenAlbumArt(); setControlsVisible(true); } } }); progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(final SeekBar seekBar) { new SilentBackgroundTask<Void>(context) { @Override protected Void doInBackground() throws Throwable { getDownloadService().seekTo(progressBar.getProgress()); return null; } @Override protected void done(Void result) { seekInProgress = false; } }.execute(); } @Override public void onStartTrackingTouch(final SeekBar seekBar) { seekInProgress = true; } @Override public void onProgressChanged(final SeekBar seekBar, final int position, final boolean fromUser) { if (fromUser) { positionTextView.setText(Util.formatDuration(position / 1000)); setControlsVisible(true); } DownloadService downloadService = getDownloadService(); TextView textTimer = (TextView) context.findViewById(R.id.textTimer); if (downloadService != null && downloadService.getSleepTimer()) { int timeRemaining = downloadService.getSleepTimeRemaining(); textTimer.setText(context.getResources().getString(R.string.download_stop_time_remaining, Util.formatDuration(timeRemaining))); if (timeRemaining > 0) { textTimer.setVisibility(View.VISIBLE); } else { textTimer.setVisibility(View.GONE); } } else { if (textTimer != null) { textTimer.setVisibility(View.GONE); } } } }); return rootView; }