forked from upstream-mirrors/OpenTracks
Fix force close on stop button for older devices (#393)
* correct thread handling in ButtonDelay Discovered in #390 for devices with API Level 25. Not fixing the whole issue, but a first step. * fix #390 crash when stopping for older devices The VectorDrawable ic_button_stop.xml referenced from withing the AnimatedVectorDrawable ic_button_stop_anim.xml was a problem for older devices. Now the VectorDrawable is expanded (duplicated) inside the AnimatedVectorDrawable. Now it is working. Even with the animation.
This commit is contained in:
@@ -19,6 +19,7 @@ package de.dennisguse.opentracks;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.graphics.drawable.AnimatedVectorDrawable;
|
import android.graphics.drawable.AnimatedVectorDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@@ -28,6 +29,8 @@ import android.widget.ImageButton;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceInterface;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceInterface;
|
||||||
import de.dennisguse.opentracks.util.ActivityUtils;
|
import de.dennisguse.opentracks.util.ActivityUtils;
|
||||||
@@ -134,7 +137,7 @@ public class TrackController {
|
|||||||
private final Activity activity;
|
private final Activity activity;
|
||||||
private final OnClickListener clickListener;
|
private final OnClickListener clickListener;
|
||||||
private final int delayMillis;
|
private final int delayMillis;
|
||||||
private final AnimatedVectorDrawable animatedDrawable;
|
private final Drawable drawable;
|
||||||
private final int delayMessageId;
|
private final int delayMessageId;
|
||||||
|
|
||||||
private ButtonDelay(final Activity activity, final ImageButton imageButton, final int animDrawableId, final int delayMessageId, final OnClickListener clickListener) {
|
private ButtonDelay(final Activity activity, final ImageButton imageButton, final int animDrawableId, final int delayMessageId, final OnClickListener clickListener) {
|
||||||
@@ -142,24 +145,30 @@ public class TrackController {
|
|||||||
this.clickListener = clickListener;
|
this.clickListener = clickListener;
|
||||||
this.delayMillis = activity.getResources().getInteger(R.integer.buttonDelayMillis);
|
this.delayMillis = activity.getResources().getInteger(R.integer.buttonDelayMillis);
|
||||||
this.imageButton = imageButton;
|
this.imageButton = imageButton;
|
||||||
this.animatedDrawable = (AnimatedVectorDrawable) activity.getDrawable(animDrawableId);
|
this.drawable = ContextCompat.getDrawable(activity, animDrawableId);
|
||||||
this.delayMessageId = delayMessageId;
|
this.delayMessageId = delayMessageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
imageButton.setImageDrawable(animatedDrawable);
|
activity.runOnUiThread(()->{
|
||||||
activity.runOnUiThread(animatedDrawable::start);
|
imageButton.setImageDrawable(drawable);
|
||||||
|
if (drawable instanceof AnimatedVectorDrawable) {
|
||||||
|
((AnimatedVectorDrawable) drawable).start();
|
||||||
|
}
|
||||||
|
ActivityUtils.vibrate(activity, 150);
|
||||||
|
ActivityUtils.toast(activity, delayMessageId, Toast.LENGTH_SHORT, Gravity.TOP);
|
||||||
|
});
|
||||||
|
|
||||||
ActivityUtils.vibrate(activity, 150);
|
|
||||||
activity.runOnUiThread(()-> ActivityUtils.toast(activity, delayMessageId, Toast.LENGTH_SHORT, Gravity.TOP));
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(delayMillis);
|
Thread.sleep(delayMillis);
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
}
|
}
|
||||||
if (!canceled) {
|
if (!canceled) {
|
||||||
activity.runOnUiThread(()-> clickListener.onClick(null));
|
activity.runOnUiThread(()-> {
|
||||||
ActivityUtils.vibrate(activity, 1000);
|
clickListener.onClick(null);
|
||||||
|
ActivityUtils.vibrate(activity, 1000);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,40 @@
|
|||||||
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:drawable="@drawable/ic_button_stop" >
|
xmlns:aapt="http://schemas.android.com/aapt">
|
||||||
|
<aapt:attr name="android:drawable">
|
||||||
|
<vector
|
||||||
|
android:width="82dp"
|
||||||
|
android:height="82dp"
|
||||||
|
android:viewportWidth="125"
|
||||||
|
android:viewportHeight="125">
|
||||||
|
<path
|
||||||
|
android:fillAlpha="1"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M2.516,63.008a60.239,59.73 134.879,1 0,119.968 -1.017a60.239,59.73 134.879,1 0,-119.968 1.017z"
|
||||||
|
android:strokeWidth="5.03194237"
|
||||||
|
android:strokeAlpha="1"
|
||||||
|
android:strokeColor="#555555" />
|
||||||
|
<path
|
||||||
|
android:fillAlpha="1"
|
||||||
|
android:fillColor="#484848"
|
||||||
|
android:pathData="M62.5,62.5m-50,0a50,50 0,1 1,100 0a50,50 0,1 1,-100 0"
|
||||||
|
android:strokeWidth="6.9172821"
|
||||||
|
android:strokeAlpha="1"
|
||||||
|
android:strokeColor="#00000000" />
|
||||||
|
<path
|
||||||
|
android:fillAlpha="1"
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:fillType="nonZero"
|
||||||
|
android:pathData="M53.02,54.02h17.46v17.46h-17.46z"
|
||||||
|
android:strokeWidth="1.04023623"
|
||||||
|
android:strokeAlpha="1"
|
||||||
|
android:strokeColor="#414141" />
|
||||||
|
<path android:name="fade_out_circle"
|
||||||
|
android:pathData="M62.5,62.5m-0,-62a50,50 0,1 1,-0 123a50,50 0,1 1,-0 -123"
|
||||||
|
android:fillAlpha="0.0"
|
||||||
|
android:fillColor="#a31a1f">
|
||||||
|
</path>
|
||||||
|
</vector>
|
||||||
|
</aapt:attr>
|
||||||
<target
|
<target
|
||||||
android:name="fade_out_circle"
|
android:name="fade_out_circle"
|
||||||
android:animation="@animator/button_animator" />
|
android:animation="@animator/button_animator" />
|
||||||
|
|||||||
Reference in New Issue
Block a user