Wessam The Educational Forum وسام المنتدي التربوي
عزيزي الزائر يشرفنا إنضمامك لأسرة المنتدي بالضغط علي كلمة التسجيل وإن كنت عضوا في المنتدي فبادر بالضغط علي كلمة دخول وأكتب أسمك وكلمة السر فنحن في إنتظارك لتنضم إليناDear Guest ,We welcome to you with us & We hope That you will be a Member in our Forum


We Present Wessam The Educational Forum بسم الله الرحمن الرحيم نقدم لكم وسام المنتدي التربوي
 
الرئيسيةFace Bookس .و .جبحـثالتسجيلقائمة الاعضاءدخول
المواضيع الأخيرة
» معاذ عبدالمجيد حميد الكبيسي : الهندسة البيئية (رؤية تربوية)
السبت أغسطس 29, 2015 11:38 am من طرف د.عبدالمجيد حميد الكبيسي

» CHI-SQUARE TEST كاي سكوير التعريف والخطوات مترجم من العربية إلي الإنجليزية
الأربعاء مايو 27, 2015 2:36 pm من طرف mona abdou

» أثر الوعي بالعمليات الإبداعية و الإسلوب الإبداعي في كفاءة حل المشكلات:رسالة دكتوراه (للتحميل)
السبت مايو 16, 2015 9:12 pm من طرف عصام عبد الرازق

» طلب بحوث ودراسات عن مناهج وطرق تدريس العلوم
السبت مايو 16, 2015 9:03 pm من طرف عصام عبد الرازق

» د.عبدالمجيد حميد الكبيسي: دليل الآنشطة التدريبية التربوية
الإثنين مايو 11, 2015 2:27 am من طرف د.عبدالمجيد حميد الكبيسي

» ملخصات رسائل ماجستير ودكتوراة في تخصص مناهج وطرق تدريس اللغة الإنجليزية للتحميل
الأحد أبريل 19, 2015 2:11 am من طرف Admin//د.وسام محمد

» برامج تحويل الملفات بي دي اف لاي صيغة اخري وبالعكس PDF2word&html...etc
السبت أبريل 18, 2015 7:13 pm من طرف معتز الليثي

» الأعداد الكاملة لمجلة كلية التربية جامعة الامارات العربية المتحدة منذ الصدور
الإثنين أبريل 13, 2015 9:36 am من طرف Admin//د.وسام محمد

» تخطيط لدرس تاريخ في منهج الدراسات الإجتماعية للصف السادس الإبتدائي بإستخدام 5 من طرق التدريس (تخطيط كامل للدرس)
الأربعاء أبريل 08, 2015 8:30 pm من طرف mallak

مواضيع مماثلة
أفضل 10 أعضاء في هذا المنتدى
zinab
 
Admin//د.وسام محمد
 
abeerkhaled
 
esraa_eman hussein
 
yasmin abd elatif
 
Doaa Elgana
 
أبو بدر
 
MARWA ELBAHI
 
مونى00
 
marwa ali mahdy
 

شاطر | 
 

 Creating Mobile Web Sites with Google App Engine

استعرض الموضوع السابق استعرض الموضوع التالي اذهب الى الأسفل 
كاتب الموضوعرسالة
Admin//د.وسام محمد
المدير العام Administrator
المدير العام Administrator


الابراج : الميزان

عدد المساهمات : 3746
تاريخ الميلاد : 13/10/1981
العمر : 35
نقاط : 6261
تاريخ التسجيل : 04/01/2008
رقم الهاتف الجوال : 0020169785672

بطاقة الشخصية
تربوي:

مُساهمةموضوع: Creating Mobile Web Sites with Google App Engine   الإثنين يناير 03, 2011 10:32 pm

[right] ربي السلام عليكم وبسم ال ربي

Creating Mobile Web Sites with Google App Engine

Posted by ronan 2 years 31 weeks ago

See also...
■Mobile Web App Development with ASP.NET and HAWHAW
■Build a Mobile and Desktop-Friendly Application in Django in 15 Minutes
■Creating mobile web sites using Google App Engine
■MyMobileWeb - An open source platform for developing .mobi-compliant applications
■DeviceAtlas & jQueryMobile
By now most people have heard of Google's App Engine (GAE). In case you haven't, GAE lets you run your own web applications on Google's extensive network of servers meaning that you can scale your application as traffic demands, with no hardware headaches, no machine provisioning, no LAMP stacks, no Apache configurations. So far the buzz has been very positive -- with some notable exceptions (Python only for now, no way to schedule tasks on the server) GAE has been well-received by desktop web developers.

But What About Mobile?
So what about the 1.3 billion mobile web devices? Can GAE be used for that also? The short answer is yes, of course, GAE can be made to emit mobile pages also. But to create a mobile web application that really delivers a good experience to end users you need to build in device detection. Device detection is serves two main purposes in this case:

■To distinguish between desktop browsers and mobile browsers. You will likely want to give a different presentation of your site depending on whether the user is using a mobile or desktop browser
■To fine-tune the presentation of the mobile site so that it works well on the target device.
Diversity of characteristics on PCs is relatively limited: there are about 3 or 4 popular browsers, almost every PC has a keyboard and mouse, and you can assume with a good degree of confidence that you are dealing with a screen resolution of 1024x768, or greater. On mobile by comparison, the matrix of characteristics is wildly varied by comparison: there are countless different browsers, device screen resolutions, aspect ratios, and input devices are very diverse.

To navigate this complex landscape you need a good way to identify the requesting device and determine its capabilities. This article describes how to do this with GAE and dotMobi's DeviceAtlas device database. Why use DeviceAtlas?

■It's accurate and comprehensive - DeviceAtlas incorporates device knowledge from a variety of sources such as WURFL, Volantis, ArgoGroup etc.,
■It's very fast - several thousand recognitions per second on moderate hardware
■It's cheap - free for developers
Note that this is not an article on how to use GAE, rather it is an article on how to add device detection capabilities to a GAE application. I'll demonstrate how to build a mobile and desktop application by building a functional but trivial application that detects device type, and serves up a different experience accordingly. All the application does is show you a Google map of the location of dotMobi HQ in Dublin, sized accordingly, with a click-to-call link if supported (hey, I said it was trivial!).

Getting Started
First things first: use the normal GAE procedure to create your application directory and YAML config file. We'll call this application "contact-dotmobi".

Next, we need to add the module for device detection to the base GAE scaffolding. This article uses the Python API for DeviceAtlas. Using the DeviceAtlas API with GAE is simply a matter of dropping the API and exceptions modules and the JSON device information file into your GAE application directory.

api.py - the main DeviceAtlas module
daExceptions.py - exceptions for above
DeviceAtlas.json - the device data

For simplicity, we'll place these in the root directory of the GAE application.

Finally, the DeviceAtlas API depends on a Python module called SimpleJson to parse our devices files. Since this module isn't included in the standard GAE Python version we need to add this also. The simplest way to do this is to download it from http://www.undefined.org/python/ and drop the SimpleJson module directory into the GAE application directory. At this point the application looks something like this:

api.py
app.yaml
daExceptions.py
DeviceAtlas.json
index.yaml
simplejson


Now for some code. For simplicity, we'll just map one URL to a method in this application and to be tidy we'll add something for the favicon also. This gives the following YAML file:
application: contact-dotmobi
version: 1
runtime: python
api_version: 1

handlers:
- url: /
script: contact-dotmobi.py
- url: /favicon.ico
static_files: favicon.ico
upload: favicon.icoThe First Code
Config done, it's now time to write some proper code, in a file called contact-dotmobi.py. First of all, some standard GAE imports:

import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import templateNow we need to import DeviceAtlas:

import apiAnd read in the device data:


# instantiate API and read in the JSON
TREEFILE = 'DeviceAtlas.json'
da = api.DaApi()
tree = da.getTreeFromFile(TREEFILE)This code instantiates the DeviceAtlas class and loads the data from TREEFILE. This code runs once and makes available the DeviceAtlas API for all subsequent operations. This is important because loading and parsing the JSON is a relatively slow task (typically a couple of seconds), and not something that you want to do for each request to the application. Once loaded however, the Patricia-tree structure of the data allows for lightning-fast lookups with minimal overhead.

Now that we have our device properties tree ready, we can write some code to handle HTTP requests. We start with some standard boiler-plate:

.
.
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/html'
ua = self.request.user_agent
.
.This code simply subclasses the webapp.RequestHandler, sets the response header, and picks up the User-Agent string from the HTTP request for use later -- nothing too exciting here. The UA string is important for us since this is the piece of data that DeviceAtlas uses to identify the requesting device. Now for the interesting bit:

props = da.getPropertiesAsTyped(tree, ua)This queries the DeviceAtlas API by passing it the existing JSON device database tree and the UA string from the requesting device. The getPropertiesAsTyped method returns a strongly-typed Python dictionary containing everything that DeviceAtlas knows about the requesting device. This dictionary of properties allows us to start making presentation choices for our user. The first thing to do is to decide if this device is a mobile device or not:

mobileDevice = False
if props.has_key('mobileDevice'):
if props['mobileDevice']:
mobileDevice = TrueNow that we know if the device is mobile or not, we can decide how big to make our map image:

mapWidth = 512 # default max for Google maps
mapHeight = 512

if mobileDevice:
mapWidth = 128 # default, in case no screen size information available
mapHeight = 128
if props.has_key('displayWidth'): #otherwise base it on width
mapWidth = mapHeight = props['displayWidth'] - 25This code sets a default map size, and reduces it down as appropriate by querying the DeviceAtlas displayWidth property. Since most mobile devices have portrait aspect ratios, we are using the width of the device screen as the contraining factor, and setting the height to the same value to give a square image. Subtracting 25 pixels from the width allows for scrollbars and other intrusions into the view port.

Now we have pretty much everything we need to start rendering the markup so we create a dictionary of values to pass to the template:

template_values = {
'props': props,
'mapWidth': mapWidth,
'mapHeight': mapHeight,
'zoom': zoom,
'ua': ua,
}
The zoom variable here is a tweak to set the Google map zoom level appropriately for the pixel size of the map (the Google static maps API doesn't scale the map as you reduce its pixel size).

Templates
In general, you are better off sending XHTML Mobile Profile or Basic markup to a mobile device. Desktop browser are much less fussy about markup and a richer presentation can / should be used. For this reason it often makes sense to use entirely different templates depending on wether you are serving pages to a mobile or fixed user:

if mobileDevice:
self.response.out.write(template.render('index.xhtml', template_values))
else:
self.response.out.write(template.render('index.html', template_values))That code passes the data to the template and sends the response to the device. The XHTML template (the one for mobile devices) looks like this:




Contact dotMobi

.
.
Phone:
{% if props.uriSchemeTel %} +353 (1) 854 110 {% else %} +353 (1) 854 1100 {% endif %}
.
.
map

.
.
Detected UA string: {{ua}}
DeviceAtlas version: {{apiRevision}}
Vendor: {{props.vendor}}
Model: {{props.model}}There are three interesting things to note in this template:

■We use the uriSchemeTel property from DeviceAtlas to determine if a tel: link for the dotMobi phone number should be displayed. If not, a plain text alternative is used
■The size of the Google maps image is determined by the mapWidth variable passed to the template
■We have some debugging information in the footer of the page. This lists the detected UA string, DeviceAtlas version and vendor/model of the phone
The desktop version of the template (index.html) is simpler, since there are fewer choices to make.


Wrapping it Up
Now all there is left to do is wrap this up with code to map requests to our class and tell Google to run it:

def main():
application = webapp.WSGIApplication( [('/', MainPage)], debug=True)
wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
main()The entire application now looks like this:

api.py
app.yaml
daExceptions.py
DeviceAtlas.json
favicon.ico
contact-dotmobi.py
index.html
index.xhtml
index.yaml
simplejson

So there you have it! A desktop and mobile aware application that delivers a tailored experience to both classes of browser, and scores a perfect 5 on ready.mobi! Once uploaded to Google, this application takes about a second or two to spin up and then serves requests very rapidly indeed. You can try it live at this address: http://contact-dotmobi.appspot.com

Another Example
For people experimenting with DeviceAtlas, we've also put together another sample application that lists all known properties for the requesting device.


The code for this application is even simpler:

.
.
def get(self):
self.response.headers['Content-Type'] = 'text/html'
ua = self.request.user_agent
apiRevision = da.getApiRevision()

props = da.getPropertiesAsTyped(tree, self.request.user_agent)

if props.has_key('vendor') and props.has_key('model'):
imgSrc = 'http://deviceatlas.com/sites/deviceatlas.com/themes/eris/img/device_images//.jpg' % (props['vendor'].lower(), props['model'].lower())
else:
imgSrc = False


template_values = {
'apiRevision': apiRevision,
'props': props,
'imgSrc': imgSrc,
'ua': ua,
't': True,
'f': False,
}
.
.This checks to see if we have a vendor and model for the phone, and if so, constucts a link to the corresponding device image on deviceatlas.com. The corresponding template looks like this:

.
.
{% if imgSrc %}
Device Image
{% else %}

No image available


{% endif %}
.
.


Available Properties


{% for prop in props.items %}




{% endfor %}

{{ prop.0 }}

{% ifequal prop.1 t %}
{{ prop.1 }}
{% else %}
{% ifequal prop.1 f %}
{{ prop.1 }}
{% else %}
prop.1
{% endifequal %}
{% endifequal %}
.
.This template simply displays a device image if available, and lists the known device properties in a simple table. You can try this application live on http://deviceatlas.appspot.com.

The source for both of these applications is included as an attachment to this article. The files are listed as .txts - you will need to rename them to .zips after you download. If you want to run this application yourself you'll need a valid GAE invite and a Google map key. We can't help you with that, sorry.

What's Next
The Python version of the DeviceAtlas API will be made available soon - watch this space. In the meantime, feel free to try out the Java/.net/PHP versions available free at deviceatlas.com

_________________

مع خالص شكري وتحياتي
د.وسام محمد إبراهيم علي
مدير"وسام المنتدي التربوي"
http://wessam.allgoo.us/
مدرس المناهج وتقنيات تعليم التاريخ

كلية التربية-جامعة الإسكندرية-جمهورية مصر العربية
mobile:00201069785672
e-mails:dr_wessam2006@hotmail.com
wessam_mohamed_4ever@yahoo.com
With my sincere thanks and greetings
Dr.Wessam  Mohammed Ibrahim Ali
Lecturer and faculty member
PHD Doctor in curricula and Technology of history Education
College of Education - University of Alexandria - Arab Republic of Egypt



الرجوع الى أعلى الصفحة اذهب الى الأسفل
http://wessam.allgoo.us
 
Creating Mobile Web Sites with Google App Engine
استعرض الموضوع السابق استعرض الموضوع التالي الرجوع الى أعلى الصفحة 
صفحة 1 من اصل 1
 مواضيع مماثلة
-
» شرح طريقة حذف الكلمات المخزنة بصفحة البحث Google وغيرها
» برنامج google pub لاشهار المنتديات
» جوجل (Google) للأراضي الفلسطينية
» محركات الديزل Diesel ENGINE
» الآن دورات في (Mobile Networking and Services) وتتضمن (GSM, GPRS,EDGE and UMTS)

صلاحيات هذا المنتدى:لاتستطيع الرد على المواضيع في هذا المنتدى
Wessam The Educational Forum وسام المنتدي التربوي :: تكنولوجيا التعليمInstructional Technology-
انتقل الى: