mobileesp_converted 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/README.md +18 -0
- data/Rakefile +16 -0
- data/convert_to_ruby.vim +236 -0
- data/java_source/UAgentInfo.java +1026 -0
- data/lib/mobileesp_converted/u_agent_info.rb +1086 -0
- data/lib/mobileesp_converted/version.rb +3 -0
- data/lib/mobileesp_converted.rb +5 -0
- data/mobileesp_converted.gemspec +24 -0
- data/spec/mobileesp_converted/u_agent_info_spec.rb +111 -0
- data/spec/spec_helper.rb +4 -0
- metadata +86 -0
@@ -0,0 +1,1086 @@
|
|
1
|
+
# This file has been automatically converted to Ruby from Java source code.
|
2
|
+
#
|
3
|
+
#
|
4
|
+
#
|
5
|
+
=begin
|
6
|
+
*******************************************
|
7
|
+
# Copyright 2010-2012, Anthony Hand
|
8
|
+
#
|
9
|
+
# File version date: January 21, 2012
|
10
|
+
# Update:
|
11
|
+
# - Moved Windows Phone 7 to the iPhone Tier. WP7.5's IE 9-based browser is good enough now.
|
12
|
+
# - Added a new variable for 2 versions of the new BlackBerry Bold Touch (9900 and 9930): deviceBBBoldTouch.
|
13
|
+
# - Updated DetectBlackBerryTouch() to support the 2 versions of the new BlackBerry Bold Touch (9900 and 9930).
|
14
|
+
# - Updated DetectKindle() to focus on eInk devices only. The Kindle Fire should be detected as a regular Android device.
|
15
|
+
#
|
16
|
+
# File version date: August 22, 2011
|
17
|
+
# Update:
|
18
|
+
# - Updated DetectAndroidTablet() to fix a bug I introduced in the last fix!
|
19
|
+
#
|
20
|
+
# File version date: August 16, 2011
|
21
|
+
# Update:
|
22
|
+
# - Updated DetectAndroidTablet() to exclude Opera Mini, which was falsely reporting as running on a tablet device when on a phone.
|
23
|
+
#
|
24
|
+
# File version date: August 7, 2011
|
25
|
+
# Update:
|
26
|
+
# - The Opera for Android browser doesn't follow Google's recommended useragent string guidelines, so some fixes were needed.
|
27
|
+
# - Updated DetectAndroidPhone() and DetectAndroidTablet() to properly detect devices running Opera Mobile.
|
28
|
+
# - Created 2 new methods: DetectOperaAndroidPhone() and DetectOperaAndroidTablet().
|
29
|
+
# - Updated DetectTierIphone(). Removed the call to DetectMaemoTablet(), an obsolete mobile OS.
|
30
|
+
#
|
31
|
+
#
|
32
|
+
# LICENSE INFORMATION
|
33
|
+
# Licensed under the Apache License, Version 2.0 (the "License")
|
34
|
+
# you may not use this file except in compliance with the License.
|
35
|
+
# You may obtain a copy of the License at
|
36
|
+
# http:
|
37
|
+
# Unless required by applicable law or agreed to in writing,
|
38
|
+
# software distributed under the License is distributed on an
|
39
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
40
|
+
# either express or implied. See the License for the specific
|
41
|
+
# language governing permissions and limitations under the License.
|
42
|
+
#
|
43
|
+
#
|
44
|
+
# ABOUT THIS PROJECT
|
45
|
+
# Project Owner: Anthony Hand
|
46
|
+
# Email: anthony.hand@gmail.com
|
47
|
+
# Web Site: http:
|
48
|
+
# Source Files: http:
|
49
|
+
#
|
50
|
+
# Versions of this code are available for:
|
51
|
+
# PHP, JavaScript, Java, ASP.NET (C#), and Ruby
|
52
|
+
#
|
53
|
+
# *******************************************
|
54
|
+
|
55
|
+
=end
|
56
|
+
|
57
|
+
|
58
|
+
=begin
|
59
|
+
*
|
60
|
+
* The DetectSmartPhone class encapsulates information about
|
61
|
+
* a browser's connection to your web site.
|
62
|
+
* You can use it to find out whether the browser asking for
|
63
|
+
* your site's content is probably running on a mobile device.
|
64
|
+
* The methods were written so you can be as granular as you want.
|
65
|
+
* For example, enquiring whether it's as specific as an iPod Touch or
|
66
|
+
* as general as a smartphone class device.
|
67
|
+
* The object's methods return true, or false.
|
68
|
+
|
69
|
+
=end
|
70
|
+
module MobileESPConverted
|
71
|
+
class UAgentInfo
|
72
|
+
|
73
|
+
|
74
|
+
attr_reader :user_agent
|
75
|
+
attr_reader :http_accept
|
76
|
+
|
77
|
+
|
78
|
+
attr_reader :is_iphone
|
79
|
+
attr_reader :is_android_phone
|
80
|
+
attr_reader :is_tier_tablet
|
81
|
+
attr_reader :is_tier_iphone
|
82
|
+
attr_reader :is_tier_rich_css
|
83
|
+
attr_reader :is_tier_generic_mobile
|
84
|
+
|
85
|
+
|
86
|
+
ENGINE_WEB_KIT = "webkit"
|
87
|
+
|
88
|
+
DEVICE_IPHONE = "iphone"
|
89
|
+
DEVICE_IPOD = "ipod"
|
90
|
+
DEVICE_IPAD = "ipad"
|
91
|
+
DEVICE_MAC_PPC = "macintosh"
|
92
|
+
|
93
|
+
DEVICE_ANDROID = "android"
|
94
|
+
DEVICE_GOOGLE_T_V = "googletv"
|
95
|
+
DEVICE_XOOM = "xoom"
|
96
|
+
DEVICE_HTC_FLYER = "htc_flyer"
|
97
|
+
|
98
|
+
DEVICE_SYMBIAN = "symbian"
|
99
|
+
DEVICE_S60 = "series60"
|
100
|
+
DEVICE_S70 = "series70"
|
101
|
+
DEVICE_S80 = "series80"
|
102
|
+
DEVICE_S90 = "series90"
|
103
|
+
|
104
|
+
DEVICE_WIN_PHONE7 = "windows phone os 7"
|
105
|
+
DEVICE_WIN_MOB = "windows ce"
|
106
|
+
DEVICE_WINDOWS = "windows"
|
107
|
+
DEVICE_IE_MOB = "iemobile"
|
108
|
+
DEVICE_PPC = "ppc"
|
109
|
+
ENGINE_PIE = "wm5 pie"
|
110
|
+
|
111
|
+
DEVICE_B_B = "blackberry"
|
112
|
+
VND_R_I_M = "vnd.rim"
|
113
|
+
DEVICE_B_B_STORM = "blackberry95"
|
114
|
+
DEVICE_B_B_BOLD = "blackberry97"
|
115
|
+
DEVICE_B_B_BOLD_TOUCH = "blackberry 99"
|
116
|
+
DEVICE_B_B_TOUR = "blackberry96"
|
117
|
+
DEVICE_B_B_CURVE = "blackberry89"
|
118
|
+
DEVICE_B_B_TORCH = "blackberry 98"
|
119
|
+
DEVICE_B_B_PLAYBOOK = "playbook"
|
120
|
+
|
121
|
+
DEVICE_PALM = "palm"
|
122
|
+
DEVICE_WEB_O_S = "webos"
|
123
|
+
DEVICE_WEB_O_SHP = "hpwos"
|
124
|
+
|
125
|
+
ENGINE_BLAZER = "blazer"
|
126
|
+
ENGINE_XIINO = "xiino"
|
127
|
+
|
128
|
+
DEVICE_KINDLE = "kindle"
|
129
|
+
|
130
|
+
DEVICE_NUVIFONE = "nuvifone"
|
131
|
+
|
132
|
+
|
133
|
+
VNDWAP = "vnd.wap"
|
134
|
+
WML = "wml"
|
135
|
+
|
136
|
+
|
137
|
+
DEVICE_TABLET = "tablet"
|
138
|
+
DEVICE_BREW = "brew"
|
139
|
+
DEVICE_DANGER = "danger"
|
140
|
+
DEVICE_HIPTOP = "hiptop"
|
141
|
+
DEVICE_PLAYSTATION = "playstation"
|
142
|
+
DEVICE_NINTENDO_DS = "nitro"
|
143
|
+
DEVICE_NINTENDO = "nintendo"
|
144
|
+
DEVICE_WII = "wii"
|
145
|
+
DEVICE_XBOX = "xbox"
|
146
|
+
DEVICE_ARCHOS = "archos"
|
147
|
+
|
148
|
+
ENGINE_OPERA = "opera"
|
149
|
+
ENGINE_NETFRONT = "netfront"
|
150
|
+
ENGINE_UP_BROWSER = "up.browser"
|
151
|
+
ENGINE_OPEN_WEB = "openweb"
|
152
|
+
DEVICE_MIDP = "midp"
|
153
|
+
UPLINK = "up.link"
|
154
|
+
ENGINE_TELECA_Q = "teleca q"
|
155
|
+
DEVICE_PDA = "pda"
|
156
|
+
MINI = "mini"
|
157
|
+
MOBILE = "mobile"
|
158
|
+
MOBI = "mobi"
|
159
|
+
|
160
|
+
|
161
|
+
MAEMO = "maemo"
|
162
|
+
LINUX = "linux"
|
163
|
+
QTEMBEDDED = "qt embedded"
|
164
|
+
MYLOCOM2 = "com2"
|
165
|
+
|
166
|
+
|
167
|
+
MANU_SONY_ERICSSON = "sonyericsson"
|
168
|
+
MANUERICSSON = "ericsson"
|
169
|
+
MANU_SAMSUNG1 = "sec-sgh"
|
170
|
+
MANU_SONY = "sony"
|
171
|
+
MANU_HTC = "htc"
|
172
|
+
|
173
|
+
|
174
|
+
SVC_DOCOMO = "docomo"
|
175
|
+
SVC_KDDI = "kddi"
|
176
|
+
SVC_VODAFONE = "vodafone"
|
177
|
+
|
178
|
+
|
179
|
+
DIS_UPDATE = "update"
|
180
|
+
|
181
|
+
|
182
|
+
=begin
|
183
|
+
*
|
184
|
+
* Initialize the user_agent and http_accept variables
|
185
|
+
*
|
186
|
+
* @param user_agent the User-Agent header
|
187
|
+
* @param http_accept the Accept header
|
188
|
+
|
189
|
+
=end
|
190
|
+
def initialize(user_agent, http_accept)
|
191
|
+
if (user_agent != nil)
|
192
|
+
@user_agent = user_agent.downcase
|
193
|
+
end
|
194
|
+
if (http_accept != nil)
|
195
|
+
@http_accept = http_accept.downcase
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
init_device_scan()
|
200
|
+
end
|
201
|
+
|
202
|
+
=begin
|
203
|
+
*
|
204
|
+
* Return the lower case HTTP_USER_AGENT
|
205
|
+
* @return user_agent
|
206
|
+
|
207
|
+
=end
|
208
|
+
def get_user_agent()
|
209
|
+
return user_agent
|
210
|
+
end
|
211
|
+
|
212
|
+
=begin
|
213
|
+
*
|
214
|
+
* Return the lower case HTTP_ACCEPT
|
215
|
+
* @return http_accept
|
216
|
+
|
217
|
+
=end
|
218
|
+
def get_http_accept()
|
219
|
+
return http_accept
|
220
|
+
end
|
221
|
+
|
222
|
+
=begin
|
223
|
+
*
|
224
|
+
* Return whether the device is an Iphone or iPod Touch
|
225
|
+
* @return is_iphone
|
226
|
+
|
227
|
+
=end
|
228
|
+
def get_is_iphone()
|
229
|
+
return is_iphone
|
230
|
+
end
|
231
|
+
|
232
|
+
=begin
|
233
|
+
*
|
234
|
+
* Return whether the device is in the Tablet Tier.
|
235
|
+
* @return is_tier_tablet
|
236
|
+
|
237
|
+
=end
|
238
|
+
def get_is_tier_tablet()
|
239
|
+
return is_tier_tablet
|
240
|
+
end
|
241
|
+
|
242
|
+
=begin
|
243
|
+
*
|
244
|
+
* Return whether the device is in the Iphone Tier.
|
245
|
+
* @return is_tier_iphone
|
246
|
+
|
247
|
+
=end
|
248
|
+
def get_is_tier_iphone()
|
249
|
+
return is_tier_iphone
|
250
|
+
end
|
251
|
+
|
252
|
+
=begin
|
253
|
+
*
|
254
|
+
* Return whether the device is in the 'Rich CSS' tier of mobile devices.
|
255
|
+
* @return is_tier_rich_css
|
256
|
+
|
257
|
+
=end
|
258
|
+
def get_is_tier_rich_css()
|
259
|
+
return is_tier_rich_css
|
260
|
+
end
|
261
|
+
|
262
|
+
=begin
|
263
|
+
*
|
264
|
+
* Return whether the device is a generic, less-capable mobile device.
|
265
|
+
* @return is_tier_generic_mobile
|
266
|
+
|
267
|
+
=end
|
268
|
+
def get_is_tier_generic_mobile()
|
269
|
+
return is_tier_generic_mobile
|
270
|
+
end
|
271
|
+
|
272
|
+
=begin
|
273
|
+
*
|
274
|
+
* Initialize Key Stored Values.
|
275
|
+
|
276
|
+
=end
|
277
|
+
def init_device_scan()
|
278
|
+
@is_iphone = detect_iphone_or_ipod()
|
279
|
+
@is_android_phone = detect_android_phone()
|
280
|
+
@is_tier_tablet = detect_tier_tablet()
|
281
|
+
@is_tier_iphone = detect_tier_iphone()
|
282
|
+
@is_tier_rich_css = detect_tier_rich_css()
|
283
|
+
@is_tier_generic_mobile = detect_tier_other_phones()
|
284
|
+
end
|
285
|
+
|
286
|
+
=begin
|
287
|
+
*
|
288
|
+
* Detects if the current device is an iPhone.
|
289
|
+
* @return detection of an iPhone
|
290
|
+
|
291
|
+
=end
|
292
|
+
def detect_iphone()
|
293
|
+
|
294
|
+
if (user_agent.include?(DEVICE_IPHONE) &&
|
295
|
+
!detect_ipad() &&
|
296
|
+
!detect_ipod())
|
297
|
+
return true
|
298
|
+
end
|
299
|
+
return false
|
300
|
+
end
|
301
|
+
|
302
|
+
=begin
|
303
|
+
*
|
304
|
+
* Detects if the current device is an iPod Touch.
|
305
|
+
* @return detection of an iPod Touch
|
306
|
+
|
307
|
+
=end
|
308
|
+
def detect_ipod()
|
309
|
+
if (user_agent.include?(DEVICE_IPOD))
|
310
|
+
return true
|
311
|
+
end
|
312
|
+
return false
|
313
|
+
end
|
314
|
+
|
315
|
+
=begin
|
316
|
+
*
|
317
|
+
* Detects if the current device is an iPad tablet.
|
318
|
+
* @return detection of an iPad
|
319
|
+
|
320
|
+
=end
|
321
|
+
def detect_ipad()
|
322
|
+
if (user_agent.include?(DEVICE_IPAD) && detect_webkit())
|
323
|
+
return true
|
324
|
+
end
|
325
|
+
return false
|
326
|
+
end
|
327
|
+
|
328
|
+
=begin
|
329
|
+
*
|
330
|
+
* Detects if the current device is an iPhone or iPod Touch.
|
331
|
+
* @return detection of an iPhone or iPod Touch
|
332
|
+
|
333
|
+
=end
|
334
|
+
def detect_iphone_or_ipod()
|
335
|
+
|
336
|
+
if (detect_iphone() || user_agent.include?(DEVICE_IPOD))
|
337
|
+
return true
|
338
|
+
end
|
339
|
+
return false
|
340
|
+
end
|
341
|
+
|
342
|
+
=begin
|
343
|
+
*
|
344
|
+
* Detects *any* iOS device: iPhone, iPod Touch, iPad.
|
345
|
+
* @return detection of an Apple iOS device
|
346
|
+
|
347
|
+
=end
|
348
|
+
def detect_ios()
|
349
|
+
if (detect_iphone_or_ipod() || detect_ipad())
|
350
|
+
return true
|
351
|
+
end
|
352
|
+
return false
|
353
|
+
end
|
354
|
+
|
355
|
+
|
356
|
+
=begin
|
357
|
+
*
|
358
|
+
* Detects *any* Android OS-based device: phone, tablet, and multi-media player.
|
359
|
+
* Also detects Google TV.
|
360
|
+
* @return detection of an Android device
|
361
|
+
|
362
|
+
=end
|
363
|
+
def detect_android()
|
364
|
+
if ((user_agent.include?(DEVICE_ANDROID)) ||
|
365
|
+
detect_google_t_v())
|
366
|
+
return true
|
367
|
+
end
|
368
|
+
|
369
|
+
if (user_agent.include?(DEVICE_HTC_FLYER))
|
370
|
+
return true
|
371
|
+
end
|
372
|
+
return false
|
373
|
+
end
|
374
|
+
|
375
|
+
=begin
|
376
|
+
*
|
377
|
+
* Detects if the current device is a (small-ish) Android OS-based device
|
378
|
+
* used for calling and/or multi-media (like a Samsung Galaxy Player).
|
379
|
+
* Google says these devices will have 'Android' AND 'mobile' in user agent.
|
380
|
+
* Ignores tablets (Honeycomb and later).
|
381
|
+
* @return detection of an Android phone
|
382
|
+
|
383
|
+
=end
|
384
|
+
def detect_android_phone()
|
385
|
+
if (detect_android() && (user_agent.include?(MOBILE)))
|
386
|
+
return true
|
387
|
+
end
|
388
|
+
|
389
|
+
if (detect_opera_android_phone())
|
390
|
+
return true
|
391
|
+
end
|
392
|
+
|
393
|
+
if (user_agent.include?(DEVICE_HTC_FLYER))
|
394
|
+
return true
|
395
|
+
end
|
396
|
+
return false
|
397
|
+
end
|
398
|
+
|
399
|
+
=begin
|
400
|
+
*
|
401
|
+
* Detects if the current device is a (self-reported) Android tablet.
|
402
|
+
* Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
|
403
|
+
* @return detection of an Android tablet
|
404
|
+
|
405
|
+
=end
|
406
|
+
def detect_android_tablet()
|
407
|
+
|
408
|
+
if (!detect_android())
|
409
|
+
return false
|
410
|
+
end
|
411
|
+
|
412
|
+
|
413
|
+
if (detect_opera_mobile())
|
414
|
+
return false
|
415
|
+
end
|
416
|
+
|
417
|
+
if (user_agent.include?(DEVICE_HTC_FLYER))
|
418
|
+
return false
|
419
|
+
end
|
420
|
+
|
421
|
+
|
422
|
+
if ((user_agent.include?(MOBILE)))
|
423
|
+
return false
|
424
|
+
else
|
425
|
+
return true
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
=begin
|
430
|
+
*
|
431
|
+
* Detects if the current device is an Android OS-based device and
|
432
|
+
* the browser is based on WebKit.
|
433
|
+
* @return detection of an Android WebKit browser
|
434
|
+
|
435
|
+
=end
|
436
|
+
def detect_android_web_kit()
|
437
|
+
if (detect_android() && detect_webkit())
|
438
|
+
return true
|
439
|
+
end
|
440
|
+
return false
|
441
|
+
end
|
442
|
+
|
443
|
+
=begin
|
444
|
+
*
|
445
|
+
* Detects if the current device is a GoogleTV.
|
446
|
+
* @return detection of GoogleTV
|
447
|
+
|
448
|
+
=end
|
449
|
+
def detect_google_t_v()
|
450
|
+
if (user_agent.include?(DEVICE_GOOGLE_T_V))
|
451
|
+
return true
|
452
|
+
end
|
453
|
+
return false
|
454
|
+
end
|
455
|
+
|
456
|
+
=begin
|
457
|
+
*
|
458
|
+
* Detects if the current browser is based on WebKit.
|
459
|
+
* @return detection of a WebKit browser
|
460
|
+
|
461
|
+
=end
|
462
|
+
def detect_webkit()
|
463
|
+
if (user_agent.include?(ENGINE_WEB_KIT))
|
464
|
+
return true
|
465
|
+
end
|
466
|
+
return false
|
467
|
+
end
|
468
|
+
|
469
|
+
=begin
|
470
|
+
*
|
471
|
+
* Detects if the current browser is the Symbian S60 Open Source Browser.
|
472
|
+
* @return detection of Symbian S60 Browser
|
473
|
+
|
474
|
+
=end
|
475
|
+
def detect_s60_oss_browser()
|
476
|
+
|
477
|
+
if (detect_webkit() && (user_agent.include?(DEVICE_SYMBIAN) || user_agent.include?(DEVICE_S60)))
|
478
|
+
return true
|
479
|
+
end
|
480
|
+
return false
|
481
|
+
end
|
482
|
+
|
483
|
+
=begin
|
484
|
+
*
|
485
|
+
*
|
486
|
+
* Detects if the current device is any Symbian OS-based device,
|
487
|
+
* including older S60, Series 70, Series 80, Series 90, and UIQ,
|
488
|
+
* or other browsers running on these devices.
|
489
|
+
* @return detection of SymbianOS
|
490
|
+
|
491
|
+
=end
|
492
|
+
def detect_symbian_o_s()
|
493
|
+
if (user_agent.include?(DEVICE_SYMBIAN) || user_agent.include?(DEVICE_S60) || user_agent.include?(DEVICE_S70) || user_agent.include?(DEVICE_S80) || user_agent.include?(DEVICE_S90))
|
494
|
+
return true
|
495
|
+
end
|
496
|
+
return false
|
497
|
+
end
|
498
|
+
|
499
|
+
=begin
|
500
|
+
*
|
501
|
+
* Detects if the current browser is a
|
502
|
+
* Windows Phone 7 device.
|
503
|
+
* @return detection of Windows Phone 7
|
504
|
+
|
505
|
+
=end
|
506
|
+
def detect_windows_phone7()
|
507
|
+
if (user_agent.include?(DEVICE_WIN_PHONE7))
|
508
|
+
return true
|
509
|
+
end
|
510
|
+
return false
|
511
|
+
end
|
512
|
+
|
513
|
+
=begin
|
514
|
+
*
|
515
|
+
* Detects if the current browser is a Windows Mobile device.
|
516
|
+
* Excludes Windows Phone 7 devices.
|
517
|
+
* Focuses on Windows Mobile 6.xx and earlier.
|
518
|
+
* @return detection of Windows Mobile
|
519
|
+
|
520
|
+
=end
|
521
|
+
def detect_windows_mobile()
|
522
|
+
|
523
|
+
if (detect_windows_phone7())
|
524
|
+
return false
|
525
|
+
end
|
526
|
+
|
527
|
+
|
528
|
+
|
529
|
+
if (user_agent.include?(DEVICE_WIN_MOB) || user_agent.include?(DEVICE_WIN_MOB) || user_agent.include?(DEVICE_IE_MOB) || user_agent.include?(ENGINE_PIE) || (user_agent.include?(MANU_HTC) && user_agent.include?(DEVICE_WINDOWS)) || (detect_wap_wml() && user_agent.include?(DEVICE_WINDOWS)))
|
530
|
+
return true
|
531
|
+
end
|
532
|
+
|
533
|
+
|
534
|
+
if (user_agent.include?(DEVICE_PPC) &&
|
535
|
+
!(user_agent.include?(DEVICE_MAC_PPC)))
|
536
|
+
return true
|
537
|
+
end
|
538
|
+
|
539
|
+
return false
|
540
|
+
end
|
541
|
+
|
542
|
+
=begin
|
543
|
+
*
|
544
|
+
* Detects if the current browser is any BlackBerry.
|
545
|
+
* Includes the PlayBook.
|
546
|
+
* @return detection of Blackberry
|
547
|
+
|
548
|
+
=end
|
549
|
+
def detect_black_berry()
|
550
|
+
if (user_agent.include?(DEVICE_B_B) ||
|
551
|
+
http_accept.include?(VND_R_I_M))
|
552
|
+
return true
|
553
|
+
end
|
554
|
+
return false
|
555
|
+
end
|
556
|
+
|
557
|
+
=begin
|
558
|
+
*
|
559
|
+
* Detects if the current browser is on a BlackBerry tablet device.
|
560
|
+
* Example: PlayBook
|
561
|
+
* @return detection of a Blackberry Tablet
|
562
|
+
|
563
|
+
=end
|
564
|
+
def detect_black_berry_tablet()
|
565
|
+
if (user_agent.include?(DEVICE_B_B_PLAYBOOK))
|
566
|
+
return true
|
567
|
+
end
|
568
|
+
return false
|
569
|
+
end
|
570
|
+
|
571
|
+
=begin
|
572
|
+
*
|
573
|
+
* Detects if the current browser is a BlackBerry device AND uses a
|
574
|
+
* WebKit-based browser. These are signatures for the new BlackBerry OS 6.
|
575
|
+
* Examples: Torch. Includes the Playbook.
|
576
|
+
* @return detection of a Blackberry device with WebKit browser
|
577
|
+
|
578
|
+
=end
|
579
|
+
def detect_black_berry_web_kit()
|
580
|
+
if (detect_black_berry() &&
|
581
|
+
user_agent.include?(ENGINE_WEB_KIT))
|
582
|
+
return true
|
583
|
+
end
|
584
|
+
return false
|
585
|
+
end
|
586
|
+
|
587
|
+
=begin
|
588
|
+
*
|
589
|
+
* Detects if the current browser is a BlackBerry Touch
|
590
|
+
* device, such as the Storm, Torch, and Bold Touch. Excludes the Playbook.
|
591
|
+
* @return detection of a Blackberry touchscreen device
|
592
|
+
|
593
|
+
=end
|
594
|
+
def detect_black_berry_touch()
|
595
|
+
if (detect_black_berry() &&
|
596
|
+
(user_agent.include?(DEVICE_B_B_STORM) ||
|
597
|
+
user_agent.include?(DEVICE_B_B_TORCH) ||
|
598
|
+
user_agent.include?(DEVICE_B_B_BOLD_TOUCH)))
|
599
|
+
return true
|
600
|
+
end
|
601
|
+
return false
|
602
|
+
end
|
603
|
+
|
604
|
+
=begin
|
605
|
+
*
|
606
|
+
* Detects if the current browser is a BlackBerry device AND
|
607
|
+
* has a more capable recent browser. Excludes the Playbook.
|
608
|
+
* Examples, Storm, Bold, Tour, Curve2
|
609
|
+
* Excludes the new BlackBerry OS 6 and 7 browser!!
|
610
|
+
* @return detection of a Blackberry device with a better browser
|
611
|
+
|
612
|
+
=end
|
613
|
+
def detect_black_berry_high()
|
614
|
+
|
615
|
+
if (detect_black_berry_web_kit())
|
616
|
+
return false
|
617
|
+
end
|
618
|
+
if (detect_black_berry())
|
619
|
+
if (detect_black_berry_touch() || user_agent.include?(DEVICE_B_B_BOLD) || user_agent.include?(DEVICE_B_B_TOUR) || user_agent.include?(DEVICE_B_B_CURVE))
|
620
|
+
return true
|
621
|
+
else
|
622
|
+
return false
|
623
|
+
end
|
624
|
+
else
|
625
|
+
return false
|
626
|
+
end
|
627
|
+
end
|
628
|
+
|
629
|
+
=begin
|
630
|
+
*
|
631
|
+
* Detects if the current browser is a BlackBerry device AND
|
632
|
+
* has an older, less capable browser.
|
633
|
+
* Examples: Pearl, 8800, Curve1
|
634
|
+
* @return detection of a Blackberry device with a poorer browser
|
635
|
+
|
636
|
+
=end
|
637
|
+
def detect_black_berry_low()
|
638
|
+
if (detect_black_berry())
|
639
|
+
|
640
|
+
if (detect_black_berry_high() || detect_black_berry_web_kit())
|
641
|
+
return false
|
642
|
+
else
|
643
|
+
return true
|
644
|
+
end
|
645
|
+
else
|
646
|
+
return false
|
647
|
+
end
|
648
|
+
end
|
649
|
+
|
650
|
+
=begin
|
651
|
+
*
|
652
|
+
* Detects if the current browser is on a PalmOS device.
|
653
|
+
* @return detection of a PalmOS device
|
654
|
+
|
655
|
+
=end
|
656
|
+
def detect_palm_o_s()
|
657
|
+
|
658
|
+
if (user_agent.include?(DEVICE_PALM) || user_agent.include?(ENGINE_BLAZER) || user_agent.include?(ENGINE_XIINO))
|
659
|
+
|
660
|
+
if (detect_palm_web_o_s())
|
661
|
+
return false
|
662
|
+
else
|
663
|
+
return true
|
664
|
+
end
|
665
|
+
end
|
666
|
+
return false
|
667
|
+
end
|
668
|
+
|
669
|
+
=begin
|
670
|
+
*
|
671
|
+
* Detects if the current browser is on a Palm device
|
672
|
+
* running the new WebOS.
|
673
|
+
* @return detection of a Palm WebOS device
|
674
|
+
|
675
|
+
=end
|
676
|
+
def detect_palm_web_o_s()
|
677
|
+
if (user_agent.include?(DEVICE_WEB_O_S))
|
678
|
+
return true
|
679
|
+
end
|
680
|
+
return false
|
681
|
+
end
|
682
|
+
|
683
|
+
=begin
|
684
|
+
*
|
685
|
+
* Detects if the current browser is on an HP tablet running WebOS.
|
686
|
+
* @return detection of an HP WebOS tablet
|
687
|
+
|
688
|
+
=end
|
689
|
+
def detect_web_o_s_tablet()
|
690
|
+
if (user_agent.include?(DEVICE_WEB_O_SHP) &&
|
691
|
+
user_agent.include?(DEVICE_TABLET))
|
692
|
+
return true
|
693
|
+
end
|
694
|
+
return false
|
695
|
+
end
|
696
|
+
|
697
|
+
=begin
|
698
|
+
*
|
699
|
+
* Detects if the current browser is a
|
700
|
+
* Garmin Nuvifone.
|
701
|
+
* @return detection of a Garmin Nuvifone
|
702
|
+
|
703
|
+
=end
|
704
|
+
def detect_garmin_nuvifone()
|
705
|
+
if (user_agent.include?(DEVICE_NUVIFONE))
|
706
|
+
return true
|
707
|
+
end
|
708
|
+
return false
|
709
|
+
end
|
710
|
+
|
711
|
+
=begin
|
712
|
+
*
|
713
|
+
* Check to see whether the device is any device
|
714
|
+
* in the 'smartphone' category.
|
715
|
+
* @return detection of a general smartphone device
|
716
|
+
|
717
|
+
=end
|
718
|
+
def detect_smartphone()
|
719
|
+
return (is_iphone || is_android_phone || is_tier_iphone || detect_s60_oss_browser() || detect_symbian_o_s() || detect_windows_mobile() || detect_windows_phone7() || detect_black_berry() || detect_palm_web_o_s() || detect_palm_o_s() || detect_garmin_nuvifone())
|
720
|
+
end
|
721
|
+
|
722
|
+
=begin
|
723
|
+
*
|
724
|
+
* Detects whether the device is a Brew-powered device.
|
725
|
+
* @return detection of a Brew device
|
726
|
+
|
727
|
+
=end
|
728
|
+
def detect_brew_device()
|
729
|
+
if (user_agent.include?(DEVICE_BREW))
|
730
|
+
return true
|
731
|
+
end
|
732
|
+
return false
|
733
|
+
end
|
734
|
+
|
735
|
+
=begin
|
736
|
+
*
|
737
|
+
* Detects the Danger Hiptop device.
|
738
|
+
* @return detection of a Danger Hiptop
|
739
|
+
|
740
|
+
=end
|
741
|
+
def detect_danger_hiptop()
|
742
|
+
if (user_agent.include?(DEVICE_DANGER) || user_agent.include?(DEVICE_HIPTOP))
|
743
|
+
return true
|
744
|
+
end
|
745
|
+
return false
|
746
|
+
end
|
747
|
+
|
748
|
+
=begin
|
749
|
+
*
|
750
|
+
* Detects Opera Mobile or Opera Mini.
|
751
|
+
* @return detection of an Opera browser for a mobile device
|
752
|
+
|
753
|
+
=end
|
754
|
+
def detect_opera_mobile()
|
755
|
+
if (user_agent.include?(ENGINE_OPERA) && (user_agent.include?(MINI) || user_agent.include?(MOBI)))
|
756
|
+
return true
|
757
|
+
end
|
758
|
+
return false
|
759
|
+
end
|
760
|
+
|
761
|
+
=begin
|
762
|
+
*
|
763
|
+
* Detects Opera Mobile on an Android phone.
|
764
|
+
* @return detection of an Opera browser on an Android phone
|
765
|
+
|
766
|
+
=end
|
767
|
+
def detect_opera_android_phone()
|
768
|
+
if (user_agent.include?(ENGINE_OPERA) && (user_agent.include?(DEVICE_ANDROID) && user_agent.include?(MOBI)))
|
769
|
+
return true
|
770
|
+
end
|
771
|
+
return false
|
772
|
+
end
|
773
|
+
|
774
|
+
=begin
|
775
|
+
*
|
776
|
+
* Detects Opera Mobile on an Android tablet.
|
777
|
+
* @return detection of an Opera browser on an Android tablet
|
778
|
+
|
779
|
+
=end
|
780
|
+
def detect_opera_android_tablet()
|
781
|
+
if (user_agent.include?(ENGINE_OPERA) && (user_agent.include?(DEVICE_ANDROID) && user_agent.include?(DEVICE_TABLET)))
|
782
|
+
return true
|
783
|
+
end
|
784
|
+
return false
|
785
|
+
end
|
786
|
+
|
787
|
+
=begin
|
788
|
+
*
|
789
|
+
* Detects whether the device supports WAP or WML.
|
790
|
+
* @return detection of a WAP- or WML-capable device
|
791
|
+
|
792
|
+
=end
|
793
|
+
def detect_wap_wml()
|
794
|
+
if (http_accept.include?(VNDWAP) || http_accept.include?(WML))
|
795
|
+
return true
|
796
|
+
end
|
797
|
+
return false
|
798
|
+
end
|
799
|
+
|
800
|
+
=begin
|
801
|
+
*
|
802
|
+
* Detects if the current device is an Amazon Kindle (eInk devices only).
|
803
|
+
* Note: For the Kindle Fire, use the normal Android methods.
|
804
|
+
* @return detection of a Kindle
|
805
|
+
|
806
|
+
=end
|
807
|
+
def detect_kindle()
|
808
|
+
if (user_agent.include?(DEVICE_KINDLE) &&
|
809
|
+
!detect_android())
|
810
|
+
return true
|
811
|
+
end
|
812
|
+
return false
|
813
|
+
end
|
814
|
+
|
815
|
+
=begin
|
816
|
+
*
|
817
|
+
* Detects if the current device is a mobile device.
|
818
|
+
* This method catches most of the popular modern devices.
|
819
|
+
* Excludes Apple iPads and other modern tablets.
|
820
|
+
* @return detection of any mobile device using the quicker method
|
821
|
+
|
822
|
+
=end
|
823
|
+
def detect_mobile_quick()
|
824
|
+
|
825
|
+
if (is_tier_tablet)
|
826
|
+
return false
|
827
|
+
end
|
828
|
+
|
829
|
+
if (detect_smartphone())
|
830
|
+
return true
|
831
|
+
end
|
832
|
+
|
833
|
+
if (detect_wap_wml() || detect_brew_device() || detect_opera_mobile())
|
834
|
+
return true
|
835
|
+
end
|
836
|
+
|
837
|
+
if ((user_agent.include?(ENGINE_NETFRONT)) || (user_agent.include?(ENGINE_UP_BROWSER)) || (user_agent.include?(ENGINE_OPEN_WEB)))
|
838
|
+
return true
|
839
|
+
end
|
840
|
+
|
841
|
+
if (detect_danger_hiptop() || detect_midp_capable() || detect_maemo_tablet() || detect_archos())
|
842
|
+
return true
|
843
|
+
end
|
844
|
+
|
845
|
+
if ((user_agent.include?(DEVICE_PDA)) &&
|
846
|
+
(!user_agent.include?(DIS_UPDATE)))
|
847
|
+
return true
|
848
|
+
end
|
849
|
+
if (user_agent.include?(MOBILE))
|
850
|
+
return true
|
851
|
+
end
|
852
|
+
|
853
|
+
return false
|
854
|
+
end
|
855
|
+
|
856
|
+
=begin
|
857
|
+
*
|
858
|
+
* Detects if the current device is a Sony Playstation.
|
859
|
+
* @return detection of Sony Playstation
|
860
|
+
|
861
|
+
=end
|
862
|
+
def detect_sony_playstation()
|
863
|
+
if (user_agent.include?(DEVICE_PLAYSTATION))
|
864
|
+
return true
|
865
|
+
end
|
866
|
+
return false
|
867
|
+
end
|
868
|
+
|
869
|
+
=begin
|
870
|
+
*
|
871
|
+
* Detects if the current device is a Nintendo game device.
|
872
|
+
* @return detection of Nintendo
|
873
|
+
|
874
|
+
=end
|
875
|
+
def detect_nintendo()
|
876
|
+
if (user_agent.include?(DEVICE_NINTENDO) || user_agent.include?(DEVICE_WII) || user_agent.include?(DEVICE_NINTENDO_DS))
|
877
|
+
return true
|
878
|
+
end
|
879
|
+
return false
|
880
|
+
end
|
881
|
+
|
882
|
+
=begin
|
883
|
+
*
|
884
|
+
* Detects if the current device is a Microsoft Xbox.
|
885
|
+
* @return detection of Xbox
|
886
|
+
|
887
|
+
=end
|
888
|
+
def detect_xbox()
|
889
|
+
if (user_agent.include?(DEVICE_XBOX))
|
890
|
+
return true
|
891
|
+
end
|
892
|
+
return false
|
893
|
+
end
|
894
|
+
|
895
|
+
=begin
|
896
|
+
*
|
897
|
+
* Detects if the current device is an Internet-capable game console.
|
898
|
+
* @return detection of any Game Console
|
899
|
+
|
900
|
+
=end
|
901
|
+
def detect_game_console()
|
902
|
+
if (detect_sony_playstation() || detect_nintendo() || detect_xbox())
|
903
|
+
return true
|
904
|
+
end
|
905
|
+
return false
|
906
|
+
end
|
907
|
+
|
908
|
+
=begin
|
909
|
+
*
|
910
|
+
* Detects if the current device supports MIDP, a mobile Java technology.
|
911
|
+
* @return detection of a MIDP mobile Java-capable device
|
912
|
+
|
913
|
+
=end
|
914
|
+
def detect_midp_capable()
|
915
|
+
if (user_agent.include?(DEVICE_MIDP) || http_accept.include?(DEVICE_MIDP))
|
916
|
+
return true
|
917
|
+
end
|
918
|
+
return false
|
919
|
+
end
|
920
|
+
|
921
|
+
=begin
|
922
|
+
*
|
923
|
+
* Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
|
924
|
+
* @return detection of a Maemo OS tablet
|
925
|
+
|
926
|
+
=end
|
927
|
+
def detect_maemo_tablet()
|
928
|
+
if (user_agent.include?(MAEMO))
|
929
|
+
return true
|
930
|
+
elsif (user_agent.include?(LINUX) && user_agent.include?(DEVICE_TABLET) && !detect_web_o_s_tablet() && !detect_android())
|
931
|
+
return true
|
932
|
+
end
|
933
|
+
return false
|
934
|
+
end
|
935
|
+
|
936
|
+
=begin
|
937
|
+
*
|
938
|
+
* Detects if the current device is an Archos media player/Internet tablet.
|
939
|
+
* @return detection of an Archos media player
|
940
|
+
|
941
|
+
=end
|
942
|
+
def detect_archos()
|
943
|
+
if (user_agent.include?(DEVICE_ARCHOS))
|
944
|
+
return true
|
945
|
+
end
|
946
|
+
return false
|
947
|
+
end
|
948
|
+
|
949
|
+
=begin
|
950
|
+
*
|
951
|
+
* Detects if the current browser is a Sony Mylo device.
|
952
|
+
* @return detection of a Sony Mylo device
|
953
|
+
|
954
|
+
=end
|
955
|
+
def detect_sony_mylo()
|
956
|
+
if (user_agent.include?(MANU_SONY) && (user_agent.include?(QTEMBEDDED) || user_agent.include?(MYLOCOM2)))
|
957
|
+
return true
|
958
|
+
end
|
959
|
+
return false
|
960
|
+
end
|
961
|
+
|
962
|
+
=begin
|
963
|
+
*
|
964
|
+
* The longer and more thorough way to detect for a mobile device.
|
965
|
+
* Will probably detect most feature phones,
|
966
|
+
* smartphone-class devices, Internet Tablets,
|
967
|
+
* Internet-enabled game consoles, etc.
|
968
|
+
* This ought to catch a lot of the more obscure and older devices, also --
|
969
|
+
* but no promises on thoroughness!
|
970
|
+
* @return detection of any mobile device using the more thorough method
|
971
|
+
|
972
|
+
=end
|
973
|
+
def detect_mobile_long()
|
974
|
+
if (detect_mobile_quick() || detect_game_console() || detect_sony_mylo())
|
975
|
+
return true
|
976
|
+
end
|
977
|
+
|
978
|
+
|
979
|
+
if (user_agent.include?(UPLINK))
|
980
|
+
return true
|
981
|
+
end
|
982
|
+
if (user_agent.include?(MANU_SONY_ERICSSON))
|
983
|
+
return true
|
984
|
+
end
|
985
|
+
if (user_agent.include?(MANUERICSSON))
|
986
|
+
return true
|
987
|
+
end
|
988
|
+
if (user_agent.include?(MANU_SAMSUNG1))
|
989
|
+
return true
|
990
|
+
end
|
991
|
+
|
992
|
+
if (user_agent.include?(SVC_DOCOMO))
|
993
|
+
return true
|
994
|
+
end
|
995
|
+
if (user_agent.include?(SVC_KDDI))
|
996
|
+
return true
|
997
|
+
end
|
998
|
+
if (user_agent.include?(SVC_VODAFONE))
|
999
|
+
return true
|
1000
|
+
end
|
1001
|
+
|
1002
|
+
return false
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
|
1006
|
+
|
1007
|
+
|
1008
|
+
|
1009
|
+
=begin
|
1010
|
+
*
|
1011
|
+
* The quick way to detect for a tier of devices.
|
1012
|
+
* This method detects for the new generation of
|
1013
|
+
* HTML 5 capable, larger screen tablets.
|
1014
|
+
* Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
|
1015
|
+
* @return detection of any device in the Tablet Tier
|
1016
|
+
|
1017
|
+
=end
|
1018
|
+
def detect_tier_tablet()
|
1019
|
+
if (detect_ipad() || detect_android_tablet() || detect_black_berry_tablet() || detect_web_o_s_tablet())
|
1020
|
+
return true
|
1021
|
+
end
|
1022
|
+
return false
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
=begin
|
1026
|
+
*
|
1027
|
+
* The quick way to detect for a tier of devices.
|
1028
|
+
* This method detects for devices which can
|
1029
|
+
* display iPhone-optimized web content.
|
1030
|
+
* Includes iPhone, iPod Touch, Android, Windows Phone 7, Palm WebOS, etc.
|
1031
|
+
* @return detection of any device in the iPhone/Android/WP7/WebOS Tier
|
1032
|
+
|
1033
|
+
=end
|
1034
|
+
def detect_tier_iphone()
|
1035
|
+
if (is_iphone || is_android_phone || (detect_black_berry_web_kit() && detect_black_berry_touch()) || detect_windows_phone7() || detect_palm_web_o_s() || detect_garmin_nuvifone())
|
1036
|
+
return true
|
1037
|
+
end
|
1038
|
+
return false
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
=begin
|
1042
|
+
*
|
1043
|
+
* The quick way to detect for a tier of devices.
|
1044
|
+
* This method detects for devices which are likely to be capable
|
1045
|
+
* of viewing CSS content optimized for the iPhone,
|
1046
|
+
* but may not necessarily support JavaScript.
|
1047
|
+
* Excludes all iPhone Tier devices.
|
1048
|
+
* @return detection of any device in the 'Rich CSS' Tier
|
1049
|
+
|
1050
|
+
=end
|
1051
|
+
def detect_tier_rich_css()
|
1052
|
+
result = false
|
1053
|
+
|
1054
|
+
|
1055
|
+
if (detect_mobile_quick())
|
1056
|
+
|
1057
|
+
if (!detect_tier_iphone())
|
1058
|
+
|
1059
|
+
|
1060
|
+
|
1061
|
+
|
1062
|
+
if (detect_webkit() || detect_s60_oss_browser() || detect_black_berry_high() || detect_windows_mobile() || user_agent.include?(ENGINE_TELECA_Q))
|
1063
|
+
result= true
|
1064
|
+
end
|
1065
|
+
end
|
1066
|
+
end
|
1067
|
+
return result
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
=begin
|
1071
|
+
*
|
1072
|
+
* The quick way to detect for a tier of devices.
|
1073
|
+
* This method detects for all other types of phones,
|
1074
|
+
* but excludes the iPhone and RichCSS Tier devices.
|
1075
|
+
* @return detection of a mobile device in the less capable tier
|
1076
|
+
|
1077
|
+
=end
|
1078
|
+
def detect_tier_other_phones()
|
1079
|
+
|
1080
|
+
if (detect_mobile_long() && !detect_tier_iphone() && !detect_tier_rich_css())
|
1081
|
+
return true
|
1082
|
+
end
|
1083
|
+
return false
|
1084
|
+
end
|
1085
|
+
end
|
1086
|
+
end
|