orientation change event

775 views
Skip to first unread message

bolmaster2

unread,
Dec 3, 2008, 12:10:20 PM12/3/08
to phonegap
Hi all!
I was wondering if phonegap have fixed so we can listen for the
orientation change events from javascript? I read this thread about it
http://groups.google.com/group/phonegap/browse_thread/thread/cbf78e8ce2b81f9d
but that isnt a complete solution to it.

Does anyone have a working solution?

Thanks

Faisal siddiqui

unread,
Dec 3, 2008, 2:40:39 PM12/3/08
to phon...@googlegroups.com
I m not sure if its still unfixed

As first step therez nothing todo with it just add
a function
shouldAutoRotate
& return yes
In controller.m

I dont have code infront of me
Bt i hope this will help you

~codegenerator
--
Sent from my mobile device

bolmaster2

unread,
Dec 4, 2008, 4:44:57 AM12/4/08
to phonegap
Thanks for that man, it makes webview rotate but it doesn't trigger an
event for the javascript to listen to, so we never know when the phone
is rotated!

In my eyes, this is a quite important feature for phonegap to have
included, right? Is it planned to be added?

- bolmaster2


On 3 Dec, 20:40, "Faisal siddiqui" <faysal.siddi...@gmail.com> wrote:
> I m not sure if its still unfixed
>
> As first step therez nothing todo with it just add
> a function
>  shouldAutoRotate
> & return yes
> In controller.m
>
> I dont have code infront of me
> Bt i hope this will help you
>
> ~codegenerator
>
> On 12/3/08, bolmaster2 <bolmast...@gmail.com> wrote:
>
>
>
> > Hi all!
> > I was wondering if phonegap have fixed so we can listen for the
> > orientation change events from javascript? I read this thread about it
> >http://groups.google.com/group/phonegap/browse_thread/thread/cbf78e8c...

bolmaster2

unread,
Dec 4, 2008, 9:24:15 AM12/4/08
to phonegap
I solved this by using the willRotateToInterfaceOrientation method and
from there called a javascript function with the new orientation.

Someone might find this useful, a bit modified from
http://groups.google.com/group/phonegap/browse_thread/thread/cbf78e8ce2b81f9d
to make it work:

- (void)willRotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation duration:
(NSTimeInterval)duration {
NSString * jsCallBack = nil;
double i = 0;

switch (toInterfaceOrientation){
case UIInterfaceOrientationPortrait:
i = 0;
break;
case UIInterfaceOrientationPortraitUpsideDown:
i = 180;
break;
case UIInterfaceOrientationLandscapeLeft:
i = 90;
break;
case UIInterfaceOrientationLandscapeRight:
i = -90;
break;
}


GlassAppDelegate *appDelegate = (GlassAppDelegate*)[[UIApplication
sharedApplication] delegate];
jsCallBack = [[NSString alloc] initWithFormat:@"setOrientation(%f);
window.onorientationchange();", i];
[appDelegate.webView
stringByEvaluatingJavaScriptFromString:jsCallBack];

[jsCallBack release];
}


For example the appDelegate.webView property you have to declare and
then set it in GlassAppDelegate.m like this:
- (void)webViewDidFinishLoad:(UIWebView *)theWebView
{
[window bringSubviewToFront:viewController.view];
webView = theWebView;
}

Maybe thats not the best explanation..

Faisal siddiqui

unread,
Dec 4, 2008, 10:09:16 AM12/4/08
to phon...@googlegroups.com
I didn't check the javascript function call but my webView rotate with complete layout
but for that matter i used the CSS like this

body[orient="landscape"] > *:not(.toolbar) {
    min-height: 268px;
}

body[orient="landscape"] > .header > h1 {
    margin-left: -125px;
    width: 250px;
}

and it works for me without overiding willRoateToInterfaceOrientation method call as i dealt the complexity in CSS


~codegenerator

bolmaster2

unread,
Dec 4, 2008, 10:47:17 AM12/4/08
to phonegap
Thats a nice solution, but in my case i needed to notify the
javascript to make changes to the dom.

On 4 Dec, 16:09, "Faisal siddiqui" <faysal.siddi...@gmail.com> wrote:
> I didn't check the javascript function call but my webView rotate with
> complete layout
> but for that matter i used the CSS like this
>
> body[orient="landscape"] > *:not(.toolbar) {
>     min-height: 268px;
>
> }
>
> body[orient="landscape"] > .header > h1 {
>     margin-left: -125px;
>     width: 250px;
>
> }
>
> and it works for me without overiding
> *willRoateToInterfaceOrientation*method call as i dealt the complexity
> in CSS
>
> ~codegenerator
>
> On Thu, Dec 4, 2008 at 7:24 PM, bolmaster2 <bolmast...@gmail.com> wrote:
>
> > I solved this by using the willRotateToInterfaceOrientation method and
> > from there called a javascript function with the new orientation.
>
> > Someone might find this useful, a bit modified from
>
> >http://groups.google.com/group/phonegap/browse_thread/thread/cbf78e8c...

Faisal siddiqui

unread,
Dec 4, 2008, 10:51:56 AM12/4/08
to phon...@googlegroups.com
The important thing is your problem has been solved..
wish you good luck

cheers
~codegenerator

Brian LeRoux

unread,
Dec 4, 2008, 2:03:24 PM12/4/08
to phon...@googlegroups.com
Hey guys, very interesting discussion and, yes, this definitely needs
to be addressed. We'll be investigating / I updated the roadmap to
reflect this.

http://phonegap.pbwiki.com/Roadmap

Any further suggestions, ideas and hacks very welcome!

Code Generator

unread,
Dec 5, 2008, 2:10:41 AM12/5/08
to phonegap
You are welcome Brian
Its good to have wiki for phonegap

~codegenerator

On Dec 5, 12:03 am, "Brian LeRoux" <brian.ler...@nitobi.com> wrote:
> Hey guys, very interesting discussion and, yes, this definitely needs
> to be addressed. We'll be investigating / I updated the roadmap to
> reflect this.
>
> http://phonegap.pbwiki.com/Roadmap
>
> Any further suggestions, ideas and hacks very welcome!
>
> On Thu, Dec 4, 2008 at 7:51 AM, Faisal siddiqui
>
> <faysal.siddi...@gmail.com> wrote:
> > The important thing is your problem has been solved..
> > wish you good luck
>
> > cheers
> > ~codegenerator
>
Reply all
Reply to author
Forward
0 new messages