|
@@ -1,11 +1,15 @@
|
|
|
package de.tudarmstadt.informatik.hostage.sync.wifi_direct.ui;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
import android.app.ProgressDialog;
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
import android.net.wifi.p2p.WifiP2pDevice;
|
|
|
import android.net.wifi.p2p.WifiP2pInfo;
|
|
|
import android.os.Bundle;
|
|
|
+import android.provider.Settings;
|
|
|
import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
@@ -26,12 +30,39 @@ import de.tudarmstadt.informatik.hostage.sync.wifi_direct.BackgroundTask;
|
|
|
import de.tudarmstadt.informatik.hostage.sync.wifi_direct.WiFiP2pEventHandler;
|
|
|
import de.tudarmstadt.informatik.hostage.sync.wifi_direct.sync_tasks.SyncClientTask;
|
|
|
import de.tudarmstadt.informatik.hostage.sync.wifi_direct.sync_tasks.SyncHostTask;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
|
|
|
|
|
|
/**
|
|
|
* Created by Julien on 14.01.2015.
|
|
|
*/
|
|
|
public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemClickListener {
|
|
|
|
|
|
+ public static String CONNECTION_LOST_MESSAGE = MainActivity.getContext().getString(R.string.CONNECTION_LOST_MESSAGE);// "Connection lost permanently, please enable wifi direct.";
|
|
|
+ public static String COULD_NOT_CONNECT_MESSAGE =MainActivity.getContext().getString(R.string.COULD_NOT_CONNECT_MESSAGE);// "Could not connect to device. Retry.";
|
|
|
+
|
|
|
+ public static String SYNCHRONIZATION_COMPLETE_MESSAGE =MainActivity.getContext().getString(R.string.SYNCHRONIZATION_COMPLETE_MESSAGE);// "Synchronization complete.";
|
|
|
+ public static String SYNCHRONIZATION_FAILED_MESSAGE =MainActivity.getContext().getString(R.string.SYNCHRONIZATION_FAILED_MESSAGE);// "Could not synchronize devices. Retry";
|
|
|
+
|
|
|
+ public static String PERFORMING_TASK_AS_HOST =MainActivity.getContext().getString(R.string.PERFORMING_TASK_AS_HOST);// "Acting as Host.";
|
|
|
+ public static String PERFORMING_TASK_AS_CLIENT = MainActivity.getContext().getString(R.string.PERFORMING_TASK_AS_CLIENT);//"Acting as Client.";
|
|
|
+
|
|
|
+ public static String ACTIONBAR_TITLE =MainActivity.getContext().getString(R.string.ACTIONBAR_TITLE);// "WifiDirect Synchronization";
|
|
|
+ public static String PROGRESS_TITLE_LOADING =MainActivity.getContext().getString(R.string.PROGRESS_TITLE_LOADING);// "Loading...";
|
|
|
+ public static String PROGRESS_TITLE_CONNECTING = MainActivity.getContext().getString(R.string.PROGRESS_TITLE_CONNECTING);//"Connecting...";
|
|
|
+
|
|
|
+ public static String DEVICE_STATUS_AVAILABLE =MainActivity.getContext().getString(R.string.DEVICE_STATUS_AVAILABLE);// "Available";
|
|
|
+ public static String DEVICE_STATUS_INVITED =MainActivity.getContext().getString(R.string.DEVICE_STATUS_INVITED);// "Invited";
|
|
|
+ public static String DEVICE_STATUS_CONNECTED = MainActivity.getContext().getString(R.string.DEVICE_STATUS_CONNECTED);//"Connected";
|
|
|
+ public static String DEVICE_STATUS_FAILED =MainActivity.getContext().getString(R.string.DEVICE_STATUS_FAILED);// "Failed";
|
|
|
+ public static String DEVICE_STATUS_UNAVAILABLE =MainActivity.getContext().getString(R.string.DEVICE_STATUS_UNAVAILABLE);// "Unavailable";
|
|
|
+ public static String DEVICE_STATUS_UNKNOWN =MainActivity.getContext().getString(R.string.DEVICE_STATUS_UNKNOWN);// "Unknown";
|
|
|
+
|
|
|
+ public static String WIFI_STATUS_DISABLED_MESSAGE =MainActivity.getContext().getString(R.string.WIFI_STATUS_DISABLED_MESSAGE);// "WiFi Direct down, please enable WiFi Direct";
|
|
|
+ public static String WIFI_STATUS_ENABLE_BUTTON = MainActivity.getContext().getString(R.string.WIFI_STATUS_ENABLE_BUTTON);//"Enable WiFi Direct";
|
|
|
+
|
|
|
+ public static String CANCEL_BUTTON_TITLE =MainActivity.getContext().getString(R.string.CANCEL_BUTTON_TITLE);// "Cancel";
|
|
|
+
|
|
|
+
|
|
|
private SyncClientTask clientTask;
|
|
|
private SyncHostTask hostTask;
|
|
|
private boolean isHost;
|
|
@@ -52,7 +83,7 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
private TextView mTxtP2PNotAvailable;
|
|
|
private TextView mTxtP2PChangeDeviceName;
|
|
|
|
|
|
- private WifiP2pDevice mDevice;
|
|
|
+ private WifiP2pDevice ownDevice;
|
|
|
private WifiP2pDevice mOtherDevice;
|
|
|
|
|
|
private ArrayList<WifiP2pDevice> discoveredDevices = new ArrayList<WifiP2pDevice>();
|
|
@@ -63,7 +94,6 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
public boolean isHost() {
|
|
|
return isHost;
|
|
|
}
|
|
|
-
|
|
|
public void setHost(boolean isHost) {
|
|
|
this.isHost = isHost;
|
|
|
}
|
|
@@ -78,22 +108,26 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
setContentView(R.layout.activity_p2_psync);
|
|
|
|
|
|
assert getActionBar() != null;
|
|
|
- getActionBar().setTitle("WifiDirect Synchronization");
|
|
|
+ getActionBar().setTitle(ACTIONBAR_TITLE);
|
|
|
|
|
|
this.extractFromView();
|
|
|
this.registerListeners();
|
|
|
|
|
|
+ this.wifiEventHandler().startService();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onResume() {
|
|
|
super.onResume();
|
|
|
- this.wifiEventHandler().onResume();
|
|
|
+ this.wifiEventHandler().startService();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onPause() {
|
|
|
- this.wifiEventHandler().onPause();
|
|
|
+ if (this.clientTask != null) this.clientTask.interrupt(true);
|
|
|
+ if (this.hostTask != null) this.hostTask.interrupt(true);
|
|
|
+
|
|
|
+ this.wifiEventHandler().stopService();
|
|
|
super.onPause();
|
|
|
}
|
|
|
|
|
@@ -101,23 +135,32 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
protected void onStart()
|
|
|
{
|
|
|
super.onStart();
|
|
|
- this.wifiEventHandler().onResume();
|
|
|
+ this.wifiEventHandler().startService();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onStop()
|
|
|
{
|
|
|
+ if (this.clientTask != null) this.clientTask.interrupt(true);
|
|
|
+ if (this.hostTask != null) this.hostTask.interrupt(true);
|
|
|
this.wifiEventHandler().disconnect();
|
|
|
- this.wifiEventHandler().onPause();
|
|
|
+ this.wifiEventHandler().stopService();
|
|
|
super.onStop();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onDestroy(){
|
|
|
- this.wifiEventHandler().onPause();
|
|
|
+ if (this.clientTask != null) this.clientTask.interrupt(true);
|
|
|
+ if (this.hostTask != null) this.hostTask.interrupt(true);
|
|
|
+ this.wifiEventHandler().stopService();
|
|
|
super.onDestroy();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns a instance of the wifi event handler listener object. If no private instance was initiated it creates a new one.
|
|
|
+ * This object handles all gui changes.
|
|
|
+ * @return WiFiP2pEventHandler.WiFiP2pEventListener
|
|
|
+ */
|
|
|
private WiFiP2pEventHandler.WiFiP2pEventListener eventListener(){
|
|
|
if (_p2pEventListener == null){
|
|
|
_p2pEventListener = new WiFiP2pEventHandler.WiFiP2pEventListener() {
|
|
@@ -143,7 +186,13 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
@Override
|
|
|
public void didConnect(boolean isHost, WifiP2pInfo connectionInfo) {
|
|
|
Log.d("WiFiP2pSyncActivity", "Did connect" + ".");
|
|
|
- this.activity.progressDialog = ProgressDialog.show(activity, "", "Loading...");
|
|
|
+
|
|
|
+ String progressTitle = PROGRESS_TITLE_LOADING;
|
|
|
+ if (this.activity.progressDialog != null){
|
|
|
+ this.activity.progressDialog.dismiss();
|
|
|
+ }
|
|
|
+ this.activity.progressDialog = ProgressDialog.show(activity, "", progressTitle);
|
|
|
+
|
|
|
|
|
|
this.activity.setHost(isHost);
|
|
|
if (isHost){
|
|
@@ -158,7 +207,8 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
@Override
|
|
|
public void failedToConnect() {
|
|
|
Log.d("WiFiP2pSyncActivity", "Failed to connect" + ".");
|
|
|
- Toast.makeText(this.activity, "Could not connect to device. Retry.", Toast.LENGTH_LONG).show();
|
|
|
+ Toast.makeText(this.activity, COULD_NOT_CONNECT_MESSAGE , Toast.LENGTH_LONG).show();
|
|
|
+ this.activity.progressDialog.dismiss();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -171,22 +221,35 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
public void failedToDisconnect() {
|
|
|
Log.d("WiFiP2pSyncActivity", "Failed to disconnect" + ".");
|
|
|
//Toast.makeText(this.activity, "Could not disconnect with device. Retry.", Toast.LENGTH_LONG).show();
|
|
|
+ // Other device did disconnect a while before.
|
|
|
this.activity.progressDialog.dismiss();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void deviceIsUpdated(WifiP2pDevice device) {
|
|
|
+ public void ownDeviceInformationIsUpdated(WifiP2pDevice device) {
|
|
|
Log.d("WiFiP2pSyncActivity", "Updated device " + device.deviceName + " " + device.deviceAddress + ".");
|
|
|
- this.activity.updateDevice(device);
|
|
|
+ this.activity.updateOwnDeviceInformation(device);
|
|
|
this.activity.searchForDevices();
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onConnectionLost() {
|
|
|
+ Toast.makeText(this.activity, CONNECTION_LOST_MESSAGE , Toast.LENGTH_LONG).show();
|
|
|
+ if (this.activity.progressDialog != null && this.activity.progressDialog.isShowing()){
|
|
|
+ this.activity.progressDialog.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
}.init(this);
|
|
|
}
|
|
|
|
|
|
return _p2pEventListener;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns a instance of the wifi event handler. If no private instance was initiated it creates a new one.
|
|
|
+ * @return WiFiP2pEventHandler
|
|
|
+ */
|
|
|
private WiFiP2pEventHandler wifiEventHandler(){
|
|
|
if (this._wifiEventHandler == null){
|
|
|
this._wifiEventHandler = new WiFiP2pEventHandler(this, this.eventListener());
|
|
@@ -195,7 +258,10 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Returns a sync completion listener. If no listener was initiated it creates a new on.
|
|
|
+ * @return BackgroundTaskCompletionListener
|
|
|
+ */
|
|
|
private BackgroundTask.BackgroundTaskCompletionListener syncCompletionListener(){
|
|
|
if (_syncCompletionListener == null){
|
|
|
_syncCompletionListener = new BackgroundTask.BackgroundTaskCompletionListener() {
|
|
@@ -206,34 +272,14 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
}
|
|
|
@Override
|
|
|
public void didSucceed() {
|
|
|
- this.activity.runOnUiThread(new Runnable() {
|
|
|
- private WiFiP2pSyncActivity activity;
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- Toast.makeText(this.activity, "Synchronization complete.", Toast.LENGTH_SHORT).show();
|
|
|
- this.activity.wifiEventHandler().disconnect();
|
|
|
- }
|
|
|
- public Runnable init(WiFiP2pSyncActivity activity){
|
|
|
- this.activity = activity;
|
|
|
- return this;
|
|
|
- }
|
|
|
- }.init(this.activity));
|
|
|
+ Toast.makeText(this.activity, SYNCHRONIZATION_COMPLETE_MESSAGE , Toast.LENGTH_SHORT).show();
|
|
|
+ this.activity.wifiEventHandler().disconnect();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void didFail() {
|
|
|
- this.activity.runOnUiThread(new Runnable() {
|
|
|
- private WiFiP2pSyncActivity activity;
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- Toast.makeText(this.activity, "Could not synchronize with device. Retry.", Toast.LENGTH_LONG).show();
|
|
|
- this.activity.wifiEventHandler().disconnect();
|
|
|
- }
|
|
|
- public Runnable init(WiFiP2pSyncActivity activity){
|
|
|
- this.activity = activity;
|
|
|
- return this;
|
|
|
- }
|
|
|
- }.init(this.activity));
|
|
|
+ Toast.makeText(this.activity, SYNCHRONIZATION_FAILED_MESSAGE, Toast.LENGTH_LONG).show();
|
|
|
+ this.activity.wifiEventHandler().disconnect();
|
|
|
}
|
|
|
}.init(this);
|
|
|
}
|
|
@@ -241,13 +287,20 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void updateDeviceListView(List<WifiP2pDevice> peers){
|
|
|
+ /**
|
|
|
+ * Updates the device list on the ui thread.
|
|
|
+ * @param peers
|
|
|
+ */
|
|
|
+ private void updateDeviceListView(List<WifiP2pDevice> peers)
|
|
|
+ {
|
|
|
mTxtP2PSearchProgress.setVisibility(View.GONE);
|
|
|
|
|
|
this.discoveredDevices = new ArrayList<WifiP2pDevice>();
|
|
|
this.discoveredDevices.addAll(peers);
|
|
|
WiFiPeerListAdapter listAdapter = (WiFiPeerListAdapter) this.mLstP2PDevices.getAdapter();
|
|
|
listAdapter.addItems(peers);
|
|
|
+
|
|
|
+ // Run the update process on the gui thread, otherwise the list wont be updated.
|
|
|
this.runOnUiThread(new Runnable() {
|
|
|
private ListView listView;
|
|
|
|
|
@@ -265,47 +318,88 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
}
|
|
|
}.init(this.mLstP2PDevices));
|
|
|
Log.d("WiFiP2pSyncActivity", " Discovered "+peers.size()+" devices.");
|
|
|
+
|
|
|
+ if (peers.size() == 0){
|
|
|
+ this.searchForDevices();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private void startHost(){
|
|
|
+ /**
|
|
|
+ * Starts the Host task. Informs the user by a little toast.
|
|
|
+ */
|
|
|
+ private void startHost()
|
|
|
+ {
|
|
|
Log.d("WiFiP2pSyncActivity", "Starting HOST Task" + ".");
|
|
|
- Toast.makeText(this, "Acting as Host.", Toast.LENGTH_SHORT).show();
|
|
|
- this.hostTask = new SyncHostTask(this.syncCompletionListener(), getApplicationContext());
|
|
|
+ //Toast.makeText(this, PERFORMING_TASK_AS_HOST , Toast.LENGTH_SHORT).show();
|
|
|
+ this.hostTask = new SyncHostTask(this.ownDevice, this.syncCompletionListener(), getApplicationContext());
|
|
|
this.hostTask.execute();
|
|
|
}
|
|
|
|
|
|
- private void startClient(WifiP2pInfo info){
|
|
|
+ /**
|
|
|
+ * Starts the wifi direct client task. Informs the user by a little toast.
|
|
|
+ * @param info the WifiP2pInfo contains the groupOwnerAddress which is needed for the client task.
|
|
|
+ */
|
|
|
+ private void startClient(WifiP2pInfo info)
|
|
|
+ {
|
|
|
Log.d("WiFiP2pSyncActivity", "Starting CLIENT Task" + ".");
|
|
|
- Toast.makeText(this, "Acting as Client.", Toast.LENGTH_SHORT).show();
|
|
|
- this.clientTask = new SyncClientTask(info.groupOwnerAddress.getHostAddress(), this.syncCompletionListener(), getApplicationContext() );
|
|
|
+ //Toast.makeText(this, PERFORMING_TASK_AS_CLIENT, Toast.LENGTH_SHORT).show();
|
|
|
+ this.clientTask = new SyncClientTask( info.groupOwnerAddress.getHostAddress(),this.ownDevice, this.syncCompletionListener(), getApplicationContext() );
|
|
|
this.clientTask.execute();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Try to connect to the given device and shows a simple progress dialog.
|
|
|
+ * @param device
|
|
|
+ */
|
|
|
+ private void connectTo(WifiP2pDevice device){
|
|
|
+ String connectionTitle = PROGRESS_TITLE_CONNECTING;
|
|
|
+ if (device != null){
|
|
|
+ if (progressDialog == null){
|
|
|
+ this.progressDialog = ProgressDialog.show(this, "", connectionTitle);
|
|
|
+ } else {
|
|
|
+ progressDialog.setTitle(connectionTitle);
|
|
|
+ }
|
|
|
+ mOtherDevice = device;
|
|
|
+ this.wifiEventHandler().connect(device);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns a localized device status string.
|
|
|
+ * @param deviceStatus the status to convert.
|
|
|
+ * @return status string
|
|
|
+ */
|
|
|
private static String getDeviceStatus(int deviceStatus) {
|
|
|
switch (deviceStatus) {
|
|
|
case WifiP2pDevice.AVAILABLE:
|
|
|
- return "Available";
|
|
|
+ return DEVICE_STATUS_AVAILABLE;
|
|
|
case WifiP2pDevice.INVITED:
|
|
|
- return "Invited";
|
|
|
+ return DEVICE_STATUS_INVITED;
|
|
|
case WifiP2pDevice.CONNECTED:
|
|
|
- return "Connected";
|
|
|
+ return DEVICE_STATUS_CONNECTED;
|
|
|
case WifiP2pDevice.FAILED:
|
|
|
- return "Failed";
|
|
|
+ return DEVICE_STATUS_FAILED;
|
|
|
case WifiP2pDevice.UNAVAILABLE:
|
|
|
- return "Unavailable";
|
|
|
+ return DEVICE_STATUS_UNAVAILABLE;
|
|
|
default:
|
|
|
- return "Unknown";
|
|
|
+ return DEVICE_STATUS_UNKNOWN;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private void updateDevice(WifiP2pDevice device){
|
|
|
+ /**
|
|
|
+ * Updates / displays own device information.
|
|
|
+ * @param device
|
|
|
+ */
|
|
|
+ private void updateOwnDeviceInformation(WifiP2pDevice device)
|
|
|
+ {
|
|
|
mTxtP2PDeviceName.setText(device.deviceName);
|
|
|
mTxtP2PDeviceStatus.setText(getDeviceStatus(device.status));
|
|
|
- mDevice = device;
|
|
|
+ ownDevice = device;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Method to search for new devices.
|
|
|
+ */
|
|
|
private void searchForDevices(){
|
|
|
mTxtP2PSearchProgress.setVisibility(View.VISIBLE);
|
|
|
this.wifiEventHandler().discoverDevices();
|
|
@@ -313,22 +407,50 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
|
|
|
/********************** UI ************************/
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Informs the user about a changed wifi state.
|
|
|
+ * enabled = true - mTxtP2PNotAvailable is gone
|
|
|
+ * enabled = false - mTxtP2PNotAvailable stays and a alert box is displayed for a quick navigation to the wifi settings.
|
|
|
+ * @param enabled
|
|
|
+ */
|
|
|
public void setWifiDirectAvailable(boolean enabled){
|
|
|
if (enabled){
|
|
|
mTxtP2PNotAvailable.setVisibility(View.GONE);
|
|
|
} else {
|
|
|
mTxtP2PNotAvailable.setVisibility(View.VISIBLE);
|
|
|
((WiFiPeerListAdapter) mLstP2PDevices.getAdapter()).notifyDataSetChanged();
|
|
|
- mDevice = null;
|
|
|
+ ownDevice = null;
|
|
|
this.updateDeviceListView(new ArrayList<WifiP2pDevice>());
|
|
|
-
|
|
|
- Toast.makeText(this, "WiFi Direct P2P is disabled.", Toast.LENGTH_LONG).show();
|
|
|
+ this.showWifiDisabledDialog();
|
|
|
+ //Toast.makeText(this, "WiFi Direct P2P is disabled.", Toast.LENGTH_LONG).show();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Displays a AlertDialog that informs the User about the disabled Wifi state and can navigate the user directly to the wifi settings.
|
|
|
+ */
|
|
|
+ private void showWifiDisabledDialog(){
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
+ builder.setMessage(WIFI_STATUS_DISABLED_MESSAGE)
|
|
|
+ .setCancelable(true)
|
|
|
+ .setPositiveButton(WIFI_STATUS_ENABLE_BUTTON, new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int id) {
|
|
|
+ startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setNegativeButton(CANCEL_BUTTON_TITLE, new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int id) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
+ AlertDialog info = builder.create();
|
|
|
+ info.show();
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * Extracts all subview initially from the view hierarchy.
|
|
|
+ */
|
|
|
private void extractFromView(){
|
|
|
this.mTxtP2PDeviceName = (TextView) findViewById(R.id.txt_p2p_device_name);
|
|
|
this.mTxtP2PDeviceStatus = (TextView) findViewById(R.id.txt_p2p_device_status);
|
|
@@ -342,25 +464,10 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
this.mTxtP2PNotAvailable = (TextView) findViewById(R.id.txtP2PNotAvailable);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Registers all the gui listeners.
|
|
|
+ */
|
|
|
public void registerListeners(){
|
|
|
- /*
|
|
|
- mTxtP2PChangeDeviceName.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- Method method1 = null;
|
|
|
- try {
|
|
|
- method1 = mManager.getClass().getDeclaredMethod("setDeviceName", WifiP2pManager.Channel.class);
|
|
|
- method1.invoke(mManager, mChannel, "Android_fc546");
|
|
|
- } catch (NoSuchMethodException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (InvocationTargetException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IllegalAccessException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- });*/
|
|
|
-
|
|
|
if (this.mLstP2PDevices.getOnItemClickListener() != this)
|
|
|
this.mLstP2PDevices.setOnItemClickListener(this);
|
|
|
|
|
@@ -375,8 +482,7 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
@Override
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
final WifiP2pDevice device = (WifiP2pDevice) this.mLstP2PDevices.getAdapter().getItem(position);
|
|
|
- this.wifiEventHandler().connect(device);
|
|
|
- mOtherDevice = device;
|
|
|
+ this.connectTo(device);
|
|
|
}
|
|
|
|
|
|
|