class MainActivity : ComponentActivity(), ICounterStatusNotify
{
private lateinit var rootComponent : ViewRoot
- //private var pendingStart = false
+ private var pendingStart = false
//private var stopTrigger: ITimerStopTrigger? = null
/**
}
}
- //AppSingleton.controller.setupReferenceData()
- //if (isStartTimer)
- //{
- // pendingStart = true
- //}
+ AppSingleton.controller.setupReferenceData()
+ if (isStartTimer)
+ {
+ pendingStart = true
+ }
}
/**
{
try
{
- Log.v(TAG, "counterStatusChanged($forceStartTimer)")
+ Log.v(TAG, "counterStatusChanged($forceStartTimer), pendingStart:v$pendingStart")
if (forceStartTimer)
{
AppSingleton.timerCounter.start()
}
- //runOnUiThread {
- // if (pendingStart)
- // {
- // AppSingleton.timerCounter.start()
- // pendingStart = false
- // }
- //}
+ runOnUiThread {
+ if (pendingStart)
+ {
+ AppSingleton.timerCounter.start()
+ pendingStart = false
+ }
+ }
}
catch (e: Exception)
{
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.sp
-import androidx.navigation.NavHostController
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.Text
+import net.osdn.gokigen.joggingtimer.stopwatch.timer.ITimerCounter
+import net.osdn.ja.gokigen.wearos.timerapp.counter.TimeStringConvert
@Composable
-fun LapTimeList(navController: NavHostController) {
+fun LapTimeList(counterManager: ITimerCounter)
+{
+ LapTimeListPastTime(counterManager)
+}
- Text(
- modifier = Modifier.fillMaxWidth(),
- textAlign = TextAlign.Center,
- color = MaterialTheme.colors.primary,
- text = "00:00:00.00",
- fontSize = 12.sp,
- )
- Text(
- modifier = Modifier.fillMaxWidth(),
- textAlign = TextAlign.Center,
- color = MaterialTheme.colors.primary,
- text = "00:00:00.00",
- fontSize = 12.sp,
- )
- Text(
- modifier = Modifier.fillMaxWidth(),
- textAlign = TextAlign.Center,
- color = MaterialTheme.colors.primary,
- text = "00:00:00.00",
- fontSize = 12.sp,
- )
- Text(
- modifier = Modifier.fillMaxWidth(),
- textAlign = TextAlign.Center,
- color = MaterialTheme.colors.primary,
- text = "00:00:00.00",
- fontSize = 12.sp,
- )
- Text(
- modifier = Modifier.fillMaxWidth(),
- textAlign = TextAlign.Center,
- color = MaterialTheme.colors.primary,
- text = "00:00:00.00",
- fontSize = 12.sp,
- )
- Text(
- modifier = Modifier.fillMaxWidth(),
- textAlign = TextAlign.Center,
- color = MaterialTheme.colors.primary,
- text = "00:00:00.00",
- fontSize = 12.sp,
- )
+@Composable
+fun LapTimeListPastTime(counterManager: ITimerCounter)
+{
+ // (通常の)ラップタイム表示
+ val lapTimeCount = counterManager.getLapTimeCount()
+ val stopLapIndex = 1
+ //val stopLapIndex = if (lapTimeCount > (5 + 1)) { lapTimeCount - 5 } else { 1 } // 表示するラップ数を最大5に制限する場合...
+ if (lapTimeCount > 0)
+ {
+ // 最新ラップタイムが上に表示されるようにしてみる
+ for (lapTimeIndex in (lapTimeCount - 1) downTo stopLapIndex)
+ {
+ val lapTime = counterManager.getLapTime(lapTimeIndex)
+ val previousTime = counterManager.getLapTime(lapTimeIndex - 1)
+ val timeString = TimeStringConvert.getTimeString(lapTime - previousTime)
+ Text(
+ modifier = Modifier.fillMaxWidth(),
+ textAlign = TextAlign.Center,
+ color = MaterialTheme.colors.primary,
+ text = "[${lapTimeIndex}] $timeString",
+ fontSize = 12.sp,
+ )
+ }
+ }
+ else
+ {
+ // ラップタイムがない(リセットされている)場合...
+ Text(
+ modifier = Modifier.fillMaxWidth(),
+ textAlign = TextAlign.Center,
+ color = MaterialTheme.colors.primary,
+ text = " - - - - - ",
+ fontSize = 12.sp,
+ )
+ }
}
fun MainCounter(counterManager: ITimerCounter)
{
val totalTimeValue = counterManager.getPastTime() //- counterManager.getStartTime()
- val lapTimeValue = counterManager.getPastTime() - if (counterManager.getLastElapsedTime() <= 0 ) { 0 } else { counterManager.getLastElapsedTime() }
+ val lapTimeValue = counterManager.getPastTime() - if (counterManager.getLastLapTime() <= 0 ) { 0 } else { counterManager.getLastLapTime() }
val finishTimeValue = counterManager.getStopTime() - counterManager.getStartTime()
val timeString = if (counterManager.getCounterMode()) {
// メインカウンタはトータル時間を表示する
when (counterManager.getCurrentCountStatus()) {
ICounterStatus.START -> {
// 実行中
- "[${counterManager.getElapsedCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
+ "[${counterManager.getLapTimeCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
}
ICounterStatus.STOP -> {
// 開始前
}
ICounterStatus.FINISHED -> {
// カウント終了
- "[${counterManager.getElapsedCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
+ "[${counterManager.getLapTimeCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
}
}
}
}
// ラップタイム一覧の表示
- LapTimeList(navController)
+ LapTimeList(counterManager)
// 現在の状態によって、サブボタンの表示を切り替える
when (counterManager.getCurrentCountStatus())
fun SubCounter(counterManager: ITimerCounter)
{
val totalTimeValue = counterManager.getPastTime() // - counterManager.getStartTime()
- val lapTimeValue = counterManager.getPastTime() - if (counterManager.getLastElapsedTime() <= 0 ) { 0 } else { counterManager.getLastElapsedTime() }
+ val lapTimeValue = counterManager.getPastTime() - if (counterManager.getLastLapTime() <= 0 ) { 0 } else { counterManager.getLastLapTime() }
val finishTimeValue = counterManager.getStopTime() - counterManager.getStartTime()
val timeString = if (counterManager.getCounterMode()) {
// サブカウンタは、ラップタイムを表示する
when (counterManager.getCurrentCountStatus()) {
ICounterStatus.START -> {
// 実行中
- "[${counterManager.getElapsedCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
+ "[${counterManager.getLapTimeCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
}
ICounterStatus.STOP -> {
// 開始前
}
ICounterStatus.FINISHED -> {
// カウント終了
- "[${counterManager.getElapsedCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
+ "[${counterManager.getLapTimeCount()}] ${TimeStringConvert.getTimeString(lapTimeValue)}"
}
}
}
fun stop()
fun timeStamp(): Long
fun reset()
- fun getElapsedCount(): Int
+ fun getLapTimeCount(): Int
fun getPastTime(): Long
- fun getElapsedTime(lapCount: Int): Long
- fun getLastElapsedTime(): Long
- fun getCurrentElapsedTime(): Long
+ fun getLapTime(lapCount: Int): Long
+ fun getLastLapTime(): Long
+ fun getCurrentLapTime(): Long
fun getStartTime(): Long
fun getStopTime(): Long
fun getLapTimeList(): List<Long>
private var currentTimer = mutableLongStateOf(0)
private var currentLapCount = mutableIntStateOf(0)
private var referenceTimeId = 0
- private var elapsedTime: MutableList<Long>
+ private var lapTime: MutableList<Long>
private var referenceTimeA: List<Long>? = null
private var referenceTimeB: List<Long>? = null
private var referenceTimeC: List<Long>? = null
init
{
- elapsedTime = ArrayList()
+ lapTime = ArrayList()
currentLapCount.intValue = 0
currentTimer.longValue = 0L
}
{
startTime = System.currentTimeMillis()
stopTime = 0L
- elapsedTime.clear()
- elapsedTime.add(startTime)
+ lapTime.clear()
+ lapTime.add(startTime)
currentTimer.longValue = startTime
currentLapCount.intValue = 1
counterStatus.value = ICounterStatus.START
if (counterStatus.value == ICounterStatus.START)
{
timeToSet = System.currentTimeMillis()
- elapsedTime.add(timeToSet)
+ lapTime.add(timeToSet)
++(currentLapCount.intValue)
}
return timeToSet
if (counterStatus.value == ICounterStatus.START)
{
stopTime = System.currentTimeMillis()
- elapsedTime.add(stopTime)
+ lapTime.add(stopTime)
++(currentLapCount.intValue)
counterStatus.value = ICounterStatus.FINISHED
}
stopTime = 0L
currentTimer.longValue = 0L
currentLapCount.intValue = 0
- elapsedTime.clear()
+ lapTime.clear()
counterStatus.value = ICounterStatus.STOP
}
myTimer.forceStop()
}
- override fun getElapsedCount(): Int
+ override fun getLapTimeCount(): Int
{
return (currentLapCount.intValue)
}
}
}
- override fun getElapsedTime(lapCount: Int): Long
+ override fun getLapTime(lapCount: Int): Long
{
try
{
- return if (lapCount < 0) 0 else elapsedTime[lapCount] - startTime
+ return if (lapCount < 0) 0 else lapTime[lapCount] - startTime
}
catch (e: Exception)
{
e.printStackTrace()
}
- return getLastElapsedTime()
+ return getLastLapTime()
}
- override fun getLastElapsedTime(): Long
+ override fun getLastLapTime(): Long
{
try
{
- if (elapsedTime.size > 0)
+ if (lapTime.size > 0)
{
- return (elapsedTime[elapsedTime.size - 1] - startTime)
+ return (lapTime[lapTime.size - 1] - startTime)
}
}
catch (e: Exception)
return 0L
}
- override fun getCurrentElapsedTime(): Long
+ override fun getCurrentLapTime(): Long
{
val currentTime = System.currentTimeMillis()
try
{
- if (elapsedTime.size > 0)
+ if (lapTime.size > 0)
{
- return currentTime - elapsedTime[elapsedTime.size - 1]
+ return currentTime - lapTime[lapTime.size - 1]
}
}
catch (e: Exception)
}
override fun getLapTimeList(): List<Long>
{
- return elapsedTime
+ return lapTime
}
override fun setCallback(callback: ICounterStatusNotify)
myTimer.startTimer()
Log.v(TAG, "pastTime : $pastTime")
this.startTime = startTime
- elapsedTime = ArrayList(timelist)
+ lapTime = ArrayList(timelist)
stopTime = 0L
- currentLapCount.intValue = elapsedTime.size
+ currentLapCount.intValue = lapTime.size
counterStatus.value = ICounterStatus.START
callback?.counterStatusChanged(true)
}