diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 228b6c1b3..20be4abd4 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -12,7 +12,6 @@
-
Toast.makeText(XmppActivity.this, R.string.openpgp_has_been_published, Toast.LENGTH_SHORT).show();
protected ConferenceInvite mPendingConferenceInvite = null;
-
-
- protected final void refreshUi() {
- final long diff = SystemClock.elapsedRealtime() - mLastUiRefresh;
- if (diff > Config.REFRESH_UI_INTERVAL) {
- mRefreshUiHandler.removeCallbacks(mRefreshUiRunnable);
- runOnUiThread(mRefreshUiRunnable);
- } else {
- final long next = Config.REFRESH_UI_INTERVAL - diff;
- mRefreshUiHandler.removeCallbacks(mRefreshUiRunnable);
- mRefreshUiHandler.postDelayed(mRefreshUiRunnable,next);
- }
- }
-
- abstract protected void refreshUiReal();
-
- protected interface OnValueEdited {
- String onValueEdited(String value);
- }
-
- public interface OnPresenceSelected {
- void onPresenceSelected();
- }
-
protected ServiceConnection mConnection = new ServiceConnection() {
@Override
@@ -194,6 +126,87 @@ public abstract class XmppActivity extends Activity {
xmppConnectionServiceBound = false;
}
};
+ private DisplayMetrics metrics;
+ private long mLastUiRefresh = 0;
+ private Handler mRefreshUiHandler = new Handler();
+ private Runnable mRefreshUiRunnable = () -> {
+ mLastUiRefresh = SystemClock.elapsedRealtime();
+ refreshUiReal();
+ };
+ private UiCallback adhocCallback = new UiCallback() {
+ @Override
+ public void success(final Conversation conversation) {
+ runOnUiThread(() -> {
+ switchToConversation(conversation);
+ hideToast();
+ });
+ }
+
+ @Override
+ public void error(final int errorCode, Conversation object) {
+ runOnUiThread(() -> replaceToast(getString(errorCode)));
+ }
+
+ @Override
+ public void userInputRequried(PendingIntent pi, Conversation object) {
+
+ }
+ };
+
+ public static boolean cancelPotentialWork(Message message, ImageView imageView) {
+ final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
+
+ if (bitmapWorkerTask != null) {
+ final Message oldMessage = bitmapWorkerTask.message;
+ if (oldMessage == null || message != oldMessage) {
+ bitmapWorkerTask.cancel(true);
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
+ if (imageView != null) {
+ final Drawable drawable = imageView.getDrawable();
+ if (drawable instanceof AsyncDrawable) {
+ final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
+ return asyncDrawable.getBitmapWorkerTask();
+ }
+ }
+ return null;
+ }
+
+ protected void hideToast() {
+ if (mToast != null) {
+ mToast.cancel();
+ }
+ }
+
+ protected void replaceToast(String msg) {
+ replaceToast(msg, true);
+ }
+
+ protected void replaceToast(String msg, boolean showlong) {
+ hideToast();
+ mToast = Toast.makeText(this, msg, showlong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
+ mToast.show();
+ }
+
+ protected final void refreshUi() {
+ final long diff = SystemClock.elapsedRealtime() - mLastUiRefresh;
+ if (diff > Config.REFRESH_UI_INTERVAL) {
+ mRefreshUiHandler.removeCallbacks(mRefreshUiRunnable);
+ runOnUiThread(mRefreshUiRunnable);
+ } else {
+ final long next = Config.REFRESH_UI_INTERVAL - diff;
+ mRefreshUiHandler.removeCallbacks(mRefreshUiRunnable);
+ mRefreshUiHandler.postDelayed(mRefreshUiRunnable, next);
+ }
+ }
+
+ abstract protected void refreshUiReal();
@Override
protected void onStart() {
@@ -211,7 +224,7 @@ public abstract class XmppActivity extends Activity {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
protected boolean shouldRegisterListeners() {
- if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return !isDestroyed() && !isFinishing();
} else {
return !isFinishing();
@@ -239,14 +252,10 @@ public abstract class XmppActivity extends Activity {
}
protected void hideKeyboard() {
- InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
-
+ final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
View focus = getCurrentFocus();
-
- if (focus != null) {
-
- inputManager.hideSoftInputFromWindow(focus.getWindowToken(),
- InputMethodManager.HIDE_NOT_ALWAYS);
+ if (focus != null && inputManager != null) {
+ inputManager.hideSoftInputFromWindow(focus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
@@ -261,42 +270,34 @@ public abstract class XmppActivity extends Activity {
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();
+ (dialog, which) -> {
+ if (xmppConnectionServiceBound) {
+ unbindService(mConnection);
+ xmppConnectionServiceBound = false;
}
+ 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
+ (dialog, which) -> {
+ Uri uri = Uri
.parse("market://details?id=org.sufficientlysecure.keychain");
- Intent marketIntent = new Intent(Intent.ACTION_VIEW,
- uri);
- PackageManager manager = getApplicationContext()
+ Intent marketIntent = new Intent(Intent.ACTION_VIEW,
+ uri);
+ PackageManager manager = getApplicationContext()
.getPackageManager();
- List infos = manager
+ List infos = manager
.queryIntentActivities(marketIntent, 0);
- if (infos.size() > 0) {
- startActivity(marketIntent);
- } else {
- uri = Uri.parse("http://www.openkeychain.org/");
- Intent browserIntent = new Intent(
- Intent.ACTION_VIEW, uri);
- startActivity(browserIntent);
- }
- finish();
+ if (infos.size() > 0) {
+ startActivity(marketIntent);
+ } else {
+ uri = Uri.parse("http://www.openkeychain.org/");
+ Intent browserIntent = new Intent(
+ Intent.ACTION_VIEW, uri);
+ startActivity(browserIntent);
}
+ finish();
});
builder.create().show();
}
@@ -393,7 +394,7 @@ public abstract class XmppActivity extends Activity {
mSecondaryBackgroundColor = ContextCompat.getColor(this, R.color.grey200);
this.mTheme = findTheme();
- if(isDarkTheme()) {
+ if (isDarkTheme()) {
mPrimaryTextColor = ContextCompat.getColor(this, R.color.white);
mSecondaryTextColor = ContextCompat.getColor(this, R.color.white70);
mTertiaryTextColor = ContextCompat.getColor(this, R.color.white12);
@@ -405,7 +406,7 @@ public abstract class XmppActivity extends Activity {
this.mUsingEnterKey = usingEnterKey();
mUseSubject = getPreferences().getBoolean("use_subject", getResources().getBoolean(R.bool.use_subject));
final ActionBar ab = getActionBar();
- if (ab!=null) {
+ if (ab != null) {
ab.setDisplayHomeAsUpEnabled(true);
}
}
@@ -415,7 +416,7 @@ public abstract class XmppActivity extends Activity {
}
public int getThemeResource(int r_attr_name, int r_drawable_def) {
- int[] attrs = { r_attr_name };
+ int[] attrs = {r_attr_name};
TypedArray ta = this.getTheme().obtainStyledAttributes(attrs);
int res = ta.getResourceId(0, r_drawable_def);
@@ -427,7 +428,7 @@ public abstract class XmppActivity extends Activity {
protected boolean isOptimizingBattery() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
- return pm == null
+ return pm != null
&& !pm.isIgnoringBatteryOptimizations(getPackageName());
} else {
return false;
@@ -451,7 +452,7 @@ public abstract class XmppActivity extends Activity {
protected SharedPreferences getPreferences() {
return PreferenceManager
- .getDefaultSharedPreferences(getApplicationContext());
+ .getDefaultSharedPreferences(getApplicationContext());
}
public boolean useSubjectToIdentifyConference() {
@@ -463,8 +464,8 @@ public abstract class XmppActivity extends Activity {
}
public void switchToConversation(Conversation conversation, String text,
- boolean newTask) {
- switchToConversation(conversation,text,null,false,newTask);
+ boolean newTask) {
+ switchToConversation(conversation, text, null, false, newTask);
}
public void highlightInMuc(Conversation conversation, String nick) {
@@ -486,7 +487,7 @@ public abstract class XmppActivity extends Activity {
}
if (nick != null) {
viewConversationIntent.putExtra(ConversationActivity.NICK, nick);
- viewConversationIntent.putExtra(ConversationActivity.PRIVATE_MESSAGE,pm);
+ viewConversationIntent.putExtra(ConversationActivity.PRIVATE_MESSAGE, pm);
}
if (newTask) {
viewConversationIntent.setFlags(viewConversationIntent.getFlags()
@@ -596,11 +597,11 @@ public abstract class XmppActivity extends Activity {
}
}
- protected boolean noAccountUsesPgp() {
+ protected boolean noAccountUsesPgp() {
if (!hasPgp()) {
return true;
}
- for(Account account : xmppConnectionService.getAccounts()) {
+ for (Account account : xmppConnectionService.getAccounts()) {
if (account.getPgpId() != 0) {
return false;
}
@@ -642,18 +643,13 @@ public abstract class XmppActivity extends Activity {
}
protected void displayErrorDialog(final int errorCode) {
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- AlertDialog.Builder builder = new AlertDialog.Builder(
- XmppActivity.this);
- builder.setIconAttribute(android.R.attr.alertDialogIcon);
- builder.setTitle(getString(R.string.error));
- builder.setMessage(errorCode);
- builder.setNeutralButton(R.string.accept, null);
- builder.create().show();
- }
+ runOnUiThread(() -> {
+ Builder builder = new Builder(XmppActivity.this);
+ builder.setIconAttribute(android.R.attr.alertDialogIcon);
+ builder.setTitle(getString(R.string.error));
+ builder.setMessage(errorCode);
+ builder.setNeutralButton(R.string.accept, null);
+ builder.create().show();
});
}
@@ -668,15 +664,11 @@ public abstract class XmppActivity extends Activity {
builder.setMessage(getString(R.string.not_in_roster));
builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.add_contact),
- new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- final Jid jid = contact.getJid();
- Account account = contact.getAccount();
- Contact contact = account.getRoster().getContact(jid);
- xmppConnectionService.createContact(contact);
- }
+ (dialog, which) -> {
+ final Jid jid = contact.getJid();
+ Account account = contact.getAccount();
+ Contact contact1 = account.getRoster().getContact(jid);
+ xmppConnectionService.createContact(contact1);
});
builder.create().show();
}
@@ -687,35 +679,27 @@ public abstract class XmppActivity extends Activity {
builder.setMessage(R.string.request_presence_updates);
builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.request_now,
- new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (xmppConnectionServiceBound) {
- xmppConnectionService.sendPresencePacket(contact
- .getAccount(), xmppConnectionService
- .getPresenceGenerator()
- .requestPresenceUpdatesFrom(contact));
- }
+ (dialog, which) -> {
+ if (xmppConnectionServiceBound) {
+ xmppConnectionService.sendPresencePacket(contact
+ .getAccount(), xmppConnectionService
+ .getPresenceGenerator()
+ .requestPresenceUpdatesFrom(contact));
}
});
builder.create().show();
}
private void warnMutalPresenceSubscription(final Conversation conversation,
- final OnPresenceSelected listener) {
+ final OnPresenceSelected listener) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(conversation.getContact().getJid().toString());
builder.setMessage(R.string.without_mutual_presence_updates);
builder.setNegativeButton(R.string.cancel, null);
- builder.setPositiveButton(R.string.ignore, new OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- conversation.setNextCounterpart(null);
- if (listener != null) {
- listener.onPresenceSelected();
- }
+ builder.setPositiveButton(R.string.ignore, (dialog, which) -> {
+ conversation.setNextCounterpart(null);
+ if (listener != null) {
+ listener.onPresenceSelected();
}
});
builder.create().show();
@@ -731,16 +715,16 @@ public abstract class XmppActivity extends Activity {
@SuppressLint("InflateParams")
private void quickEdit(final String previousValue,
- final OnValueEdited callback,
- final int hint,
- boolean password) {
+ final OnValueEdited callback,
+ final int hint,
+ boolean password) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = getLayoutInflater().inflate(R.layout.quickedit, null);
final EditText editor = view.findViewById(R.id.editor);
if (password) {
editor.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
- builder.setPositiveButton(R.string.accept,null);
+ builder.setPositiveButton(R.string.accept, null);
} else {
builder.setPositiveButton(R.string.edit, null);
}
@@ -756,20 +740,16 @@ public abstract class XmppActivity extends Activity {
builder.setNegativeButton(R.string.cancel, null);
final AlertDialog dialog = builder.create();
dialog.show();
- View.OnClickListener clickListener = new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- String value = editor.getText().toString();
- if (!value.equals(previousValue) && value.trim().length() > 0) {
- String error = callback.onValueEdited(value);
- if (error != null) {
- editor.setError(error);
- return;
- }
+ View.OnClickListener clickListener = v -> {
+ String value = editor.getText().toString();
+ if (!value.equals(previousValue) && value.trim().length() > 0) {
+ String error = callback.onValueEdited(value);
+ if (error != null) {
+ editor.setError(error);
+ return;
}
- dialog.dismiss();
}
+ dialog.dismiss();
};
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener);
}
@@ -788,7 +768,7 @@ public abstract class XmppActivity extends Activity {
}
public void selectPresence(final Conversation conversation,
- final OnPresenceSelected listener) {
+ final OnPresenceSelected listener) {
final Contact contact = conversation.getContact();
if (conversation.hasValidOtrSession()) {
SessionID id = conversation.getOtrSession().getSessionID();
@@ -800,7 +780,7 @@ public abstract class XmppActivity extends Activity {
}
conversation.setNextCounterpart(jid);
listener.onPresenceSelected();
- } else if (!contact.showInRoster()) {
+ } else if (!contact.showInRoster()) {
showAddToRosterDialog(conversation);
} else {
final Presences presences = contact.getPresences();
@@ -819,13 +799,13 @@ public abstract class XmppActivity extends Activity {
} else if (presences.size() == 1) {
String presence = presences.toResourceArray()[0];
try {
- conversation.setNextCounterpart(Jid.fromParts(contact.getJid().getLocalpart(),contact.getJid().getDomainpart(),presence));
+ conversation.setNextCounterpart(Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), presence));
} catch (InvalidJidException e) {
conversation.setNextCounterpart(null);
}
listener.onPresenceSelected();
} else {
- showPresenceSelectionDialog(presences,conversation,listener);
+ showPresenceSelectionDialog(presences, conversation, listener);
}
}
}
@@ -836,8 +816,8 @@ public abstract class XmppActivity extends Activity {
builder.setTitle(getString(R.string.choose_presence));
final String[] resourceArray = presences.toResourceArray();
Pair