Home | History | Annotate | Download | only in phone
      1 package com.android.phone;
      2 
      3 import com.android.internal.telephony.Phone;
      4 import com.android.internal.telephony.PhoneFactory;
      5 import android.content.Context;
      6 import android.os.AsyncResult;
      7 import android.os.Handler;
      8 import android.os.Message;
      9 import android.preference.CheckBoxPreference;
     10 import android.util.AttributeSet;
     11 import android.util.Log;
     12 
     13 public class CdmaVoicePrivacyCheckBoxPreference extends CheckBoxPreference {
     14     private static final String LOG_TAG = "CdmaVoicePrivacyCheckBoxPreference";
     15     private final boolean DBG = (PhoneApp.DBG_LEVEL >= 2);
     16 
     17     Phone phone;
     18     private MyHandler mHandler = new MyHandler();
     19 
     20     public CdmaVoicePrivacyCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
     21         super(context, attrs, defStyle);
     22 
     23         phone = PhoneFactory.getDefaultPhone();
     24         phone.getEnhancedVoicePrivacy(mHandler.obtainMessage(MyHandler.MESSAGE_GET_VP));
     25     }
     26 
     27     public CdmaVoicePrivacyCheckBoxPreference(Context context, AttributeSet attrs) {
     28         this(context, attrs, com.android.internal.R.attr.checkBoxPreferenceStyle);
     29     }
     30 
     31     public CdmaVoicePrivacyCheckBoxPreference(Context context) {
     32         this(context, null);
     33     }
     34 
     35 
     36     @Override
     37     protected void onClick() {
     38         super.onClick();
     39 
     40         phone.enableEnhancedVoicePrivacy(isChecked(),
     41                 mHandler.obtainMessage(MyHandler.MESSAGE_SET_VP));
     42     }
     43 
     44 
     45 
     46     private class MyHandler extends Handler {
     47         private static final int MESSAGE_GET_VP = 0;
     48         private static final int MESSAGE_SET_VP = 1;
     49 
     50         @Override
     51         public void handleMessage(Message msg) {
     52             switch (msg.what) {
     53                 case MESSAGE_GET_VP:
     54                     handleGetVPResponse(msg);
     55                     break;
     56                 case MESSAGE_SET_VP:
     57                     handleSetVPResponse(msg);
     58                     break;
     59             }
     60         }
     61 
     62         private void handleGetVPResponse(Message msg) {
     63             AsyncResult ar = (AsyncResult) msg.obj;
     64 
     65             if (ar.exception != null) {
     66                 if (DBG) Log.d(LOG_TAG, "handleGetVPResponse: ar.exception=" + ar.exception);
     67                 setEnabled(false);
     68             } else {
     69                 if (DBG) Log.d(LOG_TAG, "handleGetVPResponse: VP state successfully queried.");
     70                 final int enable = ((int[]) ar.result)[0];
     71                 setChecked(enable != 0);
     72 
     73                 android.provider.Settings.Secure.putInt(getContext().getContentResolver(),
     74                         android.provider.Settings.Secure.ENHANCED_VOICE_PRIVACY_ENABLED, enable);
     75             }
     76         }
     77 
     78         private void handleSetVPResponse(Message msg) {
     79             AsyncResult ar = (AsyncResult) msg.obj;
     80 
     81             if (ar.exception != null) {
     82                 if (DBG) Log.d(LOG_TAG, "handleSetVPResponse: ar.exception=" + ar.exception);
     83             }
     84             if (DBG) Log.d(LOG_TAG, "handleSetVPResponse: re get");
     85 
     86             phone.getEnhancedVoicePrivacy(obtainMessage(MESSAGE_GET_VP));
     87         }
     88     }
     89 }
     90