Browse Source

Prepare for RESET & Export

master
sipp11 5 years ago
parent
commit
9ca76b99ae
  1. 2
      .idea/misc.xml
  2. 24
      app/src/main/java/co/zzyzx/sensorlogger/MainActivity.kt
  3. 36
      app/src/main/res/layout/activity_main.xml
  4. 1
      app/src/main/res/values/colors.xml

2
.idea/misc.xml

@ -5,7 +5,7 @@
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" /> <configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations> </configurations>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

24
app/src/main/java/co/zzyzx/sensorlogger/MainActivity.kt

@ -67,11 +67,21 @@ class MainActivity : AppCompatActivity(),
private fun updateCounter() { private fun updateCounter() {
val runnable = Runnable { updateCounter() } val runnable = Runnable { updateCounter() }
var hasData = false
val sensors = arrayOf("location", "accelerometer", "gyroscope") val sensors = arrayOf("location", "accelerometer", "gyroscope")
var text = mutableListOf<String>("Status", "-------------------------------") var text = mutableListOf<String>("Status", "-------------------------------")
for (sensor in sensors) { for (sensor in sensors) {
val count = recRepo.getRecordCount(sensor) val count = recRepo.getRecordCount(sensor)
text.add("$sensor --- $count records") text.add("$sensor --- $count records")
hasData = count > 0
}
if (hasData) {
reset_record_btn.visibility = View.VISIBLE
export_record_btn.visibility = View.VISIBLE
} else {
reset_record_btn.visibility = View.GONE
export_record_btn.visibility = View.GONE
} }
status_textview.text = text.joinToString(System.getProperty("line.separator")) status_textview.text = text.joinToString(System.getProperty("line.separator"))
@ -135,7 +145,18 @@ class MainActivity : AppCompatActivity(),
} }
private fun actionOnService(action: Actions) { private fun actionOnService(action: Actions) {
if (getServiceState(this) == ServiceState.STOPPED && action == Actions.STOP) return when (action) {
Actions.START -> {
start_service_btn.visibility = View.GONE
stop_service_btn.visibility = View.VISIBLE
}
Actions.STOP -> {
start_service_btn.visibility = View.VISIBLE
stop_service_btn.visibility = View.GONE
if (getServiceState(this) == ServiceState.STOPPED)
return
}
}
Intent(this, EndlessService::class.java).also { Intent(this, EndlessService::class.java).also {
it.action = action.name it.action = action.name
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -146,6 +167,7 @@ class MainActivity : AppCompatActivity(),
log("Starting the service in < 26 Mode") log("Starting the service in < 26 Mode")
startService(it) startService(it)
} }
} }
override fun onRequestPermissionsResult( override fun onRequestPermissionsResult(

36
app/src/main/res/layout/activity_main.xml

@ -4,6 +4,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:paddingHorizontal="2dp"
tools:context=".MainActivity"> tools:context=".MainActivity">
@ -24,9 +25,9 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="3" android:layout_weight="3"
android:textAlignment="center"
android:background="@android:color/background_light" android:background="@android:color/background_light"
android:text="" /> android:text=""
android:textAlignment="center" />
<Button <Button
android:id="@+id/ask_location_permission_button" android:id="@+id/ask_location_permission_button"
@ -41,26 +42,47 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"> android:orientation="horizontal">
<Button <Button
android:id="@+id/start_service_btn" android:id="@+id/start_service_btn"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_gravity="center"
android:text="Start Foreground Service" /> android:text="Start " />
<Button <Button
android:id="@+id/stop_service_btn" android:id="@+id/stop_service_btn"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_gravity="center"
android:text="Stop Foreground Service" /> android:text="Stop ◼"
android:visibility="gone" />
<Button
android:id="@+id/reset_record_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Reset ✖"
android:visibility="gone" />
<Button
android:id="@+id/export_record_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Export 📃"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
<TextView <TextView
android:id="@+id/status_textview" android:id="@+id/status_textview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:background="@color/lightGray"
android:padding="5dp"/>
</LinearLayout> </LinearLayout>

1
app/src/main/res/values/colors.xml

@ -5,4 +5,5 @@
<color name="colorAccent">#D81B60</color> <color name="colorAccent">#D81B60</color>
<color name="green">#22DD22</color> <color name="green">#22DD22</color>
<color name="red">#DD2222</color> <color name="red">#DD2222</color>
<color name="lightGray">#F6F6F6</color>
</resources> </resources>

Loading…
Cancel
Save