diff --git a/src/Kp2aBusinessLogic/UiStringKey.cs b/src/Kp2aBusinessLogic/UiStringKey.cs index fffcf70b..92cd9f37 100644 --- a/src/Kp2aBusinessLogic/UiStringKey.cs +++ b/src/Kp2aBusinessLogic/UiStringKey.cs @@ -9,8 +9,10 @@ namespace keepass2android public enum UiStringKey { AskDeletePermanentlyGroup, + AskDeletePermanentlyGroupNoRecycle, progress_title, AskDeletePermanentlyEntry, + AskDeletePermanentlyEntryNoRecycle, search_results, AskDeletePermanently_title, saving_database, @@ -58,6 +60,7 @@ namespace keepass2android DuplicateUuidsError, DuplicateUuidsErrorAdditional, DeletingItems, - AskDeletePermanentlyItems + AskDeletePermanentlyItems, + AskDeletePermanentlyItemsNoRecycle } } diff --git a/src/Kp2aBusinessLogic/database/edit/DeleteEntry.cs b/src/Kp2aBusinessLogic/database/edit/DeleteEntry.cs index 4280697c..533d56cd 100644 --- a/src/Kp2aBusinessLogic/database/edit/DeleteEntry.cs +++ b/src/Kp2aBusinessLogic/database/edit/DeleteEntry.cs @@ -43,7 +43,7 @@ namespace keepass2android } } - protected override UiStringKey QuestionsResourceId + protected override UiStringKey QuestionRecycleResourceId { get { @@ -51,6 +51,14 @@ namespace keepass2android } } + protected override UiStringKey QuestionNoRecycleResourceId + { + get + { + return UiStringKey.AskDeletePermanentlyEntryNoRecycle; + } + } + protected override void PerformDelete(List touchedGroups, List permanentlyDeletedGroups) { DoDeleteEntry(_entry, touchedGroups); diff --git a/src/Kp2aBusinessLogic/database/edit/DeleteGroup.cs b/src/Kp2aBusinessLogic/database/edit/DeleteGroup.cs index 61b1d10a..7a764953 100644 --- a/src/Kp2aBusinessLogic/database/edit/DeleteGroup.cs +++ b/src/Kp2aBusinessLogic/database/edit/DeleteGroup.cs @@ -61,14 +61,19 @@ namespace keepass2android } } - protected override UiStringKey QuestionsResourceId + protected override UiStringKey QuestionRecycleResourceId { get { return UiStringKey.AskDeletePermanentlyGroup; } } - + + protected override UiStringKey QuestionNoRecycleResourceId + { + get { return UiStringKey.AskDeletePermanentlyGroupNoRecycle; } + } + protected override void PerformDelete(List touchedGroups, List permanentlyDeletedGroups) { DoDeleteGroup(_group, touchedGroups, permanentlyDeletedGroups); diff --git a/src/Kp2aBusinessLogic/database/edit/DeleteMultipleItems.cs b/src/Kp2aBusinessLogic/database/edit/DeleteMultipleItems.cs index d70c4a2d..620ab150 100644 --- a/src/Kp2aBusinessLogic/database/edit/DeleteMultipleItems.cs +++ b/src/Kp2aBusinessLogic/database/edit/DeleteMultipleItems.cs @@ -50,11 +50,16 @@ namespace keepass2android get { return _canRecycle; } } - protected override UiStringKey QuestionsResourceId + protected override UiStringKey QuestionRecycleResourceId { get { return UiStringKey.AskDeletePermanentlyItems; } } + protected override UiStringKey QuestionNoRecycleResourceId + { + get { return UiStringKey.AskDeletePermanentlyItemsNoRecycle; } + } + protected override void PerformDelete(List touchedGroups, List permanentlyDeletedGroups) { foreach (var g in _elementsToDelete.OfType()) diff --git a/src/Kp2aBusinessLogic/database/edit/DeleteRunnable.cs b/src/Kp2aBusinessLogic/database/edit/DeleteRunnable.cs index e8fa4147..48c53cc8 100644 --- a/src/Kp2aBusinessLogic/database/edit/DeleteRunnable.cs +++ b/src/Kp2aBusinessLogic/database/edit/DeleteRunnable.cs @@ -107,17 +107,23 @@ namespace keepass2android else { System.Diagnostics.Debug.Assert(pgRecycleBin.Uuid.Equals(Db.KpDatabase.RecycleBinUuid)); } } - protected abstract UiStringKey QuestionsResourceId + protected abstract UiStringKey QuestionRecycleResourceId { get; } + protected abstract UiStringKey QuestionNoRecycleResourceId + { + get; + } + + public void Start() { if (CanRecycle) { App.AskYesNoCancel(UiStringKey.AskDeletePermanently_title, - QuestionsResourceId, + QuestionRecycleResourceId, (dlgSender, dlgEvt) => { DeletePermanently = true; @@ -138,11 +144,22 @@ namespace keepass2android } else { - ProgressTask pt = new ProgressTask(App, Ctx, this); - pt.Run(); + App.AskYesNoCancel(UiStringKey.AskDeletePermanently_title, + QuestionNoRecycleResourceId, + (dlgSender, dlgEvt) => + { + ProgressTask pt = new ProgressTask(App, Ctx, this); + pt.Run(); + }, + null, + (dlgSender, dlgEvt) => { }, + Ctx); + + } } + protected void DoDeleteEntry(PwEntry pe, List touchedGroups) { PwDatabase pd = Db.KpDatabase; diff --git a/src/keepass2android/GeneratePasswordActivity.cs b/src/keepass2android/GeneratePasswordActivity.cs index 66a83562..52cac8e0 100644 --- a/src/keepass2android/GeneratePasswordActivity.cs +++ b/src/keepass2android/GeneratePasswordActivity.cs @@ -29,7 +29,13 @@ namespace keepass2android [Activity(Label = "@string/app_name", Theme = "@style/MyTheme_ActionBar", WindowSoftInputMode = SoftInput.StateHidden)] public class GeneratePasswordActivity : LockCloseActivity { private readonly int[] _buttonIds = new[] {Resource.Id.btn_length6, Resource.Id.btn_length8, Resource.Id.btn_length12, Resource.Id.btn_length16}; - + + private ActivityDesign _design; + public GeneratePasswordActivity() + { + _design = new ActivityDesign(this); + } + public static void Launch(Activity act) { Intent i = new Intent(act, typeof(GeneratePasswordActivity)); @@ -48,6 +54,7 @@ namespace keepass2android protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); + _design.ApplyTheme(); SetContentView(Resource.Layout.generate_password); SetResult(KeePass.ExitNormal); diff --git a/src/keepass2android/IconPickerActivity.cs b/src/keepass2android/IconPickerActivity.cs index 6d9635b6..fceab804 100644 --- a/src/keepass2android/IconPickerActivity.cs +++ b/src/keepass2android/IconPickerActivity.cs @@ -20,6 +20,7 @@ using System.IO; using Android.App; using Android.Content; using Android.Graphics; +using Android.Graphics.Drawables; using Android.OS; using Android.Preferences; using Android.Views; @@ -178,6 +179,32 @@ namespace keepass2android { return 0; } + + + +public static Bitmap DrawableToBitmap (Drawable drawable) { + Bitmap bitmap = null; + + if (drawable is BitmapDrawable) { + BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; + if(bitmapDrawable.Bitmap != null) { + return bitmapDrawable.Bitmap; + } + } + + if(drawable.IntrinsicWidth <= 0 || drawable.IntrinsicHeight <= 0) { + bitmap = Bitmap.CreateBitmap(1, 1, Bitmap.Config.Argb8888); // Single color bitmap will be created of 1x1 pixel + } else { + bitmap = Bitmap.CreateBitmap(drawable.IntrinsicWidth, drawable.IntrinsicHeight, Bitmap.Config.Argb8888); + } + + Canvas canvas = new Canvas(bitmap); + drawable.SetBounds(0, 0, canvas.Width, canvas.Height); + drawable.Draw(canvas); + return bitmap; +} + + public override View GetView(int position, View convertView, ViewGroup parent) { @@ -197,8 +224,11 @@ namespace keepass2android if (position < (int)PwIcon.Count) { tv.Text = "" + position; - App.Kp2a.GetDb() - .DrawableFactory.AssignDrawableTo(iv, _act, App.Kp2a.GetDb().KpDatabase, (KeePassLib.PwIcon) position, null, false); + var drawable = App.Kp2a.GetDb() + .DrawableFactory.GetIconDrawable(_act, App.Kp2a.GetDb().KpDatabase, (KeePassLib.PwIcon) position, null, false); + drawable = new BitmapDrawable(DrawableToBitmap(drawable)); + iv.SetImageDrawable(drawable); + //App.Kp2a.GetDb().DrawableFactory.AssignDrawableTo(iv, _act, App.Kp2a.GetDb().KpDatabase, (KeePassLib.PwIcon) position, null, false); if ( PreferenceManager.GetDefaultSharedPreferences(currView.Context) @@ -206,7 +236,6 @@ namespace keepass2android { Android.Graphics.PorterDuff.Mode mMode = Android.Graphics.PorterDuff.Mode.SrcAtop; Color color = new Color(189, 189, 189); - iv.SetImageDrawable(iv.Drawable.Mutate()); iv.SetColorFilter(color, mMode); } diff --git a/src/keepass2android/PasswordActivity.cs b/src/keepass2android/PasswordActivity.cs index a941fa7a..cbd6efbc 100644 --- a/src/keepass2android/PasswordActivity.cs +++ b/src/keepass2android/PasswordActivity.cs @@ -159,13 +159,13 @@ namespace keepass2android public PasswordActivity (IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) - { - - } + { + _activityDesign = new ActivityDesign(this); + } public PasswordActivity() { - + _activityDesign = new ActivityDesign(this); } @@ -686,6 +686,8 @@ namespace keepass2android private string mDrawerTitle; private MeasuringRelativeLayout.MeasureArgs _measureArgs; + private ActivityDesign _activityDesign; + internal class MyActionBarDrawerToggle : ActionBarDrawerToggle { PasswordActivity owner; @@ -739,7 +741,7 @@ namespace keepass2android protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); - + _activityDesign.ApplyTheme(); //use FlagSecure to make sure the last (revealed) character of the master password is not visible in recent apps if (PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean( @@ -1572,6 +1574,7 @@ namespace keepass2android protected override void OnResume() { base.OnResume(); + _activityDesign.ReapplyTheme(); EditText pwd = FindViewById(Resource.Id.password_edit); pwd.PostDelayed(() => diff --git a/src/keepass2android/Resources/drawable/splash_button_bg.xml b/src/keepass2android/Resources/drawable/splash_button_bg.xml index e97dc9ca..83857ced 100644 --- a/src/keepass2android/Resources/drawable/splash_button_bg.xml +++ b/src/keepass2android/Resources/drawable/splash_button_bg.xml @@ -9,13 +9,13 @@ - + - + \ No newline at end of file diff --git a/src/keepass2android/Resources/drawable/storagetype_grid_bg.xml b/src/keepass2android/Resources/drawable/storagetype_grid_bg.xml index f43a6774..8896a489 100644 --- a/src/keepass2android/Resources/drawable/storagetype_grid_bg.xml +++ b/src/keepass2android/Resources/drawable/storagetype_grid_bg.xml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/src/keepass2android/Resources/layout/entry_edit.xml b/src/keepass2android/Resources/layout/entry_edit.xml index d95bb979..d7fb35c9 100644 --- a/src/keepass2android/Resources/layout/entry_edit.xml +++ b/src/keepass2android/Resources/layout/entry_edit.xml @@ -1,7 +1,7 @@ + style="@style/EntryEditSingleLine_TextInputLayout" + android:layout_toLeftOf="@id/icon_button"> + android:background="?activityBackgroundColor"> diff --git a/src/keepass2android/Resources/layout/icon_picker.xml b/src/keepass2android/Resources/layout/icon_picker.xml index fbe37174..6f2e3129 100644 --- a/src/keepass2android/Resources/layout/icon_picker.xml +++ b/src/keepass2android/Resources/layout/icon_picker.xml @@ -21,8 +21,8 @@ android:id="@+id/IconGridView" android:layout_width="fill_parent" android:layout_height="fill_parent" - android:background="@android:color/background_light" android:verticalSpacing="5dp" + android:background="?activityBackgroundColor" android:horizontalSpacing="5dp" android:columnWidth="60dp" android:numColumns="auto_fit" diff --git a/src/keepass2android/Resources/layout/password.xml b/src/keepass2android/Resources/layout/password.xml index e33ab160..3f63dfa0 100644 --- a/src/keepass2android/Resources/layout/password.xml +++ b/src/keepass2android/Resources/layout/password.xml @@ -10,7 +10,7 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/relative_layout" - android:background="#ffffffff"> + android:background="?activityBackgroundColor"> + android:background="?activityBackgroundColor"> + android:background="?activityBackgroundColor"> @color/appAccentColor + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + - diff --git a/src/keepass2android/Resources/xml/preferences.xml b/src/keepass2android/Resources/xml/preferences.xml index 079fee5d..58294482 100644 --- a/src/keepass2android/Resources/xml/preferences.xml +++ b/src/keepass2android/Resources/xml/preferences.xml @@ -196,7 +196,16 @@ android:persistent="false" android:key="IconSetKey"/> - + + + x is Android.App.ActivityAttribute + ).Cast().First(); + _attributeTheme = activityAttr.Theme; + } + catch (Exception e) + { + Kp2aLog.Log(e.ToString()); + } + } public void ApplyTheme() { - /*if (HasThemes()) + if (HasThemes()) { var dark = UseDarkTheme; - //int newTheme = dark ? Resource.Style.ThemeDark : Resource.Style.ThemeLight; - int newTheme = Resource.Style.ThemeMaterial; + int newTheme = dark ? DarkTheme : LightTheme; _activity.SetTheme(newTheme); _currentThemeId = newTheme; - }*/ + } _currentIconSet = PreferenceManager.GetDefaultSharedPreferences(_activity) .GetString("IconSetKey", _activity.PackageName); } + public int DarkTheme + { + get + { + if (string.IsNullOrEmpty(_attributeTheme)) + return Resource.Style.MyTheme_Dark; + if (_attributeTheme.Contains("MyTheme_Blue")) + return Resource.Style.MyTheme_Blue_Dark; + if (_attributeTheme.Contains("MyTheme_ActionBar")) + return Resource.Style.MyTheme_ActionBar_Dark; + return Resource.Style.MyTheme_Dark; + } + + } + + public int LightTheme + { + get + { + if (string.IsNullOrEmpty(_attributeTheme)) + return Resource.Style.MyTheme; + if (_attributeTheme.Contains("MyTheme_Blue")) + return Resource.Style.MyTheme_Blue; + if (_attributeTheme.Contains("MyTheme_ActionBar")) + return Resource.Style.MyTheme_ActionBar; + return Resource.Style.MyTheme; + } + + } + public void ReapplyTheme() { - /*if (HasThemes()) + if (HasThemes()) { - //int newTheme = UseDarkTheme ? Resource.Style.ThemeDark : Resource.Style.ThemeLight; - int newTheme = Resource.Style.ThemeMaterial; + int newTheme = UseDarkTheme ? DarkTheme : LightTheme; if (newTheme != _currentThemeId) { Kp2aLog.Log("recreating due to theme change."); @@ -43,7 +87,7 @@ namespace keepass2android return; } } - */ + if (PreferenceManager.GetDefaultSharedPreferences(_activity) .GetString("IconSetKey", _activity.PackageName) != _currentIconSet) { @@ -69,7 +113,7 @@ namespace keepass2android if (HasThemes()) { bool dark = UseDarkTheme; - //_activity.SetTheme(dark ? Resource.Style.DialogDark : Resource.Style.DialogLight); + _activity.SetTheme(dark ? Resource.Style.Base_Dialog : Resource.Style.Base_Dialog_Dark); } } diff --git a/src/keepass2android/app/App.cs b/src/keepass2android/app/App.cs index 7e60b10c..545bae1d 100644 --- a/src/keepass2android/app/App.cs +++ b/src/keepass2android/app/App.cs @@ -337,8 +337,8 @@ namespace keepass2android builder.SetMessage(GetResourceString(messageKey)); builder.SetPositiveButton(GetResourceString(yesString), yesHandler); - - builder.SetNegativeButton(GetResourceString(noString), noHandler); + if (noHandler != null) + builder.SetNegativeButton(GetResourceString(noString), noHandler); if (cancelHandler != null) { diff --git a/src/keepass2android/icons/DrawableFactory.cs b/src/keepass2android/icons/DrawableFactory.cs index d46fcca3..00abf73e 100644 --- a/src/keepass2android/icons/DrawableFactory.cs +++ b/src/keepass2android/icons/DrawableFactory.cs @@ -48,12 +48,16 @@ private static Drawable _blank; * Keys: Integer, Values: Drawables */ private readonly Dictionary _standardIconMap = new Dictionary(); - - public void AssignDrawableTo (ImageView iv, Context context, PwDatabase db, PwIcon icon, PwUuid customIconId, bool forGroup) + + public void AssignDrawableTo(ImageView iv, Context context, PwDatabase db, PwIcon icon, PwUuid customIconId, bool forGroup) { Drawable draw = GetIconDrawable (context, db, icon, customIconId, forGroup); if (draw != null) + { + draw = draw.Mutate(); iv.SetImageDrawable(draw); + } + else Kp2aLog.Log("icon not found : " + icon); } @@ -172,6 +176,7 @@ private static Drawable _blank; _customIconMap.Clear (); } + } } diff --git a/src/keepass2android/settings/AppSettingsActivity.cs b/src/keepass2android/settings/AppSettingsActivity.cs index 6899203c..bf136b0c 100644 --- a/src/keepass2android/settings/AppSettingsActivity.cs +++ b/src/keepass2android/settings/AppSettingsActivity.cs @@ -104,8 +104,10 @@ namespace keepass2android protected override void OnCreate(Bundle savedInstanceState) { + _design.ApplyTheme(); base.OnCreate(savedInstanceState); + SetContentView(Resource.Layout.preference); SetSupportActionBar(FindViewById(Resource.Id.mytoolbar)); diff --git a/src/keepass2android/settings/DatabaseSettingsActivity.cs b/src/keepass2android/settings/DatabaseSettingsActivity.cs index 83d8b32a..4171ff53 100644 --- a/src/keepass2android/settings/DatabaseSettingsActivity.cs +++ b/src/keepass2android/settings/DatabaseSettingsActivity.cs @@ -337,6 +337,8 @@ namespace keepass2android FindPreference(GetString(Resource.String.keyfile_key)).PreferenceChange += OnRememberKeyFileHistoryChanged; FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += OnShowUnlockedNotificationChanged; PrepareNoDonatePreference(Activity, FindPreference(GetString(Resource.String.NoDonateOption_key))); + + FindPreference(GetString(Resource.String.design_key)).PreferenceChange += (sender, args) => Activity.Recreate(); Database db = App.Kp2a.GetDb(); if (db.Loaded)