BluetoothOppIncomingFileConfirmActivity.java revision 09e9cba205af60b3f42e7a4d891a7d1392e1f2a5
1/* 2 * Copyright (c) 2008-2009, Motorola, Inc. 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * - Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * - Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * - Neither the name of the Motorola, Inc. nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33package com.android.bluetooth.opp; 34 35import android.content.ContentValues; 36import android.content.DialogInterface; 37import android.content.Intent; 38import android.net.Uri; 39import android.os.Bundle; 40import android.util.Log; 41import android.view.View; 42import android.widget.TextView; 43import android.widget.Toast; 44import android.text.format.Formatter; 45 46import com.android.internal.app.AlertActivity; 47import com.android.internal.app.AlertController; 48 49/** 50 * This class is designed to ask user to confirm if accept incoming file; 51 */ 52public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity implements 53 DialogInterface.OnClickListener { 54 private static final String TAG = "BluetoothIncomingFileConfirmActivity"; 55 56 private BluetoothOppTransferInfo mTransInfo; 57 58 private Uri mUri; 59 60 private ContentValues mUpdateValues; 61 62 private boolean mOkOrCancelClicked = false; 63 64 @Override 65 protected void onCreate(Bundle savedInstanceState) { 66 super.onCreate(savedInstanceState); 67 68 Intent intent = getIntent(); 69 mUri = intent.getData(); 70 mTransInfo = new BluetoothOppTransferInfo(); 71 mTransInfo = BluetoothOppUtility.queryRecord(this, mUri); 72 if (mTransInfo == null) { 73 if (Constants.LOGVV) { 74 Log.e(TAG, "Error: Can not get data from db"); 75 } 76 finish(); 77 return; 78 } 79 80 // Set up the "dialog" 81 final AlertController.AlertParams p = mAlertParams; 82 p.mIconId = android.R.drawable.ic_dialog_alert; 83 p.mTitle = getString(R.string.incoming_file_confirm_title); 84 p.mView = createView(); 85 p.mPositiveButtonText = getString(R.string.incoming_file_confirm_ok); 86 p.mPositiveButtonListener = this; 87 p.mNegativeButtonText = getString(R.string.incoming_file_confirm_cancel); 88 p.mNegativeButtonListener = this; 89 setupAlert(); 90 91 if (Constants.LOGVV) { 92 Log.v(TAG, "BluetoothIncomingFileConfirmActivity: Got uri:" + mUri); 93 } 94 } 95 96 private View createView() { 97 View view = getLayoutInflater().inflate(R.layout.confirm_dialog, null); 98 99 TextView contentView = (TextView)view.findViewById(R.id.content); 100 101 String text = getString(R.string.incoming_file_confirm_content).replace("%s1", 102 mTransInfo.mDeviceName).replace("%s2", mTransInfo.mFileName).replace("%s3", 103 Formatter.formatFileSize(this, mTransInfo.mTotalBytes)); 104 105 contentView.setText(text); 106 107 return view; 108 } 109 110 public void onClick(DialogInterface dialog, int which) { 111 switch (which) { 112 case DialogInterface.BUTTON_POSITIVE: 113 // Update database 114 mUpdateValues = new ContentValues(); 115 mUpdateValues.put(BluetoothShare.USER_CONFIRMATION, 116 BluetoothShare.USER_CONFIRMATION_CONFIRMED); 117 this.getContentResolver().update(mUri, mUpdateValues, null, null); 118 119 Toast.makeText(this, getString(R.string.bt_toast_1), Toast.LENGTH_SHORT).show(); 120 break; 121 122 case DialogInterface.BUTTON_NEGATIVE: 123 // Update database 124 mUpdateValues = new ContentValues(); 125 mUpdateValues.put(BluetoothShare.USER_CONFIRMATION, 126 BluetoothShare.USER_CONFIRMATION_DENIED); 127 this.getContentResolver().update(mUri, mUpdateValues, null, null); 128 129 Toast.makeText(this, getString(R.string.bt_toast_2), Toast.LENGTH_SHORT).show(); 130 break; 131 } 132 mOkOrCancelClicked = true; 133 } 134 135 @Override 136 protected void onDestroy() { 137 super.onDestroy(); 138 if (mOkOrCancelClicked) { 139 return; 140 } 141 // for the "back" key press case 142 mUpdateValues = new ContentValues(); 143 mUpdateValues.put(BluetoothShare.VISIBILITY, BluetoothShare.VISIBILITY_HIDDEN); 144 this.getContentResolver().update(mUri, mUpdateValues, null, null); 145 if (Constants.LOGVV) { 146 Log.v(TAG, "db updated: change to VISIBILITY_HIDDEN"); 147 } 148 Toast.makeText(this, getString(R.string.bt_toast_2), Toast.LENGTH_SHORT).show(); 149 } 150} 151