diff --git a/samples/BluetoothChat/AndroidManifest.xml b/samples/BluetoothChat/AndroidManifest.xml index 199c6a567..895e633d4 100644 --- a/samples/BluetoothChat/AndroidManifest.xml +++ b/samples/BluetoothChat/AndroidManifest.xml @@ -33,7 +33,7 @@ diff --git a/samples/BluetoothChat/res/menu/option_menu.xml b/samples/BluetoothChat/res/menu/option_menu.xml index 46df04367..815940119 100644 --- a/samples/BluetoothChat/res/menu/option_menu.xml +++ b/samples/BluetoothChat/res/menu/option_menu.xml @@ -16,8 +16,10 @@ + android:title="@string/connect" + android:showAsAction="ifRoom" /> + android:title="@string/discoverable" + android:showAsAction="ifRoom" /> diff --git a/samples/BluetoothChat/res/values/strings.xml b/samples/BluetoothChat/res/values/strings.xml index 1c4767671..383deb069 100644 --- a/samples/BluetoothChat/res/values/strings.xml +++ b/samples/BluetoothChat/res/values/strings.xml @@ -14,7 +14,7 @@ limitations under the License. --> - + Bluetooth Chat @@ -22,7 +22,7 @@ You are not connected to a device Bluetooth was not enabled. Leaving Bluetooth Chat. connecting... - connected: + connected to %1$s not connected diff --git a/samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChat.java b/samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChat.java index d05bbd611..0aaefcf96 100644 --- a/samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChat.java +++ b/samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChat.java @@ -16,6 +16,7 @@ package com.example.android.BluetoothChat; +import android.app.ActionBar; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; @@ -63,7 +64,6 @@ public class BluetoothChat extends Activity { private static final int REQUEST_ENABLE_BT = 2; // Layout Views - private TextView mTitle; private ListView mConversationView; private EditText mOutEditText; private Button mSendButton; @@ -86,14 +86,7 @@ public class BluetoothChat extends Activity { if(D) Log.e(TAG, "+++ ON CREATE +++"); // Set up the window layout - requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 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 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 private final Handler mHandler = new Handler() { @Override @@ -245,16 +248,15 @@ public class BluetoothChat extends Activity { if(D) Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1); switch (msg.arg1) { case BluetoothChatService.STATE_CONNECTED: - mTitle.setText(R.string.title_connected_to); - mTitle.append(mConnectedDeviceName); + setStatus(getString(R.string.title_connected_to, mConnectedDeviceName)); mConversationArrayAdapter.clear(); break; case BluetoothChatService.STATE_CONNECTING: - mTitle.setText(R.string.title_connecting); + setStatus(R.string.title_connecting); break; case BluetoothChatService.STATE_LISTEN: case BluetoothChatService.STATE_NONE: - mTitle.setText(R.string.title_not_connected); + setStatus(R.string.title_not_connected); break; } break; @@ -293,7 +295,7 @@ public class BluetoothChat extends Activity { // Get the device MAC address String address = data.getExtras() .getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); - // Get the BLuetoothDevice object + // Get the BluetoothDevice object BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); // Attempt to connect to the device mChatService.connect(device); @@ -305,7 +307,7 @@ public class BluetoothChat extends Activity { // Bluetooth is now enabled, so set up a chat session setupChat(); } 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"); Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); finish(); diff --git a/samples/BluetoothChat/src/com/example/android/BluetoothChat/DeviceListActivity.java b/samples/BluetoothChat/src/com/example/android/BluetoothChat/DeviceListActivity.java index fa722a202..3aefa12fa 100644 --- a/samples/BluetoothChat/src/com/example/android/BluetoothChat/DeviceListActivity.java +++ b/samples/BluetoothChat/src/com/example/android/BluetoothChat/DeviceListActivity.java @@ -64,7 +64,7 @@ public class DeviceListActivity extends Activity { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.device_list); - // Set result CANCELED incase the user backs out + // Set result CANCELED in case the user backs out setResult(Activity.RESULT_CANCELED); // Initialize the button to perform device discovery