mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-22 09:12:17 -05:00
A little more refactoring: Removed/moved classes, some renames, ...
Added comments for most classes
This commit is contained in:
parent
d2a06617eb
commit
8b08baa51a
@ -4,19 +4,46 @@ using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface through which Activities and the logic layer can access some app specific functionalities and Application static data
|
||||
/// </summary>
|
||||
/// This also contains methods which are UI specific and should be replacable for testing.
|
||||
public interface IKp2aApp
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Set the flag that the database needs to be locked.
|
||||
/// </summary>
|
||||
void SetShutdown();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current database
|
||||
/// </summary>
|
||||
Database GetDb();
|
||||
|
||||
/// <summary>
|
||||
/// Tell the app that the file from ioc was opened with keyfile.
|
||||
/// </summary>
|
||||
void StoreOpenedFileAsRecent(IOConnectionInfo ioc, string keyfile);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new database and returns it
|
||||
/// </summary>
|
||||
Database CreateNewDatabase();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the user-displayable string identified by stringKey
|
||||
/// </summary>
|
||||
string GetResourceString(UiStringKey stringKey);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the value from the preferences corresponding to key
|
||||
/// </summary>
|
||||
bool GetBooleanPreference(PreferenceKey key);
|
||||
|
||||
/// <summary>
|
||||
/// Asks the user the question "messageKey" with the options Yes/No/Cancel, calls the handler corresponding to the answer.
|
||||
/// </summary>
|
||||
void AskYesNoCancel(UiStringKey titleKey, UiStringKey messageKey,
|
||||
EventHandler<DialogClickEventArgs> yesHandler,
|
||||
EventHandler<DialogClickEventArgs> noHandler,
|
||||
|
@ -16,20 +16,12 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Thrown when there is an error adding the keyfie to the user key
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class KeyFileException : Exception
|
||||
{
|
||||
|
@ -1,5 +1,8 @@
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Keys which can be used to get a preference setting
|
||||
/// </summary>
|
||||
public enum PreferenceKey
|
||||
{
|
||||
remember_keyfile,
|
||||
|
@ -22,6 +22,9 @@ using Java.Lang;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to run a task while a progress dialog is shown
|
||||
/// </summary>
|
||||
public class ProgressTask {
|
||||
private readonly Handler _handler;
|
||||
private readonly RunnableOnFinish _task;
|
||||
|
@ -23,6 +23,9 @@ using KeePassLib.Utility;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class providing methods to search a given database for specific things
|
||||
/// </summary>
|
||||
public class SearchDbHelper
|
||||
{
|
||||
private readonly IKp2aApp _app;
|
||||
@ -86,21 +89,21 @@ namespace keepass2android
|
||||
|
||||
}
|
||||
|
||||
private String extractHost(String url)
|
||||
private static String ExtractHost(String url)
|
||||
{
|
||||
return UrlUtil.GetHost(url.Trim());
|
||||
}
|
||||
|
||||
public PwGroup SearchForHost(Database database, String url, bool allowSubdomains)
|
||||
{
|
||||
String host = extractHost(url);
|
||||
String host = ExtractHost(url);
|
||||
string strGroupName = _app.GetResourceString(UiStringKey.search_results) + " (\"" + host + "\")";
|
||||
PwGroup pgResults = new PwGroup(true, true, strGroupName, PwIcon.EMailSearch) {IsVirtual = true};
|
||||
if (String.IsNullOrWhiteSpace(host))
|
||||
return pgResults;
|
||||
foreach (PwEntry entry in database.Entries.Values)
|
||||
{
|
||||
String otherHost = extractHost(entry.Strings.ReadSafe(PwDefs.UrlField));
|
||||
String otherHost = ExtractHost(entry.Strings.ReadSafe(PwDefs.UrlField));
|
||||
if ((allowSubdomains) && (otherHost.StartsWith("www.")))
|
||||
otherHost = otherHost.Substring(4); //remove "www."
|
||||
if (String.IsNullOrWhiteSpace(otherHost))
|
||||
|
@ -22,6 +22,9 @@ using KeePassLib.Interfaces;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// StatusLogger implementation which shows the progress in a progress dialog
|
||||
/// </summary>
|
||||
public class UpdateStatus: IStatusLogger {
|
||||
private readonly ProgressDialog _progressDialog;
|
||||
readonly IKp2aApp _app;
|
||||
|
@ -6,6 +6,9 @@ using Java.IO;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Makes attachments of PwEntries accessible when they are stored in the app cache
|
||||
/// </summary>
|
||||
[ContentProvider(new[]{"keepass2android."+AppNames.PackagePart+".provider"})]
|
||||
public class AttachmentContentProvider : ContentProvider {
|
||||
|
||||
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
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
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(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 Android.Graphics.Drawables;
|
||||
using Android.Content.Res;
|
||||
using Android.Graphics;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
public class BitmapDrawableCompat {
|
||||
|
||||
public static BitmapDrawable GetBitmapDrawable(Resources res, Bitmap bitmap) {
|
||||
return new BitmapDrawable(res, bitmap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,9 @@ using Android.Text.Method;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Launcher activity of Keepass2Android. This activity usually forwards to FileSelect but may show the revision dialog after installation or updates.
|
||||
/// </summary>
|
||||
[Activity (Label = AppNames.AppName, MainLauncher = true, Theme="@style/Base")]
|
||||
public class KeePass : LifecycleDebugActivity
|
||||
{
|
||||
|
@ -20,6 +20,10 @@ using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for activities displaying sensitive information.
|
||||
/// </summary>
|
||||
/// Checks in OnResume whether the timeout occured and the database must be locked/closed.
|
||||
public class LockCloseActivity : LockingActivity {
|
||||
|
||||
IOConnectionInfo _ioc;
|
||||
|
@ -22,7 +22,10 @@ using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Base class for list activities displaying sensitive information.
|
||||
/// </summary>
|
||||
/// Checks in OnResume whether the timeout occured and the database must be locked/closed.
|
||||
public class LockCloseListActivity : LockingListActivity {
|
||||
public LockCloseListActivity()
|
||||
{
|
||||
|
@ -20,7 +20,9 @@ using Android.Runtime;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Base class for activities. Notifies the TimeoutHelper whether the app is active or not.
|
||||
/// </summary>
|
||||
public class LockingActivity : LifecycleDebugActivity {
|
||||
|
||||
public LockingActivity (IntPtr javaReference, JniHandleOwnership transfer)
|
||||
|
@ -366,7 +366,7 @@ namespace keepass2android
|
||||
Handler handler = new Handler();
|
||||
LoadDb task = new LoadDb(App.Kp2a, _ioConnection, pass, key, new AfterLoad(handler, this));
|
||||
ProgressTask pt = new ProgressTask(App.Kp2a, this, task, UiStringKey.loading_database);
|
||||
pt.run();
|
||||
pt.Run();
|
||||
};
|
||||
|
||||
/*CheckBox checkBox = (CheckBox) FindViewById(Resource.Id.show_password);
|
||||
@ -556,7 +556,7 @@ namespace keepass2android
|
||||
private class AfterLoad : OnFinish {
|
||||
readonly PasswordActivity _act;
|
||||
public AfterLoad(Handler handler, PasswordActivity act):base(handler) {
|
||||
this._act = act;
|
||||
_act = act;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
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
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(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.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Android.Content.PM;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
public class Interaction {
|
||||
/**
|
||||
* Indicates whether the specified action can be used as an intent. This
|
||||
* method queries the package manager for installed packages that can
|
||||
* respond to an intent with the specified action. If no suitable package is
|
||||
* found, this method returns false.
|
||||
*
|
||||
* @param context The application's environment.
|
||||
* @param action The Intent action to check for availability.
|
||||
*
|
||||
* @return True if an Intent with the specified action can be sent and
|
||||
* responded to, false otherwise.
|
||||
*/
|
||||
public static bool isIntentAvailable(Context context, String action, String type) {
|
||||
PackageManager packageManager = context.PackageManager;
|
||||
Intent intent = new Intent(action);
|
||||
if (type != null)
|
||||
intent.SetType(type);
|
||||
IList<ResolveInfo> list =
|
||||
packageManager.QueryIntentActivities(intent,
|
||||
PackageInfoFlags.MatchDefaultOnly);
|
||||
foreach (ResolveInfo i in list)
|
||||
Android.Util.Log.Debug("DEBUG", i.ActivityInfo.ApplicationInfo.PackageName);
|
||||
return list.Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -101,18 +101,43 @@ namespace keepass2android
|
||||
te.Text = str;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicates whether the specified action can be used as an intent. This
|
||||
* method queries the package manager for installed packages that can
|
||||
* respond to an intent with the specified action. If no suitable package is
|
||||
* found, this method returns false.
|
||||
*
|
||||
* @param context The application's environment.
|
||||
* @param action The Intent action to check for availability.
|
||||
*
|
||||
* @return True if an Intent with the specified action can be sent and
|
||||
* responded to, false otherwise.
|
||||
*/
|
||||
static bool IsIntentAvailable(Context context, String action, String type)
|
||||
{
|
||||
PackageManager packageManager = context.PackageManager;
|
||||
Intent intent = new Intent(action);
|
||||
if (type != null)
|
||||
intent.SetType(type);
|
||||
IList<ResolveInfo> list =
|
||||
packageManager.QueryIntentActivities(intent,
|
||||
PackageInfoFlags.MatchDefaultOnly);
|
||||
foreach (ResolveInfo i in list)
|
||||
Android.Util.Log.Debug("DEBUG", i.ActivityInfo.ApplicationInfo.PackageName);
|
||||
return list.Count > 0;
|
||||
}
|
||||
|
||||
public static void showBrowseDialog(string filename, Activity act, int requestCodeBrowse, bool forSaving)
|
||||
{
|
||||
if ((!forSaving) && (Interaction.isIntentAvailable(act, Intent.ActionGetContent, "file/*"))) {
|
||||
if ((!forSaving) && (IsIntentAvailable(act, Intent.ActionGetContent, "file/*"))) {
|
||||
Intent i = new Intent(Intent.ActionGetContent);
|
||||
i.SetType("file/*");
|
||||
|
||||
act.StartActivityForResult(i, requestCodeBrowse);
|
||||
return;
|
||||
}
|
||||
if (Interaction.isIntentAvailable(act, Intents.FileBrowse, null))
|
||||
if (IsIntentAvailable(act, Intents.FileBrowse, null))
|
||||
{
|
||||
Intent i = new Intent(Intents.FileBrowse);
|
||||
if (filename != null)
|
||||
|
@ -25,6 +25,9 @@ using Android.Preferences;
|
||||
namespace keepass2android
|
||||
{
|
||||
#if NoNet
|
||||
/// <summary>
|
||||
/// Static strings containing App names for the Offline ("nonet") release
|
||||
/// </summary>
|
||||
public static class AppNames
|
||||
{
|
||||
public const string AppName = "@string/app_name_nonet";
|
||||
@ -33,6 +36,9 @@ namespace keepass2android
|
||||
public const string PackagePart = "keepass2android_nonet";
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Static strings containing App names for the Online release
|
||||
/// </summary>
|
||||
public static class AppNames
|
||||
{
|
||||
public const string AppName = "@string/app_name";
|
||||
|
@ -63,8 +63,11 @@ namespace keepass2android
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// base class for "tasks": this are things the user wants to do and which require several activities
|
||||
/// base class for "tasks": these are things the user wants to do and which require several activities
|
||||
/// </summary>
|
||||
/// Therefore AppTasks need to be serializable to bundles and intents to "survive" saving to instance state and changing activities.
|
||||
/// An AppTask has a type and may have several parameters ("extras").
|
||||
/// Activities call the task at special points so tasks can change the behaviour at these points.
|
||||
public abstract class AppTask
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -23,22 +23,22 @@ namespace keepass2android
|
||||
{
|
||||
|
||||
public class ActivityCompat {
|
||||
private static MethodInfo invalidateOptMenuMethod;
|
||||
private static MethodInfo _invalidateOptMenuMethod;
|
||||
|
||||
|
||||
|
||||
public static void InvalidateOptionsMenu(Activity act) {
|
||||
|
||||
try {
|
||||
invalidateOptMenuMethod = act.GetType().GetMethod("InvalidateOptionsMenu", new Type[]{});
|
||||
_invalidateOptMenuMethod = act.GetType().GetMethod("InvalidateOptionsMenu", new Type[]{});
|
||||
} catch (Exception)
|
||||
{
|
||||
// Do nothing if method doesn't exist
|
||||
}
|
||||
|
||||
if (invalidateOptMenuMethod != null) {
|
||||
if (_invalidateOptMenuMethod != null) {
|
||||
try {
|
||||
invalidateOptMenuMethod.Invoke(act, (new Object[]{}));
|
||||
_invalidateOptMenuMethod.Invoke(act, (new Object[]{}));
|
||||
} catch (Exception)
|
||||
{
|
||||
// Do nothing
|
||||
|
@ -24,7 +24,9 @@ using Android.Content.PM;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Dialog to offer to install OpenIntent file manager if there's no other browser installed
|
||||
/// </summary>
|
||||
public class BrowserDialog : Dialog {
|
||||
|
||||
public BrowserDialog(Context context) : base(context)
|
||||
|
@ -24,6 +24,9 @@ using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to store the recent files in a database
|
||||
/// </summary>
|
||||
public class FileDbHelper {
|
||||
|
||||
public const String LastFilename = "lastFile";
|
||||
|
@ -27,7 +27,9 @@ using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Activity to select the file to use
|
||||
/// </summary>
|
||||
[Activity (Label = "@string/app_name",
|
||||
ConfigurationChanges=ConfigChanges.Orientation|
|
||||
ConfigChanges.KeyboardHidden,
|
||||
@ -171,7 +173,7 @@ namespace keepass2android
|
||||
App.Kp2a,
|
||||
this, create,
|
||||
UiStringKey.progress_create);
|
||||
createTask.run();
|
||||
createTask.Run();
|
||||
|
||||
|
||||
};
|
||||
|
@ -24,6 +24,9 @@ using Android.Graphics;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Factory to create password icons
|
||||
/// </summary>
|
||||
public class DrawableFactory: IDrawableFactory
|
||||
{
|
||||
private static Drawable _blank;
|
||||
@ -42,7 +45,7 @@ namespace keepass2android
|
||||
*/
|
||||
private readonly Dictionary<int/*resId*/, Drawable> _standardIconMap = new Dictionary<int, Drawable>();
|
||||
|
||||
public void assignDrawableTo (ImageView iv, Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId)
|
||||
public void AssignDrawableTo (ImageView iv, Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId)
|
||||
{
|
||||
Drawable draw = GetIconDrawable (res, db, icon, customIconId);
|
||||
iv.SetImageDrawable (draw);
|
||||
|
@ -22,42 +22,43 @@ using KeePassLib;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Stores the default pw entry icons
|
||||
/// </summary>
|
||||
public class Icons
|
||||
{
|
||||
private static Dictionary<PwIcon, int> _icons;
|
||||
|
||||
private static void BuildList()
|
||||
{
|
||||
if (_icons == null)
|
||||
if (_icons != null) return;
|
||||
|
||||
_icons = new Dictionary<PwIcon, int>();
|
||||
|
||||
FieldInfo[] fields = typeof(Resource.Drawable).GetFields(BindingFlags.Static | BindingFlags.Public);
|
||||
foreach (FieldInfo fieldInfo in fields)
|
||||
{
|
||||
_icons = new Dictionary<PwIcon, int>();
|
||||
String fieldName = fieldInfo.Name;
|
||||
|
||||
FieldInfo[] fields = typeof(Resource.Drawable).GetFields(BindingFlags.Static | BindingFlags.Public);
|
||||
foreach (FieldInfo fieldInfo in fields)
|
||||
if (fieldName.StartsWith("ic") && (fieldName.Length >= 4))
|
||||
{
|
||||
String fieldName = fieldInfo.Name;
|
||||
|
||||
if (fieldName.StartsWith("ic") && (fieldName.Length >= 4))
|
||||
String sNum = fieldName.Substring(2, 2);
|
||||
int num;
|
||||
if (int.TryParse(sNum, out num) && (num < (int)PwIcon.Count))
|
||||
{
|
||||
|
||||
String sNum = fieldName.Substring(2, 2);
|
||||
int num;
|
||||
if (int.TryParse(sNum, out num) && (num < (int)PwIcon.Count))
|
||||
int resId;
|
||||
try
|
||||
{
|
||||
|
||||
int resId;
|
||||
try
|
||||
{
|
||||
resId = (int)fieldInfo.GetValue(null);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_icons[(PwIcon)num] = resId;
|
||||
resId = (int)fieldInfo.GetValue(null);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_icons[(PwIcon)num] = resId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,9 @@ using System;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Contains constants to be used in intents
|
||||
/// </summary>
|
||||
public class Intents {
|
||||
public const String Timeout = "keepass2android.timeout";
|
||||
|
||||
|
@ -21,7 +21,9 @@ using Android.Content;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Password generator
|
||||
/// </summary>
|
||||
public class PasswordGenerator {
|
||||
private const String UpperCaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
private const String LowerCaseChars = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
@ -25,6 +25,9 @@ using keepass2android.search;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Activity to display search options
|
||||
/// </summary>
|
||||
[Activity (Label = "@string/app_name", Theme="@style/Base")]
|
||||
public class SearchActivity : LifecycleDebugActivity
|
||||
{
|
||||
|
@ -25,6 +25,9 @@ using KeePassLib;
|
||||
|
||||
namespace keepass2android.search
|
||||
{
|
||||
/// <summary>
|
||||
/// Activity to show search results
|
||||
/// </summary>
|
||||
[Activity (Label = "@string/app_name", Theme="@style/NoTitleBar")]
|
||||
[MetaData("android.app.searchable",Resource="@xml/searchable")]
|
||||
[IntentFilter(new[]{Intent.ActionSearch}, Categories=new[]{Intent.CategoryDefault})]
|
||||
|
@ -33,6 +33,12 @@ using KeePass.Util.Spr;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Service to show the notifications to make the current entry accessible through clipboard or the KP2A keyboard.
|
||||
/// </summary>
|
||||
/// The name reflects only the possibility through clipboard because keyboard was introduced later.
|
||||
/// The notifications require to be displayed by a service in order to be kept when the activity is closed
|
||||
/// after searching for a URL.
|
||||
[Service]
|
||||
public class CopyToClipboardService: Service
|
||||
{
|
||||
|
@ -23,9 +23,11 @@ using Android.Graphics;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
//This service is started as soon as a Database with QuickUnlock enabled is opened.
|
||||
//Its only purpose is to be a foreground service which prevents the App from being killed (in most situations)
|
||||
[Service]
|
||||
/// <summary>
|
||||
/// This service is started as soon as a Database with QuickUnlock enabled is opened.
|
||||
/// Its only purpose is to be a foreground service which prevents the App from being killed (in most situations)
|
||||
/// </summary>
|
||||
[Service]
|
||||
public class QuickUnlockForegroundService : Service
|
||||
{
|
||||
public override IBinder OnBind(Intent intent)
|
||||
|
@ -24,6 +24,9 @@ using Android.Util;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages timeout to lock the database after some idle time
|
||||
/// </summary>
|
||||
[Service]
|
||||
public class TimeoutService : Service {
|
||||
private const String Tag = "KeePass2Android Timer";
|
||||
|
@ -26,6 +26,9 @@ using KeePassLib.Cryptography.Cipher;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
/// <summary>
|
||||
/// Activity to configure the app
|
||||
/// </summary>
|
||||
[Activity (Label = "@string/app_name", Theme="@style/NoTitleBar")]
|
||||
public class AppSettingsActivity : LockingClosePreferenceActivity {
|
||||
public static bool KeyfileDefault = false;
|
||||
@ -80,7 +83,7 @@ namespace keepass2android
|
||||
}
|
||||
}));
|
||||
ProgressTask pt = new ProgressTask(App.Kp2a, this, save, UiStringKey.saving_database);
|
||||
pt.run();
|
||||
pt.Run();
|
||||
};
|
||||
|
||||
Preference databaseName = FindPreference(GetString(Resource.String.database_name_key));
|
||||
@ -102,7 +105,7 @@ namespace keepass2android
|
||||
}
|
||||
}));
|
||||
ProgressTask pt = new ProgressTask(App.Kp2a, this, save, UiStringKey.saving_database);
|
||||
pt.run();
|
||||
pt.Run();
|
||||
};
|
||||
|
||||
|
||||
|
@ -21,7 +21,9 @@ using Android.Preferences;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Utility class to simplify access to the app preferences
|
||||
/// </summary>
|
||||
public class PrefsUtil {
|
||||
public static float GetListTextSize(Context ctx) {
|
||||
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(ctx);
|
||||
|
@ -26,7 +26,9 @@ using Android.Util;
|
||||
|
||||
namespace keepass2android.settings
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Represents the setting for the number of key transformation rounds. Changing this requires to save the database.
|
||||
/// </summary>
|
||||
public class RoundsPreference : DialogPreference {
|
||||
|
||||
internal PwDatabase PwDatabase;
|
||||
@ -80,7 +82,7 @@ namespace keepass2android.settings
|
||||
Handler handler = new Handler();
|
||||
SaveDb save = new SaveDb(Context, App.Kp2a.GetDb(), new AfterSave(Context, handler, oldRounds, this));
|
||||
ProgressTask pt = new ProgressTask(App.Kp2a, Context, save, UiStringKey.saving_database);
|
||||
pt.run();
|
||||
pt.Run();
|
||||
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,66 @@ using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Helper class to simplify usage of timeout (lock after idle time) from the activities
|
||||
/// </summary>
|
||||
public class TimeoutHelper {
|
||||
|
||||
class Timeout
|
||||
{
|
||||
private const int RequestId = 0;
|
||||
private const long DefaultTimeout = 5 * 60 * 1000; // 5 minutes
|
||||
private const String Tag = "Keepass2Android Timeout";
|
||||
|
||||
private static PendingIntent BuildIntent(Context ctx)
|
||||
{
|
||||
Intent intent = new Intent(Intents.Timeout);
|
||||
PendingIntent sender = PendingIntent.GetBroadcast(ctx, RequestId, intent, PendingIntentFlags.CancelCurrent);
|
||||
|
||||
return sender;
|
||||
}
|
||||
|
||||
public static void Start(Context ctx)
|
||||
{
|
||||
|
||||
|
||||
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(ctx);
|
||||
String sTimeout = prefs.GetString(ctx.GetString(Resource.String.app_timeout_key), ctx.GetString(Resource.String.clipboard_timeout_default));
|
||||
|
||||
long timeout;
|
||||
if (!long.TryParse(sTimeout, out timeout))
|
||||
{
|
||||
timeout = DefaultTimeout;
|
||||
}
|
||||
|
||||
if (timeout == -1)
|
||||
{
|
||||
// No timeout don't start timeout service
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.StartService(new Intent(ctx, typeof(TimeoutService)));
|
||||
|
||||
long triggerTime = Java.Lang.JavaSystem.CurrentTimeMillis() + timeout;
|
||||
AlarmManager am = (AlarmManager)ctx.GetSystemService(Context.AlarmService);
|
||||
|
||||
Log.Debug(Tag, "Timeout start");
|
||||
am.Set(AlarmType.Rtc, triggerTime, BuildIntent(ctx));
|
||||
}
|
||||
|
||||
public static void Cancel(Context ctx)
|
||||
{
|
||||
AlarmManager am = (AlarmManager)ctx.GetSystemService(Context.AlarmService);
|
||||
|
||||
Log.Debug(Tag, "Timeout cancel");
|
||||
am.Cancel(BuildIntent(ctx));
|
||||
|
||||
ctx.StopService(new Intent(ctx, typeof(TimeoutService)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void Pause(Activity act) {
|
||||
// Record timeout time in case timeout service is killed
|
||||
long time = Java.Lang.JavaSystem.CurrentTimeMillis();
|
||||
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
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
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(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 Android.App;
|
||||
using Android.Content;
|
||||
using Android.Preferences;
|
||||
using Android.Util;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
|
||||
public class Timeout {
|
||||
private const int RequestId = 0;
|
||||
private const long DefaultTimeout = 5 * 60 * 1000; // 5 minutes
|
||||
private const String Tag = "Keepass2Android Timeout";
|
||||
|
||||
private static PendingIntent BuildIntent(Context ctx) {
|
||||
Intent intent = new Intent(Intents.Timeout);
|
||||
PendingIntent sender = PendingIntent.GetBroadcast(ctx, RequestId, intent, PendingIntentFlags.CancelCurrent);
|
||||
|
||||
return sender;
|
||||
}
|
||||
|
||||
public static void Start(Context ctx) {
|
||||
|
||||
|
||||
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(ctx);
|
||||
String sTimeout = prefs.GetString(ctx.GetString(Resource.String.app_timeout_key), ctx.GetString(Resource.String.clipboard_timeout_default));
|
||||
|
||||
long timeout;
|
||||
if (!long.TryParse(sTimeout, out timeout))
|
||||
{
|
||||
timeout = DefaultTimeout;
|
||||
}
|
||||
|
||||
if ( timeout == -1 ) {
|
||||
// No timeout don't start timeout service
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.StartService(new Intent(ctx, typeof(TimeoutService)));
|
||||
|
||||
long triggerTime = Java.Lang.JavaSystem.CurrentTimeMillis() + timeout;
|
||||
AlarmManager am = (AlarmManager) ctx.GetSystemService(Context.AlarmService);
|
||||
|
||||
Log.Debug(Tag, "Timeout start");
|
||||
am.Set(AlarmType.Rtc, triggerTime, BuildIntent(ctx));
|
||||
}
|
||||
|
||||
public static void Cancel(Context ctx) {
|
||||
AlarmManager am = (AlarmManager) ctx.GetSystemService(Context.AlarmService);
|
||||
|
||||
Log.Debug(Tag, "Timeout cancel");
|
||||
am.Cancel(BuildIntent(ctx));
|
||||
|
||||
ctx.StopService(new Intent(ctx, typeof(TimeoutService)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user