Skip to content

Commit

Permalink
changes to implement material design/fix flaws and issues in the majo…
Browse files Browse the repository at this point in the history
…r activities. More testing pending.
  • Loading branch information
PhilippC committed Dec 10, 2024
1 parent ed9cd71 commit e14cd62
Show file tree
Hide file tree
Showing 22 changed files with 245 additions and 174 deletions.
6 changes: 2 additions & 4 deletions src/keepass2android-appSdkStyle/CreateDatabaseActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,13 @@ protected override void OnCreate(Bundle bundle)
CreateDatabase(Intent.GetBooleanExtra("MakeCurrent",true));
};

ImageButton btnTogglePassword = (ImageButton)FindViewById(Resource.Id.toggle_password);
Button btnTogglePassword = (Button)FindViewById(Resource.Id.toggle_password);
btnTogglePassword.Click += (sender, e) =>
{
_showPassword = !_showPassword;
MakePasswordMaskedOrVisible();
};
Android.Graphics.PorterDuff.Mode mMode = Android.Graphics.PorterDuff.Mode.SrcAtop;
Android.Graphics.Color color = new Android.Graphics.Color (224, 224, 224);
btnTogglePassword.SetColorFilter (color, mMode);


Util.SetNoPersonalizedLearning(FindViewById(Resource.Id.root));

Expand Down
9 changes: 6 additions & 3 deletions src/keepass2android-appSdkStyle/EntryActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,10 +1211,13 @@ private void PopulateGroupText(int viewId, int containerViewId, String key)
if (PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean(
"ShowGroupInEntry", false))
{
groupName = Entry.ParentGroup.GetFullPath();
groupName = Entry.ParentGroup?.GetFullPath();
}
PopulateText(viewId, containerViewId, groupName);
_stringViews.Add (key, new StandardStringView (new List<int>{viewId}, containerViewId, this));

PopulateText(viewId, containerViewId, groupName);
_stringViews.Add(key, new StandardStringView(new List<int> { viewId }, containerViewId, this));


}

private void RequiresRefresh()
Expand Down
61 changes: 15 additions & 46 deletions src/keepass2android-appSdkStyle/EntryEditActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ You should have received a copy of the GNU General Public License
using Object = Java.Lang.Object;
using Uri = Android.Net.Uri;
using Resource = keepass2android_appSdkStyle.Resource;
using Google.Android.Material.TextField;

namespace keepass2android
{
Expand Down Expand Up @@ -260,16 +261,6 @@ protected override void OnCreate(Bundle savedInstanceState)
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
SupportActionBar.SetHomeButtonEnabled(true);

// Respect mask password setting
MakePasswordVisibleOrHidden();

Button btnTogglePassword = (Button)FindViewById(Resource.Id.toggle_password);
btnTogglePassword.Click += (sender, e) =>
{
State.ShowPassword = !State.ShowPassword;
MakePasswordVisibleOrHidden();
};


Button addButton = (Button) FindViewById(Resource.Id.add_advanced);
addButton.Visibility = ViewStates.Visible;
Expand Down Expand Up @@ -437,24 +428,7 @@ private bool CanConfigureOtpSettings()
;
}

private void MakePasswordVisibleOrHidden()
{
EditText password = (EditText) FindViewById(Resource.Id.entry_password);
TextView confpassword = (TextView) FindViewById(Resource.Id.entry_confpassword);
int selStart = password.SelectionStart, selEnd = password.SelectionEnd;
if (State.ShowPassword)
{
password.InputType = InputTypes.ClassText | InputTypes.TextVariationVisiblePassword;
_passwordFont.ApplyTo(password);
confpassword.Visibility = ViewStates.Gone;
}
else
{
password.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword;
confpassword.Visibility = ViewStates.Visible;
}
password.SetSelection(selStart, selEnd);
}


void SaveEntry()
{
Expand Down Expand Up @@ -1092,11 +1066,12 @@ RelativeLayout CreateExtraStringView(KeyValuePair<string, ProtectedString> pair,
RelativeLayout ees = (RelativeLayout)LayoutInflater.Inflate(Resource.Layout.entry_edit_section, null);
ees.Tag = pair.Key;
var keyView = ((TextView)ees.FindViewById(Resource.Id.extrakey));
var titleView = ((TextView)ees.FindViewById(Resource.Id.title));

keyView.Text = pair.Key;
titleView.Text = title;

((TextView)ees.FindViewById(Resource.Id.value)).Text = pair.Value.ReadString();
((TextView)ees.FindViewById(Resource.Id.value)).TextChanged += (sender, e) => State.EntryModified = true;
((TextInputLayout)ees.FindViewById(Resource.Id.value_container)).Hint = pair.Key;
((TextView)ees.FindViewById(Resource.Id.value)).TextChanged += (sender, e) => State.EntryModified = true;
_passwordFont.ApplyTo(((TextView)ees.FindViewById(Resource.Id.value)));
((CheckBox)ees.FindViewById(Resource.Id.protection)).Checked = pair.Value.IsProtected;

Expand Down Expand Up @@ -1346,10 +1321,15 @@ private void EditAdvancedString(View sender)
builder.SetPositiveButton(Android.Resource.String.Ok, (o, args) =>
{
CopyFieldFromExtraDialog(sender, o, Resource.Id.title, Resource.Id.extrakey);
CopyFieldFromExtraDialog(sender, o, Resource.Id.title, Resource.Id.title);
CopyFieldFromExtraDialog(sender, o, Resource.Id.value, Resource.Id.value);

CopyCheckboxFromExtraDialog(sender, o, Resource.Id.protection);
});
var sourceFieldTitle = (EditText)((Dialog)o).FindViewById(Resource.Id.title);
var sourceFieldValue = (EditText)((Dialog)o).FindViewById(Resource.Id.value);
var targetField = ((TextView)((View)sender.Parent).FindViewById(Resource.Id.value));
var targetFieldContainer = ((TextInputLayout)((View)sender.Parent).FindViewById(Resource.Id.value_container));
targetField.Text = sourceFieldValue.Text;
targetFieldContainer.Hint = sourceFieldTitle.Text;
});
Dialog dialog = builder.Create();

//setup delete button:
Expand Down Expand Up @@ -1410,7 +1390,7 @@ private void FillData()

String password = State.Entry.Strings.ReadSafe(PwDefs.PasswordField);
PopulateText(Resource.Id.entry_password, password);
PopulateText(Resource.Id.entry_confpassword, password);


_passwordFont.ApplyTo(FindViewById<EditText>(Resource.Id.entry_password));

Expand Down Expand Up @@ -1510,17 +1490,6 @@ protected bool ValidateBeforeSaving() {
return false;
}

if (!State.ShowPassword)
{
// Validate password
String pass = Util.GetEditText(this, Resource.Id.entry_password);
String conf = Util.GetEditText(this, Resource.Id.entry_confpassword);
if (!pass.Equals(conf))
{
Toast.MakeText(this, Resource.String.error_pass_match, ToastLength.Long).Show();
return false;
}
}


// Validate expiry date
Expand Down
65 changes: 41 additions & 24 deletions src/keepass2android-appSdkStyle/GeneratePasswordActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ protected override void OnCreate(Bundle savedInstanceState) {

SetContentView(Resource.Layout.generate_password);
SetResult(KeePass.ExitNormal);


var prefs = GetPreferences(FileCreationMode.Private);

Expand Down Expand Up @@ -195,6 +196,7 @@ protected override void OnCreate(Bundle savedInstanceState) {
_updateDisabled = true;
PopulateFieldsFromOptions(_profiles.LastUsedSettings);
_updateDisabled = false;


var profileSpinner = UpdateProfileSpinner();

Expand Down Expand Up @@ -462,36 +464,51 @@ private void UpdatePassword()
{
if (_updateDisabled)
return;
String password = GeneratePassword();

EditText txtPassword = (EditText) FindViewById(Resource.Id.password_edit);
txtPassword.Text = password;
String password = "";
uint passwordBits = 0;

Task.Run(() =>
{
password = GeneratePassword();
passwordBits = QualityEstimation.EstimatePasswordBits(password.ToCharArray());
RunOnUiThread(() =>
{
EditText txtPassword = (EditText)FindViewById(Resource.Id.password_edit);
txtPassword.Text = password;

var progressBar = FindViewById<ProgressBar>(Resource.Id.pb_password_strength);
var passwordBits = QualityEstimation.EstimatePasswordBits(password.ToCharArray());
progressBar.Progress = (int)passwordBits;
progressBar.Max = 128;
var progressBar = FindViewById<ProgressBar>(Resource.Id.pb_password_strength);

Color color = new Color(196, 63, 49);
if (passwordBits > 40)
{
color = new Color(219, 152, 55);
}
if (passwordBits > 64)
{
color = new Color(96, 138, 38);
}
if (passwordBits > 100)
{
color = new Color(31, 128, 31);
}
progressBar.ProgressDrawable.SetColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SrcIn));
progressBar.Progress = (int)passwordBits;
progressBar.Max = 128;

FindViewById<TextView>(Resource.Id.tv_password_strength).Text = " " + passwordBits + " bits";
Color color = new Color(196, 63, 49);
if (passwordBits > 40)
{
color = new Color(219, 152, 55);
}


if (passwordBits > 64)
{
color = new Color(96, 138, 38);
}

UpdateProfileSpinnerSelection();
if (passwordBits > 100)
{
color = new Color(31, 128, 31);
}

progressBar.ProgressDrawable.SetColorFilter(new PorterDuffColorFilter(color,
PorterDuff.Mode.SrcIn));

FindViewById<TextView>(Resource.Id.tv_password_strength).Text = " " + passwordBits + " bits";



UpdateProfileSpinnerSelection();
});
});

}

private void UpdateProfileSpinnerSelection()
Expand Down
2 changes: 1 addition & 1 deletion src/keepass2android-appSdkStyle/GroupEditActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ You should have received a copy of the GNU General Public License

namespace keepass2android
{
[Activity(Label = "@string/app_name")]
[Activity(Label = "@string/app_name", Theme= "@style/Kp2aTheme_Dialog")]
public class GroupEditActivity : LifecycleAwareActivity
{
public const String KeyParent = "parent";
Expand Down
2 changes: 1 addition & 1 deletion src/keepass2android-appSdkStyle/PasswordActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ protected override void OnCreate(Bundle savedInstanceState)
mDrawerTitle = Title;


var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn);
var btn = FindViewById(Resource.Id.fingerprintbtn);
btn.Click += (sender, args) =>
{
if (!string.IsNullOrEmpty((string)btn.Tag))
Expand Down
17 changes: 17 additions & 0 deletions src/keepass2android-appSdkStyle/Resources/drawable/add_key.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:name="path"
android:pathData="M 10.713 9.311 C 10.059 7.451 8.286 6.118 6.203 6.118 C 3.561 6.118 1.413 8.265 1.413 10.908 C 1.413 13.55 3.561 15.697 6.203 15.697 C 8.286 15.697 10.059 14.364 10.713 12.504 L 14.186 12.504 L 14.186 15.697 C 14.473 15.697 14.039 15.702 14.778 15.702 C 15.441 13.968 16.983 12.833 18.897 12.854 L 19.005 12.859 L 18.975 9.311 Z M 6.203 12.504 C 5.325 12.504 4.606 11.786 4.606 10.908 C 4.606 10.03 5.325 9.311 6.203 9.311 C 7.081 9.311 7.8 10.03 7.8 10.908 C 7.8 11.786 7.081 12.504 6.203 12.504 Z"
android:fillColor="?attr/colorControlNormal"
android:strokeWidth="1"/>
<path
android:name="path_1"
android:pathData="M 19.161 15.207 L 18.389 15.207 L 18.389 16.751 L 16.845 16.751 L 16.845 17.523 L 18.389 17.523 L 18.389 19.066 L 19.161 19.066 L 19.161 17.523 L 20.705 17.523 L 20.705 16.751 L 19.161 16.751 Z M 18.775 13.277 C 16.644 13.277 14.915 15.006 14.915 17.137 C 14.915 19.267 16.644 20.996 18.775 20.996 C 20.906 20.996 22.635 19.267 22.635 17.137 C 22.635 15.006 20.906 13.277 18.775 13.277 Z M 18.775 20.224 C 17.073 20.224 15.687 18.839 15.687 17.137 C 15.687 15.434 17.073 14.049 18.775 14.049 C 20.477 14.049 21.863 15.434 21.863 17.137 C 21.863 18.839 20.477 20.224 18.775 20.224 Z"
android:fillColor="?attr/colorControlNormal"
android:strokeWidth="1"/>
</vector>
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/EditEntryButton"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="-4dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/baseline_add_circle_outline_24" />
style="?attr/materialButtonOutlinedStyle"
app:icon="@drawable/baseline_add_circle_outline_24"
/>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/EditEntryButton"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="-4dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/baseline_delete_24" />
style="?attr/materialButtonOutlinedStyle"
app:icon="@drawable/baseline_delete_24" />
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:padding="12dp"
android:layout_height="wrap_content">

<EditText
Expand Down Expand Up @@ -64,7 +66,9 @@
android:id="@+id/totp_length" />

<Button
android:drawableLeft="@drawable/baseline_camera_alt_24"
style="?attr/materialButtonOutlinedStyle"
app:icon="@drawable/baseline_camera_alt_24"

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/totp_scan"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,23 @@ android:layout_height="wrap_content">

<Button
android:id="@+id/generate_button"
style="?attr/materialIconButtonFilledStyle"
app:icon="@drawable/add_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/ellipsis" />
<ImageButton
android:id="@+id/toggle_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/baseline_visibility_24"
android:layout_alignTop="@id/generate_button"
android:layout_toLeftOf="@id/generate_button"
/>
/>

<Button
android:id="@+id/toggle_password"
style="?attr/materialIconButtonFilledStyle"
app:icon="@drawable/baseline_visibility_24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/generate_button"
android:layout_toLeftOf="@id/generate_button"
/>

<EditText
android:id="@+id/entry_password"
style="@style/TextAppearance_EditEntry_Value"
Expand Down
Loading

0 comments on commit e14cd62

Please sign in to comment.