mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Bugfix: prevent NPE as handler should not be executed anymore.
Fixes #1035.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package de.dennisguse.opentracks;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.TransitionDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -97,7 +98,10 @@ public class ControllerFragment extends Fragment implements View.OnTouchListener
|
||||
return;
|
||||
}
|
||||
|
||||
getCallback().recordStart();
|
||||
Callback callback = (Callback) getContext();
|
||||
if (callback != null) {
|
||||
callback.recordStart();
|
||||
}
|
||||
});
|
||||
|
||||
viewBinding.controllerStop.setOnTouchListener(this);
|
||||
@@ -114,6 +118,12 @@ public class ControllerFragment extends Fragment implements View.OnTouchListener
|
||||
trackRecordingServiceConnection.startConnection(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
handlerUpdateTotalTime.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
@@ -175,7 +185,10 @@ public class ControllerFragment extends Fragment implements View.OnTouchListener
|
||||
buttonDelay = () -> {
|
||||
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
|
||||
view.performClick();
|
||||
getCallback().recordPause();
|
||||
Callback callback = (Callback) getContext();
|
||||
if (callback != null) {
|
||||
callback.recordPause();
|
||||
}
|
||||
|
||||
transition.resetTransition();
|
||||
|
||||
@@ -198,8 +211,12 @@ public class ControllerFragment extends Fragment implements View.OnTouchListener
|
||||
|
||||
buttonDelay = () -> {
|
||||
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
|
||||
getCallback().recordStop();
|
||||
ActivityUtils.vibrate(getContext(), 1000);
|
||||
Context context = getContext();
|
||||
Callback callback = (Callback) context;
|
||||
if (callback != null) {
|
||||
callback.recordStop();
|
||||
ActivityUtils.vibrate(context, 1000);
|
||||
}
|
||||
|
||||
transition.resetTransition();
|
||||
};
|
||||
@@ -222,10 +239,6 @@ public class ControllerFragment extends Fragment implements View.OnTouchListener
|
||||
viewBinding.controllerStatus.setText(recordingStatus.isPaused() ? R.string.generic_paused : R.string.generic_recording);
|
||||
}
|
||||
|
||||
private Callback getCallback() {
|
||||
return (Callback) getActivity();
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
void recordStart();
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.dennisguse.opentracks.util;
|
||||
|
||||
import static android.content.Context.VIBRATOR_SERVICE;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.SearchManager;
|
||||
import android.content.Context;
|
||||
@@ -14,6 +16,7 @@ import android.view.MenuItem;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -21,8 +24,6 @@ import java.util.ArrayList;
|
||||
import de.dennisguse.opentracks.ContextualActionModeCallback;
|
||||
import de.dennisguse.opentracks.R;
|
||||
|
||||
import static android.content.Context.VIBRATOR_SERVICE;
|
||||
|
||||
public class ActivityUtils {
|
||||
|
||||
private static final String TAG = ActivityUtils.class.getSimpleName();
|
||||
@@ -97,7 +98,7 @@ public class ActivityUtils {
|
||||
return searchView;
|
||||
}
|
||||
|
||||
public static void vibrate(Context context, int milliseconds) {
|
||||
public static void vibrate(@NonNull Context context, int milliseconds) {
|
||||
final Vibrator vibrator = (Vibrator) context.getSystemService(VIBRATOR_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
vibrator.vibrate(VibrationEffect.createOneShot(milliseconds, VibrationEffect.DEFAULT_AMPLITUDE));
|
||||
|
||||
Reference in New Issue
Block a user