BluetoothOppTransferHistory.java revision a930b6831d0c70b6c5d34e548e6b1dceaa6529a0
15cc617943765df27844e459362c4bc1821305216Lixin Yue/* 25cc617943765df27844e459362c4bc1821305216Lixin Yue * Copyright (c) 2008-2009, Motorola, Inc. 35cc617943765df27844e459362c4bc1821305216Lixin Yue * 45cc617943765df27844e459362c4bc1821305216Lixin Yue * All rights reserved. 55cc617943765df27844e459362c4bc1821305216Lixin Yue * 65cc617943765df27844e459362c4bc1821305216Lixin Yue * Redistribution and use in source and binary forms, with or without 75cc617943765df27844e459362c4bc1821305216Lixin Yue * modification, are permitted provided that the following conditions are met: 85cc617943765df27844e459362c4bc1821305216Lixin Yue * 95cc617943765df27844e459362c4bc1821305216Lixin Yue * - Redistributions of source code must retain the above copyright notice, 105cc617943765df27844e459362c4bc1821305216Lixin Yue * this list of conditions and the following disclaimer. 115cc617943765df27844e459362c4bc1821305216Lixin Yue * 125cc617943765df27844e459362c4bc1821305216Lixin Yue * - Redistributions in binary form must reproduce the above copyright notice, 135cc617943765df27844e459362c4bc1821305216Lixin Yue * this list of conditions and the following disclaimer in the documentation 145cc617943765df27844e459362c4bc1821305216Lixin Yue * and/or other materials provided with the distribution. 155cc617943765df27844e459362c4bc1821305216Lixin Yue * 165cc617943765df27844e459362c4bc1821305216Lixin Yue * - Neither the name of the Motorola, Inc. nor the names of its contributors 175cc617943765df27844e459362c4bc1821305216Lixin Yue * may be used to endorse or promote products derived from this software 185cc617943765df27844e459362c4bc1821305216Lixin Yue * without specific prior written permission. 195cc617943765df27844e459362c4bc1821305216Lixin Yue * 205cc617943765df27844e459362c4bc1821305216Lixin Yue * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 215cc617943765df27844e459362c4bc1821305216Lixin Yue * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 225cc617943765df27844e459362c4bc1821305216Lixin Yue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 235cc617943765df27844e459362c4bc1821305216Lixin Yue * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 245cc617943765df27844e459362c4bc1821305216Lixin Yue * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 255cc617943765df27844e459362c4bc1821305216Lixin Yue * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 265cc617943765df27844e459362c4bc1821305216Lixin Yue * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 275cc617943765df27844e459362c4bc1821305216Lixin Yue * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 285cc617943765df27844e459362c4bc1821305216Lixin Yue * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 295cc617943765df27844e459362c4bc1821305216Lixin Yue * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 305cc617943765df27844e459362c4bc1821305216Lixin Yue * POSSIBILITY OF SUCH DAMAGE. 315cc617943765df27844e459362c4bc1821305216Lixin Yue */ 325cc617943765df27844e459362c4bc1821305216Lixin Yue 335cc617943765df27844e459362c4bc1821305216Lixin Yuepackage com.android.bluetooth.opp; 345cc617943765df27844e459362c4bc1821305216Lixin Yue 355cc617943765df27844e459362c4bc1821305216Lixin Yueimport com.android.bluetooth.R; 365cc617943765df27844e459362c4bc1821305216Lixin Yue 375cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.app.Activity; 385cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.app.AlertDialog; 39de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yueimport android.bluetooth.BluetoothAdapter; 405cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.content.DialogInterface; 415cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.content.Intent; 425cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.database.Cursor; 435cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.net.Uri; 445cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.os.Bundle; 455cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.util.Log; 465cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.view.ContextMenu; 475cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.view.Menu; 485cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.view.MenuInflater; 495cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.view.MenuItem; 505cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.view.View; 515cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.view.ContextMenu.ContextMenuInfo; 525cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.widget.AdapterView; 535cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.widget.ListView; 545cc617943765df27844e459362c4bc1821305216Lixin Yueimport android.widget.AdapterView.OnItemClickListener; 555cc617943765df27844e459362c4bc1821305216Lixin Yue 565cc617943765df27844e459362c4bc1821305216Lixin Yue/** 575cc617943765df27844e459362c4bc1821305216Lixin Yue * View showing the user's finished bluetooth opp transfers that the user does 585cc617943765df27844e459362c4bc1821305216Lixin Yue * not confirm. Including outbound and inbound transfers, both successful and 595cc617943765df27844e459362c4bc1821305216Lixin Yue * failed. * 605cc617943765df27844e459362c4bc1821305216Lixin Yue */ 615cc617943765df27844e459362c4bc1821305216Lixin Yuepublic class BluetoothOppTransferHistory extends Activity implements 625cc617943765df27844e459362c4bc1821305216Lixin Yue View.OnCreateContextMenuListener, OnItemClickListener { 635cc617943765df27844e459362c4bc1821305216Lixin Yue private static final String TAG = "BluetoothOppTransferHistory"; 645cc617943765df27844e459362c4bc1821305216Lixin Yue 655cc617943765df27844e459362c4bc1821305216Lixin Yue private static final boolean V = Constants.VERBOSE; 665cc617943765df27844e459362c4bc1821305216Lixin Yue 675cc617943765df27844e459362c4bc1821305216Lixin Yue private ListView mListView; 685cc617943765df27844e459362c4bc1821305216Lixin Yue 695cc617943765df27844e459362c4bc1821305216Lixin Yue private Cursor mTransferCursor; 705cc617943765df27844e459362c4bc1821305216Lixin Yue 715cc617943765df27844e459362c4bc1821305216Lixin Yue private BluetoothOppTransferAdapter mTransferAdapter; 725cc617943765df27844e459362c4bc1821305216Lixin Yue 735cc617943765df27844e459362c4bc1821305216Lixin Yue private int mIdColumnId; 745cc617943765df27844e459362c4bc1821305216Lixin Yue 755cc617943765df27844e459362c4bc1821305216Lixin Yue private int mContextMenuPosition; 765cc617943765df27844e459362c4bc1821305216Lixin Yue 77de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue /** Class to handle Notification Manager updates */ 78de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue private BluetoothOppNotification mNotifier; 79de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue 805cc617943765df27844e459362c4bc1821305216Lixin Yue @Override 815cc617943765df27844e459362c4bc1821305216Lixin Yue public void onCreate(Bundle icicle) { 825cc617943765df27844e459362c4bc1821305216Lixin Yue super.onCreate(icicle); 835cc617943765df27844e459362c4bc1821305216Lixin Yue setContentView(R.layout.bluetooth_transfers_page); 845cc617943765df27844e459362c4bc1821305216Lixin Yue mListView = (ListView)findViewById(R.id.list); 855cc617943765df27844e459362c4bc1821305216Lixin Yue mListView.setEmptyView(findViewById(R.id.empty)); 865cc617943765df27844e459362c4bc1821305216Lixin Yue 875cc617943765df27844e459362c4bc1821305216Lixin Yue String direction; 885cc617943765df27844e459362c4bc1821305216Lixin Yue int dir = getIntent().getIntExtra("direction", 0); 895cc617943765df27844e459362c4bc1821305216Lixin Yue if (dir == BluetoothShare.DIRECTION_OUTBOUND) { 905cc617943765df27844e459362c4bc1821305216Lixin Yue setTitle(getText(R.string.outbound_history_title)); 915cc617943765df27844e459362c4bc1821305216Lixin Yue direction = "(" + BluetoothShare.DIRECTION + " == " + BluetoothShare.DIRECTION_OUTBOUND 925cc617943765df27844e459362c4bc1821305216Lixin Yue + ")"; 935cc617943765df27844e459362c4bc1821305216Lixin Yue } else { 945cc617943765df27844e459362c4bc1821305216Lixin Yue setTitle(getText(R.string.inbound_history_title)); 955cc617943765df27844e459362c4bc1821305216Lixin Yue direction = "(" + BluetoothShare.DIRECTION + " == " + BluetoothShare.DIRECTION_INBOUND 965cc617943765df27844e459362c4bc1821305216Lixin Yue + ")"; 975cc617943765df27844e459362c4bc1821305216Lixin Yue } 985cc617943765df27844e459362c4bc1821305216Lixin Yue 995cc617943765df27844e459362c4bc1821305216Lixin Yue final String selection = BluetoothShare.STATUS + " >= '200' AND " + "(" 1005cc617943765df27844e459362c4bc1821305216Lixin Yue + BluetoothShare.VISIBILITY + " IS NULL OR " + BluetoothShare.VISIBILITY + " == '" 1015cc617943765df27844e459362c4bc1821305216Lixin Yue + BluetoothShare.VISIBILITY_VISIBLE + "'" + ")" + " AND " + direction; 1025cc617943765df27844e459362c4bc1821305216Lixin Yue final String sortOrder = BluetoothShare.TIMESTAMP + " DESC"; 1035cc617943765df27844e459362c4bc1821305216Lixin Yue 1045cc617943765df27844e459362c4bc1821305216Lixin Yue mTransferCursor = managedQuery(BluetoothShare.CONTENT_URI, new String[] { 1055cc617943765df27844e459362c4bc1821305216Lixin Yue "_id", BluetoothShare.FILENAME_HINT, BluetoothShare.STATUS, 1065cc617943765df27844e459362c4bc1821305216Lixin Yue BluetoothShare.TOTAL_BYTES, BluetoothShare._DATA, BluetoothShare.TIMESTAMP, 1075cc617943765df27844e459362c4bc1821305216Lixin Yue BluetoothShare.VISIBILITY, BluetoothShare.DESTINATION, BluetoothShare.DIRECTION 1085cc617943765df27844e459362c4bc1821305216Lixin Yue }, selection, sortOrder); 1095cc617943765df27844e459362c4bc1821305216Lixin Yue 1105cc617943765df27844e459362c4bc1821305216Lixin Yue // only attach everything to the listbox if we can access 1115cc617943765df27844e459362c4bc1821305216Lixin Yue // the transfer database. Otherwise, just show it empty 1125cc617943765df27844e459362c4bc1821305216Lixin Yue if (mTransferCursor != null) { 1135cc617943765df27844e459362c4bc1821305216Lixin Yue mIdColumnId = mTransferCursor.getColumnIndexOrThrow(BluetoothShare._ID); 1145cc617943765df27844e459362c4bc1821305216Lixin Yue // Create a list "controller" for the data 1155cc617943765df27844e459362c4bc1821305216Lixin Yue mTransferAdapter = new BluetoothOppTransferAdapter(this, 1165cc617943765df27844e459362c4bc1821305216Lixin Yue R.layout.bluetooth_transfer_item, mTransferCursor); 1175cc617943765df27844e459362c4bc1821305216Lixin Yue mListView.setAdapter(mTransferAdapter); 1185cc617943765df27844e459362c4bc1821305216Lixin Yue mListView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET); 1195cc617943765df27844e459362c4bc1821305216Lixin Yue mListView.setOnCreateContextMenuListener(this); 1205cc617943765df27844e459362c4bc1821305216Lixin Yue mListView.setOnItemClickListener(this); 1215cc617943765df27844e459362c4bc1821305216Lixin Yue } 122de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue 123de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue mNotifier = new BluetoothOppNotification(this); 1245cc617943765df27844e459362c4bc1821305216Lixin Yue } 1255cc617943765df27844e459362c4bc1821305216Lixin Yue 1265cc617943765df27844e459362c4bc1821305216Lixin Yue @Override 1275cc617943765df27844e459362c4bc1821305216Lixin Yue public boolean onCreateOptionsMenu(Menu menu) { 1285cc617943765df27844e459362c4bc1821305216Lixin Yue if (mTransferCursor != null) { 1295cc617943765df27844e459362c4bc1821305216Lixin Yue MenuInflater inflater = getMenuInflater(); 1305cc617943765df27844e459362c4bc1821305216Lixin Yue inflater.inflate(R.menu.transferhistory, menu); 1315cc617943765df27844e459362c4bc1821305216Lixin Yue } 1325cc617943765df27844e459362c4bc1821305216Lixin Yue return true; 1335cc617943765df27844e459362c4bc1821305216Lixin Yue } 1345cc617943765df27844e459362c4bc1821305216Lixin Yue 1355cc617943765df27844e459362c4bc1821305216Lixin Yue @Override 1365cc617943765df27844e459362c4bc1821305216Lixin Yue public boolean onPrepareOptionsMenu(Menu menu) { 1375cc617943765df27844e459362c4bc1821305216Lixin Yue boolean showClear = getClearableCount() > 0; 1385cc617943765df27844e459362c4bc1821305216Lixin Yue menu.findItem(R.id.transfer_menu_clear_all).setEnabled(showClear); 1395cc617943765df27844e459362c4bc1821305216Lixin Yue return super.onPrepareOptionsMenu(menu); 1405cc617943765df27844e459362c4bc1821305216Lixin Yue } 1415cc617943765df27844e459362c4bc1821305216Lixin Yue 1425cc617943765df27844e459362c4bc1821305216Lixin Yue @Override 1435cc617943765df27844e459362c4bc1821305216Lixin Yue public boolean onOptionsItemSelected(MenuItem item) { 1445cc617943765df27844e459362c4bc1821305216Lixin Yue switch (item.getItemId()) { 1455cc617943765df27844e459362c4bc1821305216Lixin Yue case R.id.transfer_menu_clear_all: 1465cc617943765df27844e459362c4bc1821305216Lixin Yue promptClearList(); 1475cc617943765df27844e459362c4bc1821305216Lixin Yue return true; 1485cc617943765df27844e459362c4bc1821305216Lixin Yue } 1495cc617943765df27844e459362c4bc1821305216Lixin Yue return false; 1505cc617943765df27844e459362c4bc1821305216Lixin Yue } 1515cc617943765df27844e459362c4bc1821305216Lixin Yue 1525cc617943765df27844e459362c4bc1821305216Lixin Yue @Override 1535cc617943765df27844e459362c4bc1821305216Lixin Yue public boolean onContextItemSelected(MenuItem item) { 1545cc617943765df27844e459362c4bc1821305216Lixin Yue mTransferCursor.moveToPosition(mContextMenuPosition); 1555cc617943765df27844e459362c4bc1821305216Lixin Yue switch (item.getItemId()) { 1565cc617943765df27844e459362c4bc1821305216Lixin Yue case R.id.transfer_menu_open: 1575cc617943765df27844e459362c4bc1821305216Lixin Yue openCompleteTransfer(); 158de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue updateNotificationWhenBtDisabled(); 1595cc617943765df27844e459362c4bc1821305216Lixin Yue return true; 1605cc617943765df27844e459362c4bc1821305216Lixin Yue 1615cc617943765df27844e459362c4bc1821305216Lixin Yue case R.id.transfer_menu_clear: 1625cc617943765df27844e459362c4bc1821305216Lixin Yue int sessionId = mTransferCursor.getInt(mIdColumnId); 1635cc617943765df27844e459362c4bc1821305216Lixin Yue Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + sessionId); 1645cc617943765df27844e459362c4bc1821305216Lixin Yue BluetoothOppUtility.updateVisibilityToHidden(this, contentUri); 165de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue updateNotificationWhenBtDisabled(); 1665cc617943765df27844e459362c4bc1821305216Lixin Yue return true; 1675cc617943765df27844e459362c4bc1821305216Lixin Yue } 1685cc617943765df27844e459362c4bc1821305216Lixin Yue return false; 1695cc617943765df27844e459362c4bc1821305216Lixin Yue } 1705cc617943765df27844e459362c4bc1821305216Lixin Yue 1715cc617943765df27844e459362c4bc1821305216Lixin Yue @Override 1725cc617943765df27844e459362c4bc1821305216Lixin Yue public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 1735cc617943765df27844e459362c4bc1821305216Lixin Yue if (mTransferCursor != null) { 1745cc617943765df27844e459362c4bc1821305216Lixin Yue AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; 1755cc617943765df27844e459362c4bc1821305216Lixin Yue mTransferCursor.moveToPosition(info.position); 1765cc617943765df27844e459362c4bc1821305216Lixin Yue mContextMenuPosition = info.position; 1775cc617943765df27844e459362c4bc1821305216Lixin Yue 1785cc617943765df27844e459362c4bc1821305216Lixin Yue String fileName = mTransferCursor.getString(mTransferCursor 1795cc617943765df27844e459362c4bc1821305216Lixin Yue .getColumnIndexOrThrow(BluetoothShare.FILENAME_HINT)); 1805cc617943765df27844e459362c4bc1821305216Lixin Yue if (fileName == null) { 1815cc617943765df27844e459362c4bc1821305216Lixin Yue fileName = this.getString(R.string.unknown_file); 1825cc617943765df27844e459362c4bc1821305216Lixin Yue } 1835cc617943765df27844e459362c4bc1821305216Lixin Yue menu.setHeaderTitle(fileName); 1845cc617943765df27844e459362c4bc1821305216Lixin Yue 1855cc617943765df27844e459362c4bc1821305216Lixin Yue MenuInflater inflater = getMenuInflater(); 1865cc617943765df27844e459362c4bc1821305216Lixin Yue inflater.inflate(R.menu.transferhistorycontextfinished, menu); 1875cc617943765df27844e459362c4bc1821305216Lixin Yue } 1885cc617943765df27844e459362c4bc1821305216Lixin Yue } 1895cc617943765df27844e459362c4bc1821305216Lixin Yue 1905cc617943765df27844e459362c4bc1821305216Lixin Yue /** 1915cc617943765df27844e459362c4bc1821305216Lixin Yue * Prompt the user if they would like to clear the transfer history 1925cc617943765df27844e459362c4bc1821305216Lixin Yue */ 1935cc617943765df27844e459362c4bc1821305216Lixin Yue private void promptClearList() { 1945cc617943765df27844e459362c4bc1821305216Lixin Yue new AlertDialog.Builder(this).setTitle(R.string.transfer_clear_dlg_title).setMessage( 1955cc617943765df27844e459362c4bc1821305216Lixin Yue R.string.transfer_clear_dlg_msg).setPositiveButton(android.R.string.ok, 1965cc617943765df27844e459362c4bc1821305216Lixin Yue new DialogInterface.OnClickListener() { 1975cc617943765df27844e459362c4bc1821305216Lixin Yue public void onClick(DialogInterface dialog, int whichButton) { 1985cc617943765df27844e459362c4bc1821305216Lixin Yue clearAllDownloads(); 1995cc617943765df27844e459362c4bc1821305216Lixin Yue } 2005cc617943765df27844e459362c4bc1821305216Lixin Yue }).setNegativeButton(android.R.string.cancel, null).show(); 2015cc617943765df27844e459362c4bc1821305216Lixin Yue } 2025cc617943765df27844e459362c4bc1821305216Lixin Yue 2035cc617943765df27844e459362c4bc1821305216Lixin Yue /** 2045cc617943765df27844e459362c4bc1821305216Lixin Yue * Get the number of finished transfers, including error and success. 2055cc617943765df27844e459362c4bc1821305216Lixin Yue */ 2065cc617943765df27844e459362c4bc1821305216Lixin Yue private int getClearableCount() { 2075cc617943765df27844e459362c4bc1821305216Lixin Yue int count = 0; 2085cc617943765df27844e459362c4bc1821305216Lixin Yue if (mTransferCursor.moveToFirst()) { 2095cc617943765df27844e459362c4bc1821305216Lixin Yue while (!mTransferCursor.isAfterLast()) { 2105cc617943765df27844e459362c4bc1821305216Lixin Yue int statusColumnId = mTransferCursor.getColumnIndexOrThrow(BluetoothShare.STATUS); 2115cc617943765df27844e459362c4bc1821305216Lixin Yue int status = mTransferCursor.getInt(statusColumnId); 2125cc617943765df27844e459362c4bc1821305216Lixin Yue if (BluetoothShare.isStatusCompleted(status)) { 2135cc617943765df27844e459362c4bc1821305216Lixin Yue count++; 2145cc617943765df27844e459362c4bc1821305216Lixin Yue } 2155cc617943765df27844e459362c4bc1821305216Lixin Yue mTransferCursor.moveToNext(); 2165cc617943765df27844e459362c4bc1821305216Lixin Yue } 2175cc617943765df27844e459362c4bc1821305216Lixin Yue } 2185cc617943765df27844e459362c4bc1821305216Lixin Yue return count; 2195cc617943765df27844e459362c4bc1821305216Lixin Yue } 2205cc617943765df27844e459362c4bc1821305216Lixin Yue 2215cc617943765df27844e459362c4bc1821305216Lixin Yue /** 2225cc617943765df27844e459362c4bc1821305216Lixin Yue * Clear all finished transfers, error and success transfer items. 2235cc617943765df27844e459362c4bc1821305216Lixin Yue */ 2245cc617943765df27844e459362c4bc1821305216Lixin Yue private void clearAllDownloads() { 2255cc617943765df27844e459362c4bc1821305216Lixin Yue if (mTransferCursor.moveToFirst()) { 2265cc617943765df27844e459362c4bc1821305216Lixin Yue while (!mTransferCursor.isAfterLast()) { 2275cc617943765df27844e459362c4bc1821305216Lixin Yue int sessionId = mTransferCursor.getInt(mIdColumnId); 2285cc617943765df27844e459362c4bc1821305216Lixin Yue Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + sessionId); 2295cc617943765df27844e459362c4bc1821305216Lixin Yue BluetoothOppUtility.updateVisibilityToHidden(this, contentUri); 2305cc617943765df27844e459362c4bc1821305216Lixin Yue 2315cc617943765df27844e459362c4bc1821305216Lixin Yue mTransferCursor.moveToNext(); 2325cc617943765df27844e459362c4bc1821305216Lixin Yue } 233de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue updateNotificationWhenBtDisabled(); 2345cc617943765df27844e459362c4bc1821305216Lixin Yue } 2355cc617943765df27844e459362c4bc1821305216Lixin Yue } 2365cc617943765df27844e459362c4bc1821305216Lixin Yue 2375cc617943765df27844e459362c4bc1821305216Lixin Yue /* 2385cc617943765df27844e459362c4bc1821305216Lixin Yue * (non-Javadoc) 2395cc617943765df27844e459362c4bc1821305216Lixin Yue * @see 2405cc617943765df27844e459362c4bc1821305216Lixin Yue * android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget 2415cc617943765df27844e459362c4bc1821305216Lixin Yue * .AdapterView, android.view.View, int, long) 2425cc617943765df27844e459362c4bc1821305216Lixin Yue */ 243a930b6831d0c70b6c5d34e548e6b1dceaa6529a0Mohammad Shamsi public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 2445cc617943765df27844e459362c4bc1821305216Lixin Yue // Open the selected item 2455cc617943765df27844e459362c4bc1821305216Lixin Yue mTransferCursor.moveToPosition(position); 2465cc617943765df27844e459362c4bc1821305216Lixin Yue openCompleteTransfer(); 247de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue updateNotificationWhenBtDisabled(); 2485cc617943765df27844e459362c4bc1821305216Lixin Yue } 2495cc617943765df27844e459362c4bc1821305216Lixin Yue 2505cc617943765df27844e459362c4bc1821305216Lixin Yue /** 2515cc617943765df27844e459362c4bc1821305216Lixin Yue * Open the selected finished transfer. mDownloadCursor must be moved to 2525cc617943765df27844e459362c4bc1821305216Lixin Yue * appropriate position before calling this function 2535cc617943765df27844e459362c4bc1821305216Lixin Yue */ 2545cc617943765df27844e459362c4bc1821305216Lixin Yue private void openCompleteTransfer() { 2555cc617943765df27844e459362c4bc1821305216Lixin Yue int sessionId = mTransferCursor.getInt(mIdColumnId); 2565cc617943765df27844e459362c4bc1821305216Lixin Yue Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + sessionId); 2575cc617943765df27844e459362c4bc1821305216Lixin Yue BluetoothOppTransferInfo transInfo = new BluetoothOppTransferInfo(); 2585cc617943765df27844e459362c4bc1821305216Lixin Yue transInfo = BluetoothOppUtility.queryRecord(this, contentUri); 2595cc617943765df27844e459362c4bc1821305216Lixin Yue if (transInfo == null) { 2605cc617943765df27844e459362c4bc1821305216Lixin Yue Log.e(TAG, "Error: Can not get data from db"); 2615cc617943765df27844e459362c4bc1821305216Lixin Yue return; 2625cc617943765df27844e459362c4bc1821305216Lixin Yue } 2635cc617943765df27844e459362c4bc1821305216Lixin Yue if (transInfo.mDirection == BluetoothShare.DIRECTION_INBOUND 2645cc617943765df27844e459362c4bc1821305216Lixin Yue && BluetoothShare.isStatusSuccess(transInfo.mStatus)) { 2655cc617943765df27844e459362c4bc1821305216Lixin Yue // if received file successfully, open this file 2665cc617943765df27844e459362c4bc1821305216Lixin Yue BluetoothOppUtility.updateVisibilityToHidden(this, contentUri); 2675cc617943765df27844e459362c4bc1821305216Lixin Yue BluetoothOppUtility.openReceivedFile(this, transInfo.mFileName, transInfo.mFileType, 2685cc617943765df27844e459362c4bc1821305216Lixin Yue transInfo.mTimeStamp, contentUri); 2695cc617943765df27844e459362c4bc1821305216Lixin Yue } else { 2705cc617943765df27844e459362c4bc1821305216Lixin Yue Intent in = new Intent(this, BluetoothOppTransferActivity.class); 2715cc617943765df27844e459362c4bc1821305216Lixin Yue in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 2725cc617943765df27844e459362c4bc1821305216Lixin Yue in.setData(contentUri); 2735cc617943765df27844e459362c4bc1821305216Lixin Yue this.startActivity(in); 2745cc617943765df27844e459362c4bc1821305216Lixin Yue } 2755cc617943765df27844e459362c4bc1821305216Lixin Yue } 276de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue 277de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue /** 278de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue * When Bluetooth is disabled, notification can not be updated by 279de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue * ContentObserver in OppService, so need update manually. 280de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue */ 281de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue private void updateNotificationWhenBtDisabled() { 282de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 283de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue if (!adapter.isEnabled()) { 284de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue if (V) Log.v(TAG, "Bluetooth is not enabled, update notification manually."); 285de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue mNotifier.updateNotification(); 286de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue mNotifier.finishNotification(); 287de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue } 288de773e60fed15a4ad13325089a5609c9bc6ede59Lixin Yue } 2895cc617943765df27844e459362c4bc1821305216Lixin Yue} 290