package timeline.lizimumu.com.t.ui;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Chronometer;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import com.fancy.androidutils.utils.DateUtils;
import com.fancy.androidutils.utils.ToastUtils;
import dev.xesam.android.toolbox.timer.CountTimer;
import timeline.lizimumu.com.t.R;
import timeline.lizimumu.com.t.data.TimerEntity;
import timeline.lizimumu.com.t.util.DateViewUtils;
public class SubTimerSortActivity extends AppCompatActivity {
private TextView tvUsedTime;
private boolean isFirst = true;
private long startTime;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub_timer_sort);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getIntent().getStringExtra("title"));
}
initView();
initData();
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.home) {
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
private void initView() {
tvUsedTime = findViewById(R.id.tv_used_time);
TextView tvStart = findViewById(R.id.tv_start);
TextView tvPause = findViewById(R.id.tv_pause);
TextView tvEnd = findViewById(R.id.tv_end);
timer.start();
startTime = System.currentTimeMillis();
tvStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
timer.resume();
}
});
tvPause.setOnClickListener(view -> timer.pause());
tvEnd.setOnClickListener(view -> {
long endTime = System.currentTimeMillis();
TimerEntity timerEntity = new TimerEntity();
timerEntity.setStartTime(DateUtils.formatDateTime(startTime, DateUtils.DF_HH_MM_SS));
timerEntity.setEndTime(DateUtils.formatDateTime(endTime, DateUtils.DF_HH_MM_SS));
int totalSec = (int) ((endTime - startTime) / 1000);
Log.e("fanlcly", totalSec + "");
int min = totalSec / 60;
int hour = min / 60;
int hour_sec = totalSec % (60 * 60);
int sec = hour_sec % 60;
timerEntity.setTotalTime(hour + ":" + min + ":" + sec);
timerEntity.setEventName(getIntent().getStringExtra("title"));
Intent intent = new Intent();
intent.putExtra("entity", timerEntity);
setResult(2022, intent);
finish();
});
}
private void initData() {
}
CountTimer timer = new
CountTimer(100) {
@Override
public void onTick(long millisFly) { // millisFly is the Elapsed time at *Running State*
tvUsedTime.setText(((int) millisFly / 1000) + "");
Log.d("onTick", millisFly + "");
}
};
}