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
|
|
|
|
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.App;
|
|
|
|
using Android.Content;
|
|
|
|
using Android.OS;
|
|
|
|
using Java.Lang;
|
|
|
|
|
|
|
|
namespace keepass2android
|
|
|
|
{
|
2013-06-15 16:02:48 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Class to run a task while a progress dialog is shown
|
|
|
|
/// </summary>
|
2013-02-23 11:43:42 -05:00
|
|
|
public class ProgressTask {
|
2013-06-15 06:40:01 -04:00
|
|
|
private readonly Handler _handler;
|
|
|
|
private readonly RunnableOnFinish _task;
|
|
|
|
private readonly ProgressDialog _progressDialog;
|
|
|
|
private readonly IKp2aApp _app;
|
2013-03-06 14:44:02 -05:00
|
|
|
|
2013-06-14 00:14:50 -04:00
|
|
|
public ProgressTask(IKp2aApp app, Context ctx, RunnableOnFinish task, UiStringKey messageKey) {
|
2013-06-15 06:40:01 -04:00
|
|
|
_task = task;
|
|
|
|
_handler = new Handler();
|
|
|
|
_app = app;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
// Show process dialog
|
2013-06-15 06:40:01 -04:00
|
|
|
_progressDialog = new ProgressDialog(ctx);
|
|
|
|
_progressDialog.SetTitle(_app.GetResourceString(UiStringKey.progress_title));
|
|
|
|
_progressDialog.SetMessage(_app.GetResourceString(messageKey));
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
// Set code to run when this is finished
|
2013-06-15 06:40:01 -04:00
|
|
|
_task.SetStatus(new UpdateStatus(_app, _handler, _progressDialog));
|
|
|
|
_task.OnFinishToRun = new AfterTask(task.OnFinishToRun, _handler, _progressDialog);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public void Run() {
|
2013-02-23 11:43:42 -05:00
|
|
|
// Show process dialog
|
2013-06-15 06:40:01 -04:00
|
|
|
_progressDialog.Show();
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
// Start Thread to Run task
|
2013-06-15 06:40:01 -04:00
|
|
|
Thread t = new Thread(_task.Run);
|
2013-02-23 11:43:42 -05:00
|
|
|
t.Start();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private class AfterTask : OnFinish {
|
2013-06-15 06:40:01 -04:00
|
|
|
readonly ProgressDialog _progressDialog;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
public AfterTask (OnFinish finish, Handler handler, ProgressDialog pd): base(finish, handler)
|
|
|
|
{
|
2013-06-15 06:40:01 -04:00
|
|
|
_progressDialog = pd;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public override void Run() {
|
|
|
|
base.Run();
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
// Remove the progress dialog
|
2013-06-15 06:40:01 -04:00
|
|
|
Handler.Post(delegate {_progressDialog.Dismiss();});
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|