2013-02-23 11:43:42 -05:00
|
|
|
/*
|
|
|
|
This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file is based on Keepassdroid, Copyright Brian Pellin.
|
|
|
|
|
|
|
|
Keepass2Android is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2014-01-26 08:27:27 -05:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
2013-02-23 11:43:42 -05:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Keepass2Android is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
2013-06-20 03:19:07 -04:00
|
|
|
using System.Linq;
|
2014-05-10 00:18:11 -04:00
|
|
|
using System.Threading;
|
2013-02-23 11:43:42 -05:00
|
|
|
using Android.App;
|
|
|
|
using Android.Content;
|
|
|
|
using Android.OS;
|
2014-05-10 00:18:11 -04:00
|
|
|
using Android.Runtime;
|
|
|
|
using Android.Text;
|
2013-02-23 11:43:42 -05:00
|
|
|
using Android.Views;
|
|
|
|
using Android.Widget;
|
|
|
|
using Android.Preferences;
|
|
|
|
using Android.Text.Method;
|
|
|
|
using System.Globalization;
|
|
|
|
using Android.Content.PM;
|
|
|
|
using Android.Webkit;
|
2013-04-26 04:10:46 -04:00
|
|
|
using Android.Graphics;
|
2013-04-28 16:46:31 -04:00
|
|
|
using Java.IO;
|
2014-05-10 00:18:11 -04:00
|
|
|
using KeePassLib;
|
|
|
|
using KeePassLib.Security;
|
2014-05-11 01:52:38 -04:00
|
|
|
using KeePassLib.Utility;
|
2014-05-10 00:18:11 -04:00
|
|
|
using Keepass2android.Pluginsdk;
|
2014-05-11 01:52:38 -04:00
|
|
|
using keepass2android.Io;
|
2014-05-10 00:18:11 -04:00
|
|
|
using Uri = Android.Net.Uri;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
namespace keepass2android
|
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
[Activity (Label = "@string/app_name", ConfigurationChanges=ConfigChanges.Orientation|ConfigChanges.KeyboardHidden, Theme="@style/NoTitleBar")]
|
|
|
|
public class EntryActivity : LockCloseActivity
|
2014-05-10 00:18:11 -04:00
|
|
|
{
|
2013-06-15 06:40:01 -04:00
|
|
|
public const String KeyEntry = "entry";
|
|
|
|
public const String KeyRefreshPos = "refresh_pos";
|
|
|
|
public const String KeyCloseAfterCreate = "close_after_create";
|
2014-05-26 06:09:41 -04:00
|
|
|
public const String KeyGroupFullPath = "groupfullpath_key";
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-16 11:15:43 -04:00
|
|
|
public static void Launch(Activity act, PwEntry pw, int pos, AppTask appTask, ActivityFlags? flags = null)
|
2014-05-11 01:52:38 -04:00
|
|
|
{
|
|
|
|
Intent i = new Intent(act, typeof(EntryActivity));
|
|
|
|
|
|
|
|
i.PutExtra(KeyEntry, pw.Uuid.ToHexString());
|
|
|
|
i.PutExtra(KeyRefreshPos, pos);
|
|
|
|
|
2014-05-16 11:15:43 -04:00
|
|
|
if (flags != null)
|
|
|
|
i.SetFlags((ActivityFlags) flags);
|
2014-05-11 01:52:38 -04:00
|
|
|
|
2014-05-16 11:15:43 -04:00
|
|
|
appTask.ToIntent(i);
|
|
|
|
if (flags != null && (((ActivityFlags) flags) | ActivityFlags.ForwardResult) == ActivityFlags.ForwardResult)
|
|
|
|
act.StartActivity(i);
|
|
|
|
else
|
|
|
|
act.StartActivityForResult(i, 0);
|
2014-05-11 01:52:38 -04:00
|
|
|
}
|
|
|
|
|
2014-05-11 07:21:28 -04:00
|
|
|
public EntryActivity (IntPtr javaReference, JniHandleOwnership transfer)
|
|
|
|
: base(javaReference, transfer)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-05-11 01:52:38 -04:00
|
|
|
|
2014-05-11 07:21:28 -04:00
|
|
|
public EntryActivity()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-05-11 01:52:38 -04:00
|
|
|
|
|
|
|
protected PwEntry Entry;
|
2013-05-30 00:54:25 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private static Typeface _passwordFont;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
internal bool _showPassword;
|
2013-06-15 06:40:01 -04:00
|
|
|
private int _pos;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
AppTask _appTask;
|
2013-07-12 08:17:20 -04:00
|
|
|
private List<TextView> _protectedTextViews;
|
2014-05-11 01:52:38 -04:00
|
|
|
private IMenu _menu;
|
2013-07-12 08:17:20 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private readonly Dictionary<string, List<IPopupMenuItem>> _popupMenuItems =
|
|
|
|
new Dictionary<string, List<IPopupMenuItem>>();
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private readonly Dictionary<string, IStringView> _stringViews = new Dictionary<string, IStringView>();
|
|
|
|
private readonly List<PluginMenuOption> _pendingMenuOptions = new List<PluginMenuOption>();
|
2014-05-11 01:52:38 -04:00
|
|
|
|
2014-05-16 11:15:43 -04:00
|
|
|
//make sure _timer doesn't go out of scope:
|
|
|
|
private Timer _timer;
|
2014-05-30 14:51:07 -04:00
|
|
|
private PluginActionReceiver _pluginActionReceiver;
|
|
|
|
private PluginFieldReceiver _pluginFieldReceiver;
|
2014-05-16 11:15:43 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
protected void SetEntryView()
|
|
|
|
{
|
2013-02-23 11:43:42 -05:00
|
|
|
SetContentView(Resource.Layout.entry_view);
|
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
protected void SetupEditButtons() {
|
|
|
|
View edit = FindViewById(Resource.Id.entry_edit);
|
|
|
|
if (App.Kp2a.GetDb().CanWrite)
|
2014-01-26 08:27:27 -05:00
|
|
|
{
|
|
|
|
edit.Visibility = ViewStates.Visible;
|
|
|
|
edit.Click += (sender, e) =>
|
2014-05-11 01:52:38 -04:00
|
|
|
{
|
|
|
|
EntryEditActivity.Launch(this, Entry, _appTask);
|
|
|
|
};
|
2014-01-26 08:27:27 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
edit.Visibility = ViewStates.Gone;
|
|
|
|
}
|
2014-05-11 01:52:38 -04:00
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2014-05-26 09:14:34 -04:00
|
|
|
protected void SetupMoveButtons() {
|
|
|
|
View moveView = FindViewById(Resource.Id.entry_move);
|
2014-06-01 01:00:35 -04:00
|
|
|
/* Disabled for simpler UI. Wait if users demand that button.
|
2014-05-26 09:14:34 -04:00
|
|
|
if (App.Kp2a.GetDb().CanWrite)
|
|
|
|
{
|
|
|
|
moveView.Visibility = ViewStates.Visible;
|
|
|
|
moveView.Click += (sender, e) =>
|
|
|
|
{
|
|
|
|
NavigateToFolderAndLaunchMoveElementTask navMoveTask =
|
|
|
|
new NavigateToFolderAndLaunchMoveElementTask(Entry.ParentGroup,Entry.Uuid, false);
|
|
|
|
navMoveTask.SetActivityResult(this, KeePass.ExitNormal );
|
|
|
|
Finish();
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
2014-06-01 01:00:35 -04:00
|
|
|
else*/
|
2014-05-26 09:14:34 -04:00
|
|
|
{
|
|
|
|
moveView.Visibility = ViewStates.Gone;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private class PluginActionReceiver : BroadcastReceiver
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
private readonly EntryActivity _activity;
|
2013-03-06 15:25:30 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
public PluginActionReceiver(EntryActivity activity)
|
|
|
|
{
|
|
|
|
_activity = activity;
|
|
|
|
}
|
2013-03-06 15:25:30 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
public override void OnReceive(Context context, Intent intent)
|
|
|
|
{
|
|
|
|
var pluginPackage = intent.GetStringExtra(Strings.ExtraSender);
|
|
|
|
if (new PluginDatabase(context).IsValidAccessToken(pluginPackage,
|
|
|
|
intent.GetStringExtra(Strings.ExtraAccessToken),
|
|
|
|
Strings.ScopeCurrentEntry))
|
|
|
|
{
|
|
|
|
if (intent.GetStringExtra(Strings.ExtraEntryId) != _activity.Entry.Uuid.ToHexString())
|
|
|
|
{
|
|
|
|
Kp2aLog.Log("received action for wrong entry " + intent.GetStringExtra(Strings.ExtraEntryId));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_activity.AddPluginAction(pluginPackage,
|
|
|
|
intent.GetStringExtra(Strings.ExtraFieldId),
|
|
|
|
intent.GetStringExtra(Strings.ExtraActionId),
|
|
|
|
intent.GetStringExtra(Strings.ExtraActionDisplayText),
|
|
|
|
intent.GetIntExtra(Strings.ExtraActionIconResId, -1),
|
|
|
|
intent.GetBundleExtra(Strings.ExtraActionData));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Kp2aLog.Log("received invalid request. Plugin not authorized.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-06 15:25:30 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private class PluginFieldReceiver : BroadcastReceiver
|
|
|
|
{
|
|
|
|
private readonly EntryActivity _activity;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
public PluginFieldReceiver(EntryActivity activity)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
_activity = activity;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
public override void OnReceive(Context context, Intent intent)
|
|
|
|
{
|
|
|
|
if (intent.GetStringExtra(Strings.ExtraEntryId) != _activity.Entry.Uuid.ToHexString())
|
|
|
|
{
|
|
|
|
Kp2aLog.Log("received field for wrong entry " + intent.GetStringExtra(Strings.ExtraEntryId));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!new PluginDatabase(context).IsValidAccessToken(intent.GetStringExtra(Strings.ExtraSender),
|
|
|
|
intent.GetStringExtra(Strings.ExtraAccessToken),
|
|
|
|
Strings.ScopeCurrentEntry))
|
|
|
|
{
|
|
|
|
Kp2aLog.Log("received field with invalid access token from " + intent.GetStringExtra(Strings.ExtraSender));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string key = intent.GetStringExtra(Strings.ExtraFieldId);
|
|
|
|
string value = intent.GetStringExtra(Strings.ExtraFieldValue);
|
|
|
|
bool isProtected = intent.GetBooleanExtra(Strings.ExtraFieldProtected, false);
|
|
|
|
_activity.SetPluginField(key, value, isProtected);
|
|
|
|
}
|
|
|
|
}
|
2013-05-30 00:54:25 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private void SetPluginField(string key, string value, bool isProtected)
|
|
|
|
{
|
|
|
|
//update or add the string view:
|
|
|
|
IStringView existingField;
|
|
|
|
if (_stringViews.TryGetValue(key, out existingField))
|
|
|
|
{
|
|
|
|
existingField.Text = value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ViewGroup extraGroup = (ViewGroup) FindViewById(Resource.Id.extra_strings);
|
|
|
|
var view = CreateExtraSection(key, value, isProtected);
|
|
|
|
extraGroup.AddView(view.View);
|
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
//update the Entry output in the App database and notify the CopyToClipboard service
|
2014-05-11 01:52:38 -04:00
|
|
|
App.Kp2a.GetDb().LastOpenedEntry.OutputStrings.Set(key, new ProtectedString(isProtected, value));
|
2014-05-10 00:18:11 -04:00
|
|
|
Intent updateKeyboardIntent = new Intent(this, typeof(CopyToClipboardService));
|
2014-05-31 07:13:36 -04:00
|
|
|
updateKeyboardIntent.SetAction(Intents.UpdateKeyboard);
|
2014-05-10 00:18:11 -04:00
|
|
|
updateKeyboardIntent.PutExtra(KeyEntry, Entry.Uuid.ToHexString());
|
|
|
|
StartService(updateKeyboardIntent);
|
|
|
|
|
|
|
|
//notify plugins
|
|
|
|
NotifyPluginsOnModification(Strings.PrefixString+key);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void AddPluginAction(string pluginPackage, string fieldId, string popupItemId, string displayText, int iconId, Bundle bundleExtra)
|
|
|
|
{
|
|
|
|
if (fieldId != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//create a new popup item for the plugin action:
|
|
|
|
var newPopup = new PluginPopupMenuItem(this, pluginPackage, fieldId, popupItemId, displayText, iconId, bundleExtra);
|
|
|
|
//see if we already have a popup item for this field with the same item id
|
|
|
|
var popupsForField = _popupMenuItems[fieldId];
|
|
|
|
var popupItemPos = popupsForField.FindIndex(0,
|
|
|
|
item =>
|
|
|
|
(item is PluginPopupMenuItem) &&
|
|
|
|
((PluginPopupMenuItem)item).PopupItemId == popupItemId);
|
|
|
|
|
|
|
|
//replace existing or add
|
|
|
|
if (popupItemPos >= 0)
|
|
|
|
{
|
|
|
|
popupsForField[popupItemPos] = newPopup;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
popupsForField.Add(newPopup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Kp2aLog.Log(e.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//we need to add an option to the menu.
|
|
|
|
//As it is not sure that OnCreateOptionsMenu was called yet, we cannot access _menu without a check:
|
|
|
|
|
|
|
|
Intent i = new Intent(Strings.ActionEntryActionSelected);
|
|
|
|
i.SetPackage(pluginPackage);
|
|
|
|
i.PutExtra(Strings.ExtraActionData, bundleExtra);
|
|
|
|
i.PutExtra(Strings.ExtraSender, PackageName);
|
2014-05-11 01:52:38 -04:00
|
|
|
PluginHost.AddEntryToIntent(i, App.Kp2a.GetDb().LastOpenedEntry);
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
var menuOption = new PluginMenuOption()
|
|
|
|
{
|
|
|
|
DisplayText = displayText,
|
|
|
|
Icon = PackageManager.GetResourcesForApplication(pluginPackage).GetDrawable(iconId),
|
|
|
|
Intent = i
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_menu != null)
|
|
|
|
{
|
|
|
|
AddMenuOption(menuOption);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lock (_pendingMenuOptions)
|
|
|
|
{
|
|
|
|
_pendingMenuOptions.Add(menuOption);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void AddMenuOption(PluginMenuOption menuOption)
|
|
|
|
{
|
|
|
|
var menuItem = _menu.Add(menuOption.DisplayText);
|
|
|
|
menuItem.SetIcon(menuOption.Icon);
|
|
|
|
menuItem.SetIntent(menuOption.Intent);
|
|
|
|
}
|
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
protected override void OnCreate(Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
|
|
|
|
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
|
|
|
|
|
|
|
|
long usageCount = prefs.GetLong(GetString(Resource.String.UsageCount_key), 0);
|
|
|
|
|
|
|
|
ISharedPreferencesEditor edit = prefs.Edit();
|
|
|
|
edit.PutLong(GetString(Resource.String.UsageCount_key), usageCount + 1);
|
|
|
|
edit.Commit();
|
|
|
|
|
|
|
|
_showPassword =
|
|
|
|
!prefs.GetBoolean(GetString(Resource.String.maskpass_key), Resources.GetBoolean(Resource.Boolean.maskpass_default));
|
|
|
|
|
|
|
|
base.OnCreate(savedInstanceState);
|
2014-05-16 11:15:43 -04:00
|
|
|
RequestWindowFeature(WindowFeatures.IndeterminateProgress);
|
2014-05-11 01:52:38 -04:00
|
|
|
|
|
|
|
new ActivityDesign(this).ApplyTheme();
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
SetEntryView();
|
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
Database db = App.Kp2a.GetDb();
|
|
|
|
// Likely the app has been killed exit the activity
|
|
|
|
if (!db.Loaded || (App.Kp2a.QuickLocked))
|
|
|
|
{
|
|
|
|
Finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetResult(KeePass.ExitNormal);
|
|
|
|
|
|
|
|
Intent i = Intent;
|
|
|
|
PwUuid uuid = new PwUuid(MemUtil.HexStringToByteArray(i.GetStringExtra(KeyEntry)));
|
|
|
|
_pos = i.GetIntExtra(KeyRefreshPos, -1);
|
|
|
|
|
|
|
|
_appTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);
|
|
|
|
|
|
|
|
Entry = db.Entries[uuid];
|
2015-02-17 00:27:59 -05:00
|
|
|
Android.Util.Log.Debug("KP2A", "Notes: " + Entry.Strings.ReadSafe(PwDefs.NotesField));
|
2014-05-11 01:52:38 -04:00
|
|
|
|
|
|
|
// Refresh Menu contents in case onCreateMenuOptions was called before Entry was set
|
|
|
|
ActivityCompat.InvalidateOptionsMenu(this);
|
|
|
|
|
|
|
|
// Update last access time.
|
|
|
|
Entry.Touch(false);
|
|
|
|
|
|
|
|
if (PwDefs.IsTanEntry(Entry) && prefs.GetBoolean(GetString(Resource.String.TanExpiresOnUse_key), Resources.GetBoolean(Resource.Boolean.TanExpiresOnUse_default)) && ((Entry.Expires == false) || Entry.ExpiryTime > DateTime.Now))
|
|
|
|
{
|
|
|
|
PwEntry backupEntry = Entry.CloneDeep();
|
|
|
|
Entry.ExpiryTime = DateTime.Now;
|
|
|
|
Entry.Expires = true;
|
|
|
|
Entry.Touch(true);
|
|
|
|
RequiresRefresh();
|
|
|
|
UpdateEntry update = new UpdateEntry(this, App.Kp2a, backupEntry, Entry, null);
|
|
|
|
ProgressTask pt = new ProgressTask(App.Kp2a, this, update);
|
|
|
|
pt.Run();
|
|
|
|
}
|
2014-05-07 09:30:52 -04:00
|
|
|
FillData();
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
SetupEditButtons();
|
2014-05-26 09:14:34 -04:00
|
|
|
SetupMoveButtons ();
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
App.Kp2a.GetDb().LastOpenedEntry = new PwEntryOutput(Entry, App.Kp2a.GetDb().KpDatabase);
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2014-05-30 14:51:07 -04:00
|
|
|
_pluginActionReceiver = new PluginActionReceiver(this);
|
|
|
|
RegisterReceiver(_pluginActionReceiver, new IntentFilter(Strings.ActionAddEntryAction));
|
|
|
|
_pluginFieldReceiver = new PluginFieldReceiver(this);
|
|
|
|
RegisterReceiver(_pluginFieldReceiver, new IntentFilter(Strings.ActionSetEntryField));
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
new Thread(NotifyPluginsOnOpen).Start();
|
2014-05-16 11:15:43 -04:00
|
|
|
|
|
|
|
//the rest of the things to do depends on the current app task:
|
|
|
|
_appTask.CompleteOnCreateEntryActivity(this);
|
2014-01-26 09:51:16 -05:00
|
|
|
}
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private void NotifyPluginsOnOpen()
|
2014-01-26 09:51:16 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
Intent i = new Intent(Strings.ActionOpenEntry);
|
|
|
|
i.PutExtra(Strings.ExtraSender, PackageName);
|
|
|
|
AddEntryToIntent(i);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
foreach (var plugin in new PluginDatabase(this).GetPluginsWithAcceptedScope(Strings.ScopeCurrentEntry))
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
i.SetPackage(plugin);
|
|
|
|
SendBroadcast(i);
|
|
|
|
}
|
2014-05-31 07:13:36 -04:00
|
|
|
|
|
|
|
new Kp2aTotp().OnOpenEntry();
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
}
|
|
|
|
private void NotifyPluginsOnModification(string fieldId)
|
|
|
|
{
|
|
|
|
Intent i = new Intent(Strings.ActionEntryOutputModified);
|
|
|
|
i.PutExtra(Strings.ExtraSender, PackageName);
|
|
|
|
i.PutExtra(Strings.ExtraFieldId, fieldId);
|
|
|
|
AddEntryToIntent(i);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
foreach (var plugin in new PluginDatabase(this).GetPluginsWithAcceptedScope(Strings.ScopeCurrentEntry))
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
i.SetPackage(plugin);
|
|
|
|
SendBroadcast(i);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
2014-01-26 09:51:16 -05:00
|
|
|
|
2014-05-16 11:15:43 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2014-05-16 11:15:43 -04:00
|
|
|
internal void StartNotificationsService(bool closeAfterCreate)
|
|
|
|
{
|
|
|
|
Intent showNotIntent = new Intent(this, typeof (CopyToClipboardService));
|
2014-05-11 09:41:45 -04:00
|
|
|
showNotIntent.SetAction(Intents.ShowNotification);
|
2014-05-11 01:52:38 -04:00
|
|
|
showNotIntent.PutExtra(KeyEntry, Entry.Uuid.ToHexString());
|
2014-05-16 11:15:43 -04:00
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
showNotIntent.PutExtra(KeyCloseAfterCreate, closeAfterCreate);
|
|
|
|
|
|
|
|
StartService(showNotIntent);
|
2014-05-10 00:18:11 -04:00
|
|
|
}
|
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private String getDateTime(DateTime dt)
|
|
|
|
{
|
|
|
|
return dt.ToString("g", CultureInfo.CurrentUICulture);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private String concatTags(List<string> tags)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
foreach (string tag in tags)
|
|
|
|
{
|
|
|
|
sb.Append(tag);
|
|
|
|
sb.Append(", ");
|
|
|
|
}
|
|
|
|
if (tags.Count > 0)
|
2014-05-10 00:18:11 -04:00
|
|
|
sb.Remove(sb.Length - 2, 2);
|
2013-02-23 11:43:42 -05:00
|
|
|
return sb.ToString();
|
|
|
|
}
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private void PopulateExtraStrings()
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
ViewGroup extraGroup = (ViewGroup) FindViewById(Resource.Id.extra_strings);
|
|
|
|
foreach (var pair in Entry.Strings.Where(pair => !PwDefs.IsStandardField(pair.Key)).OrderBy(pair => pair.Key))
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
var stringView = CreateExtraSection(pair.Key, pair.Value.ReadString(), pair.Value.IsProtected);
|
|
|
|
extraGroup.AddView(stringView.View);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private ExtraStringView CreateExtraSection(string key, string value, bool isProtected)
|
2013-04-26 04:10:46 -04:00
|
|
|
{
|
2013-06-15 06:40:01 -04:00
|
|
|
LinearLayout layout = new LinearLayout(this, null) {Orientation = Orientation.Vertical};
|
2014-05-10 00:18:11 -04:00
|
|
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FillParent,
|
|
|
|
ViewGroup.LayoutParams.WrapContent);
|
|
|
|
|
2013-04-26 04:10:46 -04:00
|
|
|
layout.LayoutParameters = layoutParams;
|
2014-05-10 00:18:11 -04:00
|
|
|
View viewInflated = LayoutInflater.Inflate(Resource.Layout.entry_extrastring_title, null);
|
|
|
|
TextView keyView = viewInflated.FindViewById<TextView>(Resource.Id.entry_title);
|
2013-04-26 04:10:46 -04:00
|
|
|
if (key != null)
|
|
|
|
keyView.Text = key;
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
layout.AddView(viewInflated);
|
|
|
|
RelativeLayout valueViewContainer =
|
|
|
|
(RelativeLayout) LayoutInflater.Inflate(Resource.Layout.entry_extrastring_value, null);
|
|
|
|
var valueView = valueViewContainer.FindViewById<TextView>(Resource.Id.entry_extra);
|
2013-04-26 04:10:46 -04:00
|
|
|
if (value != null)
|
|
|
|
valueView.Text = value;
|
2013-10-12 16:20:02 -04:00
|
|
|
SetPasswordTypeface(valueView);
|
2013-07-12 08:17:20 -04:00
|
|
|
if (isProtected)
|
2014-05-10 00:18:11 -04:00
|
|
|
{
|
2013-07-12 08:17:20 -04:00
|
|
|
RegisterProtectedTextView(valueView);
|
2014-05-10 00:18:11 -04:00
|
|
|
valueView.TransformationMethod = PasswordTransformationMethod.Instance;
|
|
|
|
}
|
2013-07-12 08:17:20 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
layout.AddView(valueViewContainer);
|
|
|
|
var stringView = new ExtraStringView(layout, valueView, keyView);
|
2013-04-28 16:46:31 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
_stringViews.Add(key, stringView);
|
|
|
|
RegisterTextPopup(valueViewContainer, valueViewContainer.FindViewById(Resource.Id.extra_vdots), key, isProtected);
|
|
|
|
|
|
|
|
return stringView;
|
2013-07-12 08:17:20 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private List<IPopupMenuItem> RegisterPopup(string popupKey, View clickView, View anchorView)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
clickView.Click += (sender, args) =>
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
ShowPopup(anchorView, popupKey);
|
|
|
|
};
|
|
|
|
_popupMenuItems[popupKey] = new List<IPopupMenuItem>();
|
|
|
|
return _popupMenuItems[popupKey];
|
|
|
|
}
|
2014-05-11 07:21:28 -04:00
|
|
|
internal Uri WriteBinaryToFile(string key, bool writeToCacheDirectory)
|
2014-05-11 01:52:38 -04:00
|
|
|
{
|
|
|
|
ProtectedBinary pb = Entry.Binaries.Get(key);
|
|
|
|
System.Diagnostics.Debug.Assert(pb != null);
|
|
|
|
if (pb == null)
|
|
|
|
throw new ArgumentException();
|
|
|
|
|
|
|
|
|
|
|
|
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
|
|
|
|
string binaryDirectory = prefs.GetString(GetString(Resource.String.BinaryDirectory_key), GetString(Resource.String.BinaryDirectory_default));
|
|
|
|
if (writeToCacheDirectory)
|
|
|
|
binaryDirectory = CacheDir.Path + File.Separator + AttachmentContentProvider.AttachmentCacheSubDir;
|
|
|
|
|
|
|
|
string filepart = key;
|
|
|
|
if (writeToCacheDirectory)
|
|
|
|
filepart = filepart.Replace(" ", "");
|
|
|
|
var targetFile = new File(binaryDirectory, filepart);
|
|
|
|
|
|
|
|
File parent = targetFile.ParentFile;
|
|
|
|
|
|
|
|
if (parent == null || (parent.Exists() && !parent.IsDirectory))
|
|
|
|
{
|
|
|
|
Toast.MakeText(this,
|
|
|
|
Resource.String.error_invalid_path,
|
|
|
|
ToastLength.Long).Show();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parent.Exists())
|
|
|
|
{
|
|
|
|
// Create parent directory
|
|
|
|
if (!parent.Mkdirs())
|
|
|
|
{
|
|
|
|
Toast.MakeText(this,
|
|
|
|
Resource.String.error_could_not_create_parent,
|
|
|
|
ToastLength.Long).Show();
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
string filename = targetFile.AbsolutePath;
|
2014-05-11 07:21:28 -04:00
|
|
|
Uri fileUri = Uri.FromFile(targetFile);
|
2014-05-11 01:52:38 -04:00
|
|
|
|
|
|
|
byte[] pbData = pb.ReadData();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
System.IO.File.WriteAllBytes(filename, pbData);
|
|
|
|
}
|
|
|
|
catch (Exception exWrite)
|
|
|
|
{
|
|
|
|
Toast.MakeText(this, GetString(Resource.String.SaveAttachment_Failed, new Java.Lang.Object[] { filename })
|
|
|
|
+ exWrite.Message, ToastLength.Long).Show();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
MemUtil.ZeroByteArray(pbData);
|
|
|
|
}
|
|
|
|
Toast.MakeText(this, GetString(Resource.String.SaveAttachment_doneMessage, new Java.Lang.Object[] { filename }), ToastLength.Short).Show();
|
|
|
|
if (writeToCacheDirectory)
|
|
|
|
{
|
2014-05-11 07:21:28 -04:00
|
|
|
return Uri.Parse("content://" + AttachmentContentProvider.Authority + "/"
|
2014-05-11 01:52:38 -04:00
|
|
|
+ filename);
|
|
|
|
}
|
|
|
|
return fileUri;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void OpenBinaryFile(Android.Net.Uri uri)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
String theMimeType = GetMimeType(uri.Path);
|
|
|
|
if (theMimeType != null)
|
|
|
|
{
|
|
|
|
|
|
|
|
Intent theIntent = new Intent(Intent.ActionView);
|
|
|
|
theIntent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ExcludeFromRecents);
|
|
|
|
theIntent.SetDataAndType(uri, theMimeType);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
StartActivity(theIntent);
|
|
|
|
}
|
|
|
|
catch (ActivityNotFoundException)
|
|
|
|
{
|
|
|
|
//ignore
|
|
|
|
Toast.MakeText(this, "Couldn't open file", ToastLength.Short).Show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private void RegisterProtectedTextView(TextView protectedTextView)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
_protectedTextViews.Add(protectedTextView);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
private void PopulateBinaries()
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
ViewGroup binariesGroup = (ViewGroup) FindViewById(Resource.Id.binaries);
|
2014-05-11 01:52:38 -04:00
|
|
|
foreach (KeyValuePair<string, ProtectedBinary> pair in Entry.Binaries)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
|
|
|
String key = pair.Key;
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
RelativeLayout valueViewContainer =
|
|
|
|
(RelativeLayout) LayoutInflater.Inflate(Resource.Layout.entry_extrastring_value, null);
|
|
|
|
var valueView = valueViewContainer.FindViewById<TextView>(Resource.Id.entry_extra);
|
|
|
|
if (key != null)
|
|
|
|
valueView.Text = key;
|
|
|
|
|
|
|
|
string popupKey = Strings.PrefixBinary + key;
|
|
|
|
|
|
|
|
var itemList = RegisterPopup(popupKey, valueViewContainer, valueViewContainer.FindViewById(Resource.Id.extra_vdots));
|
|
|
|
itemList.Add(new WriteBinaryToFilePopupItem(key, this));
|
|
|
|
itemList.Add(new OpenBinaryPopupItem(key, this));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binariesGroup.AddView(valueViewContainer);
|
|
|
|
/*
|
2013-02-23 11:43:42 -05:00
|
|
|
Button binaryButton = new Button(this);
|
2013-06-15 06:40:01 -04:00
|
|
|
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent);
|
2013-02-23 11:43:42 -05:00
|
|
|
binaryButton.Text = key;
|
|
|
|
binaryButton.SetCompoundDrawablesWithIntrinsicBounds( Resources.GetDrawable(Android.Resource.Drawable.IcMenuSave),null, null, null);
|
2013-06-15 06:40:01 -04:00
|
|
|
binaryButton.Click += (sender, e) =>
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
|
|
|
Button btnSender = (Button)(sender);
|
|
|
|
|
2013-04-28 16:46:31 -04:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.SetTitle(GetString(Resource.String.SaveAttachmentDialog_title));
|
|
|
|
|
|
|
|
builder.SetMessage(GetString(Resource.String.SaveAttachmentDialog_text));
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
builder.SetPositiveButton(GetString(Resource.String.SaveAttachmentDialog_save), (dlgSender, dlgEvt) =>
|
2013-04-28 16:46:31 -04:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
});
|
2013-04-28 16:46:31 -04:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
builder.SetNegativeButton(GetString(Resource.String.SaveAttachmentDialog_open), (dlgSender, dlgEvt) =>
|
2013-04-28 16:46:31 -04:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
});
|
2013-04-28 16:46:31 -04:00
|
|
|
|
|
|
|
Dialog dialog = builder.Create();
|
|
|
|
dialog.Show();
|
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
};
|
|
|
|
binariesGroup.AddView(binaryButton,layoutParams);
|
2014-05-10 00:18:11 -04:00
|
|
|
*/
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
}
|
2014-05-11 07:21:28 -04:00
|
|
|
FindViewById(Resource.Id.entry_binaries_label).Visibility = Entry.Binaries.Any() ? ViewStates.Visible : ViewStates.Gone;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// url = file path or whatever suitable URL you want.
|
2013-06-15 06:40:01 -04:00
|
|
|
public static String GetMimeType(String url)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
|
|
|
String type = null;
|
|
|
|
String extension = MimeTypeMap.GetFileExtensionFromUrl(url);
|
2014-05-10 00:18:11 -04:00
|
|
|
if (extension != null)
|
|
|
|
{
|
2013-02-23 11:43:42 -05:00
|
|
|
MimeTypeMap mime = MimeTypeMap.Singleton;
|
|
|
|
type = mime.GetMimeTypeFromExtension(extension);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
2013-05-17 00:53:58 -04:00
|
|
|
|
|
|
|
public override void OnBackPressed()
|
|
|
|
{
|
|
|
|
base.OnBackPressed();
|
2014-05-11 01:52:38 -04:00
|
|
|
OverridePendingTransition(Resource.Animation.anim_enter_back, Resource.Animation.anim_leave_back);
|
2013-05-17 00:53:58 -04:00
|
|
|
}
|
|
|
|
|
2014-05-07 09:30:52 -04:00
|
|
|
protected void FillData()
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2013-07-12 08:17:20 -04:00
|
|
|
_protectedTextViews = new List<TextView>();
|
2014-05-10 00:18:11 -04:00
|
|
|
ImageView iv = (ImageView) FindViewById(Resource.Id.entry_icon);
|
2013-04-12 23:28:15 -04:00
|
|
|
if (iv != null)
|
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
iv.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.ic00));
|
2013-04-26 04:10:46 -04:00
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
ActionBar.Title = Entry.Strings.ReadSafe(PwDefs.TitleField);
|
2014-05-10 00:18:11 -04:00
|
|
|
ActionBar.SetDisplayHomeAsUpEnabled(true);
|
|
|
|
|
2014-05-26 06:09:41 -04:00
|
|
|
PopulateGroupText (Resource.Id.entry_group_name, Resource.Id.entryfield_group_container, KeyGroupFullPath);
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
PopulateStandardText(Resource.Id.entry_user_name, Resource.Id.entryfield_container_username, PwDefs.UserNameField);
|
|
|
|
PopulateStandardText(Resource.Id.entry_url, Resource.Id.entryfield_container_url, PwDefs.UrlField);
|
|
|
|
PopulateStandardText(Resource.Id.entry_password, Resource.Id.entryfield_container_password, PwDefs.PasswordField);
|
2013-07-12 08:17:20 -04:00
|
|
|
RegisterProtectedTextView(FindViewById<TextView>(Resource.Id.entry_password));
|
2013-10-12 16:20:02 -04:00
|
|
|
SetPasswordTypeface(FindViewById<TextView>(Resource.Id.entry_password));
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2014-05-26 06:09:41 -04:00
|
|
|
RegisterTextPopup(FindViewById<RelativeLayout> (Resource.Id.groupname_container),
|
|
|
|
FindViewById (Resource.Id.entry_group_name), KeyGroupFullPath);
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
RegisterTextPopup(FindViewById<RelativeLayout>(Resource.Id.username_container),
|
|
|
|
FindViewById(Resource.Id.username_vdots), PwDefs.UserNameField);
|
2014-05-26 06:09:41 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
RegisterTextPopup(FindViewById<RelativeLayout>(Resource.Id.url_container),
|
|
|
|
FindViewById(Resource.Id.url_vdots), PwDefs.UrlField)
|
|
|
|
.Add(new GotoUrlMenuItem(this));
|
|
|
|
RegisterTextPopup(FindViewById<RelativeLayout>(Resource.Id.password_container),
|
|
|
|
FindViewById(Resource.Id.password_vdots), PwDefs.PasswordField);
|
|
|
|
|
|
|
|
|
|
|
|
PopulateText(Resource.Id.entry_created, Resource.Id.entryfield_container_created, getDateTime(Entry.CreationTime));
|
|
|
|
PopulateText(Resource.Id.entry_modified, Resource.Id.entryfield_container_modified, getDateTime(Entry.LastModificationTime));
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
if (Entry.Expires)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
PopulateText(Resource.Id.entry_expires, Resource.Id.entryfield_container_expires, getDateTime(Entry.ExpiryTime));
|
2013-11-09 00:51:54 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
}
|
2013-11-09 00:51:54 -05:00
|
|
|
else
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
PopulateText(Resource.Id.entry_expires, Resource.Id.entryfield_container_expires, null);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
PopulateStandardText(Resource.Id.entry_comment, Resource.Id.entryfield_container_comment, PwDefs.NotesField);
|
2015-02-17 00:27:59 -05:00
|
|
|
RegisterTextPopup(FindViewById<RelativeLayout>(Resource.Id.comment_container),
|
|
|
|
FindViewById(Resource.Id.username_vdots), PwDefs.NotesField);
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
PopulateText(Resource.Id.entry_tags, Resource.Id.entryfield_container_tags, concatTags(Entry.Tags));
|
|
|
|
PopulateText(Resource.Id.entry_override_url, Resource.Id.entryfield_container_overrideurl, Entry.OverrideUrl);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-07 09:30:52 -04:00
|
|
|
PopulateExtraStrings();
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-07 09:30:52 -04:00
|
|
|
PopulateBinaries();
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2013-07-12 08:17:20 -04:00
|
|
|
SetPasswordStyle();
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2013-10-12 16:20:02 -04:00
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
|
2013-10-12 16:20:02 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
protected override void OnDestroy()
|
|
|
|
{
|
|
|
|
NotifyPluginsOnClose();
|
2014-05-30 14:51:07 -04:00
|
|
|
if (_pluginActionReceiver != null)
|
|
|
|
UnregisterReceiver(_pluginActionReceiver);
|
|
|
|
if (_pluginFieldReceiver != null)
|
|
|
|
UnregisterReceiver(_pluginFieldReceiver);
|
2014-05-10 00:18:11 -04:00
|
|
|
base.OnDestroy();
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
private void NotifyPluginsOnClose()
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
Intent i = new Intent(Strings.ActionCloseEntryView);
|
|
|
|
i.PutExtra(Strings.ExtraSender, PackageName);
|
|
|
|
foreach (var plugin in new PluginDatabase(this).GetPluginsWithAcceptedScope(Strings.ScopeCurrentEntry))
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
i.SetPackage(plugin);
|
|
|
|
SendBroadcast(i);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
private List<IPopupMenuItem> RegisterTextPopup(View container, View anchor, string fieldKey)
|
|
|
|
{
|
|
|
|
return RegisterTextPopup(container, anchor, fieldKey, Entry.Strings.GetSafe(fieldKey).IsProtected);
|
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private List<IPopupMenuItem> RegisterTextPopup(View container, View anchor, string fieldKey, bool isProtected)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
string popupKey = Strings.PrefixString + fieldKey;
|
|
|
|
var popupItems = RegisterPopup(
|
|
|
|
popupKey,
|
|
|
|
container,
|
|
|
|
anchor);
|
|
|
|
popupItems.Add(new CopyToClipboardPopupMenuIcon(this, _stringViews[fieldKey]));
|
|
|
|
if (isProtected)
|
|
|
|
popupItems.Add(new ToggleVisibilityPopupMenuItem(this));
|
|
|
|
return popupItems;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ShowPopup(View anchor, string popupKey)
|
|
|
|
{
|
|
|
|
//PopupMenu popupMenu = new PopupMenu(this, FindViewById(Resource.Id.entry_user_name));
|
|
|
|
PopupMenu popupMenu = new PopupMenu(this, anchor);
|
|
|
|
|
|
|
|
AccessManager.PreparePopup(popupMenu);
|
|
|
|
int itemId = 0;
|
|
|
|
foreach (IPopupMenuItem popupItem in _popupMenuItems[popupKey])
|
|
|
|
{
|
|
|
|
popupMenu.Menu.Add(0, itemId, 0, popupItem.Text)
|
|
|
|
.SetIcon(popupItem.Icon);
|
|
|
|
itemId++;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
popupMenu.MenuItemClick += delegate(object sender, PopupMenu.MenuItemClickEventArgs args)
|
|
|
|
{
|
|
|
|
_popupMenuItems[popupKey][args.Item.ItemId].HandleClick();
|
|
|
|
};
|
|
|
|
popupMenu.Show();
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2014-05-11 07:21:28 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private void SetPasswordTypeface(TextView textView)
|
|
|
|
{
|
2014-05-11 01:52:38 -04:00
|
|
|
if (_passwordFont == null)
|
|
|
|
_passwordFont = Typeface.CreateFromAsset(Assets, "DejaVuSansMono.ttf");
|
|
|
|
textView.Typeface = _passwordFont;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2014-05-07 09:30:52 -04:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private void PopulateText(int viewId, int containerViewId, String text)
|
|
|
|
{
|
|
|
|
View container = FindViewById(containerViewId);
|
|
|
|
TextView tv = (TextView) FindViewById(viewId);
|
|
|
|
if (String.IsNullOrEmpty(text))
|
2014-05-07 09:30:52 -04:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
container.Visibility = tv.Visibility = ViewStates.Gone;
|
2014-05-07 09:30:52 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
container.Visibility = tv.Visibility = ViewStates.Visible;
|
|
|
|
tv.Text = text;
|
|
|
|
|
2014-05-07 09:30:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private void PopulateStandardText(int viewId, int containerViewId, String key)
|
|
|
|
{
|
|
|
|
PopulateText(viewId, containerViewId, Entry.Strings.ReadSafe(key));
|
|
|
|
_stringViews.Add(key, new StandardStringView(viewId, containerViewId, this));
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:09:41 -04:00
|
|
|
private void PopulateGroupText(int viewId, int containerViewId, String key)
|
|
|
|
{
|
2014-05-28 11:24:43 -04:00
|
|
|
string groupName = null;
|
|
|
|
if (PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean(
|
|
|
|
"ShowGroupInEntry", false))
|
|
|
|
{
|
|
|
|
groupName = Entry.ParentGroup.GetFullPath();
|
|
|
|
}
|
|
|
|
PopulateText(viewId, containerViewId, groupName);
|
2014-05-26 06:09:41 -04:00
|
|
|
_stringViews.Add (key, new StandardStringView (viewId, containerViewId, this));
|
|
|
|
}
|
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
private void RequiresRefresh()
|
|
|
|
{
|
|
|
|
Intent ret = new Intent();
|
|
|
|
ret.PutExtra(KeyRefreshPos, _pos);
|
2014-05-16 11:15:43 -04:00
|
|
|
_appTask.ToIntent(ret);
|
2014-05-11 01:52:38 -04:00
|
|
|
SetResult(KeePass.ExitRefresh, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) {
|
|
|
|
base.OnActivityResult(requestCode, resultCode, data);
|
2014-05-16 11:15:43 -04:00
|
|
|
if (AppTask.TryGetFromActivityResult(data, ref _appTask))
|
|
|
|
{
|
|
|
|
//make sure app task is passed to calling activity.
|
|
|
|
//the result code might be modified later.
|
|
|
|
Intent retData = new Intent();
|
|
|
|
_appTask.ToIntent(retData);
|
|
|
|
SetResult(KeePass.ExitNormal, retData);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
if ( resultCode == KeePass.ExitRefresh || resultCode == KeePass.ExitRefreshTitle ) {
|
|
|
|
if ( resultCode == KeePass.ExitRefreshTitle ) {
|
|
|
|
RequiresRefresh ();
|
|
|
|
}
|
|
|
|
Recreate();
|
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
}
|
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
public override bool OnCreateOptionsMenu(IMenu menu)
|
|
|
|
{
|
|
|
|
_menu = menu;
|
|
|
|
base.OnCreateOptionsMenu(menu);
|
|
|
|
|
|
|
|
MenuInflater inflater = MenuInflater;
|
|
|
|
inflater.Inflate(Resource.Menu.entry, menu);
|
|
|
|
|
|
|
|
lock (_pendingMenuOptions)
|
|
|
|
{
|
|
|
|
foreach (var option in _pendingMenuOptions)
|
|
|
|
AddMenuOption(option);
|
|
|
|
_pendingMenuOptions.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdateTogglePasswordMenu();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2014-05-18 12:01:17 -04:00
|
|
|
public override bool OnPrepareOptionsMenu(IMenu menu)
|
|
|
|
{
|
|
|
|
Util.PrepareDonateOptionMenu(menu, this);
|
|
|
|
return base.OnPrepareOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
private void UpdateTogglePasswordMenu()
|
|
|
|
{
|
|
|
|
IMenuItem togglePassword = _menu.FindItem(Resource.Id.menu_toggle_pass);
|
|
|
|
if (_showPassword)
|
|
|
|
{
|
|
|
|
togglePassword.SetTitle(Resource.String.menu_hide_password);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
togglePassword.SetTitle(Resource.String.show_password);
|
|
|
|
}
|
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
|
|
|
|
private void SetPasswordStyle()
|
|
|
|
{
|
2013-07-12 08:17:20 -04:00
|
|
|
foreach (TextView password in _protectedTextViews)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_showPassword)
|
|
|
|
{
|
2015-01-26 23:53:01 -05:00
|
|
|
//password.TransformationMethod = null;
|
|
|
|
password.InputType = InputTypes.TextVariationVisiblePassword ;
|
2013-07-12 08:17:20 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-26 23:53:01 -05:00
|
|
|
//password.TransformationMethod = PasswordTransformationMethod.Instance;
|
|
|
|
password.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword;
|
2013-07-12 08:17:20 -04:00
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
|
2013-04-28 16:46:31 -04:00
|
|
|
protected override void OnResume()
|
|
|
|
{
|
2014-05-11 01:52:38 -04:00
|
|
|
ClearCache();
|
2014-05-10 00:18:11 -04:00
|
|
|
base.OnResume();
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2014-01-26 09:51:16 -05:00
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
public void ClearCache()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
File dir = new File(CacheDir.Path + File.Separator + AttachmentContentProvider.AttachmentCacheSubDir);
|
|
|
|
if (dir.IsDirectory)
|
|
|
|
{
|
|
|
|
IoUtil.DeleteDir(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool OnOptionsItemSelected(IMenuItem item)
|
|
|
|
{
|
|
|
|
//check if this is a plugin action
|
|
|
|
if ((item.Intent != null) && (item.Intent.Action == Strings.ActionEntryActionSelected))
|
|
|
|
{
|
|
|
|
//yes. let the plugin handle the click:
|
|
|
|
SendBroadcast(item.Intent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (item.ItemId)
|
|
|
|
{
|
|
|
|
case Resource.Id.menu_donate:
|
2014-05-18 12:01:17 -04:00
|
|
|
return Util.GotoDonateUrl(this);
|
2014-05-11 01:52:38 -04:00
|
|
|
case Resource.Id.menu_toggle_pass:
|
|
|
|
if (_showPassword)
|
|
|
|
{
|
|
|
|
item.SetTitle(Resource.String.show_password);
|
|
|
|
_showPassword = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.SetTitle(Resource.String.menu_hide_password);
|
|
|
|
_showPassword = true;
|
|
|
|
}
|
|
|
|
SetPasswordStyle();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case Resource.Id.menu_lock:
|
2014-05-18 12:01:17 -04:00
|
|
|
App.Kp2a.LockDatabase();
|
2014-05-11 01:52:38 -04:00
|
|
|
return true;
|
|
|
|
case Android.Resource.Id.Home:
|
|
|
|
//Currently the action bar only displays the home button when we come from a previous activity.
|
|
|
|
//So we can simply Finish. See this page for information on how to do this in more general (future?) cases:
|
|
|
|
//http://developer.android.com/training/implementing-navigation/ancestral.html
|
|
|
|
Finish();
|
|
|
|
OverridePendingTransition(Resource.Animation.anim_enter_back, Resource.Animation.anim_leave_back);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return base.OnOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-16 11:15:43 -04:00
|
|
|
|
|
|
|
internal void AddUrlToEntry(string url, Action finishAction)
|
2014-05-11 01:52:38 -04:00
|
|
|
{
|
|
|
|
PwEntry initialEntry = Entry.CloneDeep();
|
|
|
|
|
|
|
|
PwEntry newEntry = Entry;
|
|
|
|
newEntry.History = newEntry.History.CloneDeep();
|
|
|
|
newEntry.CreateBackup(null);
|
|
|
|
|
|
|
|
newEntry.Touch(true, false); // Touch *after* backup
|
|
|
|
|
|
|
|
//if there is no URL in the entry, set that field. If it's already in use, use an additional (not existing) field
|
|
|
|
if (String.IsNullOrEmpty(newEntry.Strings.ReadSafe(PwDefs.UrlField)))
|
|
|
|
{
|
|
|
|
newEntry.Strings.Set(PwDefs.UrlField, new ProtectedString(false, url));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int c = 1;
|
|
|
|
while (newEntry.Strings.Get("KP2A_URL_" + c) != null)
|
|
|
|
{
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
|
|
|
|
newEntry.Strings.Set("KP2A_URL_" + c, new ProtectedString(false, url));
|
|
|
|
}
|
|
|
|
|
|
|
|
//save the entry:
|
2014-01-26 09:51:16 -05:00
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
ActionOnFinish closeOrShowError = new ActionOnFinish((success, message) =>
|
|
|
|
{
|
|
|
|
OnFinish.DisplayMessage(this, message);
|
2014-05-16 11:15:43 -04:00
|
|
|
finishAction();
|
2014-05-11 01:52:38 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
RunnableOnFinish runnable = new UpdateEntry(this, App.Kp2a, initialEntry, newEntry, closeOrShowError);
|
|
|
|
|
|
|
|
ProgressTask pt = new ProgressTask(App.Kp2a, this, runnable);
|
|
|
|
pt.Run();
|
|
|
|
|
2014-05-16 11:15:43 -04:00
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
public void ToggleVisibility()
|
2014-01-26 09:51:16 -05:00
|
|
|
{
|
2014-05-10 00:18:11 -04:00
|
|
|
_showPassword = !_showPassword;
|
|
|
|
SetPasswordStyle();
|
|
|
|
UpdateTogglePasswordMenu();
|
|
|
|
}
|
2014-01-26 09:51:16 -05:00
|
|
|
|
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
public bool GotoUrl()
|
2014-05-10 00:18:11 -04:00
|
|
|
{
|
2014-05-11 01:52:38 -04:00
|
|
|
string url = _stringViews[PwDefs.UrlField].Text;
|
|
|
|
if (url == null) return false;
|
2014-01-26 09:51:16 -05:00
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
// Default http:// if no protocol specified
|
|
|
|
if (!url.Contains("://"))
|
|
|
|
{
|
|
|
|
url = "http://" + url;
|
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-11 01:52:38 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Util.GotoUrl(this, url);
|
|
|
|
}
|
|
|
|
catch (ActivityNotFoundException)
|
|
|
|
{
|
|
|
|
Toast.MakeText(this, Resource.String.no_url_handler, ToastLength.Long).Show();
|
|
|
|
}
|
|
|
|
return true;
|
2014-05-10 00:18:11 -04:00
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-05-10 00:18:11 -04:00
|
|
|
public void AddEntryToIntent(Intent intent)
|
|
|
|
{
|
2014-05-11 01:52:38 -04:00
|
|
|
PluginHost.AddEntryToIntent(intent, App.Kp2a.GetDb().LastOpenedEntry);
|
2014-05-10 00:18:11 -04:00
|
|
|
}
|
2014-05-16 11:15:43 -04:00
|
|
|
|
|
|
|
public void CloseAfterTaskComplete()
|
|
|
|
{
|
|
|
|
//before closing, wait a little to get plugin updates
|
|
|
|
int numPlugins = new PluginDatabase(this).GetPluginsWithAcceptedScope(Strings.ScopeCurrentEntry).Count();
|
|
|
|
var timeToWait = TimeSpan.FromMilliseconds(500*numPlugins);
|
|
|
|
SetProgressBarIndeterminateVisibility(true);
|
|
|
|
_timer = new Timer(obj =>
|
|
|
|
{
|
|
|
|
RunOnUiThread(() =>
|
|
|
|
{
|
|
|
|
//task is completed -> return NullTask
|
|
|
|
Intent resIntent = new Intent();
|
|
|
|
new NullTask().ToIntent(resIntent);
|
|
|
|
SetResult(KeePass.ExitCloseAfterTaskComplete, resIntent);
|
|
|
|
//close activity:
|
|
|
|
Finish();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
null, timeToWait, TimeSpan.FromMilliseconds(-1));
|
|
|
|
}
|
2014-05-10 00:18:11 -04:00
|
|
|
}
|
|
|
|
}
|