-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addded build variant to test Google Play Store compatibility
- Loading branch information
Showing
14 changed files
with
389 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name" translatable="false">Car Stats Viewer (Play Edition, Dev)</string> | ||
<string name="app_name_short" translatable="false">CSV (Play, Dev)</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
automotive/src/main/java/com/ixam97/carStatsViewer/aaos/CarStatsViewerScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.ixam97.carStatsViewer.aaos | ||
|
||
import android.content.Intent | ||
import androidx.car.app.CarContext | ||
import androidx.car.app.Screen | ||
import androidx.car.app.model.Action | ||
import androidx.car.app.model.ActionStrip | ||
import androidx.car.app.model.CarColor | ||
import androidx.car.app.model.CarIcon | ||
import androidx.car.app.model.ItemList | ||
import androidx.car.app.model.ListTemplate | ||
import androidx.car.app.model.Row | ||
import androidx.car.app.model.SectionedItemList | ||
import androidx.car.app.model.Template | ||
import androidx.core.content.ContextCompat | ||
import androidx.core.graphics.drawable.IconCompat | ||
import com.ixam97.carStatsViewer.CarStatsViewer | ||
import com.ixam97.carStatsViewer.R | ||
import com.ixam97.carStatsViewer.ui.activities.HistoryActivity | ||
import com.ixam97.carStatsViewer.ui.activities.MainActivity | ||
import com.ixam97.carStatsViewer.ui.activities.SettingsActivity | ||
import com.ixam97.carStatsViewer.utils.InAppLogger | ||
import com.ixam97.carStatsViewer.utils.StringFormatters | ||
|
||
|
||
class CarStatsViewerScreen(carContext: CarContext) : Screen(carContext) { | ||
|
||
private var apiStateString = "No Data" | ||
private var speed : Float? = 0f | ||
private var power : Float? = 0f | ||
init { | ||
setupListeners() | ||
} | ||
|
||
private fun setupListeners() { | ||
val exec = ContextCompat.getMainExecutor(carContext) | ||
CarStatsViewer.watchdog.setAaosCallback(exec) { updateLiveData() } | ||
CarStatsViewer.dataProcessor.setAaosCallback(exec) { updateLiveData() } | ||
} | ||
private fun updateLiveData() { | ||
val apiState = CarStatsViewer.watchdog.getCurrentWatchdogState().apiState | ||
val realTimeData = CarStatsViewer.dataProcessor.realTimeData | ||
InAppLogger.d("[AAOS] Updating live data: $apiState") | ||
apiStateString = apiState.toString() | ||
speed = realTimeData.speed | ||
power = realTimeData.power | ||
invalidate() | ||
} | ||
override fun onGetTemplate(): Template { | ||
val settingsActivityIntent = Intent(carContext, SettingsActivity::class.java) | ||
settingsActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
val mainActivityIntent = Intent(carContext, MainActivity::class.java) | ||
mainActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
val historyActivityIntent = Intent(carContext, HistoryActivity::class.java) | ||
historyActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
|
||
val dashboardRow = Row.Builder() | ||
.setTitle("Open Dashboard") | ||
.setOnClickListener { | ||
carContext.startActivity(mainActivityIntent) | ||
} | ||
.setImage( | ||
CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_diagram)) | ||
.setTint(CarColor.DEFAULT).build() | ||
) | ||
.setBrowsable(true) | ||
.build() | ||
val historyRow = Row.Builder() | ||
.setTitle("Open Trip History") | ||
.setOnClickListener { | ||
carContext.startActivity(historyActivityIntent) | ||
} | ||
.setImage( | ||
CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_history)) | ||
.setTint(CarColor.DEFAULT).build() | ||
) | ||
.setBrowsable(true) | ||
.build() | ||
|
||
return ListTemplate.Builder().apply { | ||
setTitle(carContext.getString(R.string.app_name)) | ||
setHeaderAction(Action.APP_ICON) | ||
setActionStrip(ActionStrip.Builder().apply { | ||
addAction(Action.Builder().apply { | ||
setIcon(CarIcon.Builder( | ||
IconCompat.createWithResource(carContext, R.drawable.ic_settings) | ||
).setTint(CarColor.DEFAULT).build()) | ||
setOnClickListener { | ||
carContext.startActivity(settingsActivityIntent) | ||
} | ||
}.build()) | ||
}.build()) | ||
|
||
addSectionedList(SectionedItemList.create(ItemList.Builder().apply { | ||
addItem(dashboardRow) | ||
addItem(historyRow) | ||
}.build(), "Main Functions")) | ||
|
||
addSectionedList(SectionedItemList.create(ItemList.Builder().apply { | ||
addItem(Row.Builder().apply { | ||
setTitle(apiStateString) | ||
}.build()) | ||
}.build(), "API Status")) | ||
|
||
addSectionedList(SectionedItemList.create(ItemList.Builder().apply { | ||
addItem(Row.Builder().apply { | ||
setTitle("${((speed?:0f) * 3.6f).toInt()} km/h") | ||
addText("Speed") | ||
}.build()) | ||
addItem(Row.Builder().apply { | ||
setTitle("${((power?:0f) / 1_000_000).toInt()} kW") | ||
addText("Power") | ||
}.build()) | ||
}.build(), "Car Data")) | ||
|
||
}.build() | ||
} | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
automotive/src/main/java/com/ixam97/carStatsViewer/aaos/CarStatsViewerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.ixam97.carStatsViewer.aaos | ||
|
||
import android.content.pm.ApplicationInfo | ||
import androidx.car.app.CarAppService | ||
import androidx.car.app.Session | ||
import androidx.car.app.SessionInfo | ||
import androidx.car.app.validation.HostValidator | ||
|
||
|
||
class CarStatsViewerService : CarAppService() { | ||
override fun onCreateSession(sessionInfo: SessionInfo): Session { | ||
return CarStatsViewerSession() | ||
} | ||
|
||
override fun createHostValidator(): HostValidator { | ||
return if (getApplicationInfo().flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) { | ||
HostValidator.ALLOW_ALL_HOSTS_VALIDATOR | ||
} else { | ||
HostValidator.Builder(getApplicationContext()) | ||
.addAllowedHosts(androidx.car.app.R.array.hosts_allowlist_sample) | ||
.build() | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
automotive/src/main/java/com/ixam97/carStatsViewer/aaos/CarStatsViewerSession.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.ixam97.carStatsViewer.aaos | ||
|
||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import androidx.car.app.Screen | ||
import androidx.car.app.Session | ||
import com.ixam97.carStatsViewer.dataCollector.DataCollector | ||
import com.ixam97.carStatsViewer.ui.activities.PermissionsActivity | ||
|
||
class CarStatsViewerSession : Session() { | ||
|
||
val permissions = PermissionsActivity.PERMISSIONS.toList() | ||
override fun onCreateScreen(intent: Intent): Screen { | ||
var neededPermissions = permissions.filter { carContext.checkSelfPermission(it) != PackageManager.PERMISSION_GRANTED } | ||
if (neededPermissions.isNotEmpty()) { | ||
carContext.requestPermissions(permissions) {granted,_ -> | ||
if (granted.containsAll(permissions)) { | ||
startService() | ||
} | ||
} | ||
} else { | ||
startService() | ||
} | ||
return CarStatsViewerScreen(carContext) | ||
} | ||
|
||
private fun startService() { | ||
carContext.startForegroundService(Intent(carContext, DataCollector::class.java)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.