Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / preferences / NetworkPredictionOptions.java
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.preferences;
6
7 import org.chromium.chrome.R;
8
9 import java.util.Locale;
10
11 /**
12  * Bandwidth options available based on network.
13  */
14 public enum NetworkPredictionOptions {
15     NETWORK_PREDICTION_ALWAYS,
16     NETWORK_PREDICTION_WIFI_ONLY,
17     NETWORK_PREDICTION_NEVER;
18
19     public static final NetworkPredictionOptions DEFAULT = NETWORK_PREDICTION_WIFI_ONLY;
20
21     /**
22      * @return The number of choices offered for the user.
23      */
24     public static int choiceCount() {
25         return values().length;
26     }
27
28     /**
29      * Fetch the display title for the preference.
30      * @return resource for the title.
31      */
32     public int getDisplayTitle() {
33         switch(this) {
34             case NETWORK_PREDICTION_ALWAYS:
35                 return R.string.always_prefetch_bandwidth_entry;
36             case NETWORK_PREDICTION_WIFI_ONLY :
37                 return R.string.wifi_prefetch_bandwidth_entry;
38             case NETWORK_PREDICTION_NEVER:
39                 return R.string.never_prefetch_bandwidth_entry;
40             default:
41                 assert false;
42                 return 0;
43         }
44     }
45
46     /**
47      * Convert an integer to enum NetworkPredictionOptions.
48      * @return NetworkPredictionOptions instance.
49      */
50     public static NetworkPredictionOptions intToEnum(int index) {
51         return NetworkPredictionOptions.values()[index];
52     }
53
54     /**
55      * Convert an enum NetworkPredictionOptions to integer.
56      * @return Integer corresponding to NetworkPredictionOptions instance.
57      */
58     public int enumToInt() {
59         return ordinal();
60     }
61
62     /**
63      * Convert an string to enum NetworkPredictionOptions.
64      * @return NetworkPredictionOptions instance.
65      */
66     public static NetworkPredictionOptions stringToEnum(String name) {
67         return valueOf(name.toUpperCase(Locale.US));
68     }
69
70     /**
71      * Convert an enum NetworkPredictionOptions to String.
72      * @return String corresponding to NetworkPredictionOptions instance.
73      */
74     public String enumToString() {
75         return name().toLowerCase(Locale.US);
76     }
77 }