Home | History | Annotate | Download | only in vpn
      1 /* * Copyright (C) 2009 The Android Open Source Project
      2  *
      3  * Licensed under the Apache License, Version 2.0 (the "License");
      4  * you may not use this file except in compliance with the License.
      5  * You may obtain a copy of the License at
      6  *
      7  *      http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software
     10  * distributed under the License is distributed on an "AS IS" BASIS,
     11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12  * See the License for the specific language governing permissions and
     13  * limitations under the License.
     14  */
     15 
     16 package com.android.settings.vpn;
     17 
     18 import com.android.settings.R;
     19 
     20 import android.content.Context;
     21 import android.net.vpn.PptpProfile;
     22 import android.preference.CheckBoxPreference;
     23 import android.preference.Preference;
     24 import android.preference.PreferenceGroup;
     25 
     26 /**
     27  * The class for editing {@link PptpProfile}.
     28  */
     29 class PptpEditor extends VpnProfileEditor {
     30     private CheckBoxPreference mEncryption;
     31 
     32     public PptpEditor(PptpProfile p) {
     33         super(p);
     34     }
     35 
     36     @Override
     37     protected void loadExtraPreferencesTo(PreferenceGroup subpanel) {
     38         Context c = subpanel.getContext();
     39         subpanel.addPreference(createEncryptionPreference(c));
     40 
     41         PptpProfile profile = (PptpProfile) getProfile();
     42     }
     43 
     44     private Preference createEncryptionPreference(Context c) {
     45         final PptpProfile profile = (PptpProfile) getProfile();
     46         CheckBoxPreference encryption = mEncryption = new CheckBoxPreference(c);
     47         boolean enabled = profile.isEncryptionEnabled();
     48         setCheckBoxTitle(encryption, R.string.vpn_pptp_encryption_title);
     49         encryption.setChecked(enabled);
     50         setEncryptionSummary(encryption, enabled);
     51         encryption.setOnPreferenceChangeListener(
     52                 new Preference.OnPreferenceChangeListener() {
     53                     public boolean onPreferenceChange(
     54                             Preference pref, Object newValue) {
     55                         boolean enabled = (Boolean) newValue;
     56                         profile.setEncryptionEnabled(enabled);
     57                         setEncryptionSummary(mEncryption, enabled);
     58                         return true;
     59                     }
     60                 });
     61         return encryption;
     62     }
     63 
     64     private void setEncryptionSummary(CheckBoxPreference encryption,
     65             boolean enabled) {
     66         Context c = encryption.getContext();
     67         String formatString = c.getString(enabled
     68                 ? R.string.vpn_is_enabled
     69                 : R.string.vpn_is_disabled);
     70         encryption.setSummary(String.format(
     71                 formatString, c.getString(R.string.vpn_pptp_encryption)));
     72     }
     73 }
     74