package net.osdn.gokigen.joggingtimer.recordlist
+import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.util.Log
*/
class ListActivity : AppCompatActivity(),
IDetailLauncher, RecordSummarySetup.IDatabaseReadyNotify, ICreatedModelDataCallback,
- ListSelectionMenuAdapter.ISelectedMenu, AmbientModeSupport.AmbientCallbackProvider {
- private val TAG = toString()
+ ListSelectionMenuAdapter.ISelectedMenu, AmbientModeSupport.AmbientCallbackProvider
+{
private var summaryAdapter: RecordSummaryAdapter? = null
private var setupper: RecordSummarySetup? = null
/**
*
*/
- override fun onCreate(savedInstanceState: Bundle?) {
+ override fun onCreate(savedInstanceState: Bundle?)
+ {
super.onCreate(savedInstanceState)
Log.v(TAG, "onCreate()")
setContentView(R.layout.activity_list)
// Enables Always-on
//setAmbientEnabled();
- try {
+ try
+ {
val ambientController = AmbientModeSupport.attach(this)
ambientController.setAutoResumeEnabled(true)
//boolean isAmbient = ambientController.isAmbient();
- } catch (e: Exception) {
+ }
+ catch (e: Exception)
+ {
e.printStackTrace()
}
- try {
+ try
+ {
val naviView =
findViewById<WearableNavigationDrawerView>(R.id.list_top_navigation_drawer)
val menuAdapter = ListSelectionMenuAdapter(this, this)
view.addItemDecoration(dividerDecoration)
view.layoutManager = layoutManager
view.adapter = summaryAdapter
- } catch (e: Exception) {
+ }
+ catch (e: Exception)
+ {
e.printStackTrace()
summaryAdapter = null
}
/**
*
*/
- override fun onSaveInstanceState(outState: Bundle) {
- super.onSaveInstanceState(outState)
- }
-
- /**
- *
- */
- override fun onRestoreInstanceState(savedInstanceState: Bundle) {
- super.onRestoreInstanceState(savedInstanceState)
- }
-
- /**
- *
- */
- override fun onResume() {
+ override fun onResume()
+ {
super.onResume()
Log.v(TAG, "onResume()")
- try {
+ try
+ {
setupper = RecordSummarySetup(this, this, this, summaryAdapter, this)
- setupper!!.setup()
- } catch (e: Exception) {
+ setupper?.setup()
+ }
+ catch (e: Exception)
+ {
e.printStackTrace()
}
}
/**
*
*/
- override fun onPause() {
+ override fun onPause()
+ {
super.onPause()
Log.v(TAG, "onPause()")
- try {
- if (setupper != null) {
- setupper!!.closeDatabase()
+ try
+ {
+ if (setupper != null)
+ {
+ setupper?.closeDatabase()
setupper = null
}
- } catch (e: Exception) {
+ }
+ catch (e: Exception)
+ {
e.printStackTrace()
}
System.gc()
*
*
*/
- public override fun onStart() {
+ public override fun onStart()
+ {
super.onStart()
Log.v(TAG, "onStart()")
}
*
*
*/
- public override fun onStop() {
+ public override fun onStop()
+ {
super.onStop()
Log.v(TAG, "onStop()")
}
- /*
- @Override
- public void onEnterAmbient(Bundle ambientDetails)
- {
- super.onEnterAmbient(ambientDetails);
- Log.v(TAG, "onEnterAmbient()");
- }
-
- @Override
- public void onExitAmbient()
- {
- super.onExitAmbient();
- Log.v(TAG, "onExitAmbient()");
- }
-
- @Override
- public void onUpdateAmbient()
- {
- super.onUpdateAmbient();
- Log.v(TAG, "onUpdateAmbient()");
- }
-*/
override fun onGenericMotionEvent(ev: MotionEvent?): Boolean
{
*
*
*/
- override fun launchDetail(recordId: Long) {
+ override fun launchDetail(recordId: Long)
+ {
Log.v(TAG, "launchDetail() id:$recordId")
- try {
+ try
+ {
val intent = Intent(this, DetailActivity::class.java)
intent.putExtra(DetailActivity.INTENT_EXTRA_DATA_ID, recordId)
startActivity(intent)
- } catch (e: Exception) {
+ }
+ catch (e: Exception)
+ {
e.printStackTrace()
}
}
*
*
*/
- private fun itemSelected(itemId: Int) {
- //String toastMessage = "";
- if (itemId == R.id.menu_create_model) {
+ private fun itemSelected(itemId: Int)
+ {
+ if (itemId == R.id.menu_create_model)
+ {
// モデルデータの作成
val dialog2 = CreateModelDataDialog.newInstance(
true,
getString(R.string.information_time_picker),
0,
- setupper!!.getCreateModelDataCallback(
+ setupper?.getCreateModelDataCallback(
ITimeEntryDatabase.DONT_USE_ID,
ITimeEntryDatabase.DONT_USE_ID
),
)
dialog2.show(supportFragmentManager, "dialog2")
}
- /*
- try
- {
- if (toastMessage.length() > 0)
- {
- Toast toast = Toast.makeText(getApplicationContext(), toastMessage, Toast.LENGTH_SHORT);
- toast.show();
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- */
}
/**
*
*
*/
- override fun deleteRecord(targetRecord: DataRecord) {
- try {
+ override fun deleteRecord(targetRecord: DataRecord)
+ {
+ try
+ {
val positionId = targetRecord.positionId
val title = targetRecord.title
Log.v(TAG, "deleteRecord() : $title")
}
}
dialog.show(supportFragmentManager, "dialog")
- } catch (e: Exception) {
+ }
+ catch (e: Exception)
+ {
e.printStackTrace()
}
}
*
*
*/
- override fun databaseSetupFinished(result: Boolean) {
+ override fun databaseSetupFinished(result: Boolean)
+ {
Log.v(TAG, "databaseSetupFinished() : $result")
}
*
*
*/
- override fun selectedMenu(itemId: Int) {
+ override fun selectedMenu(itemId: Int)
+ {
itemSelected(itemId)
}
*
*
*/
- override fun createdModelData(indexId: Long) {
- // データの登録
- setupper!!.setIndexData(indexId)
+ @SuppressLint("NotifyDataSetChanged")
+ override fun createdModelData(indexId: Long)
+ {
+ try
+ {
+ // データの登録
+ setupper?.setIndexData(indexId)
- // 一覧の更新
- runOnUiThread {
- if (summaryAdapter != null) {
- val count = summaryAdapter!!.itemCount
- summaryAdapter!!.notifyItemChanged(count - 1)
- summaryAdapter!!.notifyDataSetChanged()
- }
+ // 一覧の更新
+ runOnUiThread {
+ if (summaryAdapter != null)
+ {
+ val count = summaryAdapter?.itemCount ?: 1
+ summaryAdapter?.notifyItemChanged(count - 1)
+ summaryAdapter?.notifyDataSetChanged()
+ }
- // Toastで作成を通知する
- val toast = Toast.makeText(
- applicationContext,
- getString(R.string.created_model_data),
- Toast.LENGTH_SHORT
- )
- toast.show()
+ // Toastで作成を通知する
+ val toast = Toast.makeText(
+ applicationContext,
+ getString(R.string.created_model_data),
+ Toast.LENGTH_SHORT
+ )
+ toast.show()
+ }
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
}
}
- override fun getAmbientCallback(): AmbientModeSupport.AmbientCallback {
+ override fun getAmbientCallback(): AmbientModeSupport.AmbientCallback
+ {
return object : AmbientModeSupport.AmbientCallback() {
- override fun onEnterAmbient(ambientDetails: Bundle) {
+ override fun onEnterAmbient(ambientDetails: Bundle)
+ {
Log.v(TAG, "onEnterAmbient()")
}
-
- fun onExitAmbient(ambientDetails: Bundle?) {
- Log.v(TAG, "onExitAmbient()")
- //updateTimerLabel();
- }
}
}
- override fun onPointerCaptureChanged(hasCapture: Boolean) {
- super.onPointerCaptureChanged(hasCapture)
+ companion object
+ {
+ private val TAG = ListActivity::class.java.simpleName
}
-}
\ No newline at end of file
+}
package net.osdn.gokigen.joggingtimer.stopwatch
+import android.content.Context
import android.content.Intent
import android.util.Log
+import net.osdn.gokigen.joggingtimer.storage.ITimeEntryDatabaseCallback
+import net.osdn.gokigen.joggingtimer.storage.TimeEntryDatabaseFactory
import java.lang.Exception
-class IntentSendImporter
+class IntentSendImporter(context: Context, val intent: Intent) : ITimeEntryDatabaseCallback
{
- fun handleIntent(receivedIntent: Intent)
+ val database = TimeEntryDatabaseFactory(context, this).entryDatabase
+
+ fun start()
+ {
+ database.prepare()
+ }
+ private fun handleIntent(receivedIntent: Intent)
{
try
{
}
Log.v(TAG, " ===== handleIntent: ${receivedIntent.action} : $title")
- var nofLapTime = 0
- val timeValueList = ArrayList<String>()
+ var totalTime: Long = 0
+ val lapTimeList = ArrayList<Long>()
val lines = data.split("\r?\n".toRegex())
for ((currentLine, line) in lines.withIndex())
{
// 正当なデータがないので抜ける
break
}
- timeValueList.add(timeValue[3])
- nofLapTime++
+ val lapTime = timeValue[3].toLong()
+ totalTime += lapTime
+ lapTimeList.add(lapTime)
}
}
val dataTitle = title ?: "imported data"
- importLapTime(dataTitle, timeValueList)
+ importLapTime(dataTitle, totalTime, lapTimeList)
}
catch (e: Exception)
{
e.printStackTrace()
}
}
-
- private fun importLapTime(title: String, lapTimeList: ArrayList<String>)
+ private fun importLapTime(dataTitle: String, totalTime: Long, lapTimeList: ArrayList<Long>)
{
- // ここでデータベースにデータを入れる
- // 題名 : title (String型)
- // ラップタイムの配列 : timeValueList (Int型、単位は ms)
- Log.v(TAG, " ----- $title ----- ")
+ // ここでデータベースにデータを入れる (入れたあとはコールバックで戻る)
+ database.createImportedTimeEntryData(dataTitle, "imported data", totalTime, lapTimeList)
+/*
+ // 題名 : dataTitle (String型)
+ // ラップタイムの配列 : lapTimeList (Int型、単位は ms)
+ Log.v(TAG, " ----- $dataTitle ----- ")
for ((index, timeValue) in lapTimeList.withIndex())
{
Log.v(TAG, " $index $timeValue")
}
Log.v(TAG, " ---------- ")
-
+*/
}
companion object
{
private val TAG = IntentSendImporter::class.java.simpleName
}
+
+ override fun prepareFinished(isReady: Boolean)
+ {
+ handleIntent(intent)
+ }
+
+ override fun dataEntryFinished(
+ operationType: ITimeEntryDatabaseCallback.OperationType?,
+ result: Boolean,
+ id: Long,
+ title: String?
+ )
+ {
+ Log.v(TAG, "dataEntryFinished()")
+ }
+
+ override fun timeEntryFinished(
+ operationType: ITimeEntryDatabaseCallback.OperationType?,
+ result: Boolean,
+ indexId: Long,
+ dataId: Long
+ )
+ {
+ Log.v(TAG, "timeEntryFinished()")
+ }
+
+ override fun modelDataEntryFinished(
+ operationType: ITimeEntryDatabaseCallback.OperationType?,
+ result: Boolean,
+ indexId: Long,
+ title: String?
+ )
+ {
+ Log.v(TAG, "modelDataEntryFinished()")
+ }
}
\ No newline at end of file