summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-11-15 17:10:46 +0100
committercyBerta <cyberta@riseup.net>2021-11-15 17:10:46 +0100
commitd5faac5ac7937c5a7f19c9a409e2a1376afc50aa (patch)
treeb2d0e14524c8106736b0fbd76c72f8637a072786 /app/src/main/java
parentf3e23d06d8bee4c4212e606621b92a50dd7034ae (diff)
parent427a41a35205b1948da37727eb21b66e2c518b0c (diff)
Merge branch 'main_btn' into simply_secure_UI_changes
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java32
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java124
2 files changed, 136 insertions, 20 deletions
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 d8be1cc5..18e97411 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
@@ -27,6 +27,7 @@ import android.graphics.ColorMatrixColorFilter;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Vibrator;
+import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
@@ -37,6 +38,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.fragment.app.DialogFragment;
@@ -61,7 +63,7 @@ import se.leap.bitmaskclient.base.MainActivity;
import se.leap.bitmaskclient.base.models.Provider;
import se.leap.bitmaskclient.base.models.ProviderObservable;
import se.leap.bitmaskclient.base.views.LocationButton;
-import se.leap.bitmaskclient.base.views.VpnStateImage;
+import se.leap.bitmaskclient.base.views.MainButton;
import se.leap.bitmaskclient.eip.EipCommand;
import se.leap.bitmaskclient.eip.EipStatus;
import se.leap.bitmaskclient.eip.GatewaysManager;
@@ -105,8 +107,8 @@ public class EipFragment extends Fragment implements Observer {
@BindView(R.id.background)
AppCompatImageView background;
- @BindView(R.id.vpn_state_image)
- VpnStateImage vpnStateImage;
+ @BindView(R.id.main_button)
+ MainButton mainButton;
@BindView(R.id.gateway_location_button)
LocationButton locationButton;
@@ -267,16 +269,11 @@ public class EipFragment extends Fragment implements Observer {
preferences.edit().putBoolean(EIP_RESTART_ON_BOOT, restartOnBoot).apply();
}
- @OnClick(R.id.gateway_location_button)
+ @OnClick(R.id.main_button)
void onButtonClick() {
handleIcon();
}
- @OnClick(R.id.vpn_state_image)
- void onVpnStateImageClick() {
- handleIcon();
- }
-
void handleIcon() {
if (isOpenVpnRunningWithoutNetwork() || eipStatus.isConnected() || eipStatus.isConnecting())
handleSwitchOff();
@@ -323,7 +320,7 @@ public class EipFragment extends Fragment implements Observer {
private void setMainButtonEnabled(boolean enabled) {
locationButton.setEnabled(enabled);
- vpnStateImage.setEnabled(enabled);
+ mainButton.setEnabled(enabled);
}
public void startEipFromScratch() {
@@ -431,8 +428,7 @@ public class EipFragment extends Fragment implements Observer {
locationButton.setLocationLoad(UNKNOWN);
} else if (eipStatus.isConnected()) {
setMainButtonEnabled(true);
- vpnStateImage.setStateIcon(R.drawable.ic_btn_on_primary_color);
- vpnStateImage.stopProgress(false);
+ mainButton.updateState(true, false, false);
locationButton.setLocationLoad(gatewaysManager.getLoadForLocation(VpnStatus.getLastConnectedVpnName()));
locationButton.setText(VpnStatus.getLastConnectedVpnName());
locationButton.setVisibility(VISIBLE);
@@ -444,8 +440,7 @@ public class EipFragment extends Fragment implements Observer {
} else if(isOpenVpnRunningWithoutNetwork()){
Log.d(TAG, "eip fragment eipStatus - isOpenVpnRunningWithoutNetwork");
setMainButtonEnabled(true);
- vpnStateImage.setStateIcon(R.drawable.ic_btn_on_primary_color);
- vpnStateImage.stopProgress(false);
+ mainButton.updateState(true, false, true);
locationButton.setVisibility(VISIBLE);
locationButton.setText(VpnStatus.getCurrentlyConnectingVpnName());
colorBackgroundALittle();
@@ -466,8 +461,7 @@ public class EipFragment extends Fragment implements Observer {
subDescription.setText(R.string.connection_not_connected);
} else if (eipStatus.isBlocking()) {
setMainButtonEnabled(true);
- vpnStateImage.setStateIcon(R.drawable.ic_btn_on_primary_color);
- vpnStateImage.stopProgress(false);
+ mainButton.updateState(true, false, true);
colorBackgroundALittle();
locationButton.setText(getString(R.string.finding_best_connection));
locationButton.setVisibility(VISIBLE);
@@ -477,8 +471,7 @@ public class EipFragment extends Fragment implements Observer {
} else {
locationButton.setText(activity.getString(R.string.vpn_button_turn_on));
setMainButtonEnabled(true);
- vpnStateImage.setStateIcon(R.drawable.ic_btn_on_disabled);
- vpnStateImage.stopProgress(false);
+ mainButton.updateState(false, false, false);
greyscaleBackground();
locationButton.setLocationLoad(UNKNOWN);
locationButton.setVisibility(INVISIBLE);
@@ -517,8 +510,7 @@ public class EipFragment extends Fragment implements Observer {
}
private void showConnectionTransitionLayout(boolean isConnecting) {
- vpnStateImage.setStateIcon(R.drawable.ic_btn_on_connecting);
- vpnStateImage.showProgress();
+ mainButton.updateState(true, true, false);
if (isConnecting) {
colorBackgroundALittle();
} else {
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java b/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java
new file mode 100644
index 00000000..c5ac4544
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java
@@ -0,0 +1,124 @@
+package se.leap.bitmaskclient.base.views;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.graphics.PorterDuff;
+import android.graphics.drawable.AnimationDrawable;
+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.RelativeLayout;
+
+import androidx.annotation.ColorRes;
+import androidx.annotation.DrawableRes;
+import androidx.appcompat.widget.AppCompatImageView;
+import androidx.core.content.ContextCompat;
+
+import se.leap.bitmaskclient.R;
+
+public class MainButton extends RelativeLayout {
+
+ private static final String TAG = MainButton.class.getSimpleName();
+
+ AppCompatImageView glow;
+ AppCompatImageView shadowLight;
+ AnimationDrawable glowAnimation;
+
+ private boolean isOn = false;
+ private boolean isProcessing = false;
+ private boolean isError = true;
+
+
+ public MainButton(Context context) {
+ super(context);
+ initLayout(context);
+ }
+
+ public MainButton(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ initLayout(context);
+ }
+
+ public MainButton(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ initLayout(context);
+ }
+
+
+ @TargetApi(21)
+ public MainButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ initLayout(context);
+ }
+
+ private void initLayout(Context context) {
+ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ View rootview = inflater.inflate(R.layout.v_main_btn, this, true);
+
+ glow = rootview.findViewById(R.id.vpn_btn_glow);
+ glowAnimation = (AnimationDrawable) glow.getBackground();
+ shadowLight = rootview.findViewById(R.id.vpn_btn_shadow_light);
+ }
+
+
+ private void stopGlowAnimation() {
+ AlphaAnimation fadeOutAnimation = new AlphaAnimation(1.0f, 0.0f);
+ fadeOutAnimation.setDuration(300);
+ fadeOutAnimation.setAnimationListener(new Animation.AnimationListener() {
+ @Override
+ public void onAnimationStart(Animation animation) {}
+
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ glow.setVisibility(GONE);
+ glowAnimation.stop();
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation animation) {}
+ });
+ glow.startAnimation(fadeOutAnimation);
+ }
+
+ private void startGlowAnimation() {
+ glow.setAlpha(1.0f);
+ glow.setVisibility(VISIBLE);
+ glowAnimation.start();
+ }
+
+ public void updateState(boolean isOn, boolean isProcessing, boolean isError) {
+ if (this.isOn != isOn) {
+ this.isOn = isOn;
+ shadowLight.setVisibility(isOn ? VISIBLE : GONE);
+ }
+
+ if (this.isProcessing != isProcessing) {
+ if (!isProcessing) {
+ stopGlowAnimation();
+ } else {
+ startGlowAnimation();
+ }
+ this.isProcessing = isProcessing;
+ }
+
+ if (this.isError != isError) {
+ @DrawableRes int drawableResource = isOn ? R.drawable.on_off_btn_start_2_enabled : R.drawable.on_off_btn_start_2_disabled;
+ if (!isError) {
+ setImageWithTint(shadowLight, drawableResource, R.color.colorMainBtnHighlight);
+ } else {
+ setImageWithTint(shadowLight, drawableResource, R.color.colorMainBtnError);
+ }
+ this.isError = isError;
+ }
+ }
+
+ private void setImageWithTint(AppCompatImageView view, @DrawableRes int resourceId, @ColorRes int color) {
+ view.setImageDrawable(ContextCompat.getDrawable(getContext(), resourceId));
+ view.setColorFilter(ContextCompat.getColor(getContext(), color), PorterDuff.Mode.SRC_ATOP);
+ }
+
+
+
+}