Jquery mobile orientationChange error on startup in landscape mode - android

I have some kind of app, where interface depends on orientation change. So I have two functions for interface portraitSet() and landscapeSet(). Here is the code how I catching up orientation change event:
$(window).on("orientationchange",function(event){
alert(event.orientation);
if (event.orientation == 'portrait')
{
$(portraitSet());
}
else if (event.orientation == 'landscape')
{
$(landscapeSet());
}
});
On launch app in portrait mode it works perfectly, but when start app in landscape mode and trying to set mobile into portrait mode my alert(event.orientation) giving me message "landscape", but mobile on portrait mode. Where is my mistake?

hi use this code.....
$(window).resize( function(){
var height = $(window).height();
var width = $(window).width();
if(width>height) {
// Landscape
alert("LANDSCAPE");
} else {
// Portrait
alert("PORTRAIT");
}
});
if you need more refer

Related

Enable Device Screen Rotation Landscape or Potrait, only for Tablet Device by Flutter

I would like to enable my application screen to landscape or portrait only for tablets. Still on Portrait for smartphone The application was developed by Flutter.
check device is tablet
class DeviceUtil {
static String get _getDeviceType {
final data = MediaQueryData.fromWindow(WidgetsBinding.instance.window);
return data.size.shortestSide < 550 ? 'phone' : 'tablet';
}
static bool get isTablet {
return _getDeviceType == 'tablet';
}
}
DeviceUtil.isTablet; //true
use of this
if(DeviceUtil.isTablet){
//landscape-or-potrait
}else{
//landscape-or-potrait
}
You can set portrait with SystemChrome
final data = MediaQueryData.fromWindow(WidgetsBinding.instance!.window);
if(data.size.shortestSide > 600) { // check if its bigger
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
} else { // otherwise will be ..
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
}
Play with digit to get the best

How do I keep the screen turned on while debugging in Android?

Settings the developer's flag "Stay awake" might result in constant battery drain of your debugging device. So, how can you easily keep the device screen on ONLY while debugging?
try this
try
{
if( BuildConfig.DEBUG && Debug.isDebuggerConnected() )
{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
else
{
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}
catch(Exception e)
{
e.printStackTrace();
}
this is for vertical
//vetical position
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Make to run your application only in portrait mode
this is for screen always screen on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

HTML5 video controls disappear in full-screen mode on android devices

I'm developing a cross platform app using cordova with an angular material front end.
I use HTML5 video tags in a list of md-cards to play videos with external urls. When inline the videos play correctly, and display the native controls as expected.
<video class="project-video" video-directive item="$ctrl.project" ng-src="{{$ctrl.project.videoUrl | trustUrl}}" preload="auto"
controls poster="{{$ctrl.project.video.thumbnail_url}}">
Your browser does not support the video tag.
</video>
However when I click the "toggle full-screen" button the video does go to full-screen, but the default controls disappear. I cannot get back to the app after this - the native android back button does not close the full screen - instead it closes the whole app.
The solution I am looking for will make the controls always appear even in full screen mode; this works out the box running the same code on iOS.
Therefore I do not want to spend time developing my own custom video controls just for android, if I can help it! So please do not post answers about how to do that (plenty already available on SO and elsewhere).
I am using a Meizu m2 note android device.
Thanks!
EDIT:
The controls are still there but are showing up in the shadow DOM tree in css as being of size 0 x 0px. Even when I change their size in chrome dev tools using the !important flag, they do not show up.
Any ideas?
This is an issue with Flyme OS which is used by Meizu devices. Since the controls are available and not visible, this should be resolved by ugrading the Flyme OS.
Please update Flyme OS to resolve this as the older versions of Flyme seems to have quiet some problems with fullscreen video mode. Hope it helps. Cheers
set the values which then allow to exit fullscreen.
var videoElement = document.getElementById("myvideo");
function toggleFullScreen() {
if (!document.mozFullScreen && !document.webkitFullScreen) {
if (videoElement.mozRequestFullScreen) {
videoElement.mozRequestFullScreen();
} else {
videoElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
document.mozFullScreen = true;
document.webkitFullScreen = true;
} else {
if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else {
document.webkitCancelFullScreen();
}
}
}
document.addEventListener("keydown", function(e) {
if (e.keyCode == 13) {
toggleFullScreen();
}
}, false);
add these two lines ..
document.mozFullScreen = true;
document.webkitFullScreen = true;
if you want something better
fullScreenButton.addEventListener("click", function() {
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) { // current working methods
if (video.requestFullscreen) {
video.requestFullscreen();
} else if (video.msRequestFullscreen) {
video.msRequestFullscreen();
} else if (video.mozRequestFullScreen) {
video.mozRequestFullScreen();
} else if (video.webkitRequestFullscreen) {
video.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
});
How about this in your code your not mentioned controls attribute fully may be that could cause the problem
<video id="myvideo">
<source src="path/to/movie.mp4" />
</video>
<p onclick="toggleControls();">Toggle</p>
<script>
var video = document.getElementById("myvideo");
function toggleControls() {
if (video.hasAttribute("controls")) {
video.removeAttribute("controls")
} else {
video.setAttribute("controls","controls")
}
}
</script>

Force browser screen orientation

I'd like to display my website only in landscape mode when viewed from modern smartphones. Is there a way to force the major mobile browsers- Chrome/Firefox/Safari/IE10 to do so? Basically I'd like them to start the browser in landscape mode, irrespective of screen orientation and rotation lock.
Is it too much to ask? I think not because certainly there are games that only play in landscape mode, and the Windows Phone UI home screen uses only portrait mode.
Well, you can't force browsers orientation to landscape, but you sure can try to detect device orientation and suggest the user to rotate his/her device (through a full screen <div> and hide it when the user rotated the display)!
if (window.DeviceOrientationEvent) {
console.log("DeviceOrientation is supported");
}
Then add the appropriate listeners once you know device orientation is supported:
if (window.DeviceOrientationEvent) {
// Listen for the event and handle DeviceOrientationEvent object
window.addEventListener('deviceorientation', devOrientHandler, false);
}
Then, handle the event:
if (window.DeviceOrientationEvent) {
document.getElementById("doEvent").innerHTML = "DeviceOrientation";
// Listen for the deviceorientation event and handle the raw data
window.addEventListener('deviceorientation', function(eventData) {
// gamma is the left-to-right tilt in degrees, where right is positive
var tiltLR = eventData.gamma;
// beta is the front-to-back tilt in degrees, where front is positive
var tiltFB = eventData.beta;
// alpha is the compass direction the device is facing in degrees
var dir = eventData.alpha
// call our orientation event handler
deviceOrientationHandler(tiltLR, tiltFB, dir);
}, false);
} else {
document.getElementById("doEvent").innerHTML = "Not supported."
}
...and display the result (i.e hide the full screen suggestion <div>)!
document.getElementById("doTiltLR").innerHTML = Math.round(tiltLR);
document.getElementById("doTiltFB").innerHTML = Math.round(tiltFB);
document.getElementById("doDirection").innerHTML = Math.round(dir);
// Apply the transform to the image
var logo = document.getElementById("imgLogo");
logo.style.webkitTransform =
"rotate("+ tiltLR +"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
logo.style.MozTransform = "rotate("+ tiltLR +"deg)";
logo.style.transform =
"rotate("+ tiltLR +"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
Reference: http://www.html5rocks.com/en/tutorials/device/orientation/
Hope that helped :)

Flash Builder 4.6 Mobile Orientation

I'm working with FlashBuilder 4.6 to develop Android app.
In the application there is a requirement of setting some values when device orientation changes. i.e. setting the values when the screen/device orientation changes from Landscape to Portrait and vice-verse.
Although Initially my application has LandScape orientation. And this requirement is on specific view.
I want every time when the screen/device orientation changes the values must be set there.
I am not getting the desired result.
Please guide me and tell me if I am at wrong in code or how can i achieve this.
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="{data}"
xmlns:mx="library://ns.adobe.com/flex/mx"
viewActivate="view1_viewActivateHandler(event)"
creationComplete="view1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
if(Accelerometer.isSupported)
{
accl = new Accelerometer();
accl.addEventListener(AccelerometerEvent.UPDATE,update); //accl.addEventListener(AccelerometerEvent.UPDATE,adjustImage);
}
}
private function update(event:AccelerometerEvent):void
{
this.stage.autoOrients = true;
//in the below line I am attaching StageOrienationEvent that will adjust the
//values.
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE,adjust);
}
private function adjust(event:StageOrientationEvent):void
{
if(event.afterOrientation == StageOrientation.ROTATED_LEFT)
{
testVal.text ="After OR is LEFT";
}
else if(event.afterOrientation == StageOrientation.ROTATED_RIGHT)
{
testVal.text ="After OR is RIGHT";
}
else if(StageAspectRatio.LANDSCAPE)
{
testVal.text ="StageAspectRatio is Landscape";
}
else if(StageAspectRatio.PORTRAIT)
{
testVal.text="StageAspectRatio is Portrait";
}
}
</fx:Script>
Thanks.
Finally found the solution after spending two days on this.
in update function add OrientationChanging Event in stage.addEventListner.
private function update(event:AccelerometerEvent):void
{
this.stage.autoOrients = true;
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING,adjust);
}
private function adjust(event:StageOrientationEvent):void
{
switch(event.afterOrientation)
{
case StageOrientation.DEFAULT:
//Do Something here. The Portrait Position.
break;
case StageOrienatation.ROTATED_LEFT:
//Do Something here when you rotate your phone portrait to left side.
break;
case StageOrienatation.ROTATED_RIGHT:
//Do something here when you rotate your phone portrait to right side.
break;
}
}
Many thanks to all who viewed this question and try put their efforts for solution. :)
i am not a experimented coder! but : private function update(event:AccelerometerEvent):void should be : private function accl(event:AccelerometerEvent):void ?? or something like this in below code if(stage[not event].afterOrientation == ??? its just a opinion!

Categories

Resources