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;
|
2013-09-28 01:46:44 -04:00
|
|
|
using System.Collections;
|
2013-02-23 11:43:42 -05:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using Android.App;
|
|
|
|
using Android.Content;
|
2013-10-07 00:28:06 -04:00
|
|
|
using Android.Database;
|
2014-05-18 12:01:17 -04:00
|
|
|
using Android.Preferences;
|
2013-10-07 00:28:06 -04:00
|
|
|
using Android.Provider;
|
2013-10-12 16:20:02 -04:00
|
|
|
using Android.Views;
|
2013-02-23 11:43:42 -05:00
|
|
|
using Android.Widget;
|
2013-03-23 16:19:37 -04:00
|
|
|
using Android.Content.PM;
|
2013-10-12 16:20:02 -04:00
|
|
|
using KeePassLib.Serialization;
|
2013-09-28 01:46:44 -04:00
|
|
|
using Uri = Android.Net.Uri;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
namespace keepass2android
|
|
|
|
{
|
|
|
|
|
|
|
|
public class Util {
|
2013-10-02 21:49:04 -04:00
|
|
|
public static String GetClipboard(Context context) {
|
2013-02-23 11:43:42 -05:00
|
|
|
Android.Text.ClipboardManager clipboard = (Android.Text.ClipboardManager) context.GetSystemService(Context.ClipboardService);
|
|
|
|
return clipboard.Text;
|
|
|
|
}
|
|
|
|
|
2013-10-02 21:49:04 -04:00
|
|
|
public static void CopyToClipboard(Context context, String text) {
|
2013-02-23 11:43:42 -05:00
|
|
|
Android.Text.ClipboardManager clipboard = (Android.Text.ClipboardManager) context.GetSystemService(Context.ClipboardService);
|
|
|
|
clipboard.Text = text;
|
|
|
|
}
|
|
|
|
|
2013-10-02 21:49:04 -04:00
|
|
|
public static void GotoUrl(Context context, String url) {
|
2014-05-29 14:28:49 -04:00
|
|
|
if ( !string.IsNullOrEmpty(url) ) {
|
2013-06-01 09:51:54 -04:00
|
|
|
|
|
|
|
if (url.StartsWith("androidapp://"))
|
|
|
|
{
|
|
|
|
string packageName = url.Substring("androidapp://".Length);
|
|
|
|
Intent startKp2aIntent = context.PackageManager.GetLaunchIntentForPackage(packageName);
|
|
|
|
if (startKp2aIntent != null)
|
|
|
|
{
|
|
|
|
startKp2aIntent.AddCategory(Intent.CategoryLauncher);
|
|
|
|
startKp2aIntent.AddFlags(ActivityFlags.NewTask);
|
|
|
|
context.StartActivity(startKp2aIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-02 21:49:04 -04:00
|
|
|
Uri uri = Uri.Parse(url);
|
2013-06-01 09:51:54 -04:00
|
|
|
context.StartActivity(new Intent(Intent.ActionView, uri));
|
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-02 21:49:04 -04:00
|
|
|
public static void GotoUrl(Context context, int resId) {
|
|
|
|
GotoUrl(context, context.GetString(resId));
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2013-03-23 16:19:37 -04:00
|
|
|
|
2013-10-02 21:49:04 -04:00
|
|
|
public static void GotoMarket(Context context)
|
2013-03-23 16:19:37 -04:00
|
|
|
{
|
2013-10-02 21:49:04 -04:00
|
|
|
GotoUrl(context, context.GetString(Resource.String.MarketURL)+context.PackageName);
|
2013-03-23 16:19:37 -04:00
|
|
|
}
|
2013-04-09 16:59:33 -04:00
|
|
|
|
2014-05-18 12:01:17 -04:00
|
|
|
public static bool GotoDonateUrl(Context context)
|
2013-04-09 16:59:33 -04:00
|
|
|
{
|
|
|
|
string donateUrl = context.GetString(Resource.String.donate_url,
|
|
|
|
new Java.Lang.Object[]{context.Resources.Configuration.Locale.Language,
|
|
|
|
context.PackageName
|
|
|
|
});
|
2014-05-18 12:01:17 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
GotoUrl(context, donateUrl);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (ActivityNotFoundException)
|
|
|
|
{
|
|
|
|
Toast.MakeText(context, Resource.String.error_failed_to_launch_link, ToastLength.Long).Show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-09 16:59:33 -04:00
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2013-06-25 15:27:41 -04:00
|
|
|
public static String GetEditText(Activity act, int resId) {
|
2013-02-23 11:43:42 -05:00
|
|
|
TextView te = (TextView) act.FindViewById(resId);
|
|
|
|
System.Diagnostics.Debug.Assert(te != null);
|
|
|
|
|
|
|
|
if (te != null) {
|
2013-06-25 15:27:41 -04:00
|
|
|
return te.Text;
|
2013-02-23 11:43:42 -05:00
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:27:41 -04:00
|
|
|
public static void SetEditText(Activity act, int resId, String str) {
|
2013-02-23 11:43:42 -05:00
|
|
|
TextView te = (TextView) act.FindViewById(resId);
|
|
|
|
System.Diagnostics.Debug.Assert(te != null);
|
|
|
|
|
|
|
|
if (te != null) {
|
|
|
|
te.Text = str;
|
|
|
|
}
|
|
|
|
}
|
2013-06-15 16:02:48 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-12-16 00:50:02 -05:00
|
|
|
static bool IsIntentAvailable(Context context, String action, String type, List<String> categories )
|
2013-06-15 16:02:48 -04:00
|
|
|
{
|
|
|
|
PackageManager packageManager = context.PackageManager;
|
|
|
|
Intent intent = new Intent(action);
|
|
|
|
if (type != null)
|
|
|
|
intent.SetType(type);
|
2013-12-16 00:50:02 -05:00
|
|
|
if (categories != null)
|
|
|
|
categories.ForEach(c => intent.AddCategory(c));
|
2013-06-15 16:02:48 -04:00
|
|
|
IList<ResolveInfo> list =
|
|
|
|
packageManager.QueryIntentActivities(intent,
|
|
|
|
PackageInfoFlags.MatchDefaultOnly);
|
|
|
|
foreach (ResolveInfo i in list)
|
2013-07-06 10:11:38 -04:00
|
|
|
Kp2aLog.Log(i.ActivityInfo.ApplicationInfo.PackageName);
|
2013-06-15 16:02:48 -04:00
|
|
|
return list.Count > 0;
|
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2014-11-08 15:29:36 -05:00
|
|
|
public static void ShowBrowseDialog(Activity act, int requestCodeBrowse, bool forSaving)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2013-12-16 00:50:02 -05:00
|
|
|
if ((!forSaving) && (IsIntentAvailable(act, Intent.ActionGetContent, "*/*", new List<string> { Intent.CategoryOpenable})))
|
2013-10-07 00:28:06 -04:00
|
|
|
{
|
2013-04-26 06:43:06 -04:00
|
|
|
Intent i = new Intent(Intent.ActionGetContent);
|
2013-12-16 00:50:02 -05:00
|
|
|
i.SetType("*/*");
|
|
|
|
i.AddCategory(Intent.CategoryOpenable);
|
2013-04-26 06:43:06 -04:00
|
|
|
|
|
|
|
act.StartActivityForResult(i, requestCodeBrowse);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-07 00:28:06 -04:00
|
|
|
string defaultPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
|
|
|
|
|
|
|
|
|
|
|
|
ShowInternalLocalFileChooser(act, requestCodeBrowse, forSaving, defaultPath);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-07 00:28:06 -04:00
|
|
|
private static void ShowInternalLocalFileChooser(Activity act, int requestCodeBrowse, bool forSaving, string defaultPath)
|
|
|
|
{
|
2013-11-12 22:13:45 -05:00
|
|
|
|
|
|
|
#if !EXCLUDE_FILECHOOSER
|
2013-12-26 00:31:40 -05:00
|
|
|
string fileProviderAuthority = act.PackageName+".android-filechooser.localfile";
|
2013-10-07 00:28:06 -04:00
|
|
|
|
|
|
|
Intent i = Keepass2android.Kp2afilechooser.Kp2aFileChooserBridge.GetLaunchFileChooserIntent(act,
|
|
|
|
fileProviderAuthority,
|
|
|
|
defaultPath);
|
|
|
|
if (forSaving)
|
|
|
|
i.PutExtra("group.pals.android.lib.ui.filechooser.FileChooserActivity.save_dialog", true);
|
|
|
|
|
|
|
|
act.StartActivityForResult(i, requestCodeBrowse);
|
2013-10-07 01:11:47 -04:00
|
|
|
#else
|
|
|
|
Toast.MakeText(act, "File Chooser excluded!",ToastLength.Long).Show();
|
|
|
|
#endif
|
2013-10-07 00:28:06 -04:00
|
|
|
}
|
|
|
|
|
2013-09-28 01:46:44 -04:00
|
|
|
public static string IntentToFilename(Intent data, Context ctx)
|
2013-04-26 06:43:06 -04:00
|
|
|
{
|
2013-09-28 15:14:21 -04:00
|
|
|
#if !EXCLUDE_FILECHOOSER
|
2013-09-28 01:46:44 -04:00
|
|
|
string EXTRA_RESULTS = "group.pals.android.lib.ui.filechooser.FileChooserActivity.results";
|
|
|
|
if (data.HasExtra(EXTRA_RESULTS))
|
|
|
|
{
|
|
|
|
IList uris = data.GetParcelableArrayListExtra(EXTRA_RESULTS);
|
|
|
|
Uri uri = (Uri) uris[0];
|
|
|
|
return Group.Pals.Android.Lib.UI.Filechooser.Providers.BaseFileProviderUtils.GetRealUri(ctx, uri).ToString();
|
|
|
|
}
|
2013-10-07 00:28:06 -04:00
|
|
|
|
2013-09-28 15:14:21 -04:00
|
|
|
#endif
|
2013-10-07 00:28:06 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Uri uri = data.Data;
|
|
|
|
if ((uri != null) && (uri.Scheme == "content"))
|
|
|
|
{
|
|
|
|
String[] col = new String[] {MediaStore.MediaColumns.Data};
|
|
|
|
|
|
|
|
ICursor c1 = ctx.ContentResolver.Query(uri, col, null, null, null);
|
|
|
|
c1.MoveToFirst();
|
|
|
|
|
|
|
|
return c1.GetString(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Kp2aLog.Log(e.ToString());
|
|
|
|
}
|
2013-09-28 01:46:44 -04:00
|
|
|
|
2013-04-26 06:43:06 -04:00
|
|
|
String filename = data.Data.Path;
|
|
|
|
if (String.IsNullOrEmpty(filename))
|
|
|
|
filename = data.DataString;
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2013-04-28 16:46:31 -04:00
|
|
|
public static bool HasActionBar(Activity activity)
|
|
|
|
{
|
|
|
|
//Actionbar is available since 11, but the layout has its own "pseudo actionbar" until 13
|
|
|
|
return ((int)Android.OS.Build.VERSION.SdkInt >= 14) && (activity.ActionBar != null);
|
|
|
|
}
|
2013-10-12 16:20:02 -04:00
|
|
|
|
2013-12-16 00:50:02 -05:00
|
|
|
public delegate bool FileSelectedHandler(string filename);
|
2013-10-12 16:20:02 -04:00
|
|
|
|
2014-11-08 15:29:36 -05:00
|
|
|
public static void ShowSftpDialog(Activity activity, FileSelectedHandler onStartBrowse, Action onCancel)
|
2013-12-31 03:46:57 -05:00
|
|
|
{
|
2014-01-26 08:27:27 -05:00
|
|
|
#if !EXCLUDE_JAVAFILESTORAGE
|
2013-12-31 03:46:57 -05:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
|
View dlgContents = activity.LayoutInflater.Inflate(Resource.Layout.sftpcredentials, null);
|
|
|
|
builder.SetView(dlgContents);
|
|
|
|
builder.SetPositiveButton(Android.Resource.String.Ok,
|
|
|
|
(sender, args) =>
|
|
|
|
{
|
|
|
|
string host = dlgContents.FindViewById<EditText>(Resource.Id.sftp_host).Text;
|
|
|
|
string portText = dlgContents.FindViewById<EditText>(Resource.Id.sftp_port).Text;
|
|
|
|
int port = Keepass2android.Javafilestorage.SftpStorage.DefaultSftpPort;
|
|
|
|
if (!string.IsNullOrEmpty(portText))
|
|
|
|
int.TryParse(portText, out port);
|
|
|
|
string user = dlgContents.FindViewById<EditText>(Resource.Id.sftp_user).Text;
|
|
|
|
string password = dlgContents.FindViewById<EditText>(Resource.Id.sftp_password).Text;
|
|
|
|
string initialPath = dlgContents.FindViewById<EditText>(Resource.Id.sftp_initial_dir).Text;
|
|
|
|
string sftpPath = new Keepass2android.Javafilestorage.SftpStorage().BuildFullPath(host, port, initialPath, user,
|
|
|
|
password);
|
|
|
|
onStartBrowse(sftpPath);
|
|
|
|
});
|
2014-11-08 15:29:36 -05:00
|
|
|
builder.SetNegativeButton(Android.Resource.String.Cancel, onCancel);
|
2013-12-31 03:46:57 -05:00
|
|
|
builder.SetTitle(activity.GetString(Resource.String.enter_sftp_login_title));
|
|
|
|
Dialog dialog = builder.Create();
|
|
|
|
|
|
|
|
dialog.Show();
|
2014-01-26 08:27:27 -05:00
|
|
|
#endif
|
2013-12-31 03:46:57 -05:00
|
|
|
}
|
|
|
|
|
2014-11-08 15:29:36 -05:00
|
|
|
class DismissListener: Java.Lang.Object, IDialogInterfaceOnDismissListener
|
|
|
|
{
|
|
|
|
private readonly Action _onDismiss;
|
|
|
|
|
|
|
|
public DismissListener(Action onDismiss)
|
|
|
|
{
|
|
|
|
_onDismiss = onDismiss;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnDismiss(IDialogInterface dialog)
|
|
|
|
{
|
|
|
|
_onDismiss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 00:24:35 -05:00
|
|
|
|
|
|
|
class CancelListener: Java.Lang.Object, IDialogInterfaceOnCancelListener
|
|
|
|
{
|
|
|
|
private readonly Action _onCancel;
|
|
|
|
|
|
|
|
public CancelListener(Action onCancel)
|
|
|
|
{
|
|
|
|
_onCancel = onCancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnCancel(IDialogInterface dialog)
|
|
|
|
{
|
|
|
|
_onCancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-08 15:29:36 -05:00
|
|
|
public static void ShowFilenameDialog(Activity activity, FileSelectedHandler onOpen, FileSelectedHandler onCreate, Action onCancel, bool showBrowseButton, string defaultFilename, string detailsText, int requestCodeBrowse)
|
2013-10-12 16:20:02 -04:00
|
|
|
{
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
|
builder.SetView(activity.LayoutInflater.Inflate(Resource.Layout.file_selection_filename, null));
|
2014-11-18 00:24:35 -05:00
|
|
|
|
|
|
|
if (onCancel != null)
|
|
|
|
builder.SetOnCancelListener(new CancelListener(onCancel));
|
2013-10-12 16:20:02 -04:00
|
|
|
Dialog dialog = builder.Create();
|
|
|
|
dialog.Show();
|
|
|
|
|
|
|
|
Button openButton = (Button) dialog.FindViewById(Resource.Id.open);
|
|
|
|
Button createButton = (Button) dialog.FindViewById(Resource.Id.create);
|
2014-11-08 15:29:36 -05:00
|
|
|
|
2013-10-12 16:20:02 -04:00
|
|
|
TextView enterFilenameDetails = (TextView) dialog.FindViewById(Resource.Id.label_open_by_filename_details);
|
|
|
|
openButton.Visibility = onOpen != null ? ViewStates.Visible : ViewStates.Gone;
|
|
|
|
createButton.Visibility = onCreate != null? ViewStates.Visible : ViewStates.Gone;
|
|
|
|
// Set the initial value of the filename
|
|
|
|
EditText editFilename = (EditText) dialog.FindViewById(Resource.Id.file_filename);
|
|
|
|
editFilename.Text = defaultFilename;
|
|
|
|
enterFilenameDetails.Text = detailsText;
|
|
|
|
enterFilenameDetails.Visibility = enterFilenameDetails.Text == "" ? ViewStates.Gone : ViewStates.Visible;
|
|
|
|
|
|
|
|
// Open button
|
|
|
|
if (onOpen != null)
|
2013-10-28 16:53:18 -04:00
|
|
|
openButton.Click += (sender, args) =>
|
|
|
|
{
|
|
|
|
String fileName = ((EditText) dialog.FindViewById(Resource.Id.file_filename)).Text;
|
2013-12-16 00:50:02 -05:00
|
|
|
if (onOpen(fileName))
|
|
|
|
dialog.Dismiss();
|
2013-10-28 16:53:18 -04:00
|
|
|
};
|
2013-10-12 16:20:02 -04:00
|
|
|
|
|
|
|
// Create button
|
|
|
|
if (onCreate != null)
|
2013-10-28 16:53:18 -04:00
|
|
|
createButton.Click += (sender, args) =>
|
|
|
|
{
|
|
|
|
String fileName = ((EditText)dialog.FindViewById(Resource.Id.file_filename)).Text;
|
2013-12-16 00:50:02 -05:00
|
|
|
if (onCreate(fileName))
|
|
|
|
dialog.Dismiss();
|
2013-10-28 16:53:18 -04:00
|
|
|
};
|
2014-11-08 15:29:36 -05:00
|
|
|
|
2013-10-12 16:20:02 -04:00
|
|
|
Button cancelButton = (Button) dialog.FindViewById(Resource.Id.fnv_cancel);
|
2014-11-08 15:29:36 -05:00
|
|
|
cancelButton.Click += delegate
|
|
|
|
{
|
|
|
|
dialog.Dismiss();
|
2014-11-18 00:24:35 -05:00
|
|
|
if (onCancel != null)
|
2014-11-24 12:21:45 -05:00
|
|
|
onCancel();
|
2014-11-08 15:29:36 -05:00
|
|
|
};
|
|
|
|
|
2014-11-18 00:24:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-08 15:29:36 -05:00
|
|
|
|
2013-10-12 16:20:02 -04:00
|
|
|
|
|
|
|
ImageButton browseButton = (ImageButton) dialog.FindViewById(Resource.Id.browse_button);
|
|
|
|
if (!showBrowseButton)
|
|
|
|
{
|
|
|
|
browseButton.Visibility = ViewStates.Invisible;
|
|
|
|
}
|
|
|
|
browseButton.Click += (sender, evt) =>
|
|
|
|
{
|
|
|
|
string filename = ((EditText) dialog.FindViewById(Resource.Id.file_filename)).Text;
|
|
|
|
|
2014-11-24 12:21:45 -05:00
|
|
|
Util.ShowBrowseDialog(activity, requestCodeBrowse, onCreate != null);
|
2013-10-12 16:20:02 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2013-12-16 00:50:02 -05:00
|
|
|
|
|
|
|
public static void QueryCredentials(IOConnectionInfo ioc, Action<IOConnectionInfo> afterQueryCredentials, Activity activity)
|
|
|
|
{
|
|
|
|
//Build dialog to query credentials:
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
|
builder.SetTitle(activity.GetString(Resource.String.credentials_dialog_title));
|
|
|
|
builder.SetPositiveButton(activity.GetString(Android.Resource.String.Ok), (dlgSender, dlgEvt) =>
|
|
|
|
{
|
|
|
|
Dialog dlg = (Dialog)dlgSender;
|
|
|
|
string username = ((EditText)dlg.FindViewById(Resource.Id.cred_username)).Text;
|
|
|
|
string password = ((EditText)dlg.FindViewById(Resource.Id.cred_password)).Text;
|
|
|
|
int credentialRememberMode = ((Spinner)dlg.FindViewById(Resource.Id.cred_remember_mode)).SelectedItemPosition;
|
|
|
|
ioc.UserName = username;
|
|
|
|
ioc.Password = password;
|
|
|
|
ioc.CredSaveMode = (IOCredSaveMode)credentialRememberMode;
|
|
|
|
afterQueryCredentials(ioc);
|
|
|
|
});
|
|
|
|
builder.SetView(activity.LayoutInflater.Inflate(Resource.Layout.url_credentials, null));
|
|
|
|
builder.SetNeutralButton(activity.GetString(Android.Resource.String.Cancel),
|
|
|
|
(dlgSender, dlgEvt) => { });
|
|
|
|
Dialog dialog = builder.Create();
|
|
|
|
dialog.Show();
|
|
|
|
((EditText)dialog.FindViewById(Resource.Id.cred_username)).Text = ioc.UserName;
|
|
|
|
((EditText)dialog.FindViewById(Resource.Id.cred_password)).Text = ioc.Password;
|
|
|
|
((Spinner)dialog.FindViewById(Resource.Id.cred_remember_mode)).SetSelection((int)ioc.CredSaveMode);
|
|
|
|
}
|
2014-02-02 01:03:40 -05:00
|
|
|
|
2014-05-14 01:23:31 -04:00
|
|
|
|
|
|
|
public static void FinishAndForward(Activity activity, Intent i)
|
|
|
|
{
|
|
|
|
i.SetFlags(ActivityFlags.ForwardResult);
|
|
|
|
activity.StartActivity(i);
|
|
|
|
activity.Finish();
|
|
|
|
}
|
2014-05-18 12:01:17 -04:00
|
|
|
|
|
|
|
public static void PrepareNoDonatePreference(Context ctx, Preference preference)
|
|
|
|
{
|
|
|
|
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(ctx);
|
|
|
|
|
|
|
|
long usageCount = prefs.GetLong(ctx.GetString(Resource.String.UsageCount_key), 0);
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
preference.Enabled = (usageCount > 1);
|
|
|
|
#else
|
|
|
|
preference.Enabled = (usageCount > 50);
|
|
|
|
#endif
|
|
|
|
preference.PreferenceChange += delegate(object sender, Preference.PreferenceChangeEventArgs args)
|
|
|
|
{
|
|
|
|
if ((bool) args.NewValue)
|
|
|
|
{
|
|
|
|
new AlertDialog.Builder(ctx)
|
2014-06-05 15:40:43 -04:00
|
|
|
.SetTitle(ctx.GetString(AppNames.AppNameResource))
|
2014-05-18 12:01:17 -04:00
|
|
|
.SetCancelable(false)
|
|
|
|
.SetPositiveButton(Android.Resource.String.Ok, delegate(object o, DialogClickEventArgs eventArgs)
|
|
|
|
{
|
|
|
|
GotoDonateUrl(ctx);
|
|
|
|
((Dialog) o).Dismiss();
|
|
|
|
})
|
|
|
|
.SetMessage(Resource.String.NoDonateOption_question)
|
|
|
|
.Create().Show();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void PrepareDonateOptionMenu(IMenu menu, Context ctx)
|
|
|
|
{
|
|
|
|
var donateItem = menu.FindItem(Resource.Id.menu_donate);
|
|
|
|
if (donateItem != null)
|
|
|
|
{
|
|
|
|
donateItem.SetVisible(
|
|
|
|
!PreferenceManager.GetDefaultSharedPreferences(ctx)
|
|
|
|
.GetBoolean(ctx.GetString(Resource.String.NoDonateOption_key), false)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|