Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Anti-censorship
Pluggable Transports
Snowflake Mobile
Commits
73bf1dfb
Verified
Commit
73bf1dfb
authored
Aug 06, 2020
by
HashikD
Browse files
Animated logo color change
parent
23b98aa4
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/org/torproject/snowflake/fragments/MainFragment.java
View file @
73bf1dfb
package
org.torproject.snowflake.fragments
;
import
android.animation.ArgbEvaluator
;
import
android.animation.ValueAnimator
;
import
android.content.Context
;
import
android.graphics.PorterDuff
;
import
android.os.Bundle
;
...
...
@@ -28,6 +30,7 @@ public class MainFragment extends Fragment {
private
static
final
String
TAG
=
"MainFragment"
;
MainFragmentCallback
callback
;
TextView
usersServedTV
;
ImageView
snowflakeLogo
;
public
MainFragment
()
{
// Required empty public constructor
...
...
@@ -56,15 +59,15 @@ public class MainFragment extends Fragment {
View
rootView
=
inflater
.
inflate
(
R
.
layout
.
fragment_main
,
container
,
false
);
usersServedTV
=
rootView
.
findViewById
(
R
.
id
.
users_served
);
Switch
startButton
=
rootView
.
findViewById
(
R
.
id
.
snowflake_switch
);
ImageView
snowflakeLogo
=
rootView
.
findViewById
(
R
.
id
.
snowflake_logo
);
snowflakeLogo
=
rootView
.
findViewById
(
R
.
id
.
snowflake_logo
);
startButton
.
setOnCheckedChangeListener
((
buttonView
,
isChecked
)
->
{
if
(
callback
.
isServiceRunning
()
&&
!
isChecked
)
{
//Toggling the service.
snowflak
eLogo
.
set
Color
Filter
(
ContextCompat
.
getColor
(
getActivity
(),
R
.
color
.
snowflakeOff
)
);
chang
eLogoColor
Status
(
false
);
startButton
.
setText
(
getString
(
R
.
string
.
Snowflake_Off
));
callback
.
serviceToggle
(
ForegroundServiceConstants
.
ACTION_STOP
);
}
else
{
snowflak
eLogo
.
set
Color
Filter
(
ContextCompat
.
getColor
(
getActivity
(),
R
.
color
.
snowflakeOn
)
);
chang
eLogoColor
Status
(
true
);
startButton
.
setText
(
getString
(
R
.
string
.
Snowflake_On
));
callback
.
serviceToggle
(
ForegroundServiceConstants
.
ACTION_START
);
}
...
...
@@ -90,4 +93,20 @@ public class MainFragment extends Fragment {
usersServedTV
.
setText
(
servedText
);
}
}
private
void
changeLogoColorStatus
(
boolean
status
)
{
int
from
,
to
;
if
(
status
)
{
//Status on
from
=
this
.
getResources
().
getColor
(
R
.
color
.
snowflakeOff
);
to
=
this
.
getResources
().
getColor
(
R
.
color
.
snowflakeOn
);
}
else
{
//off
from
=
this
.
getResources
().
getColor
(
R
.
color
.
snowflakeOn
);
to
=
this
.
getResources
().
getColor
(
R
.
color
.
snowflakeOff
);
}
ValueAnimator
colorAnimation
=
ValueAnimator
.
ofObject
(
new
ArgbEvaluator
(),
from
,
to
);
colorAnimation
.
setDuration
(
300
);
// milliseconds
colorAnimation
.
addUpdateListener
(
animator
->
snowflakeLogo
.
setColorFilter
((
int
)
animator
.
getAnimatedValue
(),
PorterDuff
.
Mode
.
SRC_IN
));
colorAnimation
.
start
();
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
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