summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/base/views
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-07-22 15:31:08 +0200
committercyBerta <cyberta@riseup.net>2021-11-14 19:22:16 +0100
commit1e9202c3d929083220924f7c76ea01a2b6f6af9f (patch)
treeeda2def77a2a7d135961689c5e5f7fd15a220132 /app/src/main/java/se/leap/bitmaskclient/base/views
parent5b4db114cb35c5c9012c744c82656b1071aacda0 (diff)
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
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/base/views')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java44
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java76
2 files changed, 120 insertions, 0 deletions
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;
+ }
+ }
+}