am c09e5a4e: am 3695fe3a: Fix BT chat sample app to use Honeycomb action bar.

* commit 'c09e5a4ec9a9d51afbc4e97d8fdb0a8cc924594b':
  Fix BT chat sample app to use Honeycomb action bar.
This commit is contained in:
Jake Hamby
2011-01-13 17:48:22 -08:00
committed by Android Git Automerger
5 changed files with 24 additions and 20 deletions

View File

@@ -33,7 +33,7 @@
</activity> </activity>
<activity android:name=".DeviceListActivity" <activity android:name=".DeviceListActivity"
android:label="@string/select_device" android:label="@string/select_device"
android:theme="@android:style/Theme.Dialog" android:theme="@android:style/Theme.Holo.Dialog"
android:configChanges="orientation|keyboardHidden" /> android:configChanges="orientation|keyboardHidden" />
</application> </application>
</manifest> </manifest>

View File

@@ -16,8 +16,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/scan" <item android:id="@+id/scan"
android:icon="@android:drawable/ic_menu_search" android:icon="@android:drawable/ic_menu_search"
android:title="@string/connect" /> android:title="@string/connect"
android:showAsAction="ifRoom" />
<item android:id="@+id/discoverable" <item android:id="@+id/discoverable"
android:icon="@android:drawable/ic_menu_mylocation" android:icon="@android:drawable/ic_menu_mylocation"
android:title="@string/discoverable" /> android:title="@string/discoverable"
android:showAsAction="ifRoom" />
</menu> </menu>

View File

@@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
--> -->
<resources> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">Bluetooth Chat</string> <string name="app_name">Bluetooth Chat</string>
<!-- BluetoothChat --> <!-- BluetoothChat -->
@@ -22,7 +22,7 @@
<string name="not_connected">You are not connected to a device</string> <string name="not_connected">You are not connected to a device</string>
<string name="bt_not_enabled_leaving">Bluetooth was not enabled. Leaving Bluetooth Chat.</string> <string name="bt_not_enabled_leaving">Bluetooth was not enabled. Leaving Bluetooth Chat.</string>
<string name="title_connecting">connecting...</string> <string name="title_connecting">connecting...</string>
<string name="title_connected_to">connected: </string> <string name="title_connected_to">connected to <xliff:g id="device_name">%1$s</xliff:g></string>
<string name="title_not_connected">not connected</string> <string name="title_not_connected">not connected</string>
<!-- DeviceListActivity --> <!-- DeviceListActivity -->

View File

@@ -16,6 +16,7 @@
package com.example.android.BluetoothChat; package com.example.android.BluetoothChat;
import android.app.ActionBar;
import android.app.Activity; import android.app.Activity;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
@@ -63,7 +64,6 @@ public class BluetoothChat extends Activity {
private static final int REQUEST_ENABLE_BT = 2; private static final int REQUEST_ENABLE_BT = 2;
// Layout Views // Layout Views
private TextView mTitle;
private ListView mConversationView; private ListView mConversationView;
private EditText mOutEditText; private EditText mOutEditText;
private Button mSendButton; private Button mSendButton;
@@ -86,14 +86,7 @@ public class BluetoothChat extends Activity {
if(D) Log.e(TAG, "+++ ON CREATE +++"); if(D) Log.e(TAG, "+++ ON CREATE +++");
// Set up the window layout // Set up the window layout
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main); setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
// Set up the custom title
mTitle = (TextView) findViewById(R.id.title_left_text);
mTitle.setText(R.string.app_name);
mTitle = (TextView) findViewById(R.id.title_right_text);
// Get local Bluetooth adapter // Get local Bluetooth adapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
@@ -236,6 +229,16 @@ public class BluetoothChat extends Activity {
} }
}; };
private final void setStatus(int resId) {
final ActionBar actionBar = getActionBar();
actionBar.setSubtitle(resId);
}
private final void setStatus(CharSequence subTitle) {
final ActionBar actionBar = getActionBar();
actionBar.setSubtitle(subTitle);
}
// The Handler that gets information back from the BluetoothChatService // The Handler that gets information back from the BluetoothChatService
private final Handler mHandler = new Handler() { private final Handler mHandler = new Handler() {
@Override @Override
@@ -245,16 +248,15 @@ public class BluetoothChat extends Activity {
if(D) Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1); if(D) Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
switch (msg.arg1) { switch (msg.arg1) {
case BluetoothChatService.STATE_CONNECTED: case BluetoothChatService.STATE_CONNECTED:
mTitle.setText(R.string.title_connected_to); setStatus(getString(R.string.title_connected_to, mConnectedDeviceName));
mTitle.append(mConnectedDeviceName);
mConversationArrayAdapter.clear(); mConversationArrayAdapter.clear();
break; break;
case BluetoothChatService.STATE_CONNECTING: case BluetoothChatService.STATE_CONNECTING:
mTitle.setText(R.string.title_connecting); setStatus(R.string.title_connecting);
break; break;
case BluetoothChatService.STATE_LISTEN: case BluetoothChatService.STATE_LISTEN:
case BluetoothChatService.STATE_NONE: case BluetoothChatService.STATE_NONE:
mTitle.setText(R.string.title_not_connected); setStatus(R.string.title_not_connected);
break; break;
} }
break; break;
@@ -293,7 +295,7 @@ public class BluetoothChat extends Activity {
// Get the device MAC address // Get the device MAC address
String address = data.getExtras() String address = data.getExtras()
.getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); .getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
// Get the BLuetoothDevice object // Get the BluetoothDevice object
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
// Attempt to connect to the device // Attempt to connect to the device
mChatService.connect(device); mChatService.connect(device);
@@ -305,7 +307,7 @@ public class BluetoothChat extends Activity {
// Bluetooth is now enabled, so set up a chat session // Bluetooth is now enabled, so set up a chat session
setupChat(); setupChat();
} else { } else {
// User did not enable Bluetooth or an error occured // User did not enable Bluetooth or an error occurred
Log.d(TAG, "BT not enabled"); Log.d(TAG, "BT not enabled");
Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show();
finish(); finish();