-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,140 additions
and
181 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
50 changes: 50 additions & 0 deletions
50
automotive/src/main/java/com/ixam97/carStatsViewer/carApp/CarStatsTab.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,50 @@ | ||
package com.ixam97.carStatsViewer.carApp | ||
|
||
import android.car.Car | ||
import androidx.annotation.OptIn | ||
import androidx.car.app.annotations.ExperimentalCarApi | ||
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.core.graphics.drawable.IconCompat | ||
import com.ixam97.carStatsViewer.CarStatsViewer | ||
import com.ixam97.carStatsViewer.R | ||
|
||
@OptIn(ExperimentalCarApi::class) | ||
internal fun CarStatsViewerScreen.CarStatsList() = ListTemplate.Builder().apply { | ||
addSectionedList(SectionedItemList.create( | ||
ItemList.Builder().apply { | ||
addItem(Row.Builder().apply { | ||
setTitle("Not yet supported!") | ||
setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_construction)).build()) | ||
}.build()) | ||
}.build(), | ||
"Real time data" | ||
)) | ||
addSectionedList(SectionedItemList.create( | ||
ItemList.Builder().apply { | ||
|
||
apiState.forEach { (apiName, status) -> | ||
val apiIconColor = when (status) { | ||
0 -> colorDisconnected | ||
1 -> colorConnected | ||
2 -> colorLimited | ||
else -> colorError | ||
} | ||
addItem(Row.Builder().apply { | ||
setTitle(apiName) | ||
addText(when (status) { | ||
0 -> "Disabled" | ||
1 -> "Connected" | ||
2 -> "Limited" | ||
else -> "Error" | ||
}) | ||
setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_connected)).setTint(apiIconColor).build()) | ||
}.build()) | ||
} | ||
}.build(), | ||
"APIs" | ||
)) | ||
}.build() |
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
51 changes: 51 additions & 0 deletions
51
automotive/src/main/java/com/ixam97/carStatsViewer/carApp/ConfirmResetScreen.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,51 @@ | ||
package com.ixam97.carStatsViewer.carApp | ||
|
||
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.CarIcon | ||
import androidx.car.app.model.MessageTemplate | ||
import androidx.car.app.model.Template | ||
import androidx.core.graphics.drawable.IconCompat | ||
import com.ixam97.carStatsViewer.CarStatsViewer | ||
import com.ixam97.carStatsViewer.R | ||
import com.ixam97.carStatsViewer.database.tripData.TripType | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
class ConfirmResetScreen(carContext: CarContext) : Screen(carContext) { | ||
|
||
override fun onGetTemplate(): Template { | ||
return dialogTemplate() | ||
} | ||
|
||
private fun dialogTemplate() = MessageTemplate.Builder( | ||
carContext.getString(R.string.dialog_reset_message) | ||
).apply { | ||
// addAction(Action.BACK) | ||
setHeaderAction(Action.BACK) | ||
setTitle(carContext.getString(R.string.dialog_reset_title)) | ||
setIcon(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_reset)).build()) | ||
addAction(Action.Builder().apply { | ||
setTitle(carContext.getString(R.string.dialog_reset_confirm)) | ||
setFlags(Action.FLAG_PRIMARY) | ||
setOnClickListener { | ||
CoroutineScope(Dispatchers.IO).launch { | ||
CarStatsViewer.dataProcessor.resetTrip( | ||
TripType.MANUAL, | ||
CarStatsViewer.dataProcessor.realTimeData.drivingState | ||
) | ||
} | ||
screenManager.popToRoot() | ||
} | ||
}.build()) | ||
addAction(Action.Builder().apply { | ||
setTitle(carContext.getString(R.string.dialog_reset_cancel)) | ||
setOnClickListener { | ||
screenManager.pop() | ||
} | ||
}.build()) | ||
}.build() | ||
} |
55 changes: 55 additions & 0 deletions
55
automotive/src/main/java/com/ixam97/carStatsViewer/carApp/MenuTab.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,55 @@ | ||
package com.ixam97.carStatsViewer.carApp | ||
|
||
import android.content.Intent | ||
import androidx.car.app.CarContext | ||
import androidx.car.app.Screen | ||
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.Template | ||
import androidx.core.graphics.drawable.IconCompat | ||
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 | ||
|
||
internal fun CarStatsViewerScreen.MenuList() = ListTemplate.Builder().apply { | ||
|
||
val settingsActivityIntent = Intent(carContext, SettingsActivity::class.java).apply { | ||
flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
} | ||
val mainActivityIntent = Intent(carContext, MainActivity::class.java).apply { | ||
flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
} | ||
val historyActivityIntent = Intent(carContext, HistoryActivity::class.java).apply { | ||
flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
} | ||
|
||
setSingleList(ItemList.Builder().apply { | ||
addItem(Row.Builder().apply{ | ||
setTitle(carContext.getString(R.string.car_app_dashboard)) | ||
setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_diagram)).build()) | ||
setBrowsable(true) | ||
setOnClickListener { | ||
carContext.startActivity(mainActivityIntent) | ||
} | ||
}.build()) | ||
addItem(Row.Builder().apply{ | ||
setTitle(carContext.getString(R.string.history_title)) | ||
setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_history)).build()) | ||
setBrowsable(true) | ||
setOnClickListener { | ||
carContext.startActivity(historyActivityIntent) | ||
} | ||
}.build()) | ||
addItem(Row.Builder().apply{ | ||
setTitle(carContext.getString(R.string.settings_title)) | ||
setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_settings)).build()) | ||
setBrowsable(true) | ||
setOnClickListener { | ||
carContext.startActivity(settingsActivityIntent) | ||
} | ||
}.build()) | ||
}.build()) | ||
}.build() |
82 changes: 82 additions & 0 deletions
82
automotive/src/main/java/com/ixam97/carStatsViewer/carApp/TripDataSettingsScreen.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,82 @@ | ||
package com.ixam97.carStatsViewer.carApp | ||
|
||
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.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.graphics.drawable.IconCompat | ||
import com.ixam97.carStatsViewer.CarStatsViewer | ||
import com.ixam97.carStatsViewer.R | ||
|
||
class TripDataSettingsScreen(carContext: CarContext) : Screen(carContext) { | ||
|
||
override fun onGetTemplate(): Template { | ||
return tripDataSettingsList() | ||
} | ||
|
||
private fun tripDataSettingsList() = ListTemplate.Builder().apply { | ||
setTitle(carContext.getString(R.string.car_app_trip_data)) | ||
setHeaderAction(Action.BACK) | ||
if (CarStatsViewer.appPreferences.mainViewTrip == 0) { | ||
setActionStrip(ActionStrip.Builder().apply { | ||
addAction(Action.Builder().apply { | ||
// setIcon(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_reset)).build()) | ||
setTitle(carContext.getString(R.string.dialog_reset_confirm)) | ||
setOnClickListener { | ||
screenManager.push(ConfirmResetScreen(carContext)) | ||
} | ||
}.build()) | ||
}.build()) | ||
} | ||
addSectionedList(SectionedItemList.create(ItemList.Builder().apply { | ||
setSelectedIndex(CarStatsViewer.appPreferences.mainViewTrip) | ||
addItem(tripTypeRow(0)) | ||
addItem(tripTypeRow(1)) | ||
addItem(tripTypeRow(2)) | ||
addItem(tripTypeRow(3)) | ||
setOnSelectedListener{ changeSelectedTrip(it) } | ||
}.build(), carContext.getString(R.string.settings_select_trip))) | ||
// addSectionedList(SectionedItemList.create(ItemList.Builder().apply { | ||
// addItem(Row.Builder().apply { | ||
// setTitle(carContext.getString(R.string.summary_button_reset_trip)) | ||
// setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_reset)).build()) | ||
// setOnClickListener { | ||
// screenManager.push(ConfirmResetScreen(carContext)) | ||
// } | ||
// }.build()) | ||
// }.build(), carContext.getString(R.string.CurrentTripData))) | ||
}.build() | ||
|
||
private fun changeSelectedTrip(index: Int) { | ||
CarStatsViewer.dataProcessor.changeSelectedTrip(index + 1) | ||
CarStatsViewer.appPreferences.mainViewTrip = index | ||
screenManager.popToRoot() | ||
} | ||
private fun tripTypeRow(tripType: Int) = Row.Builder().apply { | ||
when (tripType) { | ||
0 -> { | ||
setTitle(carContext.getString(R.string.CurrentTripData)) | ||
setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_hand)).build()) | ||
} | ||
1 -> { | ||
setTitle(carContext.getString(R.string.SinceChargeData)) | ||
setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_charger)).build()) | ||
} | ||
2 -> { | ||
setTitle(carContext.getString(R.string.AutoTripData)) | ||
setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_day)).build()) | ||
} | ||
3 -> { | ||
setTitle(carContext.getString(R.string.CurrentMonthData)) | ||
setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_month)).build()) | ||
} | ||
else -> throw Exception("Unknown Trip Type!") | ||
} | ||
}.build() | ||
} |
Oops, something went wrong.