Replacing deprecated default constructor of handler with constructor that accepts Looper (#4513)

This commit is contained in:
Chetan Pawar 2020-10-09 12:35:07 +05:30 committed by GitHub
parent 77b12fa231
commit 9833bd753b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import android.content.res.Resources;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
@ -182,7 +183,7 @@ public class MainActivity extends CastEnabledActivity {
SharedPreferences prefs = getSharedPreferences(PREF_NAME, MODE_PRIVATE); SharedPreferences prefs = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
if (prefs.getBoolean(PREF_IS_FIRST_LAUNCH, true)) { if (prefs.getBoolean(PREF_IS_FIRST_LAUNCH, true)) {
loadFragment(AddFeedFragment.TAG, null); loadFragment(AddFeedFragment.TAG, null);
new Handler().postDelayed(() -> { new Handler(Looper.getMainLooper()).postDelayed(() -> {
if (drawerLayout != null) { // Tablet layout does not have a drawer if (drawerLayout != null) { // Tablet layout does not have a drawer
drawerLayout.openDrawer(navDrawer); drawerLayout.openDrawer(navDrawer);
} }

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.dialog;
import android.app.Dialog; import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.view.View; import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
@ -159,7 +160,7 @@ public class PlaybackControlsDialog extends DialogFragment {
butAudioTracks.setText(audioTracks.get(selectedAudioTrack)); butAudioTracks.setText(audioTracks.get(selectedAudioTrack));
butAudioTracks.setOnClickListener(v -> { butAudioTracks.setOnClickListener(v -> {
controller.setAudioTrack((selectedAudioTrack + 1) % audioTracks.size()); controller.setAudioTrack((selectedAudioTrack + 1) % audioTracks.size());
new Handler().postDelayed(this::setupAudioTracks, 500); new Handler(Looper.getMainLooper()).postDelayed(this::setupAudioTracks, 500);
}); });
} }
} }

View File

@ -9,6 +9,7 @@ import androidx.recyclerview.widget.SimpleItemAnimator;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -220,7 +221,7 @@ public abstract class EpisodesListFragment extends Fragment {
SwipeRefreshLayout swipeRefreshLayout = root.findViewById(R.id.swipeRefresh); SwipeRefreshLayout swipeRefreshLayout = root.findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setOnRefreshListener(() -> { swipeRefreshLayout.setOnRefreshListener(() -> {
AutoUpdateManager.runImmediate(requireContext()); AutoUpdateManager.runImmediate(requireContext());
new Handler().postDelayed(() -> swipeRefreshLayout.setRefreshing(false), new Handler(Looper.getMainLooper()).postDelayed(() -> swipeRefreshLayout.setRefreshing(false),
getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms)); getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms));
}); });

View File

@ -7,6 +7,7 @@ import android.content.Intent;
import android.graphics.LightingColorFilter; import android.graphics.LightingColorFilter;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -216,7 +217,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
} catch (DownloadRequestException e) { } catch (DownloadRequestException e) {
e.printStackTrace(); e.printStackTrace();
} }
new Handler().postDelayed(() -> swipeRefreshLayout.setRefreshing(false), new Handler(Looper.getMainLooper()).postDelayed(() -> swipeRefreshLayout.setRefreshing(false),
getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms)); getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms));
}); });

View File

@ -6,6 +6,7 @@ import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -110,7 +111,7 @@ public class SubscriptionFragment extends Fragment {
SwipeRefreshLayout swipeRefreshLayout = root.findViewById(R.id.swipeRefresh); SwipeRefreshLayout swipeRefreshLayout = root.findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setOnRefreshListener(() -> { swipeRefreshLayout.setOnRefreshListener(() -> {
AutoUpdateManager.runImmediate(requireContext()); AutoUpdateManager.runImmediate(requireContext());
new Handler().postDelayed(() -> swipeRefreshLayout.setRefreshing(false), new Handler(Looper.getMainLooper()).postDelayed(() -> swipeRefreshLayout.setRefreshing(false),
getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms)); getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms));
}); });
return root; return root;

View File

@ -10,6 +10,7 @@ import android.content.IntentFilter;
import android.os.Binder; import android.os.Binder;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -178,7 +179,7 @@ public class DownloadService extends Service {
public void onCreate() { public void onCreate() {
Log.d(TAG, "Service started"); Log.d(TAG, "Service started");
isRunning = true; isRunning = true;
handler = new Handler(); handler = new Handler(Looper.getMainLooper());
notificationManager = new DownloadServiceNotification(this); notificationManager = new DownloadServiceNotification(this);
IntentFilter cancelDownloadReceiverFilter = new IntentFilter(); IntentFilter cancelDownloadReceiverFilter = new IntentFilter();

View File

@ -343,7 +343,7 @@ public class PlaybackServiceTaskManager {
if (Looper.myLooper() == Looper.getMainLooper()) { if (Looper.myLooper() == Looper.getMainLooper()) {
// Called in main thread => ExoPlayer is used // Called in main thread => ExoPlayer is used
// Run on ui thread even if called from schedExecutor // Run on ui thread even if called from schedExecutor
Handler handler = new Handler(); Handler handler = new Handler(Looper.getMainLooper());
return () -> handler.post(runnable); return () -> handler.post(runnable);
} else { } else {
return runnable; return runnable;
@ -370,7 +370,7 @@ public class PlaybackServiceTaskManager {
if (UserPreferences.useExoplayer() && Looper.myLooper() == Looper.getMainLooper()) { if (UserPreferences.useExoplayer() && Looper.myLooper() == Looper.getMainLooper()) {
// Run callbacks in main thread so they can call ExoPlayer methods themselves // Run callbacks in main thread so they can call ExoPlayer methods themselves
this.handler = new Handler(); this.handler = new Handler(Looper.getMainLooper());
} else { } else {
this.handler = null; this.handler = null;
} }