2019-02-26 20:38:27 +01:00
|
|
|
package info.nightscout.androidaps.utils;
|
2017-12-22 19:50:16 +01:00
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.SystemClock;
|
2019-05-16 13:57:37 +02:00
|
|
|
import androidx.annotation.Nullable;
|
2017-12-22 19:50:16 +01:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2020-01-13 19:22:28 +01:00
|
|
|
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
|
|
|
|
2017-12-22 19:50:16 +01:00
|
|
|
/**
|
|
|
|
* Created by mike on 22.12.2017.
|
|
|
|
*/
|
|
|
|
|
2019-05-16 13:57:37 +02:00
|
|
|
public class SingleClickButton extends androidx.appcompat.widget.AppCompatButton implements View.OnClickListener {
|
2020-01-13 19:22:28 +01:00
|
|
|
private static Logger log = StacktraceLoggerWrapper.getLogger(SingleClickButton.class);
|
2017-12-22 19:50:16 +01:00
|
|
|
|
|
|
|
Context context;
|
|
|
|
OnClickListener listener = null;
|
|
|
|
|
|
|
|
public SingleClickButton(Context context) {
|
|
|
|
super(context);
|
|
|
|
this.context = context;
|
|
|
|
super.setOnClickListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public SingleClickButton(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
this.context = context;
|
|
|
|
super.setOnClickListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public SingleClickButton(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
this.context = context;
|
|
|
|
super.setOnClickListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setOnClickListener(@Nullable OnClickListener l) {
|
|
|
|
listener = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
|
|
|
setEnabled(false);
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
SystemClock.sleep(3000);
|
|
|
|
Activity activity = (Activity) context;
|
|
|
|
if (activity != null)
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
setEnabled(true);
|
|
|
|
log.debug("Button enabled");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
if (listener != null)
|
|
|
|
listener.onClick(v);
|
|
|
|
}
|
|
|
|
}
|