Allow p2p device rename
Change-Id: Ib61425da344f955b0a583716516181bdfbd4b504
This commit is contained in:
@@ -1420,15 +1420,17 @@
|
||||
<string name="wifi_p2p_peer_devices">Peer devices</string>
|
||||
<!-- Toast text for a failed connection initiation -->
|
||||
<string name="wifi_p2p_failed_connect_message">Couldn\'t connect.</string>
|
||||
<!-- Message text for failure to rename -->
|
||||
<string name="wifi_p2p_failed_rename_message">Failed to rename device.</string>
|
||||
<!-- Title for disconnect dialog -->
|
||||
<string name="wifi_p2p_disconnect_title">Disconnect?</string>
|
||||
<!-- Message test for disconnection from one device-->
|
||||
<!-- Message text for disconnection from one device-->
|
||||
<string name="wifi_p2p_disconnect_message">If you disconnect, your connection with <xliff:g id="peer_name">%1$s</xliff:g> will end.</string>
|
||||
<!-- Message test for disconnection from multiple devices-->
|
||||
<!-- Message text for disconnection from multiple devices-->
|
||||
<string name="wifi_p2p_disconnect_multiple_message">If you disconnect, your connection with <xliff:g id="peer_name">%1$s</xliff:g> and <xliff:g id="peer_count">%2$s</xliff:g> other devices will end.</string>
|
||||
<!-- Title for cancel connect dialog -->
|
||||
<string name="wifi_p2p_cancel_connect_title">Cancel invitation?</string>
|
||||
<!-- Message test for disconnection from one device-->
|
||||
<!-- Message text for disconnection from one device-->
|
||||
<string name="wifi_p2p_cancel_connect_message">Do you want to cancel invitation to connect with <xliff:g id="peer_name">%1$s</xliff:g>?</string>
|
||||
|
||||
<!-- Wifi AP settings-->
|
||||
|
@@ -47,6 +47,7 @@ import android.view.Gravity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Switch;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -71,9 +72,11 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
private final IntentFilter mIntentFilter = new IntentFilter();
|
||||
private WifiP2pManager mWifiP2pManager;
|
||||
private WifiP2pManager.Channel mChannel;
|
||||
private OnClickListener mRenameListener;
|
||||
private OnClickListener mDisconnectListener;
|
||||
private OnClickListener mCancelConnectListener;
|
||||
private WifiP2pPeer mSelectedWifiPeer;
|
||||
private EditText mDeviceNameText;
|
||||
|
||||
private boolean mWifiP2pEnabled;
|
||||
private boolean mWifiP2pSearching;
|
||||
@@ -84,6 +87,7 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
|
||||
private static final int DIALOG_DISCONNECT = 1;
|
||||
private static final int DIALOG_CANCEL_CONNECT = 2;
|
||||
private static final int DIALOG_RENAME = 3;
|
||||
|
||||
private WifiP2pDevice mThisDevice;
|
||||
private WifiP2pDeviceList mPeers = new WifiP2pDeviceList();
|
||||
@@ -153,6 +157,28 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
Log.e(TAG, "mWifiP2pManager is null !");
|
||||
}
|
||||
|
||||
mRenameListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
if (mWifiP2pManager != null) {
|
||||
mWifiP2pManager.setDeviceName(mChannel,
|
||||
mDeviceNameText.getText().toString(),
|
||||
new WifiP2pManager.ActionListener() {
|
||||
public void onSuccess() {
|
||||
if (DBG) Log.d(TAG, " device rename success");
|
||||
}
|
||||
public void onFailure(int reason) {
|
||||
Toast.makeText(getActivity(),
|
||||
R.string.wifi_p2p_failed_rename_message,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//disconnect dialog listener
|
||||
mDisconnectListener = new OnClickListener() {
|
||||
@Override
|
||||
@@ -258,7 +284,7 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
startSearch();
|
||||
return true;
|
||||
case MENU_ID_RENAME:
|
||||
//TODO: handle rename
|
||||
showDialog(DIALOG_RENAME);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
@@ -335,6 +361,15 @@ public class WifiP2pSettings extends SettingsPreferenceFragment
|
||||
.setNegativeButton(getActivity().getString(R.string.dlg_cancel), null)
|
||||
.create();
|
||||
return dialog;
|
||||
} else if (id == DIALOG_RENAME) {
|
||||
mDeviceNameText = new EditText(getActivity());
|
||||
AlertDialog dialog = new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.wifi_p2p_menu_rename)
|
||||
.setView(mDeviceNameText)
|
||||
.setPositiveButton(getActivity().getString(R.string.dlg_ok), mRenameListener)
|
||||
.setNegativeButton(getActivity().getString(R.string.dlg_cancel), null)
|
||||
.create();
|
||||
return dialog;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user