summaryrefslogtreecommitdiffstats
path: root/samples/BluetoothChat
diff options
context:
space:
mode:
authorJake Hamby <jhamby@google.com>2011-01-13 16:59:47 -0800
committerJake Hamby <jhamby@google.com>2011-01-13 16:59:47 -0800
commit3695fe3a4242504d523d0222306775ada5cd6430 (patch)
tree1d4fc72cf521a884c754e5ad88975288a212569a /samples/BluetoothChat
parent3eb48a061aa2d6aafe7493bb3d83ea8f8d53a33d (diff)
downloadandroid_development-3695fe3a4242504d523d0222306775ada5cd6430.tar.gz
android_development-3695fe3a4242504d523d0222306775ada5cd6430.tar.bz2
android_development-3695fe3a4242504d523d0222306775ada5cd6430.zip
Fix BT chat sample app to use Honeycomb action bar.
The BT chat app previously used a custom title, which is no longer supported in Honeycomb with the default theme. It also required the option menu, which has been replaced with the action bar. Fixed the app to use the standard Honeycomb style and action bar. Bug: 3098795 Change-Id: I8f8656b261c6e15cc6b0b2f445087ff3baabb4d4
Diffstat (limited to 'samples/BluetoothChat')
-rw-r--r--samples/BluetoothChat/AndroidManifest.xml2
-rw-r--r--samples/BluetoothChat/res/menu/option_menu.xml6
-rw-r--r--samples/BluetoothChat/res/values/strings.xml4
-rw-r--r--samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChat.java30
-rw-r--r--samples/BluetoothChat/src/com/example/android/BluetoothChat/DeviceListActivity.java2
5 files changed, 24 insertions, 20 deletions
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 @@
</activity>
<activity android:name=".DeviceListActivity"
android:label="@string/select_device"
- android:theme="@android:style/Theme.Dialog"
+ android:theme="@android:style/Theme.Holo.Dialog"
android:configChanges="orientation|keyboardHidden" />
</application>
</manifest>
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 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/scan"
android:icon="@android:drawable/ic_menu_search"
- android:title="@string/connect" />
+ android:title="@string/connect"
+ android:showAsAction="ifRoom" />
<item android:id="@+id/discoverable"
android:icon="@android:drawable/ic_menu_mylocation"
- android:title="@string/discoverable" />
+ android:title="@string/discoverable"
+ android:showAsAction="ifRoom" />
</menu>
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.
-->
-<resources>
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">Bluetooth Chat</string>
<!-- BluetoothChat -->
@@ -22,7 +22,7 @@
<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="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>
<!-- DeviceListActivity -->
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