LEFT | RIGHT |
(no file at all) | |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-present eyeo GmbH | |
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("wifi") | |
26 { | |
27 @Override | |
28 public boolean isRequiredConnection(ConnectivityManager manager) | |
29 { | |
30 return manager.getActiveNetworkInfo().getType() == ConnectivityManager.TYP
E_WIFI; | |
31 } | |
32 }, | |
33 | |
34 // Non-metered WiFi networks | |
35 WIFI_NON_METERED("wifi_non_metered") | |
36 { | |
37 @Override | |
38 public boolean isRequiredConnection(ConnectivityManager manager) | |
39 { | |
40 return | |
41 manager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIF
I && | |
42 !manager.isActiveNetworkMetered(); | |
43 } | |
44 }, | |
45 | |
46 // Any connection | |
47 ANY("any") | |
48 { | |
49 @Override | |
50 public boolean isRequiredConnection(ConnectivityManager manager) | |
51 { | |
52 return true; | |
53 } | |
54 }; | |
55 | |
56 private String value; | |
57 | |
58 public String getValue() | |
59 { | |
60 return value; | |
61 } | |
62 | |
63 // check if current device connection type is equal to this concrete connectio
n type | |
64 public abstract boolean isRequiredConnection(ConnectivityManager manager); | |
65 | |
66 ConnectionType(String value) | |
67 { | |
68 this.value = value; | |
69 } | |
70 | |
71 public static ConnectionType findByValue(String value) | |
72 { | |
73 if (value == null) | |
74 { | |
75 return null; | |
76 } | |
77 | |
78 for (ConnectionType eachConnectionType : ConnectionType.values()) | |
79 { | |
80 if (eachConnectionType.getValue().equals(value)) | |
81 { | |
82 return eachConnectionType; | |
83 } | |
84 } | |
85 | |
86 // not found | |
87 return null; | |
88 } | |
89 } | |
LEFT | RIGHT |