development
リビジョン | c09e5a4ec9a9d51afbc4e97d8fdb0a8cc924594b (tree) |
---|---|
日時 | 2011-01-14 10:46:33 |
作者 | Jake Hamby <jhamby@goog...> |
コミッター | Android Git Automerger |
am 3695fe3a: Fix BT chat sample app to use Honeycomb action bar.
* commit '3695fe3a4242504d523d0222306775ada5cd6430':
@@ -33,7 +33,7 @@ | ||
33 | 33 | </activity> |
34 | 34 | <activity android:name=".DeviceListActivity" |
35 | 35 | android:label="@string/select_device" |
36 | - android:theme="@android:style/Theme.Dialog" | |
36 | + android:theme="@android:style/Theme.Holo.Dialog" | |
37 | 37 | android:configChanges="orientation|keyboardHidden" /> |
38 | 38 | </application> |
39 | 39 | </manifest> |
@@ -16,8 +16,10 @@ | ||
16 | 16 | <menu xmlns:android="http://schemas.android.com/apk/res/android"> |
17 | 17 | <item android:id="@+id/scan" |
18 | 18 | android:icon="@android:drawable/ic_menu_search" |
19 | - android:title="@string/connect" /> | |
19 | + android:title="@string/connect" | |
20 | + android:showAsAction="ifRoom" /> | |
20 | 21 | <item android:id="@+id/discoverable" |
21 | 22 | android:icon="@android:drawable/ic_menu_mylocation" |
22 | - android:title="@string/discoverable" /> | |
23 | + android:title="@string/discoverable" | |
24 | + android:showAsAction="ifRoom" /> | |
23 | 25 | </menu> |
@@ -14,7 +14,7 @@ | ||
14 | 14 | limitations under the License. |
15 | 15 | --> |
16 | 16 | |
17 | -<resources> | |
17 | +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> | |
18 | 18 | <string name="app_name">Bluetooth Chat</string> |
19 | 19 | |
20 | 20 | <!-- BluetoothChat --> |
@@ -22,7 +22,7 @@ | ||
22 | 22 | <string name="not_connected">You are not connected to a device</string> |
23 | 23 | <string name="bt_not_enabled_leaving">Bluetooth was not enabled. Leaving Bluetooth Chat.</string> |
24 | 24 | <string name="title_connecting">connecting...</string> |
25 | - <string name="title_connected_to">connected: </string> | |
25 | + <string name="title_connected_to">connected to <xliff:g id="device_name">%1$s</xliff:g></string> | |
26 | 26 | <string name="title_not_connected">not connected</string> |
27 | 27 | |
28 | 28 | <!-- DeviceListActivity --> |
@@ -16,6 +16,7 @@ | ||
16 | 16 | |
17 | 17 | package com.example.android.BluetoothChat; |
18 | 18 | |
19 | +import android.app.ActionBar; | |
19 | 20 | import android.app.Activity; |
20 | 21 | import android.bluetooth.BluetoothAdapter; |
21 | 22 | import android.bluetooth.BluetoothDevice; |
@@ -63,7 +64,6 @@ public class BluetoothChat extends Activity { | ||
63 | 64 | private static final int REQUEST_ENABLE_BT = 2; |
64 | 65 | |
65 | 66 | // Layout Views |
66 | - private TextView mTitle; | |
67 | 67 | private ListView mConversationView; |
68 | 68 | private EditText mOutEditText; |
69 | 69 | private Button mSendButton; |
@@ -86,14 +86,7 @@ public class BluetoothChat extends Activity { | ||
86 | 86 | if(D) Log.e(TAG, "+++ ON CREATE +++"); |
87 | 87 | |
88 | 88 | // Set up the window layout |
89 | - requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); | |
90 | 89 | setContentView(R.layout.main); |
91 | - getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title); | |
92 | - | |
93 | - // Set up the custom title | |
94 | - mTitle = (TextView) findViewById(R.id.title_left_text); | |
95 | - mTitle.setText(R.string.app_name); | |
96 | - mTitle = (TextView) findViewById(R.id.title_right_text); | |
97 | 90 | |
98 | 91 | // Get local Bluetooth adapter |
99 | 92 | mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); |
@@ -236,6 +229,16 @@ public class BluetoothChat extends Activity { | ||
236 | 229 | } |
237 | 230 | }; |
238 | 231 | |
232 | + private final void setStatus(int resId) { | |
233 | + final ActionBar actionBar = getActionBar(); | |
234 | + actionBar.setSubtitle(resId); | |
235 | + } | |
236 | + | |
237 | + private final void setStatus(CharSequence subTitle) { | |
238 | + final ActionBar actionBar = getActionBar(); | |
239 | + actionBar.setSubtitle(subTitle); | |
240 | + } | |
241 | + | |
239 | 242 | // The Handler that gets information back from the BluetoothChatService |
240 | 243 | private final Handler mHandler = new Handler() { |
241 | 244 | @Override |
@@ -245,16 +248,15 @@ public class BluetoothChat extends Activity { | ||
245 | 248 | if(D) Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1); |
246 | 249 | switch (msg.arg1) { |
247 | 250 | case BluetoothChatService.STATE_CONNECTED: |
248 | - mTitle.setText(R.string.title_connected_to); | |
249 | - mTitle.append(mConnectedDeviceName); | |
251 | + setStatus(getString(R.string.title_connected_to, mConnectedDeviceName)); | |
250 | 252 | mConversationArrayAdapter.clear(); |
251 | 253 | break; |
252 | 254 | case BluetoothChatService.STATE_CONNECTING: |
253 | - mTitle.setText(R.string.title_connecting); | |
255 | + setStatus(R.string.title_connecting); | |
254 | 256 | break; |
255 | 257 | case BluetoothChatService.STATE_LISTEN: |
256 | 258 | case BluetoothChatService.STATE_NONE: |
257 | - mTitle.setText(R.string.title_not_connected); | |
259 | + setStatus(R.string.title_not_connected); | |
258 | 260 | break; |
259 | 261 | } |
260 | 262 | break; |
@@ -293,7 +295,7 @@ public class BluetoothChat extends Activity { | ||
293 | 295 | // Get the device MAC address |
294 | 296 | String address = data.getExtras() |
295 | 297 | .getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); |
296 | - // Get the BLuetoothDevice object | |
298 | + // Get the BluetoothDevice object | |
297 | 299 | BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); |
298 | 300 | // Attempt to connect to the device |
299 | 301 | mChatService.connect(device); |
@@ -305,7 +307,7 @@ public class BluetoothChat extends Activity { | ||
305 | 307 | // Bluetooth is now enabled, so set up a chat session |
306 | 308 | setupChat(); |
307 | 309 | } else { |
308 | - // User did not enable Bluetooth or an error occured | |
310 | + // User did not enable Bluetooth or an error occurred | |
309 | 311 | Log.d(TAG, "BT not enabled"); |
310 | 312 | Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); |
311 | 313 | finish(); |
@@ -64,7 +64,7 @@ public class DeviceListActivity extends Activity { | ||
64 | 64 | requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); |
65 | 65 | setContentView(R.layout.device_list); |
66 | 66 | |
67 | - // Set result CANCELED incase the user backs out | |
67 | + // Set result CANCELED in case the user backs out | |
68 | 68 | setResult(Activity.RESULT_CANCELED); |
69 | 69 | |
70 | 70 | // Initialize the button to perform device discovery |