2017-11-08 12:20:11 -08:00
|
|
|
package org.thoughtcrime.securesms.components.registration;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.annotation.RequiresApi;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
2019-02-13 11:52:55 -08:00
|
|
|
import android.widget.Button;
|
2017-11-08 12:20:11 -08:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
|
|
|
|
2019-02-13 11:52:55 -08:00
|
|
|
public class CallMeCountDownView extends android.support.v7.widget.AppCompatButton {
|
2017-11-08 12:20:11 -08:00
|
|
|
|
2019-02-13 11:52:55 -08:00
|
|
|
private int countDown;
|
2017-11-08 12:20:11 -08:00
|
|
|
|
|
|
|
public CallMeCountDownView(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CallMeCountDownView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CallMeCountDownView(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startCountDown(int countDown) {
|
|
|
|
this.countDown = countDown;
|
|
|
|
updateCountDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCallEnabled() {
|
2019-02-13 11:52:55 -08:00
|
|
|
setText(R.string.RegistrationActivity_call);
|
|
|
|
setEnabled(true);
|
|
|
|
setAlpha(1.0f);
|
2017-11-08 12:20:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateCountDown() {
|
|
|
|
if (countDown > 0) {
|
2019-02-13 11:52:55 -08:00
|
|
|
setEnabled(false);
|
|
|
|
setAlpha(0.5f);
|
|
|
|
|
2017-11-08 12:20:11 -08:00
|
|
|
countDown--;
|
|
|
|
|
|
|
|
int minutesRemaining = countDown / 60;
|
|
|
|
int secondsRemaining = countDown - (minutesRemaining * 60);
|
|
|
|
|
2019-02-13 11:52:55 -08:00
|
|
|
setText(getResources().getString(R.string.RegistrationActivity_call_me_instead_available_in, minutesRemaining, secondsRemaining));
|
|
|
|
postDelayed(this::updateCountDown, 1000);
|
2017-11-08 12:20:11 -08:00
|
|
|
} else if (countDown == 0) {
|
|
|
|
setCallEnabled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|