Skip to content

Commit

Permalink
ui improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay-Kumar-S committed Mar 16, 2021
1 parent f2dd28a commit 8f21a97
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
18 changes: 9 additions & 9 deletions automotive/src/main/java/com/volvo/polestar/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.car.Car
import android.car.hardware.property.CarPropertyManager
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.volvo.polestar.interfaces.MainView
Expand All @@ -32,6 +31,7 @@ class MainActivity : AppCompatActivity(), MainView {
private lateinit var batteryCapacity: TextView
private lateinit var fuelType: TextView
private lateinit var connectorTypes: TextView
private lateinit var locationView: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -41,23 +41,17 @@ class MainActivity : AppCompatActivity(), MainView {
initUI()
updateUI()

Log.e(TAG, "onCreate: CarInfo")
CarUtil.getCarInfo(car)
Log.e(TAG, "onCreate: getCarProperties")
CarUtil.getCarProperties(car, vehicleProperties)

AndroidUtil.getAllInstalledApps(this)
AndroidUtil.getLocation(this)
}

private fun initCar() {
if (!packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) {
if (!packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE))
return
}

if (::car.isInitialized) {
if (::car.isInitialized)
return
}

car = Car.createCar(this)
vehicleProperties = VehicleProperties(this)
Expand All @@ -80,6 +74,8 @@ class MainActivity : AppCompatActivity(), MainView {
fuelCapacity = findViewById(R.id.car_fuel_capacity)
batteryCapacity = findViewById(R.id.car_battery_capacity)
connectorTypes = findViewById(R.id.car_ev_connectors)

locationView = findViewById(R.id.car_location)
}

@SuppressLint("SetTextI18n")
Expand All @@ -97,6 +93,10 @@ class MainActivity : AppCompatActivity(), MainView {
fuelCapacity.text = "Fuel Capacity: " + carInfo.fuelCapacity.toString() + " ml"
batteryCapacity.text = "Battery Capacity: " + carInfo.evBatteryCapacity.toString()
connectorTypes.text = "Ev Connectors: " + carInfo.evConnectorTypes.toString()

val location = AndroidUtil.getLocation(this)
locationView.text =
"Location: latitude: ${location?.latitude}, longitude: ${location?.longitude}, accuracy: ${location?.accuracy}"
}

override fun onDestroy() {
Expand Down
13 changes: 4 additions & 9 deletions automotive/src/main/java/com/volvo/polestar/utils/AndroidUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.content.Context.LOCATION_SERVICE
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.location.Location
import android.location.LocationManager
import android.os.Build
import android.provider.Settings
Expand All @@ -29,7 +30,7 @@ object AndroidUtil {
}
}

fun getLocation(context: Context) {
fun getLocation(context: Context) : Location? {
val locationManager = context.getSystemService(LOCATION_SERVICE) as LocationManager
if (ActivityCompat.checkSelfPermission(
context, Manifest.permission.ACCESS_FINE_LOCATION
Expand All @@ -38,15 +39,9 @@ object AndroidUtil {
context, Manifest.permission.ACCESS_COARSE_LOCATION
) == PackageManager.PERMISSION_GRANTED
) {
Log.d(TAG, "getLocation:have permission ")
val location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
if (location != null) {
val lat: Double = location.latitude
val long: Double = location.longitude
val acc: Float = location.accuracy
Log.d(TAG, "getLocation: lat: $lat, long: $long, accuracy: $acc")
}
return locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
}
return null
}

fun getDeviceBrand() : String {
Expand Down
4 changes: 1 addition & 3 deletions automotive/src/main/java/com/volvo/polestar/utils/CarUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ object CarUtil {

pptMgr.registerCallback(iCallback, VehiclePropertyIds.GEAR_SELECTION, SENSOR_RATE_NORMAL)
pptMgr.registerCallback(
iCallback,
VehiclePropertyIds.PERF_VEHICLE_SPEED,
SENSOR_RATE_FASTEST
iCallback, VehiclePropertyIds.PERF_VEHICLE_SPEED, SENSOR_RATE_FASTEST
)
pptMgr.registerCallback(iCallback, VehiclePropertyIds.IGNITION_STATE, SENSOR_RATE_FASTEST)
}
Expand Down
8 changes: 8 additions & 0 deletions automotive/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@
app:layout_constraintTop_toBottomOf="@id/car_fuel_type"
android:textSize="28sp"/>

<TextView
android:id="@+id/car_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
app:layout_constraintTop_toBottomOf="@id/car_ev_connectors"
android:textSize="28sp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>

0 comments on commit 8f21a97

Please sign in to comment.