diff options
Diffstat (limited to 'src/eu/siacs/conversations/ui/XmppActivity.java')
-rw-r--r-- | src/eu/siacs/conversations/ui/XmppActivity.java | 174 |
1 files changed, 92 insertions, 82 deletions
diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index ca9ee490..a6cf0588 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -27,15 +27,15 @@ import android.view.View; import android.view.inputmethod.InputMethodManager; public abstract class XmppActivity extends Activity { - + public static final int REQUEST_ANNOUNCE_PGP = 0x73731; - + protected final static String LOGTAG = "xmppService"; - + public XmppConnectionService xmppConnectionService; public boolean xmppConnectionServiceBound = false; protected boolean handledViewIntent = false; - + protected ServiceConnection mConnection = new ServiceConnection() { @Override @@ -51,7 +51,7 @@ public abstract class XmppActivity extends Activity { xmppConnectionServiceBound = false; } }; - + @Override protected void onStart() { super.onStart(); @@ -59,14 +59,14 @@ public abstract class XmppActivity extends Activity { connectToBackend(); } } - + public void connectToBackend() { Intent intent = new Intent(this, XmppConnectionService.class); intent.setAction("ui"); startService(intent); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } - + @Override protected void onStop() { super.onStop(); @@ -75,7 +75,7 @@ public abstract class XmppActivity extends Activity { xmppConnectionServiceBound = false; } } - + protected void hideKeyboard() { InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); @@ -83,50 +83,52 @@ public abstract class XmppActivity extends Activity { if (focus != null) { - inputManager.hideSoftInputFromWindow( - focus.getWindowToken(), + inputManager.hideSoftInputFromWindow(focus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } - + public boolean hasPgp() { - if (xmppConnectionService.getPgpEngine()!=null) { - return true; - } else { - Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getString(R.string.openkeychain_required)); - builder.setIconAttribute(android.R.attr.alertDialogIcon); - builder.setMessage(getText(R.string.openkeychain_required_long)); - builder.setNegativeButton(getString(R.string.cancel), null); - builder.setNeutralButton(getString(R.string.restart), new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - if (xmppConnectionServiceBound) { - unbindService(mConnection); - xmppConnectionServiceBound = false; + return xmppConnectionService.getPgpEngine() != null; + } + + public void showInstallPgpDialog() { + Builder builder = new AlertDialog.Builder(this); + builder.setTitle(getString(R.string.openkeychain_required)); + builder.setIconAttribute(android.R.attr.alertDialogIcon); + builder.setMessage(getText(R.string.openkeychain_required_long)); + builder.setNegativeButton(getString(R.string.cancel), null); + builder.setNeutralButton(getString(R.string.restart), + new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + if (xmppConnectionServiceBound) { + unbindService(mConnection); + xmppConnectionServiceBound = false; + } + stopService(new Intent(XmppActivity.this, + XmppConnectionService.class)); + finish(); } - stopService(new Intent(XmppActivity.this, XmppConnectionService.class)); - finish(); - } - }); - builder.setPositiveButton(getString(R.string.install), new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - Uri uri = Uri.parse("market://details?id=org.sufficientlysecure.keychain"); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - startActivity(intent); - finish(); - } - }); - builder.create().show(); - return false; - } + }); + builder.setPositiveButton(getString(R.string.install), + new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + Uri uri = Uri + .parse("market://details?id=org.sufficientlysecure.keychain"); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(intent); + finish(); + } + }); + builder.create().show(); } - + abstract void onBackendConnected(); - + public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_settings: @@ -138,68 +140,76 @@ public abstract class XmppActivity extends Activity { } return super.onOptionsItemSelected(item); } - + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ExceptionHelper.init(getApplicationContext()); } - - public void switchToConversation(Conversation conversation, String text, boolean newTask) { + + public void switchToConversation(Conversation conversation, String text, + boolean newTask) { Intent viewConversationIntent = new Intent(this, ConversationActivity.class); viewConversationIntent.setAction(Intent.ACTION_VIEW); viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversation.getUuid()); - if (text!=null) { + if (text != null) { viewConversationIntent.putExtra(ConversationActivity.TEXT, text); } viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION); if (newTask) { viewConversationIntent.setFlags(viewConversationIntent.getFlags() - | Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_SINGLE_TOP); + | Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_SINGLE_TOP); } else { viewConversationIntent.setFlags(viewConversationIntent.getFlags() - | Intent.FLAG_ACTIVITY_CLEAR_TOP); + | Intent.FLAG_ACTIVITY_CLEAR_TOP); } startActivity(viewConversationIntent); } - + protected void announcePgp(Account account, final Conversation conversation) { - xmppConnectionService.getPgpEngine().generateSignature(account, "online", new UiCallback<Account>() { - - @Override - public void userInputRequried(PendingIntent pi, Account account) { - try { - startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); - } catch (SendIntentException e) { - Log.d("xmppService","coulnd start intent for pgp anncouncment"); - } - } - - @Override - public void success(Account account) { - xmppConnectionService.databaseBackend.updateAccount(account); - xmppConnectionService.sendPresence(account); - if (conversation!=null) { - conversation.setNextEncryption(Message.ENCRYPTION_PGP); - } - } - - @Override - public void error(int error, Account account) { - displayErrorDialog(error); - } - }); + xmppConnectionService.getPgpEngine().generateSignature(account, + "online", new UiCallback<Account>() { + + @Override + public void userInputRequried(PendingIntent pi, + Account account) { + try { + startIntentSenderForResult(pi.getIntentSender(), + REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); + } catch (SendIntentException e) { + Log.d("xmppService", + "coulnd start intent for pgp anncouncment"); + } + } + + @Override + public void success(Account account) { + xmppConnectionService.databaseBackend + .updateAccount(account); + xmppConnectionService.sendPresence(account); + if (conversation != null) { + conversation + .setNextEncryption(Message.ENCRYPTION_PGP); + } + } + + @Override + public void error(int error, Account account) { + displayErrorDialog(error); + } + }); } - + protected void displayErrorDialog(final int errorCode) { runOnUiThread(new Runnable() { - + @Override public void run() { - AlertDialog.Builder builder = new AlertDialog.Builder(XmppActivity.this); + AlertDialog.Builder builder = new AlertDialog.Builder( + XmppActivity.this); builder.setIconAttribute(android.R.attr.alertDialogIcon); builder.setTitle(getString(R.string.error)); builder.setMessage(errorCode); @@ -207,6 +217,6 @@ public abstract class XmppActivity extends Activity { builder.create().show(); } }); - + } } |