am 3695fe3a: Fix BT chat sample app to use Honeycomb action bar.
* commit '3695fe3a4242504d523d0222306775ada5cd6430': Fix BT chat sample app to use Honeycomb action bar.
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user