From ba94657badcc5a05214a057fa938124bdf1ad47a Mon Sep 17 00:00:00 2001 From: cyBerta Date: Wed, 4 Jul 2018 23:42:45 +0200 Subject: #8886 add layout for tablets and improve tablet and phone layouts in general by implementing dynamic layout changes when keyboard appears --- .../bitmaskclient/views/ProviderHeaderView.java | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 app/src/main/java/se/leap/bitmaskclient/views/ProviderHeaderView.java (limited to 'app/src/main/java/se/leap/bitmaskclient/views/ProviderHeaderView.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/views/ProviderHeaderView.java b/app/src/main/java/se/leap/bitmaskclient/views/ProviderHeaderView.java new file mode 100644 index 00000000..ab5d6bc8 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/views/ProviderHeaderView.java @@ -0,0 +1,109 @@ +package se.leap.bitmaskclient.views; + +import android.content.Context; +import android.support.annotation.DrawableRes; +import android.support.annotation.RequiresApi; +import android.support.annotation.StringRes; +import android.support.v7.widget.AppCompatImageView; +import android.support.v7.widget.AppCompatTextView; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.RelativeLayout; + +import se.leap.bitmaskclient.R; + +import static se.leap.bitmaskclient.utils.ViewHelper.convertDimensionToPx; + +/** + * Created by cyberta on 29.06.18. + */ + +public class ProviderHeaderView extends RelativeLayout { + private int stdPadding; + private int compactPadding; + private int stdImageSize; + private int compactImageSize; + + AppCompatImageView providerHeaderLogo; + AppCompatTextView providerHeaderText; + + public ProviderHeaderView(Context context) { + super(context); + initLayout(context); + } + + public ProviderHeaderView(Context context, AttributeSet attrs) { + super(context, attrs); + initLayout(context); + } + + public ProviderHeaderView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initLayout(context); + } + + @RequiresApi(21) + public ProviderHeaderView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + initLayout(context); + } + + + void initLayout(Context context) { + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View rootview = inflater.inflate(R.layout.v_provider_header, this, true); + providerHeaderLogo = rootview.findViewById(R.id.provider_header_logo); + providerHeaderText = rootview.findViewById(R.id.provider_header_text); + + stdPadding = convertDimensionToPx(context, R.dimen.stdpadding); + compactPadding = convertDimensionToPx(context, R.dimen.compact_padding); + stdImageSize = convertDimensionToPx(context, R.dimen.bitmask_logo); + compactImageSize = convertDimensionToPx(context, R.dimen.bitmask_logo_compact); + } + + public void setTitle(String title) { + providerHeaderText.setText(title); + } + + public void setTitle(@StringRes int stringRes) { + providerHeaderText.setText(stringRes); + } + + public void setLogo(@DrawableRes int drawableRes) { + providerHeaderLogo.setImageResource(drawableRes); + } + + public void showCompactLayout() { + LayoutParams logoLayoutParams = (LayoutParams) providerHeaderLogo.getLayoutParams(); + logoLayoutParams.width = compactImageSize; + logoLayoutParams.height = compactImageSize; + providerHeaderLogo.setLayoutParams(logoLayoutParams); + + LayoutParams textLayoutParams = (LayoutParams) providerHeaderText.getLayoutParams(); + textLayoutParams.addRule(RIGHT_OF, R.id.provider_header_logo); + textLayoutParams.addRule(BELOW, 0); + textLayoutParams.addRule(ALIGN_TOP, R.id.provider_header_logo); + textLayoutParams.setMargins(compactPadding, compactPadding, compactPadding, compactPadding); + + providerHeaderText.setLayoutParams(textLayoutParams); + providerHeaderText.setMaxLines(2); + } + + public void showStandardLayout() { + LayoutParams logoLayoutParams = (LayoutParams) providerHeaderLogo.getLayoutParams(); + logoLayoutParams.width = stdImageSize; + logoLayoutParams.height = stdImageSize; + providerHeaderLogo.setLayoutParams(logoLayoutParams); + + LayoutParams textLayoutParams = (LayoutParams) providerHeaderText.getLayoutParams(); + textLayoutParams.addRule(RIGHT_OF, 0); + textLayoutParams.addRule(BELOW, R.id.provider_header_logo); + textLayoutParams.addRule(ALIGN_TOP, 0); + textLayoutParams.setMargins(stdPadding, stdPadding, stdPadding, stdPadding); + providerHeaderText.setLayoutParams(textLayoutParams); + providerHeaderText.setMaxLines(1); + } + +} -- cgit v1.2.3