From 0157b7b54f864258ae437c3566fe2cb74f0da61e Mon Sep 17 00:00:00 2001 From: cyBerta Date: Wed, 1 Jan 2020 21:24:50 +0100 Subject: add new icons for tethering --- .../bitmaskclient/views/IconCheckboxEntry.java | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java (limited to 'app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java b/app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java new file mode 100644 index 00000000..cd151885 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java @@ -0,0 +1,106 @@ +package se.leap.bitmaskclient.views; + +import android.annotation.TargetApi; +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; +import android.support.annotation.ColorRes; +import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; +import android.support.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 se.leap.bitmaskclient.R; + + +public class IconTextEntry extends LinearLayout { + + private TextView textView; + private ImageView iconView; + private TextView subtitleView; + + public IconTextEntry(Context context) { + super(context); + initLayout(context, null); + } + + public IconTextEntry(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + initLayout(context, attrs); + } + + public IconTextEntry(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initLayout(context, attrs); + } + + @TargetApi(21) + public IconTextEntry(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + initLayout(context, attrs); + } + + void initLayout(Context context, AttributeSet attrs) { + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View rootview = inflater.inflate(R.layout.v_icon_text_list_item, this, true); + textView = rootview.findViewById(android.R.id.text1); + subtitleView = rootview.findViewById(R.id.subtitle); + iconView = rootview.findViewById(R.id.material_icon); + + if (attrs != null) { + TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.IconTextEntry); + + String entryText = typedArray.getString(R.styleable.IconTextEntry_text); + if (entryText != null) { + textView.setText(entryText); + } + + String subtitle = typedArray.getString(R.styleable.IconTextEntry_subtitle); + if (subtitle != null) { + subtitleView.setText(subtitle); + subtitleView.setVisibility(VISIBLE); + } + + Drawable drawable = typedArray.getDrawable(R.styleable.IconTextEntry_icon); + if (drawable != null) { + iconView.setImageDrawable(drawable); + } + + typedArray.recycle(); + } + + + } + + public void setText(@StringRes int id) { + textView.setText(id); + } + + public void setSubtitle(String text) { + subtitleView.setText(text); + subtitleView.setVisibility(VISIBLE); + } + + public void hideSubtitle() { + subtitleView.setVisibility(GONE); + } + + public void setSubtitleColor(@ColorRes int color) { + subtitleView.setTextColor(getContext().getResources().getColor(color)); + } + + public void setText(CharSequence text) { + textView.setText(text); + } + + public void setIcon(@DrawableRes int id) { + iconView.setImageResource(id); + } + +} -- cgit v1.2.3 From 921ee995ef0f0e7f2076ac3538fed289bcb82ba9 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 2 Jan 2020 23:06:36 +0100 Subject: implement basic UI for VPN tethering --- .../bitmaskclient/views/IconCheckboxEntry.java | 91 ++++++++-------------- 1 file changed, 31 insertions(+), 60 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java b/app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java index cd151885..933d391b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java @@ -2,45 +2,51 @@ package se.leap.bitmaskclient.views; import android.annotation.TargetApi; import android.content.Context; -import android.content.res.TypedArray; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorRes; -import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; -import android.support.annotation.StringRes; +import android.support.v4.content.ContextCompat; +import android.support.v4.graphics.drawable.DrawableCompat; +import android.support.v7.widget.AppCompatImageView; 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 butterknife.ButterKnife; +import butterknife.InjectView; import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.fragments.TetheringDialog; -public class IconTextEntry extends LinearLayout { +public class IconCheckboxEntry extends LinearLayout { - private TextView textView; - private ImageView iconView; - private TextView subtitleView; + @InjectView(android.R.id.text1) + TextView textView; - public IconTextEntry(Context context) { + @InjectView(R.id.material_icon) + AppCompatImageView iconView; + + @InjectView(R.id.checked_icon) + AppCompatImageView checkedIcon; + + public IconCheckboxEntry(Context context) { super(context); initLayout(context, null); } - public IconTextEntry(Context context, @Nullable AttributeSet attrs) { + public IconCheckboxEntry(Context context, @Nullable AttributeSet attrs) { super(context, attrs); initLayout(context, attrs); } - public IconTextEntry(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + public IconCheckboxEntry(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initLayout(context, attrs); } @TargetApi(21) - public IconTextEntry(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + public IconCheckboxEntry(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); initLayout(context, attrs); } @@ -48,59 +54,24 @@ public class IconTextEntry extends LinearLayout { void initLayout(Context context, AttributeSet attrs) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View rootview = inflater.inflate(R.layout.v_icon_text_list_item, this, true); - textView = rootview.findViewById(android.R.id.text1); - subtitleView = rootview.findViewById(R.id.subtitle); - iconView = rootview.findViewById(R.id.material_icon); - - if (attrs != null) { - TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.IconTextEntry); - - String entryText = typedArray.getString(R.styleable.IconTextEntry_text); - if (entryText != null) { - textView.setText(entryText); - } - - String subtitle = typedArray.getString(R.styleable.IconTextEntry_subtitle); - if (subtitle != null) { - subtitleView.setText(subtitle); - subtitleView.setVisibility(VISIBLE); - } - - Drawable drawable = typedArray.getDrawable(R.styleable.IconTextEntry_icon); - if (drawable != null) { - iconView.setImageDrawable(drawable); - } - - typedArray.recycle(); - } - + View rootview = inflater.inflate(R.layout.v_icon_select_text_list_item, this, true); + ButterKnife.inject(this, rootview); - } - - public void setText(@StringRes int id) { - textView.setText(id); - } - - public void setSubtitle(String text) { - subtitleView.setText(text); - subtitleView.setVisibility(VISIBLE); - } - - public void hideSubtitle() { - subtitleView.setVisibility(GONE); - } + Drawable checkIcon = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_check_bold)); + DrawableCompat.setTint(checkIcon, ContextCompat.getColor(getContext(), R.color.colorSuccess)); + checkedIcon.setImageDrawable(checkIcon); - public void setSubtitleColor(@ColorRes int color) { - subtitleView.setTextColor(getContext().getResources().getColor(color)); } - public void setText(CharSequence text) { - textView.setText(text); + public void bind(TetheringDialog.DialogListAdapter.ViewModel model) { + textView.setText(model.text); + iconView.setImageDrawable(model.image); + setChecked(model.checked); } - public void setIcon(@DrawableRes int id) { - iconView.setImageResource(id); + public void setChecked(boolean checked) { + checkedIcon.setVisibility(checked ? VISIBLE : GONE); + checkedIcon.setContentDescription(checked ? "selected" : "unselected"); } } -- cgit v1.2.3 From f0ec974d143556e4729ac21c7fcf6a1f1a3687df Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 3 Jan 2020 01:01:56 +0100 Subject: detect hotspot state and disable/enable controls in TetheringDialog accordingly --- .../se/leap/bitmaskclient/views/IconCheckboxEntry.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java b/app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java index 933d391b..ca44592e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/views/IconCheckboxEntry.java @@ -57,15 +57,24 @@ public class IconCheckboxEntry extends LinearLayout { View rootview = inflater.inflate(R.layout.v_icon_select_text_list_item, this, true); ButterKnife.inject(this, rootview); - Drawable checkIcon = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_check_bold)); - DrawableCompat.setTint(checkIcon, ContextCompat.getColor(getContext(), R.color.colorSuccess)); - checkedIcon.setImageDrawable(checkIcon); + } public void bind(TetheringDialog.DialogListAdapter.ViewModel model) { + this.setEnabled(model.enabled); textView.setText(model.text); + textView.setEnabled(model.enabled); + + Drawable checkIcon = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_check_bold)).mutate(); + if (model.enabled) { + DrawableCompat.setTint(checkIcon, ContextCompat.getColor(getContext(), R.color.colorSuccess)); + } else { + DrawableCompat.setTint(checkIcon, ContextCompat.getColor(getContext(), R.color.colorDisabled)); + } + iconView.setImageDrawable(model.image); + checkedIcon.setImageDrawable(checkIcon); setChecked(model.checked); } -- cgit v1.2.3