Detecting mobile devices in Themes settings

Detecting mobile devices in Themes settings

by Joseph Rézeau -
Number of replies: 7
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi there, I've been playing around with my Xmas present HP TouchPad tablet...

From the tablet I can access my desktop's localhost's test moodle sites. I got stuck in the Themes settings / Device detection regular expressions section, as I had no idea what kind of regular expression to enter for my tablet. Had to get into moodle/lib/moodlelib.php to find out that detection was based - as expected - on

$useragent = $_SERVER['HTTP_USER_AGENT'].

I then added 1 line and modified 1 line in moodle/admin/settings.php:

$useragent = $_SERVER['HTTP_USER_AGENT'];
    $temp->add(new admin_setting_devicedetectregex('devicedetectregex', get_string('devicedetectregex', 'admin'), 'Your browser/device is: '.$useragent.' : '.get_string('devicedetectregex_desc', 'admin'), ''));

... which displayed the full contents of my HP TouchPad's HTTP_USER_AGENT (see attached screenshot). And I could enter the following, which worked as expected on my TouchPad

Device detection regular expressions Regular expression Return value
  /hp-tablet/ tablet
     

Of course, this is only useful to admins who are displaying their moodle site on a mobile device that they wish to detect. It does not answer the problem of their users/students who will be using their site on a mobile device which is not automatically detected by the moodle core regular expressions. But it's better than nothing.

Anyhow, I suggest to Moodle HQ to add "hp-tablet" to the current $tabletregex string in appearance.php.

Joseph

PS.- I found this site useful for detection of mobile devices: Detect a mobile device with PHP in 547 bytes

Attachment browser_2012-23-01_105948.png
Average of ratings: -
In reply to Joseph Rézeau

Re: Detecting mobile devices in Themes settings

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Continuing my tests with the HP TouchPad tablet and Moodle.

Just noticed that in Site administration ► Appearance ► Themes ► Theme settings if I set

Device detection regular expressions Regular expression Return value
  /hp-tablet/ tablet
     

as explained in my previous message, then on the Theme selector page I have 2 Device Type sections entitled "tablet" : one for all other mobile devices detected by core moodle expression and one for the extra expression I entered. But... it's not possible to select 2 different themes for the original "tablet" device and the added extra "tablet" device!

It would seem more logical to consider that when one enters an existing "Return value" (such as "mobile" or "tablet", no extra Device Type section should be added. Extra sections should only be added if the "Return value" does not already exist in moodle core detected devices.

Any other "non-standard tablet" users out there?

Joseph

Attachment 24-01-2012 15-04-48.jpg
In reply to Joseph Rézeau

Re: Detecting mobile devices in Themes settings

by Richard Oelmann -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Joseph,

I presume you are suggesting that there should be a way of adding a new regular expression to an existing Return Value rather than necessarily creating a new one where that may not be needed (like your case of adding a newer type of tablet, rather than a completely new category of device)?

I think that would be a very good move, particularly the rate at which new products - especially in the tablet/mobile market - are being brought out. These may not always be picked up by the existing regex but a whole new category may not be appropriate either.

Richard

In reply to Richard Oelmann

Re: Detecting mobile devices in Themes settings

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Richard "I presume you are suggesting that there should be a way of adding a new regular expression to an existing Return Value rather than necessarily creating a new one where that may not be needed (like your case of adding a newer type of tablet, rather than a completely new category of device)?"

Yes, that's the idea.

Joseph

In reply to Joseph Rézeau

Re: Detecting mobile devices in Themes settings

by Danny Wahl -

Definitely seems like a dropdown for the return values with the Moodle Core options would make more sense.  Are there other viewport types beside Mobile/tablet/desktop?

In reply to Danny Wahl

Re: Detecting mobile devices in Themes settings

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Daniel "Are there other viewport types beside Mobile/tablet/desktop?"

Not at time of writing, AFAIK, but who knows what the future holds in store? wink

Joseph

In reply to Joseph Rézeau

Re: Detecting mobile devices in Themes settings

by Roger Emery -

I agree with your suggested improvements.

I've just been adding this and Asus Transformer to the list

Mozilla/5.0 (Linux; U; Android 3.2.1; en-us; Transformer TF101 Build/HTK75) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13

but just used /Android 3/ as the expression.

However got completely confused when I wan't to add a second exception to return 'tablet'

However - this is a very useful to have an exceptiosn list as more and more BYOD roll in the door.

So the other device types I can think of:-

Console - ie Games Consoles (with browsers) and maybe another for handheld consules?

TV - eg The up and coming Apple iTV (or giant iPAd), other smart TVs

Do you need a different theme, or at least a larger default body text size for browsing moodle from the sofa? and different hover and click when using the kinect or wii?

In reply to Joseph Rézeau

Re: Detecting mobile devices in Themes settings

by mart van der niet -

The simplest solution seems to be to go into moodle/lib/moodlelib.php.

In the distributionfile ('2.2.1 (Build: 20120109)')  you'll find:

line 8177:   $tabletregex = '/Tablet browser|iPad|iProd|GT-P1000|GT-I9000|SHW-M180S|SGH-T849|SCH-I800|Build\/ERE27|sholest/i';

 

Obviously Android is missing here, so editing the line to:

line 8177:   $tabletregex = '/Tablet browser|Android|iPad|iProd|GT-P1000|GT-I9000|SHW-M180S|SGH-T849|SCH-I800|Build\/ERE27|sholest/i';

should do the trick, or am I missing something here?