Allow screen rotation on tablets, but not phones in Ionic 4 - ionic-framework

I found this thread that will lock it for every device How to restrict app to portrait mode only in ionic for all platforms? but what I am looking to do is allow screen rotation on tablets, but not phones.
I was hoping this would be something I could setup in the config.xml, but I am thinking I am going to need something more like this https://ionicframework.com/docs/native/screen-orientation/ and do it programmatically unless I am missing something. Any ideas?

You can use import { Platform} from 'ionic-angular'; for check device and import { ScreenOrientation } from '#ionic-native/screen-orientation'; for rotate your screen.
constructor(private navCtrl: NavController, private plt: Platform, private screen: ScreenOrientation) {
if (this.plt.is('tablet')) {
if (this.screen.type === 'portrait-primary') {
this.screen.lock(this.screen.ORIENTATIONS.LANDSCAPE);
}
}
}
This code with check if device is tablet and check if screen is portrait then it will automatically rotate your screen to landscape mode.

Related

Device orientation in flutter

How to develop app for both device orientation(portrait and landscape) in flutter. When I rotate my device in landscape, app size will adjust on landscape. If I rotate my device in portrait, app size will adjust on portrait.
The answer is simple called as "responsive design", please have a look to one of the best post about the same subject ;
https://medium.com/flutter-community/developing-for-multiple-screen-sizes-and-orientations-in-flutter-fragments-in-flutter-a4c51b849434
and also from the original source from Flutter documentation ;
https://flutter.dev/docs/development/ui/layout/responsive
Hope this works
you can develop two widgets for each orientation each one has different sizes of text, padding.... using MediaQuery.of(context).orientation to get the current orientation or you can use Layout Builder.
Otherwise, you can lock your app to a specific orientation:
import 'package:flutter/services.dart';
main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
runApp(MyHomePage());
}

Google Daydream Keyboard Unity UI TextInput?

I am attempting to create an input field in a google daydream app using the latest Google VR SDK for Unity and Unity 5.4.2.
I am wondering if someone may have insight into integrating the Daydream Keyboard. I can place a canvas and input field but when I run the application on the Pixel and Daydream View, and select the inputfield the standard android keyboard renders.
I am not sure if the Daydream Keyboard needs to be integrated separately in unity.
The Daydream keyboard is installed and is functional on published daydream apps.
Nope, the official Daydream Keyboard is not Unity ready, see https://forum.unity3d.com/threads/daydream-keyboard-in-unity.441448/
You can download the GoogleVR SDK, and you will find the keyboard demo scene inside GoogleVR/Demos/Scenes. From there, you can use the prefabs given for keyboard.
Apart from this, you can use the free asset "CurvedKeyboard" from asset store.
To handle the android default keyboard, you can do something like this.
public class SomeClass:MonoBehaviour
{
private TouchScreenKeyboard defaultKeyboard;
void Start ()
{
defaultKeyboard = TouchScreenKeyboard.Open ("", TouchScreenKeyboardType.Default);
defaultKeyboard.active = false;
}
public void didClickOnTextField()
{
defaultKeyboard.active = false;
}
}

Cordova/Phonegap iPhone splashscreen bug

I'm using cordova 2.6 to make an iPhone application in Landscape mode only.
I've a problem with my splashscreen, when I launch app I see the good one during view seconds, then it rotate automatically before loading index page.
All params in plist, xcode and xml are on landscape mode, splashscreen has good size and all works fine on iPad. I know there is no landscape splashscreen for iPhone, I just want it still in portrait, don't rotate after view seconds.
As I can see problem is due to the splashscreen plugin of Cordova who create a view in the bad orientation after display the good splashscreen.
Thanks for your help
There is a bug in CordovaLib\Classes\CDVSplashScreen.m where it only switches out the images on an iPad for Landscape vs Portrait.
if you remove the line
} else if (CDV_IsIPad()) {
and the corresponding } then landscape will work across devices. You will need to ensure that your Resources\splash folder has the following files in it:
iPad:
Default-Portrait~ipad.png (768x1004px)
Default-Landscape~ipad.png (1024x748px)
iPad #2x:
Default-Portrait#2x~ipad.png (1536x2008px)
Default-Landscape#2x~ipad.png (2048x1496px)
iPhone:
Default-Portrait~iphone.png (320x480px)
Default-Landscape~iphone.png (480x320px)
iPhone #2x:
Default-Portrait#2x~iphone.png (640x960px)
Default-Landscape#2x~iphone.png (960x640px)
iPhone 5 #2x:
Default-568h-Portrait#2x~iphone.png (640x1136px)
Default-568h-Landscape#2x~iphone.png (1136x640px)
Hope that helps

How to set different orientation changing settings on phone and tablet?

I making an app both for phones and galaxy tab.
I want to be only portrait mode on phones, and portrait and landscape as well in tabs.
So far i got this code snippet:
public void onCreate(Bundle savedInstanceState)
{
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
if(!(width>=800 && height>=1280))
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
//... more code below
So i just check the screen size and if it is the tablet's 800x1280, i do nothing and orientation change is active. If it is not 800x1280 i do:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
I thought it will be work fine, but for some random bug, it is not working every time..
Lets say for about ten times, the orientation just changes to landscape to a second on phones then it changes back to portrait. So a little buggy a little wrong.
Is it another better way to do this?
you can set to screenOrientation in mainfest
<activity
android:name=".Dis"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>

Disabling Video Out of App Videos on iOS devices

I have an iOS app which I am developing, this app has videos which are copyright material. I am allowed to use them to be seen within the app but not to be seen when connected to a TV. ie. via HDMI or component - instead when a video is playing and someone connects a tv out lead to the device i need to display a screen like a splash screen saying it is not allowed etc...
So my question is how can i catch when a tv out device has been connected to the device? or how can i know when tv out has been requested to the MPMoviePlayerController (which is what im using to display the video)?
I have searched everywhere for this and can not find any answer!
Thanks.
Check out Technical Q&A QA1738: How to Opt Out of Video Mirroring. Here is what you basically need to do:
UIScreen *aScreen;
NSArray *screens = [UIScreen screens];
for (aScreen in screens)
{
if ([aScreen respondsToSelector:#selector(mirroredScreen)]
&& [aScreen mirroredScreen] == [UIScreen mainScreen])
{
// The main screen is being mirrored.
}
else
{
// The main screen is not being mirrored, or
// you are not running on a compatible device.
}
}