Android Picture in Picture Potrait Mode - android

I am trying to implement Picture in Picture mode but so far as per the example given the only orientation I see is landscape mode.
https://developer.android.com/guide/topics/ui/picture-in-picture
I am trying to have a functionally similar to the WhatsApp app. When the user accepts a call and enters picture in picture mode the window is shown in portrait mode so the user can see the other person well. Will appreciate thoughts on how I can implement this.
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean,
newConfig: Configuration) {
if (isInPictureInPictureMode) {
// Hide the full-screen UI (controls, etc.) while in picture-in-picture mode.
} else {
// Restore the full-screen UI.
}
}

You can use enterPictureInPictureMode to configure the PIP window.
To have a portrait PIP window use an aspect ratio of ~2/3. (The aspect ratio must be between 0,42 and 2,39.)
override fun onUserLeaveHint() {
enterPictureInPictureMode(PictureInPictureParams.Builder()
.setAspectRatio(Rational(2, 3))
.build())
}
Example:

Related

How to rotate screen manual as well automatic in Xamarin.forms

I have a requirement to rotate the screen to Landscape from Portrait. Then I should stay in Landscape even though I have not tilted my phone. Portrait and Landscape have different views with buttons for orientation change and is in same content page which I have handled with content template. So, now I wanted to rotate automatically if I tilt the phone or if I tap on the button in either view to change orientation.
Portrait -> Landscape change using button then I should stay in landscape view until one rotation happen.
ex:- Now, I came to Landscape using a sensor, and I am in Landscape mode if I tap the button for rotation then I should change in portrait and should stay there.
I want to satisfy both cases. How to achieve that in Android and iOS (Xamarin.Forms)?
Anyone faces this kind of usecase and if you got a solution. Help me out.
When using Xamarin.Forms, the supported method of controlling device orientation is to use the settings for each individual project.
You could call the following method in dependency service.
Create a interface:
public interface IOrientationService
{
void Landscape();
void Portrait();
}
Android:
public class OrientationService : IOrientationService
{
public void Landscape()
{
((Activity)Forms.Context).RequestedOrientation = ScreenOrientation.Landscape;
}
public void Portrait()
{
((Activity)Forms.Context).RequestedOrientation = ScreenOrientation.Portrait;
}
}
iOS:
public class OrientationService : IOrientationService
{
public void Landscape()
{
AppDelegate appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate;
appDelegate.allowRotation = true;
UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.LandscapeLeft), new NSString("orientation"));
}
public void Portrait()
{
AppDelegate appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate;
appDelegate.allowRotation = true;
UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.Portrait), new NSString("orientation"));
}
}
For the usage of dependency service, you could refer to the link below. How can I block rotation to only allow portrait mode in xamarin forms?
I want to rotate only one page in my app automatically and as well as manually.
When you do the navigation, you could do the Orientation before loading the page in OnAppearing event.
protected override void OnAppearing()
{
base.OnAppearing();
DependencyService.Get<IOrientationService>().Landscape();
}
Both portrait and landscape views are different.
Liek 1., you could set the Orientation you want to in each page with OnAppearing() event.
I should not lock the particular page at any cause but I also when I want to change orientation manually I should able to do that. Even though I am not rotating/tilt the phone.
If you want to do it manually, invoke the Landscape or Portrait in a click event or tap or something else.

Sceneform - How to make the camera view too autofocus

So, the default camera view in sceneform is in fixed focus settings. But its blur and doesn't feels good. I want to get the camera to show everything clearly (Autofocus mode).
I tried changing the session config. But it is not really working.
override fun getSessionConfiguration(session: Session?): Config {
val config = Config(session)
config.focusMode = Config.FocusMode.AUTO
return config
}

How to avoid the toast when screen is on landscape mode in Android

I need to show the user a message using toast or snackbar. However, i do not want to show this message when the user tilts his/her phone into landscape mode. How can I achieve this message showing only in portrait mode and not in landscape mode?
This method will return true if the phone is in portrait and false if the phone is in Landscape it uses configurations:
private boolean isPortrait(){
return (getResources().getConfiguration().orientation==ORIENTATION_PORTRAIT);
}
Import configuration classes in Android Studio its easy. So from here you can use a simple if statement using the method given above:
if(isPortrait()){
//Show you Toast and snackbar here
}
For more information on this check the official documentation here.
You can check orientation of the phone in resources configuration object:
getResources().getConfiguration().orientation
When it equals ORIENTATION_LANDSCAPE simply don't show the toast/snackbar
For the reference see:
https://developer.android.com/reference/android/content/res/Configuration.html#orientation

locking screen orientation on mobile browser

I create a web page(chrome & safari) for mobiles (iphone & android), I want to lock the screen orientation in portrait mode.
Unlike mobile apps,there is no manifest file and activity as it a web page.
How to lock the orientation in mobiles using technologies (css/javascript/bootstrap/jquery) or any other?
I use a manifest file for my web app, which locks orientation for Chrome on my Android. For whatever reason, Safari gives their users the "right" to do this, but not the designers of the web app... Sort of feels like copyright infringement or something! ;) Don't get me started on Safari's disgraceful rewriting/rendering of input buttons!...
Anyways, back to the answer.
1) Include a link to your manifest within the head section of your page:
<link rel="manifest" href="http://yoursite.com/manifest.json">
2) Create your manifest file, "manifest.json"
{
"name":"A nice title for your web app",
"display":"standalone",
"orientation":"portrait"
}
3) Read more about manifests HERE
From my tests, assigning the screen.lockOrientation ( every browser versions ) to a var throw an illegal invocation error. Just use wind.screen.orientation.lock('landscape'); . It
EDIT: You can't use lock orientation on safari, cause it doesn't support fullscreen api at the moment http://caniuse.com/#feat=fullscreen . The lock orientation API NEED a fullscreen page to work. In Chrome, the window.screen.orientation.lock return a promise. So, AFTER you go fullscreen with the page, you can do something like this :
var lockFunction = window.screen.orientation.lock;
if (lockFunction.call(window.screen.orientation, 'landscape')) {
console.log('Orientation locked')
} else {
console.error('There was a problem in locking the orientation')
}
However, the lock orientation and fullscreen API are still experimental, not all browsers supports it.
The lockOrientation method locks the screen into the specified orientation.
lockedAllowed = window.screen.lockOrientation(orientation);
From the following code, you can check that orientation is locked or not.
var lockOrientation = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation;
if (lockOrientation("landscape-primary")) {
// orientation was locked
} else {
// orientation lock failed
}
see the following link, you will get idea from this.
https://developer.mozilla.org/en-US/docs/Web/API/Screen.lockOrientation
You can use:
screen.addEventListener("orientationchange", function () {
console.log("The orientation of the screen is: " + screen.orientation);
});
and
screen.lockOrientation('landscape');
Following: https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Managing_screen_orientation

Android AIR screen dimmed

I have such a problem. I am writing Adobe AIR application for Android device. And I need to make device screen not to be dimmed. I'm making it with SystemIdleMode.KEEP_AWAKE this function for a minute-to five. But after that, I make it SystemIdleMode.NORMAL mode and it immediately dimmed. I want it to be dimmed in some standart time. Like after 30 seconds after that time, when I swiched off KEEP_AWAKE mode. How can I do that? Thanx.
public static function (isEnabled):void
{
if(isEnabled)
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
else
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL;
}
}
I solved this issue in such a way: I switch to SystemIdleMode.NORMAL mode only after that, when user click on the screen. It gives me aditional 30 seconds to not switch screen to dimmed immediatly.

Categories

Resources