From 33bae6bada5aadc3ab3919fa04233d2d916e5721 Mon Sep 17 00:00:00 2001 From: cyberta Date: Fri, 2 Dec 2022 02:18:48 +0100 Subject: implement connecting animation for riseup --- app/src/custom/res/animator/alpha1.xml | 11 +++++ app/src/custom/res/animator/alpha2.xml | 16 ++++--- app/src/custom/res/animator/alpha3.xml | 11 ++++- app/src/custom/res/drawable/ravens.xml | 6 +++ app/src/custom/res/drawable/state_connecting.xml | 17 +++++-- .../bitmaskclient/base/fragments/EipFragment.java | 54 ++++++++++++++-------- 6 files changed, 85 insertions(+), 30 deletions(-) create mode 100644 app/src/custom/res/animator/alpha1.xml diff --git a/app/src/custom/res/animator/alpha1.xml b/app/src/custom/res/animator/alpha1.xml new file mode 100644 index 00000000..94192a0b --- /dev/null +++ b/app/src/custom/res/animator/alpha1.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/app/src/custom/res/animator/alpha2.xml b/app/src/custom/res/animator/alpha2.xml index bf997dea..b66ef59c 100644 --- a/app/src/custom/res/animator/alpha2.xml +++ b/app/src/custom/res/animator/alpha2.xml @@ -1,10 +1,12 @@ - \ No newline at end of file + android:duration="1000" + android:propertyName="fillColor" + android:valueFrom="#00000000" + android:valueTo="#000000" + android:startOffset="1000" + android:valueType="colorType" + /> + + diff --git a/app/src/custom/res/animator/alpha3.xml b/app/src/custom/res/animator/alpha3.xml index d05f36c2..2a1e0ba4 100644 --- a/app/src/custom/res/animator/alpha3.xml +++ b/app/src/custom/res/animator/alpha3.xml @@ -1,4 +1,11 @@ - - \ No newline at end of file + + diff --git a/app/src/custom/res/drawable/ravens.xml b/app/src/custom/res/drawable/ravens.xml index f97a3532..788aef84 100644 --- a/app/src/custom/res/drawable/ravens.xml +++ b/app/src/custom/res/drawable/ravens.xml @@ -4,29 +4,35 @@ android:width="342dp" android:height="206dp"> diff --git a/app/src/custom/res/drawable/state_connecting.xml b/app/src/custom/res/drawable/state_connecting.xml index 3ef89983..267ba791 100644 --- a/app/src/custom/res/drawable/state_connecting.xml +++ b/app/src/custom/res/drawable/state_connecting.xml @@ -1,4 +1,15 @@ - - - \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index 0210077c..81a9f9eb 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -41,6 +41,7 @@ import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.content.SharedPreferences; +import android.graphics.drawable.Animatable; import android.os.Bundle; import android.os.IBinder; import android.text.Spannable; @@ -53,11 +54,11 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.ColorRes; +import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatTextView; -import androidx.core.content.ContextCompat; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; @@ -468,8 +469,8 @@ public class EipFragment extends Fragment implements Observer { } else { subDescription.setText(getString(R.string.updating_certificate_message)); } - background.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.bg_connecting)); - stateView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.yellow_mask)); + background.setImageResource(R.drawable.bg_connecting); + animateState(R.drawable.state_connecting); mainButton.updateState(false, true, false); setActivityBarColor(R.color.bg_connecting_top, R.color.bg_connecting_top_light_transparent); } else if (eipStatus.isConnecting()) { @@ -484,8 +485,8 @@ public class EipFragment extends Fragment implements Observer { locationButton.showRecommendedIndicator(false); mainDescription.setText(R.string.eip_status_connecting); subDescription.setText(null); - background.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.bg_connecting)); - stateView.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.yellow_mask)); + background.setImageResource(R.drawable.bg_connecting); + animateState(R.drawable.state_connecting); mainButton.updateState(false, true, false); setActivityBarColor(R.color.bg_connecting_top, R.color.bg_connecting_top_light_transparent); } else if (eipStatus.isConnected()) { @@ -498,8 +499,8 @@ public class EipFragment extends Fragment implements Observer { locationButton.showRecommendedIndicator(getPreferredCity(getContext()) == null); mainDescription.setText(R.string.eip_status_secured); subDescription.setText(null); - background.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.bg_connected)); - stateView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.green_mask)); + background.setImageResource(R.drawable.bg_connected); + animateState(R.drawable.state_connected); setActivityBarColor(R.color.bg_running_top, R.color.bg_running_top_light_transparent); } else if(isOpenVpnRunningWithoutNetwork()) { Log.d(TAG, "eip fragment eipStatus - isOpenVpnRunningWithoutNetwork"); @@ -511,8 +512,8 @@ public class EipFragment extends Fragment implements Observer { locationButton.showRecommendedIndicator(getPreferredCity(getContext())== null); mainDescription.setText(R.string.eip_state_connected); subDescription.setText(R.string.eip_state_no_network); - background.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.bg_connecting)); - stateView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.yellow_mask)); + background.setImageResource(R.drawable.bg_connecting); + animateState(R.drawable.state_connecting); setActivityBarColor(R.color.bg_connecting_top, R.color.bg_connecting_top_light_transparent); } else if (eipStatus.isDisconnected() && reconnectingWithDifferentGateway()) { locationButton.setText(VpnStatus.getCurrentlyConnectingVpnName()); @@ -521,16 +522,15 @@ public class EipFragment extends Fragment implements Observer { locationButton.showRecommendedIndicator(false); mainDescription.setText(R.string.eip_status_connecting); subDescription.setText(R.string.reconnecting); - background.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.bg_connecting)); - stateView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.yellow_mask)); + background.setImageResource(R.drawable.bg_connecting); + animateState(R.drawable.state_connecting); setActivityBarColor(R.color.bg_connecting_top, R.color.bg_connecting_top_light_transparent); - } else if (eipStatus.isDisconnecting()) { setMainButtonEnabled(false); - background.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.bg_disconnected)); - stateView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.red_mask)); mainButton.updateState(false, false, false); mainDescription.setText(R.string.eip_status_unsecured); + background.setImageResource(R.drawable.bg_disconnected); + animateState(R.drawable.state_disconnected); setActivityBarColor(R.color.bg_disconnected_top, R.color.bg_disconnected_top_light_transparent); } else if (eipStatus.isBlocking()) { setMainButtonEnabled(true); @@ -541,8 +541,8 @@ public class EipFragment extends Fragment implements Observer { locationButton.showRecommendedIndicator(false); mainDescription.setText(R.string.eip_state_connected); subDescription.setText(getString(R.string.eip_state_blocking, getString(R.string.app_name))); - background.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.bg_disconnected)); - stateView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.red_mask)); + background.setImageResource(R.drawable.bg_disconnected); + animateState(R.drawable.state_disconnected); setActivityBarColor(R.color.bg_disconnected_top, R.color.bg_disconnected_top_light_transparent); } else { locationButton.setText(getContext().getString(R.string.vpn_button_turn_on)); @@ -555,12 +555,30 @@ public class EipFragment extends Fragment implements Observer { locationButton.showRecommendedIndicator(false); mainDescription.setText(R.string.eip_status_unsecured); subDescription.setText(null); - background.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.bg_disconnected)); - stateView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.red_mask)); + background.setImageResource(R.drawable.bg_disconnected); + animateState(R.drawable.state_disconnected); setActivityBarColor(R.color.bg_disconnected_top, R.color.bg_disconnected_top_light_transparent); } } + private void animateState(@DrawableRes int drawableRes) { + try { + int lastDrawableId = (int) stateView.getTag(); + if (lastDrawableId == drawableRes) { + return; + } + } catch (NullPointerException | ClassCastException e) { + // eat me + } + + stateView.setImageResource(drawableRes); + stateView.setTag(drawableRes); + if (stateView.getDrawable() instanceof Animatable) { + Animatable animatedDrawable = (Animatable) stateView.getDrawable(); + animatedDrawable.start(); + } + } + private boolean isOpenVpnRunningWithoutNetwork() { boolean isRunning = false; try { -- cgit v1.2.3