From 3f5115728b4dd05e65b723c6fd98edbfa63bcf9c Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 5 Apr 2019 22:30:11 -0400 Subject: [PATCH] layout tweaks --- .../BoxedView/BoxedViewRecyclerAdapter.cs | 1 + .../Renderers/BoxedView/Cells/BaseCellView.cs | 12 ++- .../BoxedView/Cells/EntryCellRenderer.cs | 80 ++++--------------- .../BoxedView/Cells/LabelCellRenderer.cs | 55 ++++++------- src/Android/Resources/Resource.designer.cs | 24 +++--- .../Resources/layout/CellBaseView.axml | 24 ++++-- src/Android/Resources/layout/FooterCell.axml | 2 + src/Android/Resources/layout/HeaderCell.axml | 2 +- src/App/Controls/BoxedView/BoxedView.cs | 8 +- src/App/Controls/BoxedView/Cells/BaseCell.cs | 4 +- src/App/Controls/BoxedView/Cells/EntryCell.cs | 4 +- src/App/Controls/BoxedView/Cells/LabelCell.cs | 4 +- 12 files changed, 95 insertions(+), 125 deletions(-) diff --git a/src/Android/Renderers/BoxedView/BoxedViewRecyclerAdapter.cs b/src/Android/Renderers/BoxedView/BoxedViewRecyclerAdapter.cs index fe15d37c5..d5f3559b8 100644 --- a/src/Android/Renderers/BoxedView/BoxedViewRecyclerAdapter.cs +++ b/src/Android/Renderers/BoxedView/BoxedViewRecyclerAdapter.cs @@ -218,6 +218,7 @@ namespace Bit.Droid.Renderers.BoxedView holder.TextView.SetBackgroundColor(_boxedView.HeaderBackgroundColor.ToAndroid()); holder.TextView.SetMaxLines(1); holder.TextView.SetMinLines(1); + holder.TextView.SetTypeface(null, Android.Graphics.TypefaceStyle.Bold); holder.TextView.Ellipsize = TextUtils.TruncateAt.End; if(_boxedView.HeaderTextColor != Color.Default) diff --git a/src/Android/Renderers/BoxedView/Cells/BaseCellView.cs b/src/Android/Renderers/BoxedView/Cells/BaseCellView.cs index aa2afc478..1db2aa249 100644 --- a/src/Android/Renderers/BoxedView/Cells/BaseCellView.cs +++ b/src/Android/Renderers/BoxedView/Cells/BaseCellView.cs @@ -17,6 +17,7 @@ namespace Bit.Droid.Renderers.BoxedView [Preserve(AllMembers = true)] public class BaseCellView : ARelativeLayout, INativeElementView { + private bool _debugWithColors = false; private CancellationTokenSource _iconTokenSource; private Android.Graphics.Color _defaultTextColor; private ColorDrawable _backgroundColor; @@ -87,6 +88,14 @@ namespace Bit.Droid.Renderers.BoxedView _defaultTextColor = new Android.Graphics.Color(CellTitle.CurrentTextColor); _defaultFontSize = CellTitle.TextSize; + + if(_debugWithColors) + { + contentView.Background = _Context.GetDrawable(Android.Resource.Color.HoloGreenLight); + CellContent.Background = _Context.GetDrawable(Android.Resource.Color.HoloOrangeLight); + CellButtonContent.Background = _Context.GetDrawable(Android.Resource.Color.HoloOrangeDark); + CellTitle.Background = _Context.GetDrawable(Android.Resource.Color.HoloBlueLight); + } } public virtual void CellPropertyChanged(object sender, PropertyChangedEventArgs e) @@ -187,7 +196,8 @@ namespace Bit.Droid.Renderers.BoxedView } else { - cellButton.Background = _Context.GetDrawable(icon); + cellButton.SetImageDrawable(_Context.GetDrawable(icon)); + cellButton.SetImageDrawable(_Context.GetDrawable(icon)); cellButton.Visibility = ViewStates.Visible; } } diff --git a/src/Android/Renderers/BoxedView/Cells/EntryCellRenderer.cs b/src/Android/Renderers/BoxedView/Cells/EntryCellRenderer.cs index 14700f67c..45123f091 100644 --- a/src/Android/Renderers/BoxedView/Cells/EntryCellRenderer.cs +++ b/src/Android/Renderers/BoxedView/Cells/EntryCellRenderer.cs @@ -1,5 +1,4 @@ using Android.Content; -using Android.Content.Res; using Android.OS; using Android.Runtime; using Android.Text; @@ -22,28 +21,29 @@ namespace Bit.Droid.Renderers.BoxedView { } [Preserve(AllMembers = true)] - public class EntryCellView : BaseCellView, ITextWatcher, TextView.IOnFocusChangeListener, + public class EntryCellView : BaseCellView, ITextWatcher, Android.Views.View.IOnFocusChangeListener, TextView.IOnEditorActionListener { + private bool _debugWithColors = false; private CustomEditText _editText; public EntryCellView(Context context, Cell cell) : base(context, cell) { - _editText = new CustomEditText(context); - - _editText.Focusable = true; - _editText.ImeOptions = ImeAction.Done; + _editText = new CustomEditText(context) + { + Focusable = true, + ImeOptions = ImeAction.Done, + OnFocusChangeListener = this, + Ellipsize = TextUtils.TruncateAt.End, + ClearFocusAction = DoneEdit, + Background = _Context.GetDrawable(Android.Resource.Color.Transparent) + }; + _editText.SetPadding(0, 0, 0, 0); _editText.SetOnEditorActionListener(this); - - _editText.OnFocusChangeListener = this; _editText.SetSingleLine(true); - _editText.Ellipsize = TextUtils.TruncateAt.End; - _editText.InputType |= InputTypes.TextFlagNoSuggestions; // Disabled spell check - _editText.Background.Alpha = 0; // Hide underline - _editText.ClearFocusAction = DoneEdit; Click += EntryCellView_Click; using(var lParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, @@ -51,6 +51,11 @@ namespace Bit.Droid.Renderers.BoxedView { CellContent.AddView(_editText, lParams); } + + if(_debugWithColors) + { + _editText.Background = _Context.GetDrawable(Android.Resource.Color.HoloRedLight); + } } App.Controls.BoxedView.EntryCell _EntryCell => Cell as App.Controls.BoxedView.EntryCell; @@ -62,7 +67,6 @@ namespace Bit.Droid.Renderers.BoxedView UpdateValueTextFontSize(); UpdateKeyboard(); UpdatePlaceholder(); - UpdateAccentColor(); UpdateTextAlignment(); UpdateIsPassword(); base.UpdateCell(); @@ -91,10 +95,6 @@ namespace Bit.Droid.Renderers.BoxedView { UpdatePlaceholder(); } - else if(e.PropertyName == App.Controls.BoxedView.EntryCell.AccentColorProperty.PropertyName) - { - UpdateAccentColor(); - } else if(e.PropertyName == App.Controls.BoxedView.EntryCell.TextAlignmentProperty.PropertyName) { UpdateTextAlignment(); @@ -116,10 +116,6 @@ namespace Bit.Droid.Renderers.BoxedView { UpdateWithForceLayout(UpdateValueTextFontSize); } - else if(e.PropertyName == App.Controls.BoxedView.BoxedView.CellAccentColorProperty.PropertyName) - { - UpdateAccentColor(); - } } protected override void Dispose(bool disposing) @@ -138,21 +134,6 @@ namespace Bit.Droid.Renderers.BoxedView base.Dispose(disposing); } - protected override void SetEnabledAppearance(bool isEnabled) - { - if(isEnabled) - { - _editText.Enabled = true; - _editText.Alpha = 1.0f; - } - else - { - _editText.Enabled = false; - _editText.Alpha = 0.3f; - } - base.SetEnabledAppearance(isEnabled); - } - private void EntryCellView_Click(object sender, EventArgs e) { _editText.RequestFocus(); @@ -214,33 +195,6 @@ namespace Bit.Droid.Renderers.BoxedView _editText.Gravity = _EntryCell.TextAlignment.ToAndroidHorizontal(); } - private void UpdateAccentColor() - { - if(_EntryCell.AccentColor != Color.Default) - { - ChangeTextViewBack(_EntryCell.AccentColor.ToAndroid()); - } - else if(CellParent != null && CellParent.CellAccentColor != Color.Default) - { - ChangeTextViewBack(CellParent.CellAccentColor.ToAndroid()); - } - } - - private void ChangeTextViewBack(Android.Graphics.Color accent) - { - var colorlist = new ColorStateList( - new int[][] - { - new int[]{Android.Resource.Attribute.StateFocused}, - new int[]{-Android.Resource.Attribute.StateFocused}, - }, - new int[] { - Android.Graphics.Color.Argb(255,accent.R,accent.G,accent.B), - Android.Graphics.Color.Argb(255, 200, 200, 200) - }); - _editText.Background.SetTintList(colorlist); - } - private void DoneEdit() { var entryCell = (IEntryCellController)Cell; diff --git a/src/Android/Renderers/BoxedView/Cells/LabelCellRenderer.cs b/src/Android/Renderers/BoxedView/Cells/LabelCellRenderer.cs index 84224ed65..cdd080cb9 100644 --- a/src/Android/Renderers/BoxedView/Cells/LabelCellRenderer.cs +++ b/src/Android/Renderers/BoxedView/Cells/LabelCellRenderer.cs @@ -19,24 +19,32 @@ namespace Bit.Droid.Renderers.BoxedView [Preserve(AllMembers = true)] public class LabelCellView : BaseCellView { + private bool _debugWithColors = false; + private TextView _valueLabel; + public LabelCellView(Context context, Cell cell) : base(context, cell) { - ValueLabel = new TextView(context); - ValueLabel.SetSingleLine(true); - ValueLabel.Ellipsize = TextUtils.TruncateAt.End; - ValueLabel.Gravity = GravityFlags.Left; + _valueLabel = new TextView(context) + { + Ellipsize = TextUtils.TruncateAt.End, + Gravity = GravityFlags.Left, + }; + _valueLabel.SetSingleLine(true); using(var lParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)) { - CellContent.AddView(ValueLabel, lParams); + CellContent.AddView(_valueLabel, lParams); + } + + if(_debugWithColors) + { + _valueLabel.Background = _Context.GetDrawable(Android.Resource.Color.HoloRedLight); } } - private LabelCell _LabelCell => Cell as LabelCell; - - public TextView ValueLabel { get; set; } + private LabelCell LabelCell => Cell as LabelCell; public override void CellPropertyChanged(object sender, PropertyChangedEventArgs e) { @@ -76,46 +84,33 @@ namespace Bit.Droid.Renderers.BoxedView UpdateValueTextFontSize(); } - protected override void SetEnabledAppearance(bool isEnabled) - { - if(isEnabled) - { - ValueLabel.Alpha = 1f; - } - else - { - ValueLabel.Alpha = 0.3f; - } - base.SetEnabledAppearance(isEnabled); - } - protected void UpdateValueText() { - ValueLabel.Text = _LabelCell.ValueText; + _valueLabel.Text = LabelCell.ValueText; } private void UpdateValueTextFontSize() { - if(_LabelCell.ValueTextFontSize > 0) + if(LabelCell.ValueTextFontSize > 0) { - ValueLabel.SetTextSize(Android.Util.ComplexUnitType.Sp, (float)_LabelCell.ValueTextFontSize); + _valueLabel.SetTextSize(Android.Util.ComplexUnitType.Sp, (float)LabelCell.ValueTextFontSize); } else if(CellParent != null) { - ValueLabel.SetTextSize(Android.Util.ComplexUnitType.Sp, (float)CellParent.CellValueTextFontSize); + _valueLabel.SetTextSize(Android.Util.ComplexUnitType.Sp, (float)CellParent.CellValueTextFontSize); } Invalidate(); } private void UpdateValueTextColor() { - if(_LabelCell.ValueTextColor != Color.Default) + if(LabelCell.ValueTextColor != Color.Default) { - ValueLabel.SetTextColor(_LabelCell.ValueTextColor.ToAndroid()); + _valueLabel.SetTextColor(LabelCell.ValueTextColor.ToAndroid()); } else if(CellParent != null && CellParent.CellValueTextColor != Color.Default) { - ValueLabel.SetTextColor(CellParent.CellValueTextColor.ToAndroid()); + _valueLabel.SetTextColor(CellParent.CellValueTextColor.ToAndroid()); } } @@ -123,8 +118,8 @@ namespace Bit.Droid.Renderers.BoxedView { if(disposing) { - ValueLabel?.Dispose(); - ValueLabel = null; + _valueLabel?.Dispose(); + _valueLabel = null; } base.Dispose(disposing); } diff --git a/src/Android/Resources/Resource.designer.cs b/src/Android/Resources/Resource.designer.cs index 657cba3df..3bc63d566 100644 --- a/src/Android/Resources/Resource.designer.cs +++ b/src/Android/Resources/Resource.designer.cs @@ -6534,29 +6534,29 @@ namespace Bit.Droid // aapt resource value: 0x7f0a003a public const int CTRL = 2131361850; - // aapt resource value: 0x7f0a00ac - public const int CellAccessory = 2131361964; - // aapt resource value: 0x7f0a00a9 - public const int CellButton1 = 2131361961; + public const int CellAccessory = 2131361961; // aapt resource value: 0x7f0a00aa - public const int CellButton2 = 2131361962; + public const int CellButton1 = 2131361962; // aapt resource value: 0x7f0a00ab - public const int CellButton3 = 2131361963; + public const int CellButton2 = 2131361963; - // aapt resource value: 0x7f0a00a8 - public const int CellButtonContent = 2131361960; + // aapt resource value: 0x7f0a00ac + public const int CellButton3 = 2131361964; + + // aapt resource value: 0x7f0a00a6 + public const int CellButtonContent = 2131361958; // aapt resource value: 0x7f0a00a5 public const int CellContent = 2131361957; - // aapt resource value: 0x7f0a00a7 - public const int CellTitle = 2131361959; + // aapt resource value: 0x7f0a00a8 + public const int CellTitle = 2131361960; - // aapt resource value: 0x7f0a00a6 - public const int CellTitleContent = 2131361958; + // aapt resource value: 0x7f0a00a7 + public const int CellTitleContent = 2131361959; // aapt resource value: 0x7f0a00ad public const int ContentCellBody = 2131361965; diff --git a/src/Android/Resources/layout/CellBaseView.axml b/src/Android/Resources/layout/CellBaseView.axml index b57a1917a..684c6bcda 100644 --- a/src/Android/Resources/layout/CellBaseView.axml +++ b/src/Android/Resources/layout/CellBaseView.axml @@ -3,16 +3,17 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:minHeight="44dp" - android:paddingLeft="10dp" - android:paddingRight="10dp" - android:paddingTop="4dp" - android:paddingBottom="4dp"> + android:paddingLeft="15dp" + android:paddingRight="15dp" + android:paddingTop="8dp" + android:paddingBottom="8dp"> + android:layout_height="match_parent" /> + android:layout_height="match_parent" /> + android:layout_height="match_parent" /> diff --git a/src/Android/Resources/layout/HeaderCell.axml b/src/Android/Resources/layout/HeaderCell.axml index 562cf5c62..5699241a7 100644 --- a/src/Android/Resources/layout/HeaderCell.axml +++ b/src/Android/Resources/layout/HeaderCell.axml @@ -11,7 +11,7 @@ android:layout_alignParentLeft="true" android:layout_width="match_parent" android:layout_height="match_parent" - android:gravity="left" /> + android:gravity="bottom|left" /> Device.GetNamedSize(NamedSize.Small, (BoxedView)bindable)); @@ -50,7 +50,7 @@ namespace Bit.App.Controls.BoxedView defaultBindingMode: BindingMode.OneWay); public static BindableProperty FooterFontSizeProperty = BindableProperty.Create( - nameof(FooterFontSize), typeof(double), typeof(BoxedView), -1.0d, + nameof(FooterFontSize), typeof(double), typeof(BoxedView), 14.0, defaultBindingMode: BindingMode.OneWay, defaultValueCreator: bindable => Device.GetNamedSize(NamedSize.Small, (BoxedView)bindable)); @@ -59,7 +59,7 @@ namespace Bit.App.Controls.BoxedView defaultBindingMode: BindingMode.OneWay); public static BindableProperty FooterPaddingProperty = BindableProperty.Create( - nameof(FooterPadding), typeof(Thickness), typeof(BoxedView), new Thickness(14, 8, 14, 8), + nameof(FooterPadding), typeof(Thickness), typeof(BoxedView), new Thickness(15, 8, 15, 8), defaultBindingMode: BindingMode.OneWay); public static BindableProperty CellTitleColorProperty = BindableProperty.Create( diff --git a/src/App/Controls/BoxedView/Cells/BaseCell.cs b/src/App/Controls/BoxedView/Cells/BaseCell.cs index 4f7557a54..e1f804988 100644 --- a/src/App/Controls/BoxedView/Cells/BaseCell.cs +++ b/src/App/Controls/BoxedView/Cells/BaseCell.cs @@ -10,11 +10,11 @@ namespace Bit.App.Controls.BoxedView nameof(Title), typeof(string), typeof(BaseCell), default(string), defaultBindingMode: BindingMode.OneWay); public static BindableProperty TitleColorProperty = BindableProperty.Create( - nameof(TitleColor), typeof(Color), typeof(BaseCell), default(Color), + nameof(TitleColor), typeof(Color), typeof(BaseCell), Color.Gray, defaultBindingMode: BindingMode.OneWay); public static BindableProperty TitleFontSizeProperty = BindableProperty.Create( - nameof(TitleFontSize), typeof(double), typeof(BaseCell), -1.0, defaultBindingMode: BindingMode.OneWay); + nameof(TitleFontSize), typeof(double), typeof(BaseCell), 14.0, defaultBindingMode: BindingMode.OneWay); public static BindableProperty Button1IconProperty = BindableProperty.Create( nameof(Button1Icon), typeof(string), typeof(BaseCell), default(string), diff --git a/src/App/Controls/BoxedView/Cells/EntryCell.cs b/src/App/Controls/BoxedView/Cells/EntryCell.cs index 5bcf14d86..a1d018823 100644 --- a/src/App/Controls/BoxedView/Cells/EntryCell.cs +++ b/src/App/Controls/BoxedView/Cells/EntryCell.cs @@ -11,11 +11,11 @@ namespace Bit.App.Controls.BoxedView // propertyChanging: ValueTextPropertyChanging); public static BindableProperty ValueTextColorProperty = BindableProperty.Create( - nameof(ValueTextColor), typeof(Color), typeof(EntryCell), default(Color), + nameof(ValueTextColor), typeof(Color), typeof(EntryCell), Color.Black, defaultBindingMode: BindingMode.OneWay); public static BindableProperty ValueTextFontSizeProperty = BindableProperty.Create( - nameof(ValueTextFontSize), typeof(double), typeof(EntryCell), -1.0, + nameof(ValueTextFontSize), typeof(double), typeof(EntryCell), 18.0, defaultBindingMode: BindingMode.OneWay); public static BindableProperty KeyboardProperty = BindableProperty.Create( diff --git a/src/App/Controls/BoxedView/Cells/LabelCell.cs b/src/App/Controls/BoxedView/Cells/LabelCell.cs index 5c37204aa..af0462976 100644 --- a/src/App/Controls/BoxedView/Cells/LabelCell.cs +++ b/src/App/Controls/BoxedView/Cells/LabelCell.cs @@ -9,11 +9,11 @@ namespace Bit.App.Controls.BoxedView defaultBindingMode: BindingMode.OneWay); public static BindableProperty ValueTextColorProperty = BindableProperty.Create( - nameof(ValueTextColor), typeof(Color), typeof(LabelCell), default(Color), + nameof(ValueTextColor), typeof(Color), typeof(LabelCell), Color.Black, defaultBindingMode: BindingMode.OneWay); public static BindableProperty ValueTextFontSizeProperty = BindableProperty.Create( - nameof(ValueTextFontSize), typeof(double), typeof(LabelCell), -1.0, + nameof(ValueTextFontSize), typeof(double), typeof(LabelCell), 18.0, defaultBindingMode: BindingMode.OneWay); public string ValueText