Hide Lanscape mode in Android phone in NativeScript Angular
1.Allow both orientations in Android tablet
2.Restrict Landscape and allow only portriat version in phone
lockOrientation(orientation) {
const activity = app.android.startActivity;
switch (orientation) {
case 'unlocked':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
break;
case 'portrait-primary':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
case 'portrait-secondary':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
break;
case 'landscape-primary':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
case 'landscape-secondary':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
break;
case 'portrait':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
break;
case 'landscape':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
break;
default:
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
break;
}
just checking and calling the below method is working for me
if (app.android && device.deviceType === 'Phone') {
this.lockOrientation('portrait');
}
Use deviceType from platforms to know which device type the app is running. If it's Tablet then use nativescript orientation plugin to lock the orientation to portrait.
Related
I am using Skiasharp on Xamarin Forms app. With SKTouchAction I was trying to capture the time duration of SKTouchAction.Pressed and SKTouchAction.Released and find if the gesture is Long pressed or not. But the issue is SKTouchAction.Released is not triggered on Android.
protected override void OnTouch(SKTouchEventArgs e)
{
switch (e.ActionType)
{
case SKTouchAction.Moved:
break;
case SKTouchAction.Pressed:
//save current time here
break;
case SKTouchAction.Released:
//Compare time here to check long press
break;
}
}
There is a similar issue on the github. It seems you need to let the OS know that you wanted to continue receiving touch events. Such as:
protected override void OnTouch(SKTouchEventArgs e)
{
e.Handled = true;
switch (e.ActionType)
{
case SKTouchAction.Moved:
break;
case SKTouchAction.Pressed:
//save current time here
break;
case SKTouchAction.Released:
//Compare time here to check long press
break;
}
}
In addition, you can also refer to this case.
I have disabled the navigation bar and i want to enable the bar only for ios and not for android.
NavigationPage.HasNavigationBar="false"
I have done the disabling through this code.
You can perform a runtime switch on Device.RuntimePlatform:
switch(Device.RuntimePlatform)
{
case Device.Android:
NavigationPage.HasNavigationBar = false;
break;
default:
break;
}
re: https://learn.microsoft.com/en-us/dotnet/api/xamarin.forms.device.runtimeplatform?view=xamarin-forms
#if __ANDROID__
NavigationPage.HasNavigationBar = false;
#endif
I would like to read pen events and touch events from a Wacom tablet, from which I need at least the position and pressure. I saw that there are touch events in SDL2, but no events are triggered in my application with the code below. I tested with a Bamboo Touch using both the pen and my fingers.
Does SDL2 not support pens? What is the easiest alternative for me to use on Windows if not?
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
running = false;
break;
case SDL_FINGERUP:
printf("finger up: \n");
break;
case SDL_FINGERDOWN:
printf("finger down: \n");
break;
case SDL_FINGERMOTION:
printf("finger motion: \n");
break;
}
}
I am Using Xcode 5.1 and Cocos2D V3.0.0.rc.3.
I have an universal app made with Cocos2d 2.0, it had a feature in AppDelegate.m that allowed to choose device orientation based on the device it was running before showing the intro scene:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
return YES;
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
return YES;
}
return NO;}
so if it was running on an iPhone, i fixed orientation to portrait mode, and if it was running on an iPad i fixed orientation to Landscape (Left), this way i loaded up a different background image for each device and later on a different scene for each device.
The thing is that i have not been able to use the same method in the newest version of Cocos2d, and i can not change it on the fly , otherwise with an if statement it would have been a piece of cake, and i can not also use an if statement in the Cocos2d config files (CCAppDelegate.h and .m)
Using the config provided by Xcode, is not working also, i think it is being overridden by Cocos2d at some point that i just can not figure out.
so, Anyone know how to choose orientation based on device? please note that it will be a fixed orientation and it is for the last Cocos2d version.
Thanks!.
Finally i have managed it myself, by modifying CCAppDelegate.m, it allowed an if comparison, note that commented code was Cocos2d default code:
-(NSUInteger)supportedInterfaceOrientations
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
return UIInterfaceOrientationMaskLandscape;
}
else
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
// if ([_screenOrientation isEqual:CCScreenOrientationLandscape])
// {
// return UIInterfaceOrientationMaskLandscape;
// }
// else
// {
// return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
// }
}
Thanks!
I have used below function for check network status in windows mobile simulator. It returns "unknown" either ethertnet present or not.
function checkConnection() {
var networkState = navigator.network.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
checkConnection();
On Windows Phone, For get The current interface you can use the class 'NetworkInterfaceList' :
NetworkInterfaceInfo CurrentInterface;
var interfacesList = new NetworkInterfaceList();
foreach (NetworkInterfaceInfo specificInterface in interfacesList)
{
CurrentInterface = specificInterface;
break;
}
You can Subscribe to an event for the network changement :
DeviceNetworkInformation.NetworkAvailabilityChanged += NetworkChanged;
private void NetworkChanged(object sender, NetworkNotificationEventArgs e)
{
CurrentInterface = e.NetworkInterface;
}
After get the current interface, you can get the true type of network :
switch (CurrentInterface.InterfaceType)
{
case NetworkInterfaceType.Ethernet:
// ETHERNET (USB connected)
break;
case NetworkInterfaceType.MobileBroadbandCdma:
switch (pNetworkInterfaceInfo.InterfaceSubtype)
{
case NetworkInterfaceSubType.Cellular_GPRS:
// 2G
break;
case NetworkInterfaceSubType.Cellular_EDGE:
// 2GP
break;
case NetworkInterfaceSubType.Cellular_EVDO:
case NetworkInterfaceSubType.Cellular_EVDV:
// ?
break;
case NetworkInterfaceSubType.Cellular_1XRTT:
// ?
break;
case NetworkInterfaceSubType.Cellular_3G:
// 3G
break;
case NetworkInterfaceSubType.Cellular_HSPA:
// 3GP
break;
case NetworkInterfaceSubType.Unknown:
// Unknonwn ? 4G is Unknown.
break;
}
break;
case NetworkInterfaceType.MobileBroadbandGsm:
switch (pNetworkInterfaceInfo.InterfaceSubtype)
{
case NetworkInterfaceSubType.Cellular_GPRS:
// 2G
break;
case NetworkInterfaceSubType.Cellular_EDGE:
// 2GP
break;
case NetworkInterfaceSubType.Cellular_EVDO:
case NetworkInterfaceSubType.Cellular_EVDV:
// ??
break;
case NetworkInterfaceSubType.Cellular_1XRTT:
// ??
break;
case NetworkInterfaceSubType.Cellular_3G:
// 3G
break;
case NetworkInterfaceSubType.Cellular_HSPA:
// 3GP
break;
case NetworkInterfaceSubType.Unknown:
// Unknown? 4G is Unknown
break;
}
break;
case NetworkInterfaceType.Wireless80211:
// WIFI
break;
}
Note that with a Windows Phone 7 project, We haven't a "4G type", When I test the 4G with a device, The NetworkInterfaceType is unknown... but, if we have a network problems in 32G or 3G, is Unknown too..
I've not test with a Windows Phone 8 project, but, in theory, that works in 4G.
Also, you can have more details on the Networks type here.
PS: For test the network, there is nothing better than testing with a real device, and therefore, a real network.