Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 12    Views: 1277

FunkyMonkey
Aspiring developer
Profile
Posts: 1177
Reg: Aug 07, 2013
blackpool
14,570
06/21/22 03:42 AM (2 years ago)

Unexpected tokens (use '' to separate expressions on the same line)

can anyone help with this error, in android studio e: C:UsersseanDesktopew uk theatresappsrcmainjavacomuktheatresuit_screensBT_screen_map.kt: (105, 68): Unexpected tokens (use ';' to separate expressions on the same line) /* * Version 2.0 * Copyright 2015, David Book, buzztouch.com * Updates made by Chris Ruddell, 12/29/2016 * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice which includes the * name(s) of the copyright holders. It must also retain this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * Neither the name of David Book, or buzztouch.com nor the names of its contributors * may be used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ package com.uktheatres.ui.bt_screens import android.Manifest import android.content.ContentValues import android.content.Intent import android.content.pm.PackageManager import android.graphics.Bitmap import android.graphics.drawable.Drawable import android.net.Uri import android.os.Build import android.os.Bundle import android.provider.MediaStore import android.view.* import androidx.core.app.ActivityCompat import androidx.core.content.res.ResourcesCompat import androidx.lifecycle.Lifecycle import com.uktheatres.uktheatres_appDelegate import com.uktheatres.R import com.uktheatres.data_models.BT_item import com.uktheatres.extensions.* import com.uktheatres.utils.* import com.google.android.gms.maps.* import com.google.android.gms.maps.GoogleMap.SnapshotReadyCallback import com.google.android.gms.maps.model.* import kotlinx.coroutines.launch import org.json.JSONArray import java.util.* class BT_screen_map : BT_fragment(), OnMapReadyCallback { // data vars.. private var mapView: GoogleMap? = null private var childItems = listOf<BT_item>() private var markers = listOf<Marker>() private var markerIndexes: MutableMap<String, Int> = mutableMapOf() private var deviceMarker: Marker? = null private var sharedBitmap: Bitmap? = null private var JSONData = "" // properties from JSON val dataURL get() = propertyValue("dataURL") val saveAsFileName get() = "${screenData.itemId}_screenData.txt" private val showUserLocation get() = propertyValue("showUserLocation", "1") == "1" private val showUserLocationButton get() = propertyValue("showUserLocationButton", "0") == "1" private val defaultMapType get() = propertyValue("defaultMapType", "default") private val showMapTypeButtons get() = propertyValue("showMapTypeButtons", "1") == "1" private val showRefreshButton get() = propertyValue("showRefreshButton", "0") == "1" val singleLocationDefaultZoom get() = propertyValue("singleLocationDefaultZoom", "15") private val allowShareScreenshot get() = propertyValue("allowShareScreenshot", "0") == "1" private val isMyLocationEnabled get() = mapView?.isMyLocationEnabled ?: false // onCreateView... override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { /* Note: fragmentName property is already setup in the parent class (BT_fragment). This allows us to add the name of this class file to the LogCat console using the BT_debugger. */ // show life-cycle event in LogCat console... if (screenData != null) BtLog(fragmentName + ":onCreateView JSON itemId: "" + screenData.itemId + "" itemType: "" + screenData.itemType + "" itemNickname: "" + screenData.itemNickname + """) // get the com.google.android.maps.v2.API_KEY from the AndroidManifest.xml file... val tmpAPIKey: String = getMetaInfo("com.google.android.maps.v2.API_KEY") ?: "" val hasAPIKeyInManifest = tmpAPIKey.isNotEmpty() && tmpAPIKey != "GOOGLE_MAPS_FOR_ANDROID_V2_API_KEY_GOES_HERE" if (!hasAPIKeyInManifest) { BtLog("$fragmentName:onCreate. Google Maps v2 API Key not found in AndroidManifest?") } else { BtLog("$fragmentName:onCreate. Found Google Maps v2 API Key: ${tmpAPIKey.take(5)}...") } val playServicesAvailable = context.playServicesAvailable()if (!playServicesAvailable) { showErrorAlert(R.string.play_services_required) } val thisScreensView: View? = if (hasAPIKeyInManifest && playServicesAvailable) inflater.inflate(R.layout.bt_screen_map, container, false) else null if (hasAPIKeyInManifest && playServicesAvailable) getMapFragment()?.getMapAsync(this) // check permission if (showUserLocation && mapView != null) { BT_permissions.checkPermission(activity, "android.permission.ACCESS_FINE_LOCATION", BT_permissions.PERMISSION_CODE_LOCATION, "We need your location so we can show you on the map") } // return the layout file or null if we don't have Google maps configured... return thisScreensView } // onCreateView... private fun getMapFragment(): SupportMapFragment? = childFragmentManager.findFragmentById(R.id.mapView) as SupportMapFragment? override fun onDestroyView() { super.onDestroyView() BtLog("$fragmentName:onDestroyView") getMapFragment()?.let { mapFragment -> // remember camera position so we can re-zoom when coming back... val mMyCam = mapView?.cameraPosition val latitude = mMyCam?.target?.latitude.toString() val longitude = mMyCam?.target?.longitude.toString() val zoom = mMyCam?.zoom.toString() BT_preferences.setPrefString(screenData.itemId + "_lastLatitude", latitude) BT_preferences.setPrefString(screenData.itemId + "_lastLongitude", longitude) BT_preferences.setPrefString(screenData.itemId + "_lastZoom", zoom) // destroy the map... if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) childFragmentManager.beginTransaction().remove(mapFragment).commit() } } // refresh screenData private fun refreshScreenData() { BtLog("$fragmentName:refreshScreenData") if (dataURL.isNotEmpty()) { launch { downloadScreenData(dataURL, saveAsFileName) if (!JSONData.isEmpty()) { parseScreenData(JSONData) } } } else { BtLog("$fragmentName:refreshScreenData NO DATA URL for this screen? Not downloading.") showMapPins() } } // show map type private fun showMapType(theMapType: String) { BtLog("$fragmentName:showMapType "$theMapType"") // standard, terrain, hybrid // standard.. if (theMapType.equals("STANDARD", ignoreCase = true)) { mapView?.mapType = GoogleMap.MAP_TYPE_NORMAL } // terrain if (theMapType.equals("TERRAIN", ignoreCase = true)) { mapView?.mapType = GoogleMap.MAP_TYPE_TERRAIN } // hybrid.. if (theMapType.equals("HYBRID", ignoreCase = true)) { mapView?.mapType = GoogleMap.MAP_TYPE_HYBRID } } // parse screenData... private fun parseScreenData(theJSONString: String) { BtLog("$fragmentName:parseScreenData") // if theJSONString is empty, look for child items in this screen's config data.. val items: JSONArray = when { theJSONString.isEmpty() -> screenData.jsonObject.getArrayOrNull("childItems") else -> theJSONString.jsonObject()?.getJSONArray("childItems") } ?: JSONArray() childItems = items.mapObj { obj -> val tmpLatitude = obj.getStringOrNull("latitude") ?: "" val tmpLongitude = obj.getStringOrNull("longitude") ?: "" // remember it only if we have location... if (tmpLatitude.length <= 4 || tmpLongitude.length <= 4) return@mapObj null BT_item().apply { itemId = obj.getStringOrNull("itemId") ?: "" itemType = obj.getStringOrNull("itemType") ?: "BT_locationItem" jsonObject = obj } }.filterNotNull() // show how many items... if (childItems.isNotEmpty()) { showToast("${childItems.size} ${getString(R.string.mapLocations)}", "short") } // show pins here after parsing data... showMapPins() } // show map pins... private fun showMapPins() { BtLog("$fragmentName:showMapPins") // show the default map type... showMapType(defaultMapType) // add the markers to the map... val staticItems = childItems.mapIndexed { index, loc -> val pinGraphicResId = loc.propertyValue("pinColor", "red").pinResource() val tmpLatitude = loc.propertyValue("latitude") val tmpLongitude = loc.propertyValue("longitude") val tmpMarkerOptions = MarkerOptions() .position(LatLng(tmpLatitude.toDouble(), tmpLongitude.toDouble())) .title(BT_strings.getJsonPropertyValue(loc.jsonObject, "title", "")) .snippet(BT_strings.getJsonPropertyValue(loc.jsonObject, "subTitle", "")) .draggable(false) .icon(BitmapDescriptorFactory.fromResource(pinGraphicResId)) // add to map and keep track of the marker.. val tmpMarker: Marker? = mapView?.addMarker(tmpMarkerOptions) markerIndexes[tmpMarker?.id.toString()] = index tmpMarker }.filterNotNull() // we must have a device location in order to show the user on the map... val tmpLatitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLatitude val tmpLongitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLongitude val userItem: List<Marker> = if (tmpLatitude.isValidLocation && tmpLongitude.isValidLocation && showUserLocation) { val tmpMarkerOptions = MarkerOptions() .position(LatLng(tmpLatitude.toDouble(), tmpLongitude.toDouble())) .title(getString(R.string.mapUserLocationTitle)) .snippet(uktheatres_appDelegate.rootApp.rootDevice.deviceModel) .draggable(false) .icon(BitmapDescriptorFactory.fromResource(R.drawable.bt_screen_map_youarehere)) // add the device's marker to the map... deviceMarker = mapView?.addMarker(tmpMarkerOptions) // remember the device's location as -1 so we know when it's tapped... markerIndexes[deviceMarker?.id.toString()] = DEVICE_LOCATION // turn off the standard user-location marker... setLocationEnabled(false) // return as a list listOf(deviceMarker) } else { setLocationEnabled(showUserLocation) // return empty lunch listOf() }.filterNotNull() markers = staticItems + userItem // setOnMarkerClickListener for location taps (prevent default callout bubble)... mapView?.setOnMarkerClickListener { marker -> // use the item id to figure out what "index" this marker is... val markerIndex = markerIndexes[marker.id.toString()] ?: return@setOnMarkerClickListener false BtLog("$fragmentName:OnMarkerClickListener Marker Index: $markerIndex") // pass index of this marker to handleMarkerClick method... handleMarkerClick(markerIndex) // return true prevents default callout bubble... true } // set the map's bounds... setMapBounds() } private fun String.pinResource(): Int = when (this.toLowerCase(Locale.US)) { "red" -> R.drawable.bt_screen_map_marker_red "green" -> R.drawable.bt_screen_map_marker_green "blue" -> R.drawable.bt_screen_map_marker_blue "purple" -> R.drawable.bt_screen_map_marker_purple else -> R.drawable.bt_screen_map_marker_red } private val String.isValidLocation get() = this.length > 4 private fun setLocationEnabled(locationEnabled: Boolean) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val context = context ?: return if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return } } if (mapView != null) mapView?.isMyLocationEnabled = locationEnabled } // setMapBoundsToPois... private fun setMapBounds() { BtLog("$fragmentName:setMapBoundsToPois") // hideProgress... hideProgress() if (childItems.isNullOrEmpty() && showUserLocation) return showDeviceLocation() // loop through each marker to figure out the bounds... val builder = LatLngBounds.Builder() markers.forEach { builder.include(it.position) } val bounds = builder.build() // if we're coming back we remembered the last pan/zoom information in onDestroy()... val lastLatitude = "${screenData.itemId}__lastLatitude".getAsStringPref() ?: "" val lastLongitude = "${screenData.itemId}_lastLongitude".getAsStringPref() ?: "" val lastZoom = "${screenData.itemId}_lastZoom".getAsStringPref() ?: "" if (lastLatitude.isNotEmpty() && lastLongitude.isNotEmpty() && lastZoom.isNotEmpty()) { // zoom to saved location... val latLng = LatLng(lastLatitude.toDouble(), lastLongitude.toDouble()) val cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, lastZoom.toFloat()) mapView?.animateCamera(cameraUpdate) } else { // padding for the edges of the map... val padding = 150 val cu = CameraUpdateFactory.newLatLngBounds(bounds, uktheatres_appDelegate.rootApp.rootDevice.deviceWidth, uktheatres_appDelegate.rootApp.rootDevice.deviceHeight, padding) // animate to bounds... mapView?.animateCamera(cu) } // enable zoom and compass... mapView?.uiSettings?.isCompassEnabled = true mapView?.uiSettings?.isZoomControlsEnabled = true } override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) BtLog("onRequestPermissionsResult($requestCode)") if (requestCode == BT_permissions.PERMISSION_CODE_LOCATION) { if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { setLocationEnabled(true) showDeviceLocation() } } } // show device's location private fun showDeviceLocation() { if (mapView == null) return BtLog("$fragmentName:showDeviceLocation") // animate to the device's location... val tmpLatitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLatitude val tmpLongitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLongitude val latLng: LatLng if (tmpLatitude.length > 4 && tmpLongitude.length > 4) { // if we have not already created the device icon.... if (deviceMarker == null) { val tmpMarkerOptions = MarkerOptions() .position(LatLng(tmpLatitude.toDouble(), tmpLongitude.toDouble())) .title(getString(R.string.mapUserLocationTitle)) .snippet(uktheatres_appDelegate.rootApp.rootDevice.deviceModel) .draggable(false) .icon(BitmapDescriptorFactory.fromResource(R.drawable.bt_screen_map_youarehere)) // add the device's marker to the map... deviceMarker = mapView?.addMarker(tmpMarkerOptions) markers = markers + listOfNotNull(deviceMarker) // remember the device's location as -1 so we know when it's tapped... markerIndexes[deviceMarker?.id.toString()] = DEVICE_LOCATION // turn off the standard user-location marker... setLocationEnabled(false) } // zoom in on lat / lon... latLng = LatLng(tmpLatitude.toDouble(), tmpLongitude.toDouble()) val cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10f) mapView?.animateCamera(cameraUpdate) } else { showToast("Your location could not be determined.", "short") } } // handleMarkerClick.. private fun handleMarkerClick(markerIndex: Int) { BtLog("$fragmentName:handleMarkerClick") when (markerIndex) { DEVICE_LOCATION -> onDeviceMarkerClicked() else -> onMarkerClicked(markerIndex) } } private val GoogleMap.latitude get() = this.myLocation?.latitude?.toString() private val GoogleMap.longitude get() = this.myLocation?.longitude?.toString() private fun onDeviceMarkerClicked() { BtLog("$fragmentName:handleMarkerClick. Device location tapped") val context = context ?: return val desc = getString(R.string.mapUserLocationDescription) val latitude = if (isMyLocationEnabled) mapView?.latitude else deviceLatitude val longitude = if (isMyLocationEnabled) mapView?.longitude else deviceLongitude val title = uktheatres_appDelegate.rootApp.rootDevice.deviceModel val subTitle = "$descLatitude: $latitudeLongitude: $longitude" val pinGraphic: Drawable? = ResourcesCompat.getDrawable(resources, R.drawable.bt_screen_map_marker_device, activity?.theme) BT_alertUtils.showWithStyle(context) { it.setTitle(title) it.setMessage(subTitle) it.setIcon(pinGraphic) it.setCancelable(false) it.addButton(1, getString(R.string.ok)) } } private fun onMarkerClicked(markerIndex: Int) { val tappedItem: BT_item = childItems[markerIndex] val title = tappedItem.propertyValue("title") val subTitle: String = tappedItem.propertyValue("subTitle") val loadScreenWithItemId = tappedItem.propertyValue("loadScreenWithItemId") val loadScreenWithNickname = tappedItem.propertyValue("loadScreenWithNickname") val calloutTapChoice = tappedItem.propertyValue("calloutTapChoice") val pinColor = tappedItem.propertyValue("pinColor", "red") val pinGraphic: Drawable? = ResourcesCompat.getDrawable(resources, pinColor.pinResource(), activity?.theme) BtLog("$fragmentName:handleMarkerClick. Tapped: "$title"") // are we showing the details button on this locations pup-up bubble? // if we are showing directions we are not showing details bubble... val hasScreenToLoad = loadScreenWithItemId.isNotEmpty() || loadScreenWithNickname.isNotEmpty() || tappedItem.jsonObject.has("loadScreenObject") val showDirectionsButton = showDirections(loadScreenWithItemId) || showDirections(calloutTapChoice) val showDetailsButton = hasScreenToLoad && !showDirectionsButton val context = context ?: return var buttonIndex = 1 BT_alertUtils.showWithStyle(context) { it.setTitle(title) it.setMessage(subTitle) it.setIcon(pinGraphic) it.setCancelable(false) if (showDirectionsButton) it.addButton(buttonIndex++, getString(R.string.mapDrivingDirections)) { showDirections(markerIndex) } if (showDetailsButton) it.addButton(buttonIndex++, getString(R.string.details)) { showDetailsScreen(markerIndex) } it.addButton(buttonIndex++, getString(R.string.ok)) } } private fun showDirections(loadScreenWithItemId: String) = loadScreenWithItemId.equalsIgnoreCase("showDirections") // showDetailsScreen... private fun showDetailsScreen(markerIndex: Int) = launch { BtLog("$fragmentName:showDetailsScreen") // get info for tapped location... val tappedItem = childItems.getOrNull(markerIndex) ?: return@launch val loadScreenWithItemId = tappedItem.propertyValue("loadScreenWithItemId") val loadScreenWithNickname = tappedItem.propertyValue("loadScreenWithNickname") // bail if none... if (loadScreenWithItemId.equalsIgnoreCase("none")) return@launch // itemId, nickname or object... val tapScreenLoadObject: BT_item? = when { loadScreenWithItemId.isNotEmpty() -> loadScreenByItemId(loadScreenWithItemId) loadScreenWithNickname.isNotEmpty() -> loadScreenByNickname(loadScreenWithNickname) else -> loadScreenByObject(tappedItem.jsonObject) } tapScreenLoadObject?.let { loadScreenObject(it, tapScreenLoadObject) } ?: showErrorAlert(R.string.errorNoScreenConnected) } // showDirections... private fun showDirections(markerIndex: Int) { // get info for tapped location... val tappedItem = childItems[markerIndex] val locationLatitude = tappedItem.propertyValue("latitude") val locationLongitude = tappedItem.propertyValue("longitude") // we must have a device location... var tmpLatitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLatitude var tmpLongitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLongitude // if we don't have a device location saved, see if we have the map's "user location" available... if (tmpLatitude.length < 3) { if (mapView?.isMyLocationEnabled == true) { val deviceLoc = mapView?.myLocation tmpLatitude = deviceLoc?.latitude.toString() tmpLongitude = deviceLoc?.latitude.toString() } } // if we found the device's location... if (tmpLatitude.length > 3) { try { // currentDevice.location > Obj_MapLocation.location val uri = Uri.parse("https://maps.google.com/maps?saddr=$tmpLatitude,$tmpLongitude&daddr=$locationLatitude,$locationLongitude") val intent = Intent(Intent.ACTION_VIEW, uri) startActivity(intent) } catch (e: Exception) { BtLog("$fragmentName:showDirections EXCEPTION $e") showAlert(getString(R.string.noNativeAppTitle), getString(R.string.noNativeAppDescription)) } } else { BtLog("$fragmentName:showDirections cannot determine device location") showAlert(getString(R.string.mapLocationErrorTitle), getString(R.string.mapLocationErrorDescription)) } } override fun onMapReady(googleMap: GoogleMap) { BT_debugger.logInfo(activity, "onMapReady()") mapView = googleMap // must have map object... if (mapView != null) { if (saveAsFileName.length > 1) { // showProgress... showProgress(null, null) // check cache... var parseData = "" if (BT_fileManager.doesCachedFileExist(saveAsFileName)) { BtLog("$fragmentName:onCreateView using cached screen data") parseData = BT_fileManager.readTextFileFromCache(saveAsFileName) parseScreenData(parseData) } else { // get data from URL if we have one... if (dataURL.length > 1) { BtLog("$fragmentName:onCreateView downloading screen data from URL") refreshScreenData() } else { // parse with "empty" data... BtLog("$fragmentName:onCreateView using data from app's configuration file") parseScreenData("") } } } // saveAsFileName if (showUserLocation) { BT_permissions.checkPermission(activity, "android.permission.ACCESS_FINE_LOCATION", BT_permissions.PERMISSION_CODE_LOCATION, "We need your location so we can show you on the map") // ((BT_activity_host)getActivity()).checkPermission("android.permission.ACCESS_COARSE_LOCATION", BT_activity_host.PERMISSION_CODE_LOCATION, "We need your location so we can show you on the map"); } } // mapView == null... } // captureScreen... private fun shareScreenshot() { BtLog("$fragmentName:shareScreenshot") val callback = SnapshotReadyCallback { snapshot -> sharedBitmap = snapshot val filePath = System.currentTimeMillis().toString() + ".jpeg" sharedBitmap?.writeToFile(FileKt.cacheFile(filePath)) // show the share options... openShareImageDialog(filePath) } mapView?.snapshot(callback) } private fun openShareImageDialog(filePath: String) { BtLog("$fragmentName:openShareImageDialog") val file = activity?.getFileStreamPath(filePath) if (filePath != "") { val values = ContentValues(2) values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg") values.put(MediaStore.Images.Media.DATA, file?.absolutePath) val contentUriFile = activity?.contentResolver?.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values) val intent = Intent(Intent.ACTION_SEND) intent.type = "image/jpeg" intent.putExtra(Intent.EXTRA_STREAM, contentUriFile) startActivity(Intent.createChooser(intent, "Share Image")) } else { showAlert("Cannot Share", "There was a problem sharing the map image") } } // end captureScreen... // ///////////////////////////////////////////////////////////////// // onCreateOptionsMenu... override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { BtLog("$fragmentName:onCreateOptionsMenu JSON itemId: "$screenItemId"") val context = context ?: return if (showRefreshButton) { menu.addIfRoom(context, MENU_ITEM_REFRESH, R.string.refreshScreenData, R.drawable.bt_refresh) } if (showUserLocationButton) { menu.addIfRoom(context, MENU_ITEM_SHOW_LOCATION, R.string.mapShowUsersLocation, R.drawable.bt_screen_map_marker) } if (allowShareScreenshot) menu.addIfRoom(context, MENU_ITEM_SHARE_SCREENSHOT, R.string.mapShare, R.drawable.bt_share) if (showMapTypeButtons) { menu.addNever(context, MENU_ITEM_STANDARD_MAP, R.string.mapShowMapTypeStandard) menu.addNever(context, MENU_ITEM_TERRAIN, R.string.mapShowMapTypeTerrain) menu.addNever(context, MENU_ITEM_HYBRID, R.string.mapShowMapTypeHybrid) } // call super... super.onCreateOptionsMenu(menu, inflater) } override fun onOptionsItemSelected(item: MenuItem): Boolean { BtLog(fragmentName + ":onOptionsItemSelected JSON itemId: "" + screenItemId + "" Selected Item's Id: " + item.itemId) return when (item.itemId) { MENU_ITEM_REFRESH -> { refreshScreenData(); true } MENU_ITEM_SHOW_LOCATION -> { showDeviceLocation(); true } MENU_ITEM_SHARE_SCREENSHOT -> { shareScreenshot(); true } MENU_ITEM_STANDARD_MAP -> { showMapType("standard"); true } MENU_ITEM_TERRAIN -> { showMapType("terrain"); true } MENU_ITEM_HYBRID -> { showMapType("hybrid"); true } else -> super.onOptionsItemSelected(item) } } companion object { private const val DEVICE_LOCATION = -1 private const val MENU_ITEM_REFRESH = 1 private const val MENU_ITEM_SHOW_LOCATION = 2 private const val MENU_ITEM_SHARE_SCREENSHOT = 3 private const val MENU_ITEM_STANDARD_MAP = 4 private const val MENU_ITEM_TERRAIN = 5 private const val MENU_ITEM_HYBRID = 6 } }
 
Cakebit
Code is Art
Profile
Posts: 501
Reg: Dec 15, 2010
In your local b...
16,510
like
06/21/22 09:14 PM (2 years ago)
Hi FunkyMonkey! I think the compiler is just yelling about a missing a line-break between these statements: val playServicesAvailable = context.playServicesAvailable()if (!playServicesAvailable) { showErrorAlert(R.string.play_services_required) } Should actually be: val playServicesAvailable = context.playServicesAvailable() if (!playServicesAvailable) { showErrorAlert(R.string.play_services_required) }
 
FunkyMonkey
Aspiring developer
Profile
Posts: 1177
Reg: Aug 07, 2013
blackpool
14,570
like
06/22/22 08:59 AM (2 years ago)
cheers Cake, now i get this Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
 
FunkyMonkey
Aspiring developer
Profile
Posts: 1177
Reg: Aug 07, 2013
blackpool
14,570
like
06/22/22 09:09 AM (2 years ago)
These where all in red in logcat, loads more as well, 2022-06-22 17:05:03.571 971-1870/? E/AudioService.PlaybackActivityMonitor: cannot find player(piid=40079, event=4, deviceId=0, uid=10061) 2022-06-22 17:05:03.571 971-1870/? E/AudioService.PlaybackActivityMonitor: cannot find player(piid=40079, event=4, deviceId=0, uid=10061) 2022-06-22 17:05:03.585 516-528/? E/engmode_world: Unknown token(00/00/00) 2022-06-22 17:05:03.585 475-475/? E/engmode_hidl_service: error to server(0xd0060012) 2022-06-22 17:05:03.610 552-552/? E/[email protected]: Could not open /sys/class/power_supply/battery/lrp 2022-06-22 17:05:03.623 1393-23922/? E/PowerUI.Notification: no saved value, so we do nothing !!
 
FunkyMonkey
Aspiring developer
Profile
Posts: 1177
Reg: Aug 07, 2013
blackpool
14,570
like
06/22/22 09:24 AM (2 years ago)
something here i think val latitude = mMyCam?.target?.latitude.toString() val longitude = mMyCam?.target?.longitude.toString() val zoom = mMyCam?.zoom.toString() BT_preferences.setPrefString(screenData.itemId + "_lastLatitude", latitude) BT_preferences.setPrefString((screenData?.itemId ?: ) + "_lastLongitude", longitude) BT_preferences.setPrefString((screenData?.itemId ?: ) + "_lastZoom", zoom) // destroy the map... if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) childFragmentManager.beginTransaction().remove(mapFragment).commit() } } // refresh screenData private fun refreshScreenData() { BtLog("$fragmentName:refreshScreenData")
 
FunkyMonkey
Aspiring developer
Profile
Posts: 1177
Reg: Aug 07, 2013
blackpool
14,570
like
06/22/22 09:24 AM (2 years ago)
e: C:\Users\sean\Desktop\files\new uk theatres\app\src\main\java\com\uktheatres\ui\bt_screens\BT_screen_map.kt: (138, 64): Expecting an element
 
FunkyMonkey
Aspiring developer
Profile
Posts: 1177
Reg: Aug 07, 2013
blackpool
14,570
like
06/23/22 03:07 AM (2 years ago)
BT_preferences.setPrefString((screenData?.itemId ?:) + "_lastLongitude", longitude) BT_preferences.setPrefString((screenData?.itemId ?: ) + "_lastZoom", zoom) itemId ?:) + itemId ?: ) + lost last 2 bits e: C:\Users\sean\Desktop\files\new uk theatres\app\src\main\java\com\uktheatres\ui\bt_screens\BT_screen_map.kt: (138, 64): Expecting an element e: C:\Users\sean\Desktop\files\new uk theatres\app\src\main\java\com\uktheatres\ui\bt_screens\BT_screen_map.kt: (139, 64): Expecting an element
 
FunkyMonkey
Aspiring developer
Profile
Posts: 1177
Reg: Aug 07, 2013
blackpool
14,570
like
06/23/22 03:11 AM (2 years ago)
its all in the bt screen map /* * Version 2.0 * Copyright 2015, David Book, buzztouch.com * Updates made by Chris Ruddell, 12/29/2016 * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice which includes the * name(s) of the copyright holders. It must also retain this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * Neither the name of David Book, or buzztouch.com nor the names of its contributors * may be used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ package com.uktheatres.ui.bt_screens import android.Manifest import android.content.ContentValues import android.content.Intent import android.content.pm.PackageManager import android.graphics.Bitmap import android.graphics.drawable.Drawable import android.net.Uri import android.os.Build import android.os.Bundle import android.os.Parcel import android.os.Parcelable import android.provider.MediaStore import android.view.* import androidx.core.app.ActivityCompat import androidx.core.content.res.ResourcesCompat import androidx.lifecycle.Lifecycle import com.uktheatres.uktheatres_appDelegate import com.uktheatres.R import com.uktheatres.data_models.BT_item import com.uktheatres.extensions.* import com.uktheatres.utils.* import com.google.android.gms.maps.* import com.google.android.gms.maps.GoogleMap.SnapshotReadyCallback import com.google.android.gms.maps.model.* import kotlinx.coroutines.launch import org.json.JSONArray import java.util.* class BT_screen_map() : BT_fragment(), OnMapReadyCallback, Parcelable { /* data vars.. */ private var mapView: GoogleMap? = null private var childItems = listOf<BT_item>() private var markers = listOf<Marker>() private var markerIndexes: MutableMap<String, Int> = mutableMapOf() private var deviceMarker: Marker? = null private var sharedBitmap: Bitmap? = null private var JSONData = "" // properties from JSON val dataURL get() = propertyValue("dataURL") val saveAsFileName get() = "${screenData.itemId}_screenData.txt" private val showUserLocation get() = propertyValue("showUserLocation", "1") == "1" private val showUserLocationButton get() = propertyValue("showUserLocationButton", "0") == "1" private val defaultMapType get() = propertyValue("defaultMapType", "default") private val showMapTypeButtons get() = propertyValue("showMapTypeButtons", "1") == "1" private val showRefreshButton get() = propertyValue("showRefreshButton", "0") == "1" val singleLocationDefaultZoom get() = propertyValue("singleLocationDefaultZoom", "15") private val allowShareScreenshot get() = propertyValue("allowShareScreenshot", "0") == "1" private val isMyLocationEnabled get() = mapView?.isMyLocationEnabled ?: false // onCreateView... override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { /* Note: fragmentName property is already setup in the parent class (BT_fragment). This allows us to add the name of this class file to the LogCat console using the BT_debugger. */ // show life-cycle event in LogCat console... if (screenData != null) BtLog(fragmentName + ":onCreateView JSON itemId: \"" + screenData.itemId + "\" itemType: \"" + screenData.itemType + "\" itemNickname: \"" + screenData.itemNickname + "\"") // get the com.google.android.maps.v2.API_KEY from the AndroidManifest.xml file... val tmpAPIKey: String = getMetaInfo("com.google.android.maps.v2.API_KEY") ?: "" val hasAPIKeyInManifest = tmpAPIKey.isNotEmpty() && tmpAPIKey != "GOOGLE_MAPS_FOR_ANDROID_V2_API_KEY_GOES_HERE" if (!hasAPIKeyInManifest) { BtLog("$fragmentName:onCreate. Google Maps v2 API Key not found in AndroidManifest?") } else { BtLog("$fragmentName:onCreate. Found Google Maps v2 API Key: ${tmpAPIKey.take(5)}...") } val playServicesAvailable = context.playServicesAvailable() if (playServicesAvailable) { } else { showErrorAlert(R.string.play_services_required) } val thisScreensView: View? = if (hasAPIKeyInManifest && playServicesAvailable) inflater.inflate(R.layout.bt_screen_map, container, false) else null if (hasAPIKeyInManifest && playServicesAvailable) getMapFragment()?.getMapAsync(this) // check permission if (showUserLocation && mapView != null) { BT_permissions.checkPermission(activity, "android.permission.ACCESS_FINE_LOCATION", BT_permissions.PERMISSION_CODE_LOCATION, "We need your location so we can show you on the map") } // return the layout file or null if we don't have Google maps configured... return thisScreensView } // onCreateView... private fun getMapFragment(): SupportMapFragment? = childFragmentManager.findFragmentById(R.id.mapView) as SupportMapFragment? override fun onDestroyView() { super.onDestroyView() BtLog("$fragmentName:onDestroyView") getMapFragment()?.let { mapFragment -> // remember camera position so we can re-zoom when coming back... val mMyCam = mapView?.cameraPosition val latitude = mMyCam?.target?.latitude.toString() val longitude = mMyCam?.target?.longitude.toString() val zoom = mMyCam?.zoom.toString() BT_preferences.setPrefString(screenData.itemId + "_lastLatitude", latitude) BT_preferences.setPrefString((screenData?.itemId ?:) + "_lastLongitude", longitude) com.uktheatres.utils.BT_preferences.setPrefString((screenData?.itemId ?: ) + "_lastZoom", zoom) // destroy the map... if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) childFragmentManager.beginTransaction().remove(mapFragment).commit() } } // refresh screenData private fun refreshScreenData() { BtLog("$fragmentName:refreshScreenData") if (dataURL.isNotEmpty()) { launch { var downloadScreenData: Comparable<String> = downloadScreenData(dataURL, saveAsFileName) if (!JSONData.isEmpty()) { parseScreenData(JSONData) } } } else { BtLog("$fragmentName:refreshScreenData NO DATA URL for this screen? Not downloading.") showMapPins() } } // show map type private fun showMapType(theMapType: String) { BtLog("$fragmentName:showMapType \"$theMapType\"") // standard, terrain, hybrid // standard.. if (theMapType.equals("STANDARD", ignoreCase = true)) { mapView?.mapType = GoogleMap.MAP_TYPE_NORMAL } // terrain if (theMapType.equals("TERRAIN", ignoreCase = true)) { mapView?.mapType = GoogleMap.MAP_TYPE_TERRAIN } // hybrid.. if (theMapType.equals("HYBRID", ignoreCase = true)) { mapView?.mapType = GoogleMap.MAP_TYPE_HYBRID } } // parse screenData... private fun parseScreenData(theJSONString: String) { BtLog("$fragmentName:parseScreenData") // if theJSONString is empty, look for child items in this screen's config data.. val items: JSONArray = when { theJSONString.isEmpty() -> screenData?.jsonObject.getArrayOrNull("childItems") else -> theJSONString.jsonObject()?.getJSONArray("childItems") } ?: JSONArray() childItems = items.mapObj { obj -> val tmpLatitude = obj.getStringOrNull("latitude") ?: "" val tmpLongitude = obj.getStringOrNull("longitude") ?: "" // remember it only if we have location... if (tmpLatitude.length <= 4 || tmpLongitude.length <= 4) return@mapObj null BT_item().apply { itemId = obj.getStringOrNull("itemId") ?: "" itemType = obj.getStringOrNull("itemType") ?: "BT_locationItem" jsonObject = obj } }.filterNotNull() // show how many items... if (childItems.isNotEmpty()) { showToast("${childItems.size} ${getString(R.string.mapLocations)}", "short") } // show pins here after parsing data... showMapPins() } // show map pins... private fun showMapPins() { BtLog("$fragmentName:showMapPins") // show the default map type... showMapType(defaultMapType) // add the markers to the map... val staticItems = childItems.mapIndexed { index, loc -> val pinGraphicResId = loc.propertyValue("pinColor", "red").pinResource() val tmpLatitude = loc.propertyValue("latitude") val tmpLongitude = loc.propertyValue("longitude") val tmpMarkerOptions = MarkerOptions() .position(LatLng(tmpLatitude.toDouble(), tmpLongitude.toDouble())) .title(BT_strings.getJsonPropertyValue(loc.jsonObject, "title", "")) .snippet(BT_strings.getJsonPropertyValue(loc.jsonObject, "subTitle", "")) .draggable(false) .icon(BitmapDescriptorFactory.fromResource(pinGraphicResId)) // add to map and keep track of the marker.. val tmpMarker: Marker? = mapView?.addMarker(tmpMarkerOptions) markerIndexes[tmpMarker?.id.toString()] = index tmpMarker }.filterNotNull() // we must have a device location in order to show the user on the map... val tmpLatitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLatitude val tmpLongitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLongitude val userItem: List<Marker> = if (tmpLatitude.isValidLocation && tmpLongitude.isValidLocation && showUserLocation) { val tmpMarkerOptions = MarkerOptions() .position(LatLng(tmpLatitude.toDouble(), tmpLongitude.toDouble())) .title(getString(R.string.mapUserLocationTitle)) .snippet(uktheatres_appDelegate.rootApp.rootDevice.deviceModel) .draggable(false) .icon(BitmapDescriptorFactory.fromResource(R.drawable.bt_screen_map_youarehere)) // add the device's marker to the map... deviceMarker = mapView?.addMarker(tmpMarkerOptions) // remember the device's location as -1 so we know when it's tapped... markerIndexes[deviceMarker?.id.toString()] = DEVICE_LOCATION // turn off the standard user-location marker... setLocationEnabled(false) // return as a list listOf(deviceMarker) } else { setLocationEnabled(showUserLocation) // return empty lunch listOf() }.filterNotNull() markers = staticItems + userItem // setOnMarkerClickListener for location taps (prevent default callout bubble)... mapView?.setOnMarkerClickListener { marker -> // use the item id to figure out what "index" this marker is... val markerIndex = markerIndexes[marker.id.toString()] ?: return@setOnMarkerClickListener false BtLog("$fragmentName:OnMarkerClickListener Marker Index: $markerIndex") // pass index of this marker to handleMarkerClick method... handleMarkerClick(markerIndex) // return true prevents default callout bubble... true } // set the map's bounds... setMapBounds() } private fun String.pinResource(): Int = when (this.toLowerCase(Locale.US)) { "red" -> R.drawable.bt_screen_map_marker_red "green" -> R.drawable.bt_screen_map_marker_green "blue" -> R.drawable.bt_screen_map_marker_blue "purple" -> R.drawable.bt_screen_map_marker_purple else -> R.drawable.bt_screen_map_marker_red } private val String.isValidLocation get() = this.length > 4 private fun setLocationEnabled(locationEnabled: Boolean) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val context = context ?: return if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return } } if (mapView != null) mapView?.isMyLocationEnabled = locationEnabled } // setMapBoundsToPois... private fun setMapBounds() { BtLog("$fragmentName:setMapBoundsToPois") // hideProgress... hideProgress() if (childItems.isNullOrEmpty() && showUserLocation) return showDeviceLocation() // loop through each marker to figure out the bounds... val builder = LatLngBounds.Builder() markers.forEach { builder.include(it.position) } val bounds = builder.build() // if we're coming back we remembered the last pan/zoom information in onDestroy()... val lastLatitude = "${screenData.itemId}__lastLatitude".getAsStringPref() ?: "" val lastLongitude = "${screenData?.itemId}_lastLongitude".getAsStringPref() ?: "" val lastZoom = "${screenData.itemId}_lastZoom".getAsStringPref() ?: "" if (lastLatitude.isNotEmpty() && lastLongitude.isNotEmpty() && lastZoom.isNotEmpty()) { // zoom to saved location... val latLng = LatLng(lastLatitude.toDouble(), lastLongitude.toDouble()) val cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, lastZoom.toFloat()) mapView?.animateCamera(cameraUpdate) } else { // padding for the edges of the map... val padding = 150 val cu = CameraUpdateFactory.newLatLngBounds(bounds, uktheatres_appDelegate.rootApp.rootDevice.deviceWidth, uktheatres_appDelegate.rootApp.rootDevice.deviceHeight, padding) // animate to bounds... mapView?.animateCamera(cu) } // enable zoom and compass... mapView?.uiSettings?.isCompassEnabled = true mapView?.uiSettings?.isZoomControlsEnabled = true } override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) BtLog("onRequestPermissionsResult($requestCode)") if (requestCode == BT_permissions.PERMISSION_CODE_LOCATION) { if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { setLocationEnabled(true) showDeviceLocation() } } } // show device's location private fun showDeviceLocation() { if (mapView == null) return BtLog("$fragmentName:showDeviceLocation") // animate to the device's location... val tmpLatitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLatitude val tmpLongitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLongitude val latLng: LatLng if (tmpLatitude.length > 4 && tmpLongitude.length > 4) { // if we have not already created the device icon.... if (deviceMarker == null) { val tmpMarkerOptions = MarkerOptions() .position(LatLng(tmpLatitude.toDouble(), tmpLongitude.toDouble())) .title(getString(R.string.mapUserLocationTitle)) .snippet(uktheatres_appDelegate.rootApp.rootDevice.deviceModel) .draggable(false) .icon(BitmapDescriptorFactory.fromResource(R.drawable.bt_screen_map_youarehere)) // add the device's marker to the map... deviceMarker = mapView?.addMarker(tmpMarkerOptions) markers = markers + listOfNotNull(deviceMarker) // remember the device's location as -1 so we know when it's tapped... markerIndexes[deviceMarker?.id.toString()] = DEVICE_LOCATION // turn off the standard user-location marker... setLocationEnabled(false) } // zoom in on lat / lon... latLng = LatLng(tmpLatitude.toDouble(), tmpLongitude.toDouble()) val cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10f) mapView?.animateCamera(cameraUpdate) } else { showToast("Your location could not be determined.", "short") } } // handleMarkerClick.. private fun handleMarkerClick(markerIndex: Int) { BtLog("$fragmentName:handleMarkerClick") when (markerIndex) { DEVICE_LOCATION -> onDeviceMarkerClicked() else -> onMarkerClicked(markerIndex) } } private val GoogleMap.latitude get() = this.myLocation?.latitude?.toString() private val GoogleMap.longitude get() = this.myLocation?.longitude?.toString() constructor(parcel: Parcel) : this() { sharedBitmap = parcel.readParcelable(Bitmap::class.java.classLoader) JSONData = parcel.readString() } private fun onDeviceMarkerClicked() { BtLog("$fragmentName:handleMarkerClick. Device location tapped") val context = context ?: return val desc = getString(R.string.mapUserLocationDescription) val latitude = if (isMyLocationEnabled) mapView?.latitude else deviceLatitude val longitude = if (isMyLocationEnabled) mapView?.longitude else deviceLongitude val title = uktheatres_appDelegate.rootApp.rootDevice.deviceModel val subTitle = "$desc\nLatitude: $latitude\nLongitude: $longitude" val pinGraphic: Drawable? = ResourcesCompat.getDrawable(resources, R.drawable.bt_screen_map_marker_device, activity?.theme) BT_alertUtils.showWithStyle(context) { it.setTitle(title) it.setMessage(subTitle) it.setIcon(pinGraphic) it.setCancelable(false) it.addButton(1, getString(R.string.ok)) } } private fun onMarkerClicked(markerIndex: Int) { val tappedItem: BT_item = childItems[markerIndex] val title = tappedItem.propertyValue("title") val subTitle: String = tappedItem.propertyValue("subTitle") val loadScreenWithItemId = tappedItem.propertyValue("loadScreenWithItemId") val loadScreenWithNickname = tappedItem.propertyValue("loadScreenWithNickname") val calloutTapChoice = tappedItem.propertyValue("calloutTapChoice") val pinColor = tappedItem.propertyValue("pinColor", "red") val pinGraphic: Drawable? = ResourcesCompat.getDrawable(resources, pinColor.pinResource(), activity?.theme) BtLog("$fragmentName:handleMarkerClick. Tapped: \"$title\"") // are we showing the details button on this locations pup-up bubble? // if we are showing directions we are not showing details bubble... val hasScreenToLoad = loadScreenWithItemId.isNotEmpty() || loadScreenWithNickname.isNotEmpty() || tappedItem.jsonObject.has("loadScreenObject") val showDirectionsButton = showDirections(loadScreenWithItemId) || showDirections(calloutTapChoice) val showDetailsButton = hasScreenToLoad && !showDirectionsButton val context = context ?: return var buttonIndex = 1 BT_alertUtils.showWithStyle(context) { it.setTitle(title) it.setMessage(subTitle) it.setIcon(pinGraphic) it.setCancelable(false) if (showDirectionsButton) it.addButton(buttonIndex++, getString(R.string.mapDrivingDirections)) { showDirections(markerIndex) } if (showDetailsButton) it.addButton(buttonIndex++, getString(R.string.details)) { showDetailsScreen(markerIndex) } it.addButton(buttonIndex++, getString(R.string.ok)) } } private fun showDirections(loadScreenWithItemId: String) = loadScreenWithItemId.equalsIgnoreCase("showDirections") // showDetailsScreen... private fun showDetailsScreen(markerIndex: Int) = launch { BtLog("$fragmentName:showDetailsScreen") // get info for tapped location... val tappedItem = childItems.getOrNull(markerIndex) ?: return@launch val loadScreenWithItemId = tappedItem.propertyValue("loadScreenWithItemId") val loadScreenWithNickname = tappedItem.propertyValue("loadScreenWithNickname") // bail if none... if (loadScreenWithItemId.equalsIgnoreCase("none")) return@launch // itemId, nickname or object... val tapScreenLoadObject: BT_item? = when { loadScreenWithItemId.isNotEmpty() -> loadScreenByItemId(loadScreenWithItemId) loadScreenWithNickname.isNotEmpty() -> loadScreenByNickname(loadScreenWithNickname) else -> loadScreenByObject(tappedItem.jsonObject) } tapScreenLoadObject?.let { loadScreenObject(it, tapScreenLoadObject) } ?: showErrorAlert(R.string.errorNoScreenConnected) } // showDirections... private fun showDirections(markerIndex: Int) { // get info for tapped location... val tappedItem = childItems[markerIndex] val locationLatitude = tappedItem.propertyValue("latitude") val locationLongitude = tappedItem.propertyValue("longitude") // we must have a device location... var tmpLatitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLatitude var tmpLongitude = uktheatres_appDelegate.rootApp.rootDevice.deviceLongitude // if we don't have a device location saved, see if we have the map's "user location" available... if (tmpLatitude.length < 3) { if (mapView?.isMyLocationEnabled == true) { val deviceLoc = mapView?.myLocation tmpLatitude = deviceLoc?.latitude.toString() tmpLongitude = deviceLoc?.latitude.toString() } } // if we found the device's location... if (tmpLatitude.length > 3) { try { // currentDevice.location > Obj_MapLocation.location val uri = Uri.parse("https://maps.google.com/maps?saddr=$tmpLatitude,$tmpLongitude&daddr=$locationLatitude,$locationLongitude") val intent = Intent(Intent.ACTION_VIEW, uri) startActivity(intent) } catch (e: Exception) { BtLog("$fragmentName:showDirections EXCEPTION $e") showAlert(getString(R.string.noNativeAppTitle), getString(R.string.noNativeAppDescription)) } } else { BtLog("$fragmentName:showDirections cannot determine device location") showAlert(getString(R.string.mapLocationErrorTitle), getString(R.string.mapLocationErrorDescription)) } } override fun onMapReady(googleMap: GoogleMap) { BT_debugger.logInfo(activity, "onMapReady()") mapView = googleMap // must have map object... if (mapView != null) { if (saveAsFileName.length > 1) { // showProgress... showProgress(null, null) // check cache... var parseData = "" if (BT_fileManager.doesCachedFileExist(saveAsFileName)) { BtLog("$fragmentName:onCreateView using cached screen data") parseData = BT_fileManager.readTextFileFromCache(saveAsFileName) parseScreenData(parseData) } else { // get data from URL if we have one... if (dataURL.length > 1) { BtLog("$fragmentName:onCreateView downloading screen data from URL") refreshScreenData() } else { // parse with "empty" data... BtLog("$fragmentName:onCreateView using data from app's configuration file") parseScreenData("") } } } // saveAsFileName if (showUserLocation) { BT_permissions.checkPermission(activity, "android.permission.ACCESS_FINE_LOCATION", BT_permissions.PERMISSION_CODE_LOCATION, "We need your location so we can show you on the map") // ((BT_activity_host)getActivity()).checkPermission("android.permission.ACCESS_COARSE_LOCATION", BT_activity_host.PERMISSION_CODE_LOCATION, "We need your location so we can show you on the map"); } } // mapView == null... } // captureScreen... private fun shareScreenshot() { BtLog("$fragmentName:shareScreenshot") val callback = SnapshotReadyCallback { snapshot -> sharedBitmap = snapshot val filePath = System.currentTimeMillis().toString() + ".jpeg" sharedBitmap?.writeToFile(FileKt.cacheFile(filePath)) // show the share options... openShareImageDialog(filePath) } mapView?.snapshot(callback) } private fun openShareImageDialog(filePath: String) { BtLog("$fragmentName:openShareImageDialog") val file = activity?.getFileStreamPath(filePath) if (filePath != "") { val values = ContentValues(2) values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg") values.put(MediaStore.Images.Media.DATA, file?.absolutePath) val contentUriFile = activity?.contentResolver?.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values) val intent = Intent(Intent.ACTION_SEND) intent.type = "image/jpeg" intent.putExtra(Intent.EXTRA_STREAM, contentUriFile) startActivity(Intent.createChooser(intent, "Share Image")) } else { showAlert("Cannot Share", "There was a problem sharing the map image") } } // end captureScreen... // ///////////////////////////////////////////////////////////////// // onCreateOptionsMenu... override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { BtLog("$fragmentName:onCreateOptionsMenu JSON itemId: \"$screenItemId\"") val context = context ?: return if (showRefreshButton) { menu.addIfRoom(context, MENU_ITEM_REFRESH, R.string.refreshScreenData, R.drawable.bt_refresh) } if (showUserLocationButton) { menu.addIfRoom(context, MENU_ITEM_SHOW_LOCATION, R.string.mapShowUsersLocation, R.drawable.bt_screen_map_marker) } if (allowShareScreenshot) menu.addIfRoom(context, MENU_ITEM_SHARE_SCREENSHOT, R.string.mapShare, com.uktheatres.R.drawable.bt_share) if (showMapTypeButtons) { menu.addNever(context, MENU_ITEM_STANDARD_MAP, R.string.mapShowMapTypeStandard) menu.addNever(context, MENU_ITEM_TERRAIN, R.string.mapShowMapTypeTerrain) menu.addNever(context, MENU_ITEM_HYBRID, R.string.mapShowMapTypeHybrid) } // call super... super.onCreateOptionsMenu(menu, inflater) } override fun onOptionsItemSelected(item: MenuItem): Boolean { BtLog(fragmentName + ":onOptionsItemSelected JSON itemId: \"" + screenItemId + "\" Selected Item's Id: " + item.itemId) return when (item.itemId) { MENU_ITEM_REFRESH -> { refreshScreenData(); true } MENU_ITEM_SHOW_LOCATION -> { showDeviceLocation(); true } MENU_ITEM_SHARE_SCREENSHOT -> { shareScreenshot(); true } MENU_ITEM_STANDARD_MAP -> { showMapType("standard"); true } MENU_ITEM_TERRAIN -> { showMapType("terrain"); true } MENU_ITEM_HYBRID -> { showMapType("hybrid"); true } else -> super.onOptionsItemSelected(item) } } companion object { private const val DEVICE_LOCATION = -1 private const val MENU_ITEM_REFRESH = 1 private const val MENU_ITEM_SHOW_LOCATION = 2 private const val MENU_ITEM_SHARE_SCREENSHOT = 3 private const val MENU_ITEM_STANDARD_MAP = 4 private const val MENU_ITEM_TERRAIN = 5 private const val MENU_ITEM_HYBRID = 6 } override fun writeToParcel(parcel: Parcel, flags: Int) { parcel.writeParcelable(sharedBitmap, flags) parcel.writeString(JSONData) } override fun describeContents(): Int { return 0 } companion object CREATOR : Parcelable.Creator<BT_screen_map> { override fun createFromParcel(parcel: Parcel): BT_screen_map { return BT_screen_map(parcel) } override fun newArray(size: Int): Array<BT_screen_map?> { return arrayOfNulls(size) } } }
 
Cakebit
Code is Art
Profile
Posts: 501
Reg: Dec 15, 2010
In your local b...
16,510
like
06/24/22 11:14 PM (2 years ago)
Hi FunkyMonkey! You can maybe try something like this: BT_preferences.setPrefString(screenData.itemId + "_lastLongitude", longitude) BT_preferences.setPrefString(screenData.itemId + "_lastZoom", zoom) And see if that works. The ?: operator usually needs a value to come after it– and there is none in this case, so you might be missing some part of your code?
 
FunkyMonkey
Aspiring developer
Profile
Posts: 1177
Reg: Aug 07, 2013
blackpool
14,570
like
06/25/22 05:11 AM (2 years ago)
i then get this BT_preferences.setPrefString(name of preferance screenData.itemId + "_lastLongitude", longitude) BT_preferences.setPrefString(name of preferance screenData.itemId + "_lastZoom", zoom) with name of preferance in bold but you cant press or copy it. still getting failed :app:kaptGenerateStubsDebugKotlin BT_screen_map.kt Expecting an element org.gradle.api.GradleException: Compilation error. See log for more details Ive worked out through stack overflo and its connected to the katlin plugin, when you disable the katlin plugin, you restart and have to reinstall studio, the the eroor shows cant run due to 2 plugins that youve just disabled cos the error is connected to them lol, ive updated the config file with buzztouch, and checked the json and its all ok, so it seams to be coming from this file, if you have differant version of it, that would be great, its the Bt_screen_map.kt
 
FunkyMonkey
Aspiring developer
Profile
Posts: 1177
Reg: Aug 07, 2013
blackpool
14,570
like
06/25/22 05:14 AM (2 years ago)
you know it is a katlin code you, other people who actually know code, are having probs for the katlin plugin, dont know if you know a solution or not, thanks for helping me with this , Cake :)
 
FunkyMonkey
Aspiring developer
Profile
Posts: 1177
Reg: Aug 07, 2013
blackpool
14,570
like
06/25/22 06:50 AM (2 years ago)
thats where the app run stops, it only shows error on building not compile, think, remember i code with a hammer, dont judge me lol its the kotlin plugin and you cant turn it off, red error :app:kaptGenerateStubsDebugKotlin
 
LA
Aspiring developer
Profile
Posts: 3278
Reg: Aug 16, 2012
Jerseyville, IL
42,880
like
01/07/23 03:46 AM (1 year ago)
That's a lot of code monkey lol
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.