Show progress bar in ActionBar while loading cached CA certificates
[strongswan.git] / src / frontends / android / src / org / strongswan / android / ui / MainActivity.java
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2012 Giuliano Grassi
4 * Copyright (C) 2012 Ralf Sager
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 package org.strongswan.android.ui;
19
20 import org.strongswan.android.logic.TrustedCertificateManager;
21
22 import android.app.ActionBar;
23 import android.app.Activity;
24 import android.content.Intent;
25 import android.net.VpnService;
26 import android.os.Bundle;
27 import android.view.Window;
28
29 public class MainActivity extends Activity
30 {
31 @Override
32 public void onCreate(Bundle savedInstanceState)
33 {
34 super.onCreate(savedInstanceState);
35 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
36 setContentView(R.layout.main);
37 startVpnService();
38
39 ActionBar bar = getActionBar();
40 bar.setDisplayShowTitleEnabled(false);
41
42 /* load CA certificates in a background thread */
43 setProgressBarIndeterminateVisibility(true);
44 new Thread(new Runnable() {
45 @Override
46 public void run()
47 {
48 TrustedCertificateManager.getInstance().load();
49 runOnUiThread(new Runnable() {
50 @Override
51 public void run()
52 {
53 setProgressBarIndeterminateVisibility(false);
54 }
55 });
56 }
57 }).start();
58 }
59
60 private void startVpnService()
61 {
62 Intent intent = VpnService.prepare(this);
63 if (intent != null)
64 {
65 startActivityForResult(intent, 0);
66 }
67 else
68 {
69 onActivityResult(0, RESULT_OK, null);
70 }
71 }
72
73 @Override
74 protected void onActivityResult(int requestCode, int resultCode, Intent data)
75 {
76 if (resultCode == RESULT_OK)
77 {
78 Intent intent = new Intent(this, CharonVpnService.class);
79 startService(intent);
80 }
81 }
82 }