From 1e9202c3d929083220924f7c76ea01a2b6f6af9f Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 22 Jul 2021 15:31:08 +0200 Subject: first implementation of the gateway button, started to remove labels from EipFragment, implement method to get the avearage load of a location as an enum value --- .../bitmaskclient/base/views/LocationButton.java | 44 +++++++++++++ .../base/views/LocationIndicator.java | 76 ++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java new file mode 100644 index 00000000..1d7f0d18 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java @@ -0,0 +1,44 @@ +package se.leap.bitmaskclient.base.views; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatTextView; +import androidx.appcompat.widget.LinearLayoutCompat; + +import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.eip.GatewaysManager; + +public class LocationButton extends LinearLayoutCompat { + private LocationIndicator locationIndicator; + private AppCompatTextView textView; + public LocationButton(@NonNull Context context) { + super(context); + initLayout(context); + } + + public LocationButton(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + initLayout(context); + } + + private void initLayout(Context context) { + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View rootview = inflater.inflate(R.layout.v_location_button, this, true); + locationIndicator = rootview.findViewById(R.id.load_indicator); + textView = rootview.findViewById(R.id.text_location); + } + + public void setLocationLoad(GatewaysManager.Load load) { + locationIndicator.setLoad(load); + } + + public void setText(CharSequence text) { + textView.setText(text); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java new file mode 100644 index 00000000..f5e3dbe2 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java @@ -0,0 +1,76 @@ +package se.leap.bitmaskclient.base.views; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.LinearLayout; + +import androidx.annotation.Nullable; + +import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.eip.GatewaysManager; + +public class LocationIndicator extends LinearLayout { + + private View level1; + private View level2; + private View level3; + + public LocationIndicator(Context context) { + super(context); + initLayout(context); + } + + public LocationIndicator(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + initLayout(context); + + } + + public LocationIndicator(Context context, @Nullable 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_location_status_indicator, this, true); + level1 = rootview.findViewById(R.id.level1); + level2 = rootview.findViewById(R.id.level2); + level3 = rootview.findViewById(R.id.level3); + } + + public void setLoad(GatewaysManager.Load load) { + switch (load) { + case GOOD: + level1.setBackgroundColor(getResources().getColor(R.color.green200)); + level2.setBackgroundColor(getResources().getColor(R.color.green200)); + level3.setBackgroundColor(getResources().getColor(R.color.green200)); + level1.setVisibility(VISIBLE); + level2.setVisibility(VISIBLE); + level3.setVisibility(VISIBLE); + break; + case AVERAGE: + level1.setBackgroundColor(getResources().getColor(R.color.yellow200)); + level2.setBackgroundColor(getResources().getColor(R.color.yellow200)); + level1.setVisibility(VISIBLE); + level2.setVisibility(VISIBLE); + level3.setVisibility(INVISIBLE); + break; + case CRITICAL: + level1.setBackgroundColor(getResources().getColor(R.color.red200)); + level1.setVisibility(VISIBLE); + level2.setVisibility(INVISIBLE); + level3.setVisibility(INVISIBLE); + break; + default: + level1.setVisibility(INVISIBLE); + level2.setVisibility(INVISIBLE); + level3.setVisibility(INVISIBLE); + break; + } + } +} -- cgit v1.2.3 From 580c97e368cd0d9fa47691f70cc31e9b711581ec Mon Sep 17 00:00:00 2001 From: cyBerta Date: Mon, 15 Nov 2021 14:09:17 +0100 Subject: implement a new fancy on-off-button --- .../leap/bitmaskclient/base/views/MainButton.java | 189 +++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') 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..586eb321 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java @@ -0,0 +1,189 @@ +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.graphics.drawable.Drawable; +import android.util.AttributeSet; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.MotionEvent; +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 androidx.core.graphics.drawable.DrawableCompat; + +import java.lang.ref.WeakReference; + +import se.leap.bitmaskclient.R; + +public class MainButton extends RelativeLayout { + + private static final String TAG = MainButton.class.getSimpleName(); + + interface MainButtonListener { + void onButtonClicked(); + } + + AppCompatImageView glow; + AppCompatImageView shadowDark; + AppCompatImageView shadowLight; + AnimationDrawable glowAnimation; + WeakReference callback; + + 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); + } + + public void setMainButtonListener(MainButtonListener callback) { + this.callback = new WeakReference<>(callback); + } + + 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(); + shadowDark = rootview.findViewById(R.id.vpn_btn_shadow_dark); + shadowLight = rootview.findViewById(R.id.vpn_btn_shadow_light); + + rootview.setOnGenericMotionListener(new OnGenericMotionListener() { + @Override + public boolean onGenericMotion(View v, MotionEvent event) { + switch (event.getAction()) { + case MotionEvent.ACTION_BUTTON_PRESS: + Log.d(TAG, "onbuttonPrees"); + break; + case MotionEvent.ACTION_BUTTON_RELEASE: + Log.d(TAG, "onButtonRelease"); + break; + } + return false; + } + }); + rootview.setOnTouchListener(new OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + Log.d(TAG, "motion down"); + Drawable drawableDown = context.getResources().getDrawable(R.drawable.on_off_btn_start_2_pressed); + shadowDark.setImageDrawable(drawableDown); + break; + case MotionEvent.ACTION_UP: + Log.d(TAG, "motion up"); + Drawable drawableUp = isOn ? + context.getResources().getDrawable(R.drawable.on_off_btn_start_2_disabled) : + context.getResources().getDrawable(R.drawable.on_off_btn_start_2_enabled); + shadowDark.setImageDrawable(drawableUp); + break; + case MotionEvent.ACTION_CANCEL: + Log.d(TAG, "motion cancelled"); + Drawable drawableRestoreState = isOn ? + context.getResources().getDrawable(R.drawable.on_off_btn_start_2_enabled) : + context.getResources().getDrawable(R.drawable.on_off_btn_start_2_disabled); + shadowDark.setImageDrawable(drawableRestoreState); + break; + } + return false; + } + }); + + } + + + 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; + Drawable drawableRestoreState = isOn ? + getContext().getResources().getDrawable(R.drawable.on_off_btn_start_2_enabled) : + getContext().getResources().getDrawable(R.drawable.on_off_btn_start_2_disabled); + shadowDark.setImageDrawable(drawableRestoreState); + 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.colorSecondary); + } else { + setImageWithTint(shadowLight, drawableResource, R.color.colorWarning); + } + 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); + } + + + +} -- cgit v1.2.3 From 78b06a47b6c7e3de5706893eeebb01bef89060d8 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Mon, 15 Nov 2021 14:23:23 +0100 Subject: only use two button pressed states --- .../leap/bitmaskclient/base/views/MainButton.java | 36 ---------------------- 1 file changed, 36 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') 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 index 586eb321..1a8fa09b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java @@ -4,7 +4,6 @@ import android.annotation.TargetApi; import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.AnimationDrawable; -import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; @@ -18,7 +17,6 @@ import androidx.annotation.ColorRes; import androidx.annotation.DrawableRes; import androidx.appcompat.widget.AppCompatImageView; import androidx.core.content.ContextCompat; -import androidx.core.graphics.drawable.DrawableCompat; import java.lang.ref.WeakReference; @@ -33,7 +31,6 @@ public class MainButton extends RelativeLayout { } AppCompatImageView glow; - AppCompatImageView shadowDark; AppCompatImageView shadowLight; AnimationDrawable glowAnimation; WeakReference callback; @@ -76,7 +73,6 @@ public class MainButton extends RelativeLayout { glow = rootview.findViewById(R.id.vpn_btn_glow); glowAnimation = (AnimationDrawable) glow.getBackground(); - shadowDark = rootview.findViewById(R.id.vpn_btn_shadow_dark); shadowLight = rootview.findViewById(R.id.vpn_btn_shadow_light); rootview.setOnGenericMotionListener(new OnGenericMotionListener() { @@ -93,34 +89,6 @@ public class MainButton extends RelativeLayout { return false; } }); - rootview.setOnTouchListener(new OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - Log.d(TAG, "motion down"); - Drawable drawableDown = context.getResources().getDrawable(R.drawable.on_off_btn_start_2_pressed); - shadowDark.setImageDrawable(drawableDown); - break; - case MotionEvent.ACTION_UP: - Log.d(TAG, "motion up"); - Drawable drawableUp = isOn ? - context.getResources().getDrawable(R.drawable.on_off_btn_start_2_disabled) : - context.getResources().getDrawable(R.drawable.on_off_btn_start_2_enabled); - shadowDark.setImageDrawable(drawableUp); - break; - case MotionEvent.ACTION_CANCEL: - Log.d(TAG, "motion cancelled"); - Drawable drawableRestoreState = isOn ? - context.getResources().getDrawable(R.drawable.on_off_btn_start_2_enabled) : - context.getResources().getDrawable(R.drawable.on_off_btn_start_2_disabled); - shadowDark.setImageDrawable(drawableRestoreState); - break; - } - return false; - } - }); - } @@ -152,10 +120,6 @@ public class MainButton extends RelativeLayout { public void updateState(boolean isOn, boolean isProcessing, boolean isError) { if (this.isOn != isOn) { this.isOn = isOn; - Drawable drawableRestoreState = isOn ? - getContext().getResources().getDrawable(R.drawable.on_off_btn_start_2_enabled) : - getContext().getResources().getDrawable(R.drawable.on_off_btn_start_2_disabled); - shadowDark.setImageDrawable(drawableRestoreState); shadowLight.setVisibility(isOn ? VISIBLE : GONE); } -- cgit v1.2.3 From 79c01db669fc68b1071f0c2e62eae1e4be66bbb8 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Mon, 15 Nov 2021 16:00:50 +0100 Subject: remove unused code --- .../leap/bitmaskclient/base/views/MainButton.java | 29 ---------------------- 1 file changed, 29 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') 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 index 1a8fa09b..b12f2b00 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java @@ -5,9 +5,7 @@ import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.AnimationDrawable; import android.util.AttributeSet; -import android.util.Log; import android.view.LayoutInflater; -import android.view.MotionEvent; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; @@ -18,29 +16,21 @@ import androidx.annotation.DrawableRes; import androidx.appcompat.widget.AppCompatImageView; import androidx.core.content.ContextCompat; -import java.lang.ref.WeakReference; - import se.leap.bitmaskclient.R; public class MainButton extends RelativeLayout { private static final String TAG = MainButton.class.getSimpleName(); - interface MainButtonListener { - void onButtonClicked(); - } - AppCompatImageView glow; AppCompatImageView shadowLight; AnimationDrawable glowAnimation; - WeakReference callback; private boolean isOn = false; private boolean isProcessing = false; private boolean isError = true; - public MainButton(Context context) { super(context); initLayout(context); @@ -63,10 +53,6 @@ public class MainButton extends RelativeLayout { initLayout(context); } - public void setMainButtonListener(MainButtonListener callback) { - this.callback = new WeakReference<>(callback); - } - 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); @@ -74,21 +60,6 @@ public class MainButton extends RelativeLayout { glow = rootview.findViewById(R.id.vpn_btn_glow); glowAnimation = (AnimationDrawable) glow.getBackground(); shadowLight = rootview.findViewById(R.id.vpn_btn_shadow_light); - - rootview.setOnGenericMotionListener(new OnGenericMotionListener() { - @Override - public boolean onGenericMotion(View v, MotionEvent event) { - switch (event.getAction()) { - case MotionEvent.ACTION_BUTTON_PRESS: - Log.d(TAG, "onbuttonPrees"); - break; - case MotionEvent.ACTION_BUTTON_RELEASE: - Log.d(TAG, "onButtonRelease"); - break; - } - return false; - } - }); } -- cgit v1.2.3 From 427a41a35205b1948da37727eb21b66e2c518b0c Mon Sep 17 00:00:00 2001 From: cyBerta Date: Mon, 15 Nov 2021 16:02:09 +0100 Subject: tweak an rename main button higlight colores --- app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') 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 index b12f2b00..c5ac4544 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java @@ -106,9 +106,9 @@ public class MainButton extends RelativeLayout { 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.colorSecondary); + setImageWithTint(shadowLight, drawableResource, R.color.colorMainBtnHighlight); } else { - setImageWithTint(shadowLight, drawableResource, R.color.colorWarning); + setImageWithTint(shadowLight, drawableResource, R.color.colorMainBtnError); } this.isError = isError; } -- cgit v1.2.3 From 96a397b01da596204e3e9d1ff2dd2c176f76e5b3 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Mon, 15 Nov 2021 20:42:58 +0100 Subject: improve location status indicator, adapt according to desktop --- .../base/views/LocationIndicator.java | 51 ++++++++++++++-------- 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java index f5e3dbe2..8245893d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java @@ -7,15 +7,21 @@ import android.view.View; import android.widget.LinearLayout; import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.eip.GatewaysManager; +import static androidx.core.content.ContextCompat.getColor; + public class LocationIndicator extends LinearLayout { private View level1; + private View level1_2; private View level2; + private View level2_2; private View level3; + private View level3_2; public LocationIndicator(Context context) { super(context); @@ -39,37 +45,46 @@ public class LocationIndicator extends LinearLayout { .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rootview = inflater.inflate(R.layout.v_location_status_indicator, this, true); level1 = rootview.findViewById(R.id.level1); + level1_2 = rootview.findViewById(R.id.level1_2); level2 = rootview.findViewById(R.id.level2); + level2_2 = rootview.findViewById(R.id.level2_2); level3 = rootview.findViewById(R.id.level3); + level3_2 = rootview.findViewById(R.id.level3_2); } public void setLoad(GatewaysManager.Load load) { switch (load) { case GOOD: - level1.setBackgroundColor(getResources().getColor(R.color.green200)); - level2.setBackgroundColor(getResources().getColor(R.color.green200)); - level3.setBackgroundColor(getResources().getColor(R.color.green200)); - level1.setVisibility(VISIBLE); - level2.setVisibility(VISIBLE); - level3.setVisibility(VISIBLE); + level1.setBackgroundColor(getColor(getContext(), R.color.green200)); + level1_2.setBackgroundColor(getColor(getContext(), R.color.green200)); + level2.setBackgroundColor(getColor(getContext(), R.color.green200)); + level2_2.setBackgroundColor(getColor(getContext(), R.color.green200)); + level3.setBackgroundColor(getColor(getContext(), R.color.green200)); + level3_2.setBackgroundColor(getColor(getContext(), R.color.green200)); break; case AVERAGE: - level1.setBackgroundColor(getResources().getColor(R.color.yellow200)); - level2.setBackgroundColor(getResources().getColor(R.color.yellow200)); - level1.setVisibility(VISIBLE); - level2.setVisibility(VISIBLE); - level3.setVisibility(INVISIBLE); + level1.setBackgroundColor(getColor(getContext(), R.color.yellow200)); + level1_2.setBackgroundColor(getColor(getContext(), R.color.yellow200)); + level2.setBackgroundColor(getColor(getContext(), R.color.yellow200)); + level2_2.setBackgroundColor(getColor(getContext(), R.color.yellow200)); + level3.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent)); + level3_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent)); break; case CRITICAL: - level1.setBackgroundColor(getResources().getColor(R.color.red200)); - level1.setVisibility(VISIBLE); - level2.setVisibility(INVISIBLE); - level3.setVisibility(INVISIBLE); + level1.setBackgroundColor(getColor(getContext(), R.color.red200)); + level1_2.setBackgroundColor(getColor(getContext(), R.color.red200)); + level2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent)); + level2_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent)); + level3.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent)); + level3_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent)); break; default: - level1.setVisibility(INVISIBLE); - level2.setVisibility(INVISIBLE); - level3.setVisibility(INVISIBLE); + level1.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent)); + level1_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent)); + level2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent)); + level2_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent)); + level3.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent)); + level3_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));; break; } } -- cgit v1.2.3 From 7436008db89d4ddf4f918fc220dc813b3289d0d7 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 16 Nov 2021 00:12:38 +0100 Subject: add bridge indicator to bottom panel --- .../java/se/leap/bitmaskclient/base/views/LocationButton.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java index 1d7f0d18..11ea198c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java @@ -4,18 +4,22 @@ import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; +import android.widget.RelativeLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatTextView; import androidx.appcompat.widget.LinearLayoutCompat; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.eip.GatewaysManager; -public class LocationButton extends LinearLayoutCompat { +public class LocationButton extends RelativeLayout { private LocationIndicator locationIndicator; private AppCompatTextView textView; + private AppCompatImageView bridgeView; + public LocationButton(@NonNull Context context) { super(context); initLayout(context); @@ -32,6 +36,7 @@ public class LocationButton extends LinearLayoutCompat { View rootview = inflater.inflate(R.layout.v_location_button, this, true); locationIndicator = rootview.findViewById(R.id.load_indicator); textView = rootview.findViewById(R.id.text_location); + bridgeView = rootview.findViewById(R.id.bridge_icn); } public void setLocationLoad(GatewaysManager.Load load) { @@ -41,4 +46,8 @@ public class LocationButton extends LinearLayoutCompat { public void setText(CharSequence text) { textView.setText(text); } + + public void showBridgeIndicator(boolean show) { + bridgeView.setVisibility(show ? VISIBLE : GONE); + } } -- cgit v1.2.3 From ca00d7454ad412bc3cf54159a87caa0ffb349502 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 16 Nov 2021 03:51:55 +0100 Subject: replace all TextViews with AppCompatTextViews --- .../leap/bitmaskclient/base/views/IconCheckboxEntry.java | 4 ++-- .../se/leap/bitmaskclient/base/views/IconSwitchEntry.java | 5 +++-- .../se/leap/bitmaskclient/base/views/IconTextEntry.java | 15 ++++++++------- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java index 977056f7..0957712b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java @@ -7,10 +7,10 @@ import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; -import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatImageView; +import androidx.appcompat.widget.AppCompatTextView; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; @@ -23,7 +23,7 @@ import se.leap.bitmaskclient.base.fragments.TetheringDialog; public class IconCheckboxEntry extends LinearLayout { @BindView(android.R.id.text1) - TextView textView; + AppCompatTextView textView; @BindView(R.id.material_icon) AppCompatImageView iconView; diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/IconSwitchEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/IconSwitchEntry.java index b6d72ab6..a499cdd1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/IconSwitchEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/IconSwitchEntry.java @@ -24,6 +24,7 @@ import androidx.annotation.DrawableRes; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.appcompat.widget.AppCompatImageView; +import androidx.appcompat.widget.AppCompatTextView; import androidx.appcompat.widget.SwitchCompat; import android.util.AttributeSet; import android.view.LayoutInflater; @@ -36,8 +37,8 @@ import se.leap.bitmaskclient.R; public class IconSwitchEntry extends LinearLayout { - private TextView textView; - private TextView subtitleView; + private AppCompatTextView textView; + private AppCompatTextView subtitleView; private AppCompatImageView iconView; private SwitchCompat switchView; private CompoundButton.OnCheckedChangeListener checkedChangeListener; diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/IconTextEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/IconTextEntry.java index 6b9bd760..2d9525ed 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/IconTextEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/IconTextEntry.java @@ -4,25 +4,26 @@ import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; -import androidx.annotation.ColorRes; -import androidx.annotation.DrawableRes; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.TextView; + +import androidx.annotation.ColorRes; +import androidx.annotation.DrawableRes; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.appcompat.widget.AppCompatTextView; import se.leap.bitmaskclient.R; public class IconTextEntry extends LinearLayout { - private TextView textView; + private AppCompatTextView textView; private ImageView iconView; - private TextView subtitleView; + private AppCompatTextView subtitleView; public IconTextEntry(Context context) { super(context); -- cgit v1.2.3 From 9cf45bbcc1e707525fecdac5e691adebf0c28cb5 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 20 Nov 2021 13:42:59 +0100 Subject: show lightning bold instead of text 'You're connected to the recommended location' --- .../main/java/se/leap/bitmaskclient/base/views/LocationButton.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java index 11ea198c..b2182d61 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java @@ -10,7 +10,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatTextView; -import androidx.appcompat.widget.LinearLayoutCompat; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.eip.GatewaysManager; @@ -19,6 +18,7 @@ public class LocationButton extends RelativeLayout { private LocationIndicator locationIndicator; private AppCompatTextView textView; private AppCompatImageView bridgeView; + private AppCompatImageView recommendedView; public LocationButton(@NonNull Context context) { super(context); @@ -37,6 +37,7 @@ public class LocationButton extends RelativeLayout { locationIndicator = rootview.findViewById(R.id.load_indicator); textView = rootview.findViewById(R.id.text_location); bridgeView = rootview.findViewById(R.id.bridge_icn); + recommendedView = rootview.findViewById(R.id.recommended_icn); } public void setLocationLoad(GatewaysManager.Load load) { @@ -50,4 +51,8 @@ public class LocationButton extends RelativeLayout { public void showBridgeIndicator(boolean show) { bridgeView.setVisibility(show ? VISIBLE : GONE); } + + public void showRecommendedIndicator(boolean show) { + recommendedView.setVisibility(show? VISIBLE : GONE ); + } } -- cgit v1.2.3 From a6cd31ae8624f830454adc627ac3a6be323a5333 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sun, 21 Nov 2021 19:36:46 +0100 Subject: implement new gateway selection UI, using same UX principles as for desktop --- .../base/views/SelectLocationEntry.java | 90 ++++++++++++++++++++++ .../bitmaskclient/base/views/SimpleCheckBox.java | 50 ++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java new file mode 100644 index 00000000..f85df4ca --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java @@ -0,0 +1,90 @@ +package se.leap.bitmaskclient.base.views; + +import android.annotation.TargetApi; +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.RelativeLayout; + +import androidx.appcompat.widget.AppCompatImageView; +import androidx.appcompat.widget.AppCompatTextView; + +import de.blinkt.openvpn.core.connection.Connection; +import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.base.models.Location; +import se.leap.bitmaskclient.eip.GatewaysManager.Load; + +public class SelectLocationEntry extends RelativeLayout { + + private static final String TAG = SelectLocationEntry.class.getSimpleName(); + AppCompatTextView title; + AppCompatTextView locationText; + SimpleCheckBox selectedView; + AppCompatImageView bridgesView; + LocationIndicator locationIndicator; + View divider; + + // private OnClickListener onClickListener; + + public SelectLocationEntry(Context context) { + super(context); + initLayout(context); + } + + public SelectLocationEntry(Context context, AttributeSet attrs) { + super(context, attrs); + initLayout(context); + } + + public SelectLocationEntry(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initLayout(context); + } + + @TargetApi(21) + public SelectLocationEntry(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_select_text_list_item, this, true); + title = rootview.findViewById(R.id.title); + locationIndicator = rootview.findViewById(R.id.quality); + locationText = rootview.findViewById(R.id.location); + bridgesView = rootview.findViewById(R.id.bridge_image); + selectedView = rootview.findViewById(R.id.selected); + divider = rootview.findViewById(R.id.divider); + } + + public void setTitle(String text) { + title.setText(text); + title.setVisibility(text != null ? VISIBLE : GONE); + } + public void setLocation(Location location) { + boolean valid = location.hasLocationInfo(); + locationText.setVisibility(valid ? VISIBLE : GONE); + locationIndicator.setVisibility(valid ? VISIBLE : GONE); + bridgesView.setVisibility(valid ? VISIBLE : GONE); + locationText.setText(location.name); + locationIndicator.setLoad(Load.getLoadByValue(location.averageLoad)); + bridgesView.setVisibility(location.supportedTransports.contains(Connection.TransportType.OBFS4) ? VISIBLE : GONE); + selectedView.setChecked(location.selected); + } + + public void showDivider(boolean show) { + divider.setVisibility(show ? VISIBLE : GONE); + } + + public void setSelected(boolean selected) { + selectedView.setChecked(selected); + } + + public boolean isSelected() { + return selectedView.checkView.getVisibility() == VISIBLE; + } + +} diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java b/app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java new file mode 100644 index 00000000..7cd790db --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java @@ -0,0 +1,50 @@ +package se.leap.bitmaskclient.base.views; + +import android.annotation.TargetApi; +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.RelativeLayout; + +import androidx.appcompat.widget.AppCompatImageView; + +import se.leap.bitmaskclient.R; + +public class SimpleCheckBox extends RelativeLayout { + + AppCompatImageView checkView; + + + public SimpleCheckBox(Context context) { + super(context); + initLayout(context); + } + + public SimpleCheckBox(Context context, AttributeSet attrs) { + super(context, attrs); + initLayout(context); + } + + public SimpleCheckBox(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initLayout(context); + } + + @TargetApi(21) + public SimpleCheckBox(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_simple_checkbox, this, true); + this.checkView = rootview.findViewById(R.id.check_view); + } + + public void setChecked(boolean checked) { + this.checkView.setVisibility(checked ? VISIBLE : INVISIBLE); + } +} -- cgit v1.2.3 From 9bf787465a3ae22c76249317496c8927b22ffdb4 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 23 Nov 2021 12:32:07 +0100 Subject: calculate and show gateway load related to transport --- .../se/leap/bitmaskclient/base/views/SelectLocationEntry.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java index f85df4ca..bf293a51 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java @@ -64,14 +64,14 @@ public class SelectLocationEntry extends RelativeLayout { title.setText(text); title.setVisibility(text != null ? VISIBLE : GONE); } - public void setLocation(Location location) { + public void setLocation(Location location, Connection.TransportType transportType) { boolean valid = location.hasLocationInfo(); locationText.setVisibility(valid ? VISIBLE : GONE); locationIndicator.setVisibility(valid ? VISIBLE : GONE); bridgesView.setVisibility(valid ? VISIBLE : GONE); - locationText.setText(location.name); - locationIndicator.setLoad(Load.getLoadByValue(location.averageLoad)); - bridgesView.setVisibility(location.supportedTransports.contains(Connection.TransportType.OBFS4) ? VISIBLE : GONE); + locationText.setText(location.getName()); + locationIndicator.setLoad(Load.getLoadByValue(location.getAverageLoad(transportType))); + bridgesView.setVisibility(location.supportsTransport(Connection.TransportType.OBFS4) ? VISIBLE : GONE); selectedView.setChecked(location.selected); } -- cgit v1.2.3 From 638b2c53f00f552693cc8f425eaa862343e6cf20 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 23 Nov 2021 15:42:41 +0100 Subject: add OnCheckedChangedListener in SimpleCheckbox --- .../bitmaskclient/base/views/SimpleCheckBox.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java b/app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java index 7cd790db..09a9132e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/SimpleCheckBox.java @@ -9,11 +9,19 @@ import android.widget.RelativeLayout; import androidx.appcompat.widget.AppCompatImageView; +import java.lang.ref.WeakReference; + import se.leap.bitmaskclient.R; public class SimpleCheckBox extends RelativeLayout { AppCompatImageView checkView; + private WeakReference checkedChangeListener = new WeakReference(null); + private boolean checked; + + public interface OnCheckedChangeListener { + void onCheckedChanged(SimpleCheckBox simpleCheckBox, boolean isChecked); + } public SimpleCheckBox(Context context) { @@ -45,6 +53,21 @@ public class SimpleCheckBox extends RelativeLayout { } public void setChecked(boolean checked) { - this.checkView.setVisibility(checked ? VISIBLE : INVISIBLE); + if (this.checked != checked) { + this.checkView.setVisibility(checked ? VISIBLE : INVISIBLE); + this.checked = checked; + OnCheckedChangeListener listener = checkedChangeListener.get(); + if (listener != null) { + listener.onCheckedChanged(this, this.checked); + } + } + } + + public void setOnCheckedChangeListener(OnCheckedChangeListener listener) { + checkedChangeListener = new WeakReference<>(listener); + } + + public void toggle() { + setChecked(!this.checked); } } -- cgit v1.2.3 From 6d24e0c721038bb6f7a5c34703e5cf405166bf6b Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 23 Nov 2021 19:06:24 +0100 Subject: improve location selection list entry layout --- .../java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java index bf293a51..204e8692 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java @@ -5,6 +5,7 @@ import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; +import android.widget.LinearLayout; import android.widget.RelativeLayout; import androidx.appcompat.widget.AppCompatImageView; @@ -15,7 +16,7 @@ import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.models.Location; import se.leap.bitmaskclient.eip.GatewaysManager.Load; -public class SelectLocationEntry extends RelativeLayout { +public class SelectLocationEntry extends LinearLayout { private static final String TAG = SelectLocationEntry.class.getSimpleName(); AppCompatTextView title; -- cgit v1.2.3 From e3cd28aa6ef16d9bde179a3e1117cdfa585939a4 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Wed, 24 Nov 2021 10:17:26 +0100 Subject: only show bridges icon in gateway selection list if location supports it AND bridges setting is enabled --- .../java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java index 204e8692..2a082579 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java @@ -16,6 +16,8 @@ import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.models.Location; import se.leap.bitmaskclient.eip.GatewaysManager.Load; +import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4; + public class SelectLocationEntry extends LinearLayout { private static final String TAG = SelectLocationEntry.class.getSimpleName(); @@ -26,8 +28,6 @@ public class SelectLocationEntry extends LinearLayout { LocationIndicator locationIndicator; View divider; - // private OnClickListener onClickListener; - public SelectLocationEntry(Context context) { super(context); initLayout(context); @@ -69,10 +69,9 @@ public class SelectLocationEntry extends LinearLayout { boolean valid = location.hasLocationInfo(); locationText.setVisibility(valid ? VISIBLE : GONE); locationIndicator.setVisibility(valid ? VISIBLE : GONE); - bridgesView.setVisibility(valid ? VISIBLE : GONE); + bridgesView.setVisibility(transportType == OBFS4 && location.supportsTransport(OBFS4) ? VISIBLE : GONE); locationText.setText(location.getName()); locationIndicator.setLoad(Load.getLoadByValue(location.getAverageLoad(transportType))); - bridgesView.setVisibility(location.supportsTransport(Connection.TransportType.OBFS4) ? VISIBLE : GONE); selectedView.setChecked(location.selected); } -- cgit v1.2.3