Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
e04350fc
Commit
e04350fc
authored
Jun 01, 2021
by
Mygod
Committed by
Mygod
Jun 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only show progress when connecting is taking too long
parent
eb827a45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
5 deletions
+23
-5
mobile/src/main/java/com/github/shadowsocks/widget/ServiceButton.kt
.../main/java/com/github/shadowsocks/widget/ServiceButton.kt
+23
-5
No files found.
mobile/src/main/java/com/github/shadowsocks/widget/ServiceButton.kt
View file @
e04350fc
...
...
@@ -29,6 +29,8 @@ import android.view.View
import
androidx.annotation.DrawableRes
import
androidx.appcompat.widget.TooltipCompat
import
androidx.dynamicanimation.animation.DynamicAnimation
import
androidx.lifecycle.LifecycleOwner
import
androidx.lifecycle.lifecycleScope
import
androidx.vectordrawable.graphics.drawable.Animatable2Compat
import
androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
import
com.github.shadowsocks.R
...
...
@@ -36,6 +38,8 @@ import com.github.shadowsocks.bg.BaseService
import
com.google.android.material.floatingactionbutton.FloatingActionButton
import
com.google.android.material.progressindicator.BaseProgressIndicator
import
com.google.android.material.progressindicator.DeterminateDrawable
import
kotlinx.coroutines.Job
import
kotlinx.coroutines.delay
import
java.util.*
class
ServiceButton
@JvmOverloads
constructor
(
context
:
Context
,
attrs
:
AttributeSet
?
=
null
,
defStyleAttr
:
Int
=
0
)
:
...
...
@@ -59,7 +63,7 @@ class ServiceButton @JvmOverloads constructor(context: Context, attrs: Attribute
}
private
inner
class
AnimatedState
(
@DrawableRes
resId
:
Int
,
private
val
onStart
:
BaseProgressIndicator
<
*
>.()
->
Unit
=
{
hide
()
})
{
private
val
onStart
:
BaseProgressIndicator
<
*
>.()
->
Unit
=
{
hide
Progress
()
})
{
val
icon
:
AnimatedVectorDrawableCompat
=
AnimatedVectorDrawableCompat
.
create
(
context
,
resId
)
!!
.
apply
{
registerAnimationCallback
(
this
@ServiceButton
.
callback
)
}
...
...
@@ -74,16 +78,25 @@ class ServiceButton @JvmOverloads constructor(context: Context, attrs: Attribute
private
val
iconStopped
by
lazy
{
AnimatedState
(
R
.
drawable
.
ic_service_stopped
)
}
private
val
iconConnecting
by
lazy
{
AnimatedState
(
R
.
drawable
.
ic_service_connecting
)
{
hide
()
isIndeterminate
=
true
show
()
hideProgress
()
delayedAnimation
=
(
context
as
LifecycleOwner
).
lifecycleScope
.
launchWhenStarted
{
delay
(
context
.
resources
.
getInteger
(
android
.
R
.
integer
.
config_mediumAnimTime
)
+
1000L
)
isIndeterminate
=
true
show
()
}
}
}
private
val
iconConnected
by
lazy
{
AnimatedState
(
R
.
drawable
.
ic_service_connected
)
{
delayedAnimation
?.
cancel
()
setProgressCompat
(
1
,
true
)
}
}
private
val
iconConnected
by
lazy
{
AnimatedState
(
R
.
drawable
.
ic_service_connected
)
{
setProgressCompat
(
1
,
true
)
}
}
private
val
iconStopping
by
lazy
{
AnimatedState
(
R
.
drawable
.
ic_service_stopping
)
}
private
val
animationQueue
=
ArrayDeque
<
AnimatedState
>()
private
var
checked
=
false
private
var
delayedAnimation
:
Job
?
=
null
private
lateinit
var
progress
:
BaseProgressIndicator
<
*
>
fun
initProgress
(
progress
:
BaseProgressIndicator
<
*
>)
{
this
.
progress
=
progress
...
...
@@ -94,6 +107,11 @@ class ServiceButton @JvmOverloads constructor(context: Context, attrs: Attribute
if
(!
canceled
)
progress
.
hide
()
}
private
fun
hideProgress
()
{
delayedAnimation
?.
cancel
()
progress
.
hide
()
}
override
fun
onCreateDrawableState
(
extraSpace
:
Int
):
IntArray
{
val
drawableState
=
super
.
onCreateDrawableState
(
extraSpace
+
1
)
if
(
checked
)
View
.
mergeDrawableStates
(
drawableState
,
intArrayOf
(
android
.
R
.
attr
.
state_checked
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment