Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package org.litesoft.useragent;

public class UserAgentFormFactorDeterminerImpl implements UserAgentFormFactorDeterminer {
    @Override
    public UserAgentFormFactor determine( String pUserAgent ) {
        return ((pUserAgent.length() > 15) && containsAnyOf( pUserAgent,
                                                             "iPhone", "iPod", "Mobile", "Android", "iPad", "IEMobile", "Tablet",
                                                             "Kindle", "Silk",
                                                             "SymbianOS", "Symbian",
                                                             "Opera Mini", "Opera Mobi",
                                                             "Fennec" )) ?
               UserAgentFormFactor.SingleViewOnly :
               UserAgentFormFactor.MultiViewable;
    }

    /**
     * Look for the Find Words (where the Word may not start the User Agent).
     */
    private boolean containsAnyOf( String pUserAgent, String... pFindWords ) {
        for ( String zWord : pFindWords ) {
            if ( containsWord( pUserAgent, zWord ) ) {
                return true;
            }
        }
        return false;
    }

    /**
     * Look for the Find Word (where the Word may not start the User Agent).
     */
    private boolean containsWord( String pUserAgent, String pWord ) {
        for ( int zAt, zFrom = 1; -1 != (zAt = pUserAgent.indexOf( pWord, zFrom )); ) {
            zFrom = zAt + pWord.length();
            if ( isWordSep( pUserAgent, zAt - 1 ) && isWordSep( pUserAgent, zFrom ) ) {
                return true;
            }
        }
        return false;
    }

    private boolean isWordSep( String pUserAgent, int pAt ) {
        return (pAt == pUserAgent.length()) || !Character.isLetterOrDigit( pUserAgent.charAt( pAt ) );
    }
}


Commits for litesoft/trunk/DeviceDesktopTest/src/org/litesoft/useragent/UserAgentFormFactorDeterminerImpl.java

Diff revisions: vs.
Revision Author Commited Message
961 Diff Diff GeorgeS picture GeorgeS Fri 01 Aug, 2014 03:13:31 +0000

Externalization Work.

950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

924 Diff Diff GeorgeS picture GeorgeS Fri 14 Mar, 2014 22:02:56 +0000

Drop IWS

920 GeorgeS picture GeorgeS Sun 16 Feb, 2014 19:06:51 +0000

DDT w/ Jetty