OSDN Git Service

Add VPN settings classes to Settings app.
[android-x86/packages-apps-Settings.git] / src / com / android / settings / vpn / VpnTypeSelection.java
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.settings.vpn;
18
19 import com.android.settings.R;
20
21 import android.content.Intent;
22 import android.net.vpn.VpnManager;
23 import android.net.vpn.VpnType;
24 import android.os.Bundle;
25 import android.preference.Preference;
26 import android.preference.PreferenceActivity;
27 import android.preference.PreferenceScreen;
28
29 import java.util.HashMap;
30 import java.util.Map;
31
32 /**
33  * The activity to select a VPN type.
34  */
35 public class VpnTypeSelection extends PreferenceActivity {
36     private Map<String, VpnType> mTypeMap = new HashMap<String, VpnType>();
37
38     @Override
39     public void onCreate(Bundle savedInstanceState) {
40         super.onCreate(savedInstanceState);
41
42         addPreferencesFromResource(R.xml.vpn_type);
43         initTypeList();
44     }
45
46     @Override
47     public boolean onPreferenceTreeClick(PreferenceScreen ps, Preference pref) {
48         setResult(mTypeMap.get(pref.getTitle().toString()));
49         finish();
50         return true;
51     }
52
53     private void initTypeList() {
54         PreferenceScreen root = getPreferenceScreen();
55         for (VpnType t : VpnManager.getSupportedVpnTypes()) {
56             String displayName = t.getDisplayName();
57             mTypeMap.put(displayName, t);
58
59             Preference pref = new Preference(this);
60             pref.setTitle(displayName);
61             root.addPreference(pref);
62         }
63     }
64
65     private void setResult(VpnType type) {
66         Intent intent = new Intent(this, VpnSettings.class);
67         intent.putExtra(VpnSettings.KEY_VPN_TYPE, type.toString());
68         setResult(RESULT_OK, intent);
69     }
70 }