From 1da539ddf8c0f651dd9dd363641fd7641b5b13be Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 13 Feb 2018 04:41:00 +0100 Subject: #8831 add a progress animation to EipFragment and don't start blocking vpn when user triggered vpn start from UI --- .../main/java/se/leap/bitmaskclient/Constants.java | 1 + .../java/se/leap/bitmaskclient/EipFragment.java | 41 +++++++++------ .../main/java/se/leap/bitmaskclient/eip/EIP.java | 7 +-- .../se/leap/bitmaskclient/views/VpnStateImage.java | 61 ++++++++++++++++++++++ 4 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java (limited to 'app/src/main/java') diff --git a/app/src/main/java/se/leap/bitmaskclient/Constants.java b/app/src/main/java/se/leap/bitmaskclient/Constants.java index acfddf5d..f197c2ed 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Constants.java +++ b/app/src/main/java/se/leap/bitmaskclient/Constants.java @@ -45,6 +45,7 @@ public interface Constants { String EIP_REQUEST = "EIP.REQUEST"; String EIP_RESTART_ON_BOOT = "EIP.RESTART_ON_BOOT"; String EIP_IS_ALWAYS_ON = "EIP.EIP_IS_ALWAYS_ON"; + String EIP_TRIGGERED_FROM_UI = "EIP.TRIGGERED_FROM_UI"; ////////////////////////////////////////////// diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 844bfd7d..3c541e71 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -53,6 +53,7 @@ import de.blinkt.openvpn.core.VpnStatus; import se.leap.bitmaskclient.eip.EIP; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.VoidVpnService; +import se.leap.bitmaskclient.views.VpnStateImage; import static android.view.View.GONE; import static android.view.View.VISIBLE; @@ -66,6 +67,7 @@ import static se.leap.bitmaskclient.Constants.EIP_NOTIFICATION; import static se.leap.bitmaskclient.Constants.EIP_RECEIVER; import static se.leap.bitmaskclient.Constants.EIP_REQUEST; import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT; +import static se.leap.bitmaskclient.Constants.EIP_TRIGGERED_FROM_UI; import static se.leap.bitmaskclient.Constants.PROVIDER_ALLOWED_REGISTERED; import static se.leap.bitmaskclient.Constants.PROVIDER_ALLOW_ANONYMOUS; import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE; @@ -85,11 +87,8 @@ public class EipFragment extends Fragment implements Observer { @InjectView(R.id.background) AppCompatImageView background; - @InjectView(R.id.key) - AppCompatImageView key; - - @InjectView(R.id.cirle) - AppCompatImageView circle; + @InjectView(R.id.vpn_state_image) + VpnStateImage vpnStateImage; @InjectView(R.id.vpn_main_button) Button mainButton; @@ -186,13 +185,8 @@ public class EipFragment extends Fragment implements Observer { handleIcon(); } - @OnClick(R.id.key) - void onKeyClick() { - handleIcon(); - } - - @OnClick(R.id.cirle) - void onCircleClick() { + @OnClick(R.id.vpn_state_image) + void onVpnStateImageClick() { handleIcon(); } @@ -262,6 +256,10 @@ public class EipFragment extends Fragment implements Observer { wantsToConnect = false; saveStatus(true); eipCommand(EIP_ACTION_START); + vpnStateImage.showProgress(); + routedText.setVisibility(GONE); + vpnRoute.setVisibility(GONE); + colorBackgroundALittle(); } private void stop() { @@ -333,9 +331,13 @@ public class EipFragment extends Fragment implements Observer { */ private void eipCommand(String action) { Activity activity = getActivity(); + if (activity == null) { + return; + } // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? Intent vpn_intent = new Intent(activity.getApplicationContext(), EIP.class); vpn_intent.setAction(action); + vpn_intent.putExtra(EIP_TRIGGERED_FROM_UI, true); vpn_intent.putExtra(EIP_RECEIVER, eipReceiver); activity.startService(vpn_intent); } @@ -360,22 +362,29 @@ public class EipFragment extends Fragment implements Observer { private void handleNewState() { Activity activity = getActivity(); + if (activity == null) { + return; + } + if (eipStatus.isConnecting()) { mainButton.setText(activity.getString(android.R.string.cancel)); - key.setImageResource(R.drawable.vpn_connecting); + vpnStateImage.setStateIcon(R.drawable.vpn_connecting); + vpnStateImage.showProgress(); routedText.setVisibility(GONE); vpnRoute.setVisibility(GONE); colorBackgroundALittle(); } else if (eipStatus.isConnected() || isOpenVpnRunningWithoutNetwork()) { mainButton.setText(activity.getString(R.string.vpn_button_turn_off)); - key.setImageResource(R.drawable.vpn_connected); + vpnStateImage.setStateIcon(R.drawable.vpn_connected); + vpnStateImage.stopProgress(); routedText.setVisibility(VISIBLE); vpnRoute.setVisibility(VISIBLE); vpnRoute.setText(ConfigHelper.getProviderName(preferences)); colorBackground(); } else { mainButton.setText(activity.getString(R.string.vpn_button_turn_on)); - key.setImageResource(R.drawable.vpn_disconnected); + vpnStateImage.setStateIcon(R.drawable.vpn_disconnected); + vpnStateImage.stopProgress(); routedText.setVisibility(GONE); vpnRoute.setVisibility(GONE); greyscaleBackground(); @@ -482,7 +491,7 @@ public class EipFragment extends Fragment implements Observer { private void colorBackground() { background.setColorFilter(null); - background.setImageAlpha(255); + background.setImageAlpha(210); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index b8858c1e..894ad672 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -41,6 +41,7 @@ import static se.leap.bitmaskclient.Constants.EIP_ACTION_UPDATE; import static se.leap.bitmaskclient.Constants.EIP_RECEIVER; import static se.leap.bitmaskclient.Constants.EIP_REQUEST; import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT; +import static se.leap.bitmaskclient.Constants.EIP_TRIGGERED_FROM_UI; import static se.leap.bitmaskclient.Constants.PROVIDER_KEY; import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE; import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; @@ -93,7 +94,7 @@ public final class EIP extends IntentService { switch (action) { case EIP_ACTION_START: - startEIP(); + startEIP(!intent.hasExtra(EIP_TRIGGERED_FROM_UI)); break; case EIP_ACTION_START_ALWAYS_ON_VPN: startEIPAlwaysOnVpn(); @@ -118,13 +119,13 @@ public final class EIP extends IntentService { * Intent to {@link de.blinkt.openvpn.LaunchVPN}. * It also sets up early routes. */ - private void startEIP() { + private void startEIP(boolean earlyRoutes) { if (!preferences.getBoolean(EIP_RESTART_ON_BOOT, false)){ preferences.edit().putBoolean(EIP_RESTART_ON_BOOT, true).commit(); } if (gatewaysManager.isEmpty()) updateEIPService(); - if (!EipStatus.getInstance().isBlockingVpnEstablished()) { + if (!EipStatus.getInstance().isBlockingVpnEstablished() && earlyRoutes) { earlyRoutes(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java b/app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java new file mode 100644 index 00000000..46221ae8 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java @@ -0,0 +1,61 @@ +package se.leap.bitmaskclient.views; + +import android.content.Context; +import android.support.constraint.ConstraintLayout; +import android.support.v7.widget.AppCompatImageView; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ProgressBar; + +import se.leap.bitmaskclient.R; + +/** + * Created by cyberta on 12.02.18. + */ + + +public class VpnStateImage extends ConstraintLayout { + + ProgressBar progressBar; + AppCompatImageView stateIcon; + + public VpnStateImage(Context context) { + super(context); + initLayout(context); + } + + public VpnStateImage(Context context, AttributeSet attrs) { + super(context, attrs); + initLayout(context); + } + + public VpnStateImage(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initLayout(context); + } + + void initLayout(Context context) { + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View rootview = inflater.inflate(R.layout.v_main_button, this, true); + stateIcon = rootview.findViewById(R.id.vpn_state_key); + progressBar = rootview.findViewById(R.id.progressBar); + progressBar.setIndeterminate(true); + } + + public void showProgress() { + progressBar.setVisibility(VISIBLE); + } + + + public void stopProgress() { + progressBar.setVisibility(GONE); + } + + public void setStateIcon(int resource) { + stateIcon.setImageResource(resource); + } + + +} -- cgit v1.2.3 From 69d79a7002df96f2d69a83fd19c69b3bdb19c829 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 13 Feb 2018 16:48:33 +0100 Subject: #8831 add a fadeout animation for the progressbar --- .../java/se/leap/bitmaskclient/EipFragment.java | 4 ++-- .../se/leap/bitmaskclient/views/VpnStateImage.java | 26 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index a082b047..4bacfff8 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -416,7 +416,7 @@ public class EipFragment extends Fragment implements Observer { } else if (eipStatus.isConnected() || isOpenVpnRunningWithoutNetwork()) { mainButton.setText(activity.getString(R.string.vpn_button_turn_off)); vpnStateImage.setStateIcon(R.drawable.vpn_connected); - vpnStateImage.stopProgress(); + vpnStateImage.stopProgress(true); routedText.setVisibility(VISIBLE); vpnRoute.setVisibility(VISIBLE); vpnRoute.setText(ConfigHelper.getProviderName(preferences)); @@ -424,7 +424,7 @@ public class EipFragment extends Fragment implements Observer { } else { mainButton.setText(activity.getString(R.string.vpn_button_turn_on)); vpnStateImage.setStateIcon(R.drawable.vpn_disconnected); - vpnStateImage.stopProgress(); + vpnStateImage.stopProgress(false); routedText.setVisibility(GONE); vpnRoute.setVisibility(GONE); greyscaleBackground(); diff --git a/app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java b/app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java index 46221ae8..2efd83d6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java +++ b/app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java @@ -6,6 +6,8 @@ import android.support.v7.widget.AppCompatImageView; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; +import android.view.animation.AlphaAnimation; +import android.view.animation.Animation; import android.widget.ProgressBar; import se.leap.bitmaskclient.R; @@ -49,8 +51,28 @@ public class VpnStateImage extends ConstraintLayout { } - public void stopProgress() { - progressBar.setVisibility(GONE); + public void stopProgress(boolean animated) { + if (!animated) { + progressBar.setVisibility(GONE); + return; + } + + AlphaAnimation fadeOutAnimation = new AlphaAnimation(1.0f, 0.0f); + fadeOutAnimation.setDuration(1000); + fadeOutAnimation.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) {} + + @Override + public void onAnimationEnd(Animation animation) { + progressBar.setVisibility(GONE); + } + + @Override + public void onAnimationRepeat(Animation animation) {} + }); + + progressBar.startAnimation(fadeOutAnimation); } public void setStateIcon(int resource) { -- cgit v1.2.3 From 5564c4e5801529f846fa88e9258859f6aac4da1d Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 16 Feb 2018 12:45:37 +0100 Subject: #8852 code review changes --- app/src/main/java/se/leap/bitmaskclient/StartActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index ee1e2a69..39717bd8 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -164,7 +164,7 @@ public class StartActivity extends Activity { } else { Log.d(TAG, "vpn provider is configured"); if (getIntent() != null && getIntent().getBooleanExtra(EIP_RESTART_ON_BOOT, false)) { - EipCommand.startVPN(getApplicationContext(), true); + EipCommand.startVPN(this, true); finish(); return; } @@ -192,7 +192,7 @@ public class StartActivity extends Activity { if (resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) { Provider provider = data.getParcelableExtra(Provider.KEY); ConfigHelper.storeProviderInPreferences(preferences, provider); - EipCommand.startVPN(this.getApplicationContext(), false); + EipCommand.startVPN(this, false); showMainActivity(); } else if (resultCode == RESULT_CANCELED) { finish(); -- cgit v1.2.3