Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VLC-Android
Manage
Activity
Members
Labels
Plan
Issues
533
Issue boards
Milestones
Wiki
Code
Merge requests
11
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VideoLAN
VLC-Android
Commits
c5060198
Commit
c5060198
authored
7 years ago
by
Geoffrey Métais
Browse files
Options
Downloads
Patches
Plain Diff
Improve fast scroller
parent
f5ac2666
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
vlc-android/src/org/videolan/vlc/gui/view/FastScroller.java
+58
-49
58 additions, 49 deletions
vlc-android/src/org/videolan/vlc/gui/view/FastScroller.java
with
58 additions
and
49 deletions
vlc-android/src/org/videolan/vlc/gui/view/FastScroller.java
+
58
−
49
View file @
c5060198
...
...
@@ -45,6 +45,7 @@ import android.widget.TextView;
import
org.videolan.libvlc.util.AndroidUtil
;
import
org.videolan.vlc.R
;
import
org.videolan.vlc.util.WeakHandler
;
@TargetApi
(
Build
.
VERSION_CODES
.
HONEYCOMB
)
...
...
@@ -65,14 +66,20 @@ public class FastScroller extends LinearLayout {
private
static
final
String
SCALE_Y
=
"scaleY"
;
private
static
final
String
ALPHA
=
"alpha"
;
private
int
mHeight
,
mItemCount
,
mRecyclerviewTotalHeight
;
boolean
mFastScrolling
,
mShowBubble
;
private
boolean
mFastScrolling
,
mShowBubble
;
private
int
mCurrentPosition
;
private
AnimatorSet
c
urrentAnimator
=
null
;
private
AnimatorSet
mC
urrentAnimator
=
null
;
private
final
ScrollListener
scrollListener
=
new
ScrollListener
();
private
RecyclerView
mRecyclerView
;
private
ImageView
handle
;
private
TextView
bubble
;
public
interface
SeparatedAdapter
{
boolean
hasSections
();
String
getSectionforPosition
(
int
position
);
}
public
FastScroller
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
initialize
(
context
);
...
...
@@ -100,9 +107,10 @@ public class FastScroller extends LinearLayout {
}
private
void
showBubble
()
{
AnimatorSet
animatorSet
=
new
AnimatorSet
();
final
AnimatorSet
animatorSet
=
new
AnimatorSet
();
bubble
.
setPivotX
(
bubble
.
getWidth
());
bubble
.
setPivotY
(
bubble
.
getHeight
());
scrollListener
.
onScrolled
(
mRecyclerView
,
0
,
0
);
bubble
.
setVisibility
(
VISIBLE
);
Animator
growerX
=
ObjectAnimator
.
ofFloat
(
bubble
,
SCALE_X
,
0
f
,
1
f
).
setDuration
(
HANDLE_ANIMATION_DURATION
);
Animator
growerY
=
ObjectAnimator
.
ofFloat
(
bubble
,
SCALE_Y
,
0
f
,
1
f
).
setDuration
(
HANDLE_ANIMATION_DURATION
);
...
...
@@ -112,19 +120,19 @@ public class FastScroller extends LinearLayout {
}
private
void
hideBubble
()
{
c
urrentAnimator
=
new
AnimatorSet
();
mC
urrentAnimator
=
new
AnimatorSet
();
bubble
.
setPivotX
(
bubble
.
getWidth
());
bubble
.
setPivotY
(
bubble
.
getHeight
());
Animator
shrinkerX
=
ObjectAnimator
.
ofFloat
(
bubble
,
SCALE_X
,
1
f
,
0
f
).
setDuration
(
HANDLE_ANIMATION_DURATION
);
Animator
shrinkerY
=
ObjectAnimator
.
ofFloat
(
bubble
,
SCALE_Y
,
1
f
,
0
f
).
setDuration
(
HANDLE_ANIMATION_DURATION
);
Animator
alpha
=
ObjectAnimator
.
ofFloat
(
bubble
,
ALPHA
,
1
f
,
0
f
).
setDuration
(
HANDLE_ANIMATION_DURATION
);
c
urrentAnimator
.
playTogether
(
shrinkerX
,
shrinkerY
,
alpha
);
c
urrentAnimator
.
addListener
(
new
AnimatorListenerAdapter
()
{
mC
urrentAnimator
.
playTogether
(
shrinkerX
,
shrinkerY
,
alpha
);
mC
urrentAnimator
.
addListener
(
new
AnimatorListenerAdapter
()
{
@Override
public
void
onAnimationEnd
(
Animator
animation
)
{
super
.
onAnimationEnd
(
animation
);
bubble
.
setVisibility
(
GONE
);
c
urrentAnimator
=
null
;
mC
urrentAnimator
=
null
;
mHandler
.
sendEmptyMessageDelayed
(
HIDE_SCROLLER
,
SCROLLER_HIDE_DELAY
);
}
...
...
@@ -132,18 +140,18 @@ public class FastScroller extends LinearLayout {
public
void
onAnimationCancel
(
Animator
animation
)
{
super
.
onAnimationCancel
(
animation
);
bubble
.
setVisibility
(
INVISIBLE
);
c
urrentAnimator
=
null
;
mC
urrentAnimator
=
null
;
mHandler
.
sendEmptyMessageDelayed
(
HIDE_SCROLLER
,
SCROLLER_HIDE_DELAY
);
}
});
c
urrentAnimator
.
start
();
mC
urrentAnimator
.
start
();
}
private
void
setPosition
(
float
y
)
{
float
position
=
y
/
mHeight
;
int
handleHeight
=
handle
.
getHeight
();
final
float
position
=
y
/
mHeight
;
final
int
handleHeight
=
handle
.
getHeight
();
ViewCompat
.
setY
(
handle
,
getValueInRange
(
0
,
mHeight
-
handleHeight
,
(
int
)
((
mHeight
-
handleHeight
)
*
position
)));
int
bubbleHeight
=
bubble
.
getHeight
();
final
int
bubbleHeight
=
bubble
.
getHeight
();
ViewCompat
.
setY
(
bubble
,
getValueInRange
(
0
,
mHeight
-
bubbleHeight
,
(
int
)
((
mHeight
-
bubbleHeight
)
*
position
)
-
handleHeight
));
}
...
...
@@ -164,9 +172,9 @@ public class FastScroller extends LinearLayout {
public
boolean
onTouchEvent
(
@NonNull
MotionEvent
event
)
{
if
(
event
.
getAction
()
==
MotionEvent
.
ACTION_DOWN
||
event
.
getAction
()
==
MotionEvent
.
ACTION_MOVE
)
{
mFastScrolling
=
true
;
se
tPosition
(
event
.
getY
())
;
if
(
c
urrentAnimator
!=
null
)
c
urrentAnimator
.
cancel
();
mCurren
tPosition
=
-
1
;
if
(
mC
urrentAnimator
!=
null
)
mC
urrentAnimator
.
cancel
();
mHandler
.
removeMessages
(
HIDE_SCROLLER
);
mHandler
.
removeMessages
(
HIDE_HANDLE
);
if
(
mShowBubble
&&
bubble
.
getVisibility
()
==
GONE
)
...
...
@@ -182,7 +190,6 @@ public class FastScroller extends LinearLayout {
return
super
.
onTouchEvent
(
event
);
}
int
formerPosition
;
private
void
setRecyclerViewPosition
(
float
y
)
{
if
(
mRecyclerView
!=
null
)
{
float
proportion
;
...
...
@@ -193,56 +200,38 @@ public class FastScroller extends LinearLayout {
}
else
{
proportion
=
y
/
(
float
)
mHeight
;
}
int
targetPos
=
getValueInRange
(
0
,
mItemCount
-
1
,
Math
.
round
(
proportion
*
(
float
)
mItemCount
));
if
(
targetPos
==
former
Position
)
final
int
targetPos
=
getValueInRange
(
0
,
mItemCount
-
1
,
Math
.
round
(
proportion
*
(
float
)
mItemCount
));
if
(
targetPos
==
mCurrent
Position
)
return
;
mCurrentPosition
=
targetPos
;
mRecyclerView
.
scrollToPosition
(
targetPos
);
}
}
private
int
getValueInRange
(
int
min
,
int
max
,
int
value
)
{
int
minimum
=
Math
.
max
(
min
,
value
);
return
Math
.
min
(
minimum
,
max
);
return
Math
.
min
(
Math
.
max
(
min
,
value
),
max
);
}
private
final
Handler
mHandler
=
new
Handler
()
{
@Override
public
void
handleMessage
(
Message
msg
)
{
switch
(
msg
.
what
)
{
case
HIDE_HANDLE:
hideBubble
();
break
;
case
HIDE_SCROLLER:
FastScroller
.
this
.
setVisibility
(
INVISIBLE
);
break
;
case
SHOW_SCROLLER:
FastScroller
.
this
.
setVisibility
(
VISIBLE
);
mHandler
.
removeMessages
(
HIDE_SCROLLER
);
mHandler
.
sendEmptyMessageDelayed
(
HIDE_SCROLLER
,
SCROLLER_HIDE_DELAY
);
break
;
}
}
};
private
class
ScrollListener
extends
RecyclerView
.
OnScrollListener
{
StringBuilder
sb
=
new
StringBuilder
();
@Override
public
void
onScrolled
(
RecyclerView
rv
,
int
dx
,
int
dy
)
{
sb
.
setLength
(
0
);
if
(
mRecyclerviewTotalHeight
==
0
)
mRecyclerviewTotalHeight
=
mRecyclerView
.
computeVerticalScrollRange
()-
mRecyclerView
.
computeVerticalScrollExtent
();
int
firstVisiblePosition
=
((
LinearLayoutManager
)
mRecyclerView
.
getLayoutManager
()).
findFirstVisibleItemPosition
();
final
float
proportion
=
mRecyclerviewTotalHeight
==
0
?
0
f
:
rv
.
computeVerticalScrollOffset
()
/
(
float
)
mRecyclerviewTotalHeight
;
setPosition
(
mHeight
*
proportion
);
if
(
mFastScrolling
)
{
sb
.
setLength
(
0
);
int
position
=
mCurrentPosition
!=
-
1
?
mCurrentPosition
:
((
LinearLayoutManager
)
mRecyclerView
.
getLayoutManager
()).
findFirstCompletelyVisibleItemPosition
();
sb
.
append
(
' '
)
.
append
(((
SeparatedAdapter
)
mRecyclerView
.
getAdapter
()).
getSectionforPosition
(
firstVisibleP
osition
))
.
append
(((
SeparatedAdapter
)
mRecyclerView
.
getAdapter
()).
getSectionforPosition
(
p
osition
))
.
append
(
' '
);
bubble
.
setText
(
sb
.
toString
());
return
;
}
if
(
mRecyclerviewTotalHeight
==
0
)
mRecyclerviewTotalHeight
=
mRecyclerView
.
computeVerticalScrollRange
()-
mRecyclerView
.
computeVerticalScrollExtent
();
if
(
FastScroller
.
this
.
getVisibility
()
==
INVISIBLE
)
mHandler
.
sendEmptyMessage
(
SHOW_SCROLLER
);
float
proportion
=
mRecyclerviewTotalHeight
==
0
?
0
f
:
rv
.
computeVerticalScrollOffset
()
/
(
float
)
mRecyclerviewTotalHeight
;
setPosition
(
mHeight
*
proportion
);
}
@Override
...
...
@@ -251,8 +240,28 @@ public class FastScroller extends LinearLayout {
}
}
public
interface
SeparatedAdapter
{
boolean
hasSections
();
String
getSectionforPosition
(
int
position
);
private
static
class
FastScrollerHandler
extends
WeakHandler
<
FastScroller
>
{
FastScrollerHandler
(
FastScroller
owner
)
{
super
(
owner
);
}
}
private
final
Handler
mHandler
=
new
FastScrollerHandler
(
this
)
{
@Override
public
void
handleMessage
(
Message
msg
)
{
switch
(
msg
.
what
)
{
case
HIDE_HANDLE:
hideBubble
();
break
;
case
HIDE_SCROLLER:
FastScroller
.
this
.
setVisibility
(
INVISIBLE
);
break
;
case
SHOW_SCROLLER:
FastScroller
.
this
.
setVisibility
(
VISIBLE
);
mHandler
.
removeMessages
(
HIDE_SCROLLER
);
mHandler
.
sendEmptyMessageDelayed
(
HIDE_SCROLLER
,
SCROLLER_HIDE_DELAY
);
break
;
}
}
};
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment