summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/base/views
diff options
context:
space:
mode:
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.java22
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java124
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/views/VpnStateImage.java99
3 files changed, 13 insertions, 232 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
index b2182d61..7ad044bd 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
@@ -3,15 +3,16 @@ 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.RelativeLayout;
+import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;
+import androidx.core.content.ContextCompat;
-import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.databinding.VLocationButtonBinding;
import se.leap.bitmaskclient.eip.GatewaysManager;
public class LocationButton extends RelativeLayout {
@@ -31,13 +32,16 @@ public class LocationButton extends RelativeLayout {
}
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);
- bridgeView = rootview.findViewById(R.id.bridge_icn);
- recommendedView = rootview.findViewById(R.id.recommended_icn);
+ VLocationButtonBinding binding = VLocationButtonBinding.inflate(LayoutInflater.from(context), this, true);
+ locationIndicator = binding.loadIndicator;
+ textView = binding.textLocation;
+ bridgeView = binding.bridgeIcn;
+ recommendedView = binding.recommendedIcn;
+
+ }
+
+ public void setTextColor(@ColorRes int color) {
+ textView.setTextColor(ContextCompat.getColor(getContext(), color));
}
public void setLocationLoad(GatewaysManager.Load load) {
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
deleted file mode 100644
index c5ac4544..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java
+++ /dev/null
@@ -1,124 +0,0 @@
-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);
- }
-
-
-
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/VpnStateImage.java b/app/src/main/java/se/leap/bitmaskclient/base/views/VpnStateImage.java
deleted file mode 100644
index 2f8a4448..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/base/views/VpnStateImage.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Copyright (c) 2018 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package se.leap.bitmaskclient.base.views;
-
-import android.content.Context;
-import androidx.constraintlayout.widget.ConstraintLayout;
-import androidx.appcompat.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;
-
-/**
- * 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(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) {
- stateIcon.setImageResource(resource);
- }
-
-
-}