1package eu.siacs.conversations.ui;
2
3import eu.siacs.conversations.services.XmppConnectionService;
4import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
5import android.app.Activity;
6import android.app.AlertDialog;
7import android.app.AlertDialog.Builder;
8import android.content.ComponentName;
9import android.content.Context;
10import android.content.Intent;
11import android.content.ServiceConnection;
12import android.os.IBinder;
13import android.view.View;
14import android.view.inputmethod.InputMethodManager;
15
16public abstract class XmppActivity extends Activity {
17 public XmppConnectionService xmppConnectionService;
18 public boolean xmppConnectionServiceBound = false;
19 protected boolean handledViewIntent = false;
20 protected ServiceConnection mConnection = new ServiceConnection() {
21
22 @Override
23 public void onServiceConnected(ComponentName className, IBinder service) {
24 XmppConnectionBinder binder = (XmppConnectionBinder) service;
25 xmppConnectionService = binder.getService();
26 xmppConnectionServiceBound = true;
27 onBackendConnected();
28 }
29
30 @Override
31 public void onServiceDisconnected(ComponentName arg0) {
32 xmppConnectionServiceBound = false;
33 }
34 };
35
36 @Override
37 protected void onStart() {
38 startService(new Intent(this, XmppConnectionService.class));
39 super.onStart();
40 if (!xmppConnectionServiceBound) {
41 Intent intent = new Intent(this, XmppConnectionService.class);
42 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
43 }
44 }
45
46 @Override
47 protected void onStop() {
48 super.onStop();
49 if (xmppConnectionServiceBound) {
50 unbindService(mConnection);
51 xmppConnectionServiceBound = false;
52 }
53 }
54
55 protected void hideKeyboard() {
56 InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
57
58 View focus = getCurrentFocus();
59
60 if (focus != null) {
61
62 inputManager.hideSoftInputFromWindow(
63 focus.getWindowToken(),
64 InputMethodManager.HIDE_NOT_ALWAYS);
65 }
66 }
67
68 public boolean hasPgp() {
69 if (xmppConnectionService.getPgpEngine()!=null) {
70 return true;
71 } else {
72 Builder builder = new AlertDialog.Builder(getApplicationContext());
73 builder.setTitle("OpenKeychain not found");
74 builder.setIconAttribute(android.R.attr.alertDialogIcon);
75 builder.setMessage("Please make sure you have installed OpenKeychain");
76 builder.create().show();
77 return false;
78 }
79 }
80
81 abstract void onBackendConnected();
82}