VS2008 and QVGA - Windows Mobile Software Development

Hi.
Firstly, if this is in the wrong place then my apologies.
Anyway, I'm trying to develop and few apps for windows mobile at the same time as bringing myself up-to-date with VB.net. I have almost finished my first one but am having problems with getting it to display properly on QVGA screens.
When I run the app on the emulator it displays properly
When I run the app on an HTC Touch HD, it runs ok, if a little small
When I run the app on an HTC Kaiser, it only displays a small portion of the web browser.
The only thing I can think of is the app is designed to run on a WVGA screen and above, only I can't think of a way to change this. Any ideas would be appreciated.
BTW, any apps I do finish will be posted for testing and then released for everyone to enjoy for free

Use the ClientSize property of the form in the OnPaint() event to get the actual size of the client area available. You may have to move stuff around and resize screen objects to get them to fit. The form's OnPaint() event is triggered before those of its child objects so set 'em up how want them here.
ClientSize is a Size object.
In VB use me.ClientSize.Width and me.ClientSize.Height to get those values for the clientarea.
Alternatively me.ClientRectangle returns a Rectangle object with the Top, Left, Bottom and Right values of the area.

Cheers, I'll try that

RE VS 2008 and QVGA
Ok, since my last post I've worked out that it's only the web-browser control on the form that is not scaling properly. Even if I try to restrict the width/height, it crops the page instead of resizing.
Your help is much appreciated.

Related

Holy Quran WVGA - optimised for WVGA 2 pages on-screen

This Qur'an Viewer was developed for my own use and will be invaluable to anyone who has memorised the Quran and wants to view two-pages at once so that it looks very similar to the mushaf.
Two types of Indo-Pak script are available, as well as two types of Uthmani script.
WVGA (800x480) resolution is an absolute necessity to run this application, any higher or lower resolution will probably not work properly and has not been tested.
You may find the size of the script is a little small, but as a Hafiz I find it invaluable as a quick reference when out and about.
You can click the page to move next/previous. You can also click the upper part of the page to go next/previous juz or surah.
You can choose from three bookmark positions, which will automatically remember your page position on each of the three virtual bookmarks.
Download it here. Unzip and see readme.txt for full installation instructions:
http://www.acclaimit.co.uk/downloads/HolyQuranWVGA_Release_20091001.zip
*** Please completely uninstall the previous Quran13Line application if you installed it before. This new application uses all new script images and a different folder structure. ***
Screenshots attached.
Jazzak Allah Khair
Could you please tell me which screen resolutions are compatible ?
qvga,vga,wqvga,wvga ???
Thank you
I'm sorry, WVGA (800x480) resolution is an absolute necessity to run this application, any higher or lower resolution will not work and has not been tested.
Thank you very much
DOWNLOADED AND INSTALLED
It is wonderful !
But could we get better Pictures ? with better script ?
Jazak-Allah, I'm glad it works. I tried my best to make the pictures look good using the 480 pixels page height so that we can fit two pages on-screen at a time. It's not going to be possible to make it any better unless we have more pixels to play with, or do you have any alternative ideas?
What do you mean by better script? Which part of the script are you having difficulty with exactly?
Thanx for your reply
I meant a different set of pictures, even the 15 line ones
attached are two samples (Zipped with WinZip)
and if you like, I can guide you to the link where you will be able to download the whole set of the first or the second sample.
Thanx again
I see. You forgot the attachments.
Please let me know the link to the whole sets of any other images you know of and I'll see what I can do... 15 or other lined ones, but I will have to rename the application too
I've resized the sample images to 480-pixel height. See attached.
I think the script on these images is much finer than the 13-line ones and is unreadable with two pages on-screen at a time. It would make more sense to show a full page at a time for the 15-line ones, which does not quite fit with the original design goal of this application.
I guess the answer would be to create a new application called "Quran15Line" showing one page at a time, but I am not sure how many people would be interested in this. Poll?
So? have you checked the samples ?
I guess the images without the frames can be visualised better especially when two of them are joined together on a horizontal WVGA screen, right ?
waiting for your reply
Well, as I have mentioned in my previous post, ( sorry just seen ur answer ), the ones without the frame are better.
Regarding your suggestion of the "Single Page", I don't think too many people will be interested in it since the images are originally taken from a software with a single page, full screen style.
These are the links to the 'non frame images' try them and give me your feedback ( Horizontal and Vertical )
http://www.4shared.com/file/96364556/390c2fa6/v_wvga.html
http://www.4shared.com/file/97539687/b3476020/h_wvga.html
Thanx again
Ahh, about your attachment, in fact they both seem readable ! and do not forget that this software is intended for a 'two page style' which means that it is obviously with smaller pages.
I am so interested in the new images !
hope you can make them.
and regarding the software, you can change the options in the TOOLS key, to 13 lines ( your old images ) and 15 lines ( my suggested images ) !
What do you think ???
Jazakhallah Khair Brother Ashiq
Inshallah you will receive Sadqah Jariya every time i use it
this is what i have been looking for for ages
if you do update it can you consider a transalation in english which corresponds to same
13 line quran if possible,maybe i am asking too much
but thanks anyway
Salaams
I was already considering English translation which should correspond with the script. However, it will take a while to do this because there are so many English translations and because we have tell the application which aayaat are on each page so that they can be matched up to the translation. It may take a few weeks, but Insha-Allah I will work on it during any spare time I have.
jaguaralani said:
These are the links to the 'non frame images' try them and give me your feedback ( Horizontal and Vertical )
http://www.4shared.com/file/96364556/390c2fa6/v_wvga.html
http://www.4shared.com/file/97539687/b3476020/h_wvga.html
Click to expand...
Click to collapse
bro what difference with this?
Code:
http://www.4shared.com/file/134351630/60362269/h_wvga-800x480-medina2.html
http://www.4shared.com/file/134114828/f2fe41e9/v_wvga-480x800-medina2.html
thanks bro
we need another resolutions plz
thanks alot
there is a collection of indopak script at pdaquran .com
which is clearer to read as it is a page per screen
wonder if you you could use the images in you excellent software
ibrahimh said:
there is a collection of indopak script at pdaquran .com
which is clearer to read as it is a page per screen
wonder if you you could use the images in you excellent software
Click to expand...
Click to collapse
This application is designed for WVGA to show two pages per screen, so unfortunately I cannot use the pdaquran images. I would urge you to contact pdaquran and ask them to provide you with a Windows Mobile application (they already provide an iPhone one). In any case, couldn't you just download the PDF and view it using Adobe Reader one page at a time?
Dear monzoyt and all - thank you for the various uthmani images you sent - I am currently preparing the Uthmani/Madinah images and will release a new application within a few days InshaAllah.
It takes a while because I have cropped the images to maintain high quality after resizing and need to also match up the bookmarks to the page numbers, and also need to render the page numbers in arabic on the page sides due to the fact that the images do not have enough space to render the page numbers at the top.
monyozt said:
bro what difference with this?
Code:
http://www.4shared.com/file/134351630/60362269/h_wvga-800x480-medina2.html
http://www.4shared.com/file/134114828/f2fe41e9/v_wvga- -medina2.html
Click to expand...
Click to collapse
800x480 and 480x800, landscape and portrait screen mode!

Programatically update today screen image

Hi all,
First a little background into what I'm attempting...
On my PC, I have a self created program which swaps the desktop image to one selected at random from a predetermined directory. There's lots of nifty features, such as image resizing to fit desktop, support for different images on different monitors in a multi monitor setup. etc.
But enough about that, as it's not really windows mobile related. What is related is the fact i'm trying to implement something similar on my Xperia X1.
Obviously I want it so I can have different images for the today screen when it's in landscape and portrait mode - like the built in themes do. I have to admit i'm fairly miffed that this feature isn't supported nativly in a nice easy non-theme related way. it's nigh-on impossible to find an image that looks good in both aspects.
Anyway, I did have something working. A small program which creates a stwater_480_800.bmp and stwater_800_480.bmp by selecting a random image from one of two predetermined directories, and then plonking said images in the windows directory. (Replacing the two bmp images put there by the theme i was using) No resizing of images or anything fancy, just a straight file copy.
This line of code:
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 242, 0)
forces the today screen to update to the lovely new images after the files have been replaced.
All was well until I installed gtrab's excellent pure windows mobile 6.5 update (http://forum.xda-developers.com/showthread.php?t=588882). And although the app still works for the main part, i.e. it picks an image, and changes the background for the today screen, i have encountered a bug.
The image behind the updated start menu doesn't get refreshed - it stays as whatever the image was when the phone was last reset (Think it's specifically a hard reset? i.e. holding power button down the rebooting with sony ericsson logo etc).
Here's the code i'm currently using (Apologies for lack of comments, despite being employed as a vb.net programmer, i'm self taught and not commenting is a bad habit i've never gotten out of.)
Code:
Public Shared Sub SwitchBG()
Randomize()
Dim curdir As New IO.DirectoryInfo(SharedVars.LandscapeDir)
Dim imagefiles As IO.FileInfo() = curdir.GetFiles("*.bmp")
If imagefiles.Length > 0 Then
IO.File.Delete("Windows\stwater_800_480.bmp")
IO.File.Copy(imagefiles(Math.Floor(Rnd() * imagefiles.Length)).FullName, "Windows\stwater_800_480.bmp")
Else
MessageBox.Show("No Landscape Images!", "BGSwitcherPPC", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
End If
curdir = New IO.DirectoryInfo(SharedVars.PortraitDir)
imagefiles = curdir.GetFiles("*.bmp")
If imagefiles.Length > 0 Then
IO.File.Delete("Windows\stwater_480_800.bmp")
IO.File.Copy(imagefiles(Math.Floor(Rnd() * imagefiles.Length)).FullName, "Windows\stwater_480_800.bmp")
Else
MessageBox.Show("No Portrait Images!", "BGSwitcherPPC", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
End If
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 242, 0)
End Sub
I'd love to know what I have to do to force the start menu image to refresh. I've googled for a while with no joys.
Incidentally, I did discover that i can use .jpgs for the background (makes sense really). Not sure if that will have any bearing, but i'll be changing the code to accept both bmp, jpgs, and probably gifs. Can't see that it will affect my specific problem, but thought it would be worth mentioning.
Once i've got this sorted, i'll be ready to tackle the next stage, which is implementing some form of schedule so i can wake up to a new today screen image every day.
Thanks in advance to anyone with any pointers.
Matt.
Sorry, just realised I should have posted this in the windows specific forum.
Still, any help much appreciated!
Okay, I've managed to do this. Via a hacky work-around.
Basically, I realised after a bit of playing, that if you set a "normal" wallpaper, all it does is create a registry key. But, rather handily, the start menu and lock screens (lock was also affected by this bug) would see this change, and update their pic.
Also, rather handily, if you set the registry to an image that doesn't exist, the image then defaults back to the appropriate stwater
so the workaround is as follows...
Every time i run the switch code, I write an incrementing value to the HKCU\software\windows\today\wall registy value. This can be anything, providing it's not a "real image"
when you next open the start menu, it looks for this "new" image, can't find it, so loads the appropriate stwater image.
I'm gona stick the program in an Xperia forum for some feedback/suggestions.
edit: link to app: http://forum.xda-developers.com/showthread.php?t=594763

Transparent controls in native WM apps

Hey all,
I've been searching for techniques people use to make transparent controls. The problem with windows mobile is that windows always have the CLIPCHILDREN window style set. So you can't grab the contents of the parent window (in WM_ERASEBKGND for example) because it isn't there.
One technique would be to have the parent pass the handle of the background DC it uses to the child control but that involves having a memory DC around all the time. And if the child control is covering any sibling controls you'd be out of luck as well.
Another solution I've read about is to temporarily hide the child window so the parent window is forced to redraw the parts that would normally be obscured by the control. I personally do not like this approach. (the drawbacks are also discussed on some MS forum, i'm not allowed to post outside links yet, google for "Rounded Buttons : Does any one see any problems with this method" and you will find it)
So, there are ways to achieve what I'm looking for but they are far from optimal. Just wondering what everybody else is doing to achieve this.
The responses in that thread are pretty much spot on (funny to find I know over half the posters in that thread by reputation).
If you want to do this well, you really need to draw your own stuff, making a complete custom UI.
There is no proper way to do this in Windows Mobile (without runtime kernel patching, that is ).
Chainfire said:
The responses in that thread are pretty much spot on (funny to find I know over half the posters in that thread by reputation).
If you want to do this well, you really need to draw your own stuff, making a complete custom UI.
There is no proper way to do this in Windows Mobile (without runtime kernel patching, that is ).
Click to expand...
Click to collapse
What do you mean by "drawing your own stuff"? I am drawing everything myself now in all control i made using AlpheBlend() where needed. But that still doesn't resolve the background issue. Or are you referring to just drawing everything in a single WM_PAINT handler and only having one screen DC?
PegNosePete said:
What do you mean by "drawing your own stuff"? I am drawing everything myself now in all control i made using AlpheBlend() where needed. But that still doesn't resolve the background issue. Or are you referring to just drawing everything in a single WM_PAINT handler and only having one screen DC?
Click to expand...
Click to collapse
Well the method I use in my own new UI's is indeed per form (excluding WinAPI controls like edit boxes and such) draw using only one DC.
The problem is that any 'windowed' control, the parent will not draw to the DC if a 'windowed' control overlaps. Due to CLIPCHILDREN all data drawn to that position is simply lost.
Now, handling WM_PAINT you can get the entire update region, which tells you which parts of your form have to be redrawn. You must use this information, because blitting the entire form is very slow!
In essence, to do this right you well end up faking most of the GDI system, including your own 'fake' child windows, invalidating and revalidating portions, calculating the intersections of your 'fake' invalidated regions of the screen with the update region you get in WM_PAINT and redrawing those parts.
There are several different strategies to go about this, one is to redraw on demand, another one is to use double buffering.
I personally mostly use the double buffering technique, as this easily provides every 'fake' control with a bitmap of it's own region. A child control can then alphablend using the parent's buffer as one of the alphablend sources.
You can of course combine this with keeping state information whether a child, grandchild, etc is using alpha / transparency and this with an algorithm deciding which control needs double buffering or can draw on-demand, which can give both speed and memory use advantages. In a lot of situations you can then suffice with only double buffering the 'top' component (form) and a select number of child components.
Of course two drawbacks of per-control double buffering are speed and memory use. You can eliminate the complete-form double buffer with some smart coding and calculating. This will give you a slight speed and memory advantage. Memory use is high because many of your controls will have a copy of their current state.
This can be as complicated, feature-filled, fast and efficient as you are willing to make it. The better you can design the code the better it will work, but it is not a trivial task. There are many ways to go at this, no one way is definitely better than the other ways. It depends on what your applications does with it's display, how simple you are drawing (are you making a simple white background, or a background based on images for example gradient?), which method is more efficient.
The other method is getting the update region and actually perform redrawing of those invalidated sections (instead of copying from buffer). I can tell you from experience that if you are using image backgrounds and alphablend calls, this will be _much_ slower than double buffering (if done right).
I know all of this probaby makes little sense, I'm not a hero with explaining things ... you really have to figure this out for yourself, I guess.
Other advantages of building your own UI system are that if you do it smartly and buffering, it is very easy to port to directdraw, and possibly even GL. But I must warn you, on far the most devices actually using directdraw for this stuff is not much faster, it is in fact hardly noticable. If you manage to make a GL port, that can especially on older HTC devices (pre-HD2) be much faster.

mobilePVD - PocketPC client for movie managment PVD

Hi all!
This is the PocketPC Version (Viewer) of PVD the very best program to organize your movies.
You can download the PC version from http://www.videodb.info/forum_en/.
My thoughts were: what is the best movie managing and cataloging software worth while in the movie store and searching for a title... or sitting in front of the TV and trying to remember what cool movie I could watch...
That, and enjoying to write software for my mobile phone, were the reasons for mobilePVD.
The software is published at PVD's home and at xda-developers place.
How it works
First of all, you have to get PVD and enter your movies. After that, make a XML export. This writes a file containing the movie information and a directory containing the pictures. Take both and copy them onto your device. I recommend to copy them onto the SD card in a sub directory PVD.
Download mobilePVD and install it on your device. When starting, you will have to select the XML file by clicking Menu->Open DB. Your can select other languages and other skins (if someone makes them ).
When going to a sublist in mobilePVD (i.e. viewing the movie details or selecting directories) and you want to get back, just slide with your finger over the list from left to right...
How to translate
In the program directory on the device is a sub directory called "Languages". Within you find the language files. I deployed English and German so far. To make own translations just copy a file to your desktop, open it with any text editor and translate. Please publish your translation on either forum, so I can build the next version with more supported languages.
How to skin
also in the program directory you will find a sub directory "Skin" with all the images I use. The images in "Manila WVGA" are for a resolution of 800x480. If you like you can take those bitmaps and change them to fit other resolutions and other colors. Don't forget to adapt the settings in the skin.ini file.
And please share your work with us and publish your skins on either forum. I will put them in the download section.
Have fun!
Obelix
Changelog:
2.1 Filtering is back and actors are grouped by first letter.
2.0 uses virtual mode to load more movies before reaching end of memory
1.1 out of memory problem fixed
1.0 Initial release
If you like my work, you can buy me a glass of wine
Version 2.1 of mobilePVD
I was hoping this allows you to enter movie info directly on mobilePVD. A desktop entry method is rather inconvenient. Would that be possible?
Does this also mean I have to re-export everytime I add movies? I took a look at the desktop version and it is very good. I can see why it is more practical using the desktop for entry of movie info.
Obelix_A, I have exported some movies and I must say it looks really nice on my HD2 although it is still not very stable, sometime I get an error that quits the program. It's only 3 movies so I am wondering if it may sow down when I have much more (2,800 in my collection). I would love to have Ratings and duration. It is missing after export. Thanks, this is great for movie lovers just like IMDB Mobile. I am just surprised that there is not much feedback yet.
I like it to a while to sort all my movies and still didnt get all the pictures from IMDB, hey ho did it manually, i need to change the skins to VGA how do i go about that im a bit of a noobie when it comes to skins?
The Actor list is huge and is close to impossible to scroll all the way down to "T" etc. Can we have a sort of filter to search actor names? trev666, use IMP plugin for movie posters. It's excellent.
@Kensong cheers mate
it works well after i restarted my phone, without changing anything from wvga to vga so im happy, thanks man not looking forward to adding all my movies though lol
Ok so i now have a HD2.... works great
great app, thanks for sharing it
here we go with Version 2.0 of mobilePVD. It now uses a virtual mode of the SliderList, what means, that it can load more movies before running out of memory.
If it runs on your devices as stable as it does on mine, we can start adding new features...
Really nice work mate
Really nice work
If you don't mind, i have share it HERE.
Please feel free to drop me a comment if you have anything else to add or in case i have missed anything. Cheers~
just released version 2.1
Filtering is back now and actors are grouped by first letter
I have installed v2.1 right now.
If I click on one of the "-" e.g. "- Actors" I get an exception:
"RemoveItem in virtual mode not allowed"
I am very interested in the development of mobilePVD since I would love to have my movie list on my phone (TD2).
Is mobilePVD a "one man show" or are you planing to involve more developers?
I will check this and fix it...
Yes mPVD is a one-man-show. you can ask my friend amirdt (here on XDA) if he wants to join the project...
Actually I wanted to ask if I could help you with mPVD
what exactly do you want to add?
the only thing I could imagine right now, is another way to read the data.
play around with PVD and the exported data (XML) and how fast you can read it.
currently I am reading with XmlReader.Read and evaluate the nodes. If you can read faster, this would help. other proposals welcome
Here is just a spontaneous list:
- WM 6.5.5 Problem with menus. The black background (when menues are displayed) does not cover the whole screen. Above there is some space visible. This is because the top bar (where the clock is) is smaller and the windows task bar is bigger in WM 6.5.5 (Sorry, cant supply a picture now how it looks like)
- Filter Actors: Add a search field also
- Add a clear button to the search fields to clear the field easily
- Add (Readd?) a ">" to the Movie list to open the movie details (I think the ">" was already there in an earlier version.
- Maybe make the UI somehow less sensitive. At least on my device it moves very quickly. E.g. I cant open the details view without moving the movie list view up or down accidentally.
- Add "Reset all Filters" menu item to the Filter Menu.
- Remove the search field in the detailed movie view to get more space to view the details.
- Maybe make the "letter lines" (+A, +B, ..) in the actors view a little bit thicker so that it is easier to open/close them with a larger thumb
- Maybe add the "letter lines" (+A, +B, ..) to the movie list also. Dont know, how large collections will be handled right now.
- Add more filters like rating (stars...)
- Add movie trailer support (e.g. prepare trailers on PC (conversion etc.) and copy them to device. Link from within mPVD to start media player on device)
- ...
So where can I get the source code to get started with it?
Regards
Al
ok, ok
I will prepare the sources and make it available for you via SVN, so we can handle developing both.
By now, the list won't move when clicking. I changed that... (but all other things from your list can/need to be done)
so, drop me a PM with your wished user name and password for SVN and give me little time to prepare...
alfish2000 now officially joined the development of mobilePVD. So let's welcome him
thanks for your support!
http://www.videodb.info/forum_en/index.php?topic=1755.40

Include local JavaScript within PhoneGap on Windows Phone 7

I have a PhoneGap application designed to work on multiple mobile platforms. I'm loading a dynamic HTML content from an external page on the Internet using jQuery Mobile. The problematic system is Windows Phone 7.
This is what I get from the external page, with the URL of the script tag already replaced to load from the phone instead of from the net to save bandwidth:
HTML:
<script type="text/javascript" charset="utf-8" src="x-wmapp1:/app/www/test.js"></script>
This works fine on Android, iPhone and even BlackBerry when I replaced the x-wmapp1: part by a respective counterpart (e.g. file:///android_asset/www/ on Android). However, on Windows Phone 7 it doesn't seem to work at all.
When I try to load the same URL via $.getScript function, it always returns a 404 eror, even if I try and load it with a relative path only.
Any suggestions?
First of all, this type of question may be better suited to the Software Development or Apps and Games sub-forums, as a lot of the people who hang out here are more familiar with homebrew hacks. I'll give it a shot, though.
First of all, what kind of path are you trying to use? I haven't tried loading scripts or images in HTML or JS, but to dynamically load content within the app itself typically requires some care with regard to the path. For example, is the JS file being built into the assembly (as a resource) or included alongside it (as content)? How about the HTML page?
This is a kind of lame approach, but one option that's sure to work is just inlining the scripts in the page, directly. That won't increase the total app size or load time at all, although it might make maintaining the app take a little bit more effort.
Thanks for the reply, I will try to post this into the more appropriate forum.
With regards to paths - you can see the path in the HTML snippet I provided in the original question. It's all a bit specific and we cannot afford to load JS directly from page, since that does increase the size of the resulting HTML, sent from an external PHP page, thus increasing bandwidth. This is the first reason why we chose to have all JS and CSS files directly bundled with the application and load them internally rather than from Internet.
Also, all of JS files are included alongside the application as content. I'm using the same approach for all images, since if they were included as a resource, they would not show in the application.
GoodDayToDie said:
First of all, this type of question may be better suited to the Software Development or Apps and Games sub-forums, as a lot of the people who hang out here are more familiar with homebrew hacks. I'll give it a shot, though.
First of all, what kind of path are you trying to use? I haven't tried loading scripts or images in HTML or JS, but to dynamically load content within the app itself typically requires some care with regard to the path. For example, is the JS file being built into the assembly (as a resource) or included alongside it (as content)? How about the HTML page?
This is a kind of lame approach, but one option that's sure to work is just inlining the scripts in the page, directly. That won't increase the total app size or load time at all, although it might make maintaining the app take a little bit more effort.
Click to expand...
Click to collapse
First question: have you set the IsScriptEnabled proerty on the control to True? It defaults to False, preventing scripting within the control. Also, changing it only takes effect
on navigation, so if you already loaded the page and then set this property, it still won't work.
Anyhow, I missed that your HTML was coming externally, and only the scripts and stylesheets were local. That's... interesting, and seems reasonable enough, and I can't find any info online that exactly matches your use case. The way you're structuring the script src URI looks weird to me, but I haven't messed with the WebBrowserControl very much at all.
One solution, though a bit hacky:
Use the WebBrowserControl's InvokeScript function to dynamically load scripts into your pages. To do this, you would first need to load the script file content into a .NET String object. The GetResourceStream function is probably your best friend here, combined with ReadToEnd(). Then, just invoke the eval() JS function, which should be built-in, and pass it the JS file content. That will load the JS into the web page, creating objects (including functions) and executing instructions as the files are eval()ed.
Of course, you'd need to do this on every page navigation, but you can actually automate it such that the page itself requests that the app load those scripts. In your app, bind the script-loading function to the ScriptNotify event handler, probably with some parameter such as the name of the script to load. Then, on each page served from your server to the app, instead of including standard <script src=...> tags, use <script>window.external.notify('load localscript1.js')</script> and so on; this will trigger the app's ScriptNotify function for you.
I hope that helps. I can see your use case, but somewhat surprisingly, I couldn't find anybody else online who had either run into your problem or written a tutorial on doing it your way.
Thank you for your reply, it was very informative. One question though - why do you think the way I'm structuring the SCRIPT URI is wierd? I tried to mess around with relative URIs and the such, however those would load the JavaScript file from Internet rather than from the application itself.
The problem I'm running into with your proposed solutions, however is that:
1. the project is a PhoneGap/Cordova application, using its own components, so I have no idea where I would look for IsScriptEnabled here (although this all worked on an older PhoneGap release, so I'm guessing they have it set up correctly)
2. injecting a script programmatically on each navigation would require me to rewrite much of the code we already use for other platforms, not to mention those custom Cordova components, which I don't even know if they can handle such thing
As for my user case - I was surprised to be the only guy on the internet with this methodology in place as well. So it either works for everyone else or nobody really thought of doing it my way, since it's basically an Internet application (maybe the don't want to disclose their sources, who knows).
CyberGhost636 said:
1. the project is a PhoneGap/Cordova application, using its own components, so I have no idea where I would look for IsScriptEnabled here (although this all worked on an older PhoneGap release, so I'm guessing they have it set up correctly)
Click to expand...
Click to collapse
In the WebBrowser properties.
CyberGhost636 said:
As for my user case - I was surprised to be the only guy on the internet with this methodology in place as well.
Click to expand...
Click to collapse
Of course you not "the only guy". I've tried to port/run a few HTML java-script based games on WP7 (Digger and couple more) more then year ago; they runs well with one HUGE exception - touch screen events are freezing scripts execution and make games not playable.
The "x-wmapp1:" URI scheme was what I was referring to. Not sure where that comes from, but I haven't done anything really with the WebBrowser control.
I have no knowledge of PhoneGap or Cordova; I assume they're "we write your app for you" frameworks? One would assume that such tools would know to set IsScriptEnabled, but you may have to do so manually. A bit of web searching on that direction may be fruitful - maybe earlier versions enabled scripting by default, and now it's disabled by default so you have to specify an option somewhere?
Injecting the script on navigation really doesn't require any major change to the server-side code. I mean, is sending
<script>window.external.notify('load localscript1.js')</script>
really much different from sending
<script type="text/javascript" charset="utf-8" src="x-wmapp1:/app/www/test.js"></script>
? If that's too different, you could instead send
<script src="http://yourserver.com/LoadLocalScripts.js"></script>
and put "LoadLocalScripts.js" on your server with the following code:
window.external.notify('load localscript1.js');
This has only a trivial increase in server traffic and load time, but lets you continue using external scripts instead of inline ones. Very little server-side change needed at all.
Now, the additional client-side code to support the window.external.notify and call InvokeScript... normally I'd say that's dead easy, because it is if you have any experience with the .NET framework, but in your case I get the feeling that this isn't so? I code to the framework, or to the underlying native code, and I tend to code "raw" (very little auto-generated code), so I'm not going to be able to help you solve the problems with a "make me an app" wizard unless I can see the code it generates for you.
For what it's worth, here's the approximate raw code that I'd use (it's over-simplified, but close enough):
void HandleNotify (String param) {
String[] parts = param.split(" ");
if (parts[0] == "load") LoadScript(parts[1]);
}
void LoadScript (String script) {
String content = Application.GetResourceStream(new Uri(script, UriType.Absolute)).ReadToEnd();
theBrowserControl.InvokeScript("eval", content);
}
void theBrowserControl_Loaded (...event handler args here...) {
theBrowserControl.IsScriptEnabled = true;
theBrowserControl.ScriptNotify += HandleNotify;
theBrowserControl.Navigate("http://yoursite.com");
}
the URI comes from Windows Phone itself, with this code, you can see for yourself:
var a = document.createElement('a');
a.setAttribute('href', '.');
alert(a.href);
also, I've been informed that this works in Cordova 2.0, so it might be a 1.8.1 bug... will try and see how it goes
thanks for your help so far!
Looks like it was a problem with PhoneGap 1.8.1 - after upgading to Cordova 2.0 (PhoneGap got renamed) it all works now... thanks for all the help!

Categories

Resources