Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-2016 Eyeo GmbH | |
Felix Dahlke
2017/03/24 07:37:24
2017 :)
anton
2017/03/24 09:43:11
Yes, i've left it 2016 as i will update 2016 to 20
Felix Dahlke
2017/03/27 14:18:11
Acknowledged.
| |
4 * | |
5 * Adblock Plus is free software: you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License version 3 as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
18 package org.adblockplus.libadblockplus.android.settings; | |
19 | |
20 import android.net.ConnectivityManager; | |
21 | |
22 public enum ConnectionType { | |
23 | |
24 // All WiFi networks | |
25 WIFI( | |
26 "wifi", | |
27 new ConnectionChecker() | |
28 { | |
29 @Override | |
30 public boolean isRequiredConnection(ConnectivityManager manager) | |
31 { | |
32 return manager.getActiveNetworkInfo().getType() == ConnectivityManager.T YPE_WIFI; | |
33 } | |
34 }), | |
35 | |
36 // Non-metered WiFi networks | |
37 WIFI_NON_METERED( | |
38 "wifi_non_metered", | |
39 new ConnectionChecker() | |
40 { | |
41 @Override | |
42 public boolean isRequiredConnection(ConnectivityManager manager) | |
43 { | |
44 return | |
45 manager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_W IFI && | |
46 !manager.isActiveNetworkMetered(); | |
47 } | |
48 }), | |
49 | |
50 // Any connection | |
51 ANY( | |
52 "any", | |
53 new ConnectionChecker() | |
54 { | |
55 @Override | |
56 public boolean isRequiredConnection(ConnectivityManager manager) | |
57 { | |
58 return true; | |
59 } | |
60 }); | |
61 | |
62 private String value; | |
63 private ConnectionChecker checker; | |
64 | |
65 public String getValue() | |
66 { | |
67 return value; | |
68 } | |
69 | |
70 public ConnectionChecker getChecker() | |
71 { | |
72 return checker; | |
73 } | |
74 | |
75 ConnectionType(String value, ConnectionChecker checker) | |
76 { | |
77 this.value = value; | |
78 this.checker = checker; | |
79 } | |
80 | |
81 interface ConnectionChecker | |
82 { | |
83 boolean isRequiredConnection(ConnectivityManager manager); | |
84 } | |
85 | |
86 public static ConnectionType findByValue(String value) | |
87 { | |
88 if (value == null) | |
89 { | |
90 return null; | |
91 } | |
92 | |
93 for (ConnectionType eachConnectionType : ConnectionType.values()) | |
94 { | |
95 if (eachConnectionType.getValue().equals(value)) | |
96 { | |
97 return eachConnectionType; | |
98 } | |
99 } | |
100 | |
101 // not found | |
102 return null; | |
103 } | |
104 } | |
OLD | NEW |