1 /* 2 * Copyright (C) 2006 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.phone.settings.fdn; 18 19 import android.content.Intent; 20 import android.net.Uri; 21 import android.os.Bundle; 22 import android.text.TextUtils; 23 24 import com.android.phone.R; 25 26 /** 27 * Activity to let the user delete an FDN contact. 28 */ 29 public class DeleteFdnContactScreen extends BaseFdnContactScreen { 30 31 @Override onCreate(Bundle icicle)32 protected void onCreate(Bundle icicle) { 33 super.onCreate(icicle); 34 35 // Starts PIN2 authentication only for the first time. 36 if (icicle == null) authenticatePin2(); 37 setContentView(R.layout.delete_fdn_contact_screen); 38 } 39 40 @Override onActivityResult(int requestCode, int resultCode, Intent intent)41 protected void onActivityResult(int requestCode, int resultCode, Intent intent) { 42 if (DBG) log("onActivityResult"); 43 44 switch (requestCode) { 45 case PIN2_REQUEST_CODE: 46 Bundle extras = (intent != null) ? intent.getExtras() : null; 47 if (extras != null) { 48 mPin2 = extras.getString("pin2"); 49 processPin2(mPin2); 50 } else { 51 // if they cancelled, then we just cancel too. 52 if (DBG) log("onActivityResult: CANCELLED"); 53 displayProgress(false); 54 finish(); 55 } 56 break; 57 } 58 } 59 60 @Override resolveIntent()61 protected void resolveIntent() { 62 super.resolveIntent(); 63 64 if (TextUtils.isEmpty(mNumber)) { 65 finish(); 66 } 67 } 68 deleteContact()69 private void deleteContact() { 70 StringBuilder buf = new StringBuilder(); 71 if (TextUtils.isEmpty(mName)) { 72 buf.append("number='"); 73 } else { 74 buf.append("tag='"); 75 buf.append(mName); 76 buf.append("' AND number='"); 77 } 78 buf.append(mNumber); 79 buf.append("' AND pin2='"); 80 buf.append(mPin2); 81 buf.append("'"); 82 83 Uri uri = FdnList.getContentUri(mSubscriptionInfoHelper); 84 85 mQueryHandler = new QueryHandler(getContentResolver()); 86 mQueryHandler.startDelete(0, null, uri, buf.toString(), null); 87 displayProgress(true); 88 } 89 90 @Override handleResult(boolean success)91 protected void handleResult(boolean success) { 92 if (success) { 93 if (DBG) log("handleResult: success!"); 94 showStatus(getResources().getText(R.string.fdn_contact_deleted)); 95 } else { 96 if (DBG) log("handleResult: failed!"); 97 showStatus(getResources().getText(R.string.pin2_invalid)); 98 } 99 mHandler.postDelayed(() -> finish(), 2000); 100 } 101 102 @Override pin2AuthenticationSucceed()103 protected void pin2AuthenticationSucceed() { 104 showStatus(getResources().getText(R.string.deleting_fdn_contact)); 105 deleteContact(); 106 } 107 } 108