WiFiP2pSyncActivity.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. package de.tudarmstadt.informatik.hostage.sync.wifi_direct.ui;
  2. import android.app.Activity;
  3. import android.app.AlertDialog;
  4. import android.app.ProgressDialog;
  5. import android.content.Context;
  6. import android.content.DialogInterface;
  7. import android.content.Intent;
  8. import android.net.wifi.p2p.WifiP2pDevice;
  9. import android.net.wifi.p2p.WifiP2pInfo;
  10. import android.os.Bundle;
  11. import android.provider.Settings;
  12. import android.util.Log;
  13. import android.view.LayoutInflater;
  14. import android.view.View;
  15. import android.view.ViewGroup;
  16. import android.widget.AdapterView;
  17. import android.widget.ArrayAdapter;
  18. import android.widget.ListView;
  19. import android.widget.RelativeLayout;
  20. import android.widget.TextView;
  21. import android.widget.Toast;
  22. import android.widget.ViewAnimator;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. import de.tudarmstadt.informatik.hostage.R;
  26. import de.tudarmstadt.informatik.hostage.sync.wifi_direct.BackgroundTask;
  27. import de.tudarmstadt.informatik.hostage.sync.wifi_direct.WiFiP2pEventHandler;
  28. import de.tudarmstadt.informatik.hostage.sync.wifi_direct.sync_tasks.SyncClientTask;
  29. import de.tudarmstadt.informatik.hostage.sync.wifi_direct.sync_tasks.SyncHostTask;
  30. import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
  31. /**
  32. * Created by Julien on 14.01.2015.
  33. */
  34. public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemClickListener {
  35. public static String CONNECTION_LOST_MESSAGE = MainActivity.getContext().getString(R.string.CONNECTION_LOST_MESSAGE);// "Connection lost permanently, please enable wifi direct.";
  36. public static String COULD_NOT_CONNECT_MESSAGE =MainActivity.getContext().getString(R.string.COULD_NOT_CONNECT_MESSAGE);// "Could not connect to device. Retry.";
  37. public static String SYNCHRONIZATION_COMPLETE_MESSAGE =MainActivity.getContext().getString(R.string.SYNCHRONIZATION_COMPLETE_MESSAGE);// "Synchronization complete.";
  38. public static String SYNCHRONIZATION_FAILED_MESSAGE =MainActivity.getContext().getString(R.string.SYNCHRONIZATION_FAILED_MESSAGE);// "Could not synchronize devices. Retry";
  39. public static String PERFORMING_TASK_AS_HOST =MainActivity.getContext().getString(R.string.PERFORMING_TASK_AS_HOST);// "Acting as Host.";
  40. public static String PERFORMING_TASK_AS_CLIENT = MainActivity.getContext().getString(R.string.PERFORMING_TASK_AS_CLIENT);//"Acting as Client.";
  41. public static String ACTIONBAR_TITLE =MainActivity.getContext().getString(R.string.ACTIONBAR_TITLE);// "WifiDirect Synchronization";
  42. public static String PROGRESS_TITLE_LOADING =MainActivity.getContext().getString(R.string.PROGRESS_TITLE_LOADING);// "Loading...";
  43. public static String PROGRESS_TITLE_CONNECTING = MainActivity.getContext().getString(R.string.PROGRESS_TITLE_CONNECTING);//"Connecting...";
  44. public static String DEVICE_STATUS_AVAILABLE =MainActivity.getContext().getString(R.string.DEVICE_STATUS_AVAILABLE);// "Available";
  45. public static String DEVICE_STATUS_INVITED =MainActivity.getContext().getString(R.string.DEVICE_STATUS_INVITED);// "Invited";
  46. public static String DEVICE_STATUS_CONNECTED = MainActivity.getContext().getString(R.string.DEVICE_STATUS_CONNECTED);//"Connected";
  47. public static String DEVICE_STATUS_FAILED =MainActivity.getContext().getString(R.string.DEVICE_STATUS_FAILED);// "Failed";
  48. public static String DEVICE_STATUS_UNAVAILABLE =MainActivity.getContext().getString(R.string.DEVICE_STATUS_UNAVAILABLE);// "Unavailable";
  49. public static String DEVICE_STATUS_UNKNOWN =MainActivity.getContext().getString(R.string.DEVICE_STATUS_UNKNOWN);// "Unknown";
  50. public static String WIFI_STATUS_DISABLED_MESSAGE =MainActivity.getContext().getString(R.string.WIFI_STATUS_DISABLED_MESSAGE);// "WiFi Direct down, please enable WiFi Direct";
  51. public static String WIFI_STATUS_ENABLE_BUTTON = MainActivity.getContext().getString(R.string.WIFI_STATUS_ENABLE_BUTTON);//"Enable WiFi Direct";
  52. public static String CANCEL_BUTTON_TITLE =MainActivity.getContext().getString(R.string.CANCEL_BUTTON_TITLE);// "Cancel";
  53. private SyncClientTask clientTask;
  54. private SyncHostTask hostTask;
  55. private BackgroundTask executingTask;
  56. private boolean isHost;
  57. private WiFiP2pEventHandler _wifiEventHandler = null;
  58. private WiFiP2pEventHandler.WiFiP2pEventListener _p2pEventListener = null;
  59. private BackgroundTask.BackgroundTaskCompletionListener _syncCompletionListener = null;
  60. private TextView mTxtP2PDeviceName;
  61. private TextView mTxtP2PDeviceStatus;
  62. private ViewAnimator mViewAnimator;
  63. private RelativeLayout mDevicesContainer;
  64. private TextView mTxtP2PSearchProgress;
  65. private ListView mLstP2PDevices;
  66. private RelativeLayout mWelcomeContainer;
  67. private TextView mTxtP2PNotAvailable;
  68. private TextView mTxtP2PChangeDeviceName;
  69. private WifiP2pDevice ownDevice;
  70. private WifiP2pDevice mOtherDevice;
  71. private ArrayList<WifiP2pDevice> discoveredDevices = new ArrayList<WifiP2pDevice>();
  72. private ProgressDialog progressDialog;
  73. public boolean isHost() {
  74. return isHost;
  75. }
  76. public void setHost(boolean isHost) {
  77. this.isHost = isHost;
  78. }
  79. @Override
  80. public void onCreate(Bundle savedInstanceState) {
  81. super.onCreate(savedInstanceState);
  82. this.wifiEventHandler();
  83. setContentView(R.layout.activity_p2_psync);
  84. assert getActionBar() != null;
  85. getActionBar().setTitle(ACTIONBAR_TITLE);
  86. this.extractFromView();
  87. this.registerListeners();
  88. this.wifiEventHandler().startService();
  89. }
  90. @Override
  91. public void onResume() {
  92. super.onResume();
  93. this.wifiEventHandler().startService();
  94. }
  95. @Override
  96. public void onPause() {
  97. if (this.clientTask != null) this.clientTask.interrupt(true);
  98. if (this.hostTask != null) this.hostTask.interrupt(true);
  99. this.wifiEventHandler().stopService();
  100. super.onPause();
  101. }
  102. @Override
  103. protected void onStart()
  104. {
  105. super.onStart();
  106. this.wifiEventHandler().startService();
  107. }
  108. @Override
  109. protected void onStop()
  110. {
  111. if (this.clientTask != null) this.clientTask.interrupt(true);
  112. if (this.hostTask != null) this.hostTask.interrupt(true);
  113. this.wifiEventHandler().disconnect();
  114. this.wifiEventHandler().stopService();
  115. super.onStop();
  116. }
  117. @Override
  118. protected void onDestroy(){
  119. if (this.clientTask != null) this.clientTask.interrupt(true);
  120. if (this.hostTask != null) this.hostTask.interrupt(true);
  121. this.wifiEventHandler().stopService();
  122. super.onDestroy();
  123. }
  124. /**
  125. * Returns a instance of the wifi event handler listener object. If no private instance was initiated it creates a new one.
  126. * This object handles all gui changes.
  127. * @return WiFiP2pEventHandler.WiFiP2pEventListener
  128. */
  129. private WiFiP2pEventHandler.WiFiP2pEventListener eventListener(){
  130. if (_p2pEventListener == null){
  131. _p2pEventListener = new WiFiP2pEventHandler.WiFiP2pEventListener() {
  132. WiFiP2pSyncActivity activity = null;
  133. public WiFiP2pEventHandler.WiFiP2pEventListener init(WiFiP2pSyncActivity act){
  134. this.activity = act;
  135. return this;
  136. }
  137. @Override
  138. public void discoveredDevices(List<WifiP2pDevice> peers) {
  139. Log.d("WiFiP2pSyncActivity", "Actualise devices list" + ".");
  140. this.activity.updateDeviceListView(peers);
  141. }
  142. @Override
  143. public void wifiP2pIsEnabled(boolean enabled) {
  144. String tmp = enabled? "enabled" : "disabled";
  145. Log.d("WiFiP2pSyncActivity", "Peer to peer is " + tmp + ".");
  146. this.activity.setWifiDirectAvailable(enabled);
  147. }
  148. @Override
  149. public void didConnect(boolean isHost, WifiP2pInfo connectionInfo) {
  150. Log.d("WiFiP2pSyncActivity", "Did connect" + ".");
  151. String progressTitle = PROGRESS_TITLE_LOADING;
  152. if (this.activity.progressDialog != null){
  153. this.activity.progressDialog.dismiss();
  154. }
  155. this.activity.progressDialog = ProgressDialog.show(activity, "", progressTitle);
  156. this.activity.setHost(isHost);
  157. if (isHost){
  158. Log.d("WiFiP2pSyncActivity", "Connected as HOST" + ".");
  159. this.activity.startHost();
  160. } else {
  161. Log.d("WiFiP2pSyncActivity", "Connected as Client" + ".");
  162. this.activity.startClient(connectionInfo);
  163. }
  164. }
  165. @Override
  166. public void failedToConnect() {
  167. Log.d("WiFiP2pSyncActivity", "Failed to connect" + ".");
  168. Toast.makeText(this.activity, COULD_NOT_CONNECT_MESSAGE , Toast.LENGTH_LONG).show();
  169. this.activity.progressDialog.dismiss();
  170. }
  171. @Override
  172. public void didDisconnect() {
  173. Log.d("WiFiP2pSyncActivity", "Did disconnect" + ".");
  174. this.activity.progressDialog.dismiss();
  175. }
  176. @Override
  177. public void failedToDisconnect() {
  178. Log.d("WiFiP2pSyncActivity", "Failed to disconnect" + ".");
  179. //Toast.makeText(this.activity, "Could not disconnect with device. Retry.", Toast.LENGTH_LONG).show();
  180. // Other device did disconnect a while before.
  181. this.activity.progressDialog.dismiss();
  182. }
  183. @Override
  184. public void ownDeviceInformationIsUpdated(WifiP2pDevice device) {
  185. Log.d("WiFiP2pSyncActivity", "Updated device " + device.deviceName + " " + device.deviceAddress + ".");
  186. this.activity.updateOwnDeviceInformation(device);
  187. this.activity.searchForDevices();
  188. }
  189. @Override
  190. public void onConnectionLost() {
  191. Toast.makeText(this.activity, CONNECTION_LOST_MESSAGE , Toast.LENGTH_LONG).show();
  192. if (this.activity.progressDialog != null && this.activity.progressDialog.isShowing()){
  193. this.activity.progressDialog.dismiss();
  194. }
  195. }
  196. }.init(this);
  197. }
  198. return _p2pEventListener;
  199. }
  200. /**
  201. * Returns a instance of the wifi event handler. If no private instance was initiated it creates a new one.
  202. * @return WiFiP2pEventHandler
  203. */
  204. private WiFiP2pEventHandler wifiEventHandler(){
  205. if (this._wifiEventHandler == null){
  206. this._wifiEventHandler = new WiFiP2pEventHandler(this, this.eventListener());
  207. }
  208. return this._wifiEventHandler;
  209. }
  210. /**
  211. * Returns a sync completion listener. If no listener was initiated it creates a new on.
  212. * @return BackgroundTaskCompletionListener
  213. */
  214. private BackgroundTask.BackgroundTaskCompletionListener syncCompletionListener(){
  215. if (_syncCompletionListener == null){
  216. _syncCompletionListener = new BackgroundTask.BackgroundTaskCompletionListener() {
  217. WiFiP2pSyncActivity activity = null;
  218. public BackgroundTask.BackgroundTaskCompletionListener init(WiFiP2pSyncActivity act){
  219. this.activity = act;
  220. return this;
  221. }
  222. @Override
  223. public void didSucceed() {
  224. Toast.makeText(this.activity, SYNCHRONIZATION_COMPLETE_MESSAGE , Toast.LENGTH_SHORT).show();
  225. this.activity.wifiEventHandler().disconnect();
  226. this.activity.hostTask = null;
  227. this.activity.clientTask = null;
  228. }
  229. @Override
  230. public void didFail() {
  231. Toast.makeText(this.activity, SYNCHRONIZATION_FAILED_MESSAGE, Toast.LENGTH_LONG).show();
  232. this.activity.wifiEventHandler().disconnect();
  233. this.activity.hostTask = null;
  234. this.activity.clientTask = null;
  235. }
  236. }.init(this);
  237. }
  238. return _syncCompletionListener;
  239. }
  240. /**
  241. * Updates the device list on the ui thread.
  242. * @param peers
  243. */
  244. private void updateDeviceListView(List<WifiP2pDevice> peers)
  245. {
  246. mTxtP2PSearchProgress.setVisibility(View.GONE);
  247. this.discoveredDevices = new ArrayList<WifiP2pDevice>();
  248. this.discoveredDevices.addAll(peers);
  249. WiFiPeerListAdapter listAdapter = (WiFiPeerListAdapter) this.mLstP2PDevices.getAdapter();
  250. listAdapter.addItems(peers);
  251. // Run the update process on the gui thread, otherwise the list wont be updated.
  252. this.runOnUiThread(new Runnable() {
  253. private ListView listView;
  254. @Override
  255. public void run() {
  256. WiFiPeerListAdapter adapter = (WiFiPeerListAdapter) this.listView.getAdapter();
  257. this.listView.setAdapter(null);
  258. adapter.notifyDataSetChanged();
  259. this.listView.setAdapter(adapter);
  260. }
  261. public Runnable init(ListView listview) {
  262. this.listView = listview;
  263. return this;
  264. }
  265. }.init(this.mLstP2PDevices));
  266. Log.d("WiFiP2pSyncActivity", " Discovered "+peers.size()+" devices.");
  267. if (peers.size() == 0){
  268. this.searchForDevices();
  269. }
  270. }
  271. /**
  272. * Starts the Host task. Informs the user by a little toast.
  273. */
  274. private void startHost()
  275. {
  276. if (this.hostTask == null){
  277. Log.d("WiFiP2pSyncActivity", "Starting HOST Task" + ".");
  278. //Toast.makeText(this, PERFORMING_TASK_AS_HOST , Toast.LENGTH_SHORT).show();
  279. this.hostTask = new SyncHostTask(this.ownDevice, this.syncCompletionListener(), getApplicationContext());
  280. this.executingTask = this.hostTask;
  281. this.hostTask.execute();
  282. } else {
  283. Log.d("WiFiP2pSyncActivity", "Preventing third device for any syncing" + ".");
  284. }
  285. }
  286. /**
  287. * Starts the wifi direct client task. Informs the user by a little toast.
  288. * @param info the WifiP2pInfo contains the groupOwnerAddress which is needed for the client task.
  289. */
  290. private void startClient(WifiP2pInfo info)
  291. {
  292. if (this.clientTask == null){
  293. Log.d("WiFiP2pSyncActivity", "Starting CLIENT Task" + ".");
  294. //Toast.makeText(this, PERFORMING_TASK_AS_CLIENT, Toast.LENGTH_SHORT).show();
  295. this.clientTask = new SyncClientTask( info.groupOwnerAddress.getHostAddress(),this.ownDevice, this.syncCompletionListener(), getApplicationContext() );
  296. this.executingTask = this.clientTask;
  297. this.clientTask.execute();
  298. } else {
  299. Log.d("WiFiP2pSyncActivity", "Preventing third device for syncing" + ".");
  300. }
  301. }
  302. /**
  303. * Try to connect to the given device and shows a simple progress dialog.
  304. * @param device
  305. */
  306. private void connectTo(WifiP2pDevice device){
  307. String connectionTitle = PROGRESS_TITLE_CONNECTING;
  308. if (device != null){
  309. if (progressDialog == null){
  310. this.progressDialog = ProgressDialog.show(this, "", connectionTitle);
  311. } else {
  312. progressDialog.setTitle(connectionTitle);
  313. }
  314. mOtherDevice = device;
  315. this.wifiEventHandler().connect(device);
  316. }
  317. }
  318. /**
  319. * Returns a localized device status string.
  320. * @param deviceStatus the status to convert.
  321. * @return status string
  322. */
  323. private static String getDeviceStatus(int deviceStatus) {
  324. switch (deviceStatus) {
  325. case WifiP2pDevice.AVAILABLE:
  326. return DEVICE_STATUS_AVAILABLE;
  327. case WifiP2pDevice.INVITED:
  328. return DEVICE_STATUS_INVITED;
  329. case WifiP2pDevice.CONNECTED:
  330. return DEVICE_STATUS_CONNECTED;
  331. case WifiP2pDevice.FAILED:
  332. return DEVICE_STATUS_FAILED;
  333. case WifiP2pDevice.UNAVAILABLE:
  334. return DEVICE_STATUS_UNAVAILABLE;
  335. default:
  336. return DEVICE_STATUS_UNKNOWN;
  337. }
  338. }
  339. /**
  340. * Updates / displays own device information.
  341. * @param device
  342. */
  343. private void updateOwnDeviceInformation(WifiP2pDevice device)
  344. {
  345. mTxtP2PDeviceName.setText(device.deviceName);
  346. mTxtP2PDeviceStatus.setText(getDeviceStatus(device.status));
  347. ownDevice = device;
  348. }
  349. /**
  350. * Method to search for new devices.
  351. */
  352. private void searchForDevices(){
  353. mTxtP2PSearchProgress.setVisibility(View.VISIBLE);
  354. this.wifiEventHandler().discoverDevices();
  355. }
  356. /********************** UI ************************/
  357. /**
  358. * Informs the user about a changed wifi state.
  359. * enabled = true - mTxtP2PNotAvailable is gone
  360. * enabled = false - mTxtP2PNotAvailable stays and a alert box is displayed for a quick navigation to the wifi settings.
  361. * @param enabled
  362. */
  363. public void setWifiDirectAvailable(boolean enabled){
  364. if (enabled){
  365. mTxtP2PNotAvailable.setVisibility(View.GONE);
  366. } else {
  367. mTxtP2PNotAvailable.setVisibility(View.VISIBLE);
  368. ((WiFiPeerListAdapter) mLstP2PDevices.getAdapter()).notifyDataSetChanged();
  369. ownDevice = null;
  370. this.updateDeviceListView(new ArrayList<WifiP2pDevice>());
  371. this.showWifiDisabledDialog();
  372. //Toast.makeText(this, "WiFi Direct P2P is disabled.", Toast.LENGTH_LONG).show();
  373. }
  374. }
  375. /**
  376. * Displays a AlertDialog that informs the User about the disabled Wifi state and can navigate the user directly to the wifi settings.
  377. */
  378. private void showWifiDisabledDialog(){
  379. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  380. builder.setMessage(WIFI_STATUS_DISABLED_MESSAGE)
  381. .setCancelable(true)
  382. .setPositiveButton(WIFI_STATUS_ENABLE_BUTTON, new DialogInterface.OnClickListener() {
  383. public void onClick(DialogInterface dialog, int id) {
  384. startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
  385. }
  386. })
  387. .setNegativeButton(CANCEL_BUTTON_TITLE, new DialogInterface.OnClickListener() {
  388. public void onClick(DialogInterface dialog, int id) {
  389. finish();
  390. }
  391. });
  392. AlertDialog info = builder.create();
  393. info.show();
  394. }
  395. /**
  396. * Extracts all subview initially from the view hierarchy.
  397. */
  398. private void extractFromView(){
  399. this.mTxtP2PDeviceName = (TextView) findViewById(R.id.txt_p2p_device_name);
  400. this.mTxtP2PDeviceStatus = (TextView) findViewById(R.id.txt_p2p_device_status);
  401. this.mTxtP2PChangeDeviceName = (TextView) findViewById(R.id.txtP2PChangeDeviceName);
  402. this.mViewAnimator = (ViewAnimator) findViewById(R.id.viewAnimator);
  403. this.mDevicesContainer = (RelativeLayout) findViewById(R.id.devicesContainer);
  404. this.mWelcomeContainer = (RelativeLayout) findViewById(R.id.welcomeContainer);
  405. this.mTxtP2PSearchProgress = (TextView) findViewById(R.id.txtP2PSearchProgress);
  406. this.mLstP2PDevices = (ListView) findViewById(R.id.lstP2PDevices);
  407. this.mTxtP2PNotAvailable = (TextView) findViewById(R.id.txtP2PNotAvailable);
  408. }
  409. /**
  410. * Registers all the gui listeners.
  411. */
  412. public void registerListeners(){
  413. if (this.mLstP2PDevices.getOnItemClickListener() != this)
  414. this.mLstP2PDevices.setOnItemClickListener(this);
  415. if (this.mLstP2PDevices.getAdapter() == null){
  416. this.discoveredDevices = new ArrayList();
  417. WiFiPeerListAdapter listAdapter = new WiFiPeerListAdapter(this, R.layout.row_devices, this.discoveredDevices);
  418. this.mLstP2PDevices.setAdapter(listAdapter);
  419. }
  420. }
  421. @Override
  422. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  423. final WifiP2pDevice device = (WifiP2pDevice) this.mLstP2PDevices.getAdapter().getItem(position);
  424. this.connectTo(device);
  425. }
  426. /**
  427. * Array adapter for ListFragment that maintains WifiP2pDevice list.
  428. */
  429. private class WiFiPeerListAdapter extends ArrayAdapter<WifiP2pDevice> {
  430. private List<WifiP2pDevice> items;
  431. /**
  432. * @param context
  433. * @param textViewResourceId
  434. * @param objects
  435. */
  436. public WiFiPeerListAdapter(Context context, int textViewResourceId,
  437. List<WifiP2pDevice> objects) {
  438. super(context, textViewResourceId, objects);
  439. items = objects;
  440. }
  441. @Override
  442. public int getCount() {
  443. return items.size();
  444. }
  445. public void addItems(List<WifiP2pDevice> devicesToAdd){
  446. items.clear();
  447. items.addAll(devicesToAdd);
  448. }
  449. @Override
  450. public View getView(int position, View convertView, ViewGroup parent) {
  451. View v = convertView;
  452. if (v == null) {
  453. LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  454. v = vi.inflate(R.layout.row_devices, null);
  455. }
  456. WifiP2pDevice device = items.get(position);
  457. if (device != null) {
  458. TextView top = (TextView) v.findViewById(R.id.device_name);
  459. TextView bottom = (TextView) v.findViewById(R.id.device_details);
  460. if (top != null) {
  461. top.setText(device.deviceName);
  462. }
  463. if (bottom != null) {
  464. bottom.setText(getDeviceStatus(device.status));
  465. }
  466. }
  467. return v;
  468. }
  469. }
  470. }