mirror of https://github.com/M66B/FairEmail.git
Singleton handler
This commit is contained in:
parent
a8a95b0953
commit
c48ee83925
|
@ -28,6 +28,7 @@ import android.content.SharedPreferences;
|
|||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -513,6 +514,10 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
|||
return super.shouldUpRecreateTask(targetIntent);
|
||||
}
|
||||
|
||||
Handler getMainHandler() {
|
||||
return ApplicationEx.getMainHandler();
|
||||
}
|
||||
|
||||
public interface IKeyPressedListener {
|
||||
boolean onKeyPressed(KeyEvent event);
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
@ -62,7 +61,7 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
|
|||
final SimpleTask boot = new SimpleTask<Boolean>() {
|
||||
@Override
|
||||
protected void onPreExecute(Bundle args) {
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
getMainHandler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getWindow().setBackgroundDrawableResource(R.drawable.splash);
|
||||
|
@ -102,7 +101,7 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
|
|||
startActivity(view);
|
||||
}
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
getMainHandler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ServiceSynchronize.eval(ActivityMain.this, "main");
|
||||
|
|
|
@ -35,7 +35,6 @@ import android.graphics.Rect;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
|
@ -332,7 +331,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
ibExpanderExtra.setImageLevel(minimal ? 1 /* more */ : 0 /* less */);
|
||||
rvMenuExtra.setVisibility(minimal ? View.GONE : View.VISIBLE);
|
||||
if (!minimal)
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
drawerContainer.fullScroll(View.FOCUS_DOWN);
|
||||
|
@ -676,7 +675,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
else {
|
||||
exit = true;
|
||||
ToastEx.makeText(this, R.string.app_exit, Toast.LENGTH_SHORT).show();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
getMainHandler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
exit = false;
|
||||
|
@ -773,7 +772,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
snackbar.show();
|
||||
|
||||
// Wait
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
getMainHandler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i("Undo timeout");
|
||||
|
|
|
@ -32,7 +32,6 @@ import android.graphics.Color;
|
|||
import android.graphics.Typeface;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
|
@ -972,7 +971,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
set(all);
|
||||
|
||||
// Delay search until after expanding
|
||||
new Handler().post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int pos = -1;
|
||||
|
|
|
@ -50,8 +50,6 @@ import android.graphics.drawable.Drawable;
|
|||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.CalendarContract;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.Settings;
|
||||
|
@ -1766,7 +1764,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
tvHeaders.setText(null);
|
||||
|
||||
if (scroll)
|
||||
new Handler().post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
View inHeaders = itemView.findViewById(R.id.inHeaders);
|
||||
|
@ -2969,7 +2967,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
|
||||
firstClick = !firstClick;
|
||||
if (firstClick) {
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
ApplicationEx.getMainHandler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (firstClick) {
|
||||
|
@ -5491,13 +5489,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
|
||||
try {
|
||||
// https://issuetracker.google.com/issues/135628748
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
Field mMainThreadExecutor = this.differ.getClass().getDeclaredField("mMainThreadExecutor");
|
||||
mMainThreadExecutor.setAccessible(true);
|
||||
mMainThreadExecutor.set(this.differ, new Executor() {
|
||||
@Override
|
||||
public void execute(final Runnable command) {
|
||||
handler.post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
@ -5967,7 +5964,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
protected void onExecuted(Bundle args, Pair<String, IPInfo.Organization> data) {
|
||||
tvHost.setText(data.first);
|
||||
tvOwner.setText(data.second.name == null ? "?" : data.second.name);
|
||||
new Handler().post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
dview.scrollTo(0, tvOwner.getBottom());
|
||||
|
|
|
@ -32,6 +32,8 @@ import android.content.SharedPreferences;
|
|||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Printer;
|
||||
import android.webkit.CookieManager;
|
||||
|
||||
|
@ -393,4 +395,12 @@ public class ApplicationEx extends Application {
|
|||
Helper.clearAuthentication(ApplicationEx.this);
|
||||
}
|
||||
};
|
||||
|
||||
private static Handler handler = null;
|
||||
|
||||
synchronized static Handler getMainHandler() {
|
||||
if (handler == null)
|
||||
handler = new Handler(Looper.getMainLooper());
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ package eu.faircode.email;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -87,8 +85,6 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
|
||||
private IBoundaryCallbackMessages intf;
|
||||
|
||||
private Handler handler;
|
||||
|
||||
private State state;
|
||||
|
||||
private static final int SEARCH_LIMIT_DEVICE = 1000;
|
||||
|
@ -113,7 +109,6 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
}
|
||||
|
||||
void setCallback(IBoundaryCallbackMessages intf) {
|
||||
this.handler = new Handler(Looper.getMainLooper());
|
||||
this.intf = intf;
|
||||
this.state = new State();
|
||||
}
|
||||
|
@ -149,7 +144,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
return;
|
||||
|
||||
if (intf != null)
|
||||
handler.post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
intf.onLoading();
|
||||
|
@ -174,7 +169,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
state.error = true;
|
||||
Log.e("Boundary", ex);
|
||||
if (intf != null)
|
||||
handler.post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
intf.onException(ex);
|
||||
|
@ -182,7 +177,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
});
|
||||
} finally {
|
||||
if (intf != null)
|
||||
handler.post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
intf.onLoaded();
|
||||
|
|
|
@ -32,8 +32,6 @@ import android.graphics.Color;
|
|||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.ContactsContract;
|
||||
import android.text.TextUtils;
|
||||
|
||||
|
@ -519,9 +517,7 @@ public class ContactInfo {
|
|||
|
||||
static void init(final Context context) {
|
||||
if (Helper.hasPermission(context, Manifest.permission.READ_CONTACTS)) {
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
ContentObserver observer = new ContentObserver(handler) {
|
||||
ContentObserver observer = new ContentObserver(ApplicationEx.getMainHandler()) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
Log.i("Contact changed uri=" + uri);
|
||||
|
|
|
@ -20,8 +20,6 @@ package eu.faircode.email;
|
|||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
|
@ -30,42 +28,33 @@ import androidx.annotation.Nullable;
|
|||
|
||||
public class ContentLoadingProgressBar extends ProgressBar {
|
||||
private int visibility;
|
||||
private Handler handler;
|
||||
|
||||
private static final int VISIBILITY_DELAY = 500; // milliseconds
|
||||
|
||||
public ContentLoadingProgressBar(@NonNull Context context) {
|
||||
this(context, null);
|
||||
init();
|
||||
}
|
||||
|
||||
public ContentLoadingProgressBar(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs, 0);
|
||||
init();
|
||||
}
|
||||
|
||||
public ContentLoadingProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
public ContentLoadingProgressBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
handler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisibility(int visibility) {
|
||||
this.visibility = visibility;
|
||||
|
||||
handler.removeCallbacks(delayedShow);
|
||||
ApplicationEx.getMainHandler().removeCallbacks(delayedShow);
|
||||
if (visibility == VISIBLE) {
|
||||
super.setVisibility(INVISIBLE);
|
||||
handler.postDelayed(delayedShow, VISIBILITY_DELAY);
|
||||
ApplicationEx.getMainHandler().postDelayed(delayedShow, VISIBILITY_DELAY);
|
||||
} else
|
||||
super.setVisibility(visibility);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import android.graphics.Color;
|
|||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
|
@ -393,7 +392,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
int visibility = (grpAdvanced.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
|
||||
grpAdvanced.setVisibility(visibility);
|
||||
if (visibility == View.VISIBLE)
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, btnAdvanced.getTop());
|
||||
|
@ -750,7 +749,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
if (!cbTrust.isChecked())
|
||||
cbTrust.setVisibility(View.GONE);
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, cbIdentity.getBottom());
|
||||
|
@ -1384,7 +1383,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
tvInstructions.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (provider != null && provider.documentation != null)
|
||||
|
@ -1593,7 +1592,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
};
|
||||
|
||||
// Load after provider has been selected
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
task.execute(FragmentAccount.this, args, "account:folders");
|
||||
|
@ -1660,7 +1659,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
case REQUEST_SAVE:
|
||||
if (resultCode == RESULT_OK) {
|
||||
final boolean save = (btnSave.getVisibility() == View.VISIBLE);
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, (save ? btnSave : btnCheck).getBottom());
|
||||
|
|
|
@ -32,6 +32,7 @@ import android.content.res.Configuration;
|
|||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -570,4 +571,8 @@ public class FragmentBase extends Fragment {
|
|||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
Handler getMainHandler() {
|
||||
return ApplicationEx.getMainHandler();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,6 @@ import android.net.NetworkRequest;
|
|||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.Settings;
|
||||
|
@ -1417,7 +1416,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
private void onMenuAddresses() {
|
||||
grpAddresses.setVisibility(grpAddresses.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (grpAddresses.getVisibility() == View.GONE)
|
||||
|
@ -4102,8 +4101,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
EntityOperation.queue(context, draft, EntityOperation.MOVE, trash.id);
|
||||
}
|
||||
|
||||
Handler handler = new Handler(context.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
public void run() {
|
||||
ToastEx.makeText(context, R.string.title_draft_deleted, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -4475,8 +4473,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
final String msg = context.getString(mid) +
|
||||
(BuildConfig.DEBUG ? ":" + draft.revision : "");
|
||||
|
||||
Handler handler = new Handler(context.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
public void run() {
|
||||
ToastEx.makeText(context, msg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -4555,8 +4552,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
feedback = context.getString(R.string.title_queued_at, DTF.format(draft.ui_snoozed));
|
||||
}
|
||||
|
||||
Handler handler = new Handler(context.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
public void run() {
|
||||
ToastEx.makeText(context, feedback, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -4894,7 +4890,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
else
|
||||
target = etBody;
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
target.requestFocus();
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -339,7 +338,7 @@ public class FragmentFolder extends FragmentBase {
|
|||
break;
|
||||
case REQUEST_SAVE_CHANGES:
|
||||
if (resultCode == RESULT_OK) {
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, btnSave.getBottom());
|
||||
|
|
|
@ -33,7 +33,6 @@ import android.net.ConnectivityManager;
|
|||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.ContactsContract;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -235,7 +234,7 @@ public class FragmentGmail extends FragmentBase {
|
|||
etName.setEnabled(granted);
|
||||
btnSelect.setEnabled(granted);
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
etName.requestFocus();
|
||||
|
@ -289,7 +288,7 @@ public class FragmentGmail extends FragmentBase {
|
|||
tvError.setText(Log.formatThrowable(ex));
|
||||
grpError.setVisibility(View.VISIBLE);
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, tvError.getBottom());
|
||||
|
@ -490,7 +489,7 @@ public class FragmentGmail extends FragmentBase {
|
|||
tvError.setText(Log.formatThrowable(ex));
|
||||
grpError.setVisibility(View.VISIBLE);
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, tvError.getBottom());
|
||||
|
|
|
@ -26,7 +26,6 @@ import android.content.Intent;
|
|||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
|
@ -361,7 +360,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
grpAdvanced.setVisibility(visibility);
|
||||
checkPassword(tilPassword.getEditText().getText().toString());
|
||||
if (visibility == View.VISIBLE)
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, btnAdvanced.getTop());
|
||||
|
@ -1042,7 +1041,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
tvInstructions.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (provider != null && provider.documentation != null)
|
||||
|
@ -1321,7 +1320,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
break;
|
||||
case REQUEST_SAVE:
|
||||
if (resultCode == RESULT_OK) {
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, btnSave.getBottom());
|
||||
|
|
|
@ -46,7 +46,6 @@ import android.net.NetworkRequest;
|
|||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcel;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Parcelable;
|
||||
|
@ -1689,7 +1688,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
|
||||
@Override
|
||||
public void scrollTo(final int pos, final int y) {
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LinearLayoutManager llm = (LinearLayoutManager) rvMessage.getLayoutManager();
|
||||
|
@ -1702,7 +1701,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
|
||||
@Override
|
||||
public void scrollBy(int x, int y) {
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
rvMessage.scrollBy(x, y);
|
||||
|
@ -1778,8 +1777,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
};
|
||||
|
||||
private ItemTouchHelper.Callback touchHelper = new ItemTouchHelper.Callback() {
|
||||
private Handler handler = new Handler();
|
||||
|
||||
private Runnable enableSelection = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -1841,11 +1838,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
super.onChildDraw(canvas, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||
|
||||
if (selectionPredicate != null) {
|
||||
handler.removeCallbacks(enableSelection);
|
||||
getMainHandler().removeCallbacks(enableSelection);
|
||||
if (isCurrentlyActive)
|
||||
selectionPredicate.setEnabled(false);
|
||||
else
|
||||
handler.postDelayed(enableSelection, SWIPE_DISABLE_SELECT_DURATION);
|
||||
getMainHandler().postDelayed(enableSelection, SWIPE_DISABLE_SELECT_DURATION);
|
||||
}
|
||||
|
||||
int pos = viewHolder.getAdapterPosition();
|
||||
|
@ -4147,7 +4144,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
model.getIds(getContext(), getViewLifecycleOwner(), new Observer<List<Long>>() {
|
||||
@Override
|
||||
public void onChanged(List<Long> ids) {
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
selectionTracker.clearSelection();
|
||||
|
|
|
@ -28,7 +28,6 @@ import android.net.ConnectivityManager;
|
|||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.util.Pair;
|
||||
|
@ -641,7 +640,7 @@ public class FragmentOAuth extends FragmentBase {
|
|||
btnOAuth.setEnabled(true);
|
||||
pbOAuth.setVisibility(View.GONE);
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, tvError.getBottom());
|
||||
|
|
|
@ -27,7 +27,6 @@ import android.content.SharedPreferences;
|
|||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -445,14 +444,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
|
|||
}
|
||||
});
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
etPin.requestFocus();
|
||||
}
|
||||
});
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
etPin.requestFocus();
|
||||
|
|
|
@ -26,7 +26,6 @@ import android.graphics.Color;
|
|||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
|
@ -549,7 +548,7 @@ public class FragmentPop extends FragmentBase {
|
|||
tvError.setText(Log.formatThrowable(ex, false));
|
||||
grpError.setVisibility(View.VISIBLE);
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, tvError.getBottom());
|
||||
|
|
|
@ -25,7 +25,6 @@ import android.net.ConnectivityManager;
|
|||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
|
@ -486,7 +485,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
tvError.setText(ex.getMessage());
|
||||
grpError.setVisibility(View.VISIBLE);
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, tvErrorHint.getBottom());
|
||||
|
@ -509,7 +508,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
|||
tvInstructions.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.containsKey("documentation"))
|
||||
|
|
|
@ -27,7 +27,6 @@ import android.database.Cursor;
|
|||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.ContactsContract;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.text.TextUtils;
|
||||
|
@ -419,7 +418,7 @@ public class FragmentRule extends FragmentBase {
|
|||
private void onActionSelected(int type) {
|
||||
showActionParameters(type);
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scroll.smoothScrollTo(0, content.getBottom());
|
||||
|
|
|
@ -40,9 +40,7 @@ import android.net.Uri;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.LocaleList;
|
||||
import android.os.Looper;
|
||||
import android.os.Parcel;
|
||||
import android.os.PowerManager;
|
||||
import android.os.StatFs;
|
||||
|
@ -1258,8 +1256,6 @@ public class Helper {
|
|||
static void authenticate(final FragmentActivity activity, final LifecycleOwner owner,
|
||||
Boolean enabled, final
|
||||
Runnable authenticated, final Runnable cancelled) {
|
||||
final Handler handler = new Handler();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
String pin = prefs.getString("pin", null);
|
||||
|
||||
|
@ -1289,7 +1285,7 @@ public class Helper {
|
|||
if (errorCode != BiometricPrompt.ERROR_NEGATIVE_BUTTON &&
|
||||
errorCode != BiometricPrompt.ERROR_CANCELED &&
|
||||
errorCode != BiometricPrompt.ERROR_USER_CANCELED)
|
||||
handler.post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ToastEx.makeText(activity,
|
||||
|
@ -1298,20 +1294,20 @@ public class Helper {
|
|||
}
|
||||
});
|
||||
|
||||
handler.post(cancelled);
|
||||
ApplicationEx.getMainHandler().post(cancelled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
|
||||
Log.i("Biometric succeeded");
|
||||
setAuthenticated(activity);
|
||||
handler.post(authenticated);
|
||||
ApplicationEx.getMainHandler().post(authenticated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationFailed() {
|
||||
Log.w("Biometric failed");
|
||||
handler.post(cancelled);
|
||||
ApplicationEx.getMainHandler().post(cancelled);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1328,12 +1324,12 @@ public class Helper {
|
|||
}
|
||||
};
|
||||
|
||||
handler.postDelayed(cancelPrompt, 60 * 1000L);
|
||||
ApplicationEx.getMainHandler().postDelayed(cancelPrompt, 60 * 1000L);
|
||||
|
||||
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
public void onDestroy() {
|
||||
handler.post(cancelPrompt);
|
||||
ApplicationEx.getMainHandler().post(cancelPrompt);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1352,21 +1348,21 @@ public class Helper {
|
|||
|
||||
if (pin.equals(entered)) {
|
||||
setAuthenticated(activity);
|
||||
handler.post(authenticated);
|
||||
ApplicationEx.getMainHandler().post(authenticated);
|
||||
} else
|
||||
handler.post(cancelled);
|
||||
ApplicationEx.getMainHandler().post(cancelled);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
handler.post(cancelled);
|
||||
ApplicationEx.getMainHandler().post(cancelled);
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
handler.post(cancelled);
|
||||
ApplicationEx.getMainHandler().post(cancelled);
|
||||
}
|
||||
})
|
||||
.create();
|
||||
|
@ -1390,7 +1386,7 @@ public class Helper {
|
|||
}
|
||||
});
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
etPin.requestFocus();
|
||||
|
@ -1413,8 +1409,6 @@ public class Helper {
|
|||
|
||||
static void selectKeyAlias(final Activity activity, final LifecycleOwner owner, final String alias, final IKeyAlias intf) {
|
||||
final Context context = activity.getApplicationContext();
|
||||
final Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -1431,7 +1425,7 @@ public class Helper {
|
|||
Log.e(ex);
|
||||
}
|
||||
|
||||
handler.post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
KeyChain.choosePrivateKeyAlias(activity, new KeyChainAliasCallback() {
|
||||
|
@ -1447,7 +1441,7 @@ public class Helper {
|
|||
}
|
||||
|
||||
private void deliver(final String selected) {
|
||||
handler.post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
|
||||
|
|
|
@ -21,6 +21,7 @@ package eu.faircode.email;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.lifecycle.LifecycleService;
|
||||
|
||||
|
@ -62,4 +63,8 @@ abstract class ServiceBase extends LifecycleService {
|
|||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
Handler getMainHandler() {
|
||||
return ApplicationEx.getMainHandler();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import android.net.ConnectivityManager;
|
|||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkRequest;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
|
@ -70,7 +69,6 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|||
private Network lastActive = null;
|
||||
private boolean lastSuitable = false;
|
||||
|
||||
private Handler handler;
|
||||
private PowerManager.WakeLock wlOutbox;
|
||||
private TwoStateOwner owner = new TwoStateOwner("send");
|
||||
private List<Long> handling = new ArrayList<>();
|
||||
|
@ -88,8 +86,6 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|||
super.onCreate();
|
||||
startForeground(Helper.NOTIFICATION_SEND, getNotificationService().build());
|
||||
|
||||
handler = new Handler();
|
||||
|
||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
wlOutbox = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":send");
|
||||
|
||||
|
@ -175,7 +171,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|||
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
cm.unregisterNetworkCallback(networkCallback);
|
||||
|
||||
handler.removeCallbacks(_checkConnectivity);
|
||||
getMainHandler().removeCallbacks(_checkConnectivity);
|
||||
|
||||
owner.stop();
|
||||
handling.clear();
|
||||
|
@ -284,7 +280,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|||
};
|
||||
|
||||
private void checkConnectivity() {
|
||||
handler.postDelayed(_checkConnectivity, CONNECTIVITY_DELAY);
|
||||
getMainHandler().postDelayed(_checkConnectivity, CONNECTIVITY_DELAY);
|
||||
}
|
||||
|
||||
private Runnable _checkConnectivity = new Runnable() {
|
||||
|
|
|
@ -35,7 +35,6 @@ import android.net.NetworkInfo;
|
|||
import android.net.NetworkRequest;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.text.TextUtils;
|
||||
|
@ -901,7 +900,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
state.reset();
|
||||
Log.i(account.name + " run thread=" + currentThread);
|
||||
|
||||
Handler handler = new Handler(getMainLooper());
|
||||
final List<TwoStateOwner> cowners = new ArrayList<>();
|
||||
|
||||
// Debug
|
||||
|
@ -1210,7 +1208,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
mapFolders.put(folder, null);
|
||||
|
||||
Log.d(folder.name + " observing");
|
||||
handler.post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TwoStateOwner cowner = new TwoStateOwner(ServiceSynchronize.this, folder.name);
|
||||
|
@ -1576,7 +1574,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
db.account().setAccountState(account.id, "closing");
|
||||
|
||||
// Stop watching for operations
|
||||
handler.post(new Runnable() {
|
||||
getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (TwoStateOwner owner : cowners)
|
||||
|
|
|
@ -23,8 +23,6 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
@ -94,8 +92,6 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|||
}
|
||||
|
||||
private void run(final Context context, final LifecycleOwner owner, final Bundle args, final String name) {
|
||||
final Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
this.name = name;
|
||||
|
||||
if (owner instanceof TwoStateOwner)
|
||||
|
@ -148,7 +144,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|||
}
|
||||
|
||||
// Run on UI thread
|
||||
handler.post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Lifecycle.State state = owner.getLifecycle().getCurrentState();
|
||||
|
|
Loading…
Reference in New Issue