Handle CustomOverlayViewController from AVPlayerViewController - tvos

I am looking for customOverlayViewController, which is from tvOS 13.0 onwards. The flow is
customOverlayViewController←UITransitionView←AVHostView←UIVisualEffectView←UIVisualEffectSubview.
This UIVisualEffectSubview contains background colour, so I want to change this to clear colour. May I know how can I do this.

I tried followed way, it is working please check
if #available(tvOS 13.0, *) {
if let customVC = self.playerVC?.customOverlayViewController {
let view = customVC.view?.superview
if let view1 = view?.superview {
for view in view1.subviews {
for view2 in view.subviews {
if view2 is UIVisualEffectView {
view2.alpha = 0.0
}
}
}
}
}
}

Related

SwiftUI: Do I need to remove UIHostingController from the controller chain when I remove the controlled view from the view hierarchy?

I am trying to migrate UIKit Views in my app to SwiftUI. One of the central elements in my app is a UICollectionView. I am embedding the SwiftUI views using a UIHostingController - so far so good.
I am wondering, since my cells are reusable, what happens to the UIHostingController when the cell is recycled?
Do I need to take it out of the controller chain?
If I need to, what is the best way to do so? (storing the UIHostingController in the cell?)
Eg. a header view looks like this so far:
class HeaderViewCell: UICollectionReusableView {
var layoutAttributes:GroupHeaderViewLayoutAttributes = GroupHeaderViewLayoutAttributes()
public func attachContent(model:GroupHeaderModel, controller:UIViewController){
let view = GroupHeaderView(model: model, layoutAttributes: self.layoutAttributes)
let hostingController = UIHostingController(rootView: view)
if let contentView = hostingController.view {
controller.addChild(hostingController)
self.addSubviewAndConstrains(contentView)
}
}
override func prepareForReuse() {
self.subviews.forEach { $0.removeFromSuperview() }
layoutAttributes = GroupHeaderViewLayoutAttributes()
}
override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
if let attributes = layoutAttributes as? TileViewLayout.HeaderViewAttributes {
self.layoutAttributes.topBarHeight = attributes.topBarHeight
self.layoutAttributes.indicatorWidth = attributes.indicatorWidth
}
}
}

How to set limitation or just notice hint for function's argument

how to set argument limitation like below?
// 1.
func ChooseColor(color string:"black|white" ) {
fmt.Println(color)
}
ChooseColor("white") // console "white"
ChooseColor("yellow") // console panic
If you feel like the noob can't understand the above solution, then alternately see below
// 2.
/**
* arg: "black|white"
*
*/
func ChooseColor(color string) {
fmt.Println(color)
}
ChooseColor( ) // IDE can notice "color: black || white"
please help me (T.T)
You can create your type Color and have constants for this type. Something like this
type Color string
const (
ColorBlack Color = "black"
ColorWhite Color = "white"
)
func ChooseColor(color Color) {
fmt.Println(color)
}
The "Go" way to do this is with godoc:
// ChooseColor selects a color. Valid colors are: black, white.
func ChooseColor(color string) {
if color != "black" && color != "white" {
/* handle the error condition */
}
/* ... */
}
This will appear in most IDEs.
This is the solution to 1.. The function panics if given argument is not expected one.
func ChooseColor(color string) {
switch color {
case "white", "black":
fmt.Println(color)
default:
panic(color)
}
}
And 2. is likely answered by Bakurits. This lets the IDE to catch what type of data will be passed to that function.
type Color bool
const (
ColorBlack Color = true
ColorWhite Color = false
)
func ChooseColor(color Color) {
if color {
fmt.Println("black")
} else {
fmt.Println("white")
}
}

Android - How to trigger standalone navigation applications with multiple way points via intent?

Today I'm using Android Intent in the following format to trigger navigation from my application on standalone navigation applications:
Action : "android.intent.action.VIEW"
URI : "google.navigation:q=48.605086,2.367014/48.607231,2.356997"
Component Name of the navigation app : For example Google Maps "com.google.android.apps.maps/com.google.android.maps.MapsActivity"
For example:
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
from : https://developers.google.com/maps/documentation/urls/android-intents
I want to trigger navigation with multiple way points, Is it possible on TomTom Go Mobile, Google Maps, Waze, Here WeGo and Sygic via Intent ?
Can I trigger navigation on the application above and start driving automatically? Without user interaction ?
I tried to trigger the above intent via ADB and do some tweaking by adding "," , ";", "and". Nothing worked.
In order to open the navigation mode in the HERE WeGo app you can use the following function
private fun navigateToDestination(destination: GeoCoordinate) {
try {
val intent = Intent().apply {
action = "com.here.maps.DIRECTIONS"
addCategory(Intent.CATEGORY_DEFAULT)
data = Uri.parse("here.directions://v1.0/mylocation/${destination.latitude},${destination.longitude}")
}
intent.resolveActivity(packageManager)?.let {
startActivity(intent)
}
} catch (t: Throwable) {
Timber.e(t)
}
}
Sygic:
private fun navigateToDestination(destination: GeoCoordinate) {
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("com.sygic.aura://coordinate|${destination.longitude}|${destination.latitude}|drive"))
intent.resolveActivity(packageManager)?.let {
startActivity(intent)
}
} catch (t: Throwable) {
Timber.e(t)
}
}
Waze:
private fun navigateToDestination(destination: GeoCoordinate) {
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("waze://?ll=${destination.latitude}, ${destination.longitude}&navigate=yes"))
intent.resolveActivity(packageManager)?.let {
startActivity(intent)
}
} catch (t: Throwable) {
Timber.e(t)
}
}
You can also resolve the installed apps that can be used for navigation and let the user decide which one s/he wants to use:
private fun navigateToDestination(destination: GeoCoordinate) {
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=${destination.latitude}, ${destination.longitude}"))
val resolvedPackages = packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL)
if (resolvedPackages.isNotEmpty()) {
val packageNames = resolvedPackages.map { it.activityInfo.packageName }
val targetIntents = packageNames.map { packageManager.getLaunchIntentForPackage(it) }
val intentChooser = Intent.createChooser(Intent(), "Choose a navigation app")
intentChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetIntents.toTypedArray())
startActivity(intentChooser)
}
} catch (t: Throwable) {
Timber.e(t)
}
}

How to choose camera for qrscan

What is the best strategy to choose camera for qrcode scanning?
Currently modern devices have few back cameras.
For example huawei mate 20 have 4 camera (3 physical and 1 virtual based on physical ones)
Currently my algorithm just selecting first camera with "back" in label.
Is there any better strategy for best readability of qr code?
Here is my code:
this.qrScannerComponent.getMediaDevices().then(devices => {
// this.info = devices.map((dev, i) => `${i}. ${dev.label}`).join('\n');
const videoDevices: MediaDeviceInfo[] = [];
for (const device of devices) {
if (device.kind.toString() === 'videoinput') {
videoDevices.push(device);
}
}
if (videoDevices.length > 0) {
let choosenDev;
for (const dev of videoDevices) {
if (dev.label.includes('back')) {
choosenDev = dev;
break;
}
}
if (choosenDev) {
this.qrScannerComponent.chooseCamera.next(choosenDev);
} else {
this.qrScannerComponent.chooseCamera.next(videoDevices[0]);
}
}
});

Angular Like Counter

I wish to make a counter of like on Angular. If there is more like than disklike the square is green and vice versa (see stackblitz link).
Link:
enter link description here
My code seems fair, I debugg with consol.log and alert but without success.
If you can help me, give me advice and enlighten me it would be a great help.
Thank you in advance,
Valentin
Along with the code link, please try providing the question code in your question itself.
In your code if you would modify your result() method to this, you would get the desired output:
result() {
if (this.nbrLove > this.nbrDontLove) {
return 'green';
} else if (this.nbrLove < this.nbrDontLove) {
return 'red';
}
}
Also, there is no need of returning values from nbrL() and nbrD() methods.
As methioned out in a comment by #Ploppy if would bind a variable to the tenplate, it will be more effecient.
You can do this by calling result() in both nbrL() and nbrD() and binding the background style with a class variable:
export class AppComponent {
nbrLove = 0;
nbrDontLove = 0;
bckColor = 'white'
nbrL() {
this.nbrLove = this.nbrLove + 1;
this.result()
}
nbrD() {
this.nbrDontLove = this.nbrDontLove + 1;
this.result();
}
result() {
if (this.nbrLove > this.nbrDontLove) {
this.bckColor = 'green';
} else if (this.nbrLove < this.nbrDontLove) {
this.bckColor = 'red';
}
else {
this.bckColor = 'white';
}
}
}
<div
[ngStyle]="{'width': '20px',
'height': '20px',
'background-color': bckColor}">
https://stackblitz.com/edit/angular-catcjl?file=src%2Fapp%2Fapp.component.html