|
@@ -1,80 +1,84 @@ |
1 |
1 |
|
/* |
2 |
2 |
|
* Copyright 2010 Daniel Kurka |
3 |
3 |
|
* |
4 |
|
- |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
5 |
|
- |
* use this file except in compliance with the License. You may obtain a copy of |
6 |
|
- |
* the License at |
|
4 |
+ |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
|
5 |
+ |
* in compliance with the License. You may obtain a copy of the License at |
7 |
6 |
|
* |
8 |
7 |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
9 |
8 |
|
* |
10 |
|
- |
* Unless required by applicable law or agreed to in writing, software |
11 |
|
- |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 |
|
- |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 |
|
- |
* License for the specific language governing permissions and limitations under |
|
9 |
+ |
* Unless required by applicable law or agreed to in writing, software distributed under the License |
|
10 |
+ |
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
|
11 |
+ |
* or implied. See the License for the specific language governing permissions and limitations under |
14 |
12 |
|
* the License. |
15 |
13 |
|
*/ |
16 |
14 |
|
package com.googlecode.gwtphonegap.client.device; |
17 |
15 |
|
|
18 |
|
- |
import java.util.Date; |
19 |
|
- |
|
20 |
16 |
|
import com.google.gwt.user.client.Cookies; |
21 |
17 |
|
|
|
18 |
+ |
import java.util.Date; |
|
19 |
+ |
|
22 |
20 |
|
public class DeviceBrowserImpl implements Device { |
23 |
21 |
|
|
24 |
|
- |
@Override |
25 |
|
- |
public String getName() { |
26 |
|
- |
return ""; |
27 |
|
- |
} |
28 |
|
- |
|
29 |
|
- |
@Override |
30 |
|
- |
public String getPhoneGapVersion() { |
31 |
|
- |
return "none"; |
32 |
|
- |
} |
33 |
|
- |
|
34 |
|
- |
@Override |
35 |
|
- |
public String getPlatform() { |
36 |
|
- |
return "browser"; |
37 |
|
- |
} |
38 |
|
- |
|
39 |
|
- |
@Override |
40 |
|
- |
public String getUuid() { |
41 |
|
- |
String value = Cookies.getCookie("gwt-phonegap-uuid"); |
42 |
|
- |
if (value == null) { |
43 |
|
- |
long end = System.currentTimeMillis() + 60l * 60l * 24l * 356l; |
44 |
|
- |
value = getPseudoGUUID(); |
45 |
|
- |
Cookies.setCookie("gwt-phonegap-uuid", value, new Date(end)); |
46 |
|
- |
|
47 |
|
- |
} |
48 |
|
- |
return value; |
49 |
|
- |
} |
50 |
|
- |
|
51 |
|
- |
private static final char[] CHAR_ARRAY = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray(); |
52 |
|
- |
|
53 |
|
- |
public static String getPseudoGUUID() { |
54 |
|
- |
char[] buffer = new char[36]; |
55 |
|
- |
|
56 |
|
- |
for (int i = 0; i < 36; i++) { |
57 |
|
- |
|
58 |
|
- |
int random = (int) (Math.random() * 16); |
59 |
|
- |
int index = 0; |
60 |
|
- |
if (i == 19) { |
61 |
|
- |
index = (random & 0x3) | 0x8; |
62 |
|
- |
} else { |
63 |
|
- |
index = random & 0xf; |
64 |
|
- |
} |
65 |
|
- |
buffer[i] = CHAR_ARRAY[index]; |
66 |
|
- |
|
67 |
|
- |
} |
68 |
|
- |
|
69 |
|
- |
buffer[8] = buffer[13] = buffer[18] = buffer[23] = '-'; |
70 |
|
- |
buffer[14] = '4'; |
71 |
|
- |
|
72 |
|
- |
return new String(buffer); |
73 |
|
- |
} |
74 |
|
- |
|
75 |
|
- |
@Override |
76 |
|
- |
public String getVersion() { |
77 |
|
- |
return "none"; |
78 |
|
- |
} |
|
22 |
+ |
@Override |
|
23 |
+ |
public String getName() { |
|
24 |
+ |
return ""; |
|
25 |
+ |
} |
|
26 |
+ |
|
|
27 |
+ |
@Override |
|
28 |
+ |
public String getPhoneGapVersion() { |
|
29 |
+ |
return "none"; |
|
30 |
+ |
} |
|
31 |
+ |
|
|
32 |
+ |
@Override |
|
33 |
+ |
public String getPlatform() { |
|
34 |
+ |
return "browser"; |
|
35 |
+ |
} |
|
36 |
+ |
|
|
37 |
+ |
@Override |
|
38 |
+ |
public String getUuid() { |
|
39 |
+ |
String value = Cookies.getCookie("gwt-phonegap-uuid"); |
|
40 |
+ |
if (value == null) { |
|
41 |
+ |
long end = System.currentTimeMillis() + 60l * 60l * 24l * 356l * 1000l; |
|
42 |
+ |
value = getPseudoGUUID(); |
|
43 |
+ |
Cookies.setCookie("gwt-phonegap-uuid", value, new Date(end)); |
|
44 |
+ |
|
|
45 |
+ |
} |
|
46 |
+ |
return value; |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
private static final char[] CHAR_ARRAY = |
|
50 |
+ |
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray(); |
|
51 |
+ |
|
|
52 |
+ |
public static String getPseudoGUUID() { |
|
53 |
+ |
char[] buffer = new char[36]; |
|
54 |
+ |
|
|
55 |
+ |
for (int i = 0; i < 36; i++) { |
|
56 |
+ |
|
|
57 |
+ |
int random = (int) (Math.random() * 16); |
|
58 |
+ |
int index = 0; |
|
59 |
+ |
if (i == 19) { |
|
60 |
+ |
index = (random & 0x3) | 0x8; |
|
61 |
+ |
} else { |
|
62 |
+ |
index = random & 0xf; |
|
63 |
+ |
} |
|
64 |
+ |
buffer[i] = CHAR_ARRAY[index]; |
|
65 |
+ |
|
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
buffer[8] = buffer[13] = buffer[18] = buffer[23] = '-'; |
|
69 |
+ |
buffer[14] = '4'; |
|
70 |
+ |
|
|
71 |
+ |
return new String(buffer); |
|
72 |
+ |
} |
|
73 |
+ |
|
|
74 |
+ |
@Override |
|
75 |
+ |
public String getVersion() { |
|
76 |
+ |
return "none"; |
|
77 |
+ |
} |
|
78 |
+ |
|
|
79 |
+ |
@Override |
|
80 |
+ |
public String getModel() { |
|
81 |
+ |
return ""; |
|
82 |
+ |
} |
79 |
83 |
|
|
80 |
84 |
|
} |