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.
5 package org.chromium.chrome.browser.preferences;
7 import org.chromium.chrome.R;
9 import java.util.Locale;
12 * Bandwidth options available based on network.
14 public enum NetworkPredictionOptions {
15 NETWORK_PREDICTION_ALWAYS,
16 NETWORK_PREDICTION_WIFI_ONLY,
17 NETWORK_PREDICTION_NEVER;
19 public static final NetworkPredictionOptions DEFAULT = NETWORK_PREDICTION_WIFI_ONLY;
22 * @return The number of choices offered for the user.
24 public static int choiceCount() {
25 return values().length;
29 * Fetch the display title for the preference.
30 * @return resource for the title.
32 public int getDisplayTitle() {
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;
47 * Convert an integer to enum NetworkPredictionOptions.
48 * @return NetworkPredictionOptions instance.
50 public static NetworkPredictionOptions intToEnum(int index) {
51 return NetworkPredictionOptions.values()[index];
55 * Convert an enum NetworkPredictionOptions to integer.
56 * @return Integer corresponding to NetworkPredictionOptions instance.
58 public int enumToInt() {
63 * Convert an string to enum NetworkPredictionOptions.
64 * @return NetworkPredictionOptions instance.
66 public static NetworkPredictionOptions stringToEnum(String name) {
67 return valueOf(name.toUpperCase(Locale.US));
71 * Convert an enum NetworkPredictionOptions to String.
72 * @return String corresponding to NetworkPredictionOptions instance.
74 public String enumToString() {
75 return name().toLowerCase(Locale.US);